blob: 429033ab6897b6745fb1afcef27ae63a76f6cdcf [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) {
860 if (shost_use_blk_mq(vha->host)) {
861 tag = blk_mq_unique_tag(cmd->request);
862 hwq = blk_mq_unique_tag_to_hwq(tag);
863 qpair = ha->queue_pair_map[hwq];
864 } else if (vha->vp_idx && vha->qpair) {
865 qpair = vha->qpair;
866 }
867
868 if (qpair)
869 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800870 }
871
Andrew Vasquez85880802009-12-15 21:29:46 -0800872 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700873 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400874 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700875 "PCI Channel IO permanent failure, exiting "
876 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700877 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700878 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400879 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700880 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800881 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700882 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700883 goto qc24_fail_command;
884 }
885
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400886 rval = fc_remote_port_chkready(rport);
887 if (rval) {
888 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400889 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700890 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
891 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700892 goto qc24_fail_command;
893 }
894
Arun Easibad75002010-05-04 15:01:30 -0700895 if (!vha->flags.difdix_supported &&
896 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700897 ql_dbg(ql_dbg_io, vha, 0x3004,
898 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
899 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700900 cmd->result = DID_NO_CONNECT << 16;
901 goto qc24_fail_command;
902 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800903
904 if (!fcport) {
905 cmd->result = DID_NO_CONNECT << 16;
906 goto qc24_fail_command;
907 }
908
Andrew Vasquezfca29702005-07-06 10:31:47 -0700909 if (atomic_read(&fcport->state) != FCS_ONLINE) {
910 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700911 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700912 ql_dbg(ql_dbg_io, vha, 0x3005,
913 "Returning DNC, fcport_state=%d loop_state=%d.\n",
914 atomic_read(&fcport->state),
915 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700916 cmd->result = DID_NO_CONNECT << 16;
917 goto qc24_fail_command;
918 }
Mike Christie7b594132008-08-17 15:24:40 -0500919 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700920 }
921
Chad Dupuise05fe292014-09-25 05:16:59 -0400922 /*
923 * Return target busy if we've received a non-zero retry_delay_timer
924 * in a FCP_RSP.
925 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100926 if (fcport->retry_delay_timestamp == 0) {
927 /* retry delay not set */
928 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400929 fcport->retry_delay_timestamp = 0;
930 else
931 goto qc24_target_busy;
932
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500933 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400934 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800935 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700936
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800937 sp->u.scmd.cmd = cmd;
938 sp->type = SRB_SCSI_CMD;
939 atomic_set(&sp->ref_count, 1);
940 CMD_SP(cmd) = (void *)sp;
941 sp->free = qla2x00_sp_free_dma;
942 sp->done = qla2x00_sp_compl;
943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800944 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500946 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700947 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700948 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700949 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700950
Andrew Vasquezfca29702005-07-06 10:31:47 -0700951 return 0;
952
953qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700954 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700955
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800956qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700957 return SCSI_MLQUEUE_HOST_BUSY;
958
Mike Christie7b594132008-08-17 15:24:40 -0500959qc24_target_busy:
960 return SCSI_MLQUEUE_TARGET_BUSY;
961
Andrew Vasquezfca29702005-07-06 10:31:47 -0700962qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800963 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700964
965 return 0;
966}
967
Michael Hernandezd7459522016-12-12 14:40:07 -0800968/* For MQ supported I/O */
969int
970qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
971 struct qla_qpair *qpair)
972{
973 scsi_qla_host_t *vha = shost_priv(host);
974 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
975 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
976 struct qla_hw_data *ha = vha->hw;
977 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
978 srb_t *sp;
979 int rval;
980
981 rval = fc_remote_port_chkready(rport);
982 if (rval) {
983 cmd->result = rval;
984 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
985 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
986 cmd, rval);
987 goto qc24_fail_command;
988 }
989
990 if (!fcport) {
991 cmd->result = DID_NO_CONNECT << 16;
992 goto qc24_fail_command;
993 }
994
995 if (atomic_read(&fcport->state) != FCS_ONLINE) {
996 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
997 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
998 ql_dbg(ql_dbg_io, vha, 0x3077,
999 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1000 atomic_read(&fcport->state),
1001 atomic_read(&base_vha->loop_state));
1002 cmd->result = DID_NO_CONNECT << 16;
1003 goto qc24_fail_command;
1004 }
1005 goto qc24_target_busy;
1006 }
1007
1008 /*
1009 * Return target busy if we've received a non-zero retry_delay_timer
1010 * in a FCP_RSP.
1011 */
1012 if (fcport->retry_delay_timestamp == 0) {
1013 /* retry delay not set */
1014 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1015 fcport->retry_delay_timestamp = 0;
1016 else
1017 goto qc24_target_busy;
1018
Quinn Tran6a629462018-09-04 14:19:15 -07001019 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001020 if (!sp)
1021 goto qc24_host_busy;
1022
1023 sp->u.scmd.cmd = cmd;
1024 sp->type = SRB_SCSI_CMD;
1025 atomic_set(&sp->ref_count, 1);
1026 CMD_SP(cmd) = (void *)sp;
1027 sp->free = qla2xxx_qpair_sp_free_dma;
1028 sp->done = qla2xxx_qpair_sp_compl;
1029 sp->qpair = qpair;
1030
1031 rval = ha->isp_ops->start_scsi_mq(sp);
1032 if (rval != QLA_SUCCESS) {
1033 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1034 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1035 if (rval == QLA_INTERFACE_ERROR)
1036 goto qc24_fail_command;
1037 goto qc24_host_busy_free_sp;
1038 }
1039
1040 return 0;
1041
1042qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001043 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001044
1045qc24_host_busy:
1046 return SCSI_MLQUEUE_HOST_BUSY;
1047
1048qc24_target_busy:
1049 return SCSI_MLQUEUE_TARGET_BUSY;
1050
1051qc24_fail_command:
1052 cmd->scsi_done(cmd);
1053
1054 return 0;
1055}
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057/*
1058 * qla2x00_eh_wait_on_command
1059 * Waits for the command to be returned by the Firmware for some
1060 * max time.
1061 *
1062 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 *
1065 * Return:
1066 * Not Found : 0
1067 * Found : 1
1068 */
1069static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001070qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001072#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001073#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001074 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001075 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1076 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001077 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Andrew Vasquez85880802009-12-15 21:29:46 -08001079 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1081 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001082 return ret;
1083 }
1084
Lalit Chandivaded9704322009-08-25 11:36:18 -07001085 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001086 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001087 }
1088 if (CMD_SP(cmd))
1089 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
f4f051e2005-04-17 15:02:26 -05001091 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092}
1093
1094/*
1095 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001096 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 * <= MAX_RETRIES_OF_ISP_ABORT or
1098 * finally HBA is disabled ie marked offline
1099 *
1100 * Input:
1101 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001102 *
1103 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 * Does context switching-Release SPIN_LOCK
1105 * (if any) before calling this routine.
1106 *
1107 * Return:
1108 * Success (Adapter is online) : 0
1109 * Failed (Adapter is offline/disabled) : 1
1110 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001111int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001114 int return_status;
1115 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001116 struct qla_hw_data *ha = vha->hw;
1117 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001119 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001120 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1121 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1122 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1123 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 msleep(1000);
1126 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001128 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 else
1130 return_status = QLA_FUNCTION_FAILED;
1131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 return (return_status);
1133}
1134
Quinn Tran726b8542017-01-19 22:28:00 -08001135static inline int test_fcport_count(scsi_qla_host_t *vha)
1136{
1137 struct qla_hw_data *ha = vha->hw;
1138 unsigned long flags;
1139 int res;
1140
1141 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001142 ql_dbg(ql_dbg_init, vha, 0x00ec,
1143 "tgt %p, fcport_count=%d\n",
1144 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001145 res = (vha->fcport_count == 0);
1146 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1147
1148 return res;
1149}
1150
1151/*
1152 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1153 * it has dependency on UNLOADING flag to stop device discovery
1154 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001155void
Quinn Tran726b8542017-01-19 22:28:00 -08001156qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1157{
1158 qla2x00_mark_all_devices_lost(vha, 0);
1159
Joe Carnucciob85e0952017-08-23 15:05:11 -07001160 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001161}
1162
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001163/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001164 * qla2x00_wait_for_hba_ready
1165 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001166 *
1167 * Input:
1168 * ha - pointer to host adapter structure
1169 *
1170 * Note:
1171 * Does context switching-Release SPIN_LOCK
1172 * (if any) before calling this routine.
1173 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001174 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001175static void
1176qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001177{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001178 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001179 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001180
Dan Carpenter1d483902016-08-03 21:42:32 +03001181 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1182 ha->flags.mbox_busy) ||
1183 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1184 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1185 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1186 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001187 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001188 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001189}
1190
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001191int
1192qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1193{
1194 int return_status;
1195 unsigned long wait_reset;
1196 struct qla_hw_data *ha = vha->hw;
1197 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1198
1199 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1200 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1201 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1202 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1203 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1204
1205 msleep(1000);
1206
1207 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1208 ha->flags.chip_reset_done)
1209 break;
1210 }
1211 if (ha->flags.chip_reset_done)
1212 return_status = QLA_SUCCESS;
1213 else
1214 return_status = QLA_FUNCTION_FAILED;
1215
1216 return return_status;
1217}
1218
Quinn Tran585def92018-09-04 14:19:20 -07001219static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001220sp_get(struct srb *sp)
1221{
Quinn Tran585def92018-09-04 14:19:20 -07001222 if (!refcount_inc_not_zero((refcount_t*)&sp->ref_count))
1223 /* kref get fail */
1224 return ENXIO;
1225 else
1226 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001227}
1228
Sawan Chandaka4655372016-07-06 11:14:32 -04001229#define ISP_REG_DISCONNECT 0xffffffffU
1230/**************************************************************************
1231* qla2x00_isp_reg_stat
1232*
1233* Description:
1234* Read the host status register of ISP before aborting the command.
1235*
1236* Input:
1237* ha = pointer to host adapter structure.
1238*
1239*
1240* Returns:
1241* Either true or false.
1242*
1243* Note: Return true if there is register disconnect.
1244**************************************************************************/
1245static inline
1246uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1247{
1248 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001249 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001250
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001251 if (IS_P3P_TYPE(ha))
1252 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1253 else
1254 return ((RD_REG_DWORD(&reg->host_status)) ==
1255 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001256}
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258/**************************************************************************
1259* qla2xxx_eh_abort
1260*
1261* Description:
1262* The abort function will abort the specified command.
1263*
1264* Input:
1265* cmd = Linux SCSI command packet to be aborted.
1266*
1267* Returns:
1268* Either SUCCESS or FAILED.
1269*
1270* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001271* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001273static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1275{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001276 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001277 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001278 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001279 unsigned int id;
1280 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001281 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001282 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001283 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001284 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Sawan Chandaka4655372016-07-06 11:14:32 -04001286 if (qla2x00_isp_reg_stat(ha)) {
1287 ql_log(ql_log_info, vha, 0x8042,
1288 "PCI/Register disconnect, exiting.\n");
1289 return FAILED;
1290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001292 ret = fc_block_scsi_eh(cmd);
1293 if (ret != 0)
1294 return ret;
1295 ret = SUCCESS;
1296
Mike Christie170babc2010-10-15 11:27:47 -07001297 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001298 if (!sp)
1299 return SUCCESS;
1300
1301 qpair = sp->qpair;
1302 if (!qpair)
1303 return SUCCESS;
1304
1305 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1306 if (!CMD_SP(cmd)) {
1307 /* there's a chance an interrupt could clear
1308 the ptr as part of done & free */
1309 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001310 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001311 }
Mike Christie170babc2010-10-15 11:27:47 -07001312
Quinn Tran585def92018-09-04 14:19:20 -07001313 if (sp_get(sp)){
1314 /* ref_count is already 0 */
1315 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1316 return SUCCESS;
1317 }
1318 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1319
1320 id = cmd->device->id;
1321 lun = cmd->device->lun;
1322
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001323 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001324 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1325 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001326
1327 /* Get a reference to the sp and drop the lock.*/
Mike Christie170babc2010-10-15 11:27:47 -07001328
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001329 rval = ha->isp_ops->abort_command(sp);
1330 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001331 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001332 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001333 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001334 ret = FAILED;
1335
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001336 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001337 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001338 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001339 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001340 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001341 wait = 1;
1342 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001343
Quinn Tran585def92018-09-04 14:19:20 -07001344 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1345 /*
1346 * Clear the slot in the oustanding_cmds array if we can't find the
1347 * command to reclaim the resources.
1348 */
1349 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
1350 vha->req->outstanding_cmds[sp->handle] = NULL;
1351
1352 /*
1353 * sp->done will do ref_count--
1354 * sp_get() took an extra count above
1355 */
1356 sp->done(sp, DID_RESET << 16);
f4f051e2005-04-17 15:02:26 -05001357
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001358 /* Did the command return during mailbox execution? */
1359 if (ret == FAILED && !CMD_SP(cmd))
1360 ret = SUCCESS;
1361
Quinn Tran585def92018-09-04 14:19:20 -07001362 if (!CMD_SP(cmd))
1363 wait = 0;
1364
1365 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1366
f4f051e2005-04-17 15:02:26 -05001367 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001368 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001371 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001372 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001377 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001378 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
f4f051e2005-04-17 15:02:26 -05001380 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381}
1382
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001383int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001384qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001385 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001387 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001388 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001389 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001390 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001391 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001392 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Andrew Vasquez523ec772008-04-03 13:13:24 -07001394 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001395
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001396 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001397 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001398 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001399 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001400 sp = req->outstanding_cmds[cnt];
1401 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001402 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001403 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001404 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001405 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001406 continue;
1407 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001408 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001409 switch (type) {
1410 case WAIT_HOST:
1411 match = 1;
1412 break;
1413 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001414 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001415 break;
1416 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001417 match = (cmd->device->id == t &&
1418 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001419 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001421 if (!match)
1422 continue;
1423
1424 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001425 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001426 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001428 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001429
1430 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Andrew Vasquez523ec772008-04-03 13:13:24 -07001433static char *reset_errors[] = {
1434 "HBA not online",
1435 "HBA not ready",
1436 "Task management failed",
1437 "Waiting for command completions",
1438};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Andrew Vasquez523ec772008-04-03 13:13:24 -07001440static int
1441__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001442 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001443{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001445 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1446 int err;
1447
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001448 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001449 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001450 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001451
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001452 err = fc_block_scsi_eh(cmd);
1453 if (err != 0)
1454 return err;
1455
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001456 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001457 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001458 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001459
1460 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001461 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1462 ql_log(ql_log_warn, vha, 0x800a,
1463 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001464 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001465 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001466 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001467 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001468 != QLA_SUCCESS) {
1469 ql_log(ql_log_warn, vha, 0x800c,
1470 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001471 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001472 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001473 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001474 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001475 cmd->device->lun, type) != QLA_SUCCESS) {
1476 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001477 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001478 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001479 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001480
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001481 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001482 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001483 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001484
1485 return SUCCESS;
1486
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001487eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001488 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001489 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001490 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1491 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001492 return FAILED;
1493}
1494
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001495static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1497{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1499 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Sawan Chandaka4655372016-07-06 11:14:32 -04001501 if (qla2x00_isp_reg_stat(ha)) {
1502 ql_log(ql_log_info, vha, 0x803e,
1503 "PCI/Register disconnect, exiting.\n");
1504 return FAILED;
1505 }
1506
Andrew Vasquez523ec772008-04-03 13:13:24 -07001507 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1508 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001512qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001514 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1515 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Sawan Chandaka4655372016-07-06 11:14:32 -04001517 if (qla2x00_isp_reg_stat(ha)) {
1518 ql_log(ql_log_info, vha, 0x803f,
1519 "PCI/Register disconnect, exiting.\n");
1520 return FAILED;
1521 }
1522
Andrew Vasquez523ec772008-04-03 13:13:24 -07001523 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1524 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527/**************************************************************************
1528* qla2xxx_eh_bus_reset
1529*
1530* Description:
1531* The bus reset function will reset the bus and abort any executing
1532* commands.
1533*
1534* Input:
1535* cmd = Linux SCSI command packet of the command that cause the
1536* bus reset.
1537*
1538* Returns:
1539* SUCCESS/FAILURE (defined as macro in scsi.h).
1540*
1541**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001542static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1544{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001545 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001546 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001547 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001548 unsigned int id;
1549 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001550 struct qla_hw_data *ha = vha->hw;
1551
1552 if (qla2x00_isp_reg_stat(ha)) {
1553 ql_log(ql_log_info, vha, 0x8040,
1554 "PCI/Register disconnect, exiting.\n");
1555 return FAILED;
1556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
f4f051e2005-04-17 15:02:26 -05001558 id = cmd->device->id;
1559 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001560
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001561 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001562 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001565 ret = fc_block_scsi_eh(cmd);
1566 if (ret != 0)
1567 return ret;
1568 ret = FAILED;
1569
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001570 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001571 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001573 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001574 ql_log(ql_log_fatal, vha, 0x8013,
1575 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001576 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
1578
Saurav Kashyapad5376892011-11-18 09:02:09 -08001579 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1580 ret = SUCCESS;
1581
f4f051e2005-04-17 15:02:26 -05001582 if (ret == FAILED)
1583 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001585 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001586 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001587 QLA_SUCCESS) {
1588 ql_log(ql_log_warn, vha, 0x8014,
1589 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001590 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
f4f051e2005-04-17 15:02:26 -05001593eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001594 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001595 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001596 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
f4f051e2005-04-17 15:02:26 -05001598 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
1600
1601/**************************************************************************
1602* qla2xxx_eh_host_reset
1603*
1604* Description:
1605* The reset function will reset the Adapter.
1606*
1607* Input:
1608* cmd = Linux SCSI command packet of the command that cause the
1609* adapter reset.
1610*
1611* Returns:
1612* Either SUCCESS or FAILED.
1613*
1614* Note:
1615**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001616static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1618{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001619 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001621 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001622 unsigned int id;
1623 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001624 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Sawan Chandaka4655372016-07-06 11:14:32 -04001626 if (qla2x00_isp_reg_stat(ha)) {
1627 ql_log(ql_log_info, vha, 0x8041,
1628 "PCI/Register disconnect, exiting.\n");
1629 schedule_work(&ha->board_disable);
1630 return SUCCESS;
1631 }
1632
f4f051e2005-04-17 15:02:26 -05001633 id = cmd->device->id;
1634 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001635
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001636 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001637 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Chad Dupuis63ee7072014-04-11 16:54:46 -04001639 /*
1640 * No point in issuing another reset if one is active. Also do not
1641 * attempt a reset if we are updating flash.
1642 */
1643 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001644 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001646 if (vha != base_vha) {
1647 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001648 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001650 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001651 if (!qla82xx_fcoe_ctx_reset(vha)) {
1652 /* Ctx reset success */
1653 ret = SUCCESS;
1654 goto eh_host_reset_lock;
1655 }
1656 /* fall thru if ctx reset failed */
1657 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001658 if (ha->wq)
1659 flush_workqueue(ha->wq);
1660
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001661 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001662 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1664 /* failed. schedule dpc to try */
1665 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1666
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001667 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1668 ql_log(ql_log_warn, vha, 0x802a,
1669 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001671 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 }
1673 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001677 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001679 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
f4f051e2005-04-17 15:02:26 -05001681eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001682 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001683 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001684 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
f4f051e2005-04-17 15:02:26 -05001686 return ret;
1687}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689/*
1690* qla2x00_loop_reset
1691* Issue loop reset.
1692*
1693* Input:
1694* ha = adapter block pointer.
1695*
1696* Returns:
1697* 0 = success
1698*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001699int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001702 int ret;
bdf79622005-04-17 15:06:53 -05001703 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001704 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Armen Baloyan58547712013-08-27 01:37:33 -04001706 if (IS_QLAFX00(ha)) {
1707 return qlafx00_loop_reset(vha);
1708 }
1709
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001710 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001711 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1712 if (fcport->port_type != FCT_TARGET)
1713 continue;
1714
1715 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1716 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001717 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001718 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001719 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001720 }
1721 }
1722 }
1723
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001724
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001725 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001726 atomic_set(&vha->loop_state, LOOP_DOWN);
1727 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1728 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001729 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001730 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001731 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1732 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 }
1735
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001736 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001737 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001738 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001739 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1740 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001741 }
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001744 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001746 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
1748
Quinn Tranbbead492017-12-28 12:33:13 -08001749static void
1750__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001751{
Quinn Tranbbead492017-12-28 12:33:13 -08001752 int cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001753 unsigned long flags;
1754 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001755 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001757 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001758 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1759 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001760
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001761 if (!ha->req_q_map)
1762 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001763 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1764 req = qp->req;
1765 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1766 sp = req->outstanding_cmds[cnt];
1767 if (sp) {
1768 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001769 switch (sp->cmd_type) {
1770 case TYPE_SRB:
Quinn Tran585def92018-09-04 14:19:20 -07001771 if (sp->type == SRB_NVME_CMD ||
1772 sp->type == SRB_NVME_LS) {
1773 if (!sp_get(sp)) {
1774 /* got sp */
Quinn Tran6b0431d2018-09-04 14:19:13 -07001775 spin_unlock_irqrestore
1776 (qp->qp_lock_ptr,
1777 flags);
1778 qla_nvme_abort(ha, sp, res);
1779 spin_lock_irqsave
Quinn Tran585def92018-09-04 14:19:20 -07001780 (qp->qp_lock_ptr, flags);
1781 }
1782 } else if (GET_CMD_SP(sp) &&
1783 !ha->flags.eeh_busy &&
1784 (!test_bit(ABORT_ISP_ACTIVE,
1785 &vha->dpc_flags)) &&
Sawan Chandakf99c5d2942018-09-11 10:18:14 -07001786 !qla2x00_isp_reg_stat(ha) &&
Quinn Tran585def92018-09-04 14:19:20 -07001787 (sp->type == SRB_SCSI_CMD)) {
1788 /*
1789 * Don't abort commands in adapter
1790 * during EEH recovery as it's not
1791 * accessible/responding.
1792 *
1793 * Get a reference to the sp and drop
1794 * the lock. The reference ensures this
1795 * sp->done() call and not the call in
1796 * qla2xxx_eh_abort() ends the SCSI cmd
1797 * (with result 'res').
1798 */
1799 if (!sp_get(sp)) {
Quinn Tran6b0431d2018-09-04 14:19:13 -07001800 spin_unlock_irqrestore
Quinn Tran585def92018-09-04 14:19:20 -07001801 (qp->qp_lock_ptr, flags);
Quinn Tran6b0431d2018-09-04 14:19:13 -07001802 status = qla2xxx_eh_abort(
1803 GET_CMD_SP(sp));
1804 spin_lock_irqsave
Quinn Tran585def92018-09-04 14:19:20 -07001805 (qp->qp_lock_ptr, flags);
Quinn Tran6b0431d2018-09-04 14:19:13 -07001806 }
Quinn Tranc5419e22017-06-13 20:47:16 -07001807 }
Quinn Tran585def92018-09-04 14:19:20 -07001808 sp->done(sp, res);
1809 break;
1810 case TYPE_TGT_CMD:
1811 if (!vha->hw->tgt.tgt_ops || !tgt ||
1812 qla_ini_mode_enabled(vha)) {
1813 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1814 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1815 vha->dpc_flags);
1816 continue;
1817 }
1818 cmd = (struct qla_tgt_cmd *)sp;
1819 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
1820 break;
1821 case TYPE_TGT_TMCMD:
1822 /*
1823 * Currently, only ABTS response gets on the
1824 * outstanding_cmds[]
1825 */
1826 ha->tgt.tgt_ops->free_mcmd(
1827 (struct qla_tgt_mgmt_cmd *)sp);
1828 break;
1829 default:
1830 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001831 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001832 }
1833 }
Quinn Tranbbead492017-12-28 12:33:13 -08001834 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1835}
1836
1837void
1838qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1839{
1840 int que;
1841 struct qla_hw_data *ha = vha->hw;
1842
1843 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1844
1845 for (que = 0; que < ha->max_qpairs; que++) {
1846 if (!ha->queue_pair_map[que])
1847 continue;
1848
1849 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1850 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001851}
1852
f4f051e2005-04-17 15:02:26 -05001853static int
1854qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
bdf79622005-04-17 15:06:53 -05001856 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001858 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001859 return -ENXIO;
1860
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001861 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001862
1863 return 0;
1864}
1865
1866static int
1867qla2xxx_slave_configure(struct scsi_device *sdev)
1868{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001869 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001870 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001871
Arun Easi9e522cd2012-08-22 14:21:31 -04001872 if (IS_T10_PI_CAPABLE(vha->hw))
1873 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1874
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001875 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001876 return 0;
1877}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
f4f051e2005-04-17 15:02:26 -05001879static void
1880qla2xxx_slave_destroy(struct scsi_device *sdev)
1881{
1882 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883}
1884
1885/**
1886 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1887 * @ha: HA context
1888 *
1889 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1890 * supported addressing method.
1891 */
1892static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001893qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001895 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
Yang Hongyang6a355282009-04-06 19:01:13 -07001898 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001899 /* Any upper-dword bits set? */
1900 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001901 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001902 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001904 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1905 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001906 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001909
Yang Hongyang284901a2009-04-06 19:01:15 -07001910 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1911 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912}
1913
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001914static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001916{
1917 unsigned long flags = 0;
1918 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1919
1920 spin_lock_irqsave(&ha->hardware_lock, flags);
1921 ha->interrupts_on = 1;
1922 /* enable risc and host interrupts */
1923 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1924 RD_REG_WORD(&reg->ictrl);
1925 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1926
1927}
1928
1929static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001930qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001931{
1932 unsigned long flags = 0;
1933 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1934
1935 spin_lock_irqsave(&ha->hardware_lock, flags);
1936 ha->interrupts_on = 0;
1937 /* disable risc and host interrupts */
1938 WRT_REG_WORD(&reg->ictrl, 0);
1939 RD_REG_WORD(&reg->ictrl);
1940 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1941}
1942
1943static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001945{
1946 unsigned long flags = 0;
1947 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1948
1949 spin_lock_irqsave(&ha->hardware_lock, flags);
1950 ha->interrupts_on = 1;
1951 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1952 RD_REG_DWORD(&reg->ictrl);
1953 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1954}
1955
1956static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001957qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001958{
1959 unsigned long flags = 0;
1960 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1961
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001962 if (IS_NOPOLLING_TYPE(ha))
1963 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001964 spin_lock_irqsave(&ha->hardware_lock, flags);
1965 ha->interrupts_on = 0;
1966 WRT_REG_DWORD(&reg->ictrl, 0);
1967 RD_REG_DWORD(&reg->ictrl);
1968 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1969}
1970
Giridhar Malavali706f4572011-11-18 09:03:16 -08001971static int
1972qla2x00_iospace_config(struct qla_hw_data *ha)
1973{
1974 resource_size_t pio;
1975 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001976
Giridhar Malavali706f4572011-11-18 09:03:16 -08001977 if (pci_request_selected_regions(ha->pdev, ha->bars,
1978 QLA2XXX_DRIVER_NAME)) {
1979 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1980 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1981 pci_name(ha->pdev));
1982 goto iospace_error_exit;
1983 }
1984 if (!(ha->bars & 1))
1985 goto skip_pio;
1986
1987 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1988 pio = pci_resource_start(ha->pdev, 0);
1989 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1990 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1991 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1992 "Invalid pci I/O region size (%s).\n",
1993 pci_name(ha->pdev));
1994 pio = 0;
1995 }
1996 } else {
1997 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1998 "Region #0 no a PIO resource (%s).\n",
1999 pci_name(ha->pdev));
2000 pio = 0;
2001 }
2002 ha->pio_address = pio;
2003 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2004 "PIO address=%llu.\n",
2005 (unsigned long long)ha->pio_address);
2006
2007skip_pio:
2008 /* Use MMIO operations for all accesses. */
2009 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2010 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2011 "Region #1 not an MMIO resource (%s), aborting.\n",
2012 pci_name(ha->pdev));
2013 goto iospace_error_exit;
2014 }
2015 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2016 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2017 "Invalid PCI mem region size (%s), aborting.\n",
2018 pci_name(ha->pdev));
2019 goto iospace_error_exit;
2020 }
2021
2022 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2023 if (!ha->iobase) {
2024 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2025 "Cannot remap MMIO (%s), aborting.\n",
2026 pci_name(ha->pdev));
2027 goto iospace_error_exit;
2028 }
2029
2030 /* Determine queue resources */
2031 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002032 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002033 if (!ql2xmqsupport || !ql2xnvmeenable ||
2034 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002035 goto mqiobase_exit;
2036
2037 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2038 pci_resource_len(ha->pdev, 3));
2039 if (ha->mqiobase) {
2040 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2041 "MQIO Base=%p.\n", ha->mqiobase);
2042 /* Read MSIX vector size of the board */
2043 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002044 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002045 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002046 /* MB interrupt uses 1 vector */
2047 ha->max_req_queues = ha->msix_count - 1;
2048 ha->max_rsp_queues = ha->max_req_queues;
2049 /* Queue pairs is the max value minus the base queue pair */
2050 ha->max_qpairs = ha->max_rsp_queues - 1;
2051 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2052 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2053
Giridhar Malavali706f4572011-11-18 09:03:16 -08002054 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002055 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002056 } else
2057 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2058 "BAR 3 not enabled.\n");
2059
2060mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002061 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002062 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002063 return (0);
2064
2065iospace_error_exit:
2066 return (-ENOMEM);
2067}
2068
2069
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002070static int
2071qla83xx_iospace_config(struct qla_hw_data *ha)
2072{
2073 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002074
2075 if (pci_request_selected_regions(ha->pdev, ha->bars,
2076 QLA2XXX_DRIVER_NAME)) {
2077 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2078 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2079 pci_name(ha->pdev));
2080
2081 goto iospace_error_exit;
2082 }
2083
2084 /* Use MMIO operations for all accesses. */
2085 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2086 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2087 "Invalid pci I/O region size (%s).\n",
2088 pci_name(ha->pdev));
2089 goto iospace_error_exit;
2090 }
2091 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2092 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2093 "Invalid PCI mem region size (%s), aborting\n",
2094 pci_name(ha->pdev));
2095 goto iospace_error_exit;
2096 }
2097
2098 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2099 if (!ha->iobase) {
2100 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2101 "Cannot remap MMIO (%s), aborting.\n",
2102 pci_name(ha->pdev));
2103 goto iospace_error_exit;
2104 }
2105
2106 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2107 /* 83XX 26XX always use MQ type access for queues
2108 * - mbar 2, a.k.a region 4 */
2109 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002110 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002111 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2112 pci_resource_len(ha->pdev, 4));
2113
2114 if (!ha->mqiobase) {
2115 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2116 "BAR2/region4 not enabled\n");
2117 goto mqiobase_exit;
2118 }
2119
2120 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2121 pci_resource_len(ha->pdev, 2));
2122 if (ha->msixbase) {
2123 /* Read MSIX vector size of the board */
2124 pci_read_config_word(ha->pdev,
2125 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002126 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002127 /*
2128 * By default, driver uses at least two msix vectors
2129 * (default & rspq)
2130 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002131 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002132 /* MB interrupt uses 1 vector */
2133 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002134
2135 /* ATIOQ needs 1 vector. That's 1 less QPair */
2136 if (QLA_TGT_MODE_ENABLED())
2137 ha->max_req_queues--;
2138
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002139 ha->max_rsp_queues = ha->max_req_queues;
2140
Michael Hernandezd7459522016-12-12 14:40:07 -08002141 /* Queue pairs is the max value minus
2142 * the base queue pair */
2143 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002144 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002145 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002146 }
2147 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002148 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002149 } else
2150 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2151 "BAR 1 not enabled.\n");
2152
2153mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002154 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002155 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002156 return 0;
2157
2158iospace_error_exit:
2159 return -ENOMEM;
2160}
2161
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002162static struct isp_operations qla2100_isp_ops = {
2163 .pci_config = qla2100_pci_config,
2164 .reset_chip = qla2x00_reset_chip,
2165 .chip_diag = qla2x00_chip_diag,
2166 .config_rings = qla2x00_config_rings,
2167 .reset_adapter = qla2x00_reset_adapter,
2168 .nvram_config = qla2x00_nvram_config,
2169 .update_fw_options = qla2x00_update_fw_options,
2170 .load_risc = qla2x00_load_risc,
2171 .pci_info_str = qla2x00_pci_info_str,
2172 .fw_version_str = qla2x00_fw_version_str,
2173 .intr_handler = qla2100_intr_handler,
2174 .enable_intrs = qla2x00_enable_intrs,
2175 .disable_intrs = qla2x00_disable_intrs,
2176 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002177 .target_reset = qla2x00_abort_target,
2178 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002179 .fabric_login = qla2x00_login_fabric,
2180 .fabric_logout = qla2x00_fabric_logout,
2181 .calc_req_entries = qla2x00_calc_iocbs_32,
2182 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2183 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2184 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2185 .read_nvram = qla2x00_read_nvram_data,
2186 .write_nvram = qla2x00_write_nvram_data,
2187 .fw_dump = qla2100_fw_dump,
2188 .beacon_on = NULL,
2189 .beacon_off = NULL,
2190 .beacon_blink = NULL,
2191 .read_optrom = qla2x00_read_optrom_data,
2192 .write_optrom = qla2x00_write_optrom_data,
2193 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002195 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002196 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002197 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002198 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002199};
2200
2201static struct isp_operations qla2300_isp_ops = {
2202 .pci_config = qla2300_pci_config,
2203 .reset_chip = qla2x00_reset_chip,
2204 .chip_diag = qla2x00_chip_diag,
2205 .config_rings = qla2x00_config_rings,
2206 .reset_adapter = qla2x00_reset_adapter,
2207 .nvram_config = qla2x00_nvram_config,
2208 .update_fw_options = qla2x00_update_fw_options,
2209 .load_risc = qla2x00_load_risc,
2210 .pci_info_str = qla2x00_pci_info_str,
2211 .fw_version_str = qla2x00_fw_version_str,
2212 .intr_handler = qla2300_intr_handler,
2213 .enable_intrs = qla2x00_enable_intrs,
2214 .disable_intrs = qla2x00_disable_intrs,
2215 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002216 .target_reset = qla2x00_abort_target,
2217 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002218 .fabric_login = qla2x00_login_fabric,
2219 .fabric_logout = qla2x00_fabric_logout,
2220 .calc_req_entries = qla2x00_calc_iocbs_32,
2221 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2222 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2223 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2224 .read_nvram = qla2x00_read_nvram_data,
2225 .write_nvram = qla2x00_write_nvram_data,
2226 .fw_dump = qla2300_fw_dump,
2227 .beacon_on = qla2x00_beacon_on,
2228 .beacon_off = qla2x00_beacon_off,
2229 .beacon_blink = qla2x00_beacon_blink,
2230 .read_optrom = qla2x00_read_optrom_data,
2231 .write_optrom = qla2x00_write_optrom_data,
2232 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002233 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002234 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002235 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002236 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002237 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002238};
2239
2240static struct isp_operations qla24xx_isp_ops = {
2241 .pci_config = qla24xx_pci_config,
2242 .reset_chip = qla24xx_reset_chip,
2243 .chip_diag = qla24xx_chip_diag,
2244 .config_rings = qla24xx_config_rings,
2245 .reset_adapter = qla24xx_reset_adapter,
2246 .nvram_config = qla24xx_nvram_config,
2247 .update_fw_options = qla24xx_update_fw_options,
2248 .load_risc = qla24xx_load_risc,
2249 .pci_info_str = qla24xx_pci_info_str,
2250 .fw_version_str = qla24xx_fw_version_str,
2251 .intr_handler = qla24xx_intr_handler,
2252 .enable_intrs = qla24xx_enable_intrs,
2253 .disable_intrs = qla24xx_disable_intrs,
2254 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002255 .target_reset = qla24xx_abort_target,
2256 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002257 .fabric_login = qla24xx_login_fabric,
2258 .fabric_logout = qla24xx_fabric_logout,
2259 .calc_req_entries = NULL,
2260 .build_iocbs = NULL,
2261 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2262 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2263 .read_nvram = qla24xx_read_nvram_data,
2264 .write_nvram = qla24xx_write_nvram_data,
2265 .fw_dump = qla24xx_fw_dump,
2266 .beacon_on = qla24xx_beacon_on,
2267 .beacon_off = qla24xx_beacon_off,
2268 .beacon_blink = qla24xx_beacon_blink,
2269 .read_optrom = qla24xx_read_optrom_data,
2270 .write_optrom = qla24xx_write_optrom_data,
2271 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002272 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002273 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002274 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002275 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002276 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002277};
2278
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002279static struct isp_operations qla25xx_isp_ops = {
2280 .pci_config = qla25xx_pci_config,
2281 .reset_chip = qla24xx_reset_chip,
2282 .chip_diag = qla24xx_chip_diag,
2283 .config_rings = qla24xx_config_rings,
2284 .reset_adapter = qla24xx_reset_adapter,
2285 .nvram_config = qla24xx_nvram_config,
2286 .update_fw_options = qla24xx_update_fw_options,
2287 .load_risc = qla24xx_load_risc,
2288 .pci_info_str = qla24xx_pci_info_str,
2289 .fw_version_str = qla24xx_fw_version_str,
2290 .intr_handler = qla24xx_intr_handler,
2291 .enable_intrs = qla24xx_enable_intrs,
2292 .disable_intrs = qla24xx_disable_intrs,
2293 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002294 .target_reset = qla24xx_abort_target,
2295 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002296 .fabric_login = qla24xx_login_fabric,
2297 .fabric_logout = qla24xx_fabric_logout,
2298 .calc_req_entries = NULL,
2299 .build_iocbs = NULL,
2300 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2301 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2302 .read_nvram = qla25xx_read_nvram_data,
2303 .write_nvram = qla25xx_write_nvram_data,
2304 .fw_dump = qla25xx_fw_dump,
2305 .beacon_on = qla24xx_beacon_on,
2306 .beacon_off = qla24xx_beacon_off,
2307 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002308 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002309 .write_optrom = qla24xx_write_optrom_data,
2310 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002311 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002312 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002313 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002314 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002315 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002316};
2317
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002318static struct isp_operations qla81xx_isp_ops = {
2319 .pci_config = qla25xx_pci_config,
2320 .reset_chip = qla24xx_reset_chip,
2321 .chip_diag = qla24xx_chip_diag,
2322 .config_rings = qla24xx_config_rings,
2323 .reset_adapter = qla24xx_reset_adapter,
2324 .nvram_config = qla81xx_nvram_config,
2325 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002326 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002327 .pci_info_str = qla24xx_pci_info_str,
2328 .fw_version_str = qla24xx_fw_version_str,
2329 .intr_handler = qla24xx_intr_handler,
2330 .enable_intrs = qla24xx_enable_intrs,
2331 .disable_intrs = qla24xx_disable_intrs,
2332 .abort_command = qla24xx_abort_command,
2333 .target_reset = qla24xx_abort_target,
2334 .lun_reset = qla24xx_lun_reset,
2335 .fabric_login = qla24xx_login_fabric,
2336 .fabric_logout = qla24xx_fabric_logout,
2337 .calc_req_entries = NULL,
2338 .build_iocbs = NULL,
2339 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2340 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002341 .read_nvram = NULL,
2342 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002343 .fw_dump = qla81xx_fw_dump,
2344 .beacon_on = qla24xx_beacon_on,
2345 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002346 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002347 .read_optrom = qla25xx_read_optrom_data,
2348 .write_optrom = qla24xx_write_optrom_data,
2349 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002350 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002351 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002352 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002353 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002354 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002355};
2356
2357static struct isp_operations qla82xx_isp_ops = {
2358 .pci_config = qla82xx_pci_config,
2359 .reset_chip = qla82xx_reset_chip,
2360 .chip_diag = qla24xx_chip_diag,
2361 .config_rings = qla82xx_config_rings,
2362 .reset_adapter = qla24xx_reset_adapter,
2363 .nvram_config = qla81xx_nvram_config,
2364 .update_fw_options = qla24xx_update_fw_options,
2365 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002366 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002367 .fw_version_str = qla24xx_fw_version_str,
2368 .intr_handler = qla82xx_intr_handler,
2369 .enable_intrs = qla82xx_enable_intrs,
2370 .disable_intrs = qla82xx_disable_intrs,
2371 .abort_command = qla24xx_abort_command,
2372 .target_reset = qla24xx_abort_target,
2373 .lun_reset = qla24xx_lun_reset,
2374 .fabric_login = qla24xx_login_fabric,
2375 .fabric_logout = qla24xx_fabric_logout,
2376 .calc_req_entries = NULL,
2377 .build_iocbs = NULL,
2378 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2379 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2380 .read_nvram = qla24xx_read_nvram_data,
2381 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002382 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002383 .beacon_on = qla82xx_beacon_on,
2384 .beacon_off = qla82xx_beacon_off,
2385 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002386 .read_optrom = qla82xx_read_optrom_data,
2387 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002388 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002389 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002390 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002391 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002392 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002393 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002394};
2395
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002396static struct isp_operations qla8044_isp_ops = {
2397 .pci_config = qla82xx_pci_config,
2398 .reset_chip = qla82xx_reset_chip,
2399 .chip_diag = qla24xx_chip_diag,
2400 .config_rings = qla82xx_config_rings,
2401 .reset_adapter = qla24xx_reset_adapter,
2402 .nvram_config = qla81xx_nvram_config,
2403 .update_fw_options = qla24xx_update_fw_options,
2404 .load_risc = qla82xx_load_risc,
2405 .pci_info_str = qla24xx_pci_info_str,
2406 .fw_version_str = qla24xx_fw_version_str,
2407 .intr_handler = qla8044_intr_handler,
2408 .enable_intrs = qla82xx_enable_intrs,
2409 .disable_intrs = qla82xx_disable_intrs,
2410 .abort_command = qla24xx_abort_command,
2411 .target_reset = qla24xx_abort_target,
2412 .lun_reset = qla24xx_lun_reset,
2413 .fabric_login = qla24xx_login_fabric,
2414 .fabric_logout = qla24xx_fabric_logout,
2415 .calc_req_entries = NULL,
2416 .build_iocbs = NULL,
2417 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2418 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2419 .read_nvram = NULL,
2420 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002421 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002422 .beacon_on = qla82xx_beacon_on,
2423 .beacon_off = qla82xx_beacon_off,
2424 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002425 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002426 .write_optrom = qla8044_write_optrom_data,
2427 .get_flash_version = qla82xx_get_flash_version,
2428 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002429 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002430 .abort_isp = qla8044_abort_isp,
2431 .iospace_config = qla82xx_iospace_config,
2432 .initialize_adapter = qla2x00_initialize_adapter,
2433};
2434
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002435static struct isp_operations qla83xx_isp_ops = {
2436 .pci_config = qla25xx_pci_config,
2437 .reset_chip = qla24xx_reset_chip,
2438 .chip_diag = qla24xx_chip_diag,
2439 .config_rings = qla24xx_config_rings,
2440 .reset_adapter = qla24xx_reset_adapter,
2441 .nvram_config = qla81xx_nvram_config,
2442 .update_fw_options = qla81xx_update_fw_options,
2443 .load_risc = qla81xx_load_risc,
2444 .pci_info_str = qla24xx_pci_info_str,
2445 .fw_version_str = qla24xx_fw_version_str,
2446 .intr_handler = qla24xx_intr_handler,
2447 .enable_intrs = qla24xx_enable_intrs,
2448 .disable_intrs = qla24xx_disable_intrs,
2449 .abort_command = qla24xx_abort_command,
2450 .target_reset = qla24xx_abort_target,
2451 .lun_reset = qla24xx_lun_reset,
2452 .fabric_login = qla24xx_login_fabric,
2453 .fabric_logout = qla24xx_fabric_logout,
2454 .calc_req_entries = NULL,
2455 .build_iocbs = NULL,
2456 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2457 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2458 .read_nvram = NULL,
2459 .write_nvram = NULL,
2460 .fw_dump = qla83xx_fw_dump,
2461 .beacon_on = qla24xx_beacon_on,
2462 .beacon_off = qla24xx_beacon_off,
2463 .beacon_blink = qla83xx_beacon_blink,
2464 .read_optrom = qla25xx_read_optrom_data,
2465 .write_optrom = qla24xx_write_optrom_data,
2466 .get_flash_version = qla24xx_get_flash_version,
2467 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002468 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002469 .abort_isp = qla2x00_abort_isp,
2470 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002471 .initialize_adapter = qla2x00_initialize_adapter,
2472};
2473
2474static struct isp_operations qlafx00_isp_ops = {
2475 .pci_config = qlafx00_pci_config,
2476 .reset_chip = qlafx00_soft_reset,
2477 .chip_diag = qlafx00_chip_diag,
2478 .config_rings = qlafx00_config_rings,
2479 .reset_adapter = qlafx00_soft_reset,
2480 .nvram_config = NULL,
2481 .update_fw_options = NULL,
2482 .load_risc = NULL,
2483 .pci_info_str = qlafx00_pci_info_str,
2484 .fw_version_str = qlafx00_fw_version_str,
2485 .intr_handler = qlafx00_intr_handler,
2486 .enable_intrs = qlafx00_enable_intrs,
2487 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002488 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002489 .target_reset = qlafx00_abort_target,
2490 .lun_reset = qlafx00_lun_reset,
2491 .fabric_login = NULL,
2492 .fabric_logout = NULL,
2493 .calc_req_entries = NULL,
2494 .build_iocbs = NULL,
2495 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2496 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2497 .read_nvram = qla24xx_read_nvram_data,
2498 .write_nvram = qla24xx_write_nvram_data,
2499 .fw_dump = NULL,
2500 .beacon_on = qla24xx_beacon_on,
2501 .beacon_off = qla24xx_beacon_off,
2502 .beacon_blink = NULL,
2503 .read_optrom = qla24xx_read_optrom_data,
2504 .write_optrom = qla24xx_write_optrom_data,
2505 .get_flash_version = qla24xx_get_flash_version,
2506 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002507 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002508 .abort_isp = qlafx00_abort_isp,
2509 .iospace_config = qlafx00_iospace_config,
2510 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002511};
2512
Chad Dupuisf73cb692014-02-26 04:15:06 -05002513static struct isp_operations qla27xx_isp_ops = {
2514 .pci_config = qla25xx_pci_config,
2515 .reset_chip = qla24xx_reset_chip,
2516 .chip_diag = qla24xx_chip_diag,
2517 .config_rings = qla24xx_config_rings,
2518 .reset_adapter = qla24xx_reset_adapter,
2519 .nvram_config = qla81xx_nvram_config,
2520 .update_fw_options = qla81xx_update_fw_options,
2521 .load_risc = qla81xx_load_risc,
2522 .pci_info_str = qla24xx_pci_info_str,
2523 .fw_version_str = qla24xx_fw_version_str,
2524 .intr_handler = qla24xx_intr_handler,
2525 .enable_intrs = qla24xx_enable_intrs,
2526 .disable_intrs = qla24xx_disable_intrs,
2527 .abort_command = qla24xx_abort_command,
2528 .target_reset = qla24xx_abort_target,
2529 .lun_reset = qla24xx_lun_reset,
2530 .fabric_login = qla24xx_login_fabric,
2531 .fabric_logout = qla24xx_fabric_logout,
2532 .calc_req_entries = NULL,
2533 .build_iocbs = NULL,
2534 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2535 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2536 .read_nvram = NULL,
2537 .write_nvram = NULL,
2538 .fw_dump = qla27xx_fwdump,
2539 .beacon_on = qla24xx_beacon_on,
2540 .beacon_off = qla24xx_beacon_off,
2541 .beacon_blink = qla83xx_beacon_blink,
2542 .read_optrom = qla25xx_read_optrom_data,
2543 .write_optrom = qla24xx_write_optrom_data,
2544 .get_flash_version = qla24xx_get_flash_version,
2545 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002546 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002547 .abort_isp = qla2x00_abort_isp,
2548 .iospace_config = qla83xx_iospace_config,
2549 .initialize_adapter = qla2x00_initialize_adapter,
2550};
2551
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002552static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002553qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002554{
2555 ha->device_type = DT_EXTENDED_IDS;
2556 switch (ha->pdev->device) {
2557 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002558 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002559 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002560 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002561 break;
2562 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002563 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002564 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002565 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002566 break;
2567 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002568 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002569 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002570 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002571 break;
2572 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002573 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002574 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002575 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002576 break;
2577 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002578 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002579 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002580 if (ha->pdev->subsystem_vendor == 0x1028 &&
2581 ha->pdev->subsystem_device == 0x0170)
2582 ha->device_type |= DT_OEM_001;
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_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002586 ha->isp_type |= DT_ISP6312;
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_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002590 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002591 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002592 break;
2593 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002594 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002595 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002596 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002597 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002598 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002599 break;
2600 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002601 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002602 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002603 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002604 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002605 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002606 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002607 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002608 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002609 ha->device_type |= DT_ZIO_SUPPORTED;
2610 ha->device_type |= DT_FWI2;
2611 ha->device_type |= DT_IIDMA;
2612 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2613 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002614 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002615 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002616 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002617 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002618 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002619 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002620 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002621 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002622 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002623 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002624 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002625 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002626 ha->device_type |= DT_ZIO_SUPPORTED;
2627 ha->device_type |= DT_FWI2;
2628 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002629 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2630 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002631 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002632 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002633 ha->device_type |= DT_ZIO_SUPPORTED;
2634 ha->device_type |= DT_FWI2;
2635 ha->device_type |= DT_IIDMA;
2636 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2637 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002638 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002639 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002640 ha->device_type |= DT_ZIO_SUPPORTED;
2641 ha->device_type |= DT_FWI2;
2642 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2643 /* Initialize 82XX ISP flags */
2644 qla82xx_init_flags(ha);
2645 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002646 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002647 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002648 ha->device_type |= DT_ZIO_SUPPORTED;
2649 ha->device_type |= DT_FWI2;
2650 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2651 /* Initialize 82XX ISP flags */
2652 qla82xx_init_flags(ha);
2653 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002654 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002655 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002656 ha->device_type |= DT_ZIO_SUPPORTED;
2657 ha->device_type |= DT_FWI2;
2658 ha->device_type |= DT_IIDMA;
2659 ha->device_type |= DT_T10_PI;
2660 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2661 break;
2662 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002663 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002664 ha->device_type |= DT_ZIO_SUPPORTED;
2665 ha->device_type |= DT_FWI2;
2666 ha->device_type |= DT_IIDMA;
2667 ha->device_type |= DT_T10_PI;
2668 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2669 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002670 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002671 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002672 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002673 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002674 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002675 ha->device_type |= DT_ZIO_SUPPORTED;
2676 ha->device_type |= DT_FWI2;
2677 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002678 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002679 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2680 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002681 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002682 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002683 ha->device_type |= DT_ZIO_SUPPORTED;
2684 ha->device_type |= DT_FWI2;
2685 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002686 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002687 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2688 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002689 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002690 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002691 ha->device_type |= DT_ZIO_SUPPORTED;
2692 ha->device_type |= DT_FWI2;
2693 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002694 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002695 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2696 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002697 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002698
Giridhar Malavalia9083012010-04-12 17:59:55 -07002699 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002700 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002701 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002702 /* Get adapter physical port no from interrupt pin register. */
2703 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002704 if (IS_QLA27XX(ha))
2705 ha->port_no--;
2706 else
2707 ha->port_no = !(ha->port_no & 1);
2708 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002709
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002710 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002711 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002712 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002713}
2714
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002715static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002716qla2xxx_scan_start(struct Scsi_Host *shost)
2717{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002719
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002720 if (vha->hw->flags.running_gold_fw)
2721 return;
2722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2724 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2725 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2726 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002727}
2728
2729static int
2730qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2731{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002733
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002734 if (test_bit(UNLOADING, &vha->dpc_flags))
2735 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002737 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002739 return 1;
2740
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002741 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002742}
2743
Quinn Tranec7193e2017-03-15 09:48:55 -07002744static void qla2x00_iocb_work_fn(struct work_struct *work)
2745{
2746 struct scsi_qla_host *vha = container_of(work,
2747 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002748 struct qla_hw_data *ha = vha->hw;
2749 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002750 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002751 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002752
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002753 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2754 return;
2755
2756 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002757 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002758 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002759 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002760
2761 spin_lock_irqsave(&vha->work_lock, flags);
2762 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2763 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002764}
2765
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766/*
2767 * PCI driver interface
2768 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002769static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002770qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002772 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002774 scsi_qla_host_t *base_vha = NULL;
2775 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002776 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002777 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002778 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002779 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002780 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002781 struct req_que *req = NULL;
2782 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002783 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002784
Andrew Vasquez285d0322007-10-19 15:59:17 -07002785 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002786 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002787 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2788 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002789 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002790 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2791 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002792 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002793 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002794 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2795 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002796 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002797 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002798 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002799 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002800 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2801 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002802 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002803 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002804 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2805 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002806 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002807 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2808 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002809
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002810 if (mem_only) {
2811 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002812 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002813 } else {
2814 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002815 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
Jesse Barnes09276782008-10-18 17:33:19 -07002818 /* This may fail but that's ok */
2819 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002820
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2822 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2824 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002825 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002827 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2828 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002830 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2831 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002832 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002833 spin_lock_init(&ha->tgt.atio_lock);
2834
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002835 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
2837 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002838 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002839 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002840 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002841 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002842 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002843 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002845 /* Set ISP-type information. */
2846 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002847
2848 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002849 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002850 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002851 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002852
Chad Dupuiscba1e472011-11-18 09:03:21 -08002853 ha->prev_topology = 0;
2854 ha->init_cb_size = sizeof(init_cb_t);
2855 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2856 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002857 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002858 atomic_set(&ha->num_pend_mbx_stage1, 0);
2859 atomic_set(&ha->num_pend_mbx_stage2, 0);
2860 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002861 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2862 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002863
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002864 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002866 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 req_length = REQUEST_ENTRY_CNT_2100;
2869 rsp_length = RESPONSE_ENTRY_CNT_2100;
2870 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002871 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002872 ha->flash_conf_off = ~0;
2873 ha->flash_data_off = ~0;
2874 ha->nvram_conf_off = ~0;
2875 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002876 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002878 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002879 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 req_length = REQUEST_ENTRY_CNT_2200;
2881 rsp_length = RESPONSE_ENTRY_CNT_2100;
2882 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002883 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002884 ha->flash_conf_off = ~0;
2885 ha->flash_data_off = ~0;
2886 ha->nvram_conf_off = ~0;
2887 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002888 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002889 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002890 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 req_length = REQUEST_ENTRY_CNT_2200;
2893 rsp_length = RESPONSE_ENTRY_CNT_2300;
2894 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002895 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002896 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2897 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002898 ha->flash_conf_off = ~0;
2899 ha->flash_data_off = ~0;
2900 ha->nvram_conf_off = ~0;
2901 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002902 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002903 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002904 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002905 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002906 req_length = REQUEST_ENTRY_CNT_24XX;
2907 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002908 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002910 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002911 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002912 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002913 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002914 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002915 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2916 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2917 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2918 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002919 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002920 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002921 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002922 req_length = REQUEST_ENTRY_CNT_24XX;
2923 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002924 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002926 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002927 ha->gid_list_info_size = 8;
2928 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002929 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002930 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002931 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2932 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2933 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2934 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2935 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002936 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002937 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2938 req_length = REQUEST_ENTRY_CNT_24XX;
2939 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002940 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002941 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2942 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2943 ha->gid_list_info_size = 8;
2944 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002945 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002946 ha->isp_ops = &qla81xx_isp_ops;
2947 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2948 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2949 ha->nvram_conf_off = ~0;
2950 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002951 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002952 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002953 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2954 req_length = REQUEST_ENTRY_CNT_82XX;
2955 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2956 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2957 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2958 ha->gid_list_info_size = 8;
2959 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002960 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002961 ha->isp_ops = &qla82xx_isp_ops;
2962 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2963 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2964 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2965 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002966 } else if (IS_QLA8044(ha)) {
2967 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2968 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2969 req_length = REQUEST_ENTRY_CNT_82XX;
2970 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2971 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2972 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2973 ha->gid_list_info_size = 8;
2974 ha->optrom_size = OPTROM_SIZE_83XX;
2975 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2976 ha->isp_ops = &qla8044_isp_ops;
2977 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2978 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2979 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2980 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002981 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002982 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002983 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002984 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002985 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002986 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002987 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002988 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2989 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2990 ha->gid_list_info_size = 8;
2991 ha->optrom_size = OPTROM_SIZE_83XX;
2992 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2993 ha->isp_ops = &qla83xx_isp_ops;
2994 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2995 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2996 ha->nvram_conf_off = ~0;
2997 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002998 } else if (IS_QLAFX00(ha)) {
2999 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3000 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3001 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3002 req_length = REQUEST_ENTRY_CNT_FX00;
3003 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003004 ha->isp_ops = &qlafx00_isp_ops;
3005 ha->port_down_retry_count = 30; /* default value */
3006 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3007 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003008 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003009 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003010 ha->mr.host_info_resend = false;
3011 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003012 } else if (IS_QLA27XX(ha)) {
3013 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3014 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3015 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003016 req_length = REQUEST_ENTRY_CNT_83XX;
3017 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003018 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003019 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3020 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3021 ha->gid_list_info_size = 8;
3022 ha->optrom_size = OPTROM_SIZE_83XX;
3023 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3024 ha->isp_ops = &qla27xx_isp_ops;
3025 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3026 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3027 ha->nvram_conf_off = ~0;
3028 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003030
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003031 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3032 "mbx_count=%d, req_length=%d, "
3033 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003034 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3035 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003036 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3037 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003038 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003039 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3040 "isp_ops=%p, flash_conf_off=%d, "
3041 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3042 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3043 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003044
3045 /* Configure PCI I/O space */
3046 ret = ha->isp_ops->iospace_config(ha);
3047 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003048 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003049
3050 ql_log_pci(ql_log_info, pdev, 0x001d,
3051 "Found an ISP%04X irq %d iobase 0x%p.\n",
3052 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003053 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003054 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003055 init_completion(&ha->mbx_cmd_comp);
3056 complete(&ha->mbx_cmd_comp);
3057 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003058 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003059 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003061 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Andrew Vasquez53303c42009-01-22 09:45:37 -08003063 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003064 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3065 "64 Bit addressing is %s.\n",
3066 ha->flags.enable_64bit_addressing ? "enable" :
3067 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003068 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003069 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003070 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3071 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 goto probe_hw_failed;
3074 }
3075
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003076 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003078 req->max_q_depth = ql2xmaxqdepth;
3079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080
3081 base_vha = qla2x00_create_host(sht, ha);
3082 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003083 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 }
3086
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003087 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003088 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003091 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003092 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003093 base_vha->mgmt_svr_loop_id =
3094 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003095 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3097 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003098
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003099 /* Setup fcport template structure. */
3100 ha->mr.fcport.vha = base_vha;
3101 ha->mr.fcport.port_type = FCT_UNKNOWN;
3102 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3103 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3104 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3105 ha->mr.fcport.scan_state = 1;
3106
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003107 /* Set the SG table size based on ISP type */
3108 if (!IS_FWI2_CAPABLE(ha)) {
3109 if (IS_QLA2100(ha))
3110 host->sg_tablesize = 32;
3111 } else {
3112 if (!IS_QLA82XX(ha))
3113 host->sg_tablesize = QLA_SG_ALL;
3114 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003115 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003116 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003117 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003118 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003119 host->max_cmd_len = 32;
3120 else
3121 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003122 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003123 /* Older HBAs support only 16-bit LUNs */
3124 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3125 ql2xmaxlun > 0xffff)
3126 host->max_lun = 0xffff;
3127 else
3128 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003129 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003130 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003131
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003132 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3133 "max_id=%d this_id=%d "
3134 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003135 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003136 host->this_id, host->cmd_per_lun, host->unique_id,
3137 host->max_cmd_len, host->max_channel, host->max_lun,
3138 host->transportt, sht->vendor_id);
3139
Himanshu Madhani1010f212017-10-16 11:26:05 -07003140 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3141
Michael Hernandezd7459522016-12-12 14:40:07 -08003142 /* Set up the irqs */
3143 ret = qla2x00_request_irqs(ha, rsp);
3144 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003145 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003146
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003147 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003148 ret = qla2x00_alloc_queues(ha, req, rsp);
3149 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003150 ql_log(ql_log_fatal, base_vha, 0x003d,
3151 "Failed to allocate memory for queue pointers..."
3152 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003153 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003154 }
3155
Michael Hernandez56012362016-12-12 14:40:08 -08003156 if (ha->mqenable && shost_use_blk_mq(host)) {
3157 /* number of hardware queues supported by blk/scsi-mq*/
3158 host->nr_hw_queues = ha->max_qpairs;
3159
3160 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3161 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003162 } else {
3163 if (ql2xnvmeenable) {
3164 host->nr_hw_queues = ha->max_qpairs;
3165 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3166 "FC-NVMe support is enabled, HW queues=%d\n",
3167 host->nr_hw_queues);
3168 } else {
3169 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3170 "blk/scsi-mq disabled.\n");
3171 }
3172 }
Michael Hernandez56012362016-12-12 14:40:08 -08003173
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003174 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003175
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003176 pci_save_state(pdev);
3177
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003178 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003179 rsp->req = req;
3180 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003181
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003182 if (IS_QLAFX00(ha)) {
3183 ha->rsp_q_map[0] = rsp;
3184 ha->req_q_map[0] = req;
3185 set_bit(0, ha->req_qid_map);
3186 set_bit(0, ha->rsp_qid_map);
3187 }
3188
Andrew Vasquez08029992009-03-24 09:07:55 -07003189 /* FWI2-capable only. */
3190 req->req_q_in = &ha->iobase->isp24.req_q_in;
3191 req->req_q_out = &ha->iobase->isp24.req_q_out;
3192 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3193 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003194 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003195 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3196 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3197 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3198 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003199 }
3200
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003201 if (IS_QLAFX00(ha)) {
3202 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3203 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3204 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3205 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3206 }
3207
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003208 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003209 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3210 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3211 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3212 }
3213
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003214 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3215 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3216 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3217 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3218 "req->req_q_in=%p req->req_q_out=%p "
3219 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3220 req->req_q_in, req->req_q_out,
3221 rsp->rsp_q_in, rsp->rsp_q_out);
3222 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3223 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3224 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3225 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3226 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3227 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003229 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3230
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003231 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003232 ql_log(ql_log_fatal, base_vha, 0x00d6,
3233 "Failed to initialize adapter - Adapter flags %x.\n",
3234 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235
Giridhar Malavalia9083012010-04-12 17:59:55 -07003236 if (IS_QLA82XX(ha)) {
3237 qla82xx_idc_lock(ha);
3238 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003239 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003240 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003241 ql_log(ql_log_fatal, base_vha, 0x00d7,
3242 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003243 } else if (IS_QLA8044(ha)) {
3244 qla8044_idc_lock(ha);
3245 qla8044_wr_direct(base_vha,
3246 QLA8044_CRB_DEV_STATE_INDEX,
3247 QLA8XXX_DEV_FAILED);
3248 qla8044_idc_unlock(ha);
3249 ql_log(ql_log_fatal, base_vha, 0x0150,
3250 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003251 }
3252
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 ret = -ENODEV;
3254 goto probe_failed;
3255 }
3256
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003257 if (IS_QLAFX00(ha))
3258 host->can_queue = QLAFX00_MAX_CANQUEUE;
3259 else
3260 host->can_queue = req->num_outstanding_cmds - 10;
3261
3262 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3263 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3264 host->can_queue, base_vha->req,
3265 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3266
Quinn Trane326d222017-06-13 20:47:18 -07003267 if (ha->mqenable) {
3268 bool mq = false;
3269 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003270
3271 if (QLA_TGT_MODE_ENABLED()) {
3272 mq = true;
3273 startit = false;
3274 }
3275
3276 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3277 shost_use_blk_mq(host)) {
3278 mq = true;
3279 startit = true;
3280 }
3281
3282 if (mq) {
3283 /* Create start of day qpairs for Block MQ */
Michael Hernandez56012362016-12-12 14:40:08 -08003284 for (i = 0; i < ha->max_qpairs; i++)
Quinn Trane326d222017-06-13 20:47:18 -07003285 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003286 }
3287 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003288
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003289 if (ha->flags.running_gold_fw)
3290 goto skip_dpc;
3291
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 /*
3293 * Startup the kernel thread for this host adapter
3294 */
3295 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003296 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003298 ql_log(ql_log_fatal, base_vha, 0x00ed,
3299 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003301 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 goto probe_failed;
3303 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003304 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3305 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003307 /*
3308 * If we're not coming up in initiator mode, we might sit for
3309 * a while without waking up the dpc thread, which leads to a
3310 * stuck process warning. So just kick the dpc once here and
3311 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3312 */
3313 qla2xxx_wake_dpc(base_vha);
3314
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003315 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3316
Saurav Kashyap81178772012-08-22 14:21:04 -04003317 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3318 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3319 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3320 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3321
3322 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3323 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3324 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3325 INIT_WORK(&ha->idc_state_handler,
3326 qla83xx_idc_state_handler_work);
3327 INIT_WORK(&ha->nic_core_unrecoverable,
3328 qla83xx_nic_core_unrecoverable_work);
3329 }
3330
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003331skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 list_add_tail(&base_vha->list, &ha->vp_list);
3333 base_vha->host->irq = ha->pdev->irq;
3334
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003336 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003337 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3338 "Started qla2x00_timer with "
3339 "interval=%d.\n", WATCH_INTERVAL);
3340 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3341 "Detected hba at address=%p.\n",
3342 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
Arun Easie02587d2011-08-16 11:29:23 -07003344 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003345 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003346 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003347 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003348 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3349 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003350 if (ql2xenabledif == 1)
3351 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003352 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003353 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003354 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003355 | SHOST_DIF_TYPE3_PROTECTION
3356 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003357 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003358 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003359
3360 guard = SHOST_DIX_GUARD_CRC;
3361
3362 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3363 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3364 guard |= SHOST_DIX_GUARD_IP;
3365
3366 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003367 } else
3368 base_vha->flags.difdix_supported = 0;
3369 }
3370
Giridhar Malavalia9083012010-04-12 17:59:55 -07003371 ha->isp_ops->enable_intrs(ha);
3372
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003373 if (IS_QLAFX00(ha)) {
3374 ret = qlafx00_fx_disc(base_vha,
3375 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3376 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3377 QLA_SG_ALL : 128;
3378 }
3379
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003380 ret = scsi_add_host(host, &pdev->dev);
3381 if (ret)
3382 goto probe_failed;
3383
Michael Reed14864002009-12-02 09:11:16 -06003384 base_vha->flags.init_done = 1;
3385 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003386 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003387
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003388 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3389 "Init done and hba is online.\n");
3390
Quinn Tran726b8542017-01-19 22:28:00 -08003391 if (qla_ini_mode_enabled(base_vha) ||
3392 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003393 scsi_scan_host(host);
3394 else
3395 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3396 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003397
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003399
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003400 if (IS_QLAFX00(ha)) {
3401 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003402 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3403
3404 /* Register system information */
3405 ret = qlafx00_fx_disc(base_vha,
3406 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3407 }
3408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003409 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003410
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003412
Armen Baloyan03eb9122013-10-30 03:38:22 -04003413 ql_log(ql_log_info, base_vha, 0x00fb,
3414 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003415 ql_log(ql_log_info, base_vha, 0x00fc,
3416 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3417 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3418 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3419 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003420 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003422 qlt_add_target(ha, base_vha);
3423
Joe Lawrence6b383972014-08-26 17:12:29 -04003424 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003425
3426 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3427 return -ENODEV;
3428
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003429 if (ha->flags.detected_lr_sfp) {
3430 ql_log(ql_log_info, base_vha, 0xffff,
3431 "Reset chip to pick up LR SFP setting\n");
3432 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3433 qla2xxx_wake_dpc(base_vha);
3434 }
3435
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 return 0;
3437
3438probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003439 if (base_vha->timer_active)
3440 qla2x00_stop_timer(base_vha);
3441 base_vha->flags.online = 0;
3442 if (ha->dpc_thread) {
3443 struct task_struct *t = ha->dpc_thread;
3444
3445 ha->dpc_thread = NULL;
3446 kthread_stop(t);
3447 }
3448
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003449 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003451 /*
3452 * Need to NULL out local req/rsp after
3453 * qla2x00_free_device => qla2x00_free_queues frees
3454 * what these are pointing to. Or else we'll
3455 * fall over below in qla2x00_free_req/rsp_que.
3456 */
3457 req = NULL;
3458 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003461 qla2x00_mem_free(ha);
3462 qla2x00_free_req_que(ha, req);
3463 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003464 qla2x00_clear_drv_active(ha);
3465
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003466iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003467 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003468 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003469 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003470 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003471 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003472 } else {
3473 if (ha->iobase)
3474 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003475 if (ha->cregbase)
3476 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003477 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003478 pci_release_selected_regions(ha->pdev, ha->bars);
3479 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003481disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003482 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003483 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485
Adrian Bunk4c993f72008-01-14 00:55:16 -08003486static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003487qla2x00_shutdown(struct pci_dev *pdev)
3488{
3489 scsi_qla_host_t *vha;
3490 struct qla_hw_data *ha;
3491
3492 vha = pci_get_drvdata(pdev);
3493 ha = vha->hw;
3494
Sawan Chandakefdb5762017-08-23 15:05:00 -07003495 ql_log(ql_log_info, vha, 0xfffa,
3496 "Adapter shutdown\n");
3497
3498 /*
3499 * Prevent future board_disable and wait
3500 * until any pending board_disable has completed.
3501 */
3502 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3503 cancel_work_sync(&ha->board_disable);
3504
3505 if (!atomic_read(&pdev->enable_cnt))
3506 return;
3507
Armen Baloyan42479342013-08-27 01:37:37 -04003508 /* Notify ISPFX00 firmware */
3509 if (IS_QLAFX00(ha))
3510 qlafx00_driver_shutdown(vha, 20);
3511
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003512 /* Turn-off FCE trace */
3513 if (ha->flags.fce_enabled) {
3514 qla2x00_disable_fce_trace(vha, NULL, NULL);
3515 ha->flags.fce_enabled = 0;
3516 }
3517
3518 /* Turn-off EFT trace */
3519 if (ha->eft)
3520 qla2x00_disable_eft_trace(vha);
3521
Quinn Tran3407fc32017-12-28 12:33:11 -08003522 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3523 if (ha->flags.fw_started)
3524 qla2x00_abort_isp_cleanup(vha);
3525 } else {
3526 /* Stop currently executing firmware. */
3527 qla2x00_try_to_stop_firmware(vha);
3528 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003529
3530 /* Turn adapter off line */
3531 vha->flags.online = 0;
3532
3533 /* turn-off interrupts on the card */
3534 if (ha->interrupts_on) {
3535 vha->flags.init_done = 0;
3536 ha->isp_ops->disable_intrs(ha);
3537 }
3538
3539 qla2x00_free_irqs(vha);
3540
3541 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003542
Chad Dupuis61d41f62014-09-25 05:17:02 -04003543 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003544 ql_log(ql_log_info, vha, 0xfffe,
3545 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003546}
3547
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003548/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003549static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003550qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003552 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003553 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
Arun Easi43ebf162011-05-10 11:18:16 -07003555 mutex_lock(&ha->vport_lock);
3556 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003557 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003558
Arun Easi43ebf162011-05-10 11:18:16 -07003559 BUG_ON(base_vha->list.next == &ha->vp_list);
3560 /* This assumes first entry in ha->vp_list is always base vha */
3561 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003562 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003563
Arun Easi43ebf162011-05-10 11:18:16 -07003564 spin_unlock_irqrestore(&ha->vport_slock, flags);
3565 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003566
Arun Easi43ebf162011-05-10 11:18:16 -07003567 fc_vport_terminate(vha->fc_vport);
3568 scsi_host_put(vha->host);
3569
3570 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571 }
Arun Easi43ebf162011-05-10 11:18:16 -07003572 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003573}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003574
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003575/* Stops all deferred work threads */
3576static void
3577qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3578{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003579 /* Cancel all work and destroy DPC workqueues */
3580 if (ha->dpc_lp_wq) {
3581 cancel_work_sync(&ha->idc_aen);
3582 destroy_workqueue(ha->dpc_lp_wq);
3583 ha->dpc_lp_wq = NULL;
3584 }
3585
3586 if (ha->dpc_hp_wq) {
3587 cancel_work_sync(&ha->nic_core_reset);
3588 cancel_work_sync(&ha->idc_state_handler);
3589 cancel_work_sync(&ha->nic_core_unrecoverable);
3590 destroy_workqueue(ha->dpc_hp_wq);
3591 ha->dpc_hp_wq = NULL;
3592 }
3593
Andrew Vasquezb9978762009-03-24 09:08:05 -07003594 /* Kill the kernel thread for this host */
3595 if (ha->dpc_thread) {
3596 struct task_struct *t = ha->dpc_thread;
3597
3598 /*
3599 * qla2xxx_wake_dpc checks for ->dpc_thread
3600 * so we need to zero it out.
3601 */
3602 ha->dpc_thread = NULL;
3603 kthread_stop(t);
3604 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003605}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003606
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003607static void
3608qla2x00_unmap_iobases(struct qla_hw_data *ha)
3609{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003610 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003611
Chad Dupuisf73cb692014-02-26 04:15:06 -05003612 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003613 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003614 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003615 } else {
3616 if (ha->iobase)
3617 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003619 if (ha->cregbase)
3620 iounmap(ha->cregbase);
3621
Giridhar Malavalia9083012010-04-12 17:59:55 -07003622 if (ha->mqiobase)
3623 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003624
Chad Dupuisf73cb692014-02-26 04:15:06 -05003625 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003626 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003627 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003628}
3629
3630static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003631qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003632{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003633 if (IS_QLA8044(ha)) {
3634 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003635 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003636 qla8044_idc_unlock(ha);
3637 } else if (IS_QLA82XX(ha)) {
3638 qla82xx_idc_lock(ha);
3639 qla82xx_clear_drv_active(ha);
3640 qla82xx_idc_unlock(ha);
3641 }
3642}
3643
3644static void
3645qla2x00_remove_one(struct pci_dev *pdev)
3646{
3647 scsi_qla_host_t *base_vha;
3648 struct qla_hw_data *ha;
3649
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003650 base_vha = pci_get_drvdata(pdev);
3651 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003652 ql_log(ql_log_info, base_vha, 0xb079,
3653 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003654
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003655 /* Indicate device removal to prevent future board_disable and wait
3656 * until any pending board_disable has completed. */
3657 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3658 cancel_work_sync(&ha->board_disable);
3659
3660 /*
3661 * If the PCI device is disabled then there was a PCI-disconnect and
3662 * qla2x00_disable_board_on_pci_error has taken care of most of the
3663 * resources.
3664 */
3665 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003666 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3667 base_vha->gnl.l, base_vha->gnl.ldma);
3668
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003669 scsi_host_put(base_vha->host);
3670 kfree(ha);
3671 pci_set_drvdata(pdev, NULL);
3672 return;
3673 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003674 qla2x00_wait_for_hba_ready(base_vha);
3675
Quinn Tran45235022018-07-18 14:29:53 -07003676 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3677 if (ha->flags.fw_started)
3678 qla2x00_abort_isp_cleanup(base_vha);
3679 } else if (!IS_QLAFX00(ha)) {
3680 if (IS_QLA8031(ha)) {
3681 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3682 "Clearing fcoe driver presence.\n");
3683 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3684 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3685 "Error while clearing DRV-Presence.\n");
3686 }
3687
3688 qla2x00_try_to_stop_firmware(base_vha);
3689 }
3690
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003691 qla2x00_wait_for_sess_deletion(base_vha);
3692
Quinn Tran726b8542017-01-19 22:28:00 -08003693 /*
3694 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003695 * where it was set first.
3696 */
3697 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3698 return;
3699
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003700 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003701
3702 qla_nvme_delete(base_vha);
3703
Quinn Tran726b8542017-01-19 22:28:00 -08003704 dma_free_coherent(&ha->pdev->dev,
3705 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003706
Quinn Trana4239942017-12-28 12:33:26 -08003707 vfree(base_vha->scan.l);
3708
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003709 if (IS_QLAFX00(ha))
3710 qlafx00_driver_shutdown(base_vha, 20);
3711
3712 qla2x00_delete_all_vps(ha, base_vha);
3713
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003714 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3715
3716 qla2x00_dfs_remove(base_vha);
3717
3718 qla84xx_put_chip(base_vha);
3719
3720 /* Disable timer */
3721 if (base_vha->timer_active)
3722 qla2x00_stop_timer(base_vha);
3723
3724 base_vha->flags.online = 0;
3725
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003726 /* free DMA memory */
3727 if (ha->exlogin_buf)
3728 qla2x00_free_exlogin_buffer(ha);
3729
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003730 /* free DMA memory */
3731 if (ha->exchoffld_buf)
3732 qla2x00_free_exchoffld_buffer(ha);
3733
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003734 qla2x00_destroy_deferred_work(ha);
3735
3736 qlt_remove_target(ha, base_vha);
3737
3738 qla2x00_free_sysfs_attr(base_vha, true);
3739
3740 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003741 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003742
3743 scsi_remove_host(base_vha->host);
3744
3745 qla2x00_free_device(base_vha);
3746
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003747 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003748
Arun Easid2749ff2014-09-25 05:16:51 -04003749 scsi_host_put(base_vha->host);
3750
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003751 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003752
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003753 pci_release_selected_regions(ha->pdev, ha->bars);
3754 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003756 pci_disable_pcie_error_reporting(pdev);
3757
Bernhard Walle665db932007-03-28 00:49:49 +02003758 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760
3761static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003762qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003764 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765
Andrew Vasquez85880802009-12-15 21:29:46 -08003766 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3767
3768 /* Disable timer */
3769 if (vha->timer_active)
3770 qla2x00_stop_timer(vha);
3771
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003772 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003773 vha->flags.online = 0;
3774
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003775 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003776 if (ha->interrupts_on) {
3777 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003778 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003779 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003780
Quinn Tran093df732016-12-12 14:40:09 -08003781 qla2x00_free_fcports(vha);
3782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 qla2x00_free_irqs(vha);
3784
Quinn Tran093df732016-12-12 14:40:09 -08003785 /* Flush the work queue and remove it */
3786 if (ha->wq) {
3787 flush_workqueue(ha->wq);
3788 destroy_workqueue(ha->wq);
3789 ha->wq = NULL;
3790 }
3791
Chad Dupuis88670482010-07-23 15:28:30 +05003792
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003793 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003794
Giridhar Malavali08de2842011-08-16 11:31:44 -07003795 qla82xx_md_free(vha);
3796
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003797 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798}
3799
Chad Dupuis88670482010-07-23 15:28:30 +05003800void qla2x00_free_fcports(struct scsi_qla_host *vha)
3801{
3802 fc_port_t *fcport, *tfcport;
3803
3804 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3805 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003806 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003807 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003808 }
3809}
3810
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003811static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003813 int defer)
3814{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003815 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003816 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003817 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003818
3819 if (!fcport->rport)
3820 return;
3821
3822 rport = fcport->rport;
3823 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003824 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003825 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003826 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003827 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003828 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003829 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3830 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003831 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003832 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003833 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003834 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3835 "%s %8phN. rport %p roles %x\n",
3836 __func__, fcport->port_name, rport,
3837 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003838 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003839 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003840 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003841 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003842}
3843
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3846 *
3847 * Input: ha = adapter block pointer. fcport = port structure pointer.
3848 *
3849 * Return: None.
3850 *
3851 * Context:
3852 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003853void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003854 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003856 if (IS_QLAFX00(vha->hw)) {
3857 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3858 qla2x00_schedule_rport_del(vha, fcport, defer);
3859 return;
3860 }
3861
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003862 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003863 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003864 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865 qla2x00_schedule_rport_del(vha, fcport, defer);
3866 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003867 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 * We may need to retry the login, so don't change the state of the
3869 * port but do the retries.
3870 */
3871 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003872 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873
3874 if (!do_login)
3875 return;
3876
Arun Easia1d02852015-08-04 13:38:02 -04003877 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878}
3879
3880/*
3881 * qla2x00_mark_all_devices_lost
3882 * Updates fcport state when device goes offline.
3883 *
3884 * Input:
3885 * ha = adapter block pointer.
3886 * fcport = port structure pointer.
3887 *
3888 * Return:
3889 * None.
3890 *
3891 * Context:
3892 */
3893void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003894qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895{
3896 fc_port_t *fcport;
3897
Quinn Tran83548fe2017-06-02 09:12:01 -07003898 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3899 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003901 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003902 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003903 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003904
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003905 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003907
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 /*
3909 * No point in marking the device as lost, if the device is
3910 * already DEAD.
3911 */
3912 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3913 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003914 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003915 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003916 if (defer)
3917 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003918 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003919 qla2x00_schedule_rport_del(vha, fcport, defer);
3920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 }
3922}
3923
3924/*
3925* qla2x00_mem_alloc
3926* Allocates adapter memory.
3927*
3928* Returns:
3929* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003930* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003932static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003933qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3934 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935{
3936 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Andrew Vasqueze8711082008-01-31 12:33:48 -08003938 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003939 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003940 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003941 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003943 if (qlt_mem_alloc(ha) < 0)
3944 goto fail_free_init_cb;
3945
Chad Dupuis642ef982012-02-09 11:15:57 -08003946 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3947 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003948 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003949 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950
Andrew Vasqueze8711082008-01-31 12:33:48 -08003951 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3952 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003953 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003955 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003956 /* Allocate cache for CT6 Ctx. */
3957 if (!ctx_cachep) {
3958 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3959 sizeof(struct ct6_dsd), 0,
3960 SLAB_HWCACHE_ALIGN, NULL);
3961 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003962 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003963 }
3964 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3965 ctx_cachep);
3966 if (!ha->ctx_mempool)
3967 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003968 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3969 "ctx_cachep=%p ctx_mempool=%p.\n",
3970 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003971 }
3972
Andrew Vasqueze8711082008-01-31 12:33:48 -08003973 /* Get memory for cached NVRAM */
3974 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3975 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003976 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3979 ha->pdev->device);
3980 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3981 DMA_POOL_SIZE, 8, 0);
3982 if (!ha->s_dma_pool)
3983 goto fail_free_nvram;
3984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003985 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3986 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3987 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3988
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003989 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003990 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3991 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3992 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003993 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3994 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003995 goto fail_s_dma_pool;
3996 }
3997
3998 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3999 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4000 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004001 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4002 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004003 goto fail_dl_dma_pool;
4004 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004005 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4006 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
4007 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004008 }
4009
Andrew Vasqueze8711082008-01-31 12:33:48 -08004010 /* Allocate memory for SNS commands */
4011 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004012 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004013 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004014 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004015 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004016 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004017 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004018 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004019 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004021 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004022 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004023 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004024 goto fail_dma_pool;
4025 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004026 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004028 if (!ha->ct_sns)
4029 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004030 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4031 "ms_iocb=%p ct_sns=%p.\n",
4032 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 }
4034
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004036 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4037 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004038 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4039 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 goto fail_req;
4041 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004042 (*req)->length = req_len;
4043 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4044 ((*req)->length + 1) * sizeof(request_t),
4045 &(*req)->dma, GFP_KERNEL);
4046 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004047 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4048 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004049 goto fail_req_ring;
4050 }
4051 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004052 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4053 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004054 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4055 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 goto fail_rsp;
4057 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004058 (*rsp)->hw = ha;
4059 (*rsp)->length = rsp_len;
4060 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4061 ((*rsp)->length + 1) * sizeof(response_t),
4062 &(*rsp)->dma, GFP_KERNEL);
4063 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004064 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4065 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004066 goto fail_rsp_ring;
4067 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004068 (*req)->rsp = *rsp;
4069 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004070 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4071 "req=%p req->length=%d req->ring=%p rsp=%p "
4072 "rsp->length=%d rsp->ring=%p.\n",
4073 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4074 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004075 /* Allocate memory for NVRAM data for vports */
4076 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004077 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4078 sizeof(struct qla_npiv_entry),
4079 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004080 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004081 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4082 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004083 goto fail_npiv_info;
4084 }
4085 } else
4086 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004087
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004088 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004089 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004090 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4091 &ha->ex_init_cb_dma);
4092 if (!ha->ex_init_cb)
4093 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004094 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4095 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004096 }
4097
Giridhar Malavalia9083012010-04-12 17:59:55 -07004098 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4099
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004100 /* Get consistent memory allocated for Async Port-Database. */
4101 if (!IS_FWI2_CAPABLE(ha)) {
4102 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4103 &ha->async_pd_dma);
4104 if (!ha->async_pd)
4105 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004106 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4107 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004108 }
4109
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004110 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004111
4112 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004113 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4114 sizeof(long),
4115 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004116 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004117 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004118 else {
4119 qla2x00_set_reserved_loop_ids(ha);
4120 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004121 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004122 }
4123
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004124 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4125 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4126 if (!ha->sfp_data) {
4127 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4128 "Unable to allocate memory for SFP read-data.\n");
4129 goto fail_sfp_data;
4130 }
4131
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004132 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004134fail_sfp_data:
4135 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004136fail_loop_id_map:
4137 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004138fail_async_pd:
4139 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004140fail_ex_init_cb:
4141 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004142fail_npiv_info:
4143 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4144 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4145 (*rsp)->ring = NULL;
4146 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004147fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004148 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004149 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004150fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004151 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4152 sizeof(request_t), (*req)->ring, (*req)->dma);
4153 (*req)->ring = NULL;
4154 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004155fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004156 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004157 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158fail_req:
4159 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4160 ha->ct_sns, ha->ct_sns_dma);
4161 ha->ct_sns = NULL;
4162 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004163fail_free_ms_iocb:
4164 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4165 ha->ms_iocb = NULL;
4166 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004167
4168 if (ha->sns_cmd)
4169 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4170 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004171fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004172 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004173 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4174 ha->fcp_cmnd_dma_pool = NULL;
4175 }
4176fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004177 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004178 dma_pool_destroy(ha->dl_dma_pool);
4179 ha->dl_dma_pool = NULL;
4180 }
4181fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004182 dma_pool_destroy(ha->s_dma_pool);
4183 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004184fail_free_nvram:
4185 kfree(ha->nvram);
4186 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004187fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004188 if (ha->ctx_mempool)
4189 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004190 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004191fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004192 if (ha->srb_mempool)
4193 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004194 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004195fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004196 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4197 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004198 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004199 ha->gid_list = NULL;
4200 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004201fail_free_tgt_mem:
4202 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004203fail_free_init_cb:
4204 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4205 ha->init_cb_dma);
4206 ha->init_cb = NULL;
4207 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004208fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004209 ql_log(ql_log_fatal, NULL, 0x0030,
4210 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004211 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212}
4213
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004214int
4215qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4216{
4217 int rval;
4218 uint16_t size, max_cnt, temp;
4219 struct qla_hw_data *ha = vha->hw;
4220
4221 /* Return if we don't need to alloacate any extended logins */
4222 if (!ql2xexlogins)
4223 return QLA_SUCCESS;
4224
Quinn Tran99e1b682017-06-02 09:12:03 -07004225 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4226 return QLA_SUCCESS;
4227
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004228 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4229 max_cnt = 0;
4230 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4231 if (rval != QLA_SUCCESS) {
4232 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4233 "Failed to get exlogin status.\n");
4234 return rval;
4235 }
4236
4237 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004238 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004239
Quinn Tran99e1b682017-06-02 09:12:03 -07004240 if (temp != ha->exlogin_size) {
4241 qla2x00_free_exlogin_buffer(ha);
4242 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004243
Quinn Tran99e1b682017-06-02 09:12:03 -07004244 ql_log(ql_log_info, vha, 0xd024,
4245 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4246 max_cnt, size, temp);
4247
4248 ql_log(ql_log_info, vha, 0xd025,
4249 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4250
4251 /* Get consistent memory for extended logins */
4252 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4253 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4254 if (!ha->exlogin_buf) {
4255 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004256 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004257 return -ENOMEM;
4258 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004259 }
4260
4261 /* Now configure the dma buffer */
4262 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4263 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004264 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004265 "Setup extended login buffer ****FAILED****.\n");
4266 qla2x00_free_exlogin_buffer(ha);
4267 }
4268
4269 return rval;
4270}
4271
4272/*
4273* qla2x00_free_exlogin_buffer
4274*
4275* Input:
4276* ha = adapter block pointer
4277*/
4278void
4279qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4280{
4281 if (ha->exlogin_buf) {
4282 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4283 ha->exlogin_buf, ha->exlogin_buf_dma);
4284 ha->exlogin_buf = NULL;
4285 ha->exlogin_size = 0;
4286 }
4287}
4288
Quinn Tran99e1b682017-06-02 09:12:03 -07004289static void
4290qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4291{
4292 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004293 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004294 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4295
Quinn Trand1e36352017-12-28 12:33:12 -08004296 if (max_cnt > vha->hw->max_exchg)
4297 max_cnt = vha->hw->max_exchg;
4298
Quinn Tran99e1b682017-06-02 09:12:03 -07004299 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004300 if (vha->ql2xiniexchg > max_cnt)
4301 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004302
Quinn Tran0645cb82018-09-11 10:18:18 -07004303 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4304 *ret_cnt = vha->ql2xiniexchg;
4305
Quinn Tran99e1b682017-06-02 09:12:03 -07004306 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004307 if (vha->ql2xexchoffld > max_cnt) {
4308 vha->ql2xexchoffld = max_cnt;
4309 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4310 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004311
Quinn Tran0645cb82018-09-11 10:18:18 -07004312 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4313 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004314 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004315 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004316 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004317 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4318 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004319 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004320 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004321 }
4322
4323 if (temp > FW_DEF_EXCHANGES_CNT)
4324 *ret_cnt = temp;
4325 }
4326}
4327
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004328int
4329qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4330{
4331 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004332 u16 size, max_cnt;
4333 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004334 struct qla_hw_data *ha = vha->hw;
4335
Quinn Tran99e1b682017-06-02 09:12:03 -07004336 if (!ha->flags.exchoffld_enabled)
4337 return QLA_SUCCESS;
4338
4339 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004340 return QLA_SUCCESS;
4341
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004342 max_cnt = 0;
4343 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4344 if (rval != QLA_SUCCESS) {
4345 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4346 "Failed to get exlogin status.\n");
4347 return rval;
4348 }
4349
Quinn Trand1e36352017-12-28 12:33:12 -08004350 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4351 ql_log(ql_log_info, vha, 0xd014,
4352 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004353
Quinn Trand1e36352017-12-28 12:33:12 -08004354 totsz = actual_cnt * size;
4355
4356 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004357 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004358 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4359 ha->exchoffld_size = 0;
4360 ha->flags.exchoffld_enabled = 0;
4361 return QLA_SUCCESS;
4362 }
4363
Quinn Trand1e36352017-12-28 12:33:12 -08004364 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004365
Quinn Tran99e1b682017-06-02 09:12:03 -07004366 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004367 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4368 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004369
4370 ql_log(ql_log_info, vha, 0xd017,
4371 "Exchange Buffers requested size = 0x%x\n",
4372 ha->exchoffld_size);
4373
4374 /* Get consistent memory for extended logins */
4375 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4376 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4377 if (!ha->exchoffld_buf) {
4378 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004379 "Failed to allocate memory for Exchange Offload.\n");
4380
4381 if (ha->max_exchg >
4382 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4383 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4384 } else if (ha->max_exchg >
4385 (FW_DEF_EXCHANGES_CNT + 512)) {
4386 ha->max_exchg -= 512;
4387 } else {
4388 ha->flags.exchoffld_enabled = 0;
4389 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4390 "Disabling Exchange offload due to lack of memory\n");
4391 }
4392 ha->exchoffld_size = 0;
4393
Quinn Tran99e1b682017-06-02 09:12:03 -07004394 return -ENOMEM;
4395 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004396 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4397 /* pathological case */
4398 qla2x00_free_exchoffld_buffer(ha);
4399 ha->exchoffld_size = 0;
4400 ha->flags.exchoffld_enabled = 0;
4401 ql_log(ql_log_info, vha, 0xd016,
4402 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4403 ha->exchoffld_size, actual_cnt, size, totsz);
4404 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004405 }
4406
4407 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004408 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004409 if (rval) {
4410 ql_log(ql_log_fatal, vha, 0xd02e,
4411 "Setup exchange offload buffer ****FAILED****.\n");
4412 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004413 } else {
4414 /* re-adjust number of target exchange */
4415 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4416
4417 if (qla_ini_mode_enabled(vha))
4418 icb->exchange_count = 0;
4419 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004420 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004421 }
4422
4423 return rval;
4424}
4425
4426/*
4427* qla2x00_free_exchoffld_buffer
4428*
4429* Input:
4430* ha = adapter block pointer
4431*/
4432void
4433qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4434{
4435 if (ha->exchoffld_buf) {
4436 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4437 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4438 ha->exchoffld_buf = NULL;
4439 ha->exchoffld_size = 0;
4440 }
4441}
4442
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004444* qla2x00_free_fw_dump
4445* Frees fw dump stuff.
4446*
4447* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004448* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004449*/
4450static void
4451qla2x00_free_fw_dump(struct qla_hw_data *ha)
4452{
4453 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004454 dma_free_coherent(&ha->pdev->dev,
4455 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004456
Chad Dupuisf73cb692014-02-26 04:15:06 -05004457 if (ha->eft)
4458 dma_free_coherent(&ha->pdev->dev,
4459 EFT_SIZE, ha->eft, ha->eft_dma);
4460
4461 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004462 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004463 if (ha->fw_dump_template)
4464 vfree(ha->fw_dump_template);
4465
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004466 ha->fce = NULL;
4467 ha->fce_dma = 0;
4468 ha->eft = NULL;
4469 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004470 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004471 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004472 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004473 ha->fw_dump = NULL;
4474 ha->fw_dump_len = 0;
4475 ha->fw_dump_template = NULL;
4476 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004477}
4478
4479/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480* qla2x00_mem_free
4481* Frees all adapter allocated memory.
4482*
4483* Input:
4484* ha = adapter block pointer.
4485*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004486static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004487qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004489 qla2x00_free_fw_dump(ha);
4490
Saurav Kashyap81178772012-08-22 14:21:04 -04004491 if (ha->mctp_dump)
4492 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4493 ha->mctp_dump_dma);
4494
Andrew Vasqueze8711082008-01-31 12:33:48 -08004495 if (ha->srb_mempool)
4496 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004498 if (ha->dcbx_tlv)
4499 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4500 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4501
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004502 if (ha->xgmac_data)
4503 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4504 ha->xgmac_data, ha->xgmac_data_dma);
4505
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 if (ha->sns_cmd)
4507 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004508 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509
4510 if (ha->ct_sns)
4511 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004512 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513
Andrew Vasquez88729e52006-06-23 16:10:50 -07004514 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004515 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4516 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004517
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 if (ha->ms_iocb)
4519 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4520
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004521 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004522 dma_pool_free(ha->s_dma_pool,
4523 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004524
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004525 if (ha->async_pd)
4526 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4527
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 if (ha->s_dma_pool)
4529 dma_pool_destroy(ha->s_dma_pool);
4530
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004532 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4533 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534
Giridhar Malavalia9083012010-04-12 17:59:55 -07004535 if (IS_QLA82XX(ha)) {
4536 if (!list_empty(&ha->gbl_dsd_list)) {
4537 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4538
4539 /* clean up allocated prev pool */
4540 list_for_each_entry_safe(dsd_ptr,
4541 tdsd_ptr, &ha->gbl_dsd_list, list) {
4542 dma_pool_free(ha->dl_dma_pool,
4543 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4544 list_del(&dsd_ptr->list);
4545 kfree(dsd_ptr);
4546 }
4547 }
4548 }
4549
4550 if (ha->dl_dma_pool)
4551 dma_pool_destroy(ha->dl_dma_pool);
4552
4553 if (ha->fcp_cmnd_dma_pool)
4554 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4555
4556 if (ha->ctx_mempool)
4557 mempool_destroy(ha->ctx_mempool);
4558
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004559 qlt_mem_free(ha);
4560
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004561 if (ha->init_cb)
4562 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004563 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004564
Bill Kuzeja6d634062018-03-23 10:37:25 -04004565 vfree(ha->optrom_buffer);
4566 kfree(ha->nvram);
4567 kfree(ha->npiv_info);
4568 kfree(ha->swl);
4569 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570
Andrew Vasqueze8711082008-01-31 12:33:48 -08004571 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004572 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 ha->sns_cmd = NULL;
4574 ha->sns_cmd_dma = 0;
4575 ha->ct_sns = NULL;
4576 ha->ct_sns_dma = 0;
4577 ha->ms_iocb = NULL;
4578 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 ha->init_cb = NULL;
4580 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004581 ha->ex_init_cb = NULL;
4582 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004583 ha->async_pd = NULL;
4584 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004585 ha->loop_id_map = NULL;
4586 ha->npiv_info = NULL;
4587 ha->optrom_buffer = NULL;
4588 ha->swl = NULL;
4589 ha->nvram = NULL;
4590 ha->mctp_dump = NULL;
4591 ha->dcbx_tlv = NULL;
4592 ha->xgmac_data = NULL;
4593 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594
4595 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004596 ha->dl_dma_pool = NULL;
4597 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 ha->gid_list = NULL;
4600 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004601
4602 ha->tgt.atio_ring = NULL;
4603 ha->tgt.atio_dma = 0;
4604 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004605}
4606
4607struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4608 struct qla_hw_data *ha)
4609{
4610 struct Scsi_Host *host;
4611 struct scsi_qla_host *vha = NULL;
4612
4613 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004614 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004615 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4616 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004617 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004618 }
4619
4620 /* Clear our data area */
4621 vha = shost_priv(host);
4622 memset(vha, 0, sizeof(scsi_qla_host_t));
4623
4624 vha->host = host;
4625 vha->host_no = host->host_no;
4626 vha->hw = ha;
4627
Quinn Tran0645cb82018-09-11 10:18:18 -07004628 vha->qlini_mode = ql2x_ini_mode;
4629 vha->ql2xexchoffld = ql2xexchoffld;
4630 vha->ql2xiniexchg = ql2xiniexchg;
4631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004632 INIT_LIST_HEAD(&vha->vp_fcports);
4633 INIT_LIST_HEAD(&vha->work_list);
4634 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004635 INIT_LIST_HEAD(&vha->qla_cmd_list);
4636 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004637 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004638 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004639 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004640 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004641 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004642 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004643 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004644
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004645 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004646 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004647 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004648 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004649
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004650 vha->gnl.size = sizeof(struct get_name_list_extended) *
4651 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004652 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4653 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4654 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004655 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004656 "Alloc failed for name list.\n");
4657 scsi_remove_host(vha->host);
4658 return NULL;
4659 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004660
Quinn Trana4239942017-12-28 12:33:26 -08004661 /* todo: what about ext login? */
4662 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4663 vha->scan.l = vmalloc(vha->scan.size);
4664 if (!vha->scan.l) {
4665 ql_log(ql_log_fatal, vha, 0xd04a,
4666 "Alloc failed for scan database.\n");
4667 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4668 vha->gnl.l, vha->gnl.ldma);
4669 scsi_remove_host(vha->host);
4670 return NULL;
4671 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004672 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004674 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004675 ql_dbg(ql_dbg_init, vha, 0x0041,
4676 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4677 vha->host, vha->hw, vha,
4678 dev_name(&(ha->pdev->dev)));
4679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004680 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681}
4682
Quinn Tran726b8542017-01-19 22:28:00 -08004683struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004684qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004685{
4686 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004687 uint8_t bail;
4688
4689 QLA_VHA_MARK_BUSY(vha, bail);
4690 if (bail)
4691 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004692
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004693 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004694 if (!e) {
4695 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004696 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004697 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004698
4699 INIT_LIST_HEAD(&e->list);
4700 e->type = type;
4701 e->flags = QLA_EVT_FLAG_FREE;
4702 return e;
4703}
4704
Quinn Tran726b8542017-01-19 22:28:00 -08004705int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004706qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004707{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004708 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004709 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004710
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004711 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004712 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004713
4714 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4715 q = true;
4716
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004717 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004718
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004719 if (q)
4720 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004721
Andrew Vasquez0971de72008-04-03 13:13:18 -07004722 return QLA_SUCCESS;
4723}
4724
4725int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004726qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004727 u32 data)
4728{
4729 struct qla_work_evt *e;
4730
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004731 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004732 if (!e)
4733 return QLA_FUNCTION_FAILED;
4734
4735 e->u.aen.code = code;
4736 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004737 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004738}
4739
Andrew Vasquez8a659572009-02-08 20:50:12 -08004740int
4741qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4742{
4743 struct qla_work_evt *e;
4744
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004745 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004746 if (!e)
4747 return QLA_FUNCTION_FAILED;
4748
4749 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004750 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004751}
4752
Andrew Vasquezac280b62009-08-20 11:06:05 -07004753#define qla2x00_post_async_work(name, type) \
4754int qla2x00_post_async_##name##_work( \
4755 struct scsi_qla_host *vha, \
4756 fc_port_t *fcport, uint16_t *data) \
4757{ \
4758 struct qla_work_evt *e; \
4759 \
4760 e = qla2x00_alloc_work(vha, type); \
4761 if (!e) \
4762 return QLA_FUNCTION_FAILED; \
4763 \
4764 e->u.logio.fcport = fcport; \
4765 if (data) { \
4766 e->u.logio.data[0] = data[0]; \
4767 e->u.logio.data[1] = data[1]; \
4768 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004769 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004770 return qla2x00_post_work(vha, e); \
4771}
4772
4773qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004774qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4775qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004776qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08004777qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4778qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004779
Andrew Vasquez3420d362009-10-13 15:16:45 -07004780int
4781qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4782{
4783 struct qla_work_evt *e;
4784
4785 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4786 if (!e)
4787 return QLA_FUNCTION_FAILED;
4788
4789 e->u.uevent.code = code;
4790 return qla2x00_post_work(vha, e);
4791}
4792
4793static void
4794qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4795{
4796 char event_string[40];
4797 char *envp[] = { event_string, NULL };
4798
4799 switch (code) {
4800 case QLA_UEVENT_CODE_FW_DUMP:
4801 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4802 vha->host_no);
4803 break;
4804 default:
4805 /* do nothing */
4806 break;
4807 }
4808 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4809}
4810
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004811int
4812qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4813 uint32_t *data, int cnt)
4814{
4815 struct qla_work_evt *e;
4816
4817 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4818 if (!e)
4819 return QLA_FUNCTION_FAILED;
4820
4821 e->u.aenfx.evtcode = evtcode;
4822 e->u.aenfx.count = cnt;
4823 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4824 return qla2x00_post_work(vha, e);
4825}
4826
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004827void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08004828{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004829 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08004830
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004831 if (IS_SW_RESV_ADDR(fcport->d_id))
4832 return;
Quinn Tran726b8542017-01-19 22:28:00 -08004833
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004834 spin_lock_irqsave(&fcport->vha->work_lock, flags);
4835 if (fcport->disc_state == DSC_UPD_FCPORT) {
4836 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4837 return;
4838 }
4839 fcport->jiffies_at_registration = jiffies;
4840 fcport->sec_since_registration = 0;
4841 fcport->next_disc_state = DSC_DELETED;
4842 fcport->disc_state = DSC_UPD_FCPORT;
4843 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4844
4845 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08004846}
4847
4848static
4849void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4850{
4851 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07004852 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08004853 struct qlt_plogi_ack_t *pla =
4854 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07004855 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08004856
Quinn Tran9cd883f2017-12-28 12:33:24 -08004857 ql_dbg(ql_dbg_disc, vha, 0xffff,
4858 "%s %d %8phC enter\n",
4859 __func__, __LINE__, e->u.new_sess.port_name);
4860
Quinn Tran726b8542017-01-19 22:28:00 -08004861 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4862 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4863 if (fcport) {
4864 fcport->d_id = e->u.new_sess.id;
4865 if (pla) {
4866 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004867 memcpy(fcport->node_name,
4868 pla->iocb.u.isp24.u.plogi.node_name,
4869 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08004870 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4871 /* we took an extra ref_count to prevent PLOGI ACK when
4872 * fcport/sess has not been created.
4873 */
4874 pla->ref_count--;
4875 }
4876 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07004877 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004878 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4879 if (fcport) {
4880 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08004881 fcport->flags |= FCF_FABRIC_DEVICE;
4882 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran8777e432018-08-02 13:16:57 -07004883 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08004884 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08004885
Quinn Tran8777e432018-08-02 13:16:57 -07004886 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08004887 fcport->fc4_type = FC4_TYPE_OTHER;
4888 fcport->fc4f_nvme = FC4_TYPE_NVME;
4889 }
Quinn Tran33b28352018-03-20 23:09:40 -07004890
Quinn Tran726b8542017-01-19 22:28:00 -08004891 memcpy(fcport->port_name, e->u.new_sess.port_name,
4892 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07004893 } else {
4894 ql_dbg(ql_dbg_disc, vha, 0xffff,
4895 "%s %8phC mem alloc fail.\n",
4896 __func__, e->u.new_sess.port_name);
4897
4898 if (pla)
4899 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4900 return;
4901 }
4902
4903 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004904 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07004905 tfcp = qla2x00_find_fcport_by_wwpn(vha,
4906 e->u.new_sess.port_name, 1);
4907 if (tfcp) {
4908 /* should rarily happen */
4909 ql_dbg(ql_dbg_disc, vha, 0xffff,
4910 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
4911 __func__, tfcp->port_name, tfcp->disc_state,
4912 tfcp->fw_login_state);
4913
4914 free_fcport = 1;
4915 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08004916 list_add_tail(&fcport->list, &vha->vp_fcports);
4917
Quinn Tran19759032017-12-04 14:45:15 -08004918 }
4919 if (pla) {
4920 qlt_plogi_ack_link(vha, pla, fcport,
4921 QLT_PLOGI_LINK_SAME_WWN);
4922 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08004923 }
4924 }
4925 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4926
4927 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08004928 fcport->id_changed = 1;
4929 fcport->scan_state = QLA_FCPORT_FOUND;
4930 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
4931
Quinn Tran5ef696a2017-12-04 14:45:05 -08004932 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004933 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
4934 u16 wd3_lo;
4935
4936 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4937 fcport->local = 0;
4938 fcport->loop_id =
4939 le16_to_cpu(
4940 pla->iocb.u.isp24.nport_handle);
4941 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4942 wd3_lo =
4943 le16_to_cpu(
4944 pla->iocb.u.isp24.u.prli.wd3_lo);
4945
4946 if (wd3_lo & BIT_7)
4947 fcport->conf_compl_supported = 1;
4948
4949 if ((wd3_lo & BIT_4) == 0)
4950 fcport->port_type = FCT_INITIATOR;
4951 else
4952 fcport->port_type = FCT_TARGET;
4953 }
Quinn Tran726b8542017-01-19 22:28:00 -08004954 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004955 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004956 fc_port_t *dfcp = NULL;
4957
Quinn Tran5ef696a2017-12-04 14:45:05 -08004958 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4959 tfcp = qla2x00_find_fcport_by_nportid(vha,
4960 &e->u.new_sess.id, 1);
4961 if (tfcp && (tfcp != fcport)) {
4962 /*
4963 * We have a conflict fcport with same NportID.
4964 */
4965 ql_dbg(ql_dbg_disc, vha, 0xffff,
4966 "%s %8phC found conflict b4 add. DS %d LS %d\n",
4967 __func__, tfcp->port_name, tfcp->disc_state,
4968 tfcp->fw_login_state);
4969
4970 switch (tfcp->disc_state) {
4971 case DSC_DELETED:
4972 break;
4973 case DSC_DELETE_PEND:
4974 fcport->login_pause = 1;
4975 tfcp->conflict = fcport;
4976 break;
4977 default:
4978 fcport->login_pause = 1;
4979 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004980 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08004981 break;
4982 }
4983 }
4984 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004985 if (dfcp)
4986 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08004987
Quinn Trana4239942017-12-28 12:33:26 -08004988
Quinn Tran8777e432018-08-02 13:16:57 -07004989 if (N2N_TOPO(vha->hw))
4990 fcport->flags &= ~FCF_FABRIC_DEVICE;
4991
4992 if (N2N_TOPO(vha->hw)) {
4993 if (vha->flags.nvme_enabled) {
4994 fcport->fc4f_nvme = 1;
4995 fcport->n2n_flag = 1;
4996 }
4997 fcport->fw_login_state = 0;
4998 /*
4999 * wait link init done before sending login
5000 */
5001 } else {
5002 qla24xx_fcport_handle_login(vha, fcport);
5003 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08005004 }
Quinn Tran726b8542017-01-19 22:28:00 -08005005 }
Quinn Tranb5d15312017-08-30 10:16:49 -07005006
5007 if (free_fcport) {
5008 qla2x00_free_fcport(fcport);
5009 if (pla)
5010 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5011 }
Quinn Tran726b8542017-01-19 22:28:00 -08005012}
5013
Quinn Trane374f9f2017-12-28 12:33:31 -08005014static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5015{
5016 struct srb *sp = e->u.iosb.sp;
5017 int rval;
5018
5019 rval = qla2x00_start_sp(sp);
5020 if (rval != QLA_SUCCESS) {
5021 ql_dbg(ql_dbg_disc, vha, 0x2043,
5022 "%s: %s: Re-issue IOCB failed (%d).\n",
5023 __func__, sp->name, rval);
5024 qla24xx_sp_unmap(vha, sp);
5025 }
5026}
5027
Andrew Vasquezac280b62009-08-20 11:06:05 -07005028void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005029qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005030{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005031 struct qla_work_evt *e, *tmp;
5032 unsigned long flags;
5033 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005034
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005035 spin_lock_irqsave(&vha->work_lock, flags);
5036 list_splice_init(&vha->work_list, &work);
5037 spin_unlock_irqrestore(&vha->work_lock, flags);
5038
5039 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07005040 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005041
5042 switch (e->type) {
5043 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005044 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005045 e->u.aen.code, e->u.aen.data);
5046 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005047 case QLA_EVT_IDC_ACK:
5048 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5049 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005050 case QLA_EVT_ASYNC_LOGIN:
5051 qla2x00_async_login(vha, e->u.logio.fcport,
5052 e->u.logio.data);
5053 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005054 case QLA_EVT_ASYNC_LOGOUT:
5055 qla2x00_async_logout(vha, e->u.logio.fcport);
5056 break;
5057 case QLA_EVT_ASYNC_LOGOUT_DONE:
5058 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5059 e->u.logio.data);
5060 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005061 case QLA_EVT_ASYNC_ADISC:
5062 qla2x00_async_adisc(vha, e->u.logio.fcport,
5063 e->u.logio.data);
5064 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005065 case QLA_EVT_UEVENT:
5066 qla2x00_uevent_emit(vha, e->u.uevent.code);
5067 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005068 case QLA_EVT_AENFX:
5069 qlafx00_process_aen(vha, e);
5070 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005071 case QLA_EVT_GPNID:
5072 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5073 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005074 case QLA_EVT_UNMAP:
5075 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005076 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005077 case QLA_EVT_RELOGIN:
5078 qla2x00_relogin(vha);
5079 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005080 case QLA_EVT_NEW_SESS:
5081 qla24xx_create_new_sess(vha, e);
5082 break;
5083 case QLA_EVT_GPDB:
5084 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5085 e->u.fcport.opt);
5086 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005087 case QLA_EVT_PRLI:
5088 qla24xx_async_prli(vha, e->u.fcport.fcport);
5089 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005090 case QLA_EVT_GPSC:
5091 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5092 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005093 case QLA_EVT_GNL:
5094 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5095 break;
5096 case QLA_EVT_NACK:
5097 qla24xx_do_nack_work(vha, e);
5098 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005099 case QLA_EVT_ASYNC_PRLO:
5100 qla2x00_async_prlo(vha, e->u.logio.fcport);
5101 break;
5102 case QLA_EVT_ASYNC_PRLO_DONE:
5103 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5104 e->u.logio.data);
5105 break;
Quinn Trana4239942017-12-28 12:33:26 -08005106 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005107 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5108 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005109 break;
5110 case QLA_EVT_GPNFT_DONE:
5111 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5112 break;
5113 case QLA_EVT_GNNFT_DONE:
5114 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5115 break;
5116 case QLA_EVT_GNNID:
5117 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5118 break;
5119 case QLA_EVT_GFPNID:
5120 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5121 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005122 case QLA_EVT_SP_RETRY:
5123 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005124 break;
5125 case QLA_EVT_IIDMA:
5126 qla_do_iidma_work(vha, e->u.fcport.fcport);
5127 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005128 case QLA_EVT_ELS_PLOGI:
5129 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5130 e->u.fcport.fcport, false);
5131 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005132 }
5133 if (e->flags & QLA_EVT_FLAG_FREE)
5134 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005135
5136 /* For each work completed decrement vha ref count */
5137 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005138 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005139}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005140
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005141int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5142{
5143 struct qla_work_evt *e;
5144
5145 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5146
5147 if (!e) {
5148 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5149 return QLA_FUNCTION_FAILED;
5150 }
5151
5152 return qla2x00_post_work(vha, e);
5153}
5154
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005155/* Relogins all the fcports of a vport
5156 * Context: dpc thread
5157 */
5158void qla2x00_relogin(struct scsi_qla_host *vha)
5159{
5160 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005161 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005162 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005163
5164 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005165 /*
5166 * If the port is not ONLINE then try to login
5167 * to it if we haven't run out of retries.
5168 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005169 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005170 fcport->login_retry) {
5171 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5172 fcport->disc_state == DSC_LOGIN_COMPLETE)
5173 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005174
Quinn Tran23dd98a2018-08-02 13:16:45 -07005175 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5176 fcport->disc_state == DSC_DELETE_PEND) {
5177 relogin_needed = 1;
5178 } else {
5179 if (vha->hw->current_topology != ISP_CFG_NL) {
5180 memset(&ea, 0, sizeof(ea));
5181 ea.event = FCME_RELOGIN;
5182 ea.fcport = fcport;
5183 qla2x00_fcport_event_handler(vha, &ea);
5184 } else if (vha->hw->current_topology ==
5185 ISP_CFG_NL) {
5186 fcport->login_retry--;
5187 status =
5188 qla2x00_local_device_login(vha,
5189 fcport);
5190 if (status == QLA_SUCCESS) {
5191 fcport->old_loop_id =
5192 fcport->loop_id;
5193 ql_dbg(ql_dbg_disc, vha, 0x2003,
5194 "Port login OK: logged in ID 0x%x.\n",
5195 fcport->loop_id);
5196 qla2x00_update_fcport
5197 (vha, fcport);
5198 } else if (status == 1) {
5199 set_bit(RELOGIN_NEEDED,
5200 &vha->dpc_flags);
5201 /* retry the login again */
5202 ql_dbg(ql_dbg_disc, vha, 0x2007,
5203 "Retrying %d login again loop_id 0x%x.\n",
5204 fcport->login_retry,
5205 fcport->loop_id);
5206 } else {
5207 fcport->login_retry = 0;
5208 }
5209
5210 if (fcport->login_retry == 0 &&
5211 status != QLA_SUCCESS)
5212 qla2x00_clear_loop_id(fcport);
5213 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005214 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005215 }
5216 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5217 break;
5218 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005219
Quinn Tran23dd98a2018-08-02 13:16:45 -07005220 if (relogin_needed)
5221 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5222
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005223 ql_dbg(ql_dbg_disc, vha, 0x400e,
5224 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005225}
5226
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005227/* Schedule work on any of the dpc-workqueues */
5228void
5229qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5230{
5231 struct qla_hw_data *ha = base_vha->hw;
5232
5233 switch (work_code) {
5234 case MBA_IDC_AEN: /* 0x8200 */
5235 if (ha->dpc_lp_wq)
5236 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5237 break;
5238
5239 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5240 if (!ha->flags.nic_core_reset_hdlr_active) {
5241 if (ha->dpc_hp_wq)
5242 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5243 } else
5244 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5245 "NIC Core reset is already active. Skip "
5246 "scheduling it again.\n");
5247 break;
5248 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5249 if (ha->dpc_hp_wq)
5250 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5251 break;
5252 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5253 if (ha->dpc_hp_wq)
5254 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5255 break;
5256 default:
5257 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005258 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005259 }
5260
5261 return;
5262}
5263
5264/* Work: Perform NIC Core Unrecoverable state handling */
5265void
5266qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5267{
5268 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005269 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005270 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5271 uint32_t dev_state = 0;
5272
5273 qla83xx_idc_lock(base_vha, 0);
5274 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5275 qla83xx_reset_ownership(base_vha);
5276 if (ha->flags.nic_core_reset_owner) {
5277 ha->flags.nic_core_reset_owner = 0;
5278 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5279 QLA8XXX_DEV_FAILED);
5280 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5281 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5282 }
5283 qla83xx_idc_unlock(base_vha, 0);
5284}
5285
5286/* Work: Execute IDC state handler */
5287void
5288qla83xx_idc_state_handler_work(struct work_struct *work)
5289{
5290 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005291 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005292 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5293 uint32_t dev_state = 0;
5294
5295 qla83xx_idc_lock(base_vha, 0);
5296 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5297 if (dev_state == QLA8XXX_DEV_FAILED ||
5298 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5299 qla83xx_idc_state_handler(base_vha);
5300 qla83xx_idc_unlock(base_vha, 0);
5301}
5302
Saurav Kashyapfa492632012-11-21 02:40:29 -05005303static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005304qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5305{
5306 int rval = QLA_SUCCESS;
5307 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5308 uint32_t heart_beat_counter1, heart_beat_counter2;
5309
5310 do {
5311 if (time_after(jiffies, heart_beat_wait)) {
5312 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5313 "Nic Core f/w is not alive.\n");
5314 rval = QLA_FUNCTION_FAILED;
5315 break;
5316 }
5317
5318 qla83xx_idc_lock(base_vha, 0);
5319 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5320 &heart_beat_counter1);
5321 qla83xx_idc_unlock(base_vha, 0);
5322 msleep(100);
5323 qla83xx_idc_lock(base_vha, 0);
5324 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5325 &heart_beat_counter2);
5326 qla83xx_idc_unlock(base_vha, 0);
5327 } while (heart_beat_counter1 == heart_beat_counter2);
5328
5329 return rval;
5330}
5331
5332/* Work: Perform NIC Core Reset handling */
5333void
5334qla83xx_nic_core_reset_work(struct work_struct *work)
5335{
5336 struct qla_hw_data *ha =
5337 container_of(work, struct qla_hw_data, nic_core_reset);
5338 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5339 uint32_t dev_state = 0;
5340
Saurav Kashyap81178772012-08-22 14:21:04 -04005341 if (IS_QLA2031(ha)) {
5342 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5343 ql_log(ql_log_warn, base_vha, 0xb081,
5344 "Failed to dump mctp\n");
5345 return;
5346 }
5347
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005348 if (!ha->flags.nic_core_reset_hdlr_active) {
5349 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5350 qla83xx_idc_lock(base_vha, 0);
5351 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5352 &dev_state);
5353 qla83xx_idc_unlock(base_vha, 0);
5354 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5355 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5356 "Nic Core f/w is alive.\n");
5357 return;
5358 }
5359 }
5360
5361 ha->flags.nic_core_reset_hdlr_active = 1;
5362 if (qla83xx_nic_core_reset(base_vha)) {
5363 /* NIC Core reset failed. */
5364 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5365 "NIC Core reset failed.\n");
5366 }
5367 ha->flags.nic_core_reset_hdlr_active = 0;
5368 }
5369}
5370
5371/* Work: Handle 8200 IDC aens */
5372void
5373qla83xx_service_idc_aen(struct work_struct *work)
5374{
5375 struct qla_hw_data *ha =
5376 container_of(work, struct qla_hw_data, idc_aen);
5377 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5378 uint32_t dev_state, idc_control;
5379
5380 qla83xx_idc_lock(base_vha, 0);
5381 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5382 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5383 qla83xx_idc_unlock(base_vha, 0);
5384 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5385 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5386 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5387 "Application requested NIC Core Reset.\n");
5388 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5389 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5390 QLA_SUCCESS) {
5391 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5392 "Other protocol driver requested NIC Core Reset.\n");
5393 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5394 }
5395 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5396 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5397 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5398 }
5399}
5400
5401static void
5402qla83xx_wait_logic(void)
5403{
5404 int i;
5405
5406 /* Yield CPU */
5407 if (!in_interrupt()) {
5408 /*
5409 * Wait about 200ms before retrying again.
5410 * This controls the number of retries for single
5411 * lock operation.
5412 */
5413 msleep(100);
5414 schedule();
5415 } else {
5416 for (i = 0; i < 20; i++)
5417 cpu_relax(); /* This a nop instr on i386 */
5418 }
5419}
5420
Saurav Kashyapfa492632012-11-21 02:40:29 -05005421static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005422qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5423{
5424 int rval;
5425 uint32_t data;
5426 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5427 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5428 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005429 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5430 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005431
5432 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5433 if (rval)
5434 return rval;
5435
5436 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5437 return QLA_SUCCESS;
5438 } else {
5439 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5440 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5441 data);
5442 if (rval)
5443 return rval;
5444
5445 msleep(200);
5446
5447 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5448 &data);
5449 if (rval)
5450 return rval;
5451
5452 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5453 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5454 ~(idc_lck_rcvry_stage_mask));
5455 rval = qla83xx_wr_reg(base_vha,
5456 QLA83XX_IDC_LOCK_RECOVERY, data);
5457 if (rval)
5458 return rval;
5459
5460 /* Forcefully perform IDC UnLock */
5461 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5462 &data);
5463 if (rval)
5464 return rval;
5465 /* Clear lock-id by setting 0xff */
5466 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5467 0xff);
5468 if (rval)
5469 return rval;
5470 /* Clear lock-recovery by setting 0x0 */
5471 rval = qla83xx_wr_reg(base_vha,
5472 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5473 if (rval)
5474 return rval;
5475 } else
5476 return QLA_SUCCESS;
5477 }
5478
5479 return rval;
5480}
5481
Saurav Kashyapfa492632012-11-21 02:40:29 -05005482static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005483qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5484{
5485 int rval = QLA_SUCCESS;
5486 uint32_t o_drv_lockid, n_drv_lockid;
5487 unsigned long lock_recovery_timeout;
5488
5489 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5490retry_lockid:
5491 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5492 if (rval)
5493 goto exit;
5494
5495 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5496 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5497 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5498 return QLA_SUCCESS;
5499 else
5500 return QLA_FUNCTION_FAILED;
5501 }
5502
5503 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5504 if (rval)
5505 goto exit;
5506
5507 if (o_drv_lockid == n_drv_lockid) {
5508 qla83xx_wait_logic();
5509 goto retry_lockid;
5510 } else
5511 return QLA_SUCCESS;
5512
5513exit:
5514 return rval;
5515}
5516
5517void
5518qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5519{
5520 uint16_t options = (requester_id << 15) | BIT_6;
5521 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005522 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005523 struct qla_hw_data *ha = base_vha->hw;
5524
5525 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5526retry_lock:
5527 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5528 == QLA_SUCCESS) {
5529 if (data) {
5530 /* Setting lock-id to our function-number */
5531 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5532 ha->portnum);
5533 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005534 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5535 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005536 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005537 "Failed to acquire IDC lock, acquired by %d, "
5538 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005539
5540 /* Retry/Perform IDC-Lock recovery */
5541 if (qla83xx_idc_lock_recovery(base_vha)
5542 == QLA_SUCCESS) {
5543 qla83xx_wait_logic();
5544 goto retry_lock;
5545 } else
5546 ql_log(ql_log_warn, base_vha, 0xb075,
5547 "IDC Lock recovery FAILED.\n");
5548 }
5549
5550 }
5551
5552 return;
5553
5554 /* XXX: IDC-lock implementation using access-control mbx */
5555retry_lock2:
5556 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5557 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5558 "Failed to acquire IDC lock. retrying...\n");
5559 /* Retry/Perform IDC-Lock recovery */
5560 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5561 qla83xx_wait_logic();
5562 goto retry_lock2;
5563 } else
5564 ql_log(ql_log_warn, base_vha, 0xb076,
5565 "IDC Lock recovery FAILED.\n");
5566 }
5567
5568 return;
5569}
5570
5571void
5572qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5573{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005574#if 0
5575 uint16_t options = (requester_id << 15) | BIT_7;
5576#endif
5577 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005578 uint32_t data;
5579 struct qla_hw_data *ha = base_vha->hw;
5580
5581 /* IDC-unlock implementation using driver-unlock/lock-id
5582 * remote registers
5583 */
5584 retry = 0;
5585retry_unlock:
5586 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5587 == QLA_SUCCESS) {
5588 if (data == ha->portnum) {
5589 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5590 /* Clearing lock-id by setting 0xff */
5591 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5592 } else if (retry < 10) {
5593 /* SV: XXX: IDC unlock retrying needed here? */
5594
5595 /* Retry for IDC-unlock */
5596 qla83xx_wait_logic();
5597 retry++;
5598 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005599 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005600 goto retry_unlock;
5601 }
5602 } else if (retry < 10) {
5603 /* Retry for IDC-unlock */
5604 qla83xx_wait_logic();
5605 retry++;
5606 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005607 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005608 goto retry_unlock;
5609 }
5610
5611 return;
5612
Bart Van Assche5897cb22015-06-04 15:57:20 -07005613#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005614 /* XXX: IDC-unlock implementation using access-control mbx */
5615 retry = 0;
5616retry_unlock2:
5617 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5618 if (retry < 10) {
5619 /* Retry for IDC-unlock */
5620 qla83xx_wait_logic();
5621 retry++;
5622 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005623 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005624 goto retry_unlock2;
5625 }
5626 }
5627
5628 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005629#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005630}
5631
5632int
5633__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5634{
5635 int rval = QLA_SUCCESS;
5636 struct qla_hw_data *ha = vha->hw;
5637 uint32_t drv_presence;
5638
5639 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5640 if (rval == QLA_SUCCESS) {
5641 drv_presence |= (1 << ha->portnum);
5642 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5643 drv_presence);
5644 }
5645
5646 return rval;
5647}
5648
5649int
5650qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5651{
5652 int rval = QLA_SUCCESS;
5653
5654 qla83xx_idc_lock(vha, 0);
5655 rval = __qla83xx_set_drv_presence(vha);
5656 qla83xx_idc_unlock(vha, 0);
5657
5658 return rval;
5659}
5660
5661int
5662__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5663{
5664 int rval = QLA_SUCCESS;
5665 struct qla_hw_data *ha = vha->hw;
5666 uint32_t drv_presence;
5667
5668 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5669 if (rval == QLA_SUCCESS) {
5670 drv_presence &= ~(1 << ha->portnum);
5671 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5672 drv_presence);
5673 }
5674
5675 return rval;
5676}
5677
5678int
5679qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5680{
5681 int rval = QLA_SUCCESS;
5682
5683 qla83xx_idc_lock(vha, 0);
5684 rval = __qla83xx_clear_drv_presence(vha);
5685 qla83xx_idc_unlock(vha, 0);
5686
5687 return rval;
5688}
5689
Saurav Kashyapfa492632012-11-21 02:40:29 -05005690static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005691qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5692{
5693 struct qla_hw_data *ha = vha->hw;
5694 uint32_t drv_ack, drv_presence;
5695 unsigned long ack_timeout;
5696
5697 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5698 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5699 while (1) {
5700 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5701 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005702 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005703 break;
5704
5705 if (time_after_eq(jiffies, ack_timeout)) {
5706 ql_log(ql_log_warn, vha, 0xb067,
5707 "RESET ACK TIMEOUT! drv_presence=0x%x "
5708 "drv_ack=0x%x\n", drv_presence, drv_ack);
5709 /*
5710 * The function(s) which did not ack in time are forced
5711 * to withdraw any further participation in the IDC
5712 * reset.
5713 */
5714 if (drv_ack != drv_presence)
5715 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5716 drv_ack);
5717 break;
5718 }
5719
5720 qla83xx_idc_unlock(vha, 0);
5721 msleep(1000);
5722 qla83xx_idc_lock(vha, 0);
5723 }
5724
5725 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5726 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5727}
5728
Saurav Kashyapfa492632012-11-21 02:40:29 -05005729static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005730qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5731{
5732 int rval = QLA_SUCCESS;
5733 uint32_t idc_control;
5734
5735 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5736 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5737
5738 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5739 __qla83xx_get_idc_control(vha, &idc_control);
5740 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5741 __qla83xx_set_idc_control(vha, 0);
5742
5743 qla83xx_idc_unlock(vha, 0);
5744 rval = qla83xx_restart_nic_firmware(vha);
5745 qla83xx_idc_lock(vha, 0);
5746
5747 if (rval != QLA_SUCCESS) {
5748 ql_log(ql_log_fatal, vha, 0xb06a,
5749 "Failed to restart NIC f/w.\n");
5750 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5751 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5752 } else {
5753 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5754 "Success in restarting nic f/w.\n");
5755 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5756 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5757 }
5758
5759 return rval;
5760}
5761
5762/* Assumes idc_lock always held on entry */
5763int
5764qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5765{
5766 struct qla_hw_data *ha = base_vha->hw;
5767 int rval = QLA_SUCCESS;
5768 unsigned long dev_init_timeout;
5769 uint32_t dev_state;
5770
5771 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5772 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5773
5774 while (1) {
5775
5776 if (time_after_eq(jiffies, dev_init_timeout)) {
5777 ql_log(ql_log_warn, base_vha, 0xb06e,
5778 "Initialization TIMEOUT!\n");
5779 /* Init timeout. Disable further NIC Core
5780 * communication.
5781 */
5782 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5783 QLA8XXX_DEV_FAILED);
5784 ql_log(ql_log_info, base_vha, 0xb06f,
5785 "HW State: FAILED.\n");
5786 }
5787
5788 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5789 switch (dev_state) {
5790 case QLA8XXX_DEV_READY:
5791 if (ha->flags.nic_core_reset_owner)
5792 qla83xx_idc_audit(base_vha,
5793 IDC_AUDIT_COMPLETION);
5794 ha->flags.nic_core_reset_owner = 0;
5795 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5796 "Reset_owner reset by 0x%x.\n",
5797 ha->portnum);
5798 goto exit;
5799 case QLA8XXX_DEV_COLD:
5800 if (ha->flags.nic_core_reset_owner)
5801 rval = qla83xx_device_bootstrap(base_vha);
5802 else {
5803 /* Wait for AEN to change device-state */
5804 qla83xx_idc_unlock(base_vha, 0);
5805 msleep(1000);
5806 qla83xx_idc_lock(base_vha, 0);
5807 }
5808 break;
5809 case QLA8XXX_DEV_INITIALIZING:
5810 /* Wait for AEN to change device-state */
5811 qla83xx_idc_unlock(base_vha, 0);
5812 msleep(1000);
5813 qla83xx_idc_lock(base_vha, 0);
5814 break;
5815 case QLA8XXX_DEV_NEED_RESET:
5816 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5817 qla83xx_need_reset_handler(base_vha);
5818 else {
5819 /* Wait for AEN to change device-state */
5820 qla83xx_idc_unlock(base_vha, 0);
5821 msleep(1000);
5822 qla83xx_idc_lock(base_vha, 0);
5823 }
5824 /* reset timeout value after need reset handler */
5825 dev_init_timeout = jiffies +
5826 (ha->fcoe_dev_init_timeout * HZ);
5827 break;
5828 case QLA8XXX_DEV_NEED_QUIESCENT:
5829 /* XXX: DEBUG for now */
5830 qla83xx_idc_unlock(base_vha, 0);
5831 msleep(1000);
5832 qla83xx_idc_lock(base_vha, 0);
5833 break;
5834 case QLA8XXX_DEV_QUIESCENT:
5835 /* XXX: DEBUG for now */
5836 if (ha->flags.quiesce_owner)
5837 goto exit;
5838
5839 qla83xx_idc_unlock(base_vha, 0);
5840 msleep(1000);
5841 qla83xx_idc_lock(base_vha, 0);
5842 dev_init_timeout = jiffies +
5843 (ha->fcoe_dev_init_timeout * HZ);
5844 break;
5845 case QLA8XXX_DEV_FAILED:
5846 if (ha->flags.nic_core_reset_owner)
5847 qla83xx_idc_audit(base_vha,
5848 IDC_AUDIT_COMPLETION);
5849 ha->flags.nic_core_reset_owner = 0;
5850 __qla83xx_clear_drv_presence(base_vha);
5851 qla83xx_idc_unlock(base_vha, 0);
5852 qla8xxx_dev_failed_handler(base_vha);
5853 rval = QLA_FUNCTION_FAILED;
5854 qla83xx_idc_lock(base_vha, 0);
5855 goto exit;
5856 case QLA8XXX_BAD_VALUE:
5857 qla83xx_idc_unlock(base_vha, 0);
5858 msleep(1000);
5859 qla83xx_idc_lock(base_vha, 0);
5860 break;
5861 default:
5862 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005863 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005864 qla83xx_idc_unlock(base_vha, 0);
5865 qla8xxx_dev_failed_handler(base_vha);
5866 rval = QLA_FUNCTION_FAILED;
5867 qla83xx_idc_lock(base_vha, 0);
5868 goto exit;
5869 }
5870 }
5871
5872exit:
5873 return rval;
5874}
5875
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005876void
5877qla2x00_disable_board_on_pci_error(struct work_struct *work)
5878{
5879 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5880 board_disable);
5881 struct pci_dev *pdev = ha->pdev;
5882 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5883
Quinn Tran726b8542017-01-19 22:28:00 -08005884 /*
5885 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005886 * where it was set first.
5887 */
5888 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5889 return;
5890
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005891 ql_log(ql_log_warn, base_vha, 0x015b,
5892 "Disabling adapter.\n");
5893
Sawan Chandakefdb5762017-08-23 15:05:00 -07005894 if (!atomic_read(&pdev->enable_cnt)) {
5895 ql_log(ql_log_info, base_vha, 0xfffc,
5896 "PCI device disabled, no action req for PCI error=%lx\n",
5897 base_vha->pci_flags);
5898 return;
5899 }
5900
Quinn Tran726b8542017-01-19 22:28:00 -08005901 qla2x00_wait_for_sess_deletion(base_vha);
5902
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005903 set_bit(UNLOADING, &base_vha->dpc_flags);
5904
5905 qla2x00_delete_all_vps(ha, base_vha);
5906
5907 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5908
5909 qla2x00_dfs_remove(base_vha);
5910
5911 qla84xx_put_chip(base_vha);
5912
5913 if (base_vha->timer_active)
5914 qla2x00_stop_timer(base_vha);
5915
5916 base_vha->flags.online = 0;
5917
5918 qla2x00_destroy_deferred_work(ha);
5919
5920 /*
5921 * Do not try to stop beacon blink as it will issue a mailbox
5922 * command.
5923 */
5924 qla2x00_free_sysfs_attr(base_vha, false);
5925
5926 fc_remove_host(base_vha->host);
5927
5928 scsi_remove_host(base_vha->host);
5929
5930 base_vha->flags.init_done = 0;
5931 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005932 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005933 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005934 qla2x00_mem_free(ha);
5935 qla82xx_md_free(base_vha);
5936 qla2x00_free_queues(ha);
5937
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005938 qla2x00_unmap_iobases(ha);
5939
5940 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005941 pci_disable_pcie_error_reporting(pdev);
5942 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005943
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005944 /*
5945 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5946 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005947}
5948
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949/**************************************************************************
5950* qla2x00_do_dpc
5951* This kernel thread is a task that is schedule by the interrupt handler
5952* to perform the background processing for interrupts.
5953*
5954* Notes:
5955* This task always run in the context of a kernel thread. It
5956* is kick-off by the driver's detect code and starts up
5957* up one per adapter. It immediately goes to sleep and waits for
5958* some fibre event. When either the interrupt handler or
5959* the timer routine detects a event it will one of the task
5960* bits then wake us up.
5961**************************************************************************/
5962static int
5963qla2x00_do_dpc(void *data)
5964{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005965 scsi_qla_host_t *base_vha;
5966 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005967 uint32_t online;
5968 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005970 ha = (struct qla_hw_data *)data;
5971 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972
Dongsheng Yang8698a742014-03-11 18:09:12 +08005973 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974
James Bottomley563585e2011-01-27 16:12:37 -05005975 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005976 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005977 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5978 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979
Christoph Hellwig39a11242006-02-14 18:46:22 +01005980 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005982 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5983 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984
Andrew Vasquez85880802009-12-15 21:29:46 -08005985 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005986 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5987 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005988 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005989 }
5990
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 ha->dpc_active = 1;
5992
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005993 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5994 "DPC handler waking up, dpc_flags=0x%lx.\n",
5995 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005997 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5998 break;
5999
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006000 if (IS_P3P_TYPE(ha)) {
6001 if (IS_QLA8044(ha)) {
6002 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6003 &base_vha->dpc_flags)) {
6004 qla8044_idc_lock(ha);
6005 qla8044_wr_direct(base_vha,
6006 QLA8044_CRB_DEV_STATE_INDEX,
6007 QLA8XXX_DEV_FAILED);
6008 qla8044_idc_unlock(ha);
6009 ql_log(ql_log_info, base_vha, 0x4004,
6010 "HW State: FAILED.\n");
6011 qla8044_device_state_handler(base_vha);
6012 continue;
6013 }
6014
6015 } else {
6016 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6017 &base_vha->dpc_flags)) {
6018 qla82xx_idc_lock(ha);
6019 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6020 QLA8XXX_DEV_FAILED);
6021 qla82xx_idc_unlock(ha);
6022 ql_log(ql_log_info, base_vha, 0x0151,
6023 "HW State: FAILED.\n");
6024 qla82xx_device_state_handler(base_vha);
6025 continue;
6026 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006027 }
6028
6029 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6030 &base_vha->dpc_flags)) {
6031
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006032 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6033 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006034 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6035 &base_vha->dpc_flags))) {
6036 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6037 /* FCoE-ctx reset failed.
6038 * Escalate to chip-reset
6039 */
6040 set_bit(ISP_ABORT_NEEDED,
6041 &base_vha->dpc_flags);
6042 }
6043 clear_bit(ABORT_ISP_ACTIVE,
6044 &base_vha->dpc_flags);
6045 }
6046
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006047 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6048 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006049 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006050 } else if (IS_QLAFX00(ha)) {
6051 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6052 &base_vha->dpc_flags)) {
6053 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6054 "Firmware Reset Recovery\n");
6055 if (qlafx00_reset_initialize(base_vha)) {
6056 /* Failed. Abort isp later. */
6057 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006058 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006059 set_bit(ISP_UNRECOVERABLE,
6060 &base_vha->dpc_flags);
6061 ql_dbg(ql_dbg_dpc, base_vha,
6062 0x4021,
6063 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006064 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006065 }
6066 }
6067
6068 if (test_and_clear_bit(FX00_TARGET_SCAN,
6069 &base_vha->dpc_flags)) {
6070 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6071 "ISPFx00 Target Scan scheduled\n");
6072 if (qlafx00_rescan_isp(base_vha)) {
6073 if (!test_bit(UNLOADING,
6074 &base_vha->dpc_flags))
6075 set_bit(ISP_UNRECOVERABLE,
6076 &base_vha->dpc_flags);
6077 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6078 "ISPFx00 Target Scan Failed\n");
6079 }
6080 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6081 "ISPFx00 Target Scan End\n");
6082 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006083 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6084 &base_vha->dpc_flags)) {
6085 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6086 "ISPFx00 Host Info resend scheduled\n");
6087 qlafx00_fx_disc(base_vha,
6088 &base_vha->hw->mr.fcport,
6089 FXDISC_REG_HOST_INFO);
6090 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006091 }
6092
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006093 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6094 &base_vha->dpc_flags) &&
6095 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6096 qla24xx_detect_sfp(base_vha);
6097
6098 if (ha->flags.detected_lr_sfp !=
6099 ha->flags.using_lr_setting)
6100 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6101 }
6102
Quinn Tranb08abbd2018-07-18 14:29:54 -07006103 if (test_and_clear_bit
6104 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6105 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006106 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107
Quinn Tran0645cb82018-09-11 10:18:18 -07006108 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006109 case QLA2XXX_INI_MODE_ENABLED:
6110 break;
6111 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006112 if (!qla_tgt_mode_enabled(base_vha) &&
6113 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006114 do_reset = false;
6115 break;
6116 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006117 if (!qla_dual_mode_enabled(base_vha) &&
6118 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006119 do_reset = false;
6120 break;
6121 default:
6122 break;
6123 }
6124
6125 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006126 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006127 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6128 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006129 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130 /* failed. retry later */
6131 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006132 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006134 clear_bit(ABORT_ISP_ACTIVE,
6135 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006136 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6137 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 }
6140
David Jefferya394aac2012-11-21 02:39:54 -05006141 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6142 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006143 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006144 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006145
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006146 if (IS_QLAFX00(ha))
6147 goto loop_resync_check;
6148
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006149 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006150 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6151 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006152 if (IS_P3P_TYPE(ha)) {
6153 if (IS_QLA82XX(ha))
6154 qla82xx_device_state_handler(base_vha);
6155 if (IS_QLA8044(ha))
6156 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006157 clear_bit(ISP_QUIESCE_NEEDED,
6158 &base_vha->dpc_flags);
6159 if (!ha->flags.quiesce_owner) {
6160 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006161 if (IS_QLA82XX(ha)) {
6162 qla82xx_idc_lock(ha);
6163 qla82xx_clear_qsnt_ready(
6164 base_vha);
6165 qla82xx_idc_unlock(ha);
6166 } else if (IS_QLA8044(ha)) {
6167 qla8044_idc_lock(ha);
6168 qla8044_clear_qsnt_ready(
6169 base_vha);
6170 qla8044_idc_unlock(ha);
6171 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006172 }
6173 } else {
6174 clear_bit(ISP_QUIESCE_NEEDED,
6175 &base_vha->dpc_flags);
6176 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006177 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006178 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6179 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006180 }
6181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006182 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006183 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006184 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006186 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6187 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006188 qla2x00_rst_aen(base_vha);
6189 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006190 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6191 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 }
6193
6194 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006195 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006196 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6197 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198
Quinn Tran4005a992017-12-04 14:45:06 -08006199 if (!base_vha->relogin_jif ||
6200 time_after_eq(jiffies, base_vha->relogin_jif)) {
6201 base_vha->relogin_jif = jiffies + HZ;
6202 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6203
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006204 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006205 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006206 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006209loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006210 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006211 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006213 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6214 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215
6216 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006217 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218
Bart Van Assche52c82822015-07-09 07:23:26 -07006219 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006221 clear_bit(LOOP_RESYNC_ACTIVE,
6222 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223 }
6224
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006225 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6226 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 }
6228
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006229 if (IS_QLAFX00(ha))
6230 goto intr_on_check;
6231
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006232 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6233 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6234 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6235 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006236 }
6237
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006238intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006240 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006242 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006243 &base_vha->dpc_flags)) {
6244 if (ha->beacon_blink_led == 1)
6245 ha->isp_ops->beacon_blink(base_vha);
6246 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006247
Michael Hernandezd7459522016-12-12 14:40:07 -08006248 /* qpair online check */
6249 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6250 &base_vha->dpc_flags)) {
6251 if (ha->flags.eeh_busy ||
6252 ha->flags.pci_channel_io_perm_failure)
6253 online = 0;
6254 else
6255 online = 1;
6256
6257 mutex_lock(&ha->mq_lock);
6258 list_for_each_entry(qpair, &base_vha->qp_list,
6259 qp_list_elem)
6260 qpair->online = online;
6261 mutex_unlock(&ha->mq_lock);
6262 }
6263
Quinn Tran8b4673b2018-09-04 14:19:14 -07006264 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6265 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006266 ql_log(ql_log_info, base_vha, 0xffffff,
6267 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6268 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006269 if (qla27xx_set_zio_threshold(base_vha,
6270 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006271 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006272 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6273 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006274 }
6275 }
6276
Quinn Tran8b4673b2018-09-04 14:19:14 -07006277 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6278 &base_vha->dpc_flags)) {
6279 ql_log(ql_log_info, base_vha, 0xffffff,
6280 "SET ZIO Activity exchange threshold to %d.\n",
6281 ha->last_zio_threshold);
6282 qla27xx_set_zio_threshold(base_vha,
6283 ha->last_zio_threshold);
6284 }
6285
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006286 if (!IS_QLAFX00(ha))
6287 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006288
Quinn Tran48acad02018-08-02 13:16:44 -07006289 if (test_and_clear_bit(N2N_LINK_RESET,
6290 &base_vha->dpc_flags)) {
6291 qla2x00_lip_reset(base_vha);
6292 }
6293
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006295end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006296 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006298 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006300 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6301 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302
6303 /*
6304 * Make sure that nobody tries to wake us up again.
6305 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 ha->dpc_active = 0;
6307
Andrew Vasquezac280b62009-08-20 11:06:05 -07006308 /* Cleanup any residual CTX SRBs. */
6309 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6310
Christoph Hellwig39a11242006-02-14 18:46:22 +01006311 return 0;
6312}
6313
6314void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006315qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006316{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006317 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006318 struct task_struct *t = ha->dpc_thread;
6319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006320 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006321 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322}
6323
6324/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325* qla2x00_rst_aen
6326* Processes asynchronous reset.
6327*
6328* Input:
6329* ha = adapter block pointer.
6330*/
6331static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006332qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006334 if (vha->flags.online && !vha->flags.reset_active &&
6335 !atomic_read(&vha->loop_down_timer) &&
6336 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006338 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339
6340 /*
6341 * Issue marker command only when we are going to start
6342 * the I/O.
6343 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006344 vha->marker_needed = 1;
6345 } while (!atomic_read(&vha->loop_down_timer) &&
6346 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347 }
6348}
6349
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350/**************************************************************************
6351* qla2x00_timer
6352*
6353* Description:
6354* One second timer
6355*
6356* Context: Interrupt
6357***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006358void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006359qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006361 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 int start_dpc = 0;
6364 int index;
6365 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006366 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006367 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006368 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006369
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006370 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006371 ql_dbg(ql_dbg_timer, vha, 0x6000,
6372 "EEH = %d, restarting timer.\n",
6373 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006374 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6375 return;
6376 }
6377
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006378 /*
6379 * Hardware read to raise pending EEH errors during mailbox waits. If
6380 * the read returns -1 then disable the board.
6381 */
6382 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006383 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006384 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006387 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006388 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006389 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6390 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006391 if (IS_QLA82XX(ha))
6392 qla82xx_watchdog(vha);
6393 else if (IS_QLA8044(ha))
6394 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006395 }
6396
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006397 if (!vha->vp_idx && IS_QLAFX00(ha))
6398 qlafx00_timer_routine(vha);
6399
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006401 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006402 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6403 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006404 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006406 if (atomic_read(&vha->loop_down_timer) ==
6407 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006409 ql_log(ql_log_info, vha, 0x6008,
6410 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006412 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6413 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006415 /*
6416 * Schedule an ISP abort to return any FCP2-device
6417 * commands.
6418 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006419 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006420 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006421 spin_lock_irqsave(&ha->hardware_lock,
6422 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006423 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006424 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006425 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006426 index++) {
6427 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006428
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006429 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006430 if (!sp)
6431 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006432 if (sp->cmd_type != TYPE_SRB)
6433 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006434 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006435 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006436 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006437 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006438 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006440 if (IS_QLA82XX(ha))
6441 set_bit(FCOE_CTX_RESET_NEEDED,
6442 &vha->dpc_flags);
6443 else
6444 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006445 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006446 break;
6447 }
6448 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006449 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451 start_dpc++;
6452 }
6453
6454 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006455 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006456 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006457 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 "Loop down - aborting ISP.\n");
6459
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006460 if (IS_QLA82XX(ha))
6461 set_bit(FCOE_CTX_RESET_NEEDED,
6462 &vha->dpc_flags);
6463 else
6464 set_bit(ISP_ABORT_NEEDED,
6465 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 }
6467 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006468 ql_dbg(ql_dbg_timer, vha, 0x600a,
6469 "Loop down - seconds remaining %d.\n",
6470 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006472 /* Check if beacon LED needs to be blinked for physical host only */
6473 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006474 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006475 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006476 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6477 start_dpc++;
6478 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006479 }
6480
Andrew Vasquez550bf572008-04-24 15:21:23 -07006481 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006482 if (!list_empty(&vha->work_list)) {
6483 unsigned long flags;
6484 bool q = false;
6485
6486 spin_lock_irqsave(&vha->work_lock, flags);
6487 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6488 q = true;
6489 spin_unlock_irqrestore(&vha->work_lock, flags);
6490 if (q)
6491 queue_work(vha->hw->wq, &vha->iocb_work);
6492 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006493
Duane Grigsby7401bc12017-06-21 13:48:42 -07006494 /*
6495 * FC-NVME
6496 * see if the active AEN count has changed from what was last reported.
6497 */
Quinn Tran8b4673b2018-09-04 14:19:14 -07006498 if (!vha->vp_idx && (atomic_read(&ha->nvme_active_aen_cnt) !=
6499 ha->nvme_last_rptd_aen) && ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006500 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006501 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6502 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006503 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006504 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6505 start_dpc++;
6506 }
6507
6508 if (!vha->vp_idx &&
6509 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6510 (ha->zio_mode == QLA_ZIO_MODE_6) &&
6511 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
6512 ql_log(ql_log_info, vha, 0x3002,
6513 "Sched: Set ZIO exchange threshold to %d.\n",
6514 ha->last_zio_threshold);
6515 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006516 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6517 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006518 }
6519
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006521 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6522 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6523 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006525 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6526 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006527 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6528 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006529 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006530 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006531 ql_dbg(ql_dbg_timer, vha, 0x600b,
6532 "isp_abort_needed=%d loop_resync_needed=%d "
6533 "fcport_update_needed=%d start_dpc=%d "
6534 "reset_marker_needed=%d",
6535 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6536 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6537 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6538 start_dpc,
6539 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6540 ql_dbg(ql_dbg_timer, vha, 0x600c,
6541 "beacon_blink_needed=%d isp_unrecoverable=%d "
6542 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006543 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006544 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6545 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6546 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6547 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006548 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006549 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006552 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553}
6554
Andrew Vasquez54333832005-11-09 15:49:04 -08006555/* Firmware interface routines. */
6556
Chad Dupuisf73cb692014-02-26 04:15:06 -05006557#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006558#define FW_ISP21XX 0
6559#define FW_ISP22XX 1
6560#define FW_ISP2300 2
6561#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006562#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006563#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006564#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006565#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006566#define FW_ISP2031 8
6567#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006568#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006569
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006570#define FW_FILE_ISP21XX "ql2100_fw.bin"
6571#define FW_FILE_ISP22XX "ql2200_fw.bin"
6572#define FW_FILE_ISP2300 "ql2300_fw.bin"
6573#define FW_FILE_ISP2322 "ql2322_fw.bin"
6574#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006575#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006576#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006577#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006578#define FW_FILE_ISP2031 "ql2600_fw.bin"
6579#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006580#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006581
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006582
Daniel Walkere1e82b62008-05-12 22:21:10 -07006583static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006584
6585static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006586 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6587 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6588 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6589 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6590 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006591 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006592 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006593 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006594 { .name = FW_FILE_ISP2031, },
6595 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006596 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006597};
6598
6599struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006600qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006601{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006602 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006603 struct fw_blob *blob;
6604
Andrew Vasquez54333832005-11-09 15:49:04 -08006605 if (IS_QLA2100(ha)) {
6606 blob = &qla_fw_blobs[FW_ISP21XX];
6607 } else if (IS_QLA2200(ha)) {
6608 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006609 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006610 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006611 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006612 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006613 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006614 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006615 } else if (IS_QLA25XX(ha)) {
6616 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006617 } else if (IS_QLA81XX(ha)) {
6618 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006619 } else if (IS_QLA82XX(ha)) {
6620 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006621 } else if (IS_QLA2031(ha)) {
6622 blob = &qla_fw_blobs[FW_ISP2031];
6623 } else if (IS_QLA8031(ha)) {
6624 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006625 } else if (IS_QLA27XX(ha)) {
6626 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006627 } else {
6628 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006629 }
6630
Daniel Walkere1e82b62008-05-12 22:21:10 -07006631 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006632 if (blob->fw)
6633 goto out;
6634
6635 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006636 ql_log(ql_log_warn, vha, 0x0063,
6637 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006638 blob->fw = NULL;
6639 blob = NULL;
6640 goto out;
6641 }
6642
6643out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006644 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006645 return blob;
6646}
6647
6648static void
6649qla2x00_release_firmware(void)
6650{
6651 int idx;
6652
Daniel Walkere1e82b62008-05-12 22:21:10 -07006653 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006654 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006655 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006656 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006657}
6658
Seokmann Ju14e660e2007-09-20 14:07:36 -07006659static pci_ers_result_t
6660qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6661{
Andrew Vasquez85880802009-12-15 21:29:46 -08006662 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6663 struct qla_hw_data *ha = vha->hw;
6664
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006665 ql_dbg(ql_dbg_aer, vha, 0x9000,
6666 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006667
Sawan Chandakefdb5762017-08-23 15:05:00 -07006668 if (!atomic_read(&pdev->enable_cnt)) {
6669 ql_log(ql_log_info, vha, 0xffff,
6670 "PCI device is disabled,state %x\n", state);
6671 return PCI_ERS_RESULT_NEED_RESET;
6672 }
6673
Seokmann Ju14e660e2007-09-20 14:07:36 -07006674 switch (state) {
6675 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006676 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006677 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006678 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6679 qla2xxx_wake_dpc(vha);
6680 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006681 return PCI_ERS_RESULT_CAN_RECOVER;
6682 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006683 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006684 /* For ISP82XX complete any pending mailbox cmd */
6685 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006686 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006687 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6688 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006689 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006690 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006691 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006692 /* Return back all IOs */
6693 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006694 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006695 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6696 qla2xxx_wake_dpc(vha);
6697 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006698 return PCI_ERS_RESULT_NEED_RESET;
6699 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006700 ha->flags.pci_channel_io_perm_failure = 1;
6701 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006702 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006703 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6704 qla2xxx_wake_dpc(vha);
6705 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006706 return PCI_ERS_RESULT_DISCONNECT;
6707 }
6708 return PCI_ERS_RESULT_NEED_RESET;
6709}
6710
6711static pci_ers_result_t
6712qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6713{
6714 int risc_paused = 0;
6715 uint32_t stat;
6716 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006717 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6718 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006719 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6720 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6721
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006722 if (IS_QLA82XX(ha))
6723 return PCI_ERS_RESULT_RECOVERED;
6724
Seokmann Ju14e660e2007-09-20 14:07:36 -07006725 spin_lock_irqsave(&ha->hardware_lock, flags);
6726 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6727 stat = RD_REG_DWORD(&reg->hccr);
6728 if (stat & HCCR_RISC_PAUSE)
6729 risc_paused = 1;
6730 } else if (IS_QLA23XX(ha)) {
6731 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6732 if (stat & HSR_RISC_PAUSED)
6733 risc_paused = 1;
6734 } else if (IS_FWI2_CAPABLE(ha)) {
6735 stat = RD_REG_DWORD(&reg24->host_status);
6736 if (stat & HSRX_RISC_PAUSED)
6737 risc_paused = 1;
6738 }
6739 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6740
6741 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006742 ql_log(ql_log_info, base_vha, 0x9003,
6743 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006744 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006745
6746 return PCI_ERS_RESULT_NEED_RESET;
6747 } else
6748 return PCI_ERS_RESULT_RECOVERED;
6749}
6750
Saurav Kashyapfa492632012-11-21 02:40:29 -05006751static uint32_t
6752qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006753{
6754 uint32_t rval = QLA_FUNCTION_FAILED;
6755 uint32_t drv_active = 0;
6756 struct qla_hw_data *ha = base_vha->hw;
6757 int fn;
6758 struct pci_dev *other_pdev = NULL;
6759
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006760 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6761 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006762
6763 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6764
6765 if (base_vha->flags.online) {
6766 /* Abort all outstanding commands,
6767 * so as to be requeued later */
6768 qla2x00_abort_isp_cleanup(base_vha);
6769 }
6770
6771
6772 fn = PCI_FUNC(ha->pdev->devfn);
6773 while (fn > 0) {
6774 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006775 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6776 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006777 other_pdev =
6778 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6779 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6780 fn));
6781
6782 if (!other_pdev)
6783 continue;
6784 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006785 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6786 "Found PCI func available and enable at 0x%x.\n",
6787 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006788 pci_dev_put(other_pdev);
6789 break;
6790 }
6791 pci_dev_put(other_pdev);
6792 }
6793
6794 if (!fn) {
6795 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006796 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6797 "This devfn is reset owner = 0x%x.\n",
6798 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006799 qla82xx_idc_lock(ha);
6800
6801 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006802 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006803
6804 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6805 QLA82XX_IDC_VERSION);
6806
6807 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006808 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6809 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006810
6811 qla82xx_idc_unlock(ha);
6812 /* Reset if device is not already reset
6813 * drv_active would be 0 if a reset has already been done
6814 */
6815 if (drv_active)
6816 rval = qla82xx_start_firmware(base_vha);
6817 else
6818 rval = QLA_SUCCESS;
6819 qla82xx_idc_lock(ha);
6820
6821 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006822 ql_log(ql_log_info, base_vha, 0x900b,
6823 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006824 qla82xx_clear_drv_active(ha);
6825 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006826 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006827 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006828 ql_log(ql_log_info, base_vha, 0x900c,
6829 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006830 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006831 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006832 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006833 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006834 rval = qla82xx_restart_isp(base_vha);
6835 qla82xx_idc_lock(ha);
6836 /* Clear driver state register */
6837 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6838 qla82xx_set_drv_active(base_vha);
6839 }
6840 qla82xx_idc_unlock(ha);
6841 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006842 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6843 "This devfn is not reset owner = 0x%x.\n",
6844 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006845 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006846 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006847 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006848 rval = qla82xx_restart_isp(base_vha);
6849 qla82xx_idc_lock(ha);
6850 qla82xx_set_drv_active(base_vha);
6851 qla82xx_idc_unlock(ha);
6852 }
6853 }
6854 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6855
6856 return rval;
6857}
6858
Seokmann Ju14e660e2007-09-20 14:07:36 -07006859static pci_ers_result_t
6860qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6861{
6862 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006863 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6864 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006865 struct rsp_que *rsp;
6866 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006867
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006868 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6869 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006870
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006871 /* Workaround: qla2xxx driver which access hardware earlier
6872 * needs error state to be pci_channel_io_online.
6873 * Otherwise mailbox command timesout.
6874 */
6875 pdev->error_state = pci_channel_io_normal;
6876
6877 pci_restore_state(pdev);
6878
Richard Lary8c1496b2010-02-18 10:07:29 -08006879 /* pci_restore_state() clears the saved_state flag of the device
6880 * save restored state which resets saved_state flag
6881 */
6882 pci_save_state(pdev);
6883
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006884 if (ha->mem_only)
6885 rc = pci_enable_device_mem(pdev);
6886 else
6887 rc = pci_enable_device(pdev);
6888
6889 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006890 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006891 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006892 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006893 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006894
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006895 rsp = ha->rsp_q_map[0];
6896 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006897 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006899 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006900 goto exit_slot_reset;
6901
6902 if (IS_QLA82XX(ha)) {
6903 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6904 ret = PCI_ERS_RESULT_RECOVERED;
6905 goto exit_slot_reset;
6906 } else
6907 goto exit_slot_reset;
6908 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006909
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006910 while (ha->flags.mbox_busy && retries--)
6911 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006913 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006914 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006915 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006916 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006917
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006918
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006919exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006920 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6921 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006922
Seokmann Ju14e660e2007-09-20 14:07:36 -07006923 return ret;
6924}
6925
6926static void
6927qla2xxx_pci_resume(struct pci_dev *pdev)
6928{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006929 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6930 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006931 int ret;
6932
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006933 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6934 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006935
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006936 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006937 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006938 ql_log(ql_log_fatal, base_vha, 0x9002,
6939 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006940 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006941
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006942 pci_cleanup_aer_uncorrect_error_status(pdev);
6943
Andrew Vasquez85880802009-12-15 21:29:46 -08006944 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006945}
6946
Michael Hernandez56012362016-12-12 14:40:08 -08006947static int qla2xxx_map_queues(struct Scsi_Host *shost)
6948{
Quinn Trand68b8502017-12-04 14:44:59 -08006949 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006950 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6951
Quinn Trand68b8502017-12-04 14:44:59 -08006952 if (USER_CTRL_IRQ(vha->hw))
6953 rc = blk_mq_map_queues(&shost->tag_set);
6954 else
Keith Buschf23f5bec2018-03-27 09:39:06 -06006955 rc = blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev, 0);
Quinn Trand68b8502017-12-04 14:44:59 -08006956 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006957}
6958
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006959static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006960 .error_detected = qla2xxx_pci_error_detected,
6961 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6962 .slot_reset = qla2xxx_pci_slot_reset,
6963 .resume = qla2xxx_pci_resume,
6964};
6965
Andrew Vasquez54333832005-11-09 15:49:04 -08006966static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006967 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6968 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6969 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6970 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6971 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6972 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6973 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6974 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6975 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006976 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006977 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6978 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006979 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006980 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006981 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006982 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006983 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006984 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006985 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006986 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006987 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006988 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006989 { 0 },
6990};
6991MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6992
Andrew Vasquezfca29702005-07-06 10:31:47 -07006993static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006994 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006995 .driver = {
6996 .owner = THIS_MODULE,
6997 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006998 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006999 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08007000 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07007001 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007002 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07007003};
7004
Al Viro75ef9de2013-04-04 19:09:41 -04007005static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007006 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02007007 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007008};
7009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010/**
7011 * qla2x00_module_init - Module initialization.
7012 **/
7013static int __init
7014qla2x00_module_init(void)
7015{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007016 int ret = 0;
7017
Linus Torvalds1da177e2005-04-16 15:20:36 -07007018 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007019 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007020 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007021 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007022 ql_log(ql_log_fatal, NULL, 0x0001,
7023 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 return -ENOMEM;
7025 }
7026
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007027 /* Initialize target kmem_cache and mem_pools */
7028 ret = qlt_init();
7029 if (ret < 0) {
7030 kmem_cache_destroy(srb_cachep);
7031 return ret;
7032 } else if (ret > 0) {
7033 /*
7034 * If initiator mode is explictly disabled by qlt_init(),
7035 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7036 * performing scsi_scan_target() during LOOP UP event.
7037 */
7038 qla2xxx_transport_functions.disable_target_scan = 1;
7039 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7040 }
7041
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 /* Derive version string. */
7043 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007044 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007045 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007046 if (ql2xextended_error_logging == 1)
7047 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007048
Quinn Tran0645cb82018-09-11 10:18:18 -07007049 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7050 qla_insert_tgt_attrs();
7051
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007052 qla2xxx_transport_template =
7053 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007054 if (!qla2xxx_transport_template) {
7055 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007056 ql_log(ql_log_fatal, NULL, 0x0002,
7057 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007058 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007060 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007061
7062 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7063 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007064 ql_log(ql_log_fatal, NULL, 0x0003,
7065 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007066 }
7067
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007068 qla2xxx_transport_vport_template =
7069 fc_attach_transport(&qla2xxx_transport_vport_functions);
7070 if (!qla2xxx_transport_vport_template) {
7071 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007072 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007073 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007074 ql_log(ql_log_fatal, NULL, 0x0004,
7075 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007076 return -ENODEV;
7077 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007078 ql_log(ql_log_info, NULL, 0x0005,
7079 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007080 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007081 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007082 if (ret) {
7083 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007084 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07007085 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007086 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007087 ql_log(ql_log_fatal, NULL, 0x0006,
7088 "pci_register_driver failed...ret=%d Failing load!.\n",
7089 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007090 }
7091 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092}
7093
7094/**
7095 * qla2x00_module_exit - Module cleanup.
7096 **/
7097static void __exit
7098qla2x00_module_exit(void)
7099{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007100 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007101 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007102 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007103 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007104 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07007105 if (ctx_cachep)
7106 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007107 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007108 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007109}
7110
7111module_init(qla2x00_module_init);
7112module_exit(qla2x00_module_exit);
7113
7114MODULE_AUTHOR("QLogic Corporation");
7115MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7116MODULE_LICENSE("GPL");
7117MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007118MODULE_FIRMWARE(FW_FILE_ISP21XX);
7119MODULE_FIRMWARE(FW_FILE_ISP22XX);
7120MODULE_FIRMWARE(FW_FILE_ISP2300);
7121MODULE_FIRMWARE(FW_FILE_ISP2322);
7122MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007123MODULE_FIRMWARE(FW_FILE_ISP25XX);