blob: 29dfd1bd164dcc9ecc49a0115150feeeda1e229f [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 */
45int 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. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
71
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700289 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 */
291static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500292static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800293static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
294static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500295static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500296static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static int qla2xxx_eh_abort(struct scsi_cmnd *);
298static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700299static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
301static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400303static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400304static void qla2x00_free_device(scsi_qla_host_t *);
Michael Hernandez56012362016-12-12 14:40:08 -0800305static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700306static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700307
Quinn Tran45235022018-07-18 14:29:53 -0700308
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700309struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700311 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700312 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700313
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100314 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700315 .eh_abort_handler = qla2xxx_eh_abort,
316 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700317 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700318 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
319 .eh_host_reset_handler = qla2xxx_eh_host_reset,
320
321 .slave_configure = qla2xxx_slave_configure,
322
323 .slave_alloc = qla2xxx_slave_alloc,
324 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700325 .scan_finished = qla2xxx_scan_finished,
326 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100327 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800328 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700329 .this_id = -1,
330 .cmd_per_lun = 3,
331 .use_clustering = ENABLE_CLUSTERING,
332 .sg_tablesize = SG_ALL,
333
334 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700335 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400336
337 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100338 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700339};
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700342struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344/* TODO Convert to inlines
345 *
346 * Timer routines
347 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700349__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700350qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700352 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800354 add_timer(&vha->timer);
355 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
358static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800359qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700361 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700362 if (vha->device_flags & DFLG_DEV_FAILED) {
363 ql_dbg(ql_dbg_timer, vha, 0x600d,
364 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700365 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700366 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700367
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800368 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370
Adrian Bunka824ebb2008-01-17 09:02:15 -0800371static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800372qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800374 del_timer_sync(&vha->timer);
375 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378static int qla2x00_do_dpc(void *data);
379
380static void qla2x00_rst_aen(scsi_qla_host_t *);
381
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800382static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
383 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700384static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800385static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800386int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
387 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700390static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
391 struct rsp_que *rsp)
392{
393 struct qla_hw_data *ha = vha->hw;
394 rsp->qpair = ha->base_qpair;
395 rsp->req = req;
Quinn Tran06910942018-09-04 14:19:12 -0700396 ha->base_qpair->hw = ha;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700397 ha->base_qpair->req = req;
398 ha->base_qpair->rsp = rsp;
399 ha->base_qpair->vha = vha;
400 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
401 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
402 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
Quinn Tran6a629462018-09-04 14:19:15 -0700403 ha->base_qpair->srb_mempool = ha->srb_mempool;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700404 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
405 ha->base_qpair->enable_class_2 = ql2xenableclass2;
406 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800407 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700408 ha->base_qpair->pdev = ha->pdev;
409
410 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
411 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
412}
413
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400414static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
415 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800416{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700417 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Kees Cook6396bb22018-06-12 14:03:40 -0700418 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800419 GFP_KERNEL);
420 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700421 ql_log(ql_log_fatal, vha, 0x003b,
422 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800423 goto fail_req_map;
424 }
425
Kees Cook6396bb22018-06-12 14:03:40 -0700426 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800427 GFP_KERNEL);
428 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700429 ql_log(ql_log_fatal, vha, 0x003c,
430 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800431 goto fail_rsp_map;
432 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800433
Quinn Trane326d222017-06-13 20:47:18 -0700434 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
435 if (ha->base_qpair == NULL) {
436 ql_log(ql_log_warn, vha, 0x00e0,
437 "Failed to allocate base queue pair memory.\n");
438 goto fail_base_qpair;
439 }
440
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700441 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700442
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700443 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800444 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
445 GFP_KERNEL);
446 if (!ha->queue_pair_map) {
447 ql_log(ql_log_fatal, vha, 0x0180,
448 "Unable to allocate memory for queue pair ptrs.\n");
449 goto fail_qpair_map;
450 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800451 }
452
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400453 /*
454 * Make sure we record at least the request and response queue zero in
455 * case we need to free them if part of the probe fails.
456 */
457 ha->rsp_q_map[0] = rsp;
458 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800459 set_bit(0, ha->rsp_qid_map);
460 set_bit(0, ha->req_qid_map);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -0500461 return 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800462
Michael Hernandezd7459522016-12-12 14:40:07 -0800463fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700464 kfree(ha->base_qpair);
465 ha->base_qpair = NULL;
466fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800467 kfree(ha->rsp_q_map);
468 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800469fail_rsp_map:
470 kfree(ha->req_q_map);
471 ha->req_q_map = NULL;
472fail_req_map:
473 return -ENOMEM;
474}
475
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700476static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800477{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400478 if (IS_QLAFX00(ha)) {
479 if (req && req->ring_fx00)
480 dma_free_coherent(&ha->pdev->dev,
481 (req->length_fx00 + 1) * sizeof(request_t),
482 req->ring_fx00, req->dma_fx00);
483 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800484 dma_free_coherent(&ha->pdev->dev,
485 (req->length + 1) * sizeof(request_t),
486 req->ring, req->dma);
487
Bill Kuzeja6d634062018-03-23 10:37:25 -0400488 if (req)
Chad Dupuis8d93f552013-01-30 03:34:37 -0500489 kfree(req->outstanding_cmds);
Bill Kuzeja6d634062018-03-23 10:37:25 -0400490
491 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800492}
493
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700494static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
495{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400496 if (IS_QLAFX00(ha)) {
Meelis Roos3f6c9be2018-03-08 15:44:37 +0200497 if (rsp && rsp->ring_fx00)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400498 dma_free_coherent(&ha->pdev->dev,
499 (rsp->length_fx00 + 1) * sizeof(request_t),
500 rsp->ring_fx00, rsp->dma_fx00);
501 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700502 dma_free_coherent(&ha->pdev->dev,
503 (rsp->length + 1) * sizeof(response_t),
504 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400505 }
Bill Kuzeja6d634062018-03-23 10:37:25 -0400506 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700507}
508
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800509static void qla2x00_free_queues(struct qla_hw_data *ha)
510{
511 struct req_que *req;
512 struct rsp_que *rsp;
513 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800514 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800515
Quinn Tran82de8022017-06-13 20:47:17 -0700516 if (ha->queue_pair_map) {
517 kfree(ha->queue_pair_map);
518 ha->queue_pair_map = NULL;
519 }
520 if (ha->base_qpair) {
521 kfree(ha->base_qpair);
522 ha->base_qpair = NULL;
523 }
524
Quinn Tran093df732016-12-12 14:40:09 -0800525 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700526 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500527 if (!test_bit(cnt, ha->req_qid_map))
528 continue;
529
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800530 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800531 clear_bit(cnt, ha->req_qid_map);
532 ha->req_q_map[cnt] = NULL;
533
534 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700535 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800536 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700537 }
Quinn Tran093df732016-12-12 14:40:09 -0800538 spin_unlock_irqrestore(&ha->hardware_lock, flags);
539
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700540 kfree(ha->req_q_map);
541 ha->req_q_map = NULL;
542
Quinn Tran093df732016-12-12 14:40:09 -0800543
544 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700545 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500546 if (!test_bit(cnt, ha->rsp_qid_map))
547 continue;
548
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700549 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500550 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800551 ha->rsp_q_map[cnt] = NULL;
552 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700553 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800554 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800555 }
Quinn Tran093df732016-12-12 14:40:09 -0800556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
557
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800558 kfree(ha->rsp_q_map);
559 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800560}
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800565 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 static char *pci_bus_modes[] = {
567 "33", "66", "100", "133",
568 };
569 uint16_t pci_bus;
570
571 strcpy(str, "PCI");
572 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
573 if (pci_bus) {
574 strcat(str, "-X (");
575 strcat(str, pci_bus_modes[pci_bus]);
576 } else {
577 pci_bus = (ha->pci_attr & BIT_8) >> 8;
578 strcat(str, " (");
579 strcat(str, pci_bus_modes[pci_bus]);
580 }
581 strcat(str, " MHz)");
582
583 return (str);
584}
585
Andrew Vasquezfca29702005-07-06 10:31:47 -0700586static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700588{
589 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700592
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600593 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700594 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600595 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700596
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600597 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
598 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
599 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700600
601 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500602 switch (lspeed) {
603 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700604 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500605 break;
606 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700607 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500608 break;
609 case 3:
610 strcat(str, "8.0GT/s ");
611 break;
612 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700613 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500614 break;
615 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700616 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
617 strcat(str, lwstr);
618
619 return str;
620 }
621
622 strcpy(str, "PCI");
623 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
624 if (pci_bus == 0 || pci_bus == 8) {
625 strcat(str, " (");
626 strcat(str, pci_bus_modes[pci_bus >> 3]);
627 } else {
628 strcat(str, "-X ");
629 if (pci_bus & BIT_2)
630 strcat(str, "Mode 2");
631 else
632 strcat(str, "Mode 1");
633 strcat(str, " (");
634 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
635 }
636 strcat(str, " MHz)");
637
638 return str;
639}
640
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800641static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400642qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800645 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700646
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400647 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
648 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 if (ha->fw_attributes & BIT_9) {
651 strcat(str, "FLX");
652 return (str);
653 }
654
655 switch (ha->fw_attributes & 0xFF) {
656 case 0x7:
657 strcat(str, "EF");
658 break;
659 case 0x17:
660 strcat(str, "TP");
661 break;
662 case 0x37:
663 strcat(str, "IP");
664 break;
665 case 0x77:
666 strcat(str, "VI");
667 break;
668 default:
669 sprintf(un_str, "(%x)", ha->fw_attributes);
670 strcat(str, un_str);
671 break;
672 }
673 if (ha->fw_attributes & 0x100)
674 strcat(str, "X");
675
676 return (str);
677}
678
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800679static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400680qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700681{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800682 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700683
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400684 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800685 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700686 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700687}
688
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800689void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800690qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700691{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800692 srb_t *sp = ptr;
693 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800694 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800695 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700696
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800697 if (sp->flags & SRB_DMA_VALID) {
698 scsi_dma_unmap(cmd);
699 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700700 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700701
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800702 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
703 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
704 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
705 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
706 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700707
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700708 if (!ctx)
709 goto end;
710
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800711 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
712 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700713 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800714 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
715 }
716
717 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700718 struct crc_context *ctx0 = ctx;
719
720 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800721 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
722 }
723
724 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700725 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800726
727 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700728 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800729 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
730 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
731 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
732 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800733 }
734
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700735end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700736 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700737 CMD_SP(cmd) = NULL;
738 qla2x00_rel_sp(sp);
739 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800740}
741
Michael Hernandezd7459522016-12-12 14:40:07 -0800742void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800743qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800744{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800745 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800746 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
747
748 cmd->result = res;
749
750 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800751 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800752 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
753 sp, GET_CMD_SP(sp));
754 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400755 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800756 return;
757 }
758 if (!atomic_dec_and_test(&sp->ref_count))
759 return;
760
Joe Carnucciof3caa992017-08-23 15:05:09 -0700761 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800762 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700763}
764
Michael Hernandezd7459522016-12-12 14:40:07 -0800765void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800766qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800767{
768 srb_t *sp = (srb_t *)ptr;
769 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
770 struct qla_hw_data *ha = sp->fcport->vha->hw;
771 void *ctx = GET_CMD_CTX_SP(sp);
772
773 if (sp->flags & SRB_DMA_VALID) {
774 scsi_dma_unmap(cmd);
775 sp->flags &= ~SRB_DMA_VALID;
776 }
777
778 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
779 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
780 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
781 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
782 }
783
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700784 if (!ctx)
785 goto end;
786
Michael Hernandezd7459522016-12-12 14:40:07 -0800787 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
788 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700789 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800790 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
791 }
792
793 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700794 struct crc_context *ctx0 = ctx;
795
796 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800797 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
798 }
799
800 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700801 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800802 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
803 ctx1->fcp_cmnd_dma);
804 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
805 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
806 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
807 mempool_free(ctx1, ha->ctx_mempool);
808 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700809end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800810 CMD_SP(cmd) = NULL;
811 qla2xxx_rel_qpair_sp(sp->qpair, sp);
812}
813
814void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800815qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800816{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800817 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800818 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
819
820 cmd->result = res;
821
822 if (atomic_read(&sp->ref_count) == 0) {
823 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
824 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
825 sp, GET_CMD_SP(sp));
826 if (ql2xextended_error_logging & ql_dbg_io)
827 WARN_ON(atomic_read(&sp->ref_count) == 0);
828 return;
829 }
830 if (!atomic_dec_and_test(&sp->ref_count))
831 return;
832
Joe Carnucciof3caa992017-08-23 15:05:09 -0700833 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800834 cmd->scsi_done(cmd);
835}
836
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400837/* If we are SP1 here, we need to still take and release the host_lock as SP1
838 * does not have the changes necessary to avoid taking host->host_lock.
839 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800841qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700842{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700843 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700844 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400845 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 struct qla_hw_data *ha = vha->hw;
847 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700848 srb_t *sp;
849 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800850 struct qla_qpair *qpair = NULL;
851 uint32_t tag;
852 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700853
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200854 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
855 cmd->result = DID_NO_CONNECT << 16;
856 goto qc24_fail_command;
857 }
858
Michael Hernandez56012362016-12-12 14:40:08 -0800859 if (ha->mqenable) {
Jens Axboef664a3c2018-11-01 16:36:27 -0600860 tag = blk_mq_unique_tag(cmd->request);
861 hwq = blk_mq_unique_tag_to_hwq(tag);
862 qpair = ha->queue_pair_map[hwq];
Michael Hernandez56012362016-12-12 14:40:08 -0800863
864 if (qpair)
865 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800866 }
867
Andrew Vasquez85880802009-12-15 21:29:46 -0800868 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700869 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400870 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700871 "PCI Channel IO permanent failure, exiting "
872 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700873 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400875 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700876 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800877 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700878 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700879 goto qc24_fail_command;
880 }
881
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400882 rval = fc_remote_port_chkready(rport);
883 if (rval) {
884 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400885 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700886 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
887 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700888 goto qc24_fail_command;
889 }
890
Arun Easibad75002010-05-04 15:01:30 -0700891 if (!vha->flags.difdix_supported &&
892 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700893 ql_dbg(ql_dbg_io, vha, 0x3004,
894 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
895 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700896 cmd->result = DID_NO_CONNECT << 16;
897 goto qc24_fail_command;
898 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800899
900 if (!fcport) {
901 cmd->result = DID_NO_CONNECT << 16;
902 goto qc24_fail_command;
903 }
904
Andrew Vasquezfca29702005-07-06 10:31:47 -0700905 if (atomic_read(&fcport->state) != FCS_ONLINE) {
906 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700907 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700908 ql_dbg(ql_dbg_io, vha, 0x3005,
909 "Returning DNC, fcport_state=%d loop_state=%d.\n",
910 atomic_read(&fcport->state),
911 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700912 cmd->result = DID_NO_CONNECT << 16;
913 goto qc24_fail_command;
914 }
Mike Christie7b594132008-08-17 15:24:40 -0500915 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700916 }
917
Chad Dupuise05fe292014-09-25 05:16:59 -0400918 /*
919 * Return target busy if we've received a non-zero retry_delay_timer
920 * in a FCP_RSP.
921 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100922 if (fcport->retry_delay_timestamp == 0) {
923 /* retry delay not set */
924 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400925 fcport->retry_delay_timestamp = 0;
926 else
927 goto qc24_target_busy;
928
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500929 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400930 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800931 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700932
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800933 sp->u.scmd.cmd = cmd;
934 sp->type = SRB_SCSI_CMD;
935 atomic_set(&sp->ref_count, 1);
936 CMD_SP(cmd) = (void *)sp;
937 sp->free = qla2x00_sp_free_dma;
938 sp->done = qla2x00_sp_compl;
939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700941 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500942 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700943 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700944 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946
Andrew Vasquezfca29702005-07-06 10:31:47 -0700947 return 0;
948
949qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700950 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700951
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800952qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700953 return SCSI_MLQUEUE_HOST_BUSY;
954
Mike Christie7b594132008-08-17 15:24:40 -0500955qc24_target_busy:
956 return SCSI_MLQUEUE_TARGET_BUSY;
957
Andrew Vasquezfca29702005-07-06 10:31:47 -0700958qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800959 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700960
961 return 0;
962}
963
Michael Hernandezd7459522016-12-12 14:40:07 -0800964/* For MQ supported I/O */
965int
966qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
967 struct qla_qpair *qpair)
968{
969 scsi_qla_host_t *vha = shost_priv(host);
970 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
971 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
972 struct qla_hw_data *ha = vha->hw;
973 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
974 srb_t *sp;
975 int rval;
976
977 rval = fc_remote_port_chkready(rport);
978 if (rval) {
979 cmd->result = rval;
980 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
981 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
982 cmd, rval);
983 goto qc24_fail_command;
984 }
985
986 if (!fcport) {
987 cmd->result = DID_NO_CONNECT << 16;
988 goto qc24_fail_command;
989 }
990
991 if (atomic_read(&fcport->state) != FCS_ONLINE) {
992 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
993 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
994 ql_dbg(ql_dbg_io, vha, 0x3077,
995 "Returning DNC, fcport_state=%d loop_state=%d.\n",
996 atomic_read(&fcport->state),
997 atomic_read(&base_vha->loop_state));
998 cmd->result = DID_NO_CONNECT << 16;
999 goto qc24_fail_command;
1000 }
1001 goto qc24_target_busy;
1002 }
1003
1004 /*
1005 * Return target busy if we've received a non-zero retry_delay_timer
1006 * in a FCP_RSP.
1007 */
1008 if (fcport->retry_delay_timestamp == 0) {
1009 /* retry delay not set */
1010 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1011 fcport->retry_delay_timestamp = 0;
1012 else
1013 goto qc24_target_busy;
1014
Quinn Tran6a629462018-09-04 14:19:15 -07001015 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001016 if (!sp)
1017 goto qc24_host_busy;
1018
1019 sp->u.scmd.cmd = cmd;
1020 sp->type = SRB_SCSI_CMD;
1021 atomic_set(&sp->ref_count, 1);
1022 CMD_SP(cmd) = (void *)sp;
1023 sp->free = qla2xxx_qpair_sp_free_dma;
1024 sp->done = qla2xxx_qpair_sp_compl;
1025 sp->qpair = qpair;
1026
1027 rval = ha->isp_ops->start_scsi_mq(sp);
1028 if (rval != QLA_SUCCESS) {
1029 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1030 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1031 if (rval == QLA_INTERFACE_ERROR)
1032 goto qc24_fail_command;
1033 goto qc24_host_busy_free_sp;
1034 }
1035
1036 return 0;
1037
1038qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001039 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001040
1041qc24_host_busy:
1042 return SCSI_MLQUEUE_HOST_BUSY;
1043
1044qc24_target_busy:
1045 return SCSI_MLQUEUE_TARGET_BUSY;
1046
1047qc24_fail_command:
1048 cmd->scsi_done(cmd);
1049
1050 return 0;
1051}
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053/*
1054 * qla2x00_eh_wait_on_command
1055 * Waits for the command to be returned by the Firmware for some
1056 * max time.
1057 *
1058 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 *
1061 * Return:
1062 * Not Found : 0
1063 * Found : 1
1064 */
1065static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001066qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001068#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001069#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001070 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001071 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1072 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001073 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Andrew Vasquez85880802009-12-15 21:29:46 -08001075 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001076 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1077 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001078 return ret;
1079 }
1080
Lalit Chandivaded9704322009-08-25 11:36:18 -07001081 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001082 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001083 }
1084 if (CMD_SP(cmd))
1085 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
f4f051e2005-04-17 15:02:26 -05001087 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
1090/*
1091 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001092 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 * <= MAX_RETRIES_OF_ISP_ABORT or
1094 * finally HBA is disabled ie marked offline
1095 *
1096 * Input:
1097 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001098 *
1099 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 * Does context switching-Release SPIN_LOCK
1101 * (if any) before calling this routine.
1102 *
1103 * Return:
1104 * Success (Adapter is online) : 0
1105 * Failed (Adapter is offline/disabled) : 1
1106 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001107int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001108qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001110 int return_status;
1111 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112 struct qla_hw_data *ha = vha->hw;
1113 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001115 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001116 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1117 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1118 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1119 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 msleep(1000);
1122 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001123 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001124 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 else
1126 return_status = QLA_FUNCTION_FAILED;
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 return (return_status);
1129}
1130
Quinn Tran726b8542017-01-19 22:28:00 -08001131static inline int test_fcport_count(scsi_qla_host_t *vha)
1132{
1133 struct qla_hw_data *ha = vha->hw;
1134 unsigned long flags;
1135 int res;
1136
1137 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001138 ql_dbg(ql_dbg_init, vha, 0x00ec,
1139 "tgt %p, fcport_count=%d\n",
1140 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001141 res = (vha->fcport_count == 0);
1142 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1143
1144 return res;
1145}
1146
1147/*
1148 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1149 * it has dependency on UNLOADING flag to stop device discovery
1150 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001151void
Quinn Tran726b8542017-01-19 22:28:00 -08001152qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1153{
1154 qla2x00_mark_all_devices_lost(vha, 0);
1155
Joe Carnucciob85e0952017-08-23 15:05:11 -07001156 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001157}
1158
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001159/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001160 * qla2x00_wait_for_hba_ready
1161 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001162 *
1163 * Input:
1164 * ha - pointer to host adapter structure
1165 *
1166 * Note:
1167 * Does context switching-Release SPIN_LOCK
1168 * (if any) before calling this routine.
1169 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001170 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001171static void
1172qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001173{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001174 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001175 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001176
Dan Carpenter1d483902016-08-03 21:42:32 +03001177 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1178 ha->flags.mbox_busy) ||
1179 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1180 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1181 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1182 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001183 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001184 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001185}
1186
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001187int
1188qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1189{
1190 int return_status;
1191 unsigned long wait_reset;
1192 struct qla_hw_data *ha = vha->hw;
1193 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1194
1195 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1196 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1197 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1198 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1199 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1200
1201 msleep(1000);
1202
1203 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1204 ha->flags.chip_reset_done)
1205 break;
1206 }
1207 if (ha->flags.chip_reset_done)
1208 return_status = QLA_SUCCESS;
1209 else
1210 return_status = QLA_FUNCTION_FAILED;
1211
1212 return return_status;
1213}
1214
Quinn Tran585def92018-09-04 14:19:20 -07001215static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001216sp_get(struct srb *sp)
1217{
Quinn Tran585def92018-09-04 14:19:20 -07001218 if (!refcount_inc_not_zero((refcount_t*)&sp->ref_count))
1219 /* kref get fail */
1220 return ENXIO;
1221 else
1222 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001223}
1224
Sawan Chandaka4655372016-07-06 11:14:32 -04001225#define ISP_REG_DISCONNECT 0xffffffffU
1226/**************************************************************************
1227* qla2x00_isp_reg_stat
1228*
1229* Description:
1230* Read the host status register of ISP before aborting the command.
1231*
1232* Input:
1233* ha = pointer to host adapter structure.
1234*
1235*
1236* Returns:
1237* Either true or false.
1238*
1239* Note: Return true if there is register disconnect.
1240**************************************************************************/
1241static inline
1242uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1243{
1244 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001245 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001246
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001247 if (IS_P3P_TYPE(ha))
1248 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1249 else
1250 return ((RD_REG_DWORD(&reg->host_status)) ==
1251 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001252}
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254/**************************************************************************
1255* qla2xxx_eh_abort
1256*
1257* Description:
1258* The abort function will abort the specified command.
1259*
1260* Input:
1261* cmd = Linux SCSI command packet to be aborted.
1262*
1263* Returns:
1264* Either SUCCESS or FAILED.
1265*
1266* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001267* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001269static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1271{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001273 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001274 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001275 unsigned int id;
1276 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001277 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001278 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001280 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Sawan Chandaka4655372016-07-06 11:14:32 -04001282 if (qla2x00_isp_reg_stat(ha)) {
1283 ql_log(ql_log_info, vha, 0x8042,
1284 "PCI/Register disconnect, exiting.\n");
1285 return FAILED;
1286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001288 ret = fc_block_scsi_eh(cmd);
1289 if (ret != 0)
1290 return ret;
1291 ret = SUCCESS;
1292
Mike Christie170babc2010-10-15 11:27:47 -07001293 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001294 if (!sp)
1295 return SUCCESS;
1296
1297 qpair = sp->qpair;
1298 if (!qpair)
1299 return SUCCESS;
1300
1301 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1302 if (!CMD_SP(cmd)) {
1303 /* there's a chance an interrupt could clear
1304 the ptr as part of done & free */
1305 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001306 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001307 }
Mike Christie170babc2010-10-15 11:27:47 -07001308
Quinn Tran585def92018-09-04 14:19:20 -07001309 if (sp_get(sp)){
1310 /* ref_count is already 0 */
1311 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1312 return SUCCESS;
1313 }
1314 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1315
1316 id = cmd->device->id;
1317 lun = cmd->device->lun;
1318
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001319 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001320 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1321 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001322
1323 /* Get a reference to the sp and drop the lock.*/
Mike Christie170babc2010-10-15 11:27:47 -07001324
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001325 rval = ha->isp_ops->abort_command(sp);
1326 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001327 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001328 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001329 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001330 ret = FAILED;
1331
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001332 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001333 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001334 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001335 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001336 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001337 wait = 1;
1338 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001339
Quinn Tran585def92018-09-04 14:19:20 -07001340 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1341 /*
1342 * Clear the slot in the oustanding_cmds array if we can't find the
1343 * command to reclaim the resources.
1344 */
1345 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
1346 vha->req->outstanding_cmds[sp->handle] = NULL;
1347
1348 /*
1349 * sp->done will do ref_count--
1350 * sp_get() took an extra count above
1351 */
1352 sp->done(sp, DID_RESET << 16);
f4f051e2005-04-17 15:02:26 -05001353
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001354 /* Did the command return during mailbox execution? */
1355 if (ret == FAILED && !CMD_SP(cmd))
1356 ret = SUCCESS;
1357
Quinn Tran585def92018-09-04 14:19:20 -07001358 if (!CMD_SP(cmd))
1359 wait = 0;
1360
1361 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1362
f4f051e2005-04-17 15:02:26 -05001363 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001364 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001366 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001367 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001368 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001372 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001373 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001374 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
f4f051e2005-04-17 15:02:26 -05001376 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001379int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001381 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001383 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001384 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001385 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001386 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001387 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001388 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Andrew Vasquez523ec772008-04-03 13:13:24 -07001390 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001391
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001392 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001393 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001394 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001395 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001396 sp = req->outstanding_cmds[cnt];
1397 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001398 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001399 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001400 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001401 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001402 continue;
1403 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001404 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001405 switch (type) {
1406 case WAIT_HOST:
1407 match = 1;
1408 break;
1409 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001410 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001411 break;
1412 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001413 match = (cmd->device->id == t &&
1414 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001415 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001417 if (!match)
1418 continue;
1419
1420 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001421 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001422 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001425
1426 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427}
1428
Andrew Vasquez523ec772008-04-03 13:13:24 -07001429static char *reset_errors[] = {
1430 "HBA not online",
1431 "HBA not ready",
1432 "Task management failed",
1433 "Waiting for command completions",
1434};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Andrew Vasquez523ec772008-04-03 13:13:24 -07001436static int
1437__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001438 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001439{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001441 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1442 int err;
1443
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001444 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001445 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001446 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001447
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001448 err = fc_block_scsi_eh(cmd);
1449 if (err != 0)
1450 return err;
1451
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001452 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001453 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001454 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001455
1456 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1458 ql_log(ql_log_warn, vha, 0x800a,
1459 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001460 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001461 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001462 err = 2;
Jens Axboe9cf2bab2018-10-31 17:01:22 -06001463 if (do_reset(fcport, cmd->device->lun, blk_mq_rq_cpu(cmd->request) + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001464 != QLA_SUCCESS) {
1465 ql_log(ql_log_warn, vha, 0x800c,
1466 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001467 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001468 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001469 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001471 cmd->device->lun, type) != QLA_SUCCESS) {
1472 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001473 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001474 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001475 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001476
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001477 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001478 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001479 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001480
1481 return SUCCESS;
1482
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001483eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001484 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001485 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001486 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1487 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001488 return FAILED;
1489}
1490
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001491static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1493{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001494 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1495 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Sawan Chandaka4655372016-07-06 11:14:32 -04001497 if (qla2x00_isp_reg_stat(ha)) {
1498 ql_log(ql_log_info, vha, 0x803e,
1499 "PCI/Register disconnect, exiting.\n");
1500 return FAILED;
1501 }
1502
Andrew Vasquez523ec772008-04-03 13:13:24 -07001503 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1504 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001508qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001510 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1511 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Sawan Chandaka4655372016-07-06 11:14:32 -04001513 if (qla2x00_isp_reg_stat(ha)) {
1514 ql_log(ql_log_info, vha, 0x803f,
1515 "PCI/Register disconnect, exiting.\n");
1516 return FAILED;
1517 }
1518
Andrew Vasquez523ec772008-04-03 13:13:24 -07001519 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1520 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523/**************************************************************************
1524* qla2xxx_eh_bus_reset
1525*
1526* Description:
1527* The bus reset function will reset the bus and abort any executing
1528* commands.
1529*
1530* Input:
1531* cmd = Linux SCSI command packet of the command that cause the
1532* bus reset.
1533*
1534* Returns:
1535* SUCCESS/FAILURE (defined as macro in scsi.h).
1536*
1537**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001538static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1540{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001541 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001542 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001543 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001544 unsigned int id;
1545 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001546 struct qla_hw_data *ha = vha->hw;
1547
1548 if (qla2x00_isp_reg_stat(ha)) {
1549 ql_log(ql_log_info, vha, 0x8040,
1550 "PCI/Register disconnect, exiting.\n");
1551 return FAILED;
1552 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
f4f051e2005-04-17 15:02:26 -05001554 id = cmd->device->id;
1555 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001556
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001558 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001561 ret = fc_block_scsi_eh(cmd);
1562 if (ret != 0)
1563 return ret;
1564 ret = FAILED;
1565
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001566 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001567 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001569 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001570 ql_log(ql_log_fatal, vha, 0x8013,
1571 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001572 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 }
1574
Saurav Kashyapad5376892011-11-18 09:02:09 -08001575 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1576 ret = SUCCESS;
1577
f4f051e2005-04-17 15:02:26 -05001578 if (ret == FAILED)
1579 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001581 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001582 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001583 QLA_SUCCESS) {
1584 ql_log(ql_log_warn, vha, 0x8014,
1585 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001586 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
f4f051e2005-04-17 15:02:26 -05001589eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001590 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001591 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001592 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
f4f051e2005-04-17 15:02:26 -05001594 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
1596
1597/**************************************************************************
1598* qla2xxx_eh_host_reset
1599*
1600* Description:
1601* The reset function will reset the Adapter.
1602*
1603* Input:
1604* cmd = Linux SCSI command packet of the command that cause the
1605* adapter reset.
1606*
1607* Returns:
1608* Either SUCCESS or FAILED.
1609*
1610* Note:
1611**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001612static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1614{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001615 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001617 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001618 unsigned int id;
1619 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Sawan Chandaka4655372016-07-06 11:14:32 -04001622 if (qla2x00_isp_reg_stat(ha)) {
1623 ql_log(ql_log_info, vha, 0x8041,
1624 "PCI/Register disconnect, exiting.\n");
1625 schedule_work(&ha->board_disable);
1626 return SUCCESS;
1627 }
1628
f4f051e2005-04-17 15:02:26 -05001629 id = cmd->device->id;
1630 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001631
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001632 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001633 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Chad Dupuis63ee7072014-04-11 16:54:46 -04001635 /*
1636 * No point in issuing another reset if one is active. Also do not
1637 * attempt a reset if we are updating flash.
1638 */
1639 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001640 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 if (vha != base_vha) {
1643 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001644 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001645 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001646 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001647 if (!qla82xx_fcoe_ctx_reset(vha)) {
1648 /* Ctx reset success */
1649 ret = SUCCESS;
1650 goto eh_host_reset_lock;
1651 }
1652 /* fall thru if ctx reset failed */
1653 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001654 if (ha->wq)
1655 flush_workqueue(ha->wq);
1656
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001657 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001658 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001659 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1660 /* failed. schedule dpc to try */
1661 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1662
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001663 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1664 ql_log(ql_log_warn, vha, 0x802a,
1665 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001666 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001667 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001668 }
1669 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001673 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001674 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001675 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
f4f051e2005-04-17 15:02:26 -05001677eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001678 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001679 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001680 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
f4f051e2005-04-17 15:02:26 -05001682 return ret;
1683}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
1685/*
1686* qla2x00_loop_reset
1687* Issue loop reset.
1688*
1689* Input:
1690* ha = adapter block pointer.
1691*
1692* Returns:
1693* 0 = success
1694*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001695int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001698 int ret;
bdf79622005-04-17 15:06:53 -05001699 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Armen Baloyan58547712013-08-27 01:37:33 -04001702 if (IS_QLAFX00(ha)) {
1703 return qlafx00_loop_reset(vha);
1704 }
1705
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001706 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001707 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1708 if (fcport->port_type != FCT_TARGET)
1709 continue;
1710
1711 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1712 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001713 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001714 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001715 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001716 }
1717 }
1718 }
1719
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001720
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001721 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001722 atomic_set(&vha->loop_state, LOOP_DOWN);
1723 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1724 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001725 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001726 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001727 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1728 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 }
1731
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001732 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001733 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001734 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001735 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1736 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001737 }
1738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001740 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001742 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
Quinn Tranbbead492017-12-28 12:33:13 -08001745static void
1746__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001747{
Bart Van Asscheeb023222018-10-18 15:45:44 -07001748 int cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001749 unsigned long flags;
1750 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001751 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001752 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001753 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001754 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1755 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001756
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001757 if (!ha->req_q_map)
1758 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001759 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1760 req = qp->req;
1761 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1762 sp = req->outstanding_cmds[cnt];
1763 if (sp) {
1764 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001765 switch (sp->cmd_type) {
1766 case TYPE_SRB:
Quinn Tranbbead492017-12-28 12:33:13 -08001767 if (sp->type == SRB_NVME_CMD ||
1768 sp->type == SRB_NVME_LS) {
Quinn Tran585def92018-09-04 14:19:20 -07001769 if (!sp_get(sp)) {
1770 /* got sp */
Quinn Tran6b0431d2018-09-04 14:19:13 -07001771 spin_unlock_irqrestore
1772 (qp->qp_lock_ptr,
1773 flags);
1774 qla_nvme_abort(ha, sp, res);
1775 spin_lock_irqsave
Quinn Tran585def92018-09-04 14:19:20 -07001776 (qp->qp_lock_ptr, flags);
1777 }
Quinn Tranbbead492017-12-28 12:33:13 -08001778 } else if (GET_CMD_SP(sp) &&
1779 !ha->flags.eeh_busy &&
1780 (!test_bit(ABORT_ISP_ACTIVE,
1781 &vha->dpc_flags)) &&
Sawan Chandakf99c5d2942018-09-11 10:18:14 -07001782 !qla2x00_isp_reg_stat(ha) &&
Quinn Tranbbead492017-12-28 12:33:13 -08001783 (sp->type == SRB_SCSI_CMD)) {
1784 /*
Quinn Tran585def92018-09-04 14:19:20 -07001785 * Don't abort commands in adapter
1786 * during EEH recovery as it's not
Quinn Tranbbead492017-12-28 12:33:13 -08001787 * accessible/responding.
1788 *
Quinn Tran585def92018-09-04 14:19:20 -07001789 * Get a reference to the sp and drop
1790 * the lock. The reference ensures this
1791 * sp->done() call and not the call in
1792 * qla2xxx_eh_abort() ends the SCSI cmd
1793 * (with result 'res').
Quinn Tranbbead492017-12-28 12:33:13 -08001794 */
Quinn Tran585def92018-09-04 14:19:20 -07001795 if (!sp_get(sp)) {
Quinn Tran6b0431d2018-09-04 14:19:13 -07001796 spin_unlock_irqrestore
Quinn Tran585def92018-09-04 14:19:20 -07001797 (qp->qp_lock_ptr, flags);
Bart Van Asscheeb023222018-10-18 15:45:44 -07001798 qla2xxx_eh_abort(
1799 GET_CMD_SP(sp));
Quinn Tran6b0431d2018-09-04 14:19:13 -07001800 spin_lock_irqsave
Quinn Tran585def92018-09-04 14:19:20 -07001801 (qp->qp_lock_ptr, flags);
Quinn Tran6b0431d2018-09-04 14:19:13 -07001802 }
Quinn Tranc5419e22017-06-13 20:47:16 -07001803 }
Quinn Tranbbead492017-12-28 12:33:13 -08001804 sp->done(sp, res);
Quinn Tran585def92018-09-04 14:19:20 -07001805 break;
1806 case TYPE_TGT_CMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001807 if (!vha->hw->tgt.tgt_ops || !tgt ||
1808 qla_ini_mode_enabled(vha)) {
Quinn Tran585def92018-09-04 14:19:20 -07001809 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1810 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1811 vha->dpc_flags);
Quinn Tranbbead492017-12-28 12:33:13 -08001812 continue;
1813 }
1814 cmd = (struct qla_tgt_cmd *)sp;
1815 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001816 break;
1817 case TYPE_TGT_TMCMD:
1818 /*
1819 * Currently, only ABTS response gets on the
1820 * outstanding_cmds[]
1821 */
1822 ha->tgt.tgt_ops->free_mcmd(
1823 (struct qla_tgt_mgmt_cmd *)sp);
1824 break;
1825 default:
1826 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001827 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001828 }
1829 }
Quinn Tranbbead492017-12-28 12:33:13 -08001830 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1831}
1832
1833void
1834qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1835{
1836 int que;
1837 struct qla_hw_data *ha = vha->hw;
1838
1839 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1840
1841 for (que = 0; que < ha->max_qpairs; que++) {
1842 if (!ha->queue_pair_map[que])
1843 continue;
1844
1845 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1846 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001847}
1848
f4f051e2005-04-17 15:02:26 -05001849static int
1850qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
bdf79622005-04-17 15:06:53 -05001852 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001854 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001855 return -ENXIO;
1856
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001857 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001858
1859 return 0;
1860}
1861
1862static int
1863qla2xxx_slave_configure(struct scsi_device *sdev)
1864{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001866 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001867
Arun Easi9e522cd2012-08-22 14:21:31 -04001868 if (IS_T10_PI_CAPABLE(vha->hw))
1869 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1870
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001871 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001872 return 0;
1873}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
f4f051e2005-04-17 15:02:26 -05001875static void
1876qla2xxx_slave_destroy(struct scsi_device *sdev)
1877{
1878 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879}
1880
1881/**
1882 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1883 * @ha: HA context
1884 *
1885 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1886 * supported addressing method.
1887 */
1888static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001889qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001891 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Yang Hongyang6a355282009-04-06 19:01:13 -07001894 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001895 /* Any upper-dword bits set? */
1896 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001897 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001898 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001900 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1901 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001902 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001905
Yang Hongyang284901a2009-04-06 19:01:15 -07001906 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1907 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908}
1909
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001910static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001912{
1913 unsigned long flags = 0;
1914 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1915
1916 spin_lock_irqsave(&ha->hardware_lock, flags);
1917 ha->interrupts_on = 1;
1918 /* enable risc and host interrupts */
1919 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1920 RD_REG_WORD(&reg->ictrl);
1921 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1922
1923}
1924
1925static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001927{
1928 unsigned long flags = 0;
1929 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1930
1931 spin_lock_irqsave(&ha->hardware_lock, flags);
1932 ha->interrupts_on = 0;
1933 /* disable risc and host interrupts */
1934 WRT_REG_WORD(&reg->ictrl, 0);
1935 RD_REG_WORD(&reg->ictrl);
1936 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1937}
1938
1939static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001941{
1942 unsigned long flags = 0;
1943 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1944
1945 spin_lock_irqsave(&ha->hardware_lock, flags);
1946 ha->interrupts_on = 1;
1947 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1948 RD_REG_DWORD(&reg->ictrl);
1949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1950}
1951
1952static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001954{
1955 unsigned long flags = 0;
1956 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1957
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001958 if (IS_NOPOLLING_TYPE(ha))
1959 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001960 spin_lock_irqsave(&ha->hardware_lock, flags);
1961 ha->interrupts_on = 0;
1962 WRT_REG_DWORD(&reg->ictrl, 0);
1963 RD_REG_DWORD(&reg->ictrl);
1964 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1965}
1966
Giridhar Malavali706f4572011-11-18 09:03:16 -08001967static int
1968qla2x00_iospace_config(struct qla_hw_data *ha)
1969{
1970 resource_size_t pio;
1971 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001972
Giridhar Malavali706f4572011-11-18 09:03:16 -08001973 if (pci_request_selected_regions(ha->pdev, ha->bars,
1974 QLA2XXX_DRIVER_NAME)) {
1975 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1976 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1977 pci_name(ha->pdev));
1978 goto iospace_error_exit;
1979 }
1980 if (!(ha->bars & 1))
1981 goto skip_pio;
1982
1983 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1984 pio = pci_resource_start(ha->pdev, 0);
1985 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1986 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1987 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1988 "Invalid pci I/O region size (%s).\n",
1989 pci_name(ha->pdev));
1990 pio = 0;
1991 }
1992 } else {
1993 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1994 "Region #0 no a PIO resource (%s).\n",
1995 pci_name(ha->pdev));
1996 pio = 0;
1997 }
1998 ha->pio_address = pio;
1999 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2000 "PIO address=%llu.\n",
2001 (unsigned long long)ha->pio_address);
2002
2003skip_pio:
2004 /* Use MMIO operations for all accesses. */
2005 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2006 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2007 "Region #1 not an MMIO resource (%s), aborting.\n",
2008 pci_name(ha->pdev));
2009 goto iospace_error_exit;
2010 }
2011 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2012 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2013 "Invalid PCI mem region size (%s), aborting.\n",
2014 pci_name(ha->pdev));
2015 goto iospace_error_exit;
2016 }
2017
2018 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2019 if (!ha->iobase) {
2020 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2021 "Cannot remap MMIO (%s), aborting.\n",
2022 pci_name(ha->pdev));
2023 goto iospace_error_exit;
2024 }
2025
2026 /* Determine queue resources */
2027 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002028 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002029 if (!ql2xmqsupport || !ql2xnvmeenable ||
2030 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002031 goto mqiobase_exit;
2032
2033 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2034 pci_resource_len(ha->pdev, 3));
2035 if (ha->mqiobase) {
2036 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2037 "MQIO Base=%p.\n", ha->mqiobase);
2038 /* Read MSIX vector size of the board */
2039 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002040 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002041 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002042 /* MB interrupt uses 1 vector */
2043 ha->max_req_queues = ha->msix_count - 1;
2044 ha->max_rsp_queues = ha->max_req_queues;
2045 /* Queue pairs is the max value minus the base queue pair */
2046 ha->max_qpairs = ha->max_rsp_queues - 1;
2047 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2048 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2049
Giridhar Malavali706f4572011-11-18 09:03:16 -08002050 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002051 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002052 } else
2053 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2054 "BAR 3 not enabled.\n");
2055
2056mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002057 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002058 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002059 return (0);
2060
2061iospace_error_exit:
2062 return (-ENOMEM);
2063}
2064
2065
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002066static int
2067qla83xx_iospace_config(struct qla_hw_data *ha)
2068{
2069 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002070
2071 if (pci_request_selected_regions(ha->pdev, ha->bars,
2072 QLA2XXX_DRIVER_NAME)) {
2073 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2074 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2075 pci_name(ha->pdev));
2076
2077 goto iospace_error_exit;
2078 }
2079
2080 /* Use MMIO operations for all accesses. */
2081 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2082 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2083 "Invalid pci I/O region size (%s).\n",
2084 pci_name(ha->pdev));
2085 goto iospace_error_exit;
2086 }
2087 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2088 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2089 "Invalid PCI mem region size (%s), aborting\n",
2090 pci_name(ha->pdev));
2091 goto iospace_error_exit;
2092 }
2093
2094 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2095 if (!ha->iobase) {
2096 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2097 "Cannot remap MMIO (%s), aborting.\n",
2098 pci_name(ha->pdev));
2099 goto iospace_error_exit;
2100 }
2101
2102 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2103 /* 83XX 26XX always use MQ type access for queues
2104 * - mbar 2, a.k.a region 4 */
2105 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002106 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002107 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2108 pci_resource_len(ha->pdev, 4));
2109
2110 if (!ha->mqiobase) {
2111 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2112 "BAR2/region4 not enabled\n");
2113 goto mqiobase_exit;
2114 }
2115
2116 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2117 pci_resource_len(ha->pdev, 2));
2118 if (ha->msixbase) {
2119 /* Read MSIX vector size of the board */
2120 pci_read_config_word(ha->pdev,
2121 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002122 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002123 /*
2124 * By default, driver uses at least two msix vectors
2125 * (default & rspq)
2126 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002127 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002128 /* MB interrupt uses 1 vector */
2129 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002130
2131 /* ATIOQ needs 1 vector. That's 1 less QPair */
2132 if (QLA_TGT_MODE_ENABLED())
2133 ha->max_req_queues--;
2134
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002135 ha->max_rsp_queues = ha->max_req_queues;
2136
Michael Hernandezd7459522016-12-12 14:40:07 -08002137 /* Queue pairs is the max value minus
2138 * the base queue pair */
2139 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002140 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002141 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002142 }
2143 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002144 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002145 } else
2146 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2147 "BAR 1 not enabled.\n");
2148
2149mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002150 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002151 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002152 return 0;
2153
2154iospace_error_exit:
2155 return -ENOMEM;
2156}
2157
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002158static struct isp_operations qla2100_isp_ops = {
2159 .pci_config = qla2100_pci_config,
2160 .reset_chip = qla2x00_reset_chip,
2161 .chip_diag = qla2x00_chip_diag,
2162 .config_rings = qla2x00_config_rings,
2163 .reset_adapter = qla2x00_reset_adapter,
2164 .nvram_config = qla2x00_nvram_config,
2165 .update_fw_options = qla2x00_update_fw_options,
2166 .load_risc = qla2x00_load_risc,
2167 .pci_info_str = qla2x00_pci_info_str,
2168 .fw_version_str = qla2x00_fw_version_str,
2169 .intr_handler = qla2100_intr_handler,
2170 .enable_intrs = qla2x00_enable_intrs,
2171 .disable_intrs = qla2x00_disable_intrs,
2172 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002173 .target_reset = qla2x00_abort_target,
2174 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002175 .fabric_login = qla2x00_login_fabric,
2176 .fabric_logout = qla2x00_fabric_logout,
2177 .calc_req_entries = qla2x00_calc_iocbs_32,
2178 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2179 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2180 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2181 .read_nvram = qla2x00_read_nvram_data,
2182 .write_nvram = qla2x00_write_nvram_data,
2183 .fw_dump = qla2100_fw_dump,
2184 .beacon_on = NULL,
2185 .beacon_off = NULL,
2186 .beacon_blink = NULL,
2187 .read_optrom = qla2x00_read_optrom_data,
2188 .write_optrom = qla2x00_write_optrom_data,
2189 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002191 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002192 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002193 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002194 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002195};
2196
2197static struct isp_operations qla2300_isp_ops = {
2198 .pci_config = qla2300_pci_config,
2199 .reset_chip = qla2x00_reset_chip,
2200 .chip_diag = qla2x00_chip_diag,
2201 .config_rings = qla2x00_config_rings,
2202 .reset_adapter = qla2x00_reset_adapter,
2203 .nvram_config = qla2x00_nvram_config,
2204 .update_fw_options = qla2x00_update_fw_options,
2205 .load_risc = qla2x00_load_risc,
2206 .pci_info_str = qla2x00_pci_info_str,
2207 .fw_version_str = qla2x00_fw_version_str,
2208 .intr_handler = qla2300_intr_handler,
2209 .enable_intrs = qla2x00_enable_intrs,
2210 .disable_intrs = qla2x00_disable_intrs,
2211 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002212 .target_reset = qla2x00_abort_target,
2213 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002214 .fabric_login = qla2x00_login_fabric,
2215 .fabric_logout = qla2x00_fabric_logout,
2216 .calc_req_entries = qla2x00_calc_iocbs_32,
2217 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2218 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2219 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2220 .read_nvram = qla2x00_read_nvram_data,
2221 .write_nvram = qla2x00_write_nvram_data,
2222 .fw_dump = qla2300_fw_dump,
2223 .beacon_on = qla2x00_beacon_on,
2224 .beacon_off = qla2x00_beacon_off,
2225 .beacon_blink = qla2x00_beacon_blink,
2226 .read_optrom = qla2x00_read_optrom_data,
2227 .write_optrom = qla2x00_write_optrom_data,
2228 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002230 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002231 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002232 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002233 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002234};
2235
2236static struct isp_operations qla24xx_isp_ops = {
2237 .pci_config = qla24xx_pci_config,
2238 .reset_chip = qla24xx_reset_chip,
2239 .chip_diag = qla24xx_chip_diag,
2240 .config_rings = qla24xx_config_rings,
2241 .reset_adapter = qla24xx_reset_adapter,
2242 .nvram_config = qla24xx_nvram_config,
2243 .update_fw_options = qla24xx_update_fw_options,
2244 .load_risc = qla24xx_load_risc,
2245 .pci_info_str = qla24xx_pci_info_str,
2246 .fw_version_str = qla24xx_fw_version_str,
2247 .intr_handler = qla24xx_intr_handler,
2248 .enable_intrs = qla24xx_enable_intrs,
2249 .disable_intrs = qla24xx_disable_intrs,
2250 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002251 .target_reset = qla24xx_abort_target,
2252 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002253 .fabric_login = qla24xx_login_fabric,
2254 .fabric_logout = qla24xx_fabric_logout,
2255 .calc_req_entries = NULL,
2256 .build_iocbs = NULL,
2257 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2258 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2259 .read_nvram = qla24xx_read_nvram_data,
2260 .write_nvram = qla24xx_write_nvram_data,
2261 .fw_dump = qla24xx_fw_dump,
2262 .beacon_on = qla24xx_beacon_on,
2263 .beacon_off = qla24xx_beacon_off,
2264 .beacon_blink = qla24xx_beacon_blink,
2265 .read_optrom = qla24xx_read_optrom_data,
2266 .write_optrom = qla24xx_write_optrom_data,
2267 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002269 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002270 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002271 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002272 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002273};
2274
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002275static struct isp_operations qla25xx_isp_ops = {
2276 .pci_config = qla25xx_pci_config,
2277 .reset_chip = qla24xx_reset_chip,
2278 .chip_diag = qla24xx_chip_diag,
2279 .config_rings = qla24xx_config_rings,
2280 .reset_adapter = qla24xx_reset_adapter,
2281 .nvram_config = qla24xx_nvram_config,
2282 .update_fw_options = qla24xx_update_fw_options,
2283 .load_risc = qla24xx_load_risc,
2284 .pci_info_str = qla24xx_pci_info_str,
2285 .fw_version_str = qla24xx_fw_version_str,
2286 .intr_handler = qla24xx_intr_handler,
2287 .enable_intrs = qla24xx_enable_intrs,
2288 .disable_intrs = qla24xx_disable_intrs,
2289 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002290 .target_reset = qla24xx_abort_target,
2291 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002292 .fabric_login = qla24xx_login_fabric,
2293 .fabric_logout = qla24xx_fabric_logout,
2294 .calc_req_entries = NULL,
2295 .build_iocbs = NULL,
2296 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2297 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2298 .read_nvram = qla25xx_read_nvram_data,
2299 .write_nvram = qla25xx_write_nvram_data,
2300 .fw_dump = qla25xx_fw_dump,
2301 .beacon_on = qla24xx_beacon_on,
2302 .beacon_off = qla24xx_beacon_off,
2303 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002304 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002305 .write_optrom = qla24xx_write_optrom_data,
2306 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002307 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002308 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002309 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002310 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002311 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002312};
2313
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002314static struct isp_operations qla81xx_isp_ops = {
2315 .pci_config = qla25xx_pci_config,
2316 .reset_chip = qla24xx_reset_chip,
2317 .chip_diag = qla24xx_chip_diag,
2318 .config_rings = qla24xx_config_rings,
2319 .reset_adapter = qla24xx_reset_adapter,
2320 .nvram_config = qla81xx_nvram_config,
2321 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002322 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002323 .pci_info_str = qla24xx_pci_info_str,
2324 .fw_version_str = qla24xx_fw_version_str,
2325 .intr_handler = qla24xx_intr_handler,
2326 .enable_intrs = qla24xx_enable_intrs,
2327 .disable_intrs = qla24xx_disable_intrs,
2328 .abort_command = qla24xx_abort_command,
2329 .target_reset = qla24xx_abort_target,
2330 .lun_reset = qla24xx_lun_reset,
2331 .fabric_login = qla24xx_login_fabric,
2332 .fabric_logout = qla24xx_fabric_logout,
2333 .calc_req_entries = NULL,
2334 .build_iocbs = NULL,
2335 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2336 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002337 .read_nvram = NULL,
2338 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002339 .fw_dump = qla81xx_fw_dump,
2340 .beacon_on = qla24xx_beacon_on,
2341 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002342 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002343 .read_optrom = qla25xx_read_optrom_data,
2344 .write_optrom = qla24xx_write_optrom_data,
2345 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002346 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002347 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002348 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002349 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002350 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002351};
2352
2353static struct isp_operations qla82xx_isp_ops = {
2354 .pci_config = qla82xx_pci_config,
2355 .reset_chip = qla82xx_reset_chip,
2356 .chip_diag = qla24xx_chip_diag,
2357 .config_rings = qla82xx_config_rings,
2358 .reset_adapter = qla24xx_reset_adapter,
2359 .nvram_config = qla81xx_nvram_config,
2360 .update_fw_options = qla24xx_update_fw_options,
2361 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002362 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002363 .fw_version_str = qla24xx_fw_version_str,
2364 .intr_handler = qla82xx_intr_handler,
2365 .enable_intrs = qla82xx_enable_intrs,
2366 .disable_intrs = qla82xx_disable_intrs,
2367 .abort_command = qla24xx_abort_command,
2368 .target_reset = qla24xx_abort_target,
2369 .lun_reset = qla24xx_lun_reset,
2370 .fabric_login = qla24xx_login_fabric,
2371 .fabric_logout = qla24xx_fabric_logout,
2372 .calc_req_entries = NULL,
2373 .build_iocbs = NULL,
2374 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2375 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2376 .read_nvram = qla24xx_read_nvram_data,
2377 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002378 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002379 .beacon_on = qla82xx_beacon_on,
2380 .beacon_off = qla82xx_beacon_off,
2381 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002382 .read_optrom = qla82xx_read_optrom_data,
2383 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002384 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002385 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002386 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002387 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002388 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002389 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002390};
2391
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002392static struct isp_operations qla8044_isp_ops = {
2393 .pci_config = qla82xx_pci_config,
2394 .reset_chip = qla82xx_reset_chip,
2395 .chip_diag = qla24xx_chip_diag,
2396 .config_rings = qla82xx_config_rings,
2397 .reset_adapter = qla24xx_reset_adapter,
2398 .nvram_config = qla81xx_nvram_config,
2399 .update_fw_options = qla24xx_update_fw_options,
2400 .load_risc = qla82xx_load_risc,
2401 .pci_info_str = qla24xx_pci_info_str,
2402 .fw_version_str = qla24xx_fw_version_str,
2403 .intr_handler = qla8044_intr_handler,
2404 .enable_intrs = qla82xx_enable_intrs,
2405 .disable_intrs = qla82xx_disable_intrs,
2406 .abort_command = qla24xx_abort_command,
2407 .target_reset = qla24xx_abort_target,
2408 .lun_reset = qla24xx_lun_reset,
2409 .fabric_login = qla24xx_login_fabric,
2410 .fabric_logout = qla24xx_fabric_logout,
2411 .calc_req_entries = NULL,
2412 .build_iocbs = NULL,
2413 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2414 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2415 .read_nvram = NULL,
2416 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002417 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002418 .beacon_on = qla82xx_beacon_on,
2419 .beacon_off = qla82xx_beacon_off,
2420 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002421 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002422 .write_optrom = qla8044_write_optrom_data,
2423 .get_flash_version = qla82xx_get_flash_version,
2424 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002425 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002426 .abort_isp = qla8044_abort_isp,
2427 .iospace_config = qla82xx_iospace_config,
2428 .initialize_adapter = qla2x00_initialize_adapter,
2429};
2430
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002431static struct isp_operations qla83xx_isp_ops = {
2432 .pci_config = qla25xx_pci_config,
2433 .reset_chip = qla24xx_reset_chip,
2434 .chip_diag = qla24xx_chip_diag,
2435 .config_rings = qla24xx_config_rings,
2436 .reset_adapter = qla24xx_reset_adapter,
2437 .nvram_config = qla81xx_nvram_config,
2438 .update_fw_options = qla81xx_update_fw_options,
2439 .load_risc = qla81xx_load_risc,
2440 .pci_info_str = qla24xx_pci_info_str,
2441 .fw_version_str = qla24xx_fw_version_str,
2442 .intr_handler = qla24xx_intr_handler,
2443 .enable_intrs = qla24xx_enable_intrs,
2444 .disable_intrs = qla24xx_disable_intrs,
2445 .abort_command = qla24xx_abort_command,
2446 .target_reset = qla24xx_abort_target,
2447 .lun_reset = qla24xx_lun_reset,
2448 .fabric_login = qla24xx_login_fabric,
2449 .fabric_logout = qla24xx_fabric_logout,
2450 .calc_req_entries = NULL,
2451 .build_iocbs = NULL,
2452 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2453 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2454 .read_nvram = NULL,
2455 .write_nvram = NULL,
2456 .fw_dump = qla83xx_fw_dump,
2457 .beacon_on = qla24xx_beacon_on,
2458 .beacon_off = qla24xx_beacon_off,
2459 .beacon_blink = qla83xx_beacon_blink,
2460 .read_optrom = qla25xx_read_optrom_data,
2461 .write_optrom = qla24xx_write_optrom_data,
2462 .get_flash_version = qla24xx_get_flash_version,
2463 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002464 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002465 .abort_isp = qla2x00_abort_isp,
2466 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002467 .initialize_adapter = qla2x00_initialize_adapter,
2468};
2469
2470static struct isp_operations qlafx00_isp_ops = {
2471 .pci_config = qlafx00_pci_config,
2472 .reset_chip = qlafx00_soft_reset,
2473 .chip_diag = qlafx00_chip_diag,
2474 .config_rings = qlafx00_config_rings,
2475 .reset_adapter = qlafx00_soft_reset,
2476 .nvram_config = NULL,
2477 .update_fw_options = NULL,
2478 .load_risc = NULL,
2479 .pci_info_str = qlafx00_pci_info_str,
2480 .fw_version_str = qlafx00_fw_version_str,
2481 .intr_handler = qlafx00_intr_handler,
2482 .enable_intrs = qlafx00_enable_intrs,
2483 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002484 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002485 .target_reset = qlafx00_abort_target,
2486 .lun_reset = qlafx00_lun_reset,
2487 .fabric_login = NULL,
2488 .fabric_logout = NULL,
2489 .calc_req_entries = NULL,
2490 .build_iocbs = NULL,
2491 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2492 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2493 .read_nvram = qla24xx_read_nvram_data,
2494 .write_nvram = qla24xx_write_nvram_data,
2495 .fw_dump = NULL,
2496 .beacon_on = qla24xx_beacon_on,
2497 .beacon_off = qla24xx_beacon_off,
2498 .beacon_blink = NULL,
2499 .read_optrom = qla24xx_read_optrom_data,
2500 .write_optrom = qla24xx_write_optrom_data,
2501 .get_flash_version = qla24xx_get_flash_version,
2502 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002503 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002504 .abort_isp = qlafx00_abort_isp,
2505 .iospace_config = qlafx00_iospace_config,
2506 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002507};
2508
Chad Dupuisf73cb692014-02-26 04:15:06 -05002509static struct isp_operations qla27xx_isp_ops = {
2510 .pci_config = qla25xx_pci_config,
2511 .reset_chip = qla24xx_reset_chip,
2512 .chip_diag = qla24xx_chip_diag,
2513 .config_rings = qla24xx_config_rings,
2514 .reset_adapter = qla24xx_reset_adapter,
2515 .nvram_config = qla81xx_nvram_config,
2516 .update_fw_options = qla81xx_update_fw_options,
2517 .load_risc = qla81xx_load_risc,
2518 .pci_info_str = qla24xx_pci_info_str,
2519 .fw_version_str = qla24xx_fw_version_str,
2520 .intr_handler = qla24xx_intr_handler,
2521 .enable_intrs = qla24xx_enable_intrs,
2522 .disable_intrs = qla24xx_disable_intrs,
2523 .abort_command = qla24xx_abort_command,
2524 .target_reset = qla24xx_abort_target,
2525 .lun_reset = qla24xx_lun_reset,
2526 .fabric_login = qla24xx_login_fabric,
2527 .fabric_logout = qla24xx_fabric_logout,
2528 .calc_req_entries = NULL,
2529 .build_iocbs = NULL,
2530 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2531 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2532 .read_nvram = NULL,
2533 .write_nvram = NULL,
2534 .fw_dump = qla27xx_fwdump,
2535 .beacon_on = qla24xx_beacon_on,
2536 .beacon_off = qla24xx_beacon_off,
2537 .beacon_blink = qla83xx_beacon_blink,
2538 .read_optrom = qla25xx_read_optrom_data,
2539 .write_optrom = qla24xx_write_optrom_data,
2540 .get_flash_version = qla24xx_get_flash_version,
2541 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002542 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002543 .abort_isp = qla2x00_abort_isp,
2544 .iospace_config = qla83xx_iospace_config,
2545 .initialize_adapter = qla2x00_initialize_adapter,
2546};
2547
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002548static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002550{
2551 ha->device_type = DT_EXTENDED_IDS;
2552 switch (ha->pdev->device) {
2553 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002554 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002555 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002556 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002557 break;
2558 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002559 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002560 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002561 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002562 break;
2563 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002564 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002565 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002566 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002567 break;
2568 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002569 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002570 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002571 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002572 break;
2573 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002574 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002575 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002576 if (ha->pdev->subsystem_vendor == 0x1028 &&
2577 ha->pdev->subsystem_device == 0x0170)
2578 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002579 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002580 break;
2581 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002582 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002583 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002584 break;
2585 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002586 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002587 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002588 break;
2589 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002590 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002591 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002592 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002593 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002594 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002595 break;
2596 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002597 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002598 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002599 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002600 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002601 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002602 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002603 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002604 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002605 ha->device_type |= DT_ZIO_SUPPORTED;
2606 ha->device_type |= DT_FWI2;
2607 ha->device_type |= DT_IIDMA;
2608 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2609 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002610 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002611 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002612 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002613 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002614 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002615 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002616 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002617 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002618 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002619 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002620 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002621 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002622 ha->device_type |= DT_ZIO_SUPPORTED;
2623 ha->device_type |= DT_FWI2;
2624 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002625 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2626 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002627 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002628 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002629 ha->device_type |= DT_ZIO_SUPPORTED;
2630 ha->device_type |= DT_FWI2;
2631 ha->device_type |= DT_IIDMA;
2632 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2633 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002634 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002635 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002636 ha->device_type |= DT_ZIO_SUPPORTED;
2637 ha->device_type |= DT_FWI2;
2638 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2639 /* Initialize 82XX ISP flags */
2640 qla82xx_init_flags(ha);
2641 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002642 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002643 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002644 ha->device_type |= DT_ZIO_SUPPORTED;
2645 ha->device_type |= DT_FWI2;
2646 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2647 /* Initialize 82XX ISP flags */
2648 qla82xx_init_flags(ha);
2649 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002650 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002651 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002652 ha->device_type |= DT_ZIO_SUPPORTED;
2653 ha->device_type |= DT_FWI2;
2654 ha->device_type |= DT_IIDMA;
2655 ha->device_type |= DT_T10_PI;
2656 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2657 break;
2658 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002659 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002660 ha->device_type |= DT_ZIO_SUPPORTED;
2661 ha->device_type |= DT_FWI2;
2662 ha->device_type |= DT_IIDMA;
2663 ha->device_type |= DT_T10_PI;
2664 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2665 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002666 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002667 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002668 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002669 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002670 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002671 ha->device_type |= DT_ZIO_SUPPORTED;
2672 ha->device_type |= DT_FWI2;
2673 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002674 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002675 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2676 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002677 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002678 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002679 ha->device_type |= DT_ZIO_SUPPORTED;
2680 ha->device_type |= DT_FWI2;
2681 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002682 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002683 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2684 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002685 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002686 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002687 ha->device_type |= DT_ZIO_SUPPORTED;
2688 ha->device_type |= DT_FWI2;
2689 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002690 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002691 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2692 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002693 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002694
Giridhar Malavalia9083012010-04-12 17:59:55 -07002695 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002696 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002697 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002698 /* Get adapter physical port no from interrupt pin register. */
2699 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002700 if (IS_QLA27XX(ha))
2701 ha->port_no--;
2702 else
2703 ha->port_no = !(ha->port_no & 1);
2704 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002705
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002706 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002707 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002708 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002709}
2710
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002711static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002712qla2xxx_scan_start(struct Scsi_Host *shost)
2713{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002715
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002716 if (vha->hw->flags.running_gold_fw)
2717 return;
2718
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2720 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2721 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2722 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002723}
2724
2725static int
2726qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2727{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002728 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002729
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002730 if (test_bit(UNLOADING, &vha->dpc_flags))
2731 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002733 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002735 return 1;
2736
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002737 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002738}
2739
Quinn Tranec7193e2017-03-15 09:48:55 -07002740static void qla2x00_iocb_work_fn(struct work_struct *work)
2741{
2742 struct scsi_qla_host *vha = container_of(work,
2743 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002744 struct qla_hw_data *ha = vha->hw;
2745 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002746 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002747 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002748
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002749 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2750 return;
2751
2752 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002753 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002754 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002755 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002756
2757 spin_lock_irqsave(&vha->work_lock, flags);
2758 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2759 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002760}
2761
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762/*
2763 * PCI driver interface
2764 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002765static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002766qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002768 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 scsi_qla_host_t *base_vha = NULL;
2771 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002772 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002773 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002774 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002775 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002777 struct req_que *req = NULL;
2778 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002779 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002780
Andrew Vasquez285d0322007-10-19 15:59:17 -07002781 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002782 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002783 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2784 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002785 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002786 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2787 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002788 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002789 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002790 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2791 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002792 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002793 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002794 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002795 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002796 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2797 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002798 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002799 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002800 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2801 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002802 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002803 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2804 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002805
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002806 if (mem_only) {
2807 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002808 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002809 } else {
2810 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002811 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
Jesse Barnes09276782008-10-18 17:33:19 -07002814 /* This may fail but that's ok */
2815 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2818 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002819 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2820 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002821 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2824 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002825 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002826 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2827 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002828 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002829 spin_lock_init(&ha->tgt.atio_lock);
2830
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002831 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
2833 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002834 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002835 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002836 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002837 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002838 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002839 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002841 /* Set ISP-type information. */
2842 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002843
2844 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002845 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002846 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002847 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002848
Chad Dupuiscba1e472011-11-18 09:03:21 -08002849 ha->prev_topology = 0;
2850 ha->init_cb_size = sizeof(init_cb_t);
2851 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2852 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002853 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002854 atomic_set(&ha->num_pend_mbx_stage1, 0);
2855 atomic_set(&ha->num_pend_mbx_stage2, 0);
2856 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002857 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2858 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002859
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002860 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002862 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 req_length = REQUEST_ENTRY_CNT_2100;
2865 rsp_length = RESPONSE_ENTRY_CNT_2100;
2866 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002867 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002868 ha->flash_conf_off = ~0;
2869 ha->flash_data_off = ~0;
2870 ha->nvram_conf_off = ~0;
2871 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002872 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002874 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002875 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 req_length = REQUEST_ENTRY_CNT_2200;
2877 rsp_length = RESPONSE_ENTRY_CNT_2100;
2878 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002879 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002880 ha->flash_conf_off = ~0;
2881 ha->flash_data_off = ~0;
2882 ha->nvram_conf_off = ~0;
2883 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002884 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002885 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002886 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002888 req_length = REQUEST_ENTRY_CNT_2200;
2889 rsp_length = RESPONSE_ENTRY_CNT_2300;
2890 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002891 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002892 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2893 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002894 ha->flash_conf_off = ~0;
2895 ha->flash_data_off = ~0;
2896 ha->nvram_conf_off = ~0;
2897 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002898 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002899 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002900 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002901 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902 req_length = REQUEST_ENTRY_CNT_24XX;
2903 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002904 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002906 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002907 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002908 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002909 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002910 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002911 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2912 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2913 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2914 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002915 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002916 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002917 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 req_length = REQUEST_ENTRY_CNT_24XX;
2919 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002920 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002922 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002923 ha->gid_list_info_size = 8;
2924 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002925 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002926 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002927 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2928 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2929 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2930 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2931 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002932 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002933 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2934 req_length = REQUEST_ENTRY_CNT_24XX;
2935 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002936 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002937 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2938 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2939 ha->gid_list_info_size = 8;
2940 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002941 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002942 ha->isp_ops = &qla81xx_isp_ops;
2943 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2944 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2945 ha->nvram_conf_off = ~0;
2946 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002947 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002948 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002949 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2950 req_length = REQUEST_ENTRY_CNT_82XX;
2951 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2952 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2953 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2954 ha->gid_list_info_size = 8;
2955 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002956 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002957 ha->isp_ops = &qla82xx_isp_ops;
2958 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2959 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2960 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2961 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002962 } else if (IS_QLA8044(ha)) {
2963 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2964 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2965 req_length = REQUEST_ENTRY_CNT_82XX;
2966 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2967 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2968 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2969 ha->gid_list_info_size = 8;
2970 ha->optrom_size = OPTROM_SIZE_83XX;
2971 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2972 ha->isp_ops = &qla8044_isp_ops;
2973 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2974 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2975 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2976 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002977 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002978 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002979 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002980 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002981 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002982 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002983 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002984 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2985 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2986 ha->gid_list_info_size = 8;
2987 ha->optrom_size = OPTROM_SIZE_83XX;
2988 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2989 ha->isp_ops = &qla83xx_isp_ops;
2990 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2991 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2992 ha->nvram_conf_off = ~0;
2993 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002994 } else if (IS_QLAFX00(ha)) {
2995 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2996 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2997 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2998 req_length = REQUEST_ENTRY_CNT_FX00;
2999 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003000 ha->isp_ops = &qlafx00_isp_ops;
3001 ha->port_down_retry_count = 30; /* default value */
3002 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3003 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003004 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003005 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003006 ha->mr.host_info_resend = false;
3007 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003008 } else if (IS_QLA27XX(ha)) {
3009 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3010 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3011 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003012 req_length = REQUEST_ENTRY_CNT_83XX;
3013 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003014 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003015 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3016 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3017 ha->gid_list_info_size = 8;
3018 ha->optrom_size = OPTROM_SIZE_83XX;
3019 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3020 ha->isp_ops = &qla27xx_isp_ops;
3021 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3022 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3023 ha->nvram_conf_off = ~0;
3024 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003026
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003027 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3028 "mbx_count=%d, req_length=%d, "
3029 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003030 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3031 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003032 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3033 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003034 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003035 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3036 "isp_ops=%p, flash_conf_off=%d, "
3037 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3038 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3039 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003040
3041 /* Configure PCI I/O space */
3042 ret = ha->isp_ops->iospace_config(ha);
3043 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003044 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003045
3046 ql_log_pci(ql_log_info, pdev, 0x001d,
3047 "Found an ISP%04X irq %d iobase 0x%p.\n",
3048 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003049 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003050 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003051 init_completion(&ha->mbx_cmd_comp);
3052 complete(&ha->mbx_cmd_comp);
3053 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003054 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003055 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003057 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Andrew Vasquez53303c42009-01-22 09:45:37 -08003059 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003060 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3061 "64 Bit addressing is %s.\n",
3062 ha->flags.enable_64bit_addressing ? "enable" :
3063 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003064 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003065 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003066 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3067 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003069 goto probe_hw_failed;
3070 }
3071
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003072 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003074 req->max_q_depth = ql2xmaxqdepth;
3075
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076
3077 base_vha = qla2x00_create_host(sht, ha);
3078 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003079 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 }
3082
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003083 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003084 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003086 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003087 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003088 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003089 base_vha->mgmt_svr_loop_id =
3090 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003091 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003092 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3093 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003094
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003095 /* Setup fcport template structure. */
3096 ha->mr.fcport.vha = base_vha;
3097 ha->mr.fcport.port_type = FCT_UNKNOWN;
3098 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3099 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3100 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3101 ha->mr.fcport.scan_state = 1;
3102
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003103 /* Set the SG table size based on ISP type */
3104 if (!IS_FWI2_CAPABLE(ha)) {
3105 if (IS_QLA2100(ha))
3106 host->sg_tablesize = 32;
3107 } else {
3108 if (!IS_QLA82XX(ha))
3109 host->sg_tablesize = QLA_SG_ALL;
3110 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003111 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003112 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003113 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003114 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003115 host->max_cmd_len = 32;
3116 else
3117 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003118 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003119 /* Older HBAs support only 16-bit LUNs */
3120 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3121 ql2xmaxlun > 0xffff)
3122 host->max_lun = 0xffff;
3123 else
3124 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003125 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003126 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003127
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003128 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3129 "max_id=%d this_id=%d "
3130 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003131 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003132 host->this_id, host->cmd_per_lun, host->unique_id,
3133 host->max_cmd_len, host->max_channel, host->max_lun,
3134 host->transportt, sht->vendor_id);
3135
Himanshu Madhani1010f212017-10-16 11:26:05 -07003136 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3137
Michael Hernandezd7459522016-12-12 14:40:07 -08003138 /* Set up the irqs */
3139 ret = qla2x00_request_irqs(ha, rsp);
3140 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003141 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003142
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003143 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003144 ret = qla2x00_alloc_queues(ha, req, rsp);
3145 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003146 ql_log(ql_log_fatal, base_vha, 0x003d,
3147 "Failed to allocate memory for queue pointers..."
3148 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003149 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003150 }
3151
Jens Axboef664a3c2018-11-01 16:36:27 -06003152 if (ha->mqenable) {
Michael Hernandez56012362016-12-12 14:40:08 -08003153 /* number of hardware queues supported by blk/scsi-mq*/
3154 host->nr_hw_queues = ha->max_qpairs;
3155
3156 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3157 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003158 } else {
3159 if (ql2xnvmeenable) {
3160 host->nr_hw_queues = ha->max_qpairs;
3161 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3162 "FC-NVMe support is enabled, HW queues=%d\n",
3163 host->nr_hw_queues);
3164 } else {
3165 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3166 "blk/scsi-mq disabled.\n");
3167 }
3168 }
Michael Hernandez56012362016-12-12 14:40:08 -08003169
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003170 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003171
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003172 pci_save_state(pdev);
3173
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003174 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003175 rsp->req = req;
3176 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003177
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003178 if (IS_QLAFX00(ha)) {
3179 ha->rsp_q_map[0] = rsp;
3180 ha->req_q_map[0] = req;
3181 set_bit(0, ha->req_qid_map);
3182 set_bit(0, ha->rsp_qid_map);
3183 }
3184
Andrew Vasquez08029992009-03-24 09:07:55 -07003185 /* FWI2-capable only. */
3186 req->req_q_in = &ha->iobase->isp24.req_q_in;
3187 req->req_q_out = &ha->iobase->isp24.req_q_out;
3188 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3189 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003190 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003191 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3192 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3193 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3194 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003195 }
3196
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003197 if (IS_QLAFX00(ha)) {
3198 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3199 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3200 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3201 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3202 }
3203
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003204 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003205 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3206 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3207 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3208 }
3209
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003210 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3211 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3212 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3213 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3214 "req->req_q_in=%p req->req_q_out=%p "
3215 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3216 req->req_q_in, req->req_q_out,
3217 rsp->rsp_q_in, rsp->rsp_q_out);
3218 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3219 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3220 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3221 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3222 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3223 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003225 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3226
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003227 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_log(ql_log_fatal, base_vha, 0x00d6,
3229 "Failed to initialize adapter - Adapter flags %x.\n",
3230 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231
Giridhar Malavalia9083012010-04-12 17:59:55 -07003232 if (IS_QLA82XX(ha)) {
3233 qla82xx_idc_lock(ha);
3234 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003235 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003236 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003237 ql_log(ql_log_fatal, base_vha, 0x00d7,
3238 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003239 } else if (IS_QLA8044(ha)) {
3240 qla8044_idc_lock(ha);
3241 qla8044_wr_direct(base_vha,
3242 QLA8044_CRB_DEV_STATE_INDEX,
3243 QLA8XXX_DEV_FAILED);
3244 qla8044_idc_unlock(ha);
3245 ql_log(ql_log_fatal, base_vha, 0x0150,
3246 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003247 }
3248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 ret = -ENODEV;
3250 goto probe_failed;
3251 }
3252
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003253 if (IS_QLAFX00(ha))
3254 host->can_queue = QLAFX00_MAX_CANQUEUE;
3255 else
3256 host->can_queue = req->num_outstanding_cmds - 10;
3257
3258 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3259 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3260 host->can_queue, base_vha->req,
3261 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3262
Quinn Trane326d222017-06-13 20:47:18 -07003263 if (ha->mqenable) {
Quinn Trane326d222017-06-13 20:47:18 -07003264 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003265
Jens Axboef664a3c2018-11-01 16:36:27 -06003266 if (QLA_TGT_MODE_ENABLED())
Quinn Trane326d222017-06-13 20:47:18 -07003267 startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003268
Jens Axboef664a3c2018-11-01 16:36:27 -06003269 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
Quinn Trane326d222017-06-13 20:47:18 -07003270 startit = true;
Quinn Trane326d222017-06-13 20:47:18 -07003271
Jens Axboef664a3c2018-11-01 16:36:27 -06003272 /* Create start of day qpairs for Block MQ */
3273 for (i = 0; i < ha->max_qpairs; i++)
3274 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003275 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003276
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003277 if (ha->flags.running_gold_fw)
3278 goto skip_dpc;
3279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 /*
3281 * Startup the kernel thread for this host adapter
3282 */
3283 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003284 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003286 ql_log(ql_log_fatal, base_vha, 0x00ed,
3287 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003288 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003289 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003290 goto probe_failed;
3291 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003292 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3293 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003295 /*
3296 * If we're not coming up in initiator mode, we might sit for
3297 * a while without waking up the dpc thread, which leads to a
3298 * stuck process warning. So just kick the dpc once here and
3299 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3300 */
3301 qla2xxx_wake_dpc(base_vha);
3302
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003303 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3304
Saurav Kashyap81178772012-08-22 14:21:04 -04003305 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3306 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3307 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3308 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3309
3310 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3311 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3312 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3313 INIT_WORK(&ha->idc_state_handler,
3314 qla83xx_idc_state_handler_work);
3315 INIT_WORK(&ha->nic_core_unrecoverable,
3316 qla83xx_nic_core_unrecoverable_work);
3317 }
3318
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003319skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003320 list_add_tail(&base_vha->list, &ha->vp_list);
3321 base_vha->host->irq = ha->pdev->irq;
3322
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003324 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003325 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3326 "Started qla2x00_timer with "
3327 "interval=%d.\n", WATCH_INTERVAL);
3328 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3329 "Detected hba at address=%p.\n",
3330 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
Arun Easie02587d2011-08-16 11:29:23 -07003332 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003333 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003334 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003335 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003336 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3337 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003338 if (ql2xenabledif == 1)
3339 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003340 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003341 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003342 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003343 | SHOST_DIF_TYPE3_PROTECTION
3344 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003345 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003346 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003347
3348 guard = SHOST_DIX_GUARD_CRC;
3349
3350 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3351 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3352 guard |= SHOST_DIX_GUARD_IP;
3353
3354 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003355 } else
3356 base_vha->flags.difdix_supported = 0;
3357 }
3358
Giridhar Malavalia9083012010-04-12 17:59:55 -07003359 ha->isp_ops->enable_intrs(ha);
3360
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003361 if (IS_QLAFX00(ha)) {
3362 ret = qlafx00_fx_disc(base_vha,
3363 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3364 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3365 QLA_SG_ALL : 128;
3366 }
3367
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003368 ret = scsi_add_host(host, &pdev->dev);
3369 if (ret)
3370 goto probe_failed;
3371
Michael Reed14864002009-12-02 09:11:16 -06003372 base_vha->flags.init_done = 1;
3373 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003374 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003375
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003376 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3377 "Init done and hba is online.\n");
3378
Quinn Tran726b8542017-01-19 22:28:00 -08003379 if (qla_ini_mode_enabled(base_vha) ||
3380 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003381 scsi_scan_host(host);
3382 else
3383 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3384 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003387
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003388 if (IS_QLAFX00(ha)) {
3389 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003390 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3391
3392 /* Register system information */
3393 ret = qlafx00_fx_disc(base_vha,
3394 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3395 }
3396
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003398
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003399 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003400
Armen Baloyan03eb9122013-10-30 03:38:22 -04003401 ql_log(ql_log_info, base_vha, 0x00fb,
3402 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003403 ql_log(ql_log_info, base_vha, 0x00fc,
3404 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3405 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3406 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3407 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003408 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003410 qlt_add_target(ha, base_vha);
3411
Joe Lawrence6b383972014-08-26 17:12:29 -04003412 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003413
3414 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3415 return -ENODEV;
3416
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003417 if (ha->flags.detected_lr_sfp) {
3418 ql_log(ql_log_info, base_vha, 0xffff,
3419 "Reset chip to pick up LR SFP setting\n");
3420 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3421 qla2xxx_wake_dpc(base_vha);
3422 }
3423
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 return 0;
3425
3426probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003427 if (base_vha->timer_active)
3428 qla2x00_stop_timer(base_vha);
3429 base_vha->flags.online = 0;
3430 if (ha->dpc_thread) {
3431 struct task_struct *t = ha->dpc_thread;
3432
3433 ha->dpc_thread = NULL;
3434 kthread_stop(t);
3435 }
3436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003438 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003439 /*
3440 * Need to NULL out local req/rsp after
3441 * qla2x00_free_device => qla2x00_free_queues frees
3442 * what these are pointing to. Or else we'll
3443 * fall over below in qla2x00_free_req/rsp_que.
3444 */
3445 req = NULL;
3446 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003449 qla2x00_mem_free(ha);
3450 qla2x00_free_req_que(ha, req);
3451 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003452 qla2x00_clear_drv_active(ha);
3453
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003454iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003455 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003456 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003457 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003458 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003459 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003460 } else {
3461 if (ha->iobase)
3462 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003463 if (ha->cregbase)
3464 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003465 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003466 pci_release_selected_regions(ha->pdev, ha->bars);
3467 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003469disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003470 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003471 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
Adrian Bunk4c993f72008-01-14 00:55:16 -08003474static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003475qla2x00_shutdown(struct pci_dev *pdev)
3476{
3477 scsi_qla_host_t *vha;
3478 struct qla_hw_data *ha;
3479
3480 vha = pci_get_drvdata(pdev);
3481 ha = vha->hw;
3482
Sawan Chandakefdb5762017-08-23 15:05:00 -07003483 ql_log(ql_log_info, vha, 0xfffa,
3484 "Adapter shutdown\n");
3485
3486 /*
3487 * Prevent future board_disable and wait
3488 * until any pending board_disable has completed.
3489 */
3490 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3491 cancel_work_sync(&ha->board_disable);
3492
3493 if (!atomic_read(&pdev->enable_cnt))
3494 return;
3495
Armen Baloyan42479342013-08-27 01:37:37 -04003496 /* Notify ISPFX00 firmware */
3497 if (IS_QLAFX00(ha))
3498 qlafx00_driver_shutdown(vha, 20);
3499
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003500 /* Turn-off FCE trace */
3501 if (ha->flags.fce_enabled) {
3502 qla2x00_disable_fce_trace(vha, NULL, NULL);
3503 ha->flags.fce_enabled = 0;
3504 }
3505
3506 /* Turn-off EFT trace */
3507 if (ha->eft)
3508 qla2x00_disable_eft_trace(vha);
3509
Quinn Tran3407fc32017-12-28 12:33:11 -08003510 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3511 if (ha->flags.fw_started)
3512 qla2x00_abort_isp_cleanup(vha);
3513 } else {
3514 /* Stop currently executing firmware. */
3515 qla2x00_try_to_stop_firmware(vha);
3516 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003517
3518 /* Turn adapter off line */
3519 vha->flags.online = 0;
3520
3521 /* turn-off interrupts on the card */
3522 if (ha->interrupts_on) {
3523 vha->flags.init_done = 0;
3524 ha->isp_ops->disable_intrs(ha);
3525 }
3526
3527 qla2x00_free_irqs(vha);
3528
3529 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003530
Chad Dupuis61d41f62014-09-25 05:17:02 -04003531 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003532 ql_log(ql_log_info, vha, 0xfffe,
3533 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003534}
3535
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003536/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003537static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003538qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003540 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003541 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542
Arun Easi43ebf162011-05-10 11:18:16 -07003543 mutex_lock(&ha->vport_lock);
3544 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003545 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003546
Arun Easi43ebf162011-05-10 11:18:16 -07003547 BUG_ON(base_vha->list.next == &ha->vp_list);
3548 /* This assumes first entry in ha->vp_list is always base vha */
3549 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003550 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003551
Arun Easi43ebf162011-05-10 11:18:16 -07003552 spin_unlock_irqrestore(&ha->vport_slock, flags);
3553 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003554
Arun Easi43ebf162011-05-10 11:18:16 -07003555 fc_vport_terminate(vha->fc_vport);
3556 scsi_host_put(vha->host);
3557
3558 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559 }
Arun Easi43ebf162011-05-10 11:18:16 -07003560 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003561}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003562
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003563/* Stops all deferred work threads */
3564static void
3565qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3566{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003567 /* Cancel all work and destroy DPC workqueues */
3568 if (ha->dpc_lp_wq) {
3569 cancel_work_sync(&ha->idc_aen);
3570 destroy_workqueue(ha->dpc_lp_wq);
3571 ha->dpc_lp_wq = NULL;
3572 }
3573
3574 if (ha->dpc_hp_wq) {
3575 cancel_work_sync(&ha->nic_core_reset);
3576 cancel_work_sync(&ha->idc_state_handler);
3577 cancel_work_sync(&ha->nic_core_unrecoverable);
3578 destroy_workqueue(ha->dpc_hp_wq);
3579 ha->dpc_hp_wq = NULL;
3580 }
3581
Andrew Vasquezb9978762009-03-24 09:08:05 -07003582 /* Kill the kernel thread for this host */
3583 if (ha->dpc_thread) {
3584 struct task_struct *t = ha->dpc_thread;
3585
3586 /*
3587 * qla2xxx_wake_dpc checks for ->dpc_thread
3588 * so we need to zero it out.
3589 */
3590 ha->dpc_thread = NULL;
3591 kthread_stop(t);
3592 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003593}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003594
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003595static void
3596qla2x00_unmap_iobases(struct qla_hw_data *ha)
3597{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003598 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003599
Chad Dupuisf73cb692014-02-26 04:15:06 -05003600 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003601 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003602 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003603 } else {
3604 if (ha->iobase)
3605 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003606
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003607 if (ha->cregbase)
3608 iounmap(ha->cregbase);
3609
Giridhar Malavalia9083012010-04-12 17:59:55 -07003610 if (ha->mqiobase)
3611 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003612
Chad Dupuisf73cb692014-02-26 04:15:06 -05003613 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003614 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003615 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003616}
3617
3618static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003619qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003620{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003621 if (IS_QLA8044(ha)) {
3622 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003623 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003624 qla8044_idc_unlock(ha);
3625 } else if (IS_QLA82XX(ha)) {
3626 qla82xx_idc_lock(ha);
3627 qla82xx_clear_drv_active(ha);
3628 qla82xx_idc_unlock(ha);
3629 }
3630}
3631
3632static void
3633qla2x00_remove_one(struct pci_dev *pdev)
3634{
3635 scsi_qla_host_t *base_vha;
3636 struct qla_hw_data *ha;
3637
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003638 base_vha = pci_get_drvdata(pdev);
3639 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003640 ql_log(ql_log_info, base_vha, 0xb079,
3641 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003642
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003643 /* Indicate device removal to prevent future board_disable and wait
3644 * until any pending board_disable has completed. */
3645 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3646 cancel_work_sync(&ha->board_disable);
3647
3648 /*
3649 * If the PCI device is disabled then there was a PCI-disconnect and
3650 * qla2x00_disable_board_on_pci_error has taken care of most of the
3651 * resources.
3652 */
3653 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003654 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3655 base_vha->gnl.l, base_vha->gnl.ldma);
3656
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003657 scsi_host_put(base_vha->host);
3658 kfree(ha);
3659 pci_set_drvdata(pdev, NULL);
3660 return;
3661 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003662 qla2x00_wait_for_hba_ready(base_vha);
3663
Quinn Tran45235022018-07-18 14:29:53 -07003664 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3665 if (ha->flags.fw_started)
3666 qla2x00_abort_isp_cleanup(base_vha);
3667 } else if (!IS_QLAFX00(ha)) {
3668 if (IS_QLA8031(ha)) {
3669 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3670 "Clearing fcoe driver presence.\n");
3671 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3672 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3673 "Error while clearing DRV-Presence.\n");
3674 }
3675
3676 qla2x00_try_to_stop_firmware(base_vha);
3677 }
3678
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003679 qla2x00_wait_for_sess_deletion(base_vha);
3680
Quinn Tran726b8542017-01-19 22:28:00 -08003681 /*
3682 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003683 * where it was set first.
3684 */
3685 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3686 return;
3687
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003688 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003689
3690 qla_nvme_delete(base_vha);
3691
Quinn Tran726b8542017-01-19 22:28:00 -08003692 dma_free_coherent(&ha->pdev->dev,
3693 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003694
Quinn Trana4239942017-12-28 12:33:26 -08003695 vfree(base_vha->scan.l);
3696
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003697 if (IS_QLAFX00(ha))
3698 qlafx00_driver_shutdown(base_vha, 20);
3699
3700 qla2x00_delete_all_vps(ha, base_vha);
3701
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003702 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3703
3704 qla2x00_dfs_remove(base_vha);
3705
3706 qla84xx_put_chip(base_vha);
3707
3708 /* Disable timer */
3709 if (base_vha->timer_active)
3710 qla2x00_stop_timer(base_vha);
3711
3712 base_vha->flags.online = 0;
3713
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003714 /* free DMA memory */
3715 if (ha->exlogin_buf)
3716 qla2x00_free_exlogin_buffer(ha);
3717
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003718 /* free DMA memory */
3719 if (ha->exchoffld_buf)
3720 qla2x00_free_exchoffld_buffer(ha);
3721
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003722 qla2x00_destroy_deferred_work(ha);
3723
3724 qlt_remove_target(ha, base_vha);
3725
3726 qla2x00_free_sysfs_attr(base_vha, true);
3727
3728 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003729 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003730
3731 scsi_remove_host(base_vha->host);
3732
3733 qla2x00_free_device(base_vha);
3734
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003735 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003736
Arun Easid2749ff2014-09-25 05:16:51 -04003737 scsi_host_put(base_vha->host);
3738
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003739 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003740
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741 pci_release_selected_regions(ha->pdev, ha->bars);
3742 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003744 pci_disable_pcie_error_reporting(pdev);
3745
Bernhard Walle665db932007-03-28 00:49:49 +02003746 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
3749static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003750qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753
Andrew Vasquez85880802009-12-15 21:29:46 -08003754 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3755
3756 /* Disable timer */
3757 if (vha->timer_active)
3758 qla2x00_stop_timer(vha);
3759
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003760 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003761 vha->flags.online = 0;
3762
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003763 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003764 if (ha->interrupts_on) {
3765 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003766 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003767 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003768
Quinn Tran093df732016-12-12 14:40:09 -08003769 qla2x00_free_fcports(vha);
3770
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003771 qla2x00_free_irqs(vha);
3772
Quinn Tran093df732016-12-12 14:40:09 -08003773 /* Flush the work queue and remove it */
3774 if (ha->wq) {
3775 flush_workqueue(ha->wq);
3776 destroy_workqueue(ha->wq);
3777 ha->wq = NULL;
3778 }
3779
Chad Dupuis88670482010-07-23 15:28:30 +05003780
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003781 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003782
Giridhar Malavali08de2842011-08-16 11:31:44 -07003783 qla82xx_md_free(vha);
3784
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003785 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786}
3787
Chad Dupuis88670482010-07-23 15:28:30 +05003788void qla2x00_free_fcports(struct scsi_qla_host *vha)
3789{
3790 fc_port_t *fcport, *tfcport;
3791
3792 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3793 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003794 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003795 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003796 }
3797}
3798
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003799static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003800qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003801 int defer)
3802{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003803 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003804 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003805 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003806
3807 if (!fcport->rport)
3808 return;
3809
3810 rport = fcport->rport;
3811 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003812 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003813 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003814 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003815 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003816 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003817 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3818 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003819 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003820 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003821 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003822 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3823 "%s %8phN. rport %p roles %x\n",
3824 __func__, fcport->port_name, rport,
3825 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003826 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003827 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003828 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003829 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003830}
3831
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3834 *
3835 * Input: ha = adapter block pointer. fcport = port structure pointer.
3836 *
3837 * Return: None.
3838 *
3839 * Context:
3840 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003842 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003844 if (IS_QLAFX00(vha->hw)) {
3845 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3846 qla2x00_schedule_rport_del(vha, fcport, defer);
3847 return;
3848 }
3849
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003850 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003851 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003852 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003853 qla2x00_schedule_rport_del(vha, fcport, defer);
3854 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003855 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 * We may need to retry the login, so don't change the state of the
3857 * port but do the retries.
3858 */
3859 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003860 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 if (!do_login)
3863 return;
3864
Arun Easia1d02852015-08-04 13:38:02 -04003865 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866}
3867
3868/*
3869 * qla2x00_mark_all_devices_lost
3870 * Updates fcport state when device goes offline.
3871 *
3872 * Input:
3873 * ha = adapter block pointer.
3874 * fcport = port structure pointer.
3875 *
3876 * Return:
3877 * None.
3878 *
3879 * Context:
3880 */
3881void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883{
3884 fc_port_t *fcport;
3885
Quinn Tran83548fe2017-06-02 09:12:01 -07003886 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3887 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003889 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003890 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003891 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003892
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003893 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003895
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 /*
3897 * No point in marking the device as lost, if the device is
3898 * already DEAD.
3899 */
3900 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3901 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003902 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003903 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003904 if (defer)
3905 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003906 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003907 qla2x00_schedule_rport_del(vha, fcport, defer);
3908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 }
3910}
3911
3912/*
3913* qla2x00_mem_alloc
3914* Allocates adapter memory.
3915*
3916* Returns:
3917* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003918* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003920static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003921qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3922 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923{
3924 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925
Andrew Vasqueze8711082008-01-31 12:33:48 -08003926 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003927 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003928 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003929 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003931 if (qlt_mem_alloc(ha) < 0)
3932 goto fail_free_init_cb;
3933
Chad Dupuis642ef982012-02-09 11:15:57 -08003934 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3935 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003936 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003937 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938
Andrew Vasqueze8711082008-01-31 12:33:48 -08003939 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3940 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003941 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003943 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003944 /* Allocate cache for CT6 Ctx. */
3945 if (!ctx_cachep) {
3946 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3947 sizeof(struct ct6_dsd), 0,
3948 SLAB_HWCACHE_ALIGN, NULL);
3949 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003950 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003951 }
3952 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3953 ctx_cachep);
3954 if (!ha->ctx_mempool)
3955 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003956 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3957 "ctx_cachep=%p ctx_mempool=%p.\n",
3958 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003959 }
3960
Andrew Vasqueze8711082008-01-31 12:33:48 -08003961 /* Get memory for cached NVRAM */
3962 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3963 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003964 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3967 ha->pdev->device);
3968 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3969 DMA_POOL_SIZE, 8, 0);
3970 if (!ha->s_dma_pool)
3971 goto fail_free_nvram;
3972
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003973 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3974 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3975 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3976
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003977 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003978 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3979 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3980 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003981 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3982 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003983 goto fail_s_dma_pool;
3984 }
3985
3986 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3987 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3988 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003989 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3990 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003991 goto fail_dl_dma_pool;
3992 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003993 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3994 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3995 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003996 }
3997
Andrew Vasqueze8711082008-01-31 12:33:48 -08003998 /* Allocate memory for SNS commands */
3999 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004000 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004001 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004002 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004003 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004005 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004006 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004007 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004009 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004011 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004012 goto fail_dma_pool;
4013 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004014 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004015 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004016 if (!ha->ct_sns)
4017 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004018 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4019 "ms_iocb=%p ct_sns=%p.\n",
4020 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 }
4022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004023 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004024 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4025 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004026 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4027 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004028 goto fail_req;
4029 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004030 (*req)->length = req_len;
4031 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4032 ((*req)->length + 1) * sizeof(request_t),
4033 &(*req)->dma, GFP_KERNEL);
4034 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004035 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4036 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004037 goto fail_req_ring;
4038 }
4039 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004040 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4041 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004042 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4043 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004044 goto fail_rsp;
4045 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004046 (*rsp)->hw = ha;
4047 (*rsp)->length = rsp_len;
4048 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4049 ((*rsp)->length + 1) * sizeof(response_t),
4050 &(*rsp)->dma, GFP_KERNEL);
4051 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004052 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4053 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 goto fail_rsp_ring;
4055 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004056 (*req)->rsp = *rsp;
4057 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004058 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4059 "req=%p req->length=%d req->ring=%p rsp=%p "
4060 "rsp->length=%d rsp->ring=%p.\n",
4061 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4062 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004063 /* Allocate memory for NVRAM data for vports */
4064 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004065 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4066 sizeof(struct qla_npiv_entry),
4067 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004068 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004069 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4070 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004071 goto fail_npiv_info;
4072 }
4073 } else
4074 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004075
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004076 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004077 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004078 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4079 &ha->ex_init_cb_dma);
4080 if (!ha->ex_init_cb)
4081 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004082 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4083 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004084 }
4085
Giridhar Malavalia9083012010-04-12 17:59:55 -07004086 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4087
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004088 /* Get consistent memory allocated for Async Port-Database. */
4089 if (!IS_FWI2_CAPABLE(ha)) {
4090 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4091 &ha->async_pd_dma);
4092 if (!ha->async_pd)
4093 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004094 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4095 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004096 }
4097
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004098 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004099
4100 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004101 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4102 sizeof(long),
4103 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004104 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004105 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004106 else {
4107 qla2x00_set_reserved_loop_ids(ha);
4108 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004109 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004110 }
4111
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004112 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4113 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4114 if (!ha->sfp_data) {
4115 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4116 "Unable to allocate memory for SFP read-data.\n");
4117 goto fail_sfp_data;
4118 }
4119
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004120 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004121
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004122fail_sfp_data:
4123 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004124fail_loop_id_map:
4125 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004126fail_async_pd:
4127 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004128fail_ex_init_cb:
4129 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004130fail_npiv_info:
4131 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4132 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4133 (*rsp)->ring = NULL;
4134 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004136 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004137 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004138fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004139 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4140 sizeof(request_t), (*req)->ring, (*req)->dma);
4141 (*req)->ring = NULL;
4142 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004143fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004144 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004145 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004146fail_req:
4147 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4148 ha->ct_sns, ha->ct_sns_dma);
4149 ha->ct_sns = NULL;
4150 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004151fail_free_ms_iocb:
4152 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4153 ha->ms_iocb = NULL;
4154 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004155
4156 if (ha->sns_cmd)
4157 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4158 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004159fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004160 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004161 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4162 ha->fcp_cmnd_dma_pool = NULL;
4163 }
4164fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004165 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004166 dma_pool_destroy(ha->dl_dma_pool);
4167 ha->dl_dma_pool = NULL;
4168 }
4169fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004170 dma_pool_destroy(ha->s_dma_pool);
4171 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004172fail_free_nvram:
4173 kfree(ha->nvram);
4174 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004175fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004176 if (ha->ctx_mempool)
4177 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004178 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004179fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004180 if (ha->srb_mempool)
4181 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004182 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004183fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004184 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4185 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004186 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004187 ha->gid_list = NULL;
4188 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004189fail_free_tgt_mem:
4190 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191fail_free_init_cb:
4192 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4193 ha->init_cb_dma);
4194 ha->init_cb = NULL;
4195 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004196fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004197 ql_log(ql_log_fatal, NULL, 0x0030,
4198 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004199 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200}
4201
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004202int
4203qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4204{
4205 int rval;
4206 uint16_t size, max_cnt, temp;
4207 struct qla_hw_data *ha = vha->hw;
4208
4209 /* Return if we don't need to alloacate any extended logins */
4210 if (!ql2xexlogins)
4211 return QLA_SUCCESS;
4212
Quinn Tran99e1b682017-06-02 09:12:03 -07004213 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4214 return QLA_SUCCESS;
4215
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004216 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4217 max_cnt = 0;
4218 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4219 if (rval != QLA_SUCCESS) {
4220 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4221 "Failed to get exlogin status.\n");
4222 return rval;
4223 }
4224
4225 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004226 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004227
Quinn Tran99e1b682017-06-02 09:12:03 -07004228 if (temp != ha->exlogin_size) {
4229 qla2x00_free_exlogin_buffer(ha);
4230 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004231
Quinn Tran99e1b682017-06-02 09:12:03 -07004232 ql_log(ql_log_info, vha, 0xd024,
4233 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4234 max_cnt, size, temp);
4235
4236 ql_log(ql_log_info, vha, 0xd025,
4237 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4238
4239 /* Get consistent memory for extended logins */
4240 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4241 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4242 if (!ha->exlogin_buf) {
4243 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004244 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004245 return -ENOMEM;
4246 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004247 }
4248
4249 /* Now configure the dma buffer */
4250 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4251 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004252 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004253 "Setup extended login buffer ****FAILED****.\n");
4254 qla2x00_free_exlogin_buffer(ha);
4255 }
4256
4257 return rval;
4258}
4259
4260/*
4261* qla2x00_free_exlogin_buffer
4262*
4263* Input:
4264* ha = adapter block pointer
4265*/
4266void
4267qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4268{
4269 if (ha->exlogin_buf) {
4270 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4271 ha->exlogin_buf, ha->exlogin_buf_dma);
4272 ha->exlogin_buf = NULL;
4273 ha->exlogin_size = 0;
4274 }
4275}
4276
Quinn Tran99e1b682017-06-02 09:12:03 -07004277static void
4278qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4279{
4280 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004281 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004282 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4283
Quinn Trand1e36352017-12-28 12:33:12 -08004284 if (max_cnt > vha->hw->max_exchg)
4285 max_cnt = vha->hw->max_exchg;
4286
Quinn Tran99e1b682017-06-02 09:12:03 -07004287 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004288 if (vha->ql2xiniexchg > max_cnt)
4289 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004290
Quinn Tran0645cb82018-09-11 10:18:18 -07004291 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4292 *ret_cnt = vha->ql2xiniexchg;
4293
Quinn Tran99e1b682017-06-02 09:12:03 -07004294 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004295 if (vha->ql2xexchoffld > max_cnt) {
4296 vha->ql2xexchoffld = max_cnt;
4297 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4298 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004299
Quinn Tran0645cb82018-09-11 10:18:18 -07004300 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4301 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004302 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004303 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004304 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004305 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4306 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004307 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004308 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004309 }
4310
4311 if (temp > FW_DEF_EXCHANGES_CNT)
4312 *ret_cnt = temp;
4313 }
4314}
4315
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004316int
4317qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4318{
4319 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004320 u16 size, max_cnt;
4321 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004322 struct qla_hw_data *ha = vha->hw;
4323
Quinn Tran99e1b682017-06-02 09:12:03 -07004324 if (!ha->flags.exchoffld_enabled)
4325 return QLA_SUCCESS;
4326
4327 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004328 return QLA_SUCCESS;
4329
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004330 max_cnt = 0;
4331 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4332 if (rval != QLA_SUCCESS) {
4333 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4334 "Failed to get exlogin status.\n");
4335 return rval;
4336 }
4337
Quinn Trand1e36352017-12-28 12:33:12 -08004338 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4339 ql_log(ql_log_info, vha, 0xd014,
4340 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004341
Quinn Trand1e36352017-12-28 12:33:12 -08004342 totsz = actual_cnt * size;
4343
4344 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004345 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004346 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4347 ha->exchoffld_size = 0;
4348 ha->flags.exchoffld_enabled = 0;
4349 return QLA_SUCCESS;
4350 }
4351
Quinn Trand1e36352017-12-28 12:33:12 -08004352 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004353
Quinn Tran99e1b682017-06-02 09:12:03 -07004354 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004355 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4356 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004357
4358 ql_log(ql_log_info, vha, 0xd017,
4359 "Exchange Buffers requested size = 0x%x\n",
4360 ha->exchoffld_size);
4361
4362 /* Get consistent memory for extended logins */
4363 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4364 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4365 if (!ha->exchoffld_buf) {
4366 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004367 "Failed to allocate memory for Exchange Offload.\n");
4368
4369 if (ha->max_exchg >
4370 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4371 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4372 } else if (ha->max_exchg >
4373 (FW_DEF_EXCHANGES_CNT + 512)) {
4374 ha->max_exchg -= 512;
4375 } else {
4376 ha->flags.exchoffld_enabled = 0;
4377 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4378 "Disabling Exchange offload due to lack of memory\n");
4379 }
4380 ha->exchoffld_size = 0;
4381
Quinn Tran99e1b682017-06-02 09:12:03 -07004382 return -ENOMEM;
4383 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004384 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4385 /* pathological case */
4386 qla2x00_free_exchoffld_buffer(ha);
4387 ha->exchoffld_size = 0;
4388 ha->flags.exchoffld_enabled = 0;
4389 ql_log(ql_log_info, vha, 0xd016,
4390 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4391 ha->exchoffld_size, actual_cnt, size, totsz);
4392 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004393 }
4394
4395 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004396 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004397 if (rval) {
4398 ql_log(ql_log_fatal, vha, 0xd02e,
4399 "Setup exchange offload buffer ****FAILED****.\n");
4400 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004401 } else {
4402 /* re-adjust number of target exchange */
4403 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4404
4405 if (qla_ini_mode_enabled(vha))
4406 icb->exchange_count = 0;
4407 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004408 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004409 }
4410
4411 return rval;
4412}
4413
4414/*
4415* qla2x00_free_exchoffld_buffer
4416*
4417* Input:
4418* ha = adapter block pointer
4419*/
4420void
4421qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4422{
4423 if (ha->exchoffld_buf) {
4424 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4425 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4426 ha->exchoffld_buf = NULL;
4427 ha->exchoffld_size = 0;
4428 }
4429}
4430
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004432* qla2x00_free_fw_dump
4433* Frees fw dump stuff.
4434*
4435* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004436* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004437*/
4438static void
4439qla2x00_free_fw_dump(struct qla_hw_data *ha)
4440{
4441 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004442 dma_free_coherent(&ha->pdev->dev,
4443 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004444
Chad Dupuisf73cb692014-02-26 04:15:06 -05004445 if (ha->eft)
4446 dma_free_coherent(&ha->pdev->dev,
4447 EFT_SIZE, ha->eft, ha->eft_dma);
4448
4449 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004450 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004451 if (ha->fw_dump_template)
4452 vfree(ha->fw_dump_template);
4453
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004454 ha->fce = NULL;
4455 ha->fce_dma = 0;
4456 ha->eft = NULL;
4457 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004458 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004459 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004460 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004461 ha->fw_dump = NULL;
4462 ha->fw_dump_len = 0;
4463 ha->fw_dump_template = NULL;
4464 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004465}
4466
4467/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468* qla2x00_mem_free
4469* Frees all adapter allocated memory.
4470*
4471* Input:
4472* ha = adapter block pointer.
4473*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004474static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004475qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004477 qla2x00_free_fw_dump(ha);
4478
Saurav Kashyap81178772012-08-22 14:21:04 -04004479 if (ha->mctp_dump)
4480 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4481 ha->mctp_dump_dma);
4482
Andrew Vasqueze8711082008-01-31 12:33:48 -08004483 if (ha->srb_mempool)
4484 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004486 if (ha->dcbx_tlv)
4487 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4488 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4489
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004490 if (ha->xgmac_data)
4491 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4492 ha->xgmac_data, ha->xgmac_data_dma);
4493
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 if (ha->sns_cmd)
4495 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004496 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497
4498 if (ha->ct_sns)
4499 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004500 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501
Andrew Vasquez88729e52006-06-23 16:10:50 -07004502 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004503 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4504 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004505
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 if (ha->ms_iocb)
4507 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4508
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004509 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004510 dma_pool_free(ha->s_dma_pool,
4511 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004512
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004513 if (ha->async_pd)
4514 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4515
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 if (ha->s_dma_pool)
4517 dma_pool_destroy(ha->s_dma_pool);
4518
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004520 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4521 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522
Giridhar Malavalia9083012010-04-12 17:59:55 -07004523 if (IS_QLA82XX(ha)) {
4524 if (!list_empty(&ha->gbl_dsd_list)) {
4525 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4526
4527 /* clean up allocated prev pool */
4528 list_for_each_entry_safe(dsd_ptr,
4529 tdsd_ptr, &ha->gbl_dsd_list, list) {
4530 dma_pool_free(ha->dl_dma_pool,
4531 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4532 list_del(&dsd_ptr->list);
4533 kfree(dsd_ptr);
4534 }
4535 }
4536 }
4537
4538 if (ha->dl_dma_pool)
4539 dma_pool_destroy(ha->dl_dma_pool);
4540
4541 if (ha->fcp_cmnd_dma_pool)
4542 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4543
4544 if (ha->ctx_mempool)
4545 mempool_destroy(ha->ctx_mempool);
4546
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004547 qlt_mem_free(ha);
4548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004549 if (ha->init_cb)
4550 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004551 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004552
Bill Kuzeja6d634062018-03-23 10:37:25 -04004553 vfree(ha->optrom_buffer);
4554 kfree(ha->nvram);
4555 kfree(ha->npiv_info);
4556 kfree(ha->swl);
4557 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558
Andrew Vasqueze8711082008-01-31 12:33:48 -08004559 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004560 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 ha->sns_cmd = NULL;
4562 ha->sns_cmd_dma = 0;
4563 ha->ct_sns = NULL;
4564 ha->ct_sns_dma = 0;
4565 ha->ms_iocb = NULL;
4566 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 ha->init_cb = NULL;
4568 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004569 ha->ex_init_cb = NULL;
4570 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004571 ha->async_pd = NULL;
4572 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004573 ha->loop_id_map = NULL;
4574 ha->npiv_info = NULL;
4575 ha->optrom_buffer = NULL;
4576 ha->swl = NULL;
4577 ha->nvram = NULL;
4578 ha->mctp_dump = NULL;
4579 ha->dcbx_tlv = NULL;
4580 ha->xgmac_data = NULL;
4581 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582
4583 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004584 ha->dl_dma_pool = NULL;
4585 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 ha->gid_list = NULL;
4588 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004589
4590 ha->tgt.atio_ring = NULL;
4591 ha->tgt.atio_dma = 0;
4592 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004593}
4594
4595struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4596 struct qla_hw_data *ha)
4597{
4598 struct Scsi_Host *host;
4599 struct scsi_qla_host *vha = NULL;
4600
4601 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004602 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004603 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4604 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004605 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004606 }
4607
4608 /* Clear our data area */
4609 vha = shost_priv(host);
4610 memset(vha, 0, sizeof(scsi_qla_host_t));
4611
4612 vha->host = host;
4613 vha->host_no = host->host_no;
4614 vha->hw = ha;
4615
Quinn Tran0645cb82018-09-11 10:18:18 -07004616 vha->qlini_mode = ql2x_ini_mode;
4617 vha->ql2xexchoffld = ql2xexchoffld;
4618 vha->ql2xiniexchg = ql2xiniexchg;
4619
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004620 INIT_LIST_HEAD(&vha->vp_fcports);
4621 INIT_LIST_HEAD(&vha->work_list);
4622 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004623 INIT_LIST_HEAD(&vha->qla_cmd_list);
4624 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004625 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004626 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004627 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004628 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004629 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004630 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004631 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004632
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004633 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004634 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004635 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004636 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004637
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004638 vha->gnl.size = sizeof(struct get_name_list_extended) *
4639 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004640 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4641 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4642 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004643 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004644 "Alloc failed for name list.\n");
4645 scsi_remove_host(vha->host);
4646 return NULL;
4647 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004648
Quinn Trana4239942017-12-28 12:33:26 -08004649 /* todo: what about ext login? */
4650 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4651 vha->scan.l = vmalloc(vha->scan.size);
4652 if (!vha->scan.l) {
4653 ql_log(ql_log_fatal, vha, 0xd04a,
4654 "Alloc failed for scan database.\n");
4655 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4656 vha->gnl.l, vha->gnl.ldma);
4657 scsi_remove_host(vha->host);
4658 return NULL;
4659 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004660 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004662 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004663 ql_dbg(ql_dbg_init, vha, 0x0041,
4664 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4665 vha->host, vha->hw, vha,
4666 dev_name(&(ha->pdev->dev)));
4667
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004668 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669}
4670
Quinn Tran726b8542017-01-19 22:28:00 -08004671struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004672qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004673{
4674 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004675 uint8_t bail;
4676
4677 QLA_VHA_MARK_BUSY(vha, bail);
4678 if (bail)
4679 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004680
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004681 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004682 if (!e) {
4683 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004684 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004685 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004686
4687 INIT_LIST_HEAD(&e->list);
4688 e->type = type;
4689 e->flags = QLA_EVT_FLAG_FREE;
4690 return e;
4691}
4692
Quinn Tran726b8542017-01-19 22:28:00 -08004693int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004694qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004695{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004696 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004697 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004698
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004699 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004700 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004701
4702 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4703 q = true;
4704
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004705 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004706
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004707 if (q)
4708 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004709
Andrew Vasquez0971de72008-04-03 13:13:18 -07004710 return QLA_SUCCESS;
4711}
4712
4713int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004714qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004715 u32 data)
4716{
4717 struct qla_work_evt *e;
4718
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004719 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004720 if (!e)
4721 return QLA_FUNCTION_FAILED;
4722
4723 e->u.aen.code = code;
4724 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004725 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004726}
4727
Andrew Vasquez8a659572009-02-08 20:50:12 -08004728int
4729qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4730{
4731 struct qla_work_evt *e;
4732
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004733 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004734 if (!e)
4735 return QLA_FUNCTION_FAILED;
4736
4737 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004738 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004739}
4740
Andrew Vasquezac280b62009-08-20 11:06:05 -07004741#define qla2x00_post_async_work(name, type) \
4742int qla2x00_post_async_##name##_work( \
4743 struct scsi_qla_host *vha, \
4744 fc_port_t *fcport, uint16_t *data) \
4745{ \
4746 struct qla_work_evt *e; \
4747 \
4748 e = qla2x00_alloc_work(vha, type); \
4749 if (!e) \
4750 return QLA_FUNCTION_FAILED; \
4751 \
4752 e->u.logio.fcport = fcport; \
4753 if (data) { \
4754 e->u.logio.data[0] = data[0]; \
4755 e->u.logio.data[1] = data[1]; \
4756 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004757 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004758 return qla2x00_post_work(vha, e); \
4759}
4760
4761qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004762qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4763qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004764qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08004765qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4766qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004767
Andrew Vasquez3420d362009-10-13 15:16:45 -07004768int
4769qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4770{
4771 struct qla_work_evt *e;
4772
4773 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4774 if (!e)
4775 return QLA_FUNCTION_FAILED;
4776
4777 e->u.uevent.code = code;
4778 return qla2x00_post_work(vha, e);
4779}
4780
4781static void
4782qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4783{
4784 char event_string[40];
4785 char *envp[] = { event_string, NULL };
4786
4787 switch (code) {
4788 case QLA_UEVENT_CODE_FW_DUMP:
4789 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4790 vha->host_no);
4791 break;
4792 default:
4793 /* do nothing */
4794 break;
4795 }
4796 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4797}
4798
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004799int
4800qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4801 uint32_t *data, int cnt)
4802{
4803 struct qla_work_evt *e;
4804
4805 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4806 if (!e)
4807 return QLA_FUNCTION_FAILED;
4808
4809 e->u.aenfx.evtcode = evtcode;
4810 e->u.aenfx.count = cnt;
4811 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4812 return qla2x00_post_work(vha, e);
4813}
4814
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004815void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08004816{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004817 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08004818
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004819 if (IS_SW_RESV_ADDR(fcport->d_id))
4820 return;
Quinn Tran726b8542017-01-19 22:28:00 -08004821
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004822 spin_lock_irqsave(&fcport->vha->work_lock, flags);
4823 if (fcport->disc_state == DSC_UPD_FCPORT) {
4824 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4825 return;
4826 }
4827 fcport->jiffies_at_registration = jiffies;
4828 fcport->sec_since_registration = 0;
4829 fcport->next_disc_state = DSC_DELETED;
4830 fcport->disc_state = DSC_UPD_FCPORT;
4831 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4832
4833 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08004834}
4835
4836static
4837void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4838{
4839 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07004840 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08004841 struct qlt_plogi_ack_t *pla =
4842 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07004843 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08004844
Quinn Tran9cd883f2017-12-28 12:33:24 -08004845 ql_dbg(ql_dbg_disc, vha, 0xffff,
4846 "%s %d %8phC enter\n",
4847 __func__, __LINE__, e->u.new_sess.port_name);
4848
Quinn Tran726b8542017-01-19 22:28:00 -08004849 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4850 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4851 if (fcport) {
4852 fcport->d_id = e->u.new_sess.id;
4853 if (pla) {
4854 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004855 memcpy(fcport->node_name,
4856 pla->iocb.u.isp24.u.plogi.node_name,
4857 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08004858 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4859 /* we took an extra ref_count to prevent PLOGI ACK when
4860 * fcport/sess has not been created.
4861 */
4862 pla->ref_count--;
4863 }
4864 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07004865 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004866 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4867 if (fcport) {
4868 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08004869 fcport->flags |= FCF_FABRIC_DEVICE;
4870 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Trandb186382018-09-26 22:05:12 -07004871 if (e->u.new_sess.fc4_type & FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08004872 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08004873
Quinn Trandb186382018-09-26 22:05:12 -07004874 if (e->u.new_sess.fc4_type & FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08004875 fcport->fc4_type = FC4_TYPE_OTHER;
4876 fcport->fc4f_nvme = FC4_TYPE_NVME;
4877 }
Quinn Tran33b28352018-03-20 23:09:40 -07004878
Quinn Tran726b8542017-01-19 22:28:00 -08004879 memcpy(fcport->port_name, e->u.new_sess.port_name,
4880 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07004881 } else {
4882 ql_dbg(ql_dbg_disc, vha, 0xffff,
4883 "%s %8phC mem alloc fail.\n",
4884 __func__, e->u.new_sess.port_name);
4885
4886 if (pla)
4887 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4888 return;
4889 }
4890
4891 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004892 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07004893 tfcp = qla2x00_find_fcport_by_wwpn(vha,
4894 e->u.new_sess.port_name, 1);
4895 if (tfcp) {
4896 /* should rarily happen */
4897 ql_dbg(ql_dbg_disc, vha, 0xffff,
4898 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
4899 __func__, tfcp->port_name, tfcp->disc_state,
4900 tfcp->fw_login_state);
4901
4902 free_fcport = 1;
4903 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08004904 list_add_tail(&fcport->list, &vha->vp_fcports);
4905
Quinn Tran19759032017-12-04 14:45:15 -08004906 }
4907 if (pla) {
4908 qlt_plogi_ack_link(vha, pla, fcport,
4909 QLT_PLOGI_LINK_SAME_WWN);
4910 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08004911 }
4912 }
4913 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4914
4915 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08004916 fcport->id_changed = 1;
4917 fcport->scan_state = QLA_FCPORT_FOUND;
4918 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
4919
Quinn Tran5ef696a2017-12-04 14:45:05 -08004920 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004921 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
4922 u16 wd3_lo;
4923
4924 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4925 fcport->local = 0;
4926 fcport->loop_id =
4927 le16_to_cpu(
4928 pla->iocb.u.isp24.nport_handle);
4929 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4930 wd3_lo =
4931 le16_to_cpu(
4932 pla->iocb.u.isp24.u.prli.wd3_lo);
4933
4934 if (wd3_lo & BIT_7)
4935 fcport->conf_compl_supported = 1;
4936
4937 if ((wd3_lo & BIT_4) == 0)
4938 fcport->port_type = FCT_INITIATOR;
4939 else
4940 fcport->port_type = FCT_TARGET;
4941 }
Quinn Tran726b8542017-01-19 22:28:00 -08004942 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004943 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004944 fc_port_t *dfcp = NULL;
4945
Quinn Tran5ef696a2017-12-04 14:45:05 -08004946 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4947 tfcp = qla2x00_find_fcport_by_nportid(vha,
4948 &e->u.new_sess.id, 1);
4949 if (tfcp && (tfcp != fcport)) {
4950 /*
4951 * We have a conflict fcport with same NportID.
4952 */
4953 ql_dbg(ql_dbg_disc, vha, 0xffff,
4954 "%s %8phC found conflict b4 add. DS %d LS %d\n",
4955 __func__, tfcp->port_name, tfcp->disc_state,
4956 tfcp->fw_login_state);
4957
4958 switch (tfcp->disc_state) {
4959 case DSC_DELETED:
4960 break;
4961 case DSC_DELETE_PEND:
4962 fcport->login_pause = 1;
4963 tfcp->conflict = fcport;
4964 break;
4965 default:
4966 fcport->login_pause = 1;
4967 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004968 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08004969 break;
4970 }
4971 }
4972 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004973 if (dfcp)
4974 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08004975
Quinn Trana4239942017-12-28 12:33:26 -08004976
Quinn Tran8777e432018-08-02 13:16:57 -07004977 if (N2N_TOPO(vha->hw))
4978 fcport->flags &= ~FCF_FABRIC_DEVICE;
4979
4980 if (N2N_TOPO(vha->hw)) {
4981 if (vha->flags.nvme_enabled) {
4982 fcport->fc4f_nvme = 1;
4983 fcport->n2n_flag = 1;
4984 }
4985 fcport->fw_login_state = 0;
4986 /*
4987 * wait link init done before sending login
4988 */
4989 } else {
4990 qla24xx_fcport_handle_login(vha, fcport);
4991 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08004992 }
Quinn Tran726b8542017-01-19 22:28:00 -08004993 }
Quinn Tranb5d15312017-08-30 10:16:49 -07004994
4995 if (free_fcport) {
4996 qla2x00_free_fcport(fcport);
4997 if (pla)
4998 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4999 }
Quinn Tran726b8542017-01-19 22:28:00 -08005000}
5001
Quinn Trane374f9f2017-12-28 12:33:31 -08005002static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5003{
5004 struct srb *sp = e->u.iosb.sp;
5005 int rval;
5006
5007 rval = qla2x00_start_sp(sp);
5008 if (rval != QLA_SUCCESS) {
5009 ql_dbg(ql_dbg_disc, vha, 0x2043,
5010 "%s: %s: Re-issue IOCB failed (%d).\n",
5011 __func__, sp->name, rval);
5012 qla24xx_sp_unmap(vha, sp);
5013 }
5014}
5015
Andrew Vasquezac280b62009-08-20 11:06:05 -07005016void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005017qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005018{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005019 struct qla_work_evt *e, *tmp;
5020 unsigned long flags;
5021 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005022
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005023 spin_lock_irqsave(&vha->work_lock, flags);
5024 list_splice_init(&vha->work_list, &work);
5025 spin_unlock_irqrestore(&vha->work_lock, flags);
5026
5027 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07005028 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005029
5030 switch (e->type) {
5031 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005032 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005033 e->u.aen.code, e->u.aen.data);
5034 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005035 case QLA_EVT_IDC_ACK:
5036 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5037 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005038 case QLA_EVT_ASYNC_LOGIN:
5039 qla2x00_async_login(vha, e->u.logio.fcport,
5040 e->u.logio.data);
5041 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005042 case QLA_EVT_ASYNC_LOGOUT:
5043 qla2x00_async_logout(vha, e->u.logio.fcport);
5044 break;
5045 case QLA_EVT_ASYNC_LOGOUT_DONE:
5046 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5047 e->u.logio.data);
5048 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005049 case QLA_EVT_ASYNC_ADISC:
5050 qla2x00_async_adisc(vha, e->u.logio.fcport,
5051 e->u.logio.data);
5052 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005053 case QLA_EVT_UEVENT:
5054 qla2x00_uevent_emit(vha, e->u.uevent.code);
5055 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005056 case QLA_EVT_AENFX:
5057 qlafx00_process_aen(vha, e);
5058 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005059 case QLA_EVT_GPNID:
5060 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5061 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005062 case QLA_EVT_UNMAP:
5063 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005064 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005065 case QLA_EVT_RELOGIN:
5066 qla2x00_relogin(vha);
5067 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005068 case QLA_EVT_NEW_SESS:
5069 qla24xx_create_new_sess(vha, e);
5070 break;
5071 case QLA_EVT_GPDB:
5072 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5073 e->u.fcport.opt);
5074 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005075 case QLA_EVT_PRLI:
5076 qla24xx_async_prli(vha, e->u.fcport.fcport);
5077 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005078 case QLA_EVT_GPSC:
5079 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5080 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005081 case QLA_EVT_GNL:
5082 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5083 break;
5084 case QLA_EVT_NACK:
5085 qla24xx_do_nack_work(vha, e);
5086 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005087 case QLA_EVT_ASYNC_PRLO:
5088 qla2x00_async_prlo(vha, e->u.logio.fcport);
5089 break;
5090 case QLA_EVT_ASYNC_PRLO_DONE:
5091 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5092 e->u.logio.data);
5093 break;
Quinn Trana4239942017-12-28 12:33:26 -08005094 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005095 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5096 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005097 break;
5098 case QLA_EVT_GPNFT_DONE:
5099 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5100 break;
5101 case QLA_EVT_GNNFT_DONE:
5102 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5103 break;
5104 case QLA_EVT_GNNID:
5105 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5106 break;
5107 case QLA_EVT_GFPNID:
5108 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5109 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005110 case QLA_EVT_SP_RETRY:
5111 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005112 break;
5113 case QLA_EVT_IIDMA:
5114 qla_do_iidma_work(vha, e->u.fcport.fcport);
5115 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005116 case QLA_EVT_ELS_PLOGI:
5117 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5118 e->u.fcport.fcport, false);
5119 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005120 }
5121 if (e->flags & QLA_EVT_FLAG_FREE)
5122 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005123
5124 /* For each work completed decrement vha ref count */
5125 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005126 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005127}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005128
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005129int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5130{
5131 struct qla_work_evt *e;
5132
5133 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5134
5135 if (!e) {
5136 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5137 return QLA_FUNCTION_FAILED;
5138 }
5139
5140 return qla2x00_post_work(vha, e);
5141}
5142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005143/* Relogins all the fcports of a vport
5144 * Context: dpc thread
5145 */
5146void qla2x00_relogin(struct scsi_qla_host *vha)
5147{
5148 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005149 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005150 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005151
5152 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005153 /*
5154 * If the port is not ONLINE then try to login
5155 * to it if we haven't run out of retries.
5156 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005157 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005158 fcport->login_retry) {
5159 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5160 fcport->disc_state == DSC_LOGIN_COMPLETE)
5161 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005162
Quinn Tran23dd98a2018-08-02 13:16:45 -07005163 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5164 fcport->disc_state == DSC_DELETE_PEND) {
5165 relogin_needed = 1;
5166 } else {
5167 if (vha->hw->current_topology != ISP_CFG_NL) {
5168 memset(&ea, 0, sizeof(ea));
5169 ea.event = FCME_RELOGIN;
5170 ea.fcport = fcport;
5171 qla2x00_fcport_event_handler(vha, &ea);
5172 } else if (vha->hw->current_topology ==
5173 ISP_CFG_NL) {
5174 fcport->login_retry--;
5175 status =
5176 qla2x00_local_device_login(vha,
5177 fcport);
5178 if (status == QLA_SUCCESS) {
5179 fcport->old_loop_id =
5180 fcport->loop_id;
5181 ql_dbg(ql_dbg_disc, vha, 0x2003,
5182 "Port login OK: logged in ID 0x%x.\n",
5183 fcport->loop_id);
5184 qla2x00_update_fcport
5185 (vha, fcport);
5186 } else if (status == 1) {
5187 set_bit(RELOGIN_NEEDED,
5188 &vha->dpc_flags);
5189 /* retry the login again */
5190 ql_dbg(ql_dbg_disc, vha, 0x2007,
5191 "Retrying %d login again loop_id 0x%x.\n",
5192 fcport->login_retry,
5193 fcport->loop_id);
5194 } else {
5195 fcport->login_retry = 0;
5196 }
5197
5198 if (fcport->login_retry == 0 &&
5199 status != QLA_SUCCESS)
5200 qla2x00_clear_loop_id(fcport);
5201 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005202 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005203 }
5204 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5205 break;
5206 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005207
Quinn Tran23dd98a2018-08-02 13:16:45 -07005208 if (relogin_needed)
5209 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5210
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005211 ql_dbg(ql_dbg_disc, vha, 0x400e,
5212 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005213}
5214
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005215/* Schedule work on any of the dpc-workqueues */
5216void
5217qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5218{
5219 struct qla_hw_data *ha = base_vha->hw;
5220
5221 switch (work_code) {
5222 case MBA_IDC_AEN: /* 0x8200 */
5223 if (ha->dpc_lp_wq)
5224 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5225 break;
5226
5227 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5228 if (!ha->flags.nic_core_reset_hdlr_active) {
5229 if (ha->dpc_hp_wq)
5230 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5231 } else
5232 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5233 "NIC Core reset is already active. Skip "
5234 "scheduling it again.\n");
5235 break;
5236 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5237 if (ha->dpc_hp_wq)
5238 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5239 break;
5240 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5241 if (ha->dpc_hp_wq)
5242 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5243 break;
5244 default:
5245 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005246 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005247 }
5248
5249 return;
5250}
5251
5252/* Work: Perform NIC Core Unrecoverable state handling */
5253void
5254qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5255{
5256 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005257 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005258 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5259 uint32_t dev_state = 0;
5260
5261 qla83xx_idc_lock(base_vha, 0);
5262 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5263 qla83xx_reset_ownership(base_vha);
5264 if (ha->flags.nic_core_reset_owner) {
5265 ha->flags.nic_core_reset_owner = 0;
5266 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5267 QLA8XXX_DEV_FAILED);
5268 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5269 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5270 }
5271 qla83xx_idc_unlock(base_vha, 0);
5272}
5273
5274/* Work: Execute IDC state handler */
5275void
5276qla83xx_idc_state_handler_work(struct work_struct *work)
5277{
5278 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005279 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005280 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5281 uint32_t dev_state = 0;
5282
5283 qla83xx_idc_lock(base_vha, 0);
5284 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5285 if (dev_state == QLA8XXX_DEV_FAILED ||
5286 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5287 qla83xx_idc_state_handler(base_vha);
5288 qla83xx_idc_unlock(base_vha, 0);
5289}
5290
Saurav Kashyapfa492632012-11-21 02:40:29 -05005291static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005292qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5293{
5294 int rval = QLA_SUCCESS;
5295 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5296 uint32_t heart_beat_counter1, heart_beat_counter2;
5297
5298 do {
5299 if (time_after(jiffies, heart_beat_wait)) {
5300 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5301 "Nic Core f/w is not alive.\n");
5302 rval = QLA_FUNCTION_FAILED;
5303 break;
5304 }
5305
5306 qla83xx_idc_lock(base_vha, 0);
5307 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5308 &heart_beat_counter1);
5309 qla83xx_idc_unlock(base_vha, 0);
5310 msleep(100);
5311 qla83xx_idc_lock(base_vha, 0);
5312 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5313 &heart_beat_counter2);
5314 qla83xx_idc_unlock(base_vha, 0);
5315 } while (heart_beat_counter1 == heart_beat_counter2);
5316
5317 return rval;
5318}
5319
5320/* Work: Perform NIC Core Reset handling */
5321void
5322qla83xx_nic_core_reset_work(struct work_struct *work)
5323{
5324 struct qla_hw_data *ha =
5325 container_of(work, struct qla_hw_data, nic_core_reset);
5326 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5327 uint32_t dev_state = 0;
5328
Saurav Kashyap81178772012-08-22 14:21:04 -04005329 if (IS_QLA2031(ha)) {
5330 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5331 ql_log(ql_log_warn, base_vha, 0xb081,
5332 "Failed to dump mctp\n");
5333 return;
5334 }
5335
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005336 if (!ha->flags.nic_core_reset_hdlr_active) {
5337 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5338 qla83xx_idc_lock(base_vha, 0);
5339 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5340 &dev_state);
5341 qla83xx_idc_unlock(base_vha, 0);
5342 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5343 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5344 "Nic Core f/w is alive.\n");
5345 return;
5346 }
5347 }
5348
5349 ha->flags.nic_core_reset_hdlr_active = 1;
5350 if (qla83xx_nic_core_reset(base_vha)) {
5351 /* NIC Core reset failed. */
5352 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5353 "NIC Core reset failed.\n");
5354 }
5355 ha->flags.nic_core_reset_hdlr_active = 0;
5356 }
5357}
5358
5359/* Work: Handle 8200 IDC aens */
5360void
5361qla83xx_service_idc_aen(struct work_struct *work)
5362{
5363 struct qla_hw_data *ha =
5364 container_of(work, struct qla_hw_data, idc_aen);
5365 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5366 uint32_t dev_state, idc_control;
5367
5368 qla83xx_idc_lock(base_vha, 0);
5369 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5370 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5371 qla83xx_idc_unlock(base_vha, 0);
5372 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5373 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5374 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5375 "Application requested NIC Core Reset.\n");
5376 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5377 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5378 QLA_SUCCESS) {
5379 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5380 "Other protocol driver requested NIC Core Reset.\n");
5381 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5382 }
5383 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5384 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5385 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5386 }
5387}
5388
5389static void
5390qla83xx_wait_logic(void)
5391{
5392 int i;
5393
5394 /* Yield CPU */
5395 if (!in_interrupt()) {
5396 /*
5397 * Wait about 200ms before retrying again.
5398 * This controls the number of retries for single
5399 * lock operation.
5400 */
5401 msleep(100);
5402 schedule();
5403 } else {
5404 for (i = 0; i < 20; i++)
5405 cpu_relax(); /* This a nop instr on i386 */
5406 }
5407}
5408
Saurav Kashyapfa492632012-11-21 02:40:29 -05005409static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005410qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5411{
5412 int rval;
5413 uint32_t data;
5414 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5415 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5416 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005417 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5418 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005419
5420 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5421 if (rval)
5422 return rval;
5423
5424 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5425 return QLA_SUCCESS;
5426 } else {
5427 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5428 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5429 data);
5430 if (rval)
5431 return rval;
5432
5433 msleep(200);
5434
5435 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5436 &data);
5437 if (rval)
5438 return rval;
5439
5440 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5441 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5442 ~(idc_lck_rcvry_stage_mask));
5443 rval = qla83xx_wr_reg(base_vha,
5444 QLA83XX_IDC_LOCK_RECOVERY, data);
5445 if (rval)
5446 return rval;
5447
5448 /* Forcefully perform IDC UnLock */
5449 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5450 &data);
5451 if (rval)
5452 return rval;
5453 /* Clear lock-id by setting 0xff */
5454 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5455 0xff);
5456 if (rval)
5457 return rval;
5458 /* Clear lock-recovery by setting 0x0 */
5459 rval = qla83xx_wr_reg(base_vha,
5460 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5461 if (rval)
5462 return rval;
5463 } else
5464 return QLA_SUCCESS;
5465 }
5466
5467 return rval;
5468}
5469
Saurav Kashyapfa492632012-11-21 02:40:29 -05005470static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005471qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5472{
5473 int rval = QLA_SUCCESS;
5474 uint32_t o_drv_lockid, n_drv_lockid;
5475 unsigned long lock_recovery_timeout;
5476
5477 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5478retry_lockid:
5479 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5480 if (rval)
5481 goto exit;
5482
5483 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5484 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5485 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5486 return QLA_SUCCESS;
5487 else
5488 return QLA_FUNCTION_FAILED;
5489 }
5490
5491 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5492 if (rval)
5493 goto exit;
5494
5495 if (o_drv_lockid == n_drv_lockid) {
5496 qla83xx_wait_logic();
5497 goto retry_lockid;
5498 } else
5499 return QLA_SUCCESS;
5500
5501exit:
5502 return rval;
5503}
5504
5505void
5506qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5507{
5508 uint16_t options = (requester_id << 15) | BIT_6;
5509 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005510 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005511 struct qla_hw_data *ha = base_vha->hw;
5512
5513 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5514retry_lock:
5515 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5516 == QLA_SUCCESS) {
5517 if (data) {
5518 /* Setting lock-id to our function-number */
5519 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5520 ha->portnum);
5521 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005522 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5523 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005524 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005525 "Failed to acquire IDC lock, acquired by %d, "
5526 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005527
5528 /* Retry/Perform IDC-Lock recovery */
5529 if (qla83xx_idc_lock_recovery(base_vha)
5530 == QLA_SUCCESS) {
5531 qla83xx_wait_logic();
5532 goto retry_lock;
5533 } else
5534 ql_log(ql_log_warn, base_vha, 0xb075,
5535 "IDC Lock recovery FAILED.\n");
5536 }
5537
5538 }
5539
5540 return;
5541
5542 /* XXX: IDC-lock implementation using access-control mbx */
5543retry_lock2:
5544 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5545 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5546 "Failed to acquire IDC lock. retrying...\n");
5547 /* Retry/Perform IDC-Lock recovery */
5548 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5549 qla83xx_wait_logic();
5550 goto retry_lock2;
5551 } else
5552 ql_log(ql_log_warn, base_vha, 0xb076,
5553 "IDC Lock recovery FAILED.\n");
5554 }
5555
5556 return;
5557}
5558
5559void
5560qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5561{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005562#if 0
5563 uint16_t options = (requester_id << 15) | BIT_7;
5564#endif
5565 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005566 uint32_t data;
5567 struct qla_hw_data *ha = base_vha->hw;
5568
5569 /* IDC-unlock implementation using driver-unlock/lock-id
5570 * remote registers
5571 */
5572 retry = 0;
5573retry_unlock:
5574 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5575 == QLA_SUCCESS) {
5576 if (data == ha->portnum) {
5577 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5578 /* Clearing lock-id by setting 0xff */
5579 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5580 } else if (retry < 10) {
5581 /* SV: XXX: IDC unlock retrying needed here? */
5582
5583 /* Retry for IDC-unlock */
5584 qla83xx_wait_logic();
5585 retry++;
5586 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005587 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005588 goto retry_unlock;
5589 }
5590 } else if (retry < 10) {
5591 /* Retry for IDC-unlock */
5592 qla83xx_wait_logic();
5593 retry++;
5594 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005595 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005596 goto retry_unlock;
5597 }
5598
5599 return;
5600
Bart Van Assche5897cb22015-06-04 15:57:20 -07005601#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005602 /* XXX: IDC-unlock implementation using access-control mbx */
5603 retry = 0;
5604retry_unlock2:
5605 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5606 if (retry < 10) {
5607 /* Retry for IDC-unlock */
5608 qla83xx_wait_logic();
5609 retry++;
5610 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005611 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005612 goto retry_unlock2;
5613 }
5614 }
5615
5616 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005617#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005618}
5619
5620int
5621__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5622{
5623 int rval = QLA_SUCCESS;
5624 struct qla_hw_data *ha = vha->hw;
5625 uint32_t drv_presence;
5626
5627 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5628 if (rval == QLA_SUCCESS) {
5629 drv_presence |= (1 << ha->portnum);
5630 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5631 drv_presence);
5632 }
5633
5634 return rval;
5635}
5636
5637int
5638qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5639{
5640 int rval = QLA_SUCCESS;
5641
5642 qla83xx_idc_lock(vha, 0);
5643 rval = __qla83xx_set_drv_presence(vha);
5644 qla83xx_idc_unlock(vha, 0);
5645
5646 return rval;
5647}
5648
5649int
5650__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5651{
5652 int rval = QLA_SUCCESS;
5653 struct qla_hw_data *ha = vha->hw;
5654 uint32_t drv_presence;
5655
5656 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5657 if (rval == QLA_SUCCESS) {
5658 drv_presence &= ~(1 << ha->portnum);
5659 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5660 drv_presence);
5661 }
5662
5663 return rval;
5664}
5665
5666int
5667qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5668{
5669 int rval = QLA_SUCCESS;
5670
5671 qla83xx_idc_lock(vha, 0);
5672 rval = __qla83xx_clear_drv_presence(vha);
5673 qla83xx_idc_unlock(vha, 0);
5674
5675 return rval;
5676}
5677
Saurav Kashyapfa492632012-11-21 02:40:29 -05005678static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005679qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5680{
5681 struct qla_hw_data *ha = vha->hw;
5682 uint32_t drv_ack, drv_presence;
5683 unsigned long ack_timeout;
5684
5685 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5686 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5687 while (1) {
5688 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5689 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005690 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005691 break;
5692
5693 if (time_after_eq(jiffies, ack_timeout)) {
5694 ql_log(ql_log_warn, vha, 0xb067,
5695 "RESET ACK TIMEOUT! drv_presence=0x%x "
5696 "drv_ack=0x%x\n", drv_presence, drv_ack);
5697 /*
5698 * The function(s) which did not ack in time are forced
5699 * to withdraw any further participation in the IDC
5700 * reset.
5701 */
5702 if (drv_ack != drv_presence)
5703 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5704 drv_ack);
5705 break;
5706 }
5707
5708 qla83xx_idc_unlock(vha, 0);
5709 msleep(1000);
5710 qla83xx_idc_lock(vha, 0);
5711 }
5712
5713 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5714 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5715}
5716
Saurav Kashyapfa492632012-11-21 02:40:29 -05005717static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005718qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5719{
5720 int rval = QLA_SUCCESS;
5721 uint32_t idc_control;
5722
5723 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5724 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5725
5726 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5727 __qla83xx_get_idc_control(vha, &idc_control);
5728 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5729 __qla83xx_set_idc_control(vha, 0);
5730
5731 qla83xx_idc_unlock(vha, 0);
5732 rval = qla83xx_restart_nic_firmware(vha);
5733 qla83xx_idc_lock(vha, 0);
5734
5735 if (rval != QLA_SUCCESS) {
5736 ql_log(ql_log_fatal, vha, 0xb06a,
5737 "Failed to restart NIC f/w.\n");
5738 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5739 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5740 } else {
5741 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5742 "Success in restarting nic f/w.\n");
5743 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5744 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5745 }
5746
5747 return rval;
5748}
5749
5750/* Assumes idc_lock always held on entry */
5751int
5752qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5753{
5754 struct qla_hw_data *ha = base_vha->hw;
5755 int rval = QLA_SUCCESS;
5756 unsigned long dev_init_timeout;
5757 uint32_t dev_state;
5758
5759 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5760 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5761
5762 while (1) {
5763
5764 if (time_after_eq(jiffies, dev_init_timeout)) {
5765 ql_log(ql_log_warn, base_vha, 0xb06e,
5766 "Initialization TIMEOUT!\n");
5767 /* Init timeout. Disable further NIC Core
5768 * communication.
5769 */
5770 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5771 QLA8XXX_DEV_FAILED);
5772 ql_log(ql_log_info, base_vha, 0xb06f,
5773 "HW State: FAILED.\n");
5774 }
5775
5776 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5777 switch (dev_state) {
5778 case QLA8XXX_DEV_READY:
5779 if (ha->flags.nic_core_reset_owner)
5780 qla83xx_idc_audit(base_vha,
5781 IDC_AUDIT_COMPLETION);
5782 ha->flags.nic_core_reset_owner = 0;
5783 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5784 "Reset_owner reset by 0x%x.\n",
5785 ha->portnum);
5786 goto exit;
5787 case QLA8XXX_DEV_COLD:
5788 if (ha->flags.nic_core_reset_owner)
5789 rval = qla83xx_device_bootstrap(base_vha);
5790 else {
5791 /* Wait for AEN to change device-state */
5792 qla83xx_idc_unlock(base_vha, 0);
5793 msleep(1000);
5794 qla83xx_idc_lock(base_vha, 0);
5795 }
5796 break;
5797 case QLA8XXX_DEV_INITIALIZING:
5798 /* Wait for AEN to change device-state */
5799 qla83xx_idc_unlock(base_vha, 0);
5800 msleep(1000);
5801 qla83xx_idc_lock(base_vha, 0);
5802 break;
5803 case QLA8XXX_DEV_NEED_RESET:
5804 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5805 qla83xx_need_reset_handler(base_vha);
5806 else {
5807 /* Wait for AEN to change device-state */
5808 qla83xx_idc_unlock(base_vha, 0);
5809 msleep(1000);
5810 qla83xx_idc_lock(base_vha, 0);
5811 }
5812 /* reset timeout value after need reset handler */
5813 dev_init_timeout = jiffies +
5814 (ha->fcoe_dev_init_timeout * HZ);
5815 break;
5816 case QLA8XXX_DEV_NEED_QUIESCENT:
5817 /* XXX: DEBUG for now */
5818 qla83xx_idc_unlock(base_vha, 0);
5819 msleep(1000);
5820 qla83xx_idc_lock(base_vha, 0);
5821 break;
5822 case QLA8XXX_DEV_QUIESCENT:
5823 /* XXX: DEBUG for now */
5824 if (ha->flags.quiesce_owner)
5825 goto exit;
5826
5827 qla83xx_idc_unlock(base_vha, 0);
5828 msleep(1000);
5829 qla83xx_idc_lock(base_vha, 0);
5830 dev_init_timeout = jiffies +
5831 (ha->fcoe_dev_init_timeout * HZ);
5832 break;
5833 case QLA8XXX_DEV_FAILED:
5834 if (ha->flags.nic_core_reset_owner)
5835 qla83xx_idc_audit(base_vha,
5836 IDC_AUDIT_COMPLETION);
5837 ha->flags.nic_core_reset_owner = 0;
5838 __qla83xx_clear_drv_presence(base_vha);
5839 qla83xx_idc_unlock(base_vha, 0);
5840 qla8xxx_dev_failed_handler(base_vha);
5841 rval = QLA_FUNCTION_FAILED;
5842 qla83xx_idc_lock(base_vha, 0);
5843 goto exit;
5844 case QLA8XXX_BAD_VALUE:
5845 qla83xx_idc_unlock(base_vha, 0);
5846 msleep(1000);
5847 qla83xx_idc_lock(base_vha, 0);
5848 break;
5849 default:
5850 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005851 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005852 qla83xx_idc_unlock(base_vha, 0);
5853 qla8xxx_dev_failed_handler(base_vha);
5854 rval = QLA_FUNCTION_FAILED;
5855 qla83xx_idc_lock(base_vha, 0);
5856 goto exit;
5857 }
5858 }
5859
5860exit:
5861 return rval;
5862}
5863
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005864void
5865qla2x00_disable_board_on_pci_error(struct work_struct *work)
5866{
5867 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5868 board_disable);
5869 struct pci_dev *pdev = ha->pdev;
5870 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5871
Quinn Tran726b8542017-01-19 22:28:00 -08005872 /*
5873 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005874 * where it was set first.
5875 */
5876 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5877 return;
5878
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005879 ql_log(ql_log_warn, base_vha, 0x015b,
5880 "Disabling adapter.\n");
5881
Sawan Chandakefdb5762017-08-23 15:05:00 -07005882 if (!atomic_read(&pdev->enable_cnt)) {
5883 ql_log(ql_log_info, base_vha, 0xfffc,
5884 "PCI device disabled, no action req for PCI error=%lx\n",
5885 base_vha->pci_flags);
5886 return;
5887 }
5888
Quinn Tran726b8542017-01-19 22:28:00 -08005889 qla2x00_wait_for_sess_deletion(base_vha);
5890
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005891 set_bit(UNLOADING, &base_vha->dpc_flags);
5892
5893 qla2x00_delete_all_vps(ha, base_vha);
5894
5895 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5896
5897 qla2x00_dfs_remove(base_vha);
5898
5899 qla84xx_put_chip(base_vha);
5900
5901 if (base_vha->timer_active)
5902 qla2x00_stop_timer(base_vha);
5903
5904 base_vha->flags.online = 0;
5905
5906 qla2x00_destroy_deferred_work(ha);
5907
5908 /*
5909 * Do not try to stop beacon blink as it will issue a mailbox
5910 * command.
5911 */
5912 qla2x00_free_sysfs_attr(base_vha, false);
5913
5914 fc_remove_host(base_vha->host);
5915
5916 scsi_remove_host(base_vha->host);
5917
5918 base_vha->flags.init_done = 0;
5919 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005920 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005921 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005922 qla2x00_mem_free(ha);
5923 qla82xx_md_free(base_vha);
5924 qla2x00_free_queues(ha);
5925
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005926 qla2x00_unmap_iobases(ha);
5927
5928 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005929 pci_disable_pcie_error_reporting(pdev);
5930 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005931
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005932 /*
5933 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5934 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005935}
5936
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937/**************************************************************************
5938* qla2x00_do_dpc
5939* This kernel thread is a task that is schedule by the interrupt handler
5940* to perform the background processing for interrupts.
5941*
5942* Notes:
5943* This task always run in the context of a kernel thread. It
5944* is kick-off by the driver's detect code and starts up
5945* up one per adapter. It immediately goes to sleep and waits for
5946* some fibre event. When either the interrupt handler or
5947* the timer routine detects a event it will one of the task
5948* bits then wake us up.
5949**************************************************************************/
5950static int
5951qla2x00_do_dpc(void *data)
5952{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005953 scsi_qla_host_t *base_vha;
5954 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005955 uint32_t online;
5956 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005957
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005958 ha = (struct qla_hw_data *)data;
5959 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960
Dongsheng Yang8698a742014-03-11 18:09:12 +08005961 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962
James Bottomley563585e2011-01-27 16:12:37 -05005963 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005964 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005965 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5966 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967
Christoph Hellwig39a11242006-02-14 18:46:22 +01005968 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005970 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5971 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972
Andrew Vasquez85880802009-12-15 21:29:46 -08005973 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005974 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5975 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005976 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005977 }
5978
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 ha->dpc_active = 1;
5980
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005981 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5982 "DPC handler waking up, dpc_flags=0x%lx.\n",
5983 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005985 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5986 break;
5987
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005988 if (IS_P3P_TYPE(ha)) {
5989 if (IS_QLA8044(ha)) {
5990 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5991 &base_vha->dpc_flags)) {
5992 qla8044_idc_lock(ha);
5993 qla8044_wr_direct(base_vha,
5994 QLA8044_CRB_DEV_STATE_INDEX,
5995 QLA8XXX_DEV_FAILED);
5996 qla8044_idc_unlock(ha);
5997 ql_log(ql_log_info, base_vha, 0x4004,
5998 "HW State: FAILED.\n");
5999 qla8044_device_state_handler(base_vha);
6000 continue;
6001 }
6002
6003 } else {
6004 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6005 &base_vha->dpc_flags)) {
6006 qla82xx_idc_lock(ha);
6007 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6008 QLA8XXX_DEV_FAILED);
6009 qla82xx_idc_unlock(ha);
6010 ql_log(ql_log_info, base_vha, 0x0151,
6011 "HW State: FAILED.\n");
6012 qla82xx_device_state_handler(base_vha);
6013 continue;
6014 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006015 }
6016
6017 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6018 &base_vha->dpc_flags)) {
6019
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006020 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6021 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006022 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6023 &base_vha->dpc_flags))) {
6024 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6025 /* FCoE-ctx reset failed.
6026 * Escalate to chip-reset
6027 */
6028 set_bit(ISP_ABORT_NEEDED,
6029 &base_vha->dpc_flags);
6030 }
6031 clear_bit(ABORT_ISP_ACTIVE,
6032 &base_vha->dpc_flags);
6033 }
6034
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006035 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6036 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006037 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006038 } else if (IS_QLAFX00(ha)) {
6039 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6040 &base_vha->dpc_flags)) {
6041 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6042 "Firmware Reset Recovery\n");
6043 if (qlafx00_reset_initialize(base_vha)) {
6044 /* Failed. Abort isp later. */
6045 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006046 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006047 set_bit(ISP_UNRECOVERABLE,
6048 &base_vha->dpc_flags);
6049 ql_dbg(ql_dbg_dpc, base_vha,
6050 0x4021,
6051 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006052 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006053 }
6054 }
6055
6056 if (test_and_clear_bit(FX00_TARGET_SCAN,
6057 &base_vha->dpc_flags)) {
6058 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6059 "ISPFx00 Target Scan scheduled\n");
6060 if (qlafx00_rescan_isp(base_vha)) {
6061 if (!test_bit(UNLOADING,
6062 &base_vha->dpc_flags))
6063 set_bit(ISP_UNRECOVERABLE,
6064 &base_vha->dpc_flags);
6065 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6066 "ISPFx00 Target Scan Failed\n");
6067 }
6068 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6069 "ISPFx00 Target Scan End\n");
6070 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006071 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6072 &base_vha->dpc_flags)) {
6073 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6074 "ISPFx00 Host Info resend scheduled\n");
6075 qlafx00_fx_disc(base_vha,
6076 &base_vha->hw->mr.fcport,
6077 FXDISC_REG_HOST_INFO);
6078 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006079 }
6080
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006081 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6082 &base_vha->dpc_flags) &&
6083 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6084 qla24xx_detect_sfp(base_vha);
6085
6086 if (ha->flags.detected_lr_sfp !=
6087 ha->flags.using_lr_setting)
6088 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6089 }
6090
Quinn Tranb08abbd2018-07-18 14:29:54 -07006091 if (test_and_clear_bit
6092 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6093 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006094 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095
Quinn Tran0645cb82018-09-11 10:18:18 -07006096 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006097 case QLA2XXX_INI_MODE_ENABLED:
6098 break;
6099 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006100 if (!qla_tgt_mode_enabled(base_vha) &&
6101 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006102 do_reset = false;
6103 break;
6104 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006105 if (!qla_dual_mode_enabled(base_vha) &&
6106 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006107 do_reset = false;
6108 break;
6109 default:
6110 break;
6111 }
6112
6113 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006114 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006115 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6116 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006117 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 /* failed. retry later */
6119 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006120 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006122 clear_bit(ABORT_ISP_ACTIVE,
6123 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006124 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6125 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127 }
6128
David Jefferya394aac2012-11-21 02:39:54 -05006129 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6130 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006131 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006132 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006133
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006134 if (IS_QLAFX00(ha))
6135 goto loop_resync_check;
6136
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006137 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006138 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6139 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006140 if (IS_P3P_TYPE(ha)) {
6141 if (IS_QLA82XX(ha))
6142 qla82xx_device_state_handler(base_vha);
6143 if (IS_QLA8044(ha))
6144 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006145 clear_bit(ISP_QUIESCE_NEEDED,
6146 &base_vha->dpc_flags);
6147 if (!ha->flags.quiesce_owner) {
6148 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006149 if (IS_QLA82XX(ha)) {
6150 qla82xx_idc_lock(ha);
6151 qla82xx_clear_qsnt_ready(
6152 base_vha);
6153 qla82xx_idc_unlock(ha);
6154 } else if (IS_QLA8044(ha)) {
6155 qla8044_idc_lock(ha);
6156 qla8044_clear_qsnt_ready(
6157 base_vha);
6158 qla8044_idc_unlock(ha);
6159 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006160 }
6161 } else {
6162 clear_bit(ISP_QUIESCE_NEEDED,
6163 &base_vha->dpc_flags);
6164 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006165 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006166 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6167 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006168 }
6169
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006170 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006171 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006172 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006174 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6175 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006176 qla2x00_rst_aen(base_vha);
6177 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006178 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6179 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 }
6181
6182 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006183 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006184 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6185 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186
Quinn Tran4005a992017-12-04 14:45:06 -08006187 if (!base_vha->relogin_jif ||
6188 time_after_eq(jiffies, base_vha->relogin_jif)) {
6189 base_vha->relogin_jif = jiffies + HZ;
6190 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6191
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006192 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006193 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006194 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006197loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006198 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006199 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006201 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6202 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203
6204 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006205 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206
Bart Van Assche52c82822015-07-09 07:23:26 -07006207 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006209 clear_bit(LOOP_RESYNC_ACTIVE,
6210 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 }
6212
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006213 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6214 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 }
6216
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006217 if (IS_QLAFX00(ha))
6218 goto intr_on_check;
6219
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006220 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6221 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6222 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6223 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006224 }
6225
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006226intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006228 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006230 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006231 &base_vha->dpc_flags)) {
6232 if (ha->beacon_blink_led == 1)
6233 ha->isp_ops->beacon_blink(base_vha);
6234 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006235
Michael Hernandezd7459522016-12-12 14:40:07 -08006236 /* qpair online check */
6237 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6238 &base_vha->dpc_flags)) {
6239 if (ha->flags.eeh_busy ||
6240 ha->flags.pci_channel_io_perm_failure)
6241 online = 0;
6242 else
6243 online = 1;
6244
6245 mutex_lock(&ha->mq_lock);
6246 list_for_each_entry(qpair, &base_vha->qp_list,
6247 qp_list_elem)
6248 qpair->online = online;
6249 mutex_unlock(&ha->mq_lock);
6250 }
6251
Quinn Tran8b4673b2018-09-04 14:19:14 -07006252 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6253 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006254 ql_log(ql_log_info, base_vha, 0xffffff,
6255 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6256 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006257 if (qla27xx_set_zio_threshold(base_vha,
6258 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006259 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006260 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6261 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006262 }
6263 }
6264
Quinn Tran8b4673b2018-09-04 14:19:14 -07006265 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6266 &base_vha->dpc_flags)) {
6267 ql_log(ql_log_info, base_vha, 0xffffff,
6268 "SET ZIO Activity exchange threshold to %d.\n",
6269 ha->last_zio_threshold);
6270 qla27xx_set_zio_threshold(base_vha,
6271 ha->last_zio_threshold);
6272 }
6273
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006274 if (!IS_QLAFX00(ha))
6275 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006276
Quinn Tran48acad02018-08-02 13:16:44 -07006277 if (test_and_clear_bit(N2N_LINK_RESET,
6278 &base_vha->dpc_flags)) {
6279 qla2x00_lip_reset(base_vha);
6280 }
6281
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006283end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006284 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006286 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006288 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6289 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290
6291 /*
6292 * Make sure that nobody tries to wake us up again.
6293 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 ha->dpc_active = 0;
6295
Andrew Vasquezac280b62009-08-20 11:06:05 -07006296 /* Cleanup any residual CTX SRBs. */
6297 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6298
Christoph Hellwig39a11242006-02-14 18:46:22 +01006299 return 0;
6300}
6301
6302void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006303qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006304{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006305 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006306 struct task_struct *t = ha->dpc_thread;
6307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006308 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006309 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310}
6311
6312/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313* qla2x00_rst_aen
6314* Processes asynchronous reset.
6315*
6316* Input:
6317* ha = adapter block pointer.
6318*/
6319static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006320qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006322 if (vha->flags.online && !vha->flags.reset_active &&
6323 !atomic_read(&vha->loop_down_timer) &&
6324 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006326 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327
6328 /*
6329 * Issue marker command only when we are going to start
6330 * the I/O.
6331 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006332 vha->marker_needed = 1;
6333 } while (!atomic_read(&vha->loop_down_timer) &&
6334 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 }
6336}
6337
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338/**************************************************************************
6339* qla2x00_timer
6340*
6341* Description:
6342* One second timer
6343*
6344* Context: Interrupt
6345***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006346void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006347qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006349 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 int start_dpc = 0;
6352 int index;
6353 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006354 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006355 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006356 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006357
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006358 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006359 ql_dbg(ql_dbg_timer, vha, 0x6000,
6360 "EEH = %d, restarting timer.\n",
6361 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006362 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6363 return;
6364 }
6365
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006366 /*
6367 * Hardware read to raise pending EEH errors during mailbox waits. If
6368 * the read returns -1 then disable the board.
6369 */
6370 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006371 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006372 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006375 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006376 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006377 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6378 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006379 if (IS_QLA82XX(ha))
6380 qla82xx_watchdog(vha);
6381 else if (IS_QLA8044(ha))
6382 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006383 }
6384
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006385 if (!vha->vp_idx && IS_QLAFX00(ha))
6386 qlafx00_timer_routine(vha);
6387
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006389 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006390 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6391 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006392 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006394 if (atomic_read(&vha->loop_down_timer) ==
6395 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006397 ql_log(ql_log_info, vha, 0x6008,
6398 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006400 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6401 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006403 /*
6404 * Schedule an ISP abort to return any FCP2-device
6405 * commands.
6406 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006407 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006408 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006409 spin_lock_irqsave(&ha->hardware_lock,
6410 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006411 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006412 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006413 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006414 index++) {
6415 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006416
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006417 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006418 if (!sp)
6419 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006420 if (sp->cmd_type != TYPE_SRB)
6421 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006422 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006423 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006424 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006425 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006426 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006428 if (IS_QLA82XX(ha))
6429 set_bit(FCOE_CTX_RESET_NEEDED,
6430 &vha->dpc_flags);
6431 else
6432 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006433 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006434 break;
6435 }
6436 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006437 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 start_dpc++;
6440 }
6441
6442 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006443 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006444 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006445 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 "Loop down - aborting ISP.\n");
6447
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006448 if (IS_QLA82XX(ha))
6449 set_bit(FCOE_CTX_RESET_NEEDED,
6450 &vha->dpc_flags);
6451 else
6452 set_bit(ISP_ABORT_NEEDED,
6453 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 }
6455 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006456 ql_dbg(ql_dbg_timer, vha, 0x600a,
6457 "Loop down - seconds remaining %d.\n",
6458 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006460 /* Check if beacon LED needs to be blinked for physical host only */
6461 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006462 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006463 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006464 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6465 start_dpc++;
6466 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006467 }
6468
Andrew Vasquez550bf572008-04-24 15:21:23 -07006469 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006470 if (!list_empty(&vha->work_list)) {
6471 unsigned long flags;
6472 bool q = false;
6473
6474 spin_lock_irqsave(&vha->work_lock, flags);
6475 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6476 q = true;
6477 spin_unlock_irqrestore(&vha->work_lock, flags);
6478 if (q)
6479 queue_work(vha->hw->wq, &vha->iocb_work);
6480 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006481
Duane Grigsby7401bc12017-06-21 13:48:42 -07006482 /*
6483 * FC-NVME
6484 * see if the active AEN count has changed from what was last reported.
6485 */
Quinn Tran8b4673b2018-09-04 14:19:14 -07006486 if (!vha->vp_idx && (atomic_read(&ha->nvme_active_aen_cnt) !=
6487 ha->nvme_last_rptd_aen) && ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006488 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006489 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6490 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006491 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006492 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6493 start_dpc++;
6494 }
6495
6496 if (!vha->vp_idx &&
6497 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6498 (ha->zio_mode == QLA_ZIO_MODE_6) &&
6499 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
6500 ql_log(ql_log_info, vha, 0x3002,
6501 "Sched: Set ZIO exchange threshold to %d.\n",
6502 ha->last_zio_threshold);
6503 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006504 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6505 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006506 }
6507
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006509 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6510 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6511 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006513 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6514 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006515 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6516 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006517 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006518 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006519 ql_dbg(ql_dbg_timer, vha, 0x600b,
6520 "isp_abort_needed=%d loop_resync_needed=%d "
6521 "fcport_update_needed=%d start_dpc=%d "
6522 "reset_marker_needed=%d",
6523 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6524 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6525 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6526 start_dpc,
6527 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6528 ql_dbg(ql_dbg_timer, vha, 0x600c,
6529 "beacon_blink_needed=%d isp_unrecoverable=%d "
6530 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006531 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006532 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6533 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6534 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6535 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006536 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006537 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006540 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541}
6542
Andrew Vasquez54333832005-11-09 15:49:04 -08006543/* Firmware interface routines. */
6544
Chad Dupuisf73cb692014-02-26 04:15:06 -05006545#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006546#define FW_ISP21XX 0
6547#define FW_ISP22XX 1
6548#define FW_ISP2300 2
6549#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006550#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006551#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006552#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006553#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006554#define FW_ISP2031 8
6555#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006556#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006557
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006558#define FW_FILE_ISP21XX "ql2100_fw.bin"
6559#define FW_FILE_ISP22XX "ql2200_fw.bin"
6560#define FW_FILE_ISP2300 "ql2300_fw.bin"
6561#define FW_FILE_ISP2322 "ql2322_fw.bin"
6562#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006563#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006564#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006565#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006566#define FW_FILE_ISP2031 "ql2600_fw.bin"
6567#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006568#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006569
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006570
Daniel Walkere1e82b62008-05-12 22:21:10 -07006571static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006572
6573static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006574 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6575 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6576 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6577 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6578 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006579 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006580 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006581 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006582 { .name = FW_FILE_ISP2031, },
6583 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006584 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006585};
6586
6587struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006588qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006589{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006590 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006591 struct fw_blob *blob;
6592
Andrew Vasquez54333832005-11-09 15:49:04 -08006593 if (IS_QLA2100(ha)) {
6594 blob = &qla_fw_blobs[FW_ISP21XX];
6595 } else if (IS_QLA2200(ha)) {
6596 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006597 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006598 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006599 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006600 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006601 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006602 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006603 } else if (IS_QLA25XX(ha)) {
6604 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006605 } else if (IS_QLA81XX(ha)) {
6606 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006607 } else if (IS_QLA82XX(ha)) {
6608 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006609 } else if (IS_QLA2031(ha)) {
6610 blob = &qla_fw_blobs[FW_ISP2031];
6611 } else if (IS_QLA8031(ha)) {
6612 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006613 } else if (IS_QLA27XX(ha)) {
6614 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006615 } else {
6616 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006617 }
6618
Daniel Walkere1e82b62008-05-12 22:21:10 -07006619 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006620 if (blob->fw)
6621 goto out;
6622
6623 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006624 ql_log(ql_log_warn, vha, 0x0063,
6625 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006626 blob->fw = NULL;
6627 blob = NULL;
6628 goto out;
6629 }
6630
6631out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006632 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006633 return blob;
6634}
6635
6636static void
6637qla2x00_release_firmware(void)
6638{
6639 int idx;
6640
Daniel Walkere1e82b62008-05-12 22:21:10 -07006641 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006642 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006643 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006644 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006645}
6646
Seokmann Ju14e660e2007-09-20 14:07:36 -07006647static pci_ers_result_t
6648qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6649{
Andrew Vasquez85880802009-12-15 21:29:46 -08006650 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6651 struct qla_hw_data *ha = vha->hw;
6652
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006653 ql_dbg(ql_dbg_aer, vha, 0x9000,
6654 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006655
Sawan Chandakefdb5762017-08-23 15:05:00 -07006656 if (!atomic_read(&pdev->enable_cnt)) {
6657 ql_log(ql_log_info, vha, 0xffff,
6658 "PCI device is disabled,state %x\n", state);
6659 return PCI_ERS_RESULT_NEED_RESET;
6660 }
6661
Seokmann Ju14e660e2007-09-20 14:07:36 -07006662 switch (state) {
6663 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006664 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006665 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006666 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6667 qla2xxx_wake_dpc(vha);
6668 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006669 return PCI_ERS_RESULT_CAN_RECOVER;
6670 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006671 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006672 /* For ISP82XX complete any pending mailbox cmd */
6673 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006674 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006675 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6676 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006677 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006678 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006679 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006680 /* Return back all IOs */
6681 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006682 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006683 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6684 qla2xxx_wake_dpc(vha);
6685 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006686 return PCI_ERS_RESULT_NEED_RESET;
6687 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006688 ha->flags.pci_channel_io_perm_failure = 1;
6689 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006690 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006691 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6692 qla2xxx_wake_dpc(vha);
6693 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006694 return PCI_ERS_RESULT_DISCONNECT;
6695 }
6696 return PCI_ERS_RESULT_NEED_RESET;
6697}
6698
6699static pci_ers_result_t
6700qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6701{
6702 int risc_paused = 0;
6703 uint32_t stat;
6704 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006705 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6706 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006707 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6708 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6709
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006710 if (IS_QLA82XX(ha))
6711 return PCI_ERS_RESULT_RECOVERED;
6712
Seokmann Ju14e660e2007-09-20 14:07:36 -07006713 spin_lock_irqsave(&ha->hardware_lock, flags);
6714 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6715 stat = RD_REG_DWORD(&reg->hccr);
6716 if (stat & HCCR_RISC_PAUSE)
6717 risc_paused = 1;
6718 } else if (IS_QLA23XX(ha)) {
6719 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6720 if (stat & HSR_RISC_PAUSED)
6721 risc_paused = 1;
6722 } else if (IS_FWI2_CAPABLE(ha)) {
6723 stat = RD_REG_DWORD(&reg24->host_status);
6724 if (stat & HSRX_RISC_PAUSED)
6725 risc_paused = 1;
6726 }
6727 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6728
6729 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006730 ql_log(ql_log_info, base_vha, 0x9003,
6731 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006732 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006733
6734 return PCI_ERS_RESULT_NEED_RESET;
6735 } else
6736 return PCI_ERS_RESULT_RECOVERED;
6737}
6738
Saurav Kashyapfa492632012-11-21 02:40:29 -05006739static uint32_t
6740qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006741{
6742 uint32_t rval = QLA_FUNCTION_FAILED;
6743 uint32_t drv_active = 0;
6744 struct qla_hw_data *ha = base_vha->hw;
6745 int fn;
6746 struct pci_dev *other_pdev = NULL;
6747
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006748 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6749 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006750
6751 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6752
6753 if (base_vha->flags.online) {
6754 /* Abort all outstanding commands,
6755 * so as to be requeued later */
6756 qla2x00_abort_isp_cleanup(base_vha);
6757 }
6758
6759
6760 fn = PCI_FUNC(ha->pdev->devfn);
6761 while (fn > 0) {
6762 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006763 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6764 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006765 other_pdev =
6766 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6767 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6768 fn));
6769
6770 if (!other_pdev)
6771 continue;
6772 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006773 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6774 "Found PCI func available and enable at 0x%x.\n",
6775 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006776 pci_dev_put(other_pdev);
6777 break;
6778 }
6779 pci_dev_put(other_pdev);
6780 }
6781
6782 if (!fn) {
6783 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006784 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6785 "This devfn is reset owner = 0x%x.\n",
6786 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006787 qla82xx_idc_lock(ha);
6788
6789 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006790 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006791
6792 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6793 QLA82XX_IDC_VERSION);
6794
6795 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006796 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6797 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006798
6799 qla82xx_idc_unlock(ha);
6800 /* Reset if device is not already reset
6801 * drv_active would be 0 if a reset has already been done
6802 */
6803 if (drv_active)
6804 rval = qla82xx_start_firmware(base_vha);
6805 else
6806 rval = QLA_SUCCESS;
6807 qla82xx_idc_lock(ha);
6808
6809 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006810 ql_log(ql_log_info, base_vha, 0x900b,
6811 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006812 qla82xx_clear_drv_active(ha);
6813 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006814 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006815 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006816 ql_log(ql_log_info, base_vha, 0x900c,
6817 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006818 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006819 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006820 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006821 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006822 rval = qla82xx_restart_isp(base_vha);
6823 qla82xx_idc_lock(ha);
6824 /* Clear driver state register */
6825 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6826 qla82xx_set_drv_active(base_vha);
6827 }
6828 qla82xx_idc_unlock(ha);
6829 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006830 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6831 "This devfn is not reset owner = 0x%x.\n",
6832 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006833 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006834 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006835 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006836 rval = qla82xx_restart_isp(base_vha);
6837 qla82xx_idc_lock(ha);
6838 qla82xx_set_drv_active(base_vha);
6839 qla82xx_idc_unlock(ha);
6840 }
6841 }
6842 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6843
6844 return rval;
6845}
6846
Seokmann Ju14e660e2007-09-20 14:07:36 -07006847static pci_ers_result_t
6848qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6849{
6850 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006851 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6852 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006853 struct rsp_que *rsp;
6854 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006855
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006856 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6857 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006858
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006859 /* Workaround: qla2xxx driver which access hardware earlier
6860 * needs error state to be pci_channel_io_online.
6861 * Otherwise mailbox command timesout.
6862 */
6863 pdev->error_state = pci_channel_io_normal;
6864
6865 pci_restore_state(pdev);
6866
Richard Lary8c1496b2010-02-18 10:07:29 -08006867 /* pci_restore_state() clears the saved_state flag of the device
6868 * save restored state which resets saved_state flag
6869 */
6870 pci_save_state(pdev);
6871
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006872 if (ha->mem_only)
6873 rc = pci_enable_device_mem(pdev);
6874 else
6875 rc = pci_enable_device(pdev);
6876
6877 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006878 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006879 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006880 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006881 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006882
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006883 rsp = ha->rsp_q_map[0];
6884 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006885 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006887 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006888 goto exit_slot_reset;
6889
6890 if (IS_QLA82XX(ha)) {
6891 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6892 ret = PCI_ERS_RESULT_RECOVERED;
6893 goto exit_slot_reset;
6894 } else
6895 goto exit_slot_reset;
6896 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006897
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006898 while (ha->flags.mbox_busy && retries--)
6899 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006901 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006902 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006903 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006904 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006905
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006906
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006907exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006908 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6909 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006910
Seokmann Ju14e660e2007-09-20 14:07:36 -07006911 return ret;
6912}
6913
6914static void
6915qla2xxx_pci_resume(struct pci_dev *pdev)
6916{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006917 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6918 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006919 int ret;
6920
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006921 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6922 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006924 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006925 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006926 ql_log(ql_log_fatal, base_vha, 0x9002,
6927 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006928 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006929
6930 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006931}
6932
Michael Hernandez56012362016-12-12 14:40:08 -08006933static int qla2xxx_map_queues(struct Scsi_Host *shost)
6934{
Quinn Trand68b8502017-12-04 14:44:59 -08006935 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006936 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6937
Quinn Trand68b8502017-12-04 14:44:59 -08006938 if (USER_CTRL_IRQ(vha->hw))
6939 rc = blk_mq_map_queues(&shost->tag_set);
6940 else
Keith Buschf23f5bec2018-03-27 09:39:06 -06006941 rc = blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev, 0);
Quinn Trand68b8502017-12-04 14:44:59 -08006942 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006943}
6944
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006945static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006946 .error_detected = qla2xxx_pci_error_detected,
6947 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6948 .slot_reset = qla2xxx_pci_slot_reset,
6949 .resume = qla2xxx_pci_resume,
6950};
6951
Andrew Vasquez54333832005-11-09 15:49:04 -08006952static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006953 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6954 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6955 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6956 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6957 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6958 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6959 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6960 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6961 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006962 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006963 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6964 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006965 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006966 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006967 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006968 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006969 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006970 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006971 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006972 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006973 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006974 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006975 { 0 },
6976};
6977MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6978
Andrew Vasquezfca29702005-07-06 10:31:47 -07006979static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006980 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006981 .driver = {
6982 .owner = THIS_MODULE,
6983 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006984 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006985 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006986 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006987 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006988 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006989};
6990
Al Viro75ef9de2013-04-04 19:09:41 -04006991static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006992 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006993 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006994};
6995
Linus Torvalds1da177e2005-04-16 15:20:36 -07006996/**
6997 * qla2x00_module_init - Module initialization.
6998 **/
6999static int __init
7000qla2x00_module_init(void)
7001{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007002 int ret = 0;
7003
Linus Torvalds1da177e2005-04-16 15:20:36 -07007004 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007005 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007006 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007008 ql_log(ql_log_fatal, NULL, 0x0001,
7009 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010 return -ENOMEM;
7011 }
7012
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007013 /* Initialize target kmem_cache and mem_pools */
7014 ret = qlt_init();
7015 if (ret < 0) {
7016 kmem_cache_destroy(srb_cachep);
7017 return ret;
7018 } else if (ret > 0) {
7019 /*
7020 * If initiator mode is explictly disabled by qlt_init(),
7021 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7022 * performing scsi_scan_target() during LOOP UP event.
7023 */
7024 qla2xxx_transport_functions.disable_target_scan = 1;
7025 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7026 }
7027
Linus Torvalds1da177e2005-04-16 15:20:36 -07007028 /* Derive version string. */
7029 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007030 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007031 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007032 if (ql2xextended_error_logging == 1)
7033 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007034
Quinn Tran0645cb82018-09-11 10:18:18 -07007035 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7036 qla_insert_tgt_attrs();
7037
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007038 qla2xxx_transport_template =
7039 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007040 if (!qla2xxx_transport_template) {
7041 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007042 ql_log(ql_log_fatal, NULL, 0x0002,
7043 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007044 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007046 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007047
7048 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7049 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007050 ql_log(ql_log_fatal, NULL, 0x0003,
7051 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007052 }
7053
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007054 qla2xxx_transport_vport_template =
7055 fc_attach_transport(&qla2xxx_transport_vport_functions);
7056 if (!qla2xxx_transport_vport_template) {
7057 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007058 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007059 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007060 ql_log(ql_log_fatal, NULL, 0x0004,
7061 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007062 return -ENODEV;
7063 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007064 ql_log(ql_log_info, NULL, 0x0005,
7065 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007066 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007067 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007068 if (ret) {
7069 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007070 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07007071 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007072 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007073 ql_log(ql_log_fatal, NULL, 0x0006,
7074 "pci_register_driver failed...ret=%d Failing load!.\n",
7075 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007076 }
7077 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007078}
7079
7080/**
7081 * qla2x00_module_exit - Module cleanup.
7082 **/
7083static void __exit
7084qla2x00_module_exit(void)
7085{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007086 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007087 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007088 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007089 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007090 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07007091 if (ctx_cachep)
7092 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007093 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007094 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095}
7096
7097module_init(qla2x00_module_init);
7098module_exit(qla2x00_module_exit);
7099
7100MODULE_AUTHOR("QLogic Corporation");
7101MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7102MODULE_LICENSE("GPL");
7103MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007104MODULE_FIRMWARE(FW_FILE_ISP21XX);
7105MODULE_FIRMWARE(FW_FILE_ISP22XX);
7106MODULE_FIRMWARE(FW_FILE_ISP2300);
7107MODULE_FIRMWARE(FW_FILE_ISP2322);
7108MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007109MODULE_FIRMWARE(FW_FILE_ISP25XX);