blob: 15eaa6dded0430aef1cf4da6921929035a90cb28 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <scsi/scsi_tcq.h>
18#include <scsi/scsicam.h>
19#include <scsi/scsi_transport.h>
20#include <scsi/scsi_transport_fc.h>
21
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040022#include "qla_target.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/*
25 * Driver version
26 */
27char qla2x00_version_str[40];
28
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070029static int apidev_major;
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/*
32 * SRB allocation cache
33 */
Michael Hernandezd7459522016-12-12 14:40:07 -080034struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Giridhar Malavalia9083012010-04-12 17:59:55 -070036/*
37 * CT6 CTX allocation cache
38 */
39static struct kmem_cache *ctx_cachep;
Saurav Kashyap3ce88662011-07-14 12:00:12 -070040/*
41 * error level for logging
42 */
43int ql_errlev = ql_log_all;
Giridhar Malavalia9083012010-04-12 17:59:55 -070044
Saurav Kashyapfa492632012-11-21 02:40:29 -050045static int ql2xenableclass2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040046module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
47MODULE_PARM_DESC(ql2xenableclass2,
48 "Specify if Class 2 operations are supported from the very "
49 "beginning. Default is 0 - class 2 not supported.");
50
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080053module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054MODULE_PARM_DESC(ql2xlogintimeout,
55 "Login timeout value in seconds.");
56
Andrew Vasqueza7b61842007-05-07 07:42:59 -070057int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080058module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070060 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 "a PORT-DOWN status.");
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063int ql2xplogiabsentdevice;
64module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
65MODULE_PARM_DESC(ql2xplogiabsentdevice,
66 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070067 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080071module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_PARM_DESC(ql2xloginretrycount,
73 "Specify an alternate value for the NVRAM login retry count.");
74
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070075int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080076module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070077MODULE_PARM_DESC(ql2xallocfwdump,
78 "Option to enable allocation of memory for a firmware dump "
79 "during HBA initialization. Memory allocation requirements "
80 "vary by ISP type. Default is 1 - allocate memory.");
81
Andrew Vasquez11010fe2006-10-06 09:54:59 -070082int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070083module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -040084module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070085MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070086 "Option to enable extended error logging,\n"
87 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
88 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
89 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
90 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
91 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
92 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
93 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
94 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050095 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
96 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070097 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080098 "\t\t0x1e400000 - Preferred value for capturing essential "
99 "debug information (equivalent to old "
100 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -0700101 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700102
Giridhar Malavalia9083012010-04-12 17:59:55 -0700103int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800104module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700105MODULE_PARM_DESC(ql2xshiftctondsd,
106 "Set to control shifting of command type processing "
107 "based on total number of SG elements.");
108
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700109int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400110module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400111module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700112MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100113 "Enables FDMI registrations. "
114 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700115
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700116#define MAX_Q_DEPTH 64
Chad Dupuis50280c02013-10-30 03:38:14 -0400117static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700118module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
119MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400120 "Maximum queue depth to set for each LUN. "
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700121 "Default is 64.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700122
Duane Grigsbye84067d2017-06-21 13:48:43 -0700123#if (IS_ENABLED(CONFIG_NVME_FC))
124int ql2xenabledif;
125#else
Arun Easi9e522cd2012-08-22 14:21:31 -0400126int ql2xenabledif = 2;
Duane Grigsbye84067d2017-06-21 13:48:43 -0700127#endif
Arun Easi9e522cd2012-08-22 14:21:31 -0400128module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700129MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600130 " Enable T10-CRC-DIF:\n"
131 " Default is 2.\n"
132 " 0 -- No DIF Support\n"
133 " 1 -- Enable DIF for all types\n"
134 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700135
Duane Grigsbye84067d2017-06-21 13:48:43 -0700136#if (IS_ENABLED(CONFIG_NVME_FC))
137int ql2xnvmeenable = 1;
138#else
139int ql2xnvmeenable;
140#endif
141module_param(ql2xnvmeenable, int, 0644);
142MODULE_PARM_DESC(ql2xnvmeenable,
143 "Enables NVME support. "
144 "0 - no NVMe. Default is Y");
145
Arun Easi8cb20492011-08-16 11:29:22 -0700146int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700147module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
148MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700149 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600150 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700151 " 0 -- Error isolation disabled\n"
152 " 1 -- Error isolation enabled only for DIX Type 0\n"
153 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700154
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700155int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800156module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700157MODULE_PARM_DESC(ql2xiidmaenable,
158 "Enables iIDMA settings "
159 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
160
Michael Hernandezd7459522016-12-12 14:40:07 -0800161int ql2xmqsupport = 1;
162module_param(ql2xmqsupport, int, S_IRUGO);
163MODULE_PARM_DESC(ql2xmqsupport,
164 "Enable on demand multiple queue pairs support "
165 "Default is 1 for supported. "
166 "Set it to 0 to turn off mq qpair support.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700167
168int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700169module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400170module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700171MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700172 "Option to specify location from which to load ISP firmware:.\n"
173 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700174 " interface.\n"
175 " 1 -- load firmware from flash.\n"
176 " 0 -- use default semantics.\n");
177
Andrew Vasquezae97c912010-02-18 10:07:28 -0800178int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800179module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800180MODULE_PARM_DESC(ql2xetsenable,
181 "Enables firmware ETS burst."
182 "Default is 0 - skip ETS enablement.");
183
Giridhar Malavali69078692010-05-28 15:08:28 -0700184int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700185module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700186MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700187 "Option to specify scheme for request queue posting.\n"
188 " 0 -- Regular doorbell.\n"
189 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700190
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700191int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800192module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700193MODULE_PARM_DESC(ql2xtargetreset,
194 "Enable target reset."
195 "Default is 1 - use hw defaults.");
196
Chad Dupuis4da26e12010-10-15 11:27:40 -0700197int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800198module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700199MODULE_PARM_DESC(ql2xgffidenable,
200 "Enables GFF_ID checks of port type. "
201 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700202
himanshu.madhani@cavium.com043dc1d2017-08-23 15:05:19 -0700203int ql2xasynctmfenable = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800204module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700205MODULE_PARM_DESC(ql2xasynctmfenable,
206 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
207 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700208
209int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700210module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700211MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700212 "Option to specify reset behaviour.\n"
213 " 0 (Default) -- Reset on failure.\n"
214 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700215
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200216uint64_t ql2xmaxlun = MAX_LUNS;
217module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700218MODULE_PARM_DESC(ql2xmaxlun,
219 "Defines the maximum LU number to register with the SCSI "
220 "midlayer. Default is 65535.");
221
Giridhar Malavali08de2842011-08-16 11:31:44 -0700222int ql2xmdcapmask = 0x1F;
223module_param(ql2xmdcapmask, int, S_IRUGO);
224MODULE_PARM_DESC(ql2xmdcapmask,
225 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800226 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700227
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800228int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700229module_param(ql2xmdenable, int, S_IRUGO);
230MODULE_PARM_DESC(ql2xmdenable,
231 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800232 "0 - MiniDump disabled. "
233 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700234
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500235int ql2xexlogins = 0;
236module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
237MODULE_PARM_DESC(ql2xexlogins,
238 "Number of extended Logins. "
239 "0 (Default)- Disabled.");
240
Quinn Tran99e1b682017-06-02 09:12:03 -0700241int ql2xexchoffld = 1024;
242module_param(ql2xexchoffld, uint, 0644);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500243MODULE_PARM_DESC(ql2xexchoffld,
Quinn Tran99e1b682017-06-02 09:12:03 -0700244 "Number of target exchanges.");
245
246int ql2xiniexchg = 1024;
247module_param(ql2xiniexchg, uint, 0644);
248MODULE_PARM_DESC(ql2xiniexchg,
249 "Number of initiator exchanges.");
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500250
Himanshu Madhanif198caf2016-01-27 12:03:30 -0500251int ql2xfwholdabts = 0;
252module_param(ql2xfwholdabts, int, S_IRUGO);
253MODULE_PARM_DESC(ql2xfwholdabts,
254 "Allow FW to hold status IOCB until ABTS rsp received. "
255 "0 (Default) Do not set fw option. "
256 "1 - Set fw option to hold ABTS.");
257
Quinn Tran41dc5292017-01-19 22:28:03 -0800258int ql2xmvasynctoatio = 1;
259module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
260MODULE_PARM_DESC(ql2xmvasynctoatio,
261 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
262 "0 (Default). Do not move IOCBs"
263 "1 - Move IOCBs.");
264
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700265int ql2xautodetectsfp = 1;
266module_param(ql2xautodetectsfp, int, 0444);
267MODULE_PARM_DESC(ql2xautodetectsfp,
268 "Detect SFP range and set appropriate distance.\n"
269 "1 (Default): Enable\n");
270
Himanshu Madhanie7240af2017-10-13 09:34:03 -0700271int ql2xenablemsix = 1;
272module_param(ql2xenablemsix, int, 0444);
273MODULE_PARM_DESC(ql2xenablemsix,
274 "Set to enable MSI or MSI-X interrupt mechanism.\n"
275 " Default is 1, enable MSI-X interrupt mechanism.\n"
276 " 0 -- enable traditional pin-based mechanism.\n"
277 " 1 -- enable MSI-X interrupt mechanism.\n"
278 " 2 -- enable MSI interrupt mechanism.\n");
279
Quinn Tran9ecf0b02017-12-28 12:33:19 -0800280int qla2xuseresexchforels;
281module_param(qla2xuseresexchforels, int, 0444);
282MODULE_PARM_DESC(qla2xuseresexchforels,
283 "Reserve 1/2 of emergency exchanges for ELS.\n"
284 " 0 (default): disabled");
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700287 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 */
289static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500290static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800291static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
292static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500293static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500294static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295static int qla2xxx_eh_abort(struct scsi_cmnd *);
296static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700297static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
299static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400301static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400302static void qla2x00_free_device(scsi_qla_host_t *);
Michael Hernandez56012362016-12-12 14:40:08 -0800303static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700304static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700305
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700306struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700308 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700309 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700310
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100311 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700312 .eh_abort_handler = qla2xxx_eh_abort,
313 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700314 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700315 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
316 .eh_host_reset_handler = qla2xxx_eh_host_reset,
317
318 .slave_configure = qla2xxx_slave_configure,
319
320 .slave_alloc = qla2xxx_slave_alloc,
321 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700322 .scan_finished = qla2xxx_scan_finished,
323 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100324 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800325 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700326 .this_id = -1,
327 .cmd_per_lun = 3,
328 .use_clustering = ENABLE_CLUSTERING,
329 .sg_tablesize = SG_ALL,
330
331 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700332 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400333
334 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100335 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700336};
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700339struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/* TODO Convert to inlines
342 *
343 * Timer routines
344 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700346__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700347qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700349 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800351 add_timer(&vha->timer);
352 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800356qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700358 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700359 if (vha->device_flags & DFLG_DEV_FAILED) {
360 ql_dbg(ql_dbg_timer, vha, 0x600d,
361 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700362 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700363 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800365 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
Adrian Bunka824ebb2008-01-17 09:02:15 -0800368static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800369qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800371 del_timer_sync(&vha->timer);
372 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375static int qla2x00_do_dpc(void *data);
376
377static void qla2x00_rst_aen(scsi_qla_host_t *);
378
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800379static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
380 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700381static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800383int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
384 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700387static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
388 struct rsp_que *rsp)
389{
390 struct qla_hw_data *ha = vha->hw;
391 rsp->qpair = ha->base_qpair;
392 rsp->req = req;
393 ha->base_qpair->req = req;
394 ha->base_qpair->rsp = rsp;
395 ha->base_qpair->vha = vha;
396 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
397 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
398 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
399 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
400 ha->base_qpair->enable_class_2 = ql2xenableclass2;
401 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800402 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700403 ha->base_qpair->pdev = ha->pdev;
404
405 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
406 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
407}
408
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400409static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
410 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800411{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700412 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700413 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800414 GFP_KERNEL);
415 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700416 ql_log(ql_log_fatal, vha, 0x003b,
417 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800418 goto fail_req_map;
419 }
420
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700421 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800422 GFP_KERNEL);
423 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700424 ql_log(ql_log_fatal, vha, 0x003c,
425 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800426 goto fail_rsp_map;
427 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800428
Quinn Trane326d222017-06-13 20:47:18 -0700429 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
430 if (ha->base_qpair == NULL) {
431 ql_log(ql_log_warn, vha, 0x00e0,
432 "Failed to allocate base queue pair memory.\n");
433 goto fail_base_qpair;
434 }
435
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700436 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700437
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700438 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800439 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
440 GFP_KERNEL);
441 if (!ha->queue_pair_map) {
442 ql_log(ql_log_fatal, vha, 0x0180,
443 "Unable to allocate memory for queue pair ptrs.\n");
444 goto fail_qpair_map;
445 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800446 }
447
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400448 /*
449 * Make sure we record at least the request and response queue zero in
450 * case we need to free them if part of the probe fails.
451 */
452 ha->rsp_q_map[0] = rsp;
453 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800454 set_bit(0, ha->rsp_qid_map);
455 set_bit(0, ha->req_qid_map);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -0500456 return 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800457
Michael Hernandezd7459522016-12-12 14:40:07 -0800458fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700459 kfree(ha->base_qpair);
460 ha->base_qpair = NULL;
461fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800462 kfree(ha->rsp_q_map);
463 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800464fail_rsp_map:
465 kfree(ha->req_q_map);
466 ha->req_q_map = NULL;
467fail_req_map:
468 return -ENOMEM;
469}
470
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700471static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800472{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400473 if (IS_QLAFX00(ha)) {
474 if (req && req->ring_fx00)
475 dma_free_coherent(&ha->pdev->dev,
476 (req->length_fx00 + 1) * sizeof(request_t),
477 req->ring_fx00, req->dma_fx00);
478 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800479 dma_free_coherent(&ha->pdev->dev,
480 (req->length + 1) * sizeof(request_t),
481 req->ring, req->dma);
482
Bill Kuzeja6d634062018-03-23 10:37:25 -0400483 if (req)
Chad Dupuis8d93f552013-01-30 03:34:37 -0500484 kfree(req->outstanding_cmds);
Bill Kuzeja6d634062018-03-23 10:37:25 -0400485
486 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800487}
488
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700489static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
490{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400491 if (IS_QLAFX00(ha)) {
Meelis Roos3f6c9be2018-03-08 15:44:37 +0200492 if (rsp && rsp->ring_fx00)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400493 dma_free_coherent(&ha->pdev->dev,
494 (rsp->length_fx00 + 1) * sizeof(request_t),
495 rsp->ring_fx00, rsp->dma_fx00);
496 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700497 dma_free_coherent(&ha->pdev->dev,
498 (rsp->length + 1) * sizeof(response_t),
499 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400500 }
Bill Kuzeja6d634062018-03-23 10:37:25 -0400501 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700502}
503
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800504static void qla2x00_free_queues(struct qla_hw_data *ha)
505{
506 struct req_que *req;
507 struct rsp_que *rsp;
508 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800509 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800510
Quinn Tran82de8022017-06-13 20:47:17 -0700511 if (ha->queue_pair_map) {
512 kfree(ha->queue_pair_map);
513 ha->queue_pair_map = NULL;
514 }
515 if (ha->base_qpair) {
516 kfree(ha->base_qpair);
517 ha->base_qpair = NULL;
518 }
519
Quinn Tran093df732016-12-12 14:40:09 -0800520 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700521 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500522 if (!test_bit(cnt, ha->req_qid_map))
523 continue;
524
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800525 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800526 clear_bit(cnt, ha->req_qid_map);
527 ha->req_q_map[cnt] = NULL;
528
529 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700530 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800531 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700532 }
Quinn Tran093df732016-12-12 14:40:09 -0800533 spin_unlock_irqrestore(&ha->hardware_lock, flags);
534
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700535 kfree(ha->req_q_map);
536 ha->req_q_map = NULL;
537
Quinn Tran093df732016-12-12 14:40:09 -0800538
539 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700540 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500541 if (!test_bit(cnt, ha->rsp_qid_map))
542 continue;
543
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700544 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500545 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800546 ha->rsp_q_map[cnt] = NULL;
547 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700548 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800549 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800550 }
Quinn Tran093df732016-12-12 14:40:09 -0800551 spin_unlock_irqrestore(&ha->hardware_lock, flags);
552
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800553 kfree(ha->rsp_q_map);
554 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800555}
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800560 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 static char *pci_bus_modes[] = {
562 "33", "66", "100", "133",
563 };
564 uint16_t pci_bus;
565
566 strcpy(str, "PCI");
567 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
568 if (pci_bus) {
569 strcat(str, "-X (");
570 strcat(str, pci_bus_modes[pci_bus]);
571 } else {
572 pci_bus = (ha->pci_attr & BIT_8) >> 8;
573 strcat(str, " (");
574 strcat(str, pci_bus_modes[pci_bus]);
575 }
576 strcat(str, " MHz)");
577
578 return (str);
579}
580
Andrew Vasquezfca29702005-07-06 10:31:47 -0700581static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700583{
584 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700586 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700587
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600588 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700589 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600590 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600592 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
593 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
594 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700595
596 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500597 switch (lspeed) {
598 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700599 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500600 break;
601 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700602 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500603 break;
604 case 3:
605 strcat(str, "8.0GT/s ");
606 break;
607 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700608 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500609 break;
610 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
612 strcat(str, lwstr);
613
614 return str;
615 }
616
617 strcpy(str, "PCI");
618 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
619 if (pci_bus == 0 || pci_bus == 8) {
620 strcat(str, " (");
621 strcat(str, pci_bus_modes[pci_bus >> 3]);
622 } else {
623 strcat(str, "-X ");
624 if (pci_bus & BIT_2)
625 strcat(str, "Mode 2");
626 else
627 strcat(str, "Mode 1");
628 strcat(str, " (");
629 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
630 }
631 strcat(str, " MHz)");
632
633 return str;
634}
635
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800636static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400637qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
639 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800640 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700641
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400642 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
643 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 if (ha->fw_attributes & BIT_9) {
646 strcat(str, "FLX");
647 return (str);
648 }
649
650 switch (ha->fw_attributes & 0xFF) {
651 case 0x7:
652 strcat(str, "EF");
653 break;
654 case 0x17:
655 strcat(str, "TP");
656 break;
657 case 0x37:
658 strcat(str, "IP");
659 break;
660 case 0x77:
661 strcat(str, "VI");
662 break;
663 default:
664 sprintf(un_str, "(%x)", ha->fw_attributes);
665 strcat(str, un_str);
666 break;
667 }
668 if (ha->fw_attributes & 0x100)
669 strcat(str, "X");
670
671 return (str);
672}
673
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800674static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400675qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700676{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800677 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700678
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400679 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800680 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700681 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700682}
683
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800684void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800685qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700686{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800687 srb_t *sp = ptr;
688 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800689 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800690 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700691
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800692 if (sp->flags & SRB_DMA_VALID) {
693 scsi_dma_unmap(cmd);
694 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700695 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700696
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800697 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
698 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
699 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
700 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
701 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700702
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700703 if (!ctx)
704 goto end;
705
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800706 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
707 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700708 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800709 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
710 }
711
712 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700713 struct crc_context *ctx0 = ctx;
714
715 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800716 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
717 }
718
719 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700720 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800721
722 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700723 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800724 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
725 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
726 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
727 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800728 }
729
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700730end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700731 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700732 CMD_SP(cmd) = NULL;
733 qla2x00_rel_sp(sp);
734 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800735}
736
Michael Hernandezd7459522016-12-12 14:40:07 -0800737void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800738qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800739{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800740 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800741 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
742
743 cmd->result = res;
744
745 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800746 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800747 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
748 sp, GET_CMD_SP(sp));
749 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400750 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800751 return;
752 }
753 if (!atomic_dec_and_test(&sp->ref_count))
754 return;
755
Joe Carnucciof3caa992017-08-23 15:05:09 -0700756 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800757 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700758}
759
Michael Hernandezd7459522016-12-12 14:40:07 -0800760void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800761qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800762{
763 srb_t *sp = (srb_t *)ptr;
764 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
765 struct qla_hw_data *ha = sp->fcport->vha->hw;
766 void *ctx = GET_CMD_CTX_SP(sp);
767
768 if (sp->flags & SRB_DMA_VALID) {
769 scsi_dma_unmap(cmd);
770 sp->flags &= ~SRB_DMA_VALID;
771 }
772
773 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
774 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
775 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
776 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
777 }
778
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700779 if (!ctx)
780 goto end;
781
Michael Hernandezd7459522016-12-12 14:40:07 -0800782 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
783 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700784 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800785 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
786 }
787
788 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700789 struct crc_context *ctx0 = ctx;
790
791 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800792 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
793 }
794
795 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700796 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800797 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
798 ctx1->fcp_cmnd_dma);
799 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
800 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
801 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
802 mempool_free(ctx1, ha->ctx_mempool);
803 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700804end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800805 CMD_SP(cmd) = NULL;
806 qla2xxx_rel_qpair_sp(sp->qpair, sp);
807}
808
809void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800810qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800811{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800812 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800813 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
814
815 cmd->result = res;
816
817 if (atomic_read(&sp->ref_count) == 0) {
818 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
819 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
820 sp, GET_CMD_SP(sp));
821 if (ql2xextended_error_logging & ql_dbg_io)
822 WARN_ON(atomic_read(&sp->ref_count) == 0);
823 return;
824 }
825 if (!atomic_dec_and_test(&sp->ref_count))
826 return;
827
Joe Carnucciof3caa992017-08-23 15:05:09 -0700828 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800829 cmd->scsi_done(cmd);
830}
831
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400832/* If we are SP1 here, we need to still take and release the host_lock as SP1
833 * does not have the changes necessary to avoid taking host->host_lock.
834 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800836qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700837{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700838 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700839 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400840 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800841 struct qla_hw_data *ha = vha->hw;
842 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700843 srb_t *sp;
844 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800845 struct qla_qpair *qpair = NULL;
846 uint32_t tag;
847 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700848
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200849 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
850 cmd->result = DID_NO_CONNECT << 16;
851 goto qc24_fail_command;
852 }
853
Michael Hernandez56012362016-12-12 14:40:08 -0800854 if (ha->mqenable) {
855 if (shost_use_blk_mq(vha->host)) {
856 tag = blk_mq_unique_tag(cmd->request);
857 hwq = blk_mq_unique_tag_to_hwq(tag);
858 qpair = ha->queue_pair_map[hwq];
859 } else if (vha->vp_idx && vha->qpair) {
860 qpair = vha->qpair;
861 }
862
863 if (qpair)
864 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800865 }
866
Andrew Vasquez85880802009-12-15 21:29:46 -0800867 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700868 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400869 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700870 "PCI Channel IO permanent failure, exiting "
871 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700872 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700873 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400874 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700875 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800876 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700877 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700878 goto qc24_fail_command;
879 }
880
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400881 rval = fc_remote_port_chkready(rport);
882 if (rval) {
883 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400884 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700885 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
886 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700887 goto qc24_fail_command;
888 }
889
Arun Easibad75002010-05-04 15:01:30 -0700890 if (!vha->flags.difdix_supported &&
891 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700892 ql_dbg(ql_dbg_io, vha, 0x3004,
893 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
894 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700895 cmd->result = DID_NO_CONNECT << 16;
896 goto qc24_fail_command;
897 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800898
899 if (!fcport) {
900 cmd->result = DID_NO_CONNECT << 16;
901 goto qc24_fail_command;
902 }
903
Andrew Vasquezfca29702005-07-06 10:31:47 -0700904 if (atomic_read(&fcport->state) != FCS_ONLINE) {
905 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700906 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700907 ql_dbg(ql_dbg_io, vha, 0x3005,
908 "Returning DNC, fcport_state=%d loop_state=%d.\n",
909 atomic_read(&fcport->state),
910 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700911 cmd->result = DID_NO_CONNECT << 16;
912 goto qc24_fail_command;
913 }
Mike Christie7b594132008-08-17 15:24:40 -0500914 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700915 }
916
Chad Dupuise05fe292014-09-25 05:16:59 -0400917 /*
918 * Return target busy if we've received a non-zero retry_delay_timer
919 * in a FCP_RSP.
920 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100921 if (fcport->retry_delay_timestamp == 0) {
922 /* retry delay not set */
923 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400924 fcport->retry_delay_timestamp = 0;
925 else
926 goto qc24_target_busy;
927
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500928 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400929 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800930 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700931
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800932 sp->u.scmd.cmd = cmd;
933 sp->type = SRB_SCSI_CMD;
934 atomic_set(&sp->ref_count, 1);
935 CMD_SP(cmd) = (void *)sp;
936 sp->free = qla2x00_sp_free_dma;
937 sp->done = qla2x00_sp_compl;
938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500941 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700942 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700943 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700944 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700945
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946 return 0;
947
948qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700949 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700950
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800951qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700952 return SCSI_MLQUEUE_HOST_BUSY;
953
Mike Christie7b594132008-08-17 15:24:40 -0500954qc24_target_busy:
955 return SCSI_MLQUEUE_TARGET_BUSY;
956
Andrew Vasquezfca29702005-07-06 10:31:47 -0700957qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800958 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700959
960 return 0;
961}
962
Michael Hernandezd7459522016-12-12 14:40:07 -0800963/* For MQ supported I/O */
964int
965qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
966 struct qla_qpair *qpair)
967{
968 scsi_qla_host_t *vha = shost_priv(host);
969 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
970 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
971 struct qla_hw_data *ha = vha->hw;
972 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
973 srb_t *sp;
974 int rval;
975
976 rval = fc_remote_port_chkready(rport);
977 if (rval) {
978 cmd->result = rval;
979 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
980 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
981 cmd, rval);
982 goto qc24_fail_command;
983 }
984
985 if (!fcport) {
986 cmd->result = DID_NO_CONNECT << 16;
987 goto qc24_fail_command;
988 }
989
990 if (atomic_read(&fcport->state) != FCS_ONLINE) {
991 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
992 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
993 ql_dbg(ql_dbg_io, vha, 0x3077,
994 "Returning DNC, fcport_state=%d loop_state=%d.\n",
995 atomic_read(&fcport->state),
996 atomic_read(&base_vha->loop_state));
997 cmd->result = DID_NO_CONNECT << 16;
998 goto qc24_fail_command;
999 }
1000 goto qc24_target_busy;
1001 }
1002
1003 /*
1004 * Return target busy if we've received a non-zero retry_delay_timer
1005 * in a FCP_RSP.
1006 */
1007 if (fcport->retry_delay_timestamp == 0) {
1008 /* retry delay not set */
1009 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1010 fcport->retry_delay_timestamp = 0;
1011 else
1012 goto qc24_target_busy;
1013
1014 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
1015 if (!sp)
1016 goto qc24_host_busy;
1017
1018 sp->u.scmd.cmd = cmd;
1019 sp->type = SRB_SCSI_CMD;
1020 atomic_set(&sp->ref_count, 1);
1021 CMD_SP(cmd) = (void *)sp;
1022 sp->free = qla2xxx_qpair_sp_free_dma;
1023 sp->done = qla2xxx_qpair_sp_compl;
1024 sp->qpair = qpair;
1025
1026 rval = ha->isp_ops->start_scsi_mq(sp);
1027 if (rval != QLA_SUCCESS) {
1028 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1029 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1030 if (rval == QLA_INTERFACE_ERROR)
1031 goto qc24_fail_command;
1032 goto qc24_host_busy_free_sp;
1033 }
1034
1035 return 0;
1036
1037qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001038 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001039
1040qc24_host_busy:
1041 return SCSI_MLQUEUE_HOST_BUSY;
1042
1043qc24_target_busy:
1044 return SCSI_MLQUEUE_TARGET_BUSY;
1045
1046qc24_fail_command:
1047 cmd->scsi_done(cmd);
1048
1049 return 0;
1050}
1051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052/*
1053 * qla2x00_eh_wait_on_command
1054 * Waits for the command to be returned by the Firmware for some
1055 * max time.
1056 *
1057 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 *
1060 * Return:
1061 * Not Found : 0
1062 * Found : 1
1063 */
1064static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001067#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001068#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001069 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001070 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1071 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001072 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Andrew Vasquez85880802009-12-15 21:29:46 -08001074 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001075 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1076 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001077 return ret;
1078 }
1079
Lalit Chandivaded9704322009-08-25 11:36:18 -07001080 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001081 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001082 }
1083 if (CMD_SP(cmd))
1084 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
f4f051e2005-04-17 15:02:26 -05001086 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
1089/*
1090 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001091 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 * <= MAX_RETRIES_OF_ISP_ABORT or
1093 * finally HBA is disabled ie marked offline
1094 *
1095 * Input:
1096 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001097 *
1098 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 * Does context switching-Release SPIN_LOCK
1100 * (if any) before calling this routine.
1101 *
1102 * Return:
1103 * Success (Adapter is online) : 0
1104 * Failed (Adapter is offline/disabled) : 1
1105 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001106int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001109 int return_status;
1110 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001111 struct qla_hw_data *ha = vha->hw;
1112 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001114 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1116 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1117 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1118 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120 msleep(1000);
1121 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001123 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 else
1125 return_status = QLA_FUNCTION_FAILED;
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return (return_status);
1128}
1129
Quinn Tran726b8542017-01-19 22:28:00 -08001130static inline int test_fcport_count(scsi_qla_host_t *vha)
1131{
1132 struct qla_hw_data *ha = vha->hw;
1133 unsigned long flags;
1134 int res;
1135
1136 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001137 ql_dbg(ql_dbg_init, vha, 0x00ec,
1138 "tgt %p, fcport_count=%d\n",
1139 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001140 res = (vha->fcport_count == 0);
1141 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1142
1143 return res;
1144}
1145
1146/*
1147 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1148 * it has dependency on UNLOADING flag to stop device discovery
1149 */
1150static void
1151qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1152{
1153 qla2x00_mark_all_devices_lost(vha, 0);
1154
Joe Carnucciob85e0952017-08-23 15:05:11 -07001155 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001156}
1157
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001158/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001159 * qla2x00_wait_for_hba_ready
1160 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001161 *
1162 * Input:
1163 * ha - pointer to host adapter structure
1164 *
1165 * Note:
1166 * Does context switching-Release SPIN_LOCK
1167 * (if any) before calling this routine.
1168 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001169 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001170static void
1171qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001172{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001173 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001174 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001175
Dan Carpenter1d483902016-08-03 21:42:32 +03001176 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1177 ha->flags.mbox_busy) ||
1178 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1179 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1180 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1181 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001182 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001183 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001184}
1185
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001186int
1187qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1188{
1189 int return_status;
1190 unsigned long wait_reset;
1191 struct qla_hw_data *ha = vha->hw;
1192 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1193
1194 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1195 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1196 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1197 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1198 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1199
1200 msleep(1000);
1201
1202 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1203 ha->flags.chip_reset_done)
1204 break;
1205 }
1206 if (ha->flags.chip_reset_done)
1207 return_status = QLA_SUCCESS;
1208 else
1209 return_status = QLA_FUNCTION_FAILED;
1210
1211 return return_status;
1212}
1213
Giridhar Malavali083a4692010-05-28 15:08:18 -07001214static void
1215sp_get(struct srb *sp)
1216{
1217 atomic_inc(&sp->ref_count);
1218}
1219
Sawan Chandaka4655372016-07-06 11:14:32 -04001220#define ISP_REG_DISCONNECT 0xffffffffU
1221/**************************************************************************
1222* qla2x00_isp_reg_stat
1223*
1224* Description:
1225* Read the host status register of ISP before aborting the command.
1226*
1227* Input:
1228* ha = pointer to host adapter structure.
1229*
1230*
1231* Returns:
1232* Either true or false.
1233*
1234* Note: Return true if there is register disconnect.
1235**************************************************************************/
1236static inline
1237uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1238{
1239 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001240 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001241
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001242 if (IS_P3P_TYPE(ha))
1243 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1244 else
1245 return ((RD_REG_DWORD(&reg->host_status)) ==
1246 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001247}
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249/**************************************************************************
1250* qla2xxx_eh_abort
1251*
1252* Description:
1253* The abort function will abort the specified command.
1254*
1255* Input:
1256* cmd = Linux SCSI command packet to be aborted.
1257*
1258* Returns:
1259* Either SUCCESS or FAILED.
1260*
1261* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001262* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001264static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1266{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001267 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001268 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001269 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001270 unsigned int id;
1271 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001272 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001273 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001274 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Sawan Chandaka4655372016-07-06 11:14:32 -04001276 if (qla2x00_isp_reg_stat(ha)) {
1277 ql_log(ql_log_info, vha, 0x8042,
1278 "PCI/Register disconnect, exiting.\n");
1279 return FAILED;
1280 }
f4f051e2005-04-17 15:02:26 -05001281 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001282 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001284 ret = fc_block_scsi_eh(cmd);
1285 if (ret != 0)
1286 return ret;
1287 ret = SUCCESS;
1288
f4f051e2005-04-17 15:02:26 -05001289 id = cmd->device->id;
1290 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001291
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001292 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001293 sp = (srb_t *) CMD_SP(cmd);
1294 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001296 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001297 }
Mike Christie170babc2010-10-15 11:27:47 -07001298
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001299 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001300 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1301 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001302
1303 /* Get a reference to the sp and drop the lock.*/
1304 sp_get(sp);
1305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001307 rval = ha->isp_ops->abort_command(sp);
1308 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001309 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001310 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001311 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001312 ret = FAILED;
1313
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001314 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001315 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001316 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001317 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001318 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001319 wait = 1;
1320 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001321
1322 spin_lock_irqsave(&ha->hardware_lock, flags);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001323 sp->done(sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001324 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001325
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001326 /* Did the command return during mailbox execution? */
1327 if (ret == FAILED && !CMD_SP(cmd))
1328 ret = SUCCESS;
1329
f4f051e2005-04-17 15:02:26 -05001330 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001331 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001332 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001333 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001334 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001335 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001339 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001340 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001341 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
f4f051e2005-04-17 15:02:26 -05001343 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001346int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001347qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001348 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001350 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001351 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001353 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001354 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001355 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Andrew Vasquez523ec772008-04-03 13:13:24 -07001357 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001358
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001360 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001361 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001362 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001363 sp = req->outstanding_cmds[cnt];
1364 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001365 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001367 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001368 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001369 continue;
1370 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001371 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001372 switch (type) {
1373 case WAIT_HOST:
1374 match = 1;
1375 break;
1376 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001377 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001378 break;
1379 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001380 match = (cmd->device->id == t &&
1381 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001382 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001384 if (!match)
1385 continue;
1386
1387 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001388 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001389 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001391 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001392
1393 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
Andrew Vasquez523ec772008-04-03 13:13:24 -07001396static char *reset_errors[] = {
1397 "HBA not online",
1398 "HBA not ready",
1399 "Task management failed",
1400 "Waiting for command completions",
1401};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Andrew Vasquez523ec772008-04-03 13:13:24 -07001403static int
1404__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001405 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001406{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001407 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001408 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1409 int err;
1410
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001412 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001413 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001414
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001415 err = fc_block_scsi_eh(cmd);
1416 if (err != 0)
1417 return err;
1418
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001419 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001420 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001421 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001422
1423 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001424 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1425 ql_log(ql_log_warn, vha, 0x800a,
1426 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001427 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001428 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001429 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001430 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 != QLA_SUCCESS) {
1432 ql_log(ql_log_warn, vha, 0x800c,
1433 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001434 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001435 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001436 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001438 cmd->device->lun, type) != QLA_SUCCESS) {
1439 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001440 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001441 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001442 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001443
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001444 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001445 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001446 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001447
1448 return SUCCESS;
1449
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001450eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001451 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001452 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001453 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1454 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001455 return FAILED;
1456}
1457
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001458static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1460{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001461 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1462 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Sawan Chandaka4655372016-07-06 11:14:32 -04001464 if (qla2x00_isp_reg_stat(ha)) {
1465 ql_log(ql_log_info, vha, 0x803e,
1466 "PCI/Register disconnect, exiting.\n");
1467 return FAILED;
1468 }
1469
Andrew Vasquez523ec772008-04-03 13:13:24 -07001470 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1471 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001475qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001477 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1478 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Sawan Chandaka4655372016-07-06 11:14:32 -04001480 if (qla2x00_isp_reg_stat(ha)) {
1481 ql_log(ql_log_info, vha, 0x803f,
1482 "PCI/Register disconnect, exiting.\n");
1483 return FAILED;
1484 }
1485
Andrew Vasquez523ec772008-04-03 13:13:24 -07001486 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1487 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490/**************************************************************************
1491* qla2xxx_eh_bus_reset
1492*
1493* Description:
1494* The bus reset function will reset the bus and abort any executing
1495* commands.
1496*
1497* Input:
1498* cmd = Linux SCSI command packet of the command that cause the
1499* bus reset.
1500*
1501* Returns:
1502* SUCCESS/FAILURE (defined as macro in scsi.h).
1503*
1504**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001505static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1507{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001508 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001509 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001510 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001511 unsigned int id;
1512 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001513 struct qla_hw_data *ha = vha->hw;
1514
1515 if (qla2x00_isp_reg_stat(ha)) {
1516 ql_log(ql_log_info, vha, 0x8040,
1517 "PCI/Register disconnect, exiting.\n");
1518 return FAILED;
1519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
f4f051e2005-04-17 15:02:26 -05001521 id = cmd->device->id;
1522 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001523
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001524 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001525 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001528 ret = fc_block_scsi_eh(cmd);
1529 if (ret != 0)
1530 return ret;
1531 ret = FAILED;
1532
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001533 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001534 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001537 ql_log(ql_log_fatal, vha, 0x8013,
1538 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001539 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
1541
Saurav Kashyapad5376892011-11-18 09:02:09 -08001542 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1543 ret = SUCCESS;
1544
f4f051e2005-04-17 15:02:26 -05001545 if (ret == FAILED)
1546 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001548 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001549 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001550 QLA_SUCCESS) {
1551 ql_log(ql_log_warn, vha, 0x8014,
1552 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001553 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
f4f051e2005-04-17 15:02:26 -05001556eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001558 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001559 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
f4f051e2005-04-17 15:02:26 -05001561 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
1564/**************************************************************************
1565* qla2xxx_eh_host_reset
1566*
1567* Description:
1568* The reset function will reset the Adapter.
1569*
1570* Input:
1571* cmd = Linux SCSI command packet of the command that cause the
1572* adapter reset.
1573*
1574* Returns:
1575* Either SUCCESS or FAILED.
1576*
1577* Note:
1578**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001579static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1581{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001582 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001584 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001585 unsigned int id;
1586 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001587 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Sawan Chandaka4655372016-07-06 11:14:32 -04001589 if (qla2x00_isp_reg_stat(ha)) {
1590 ql_log(ql_log_info, vha, 0x8041,
1591 "PCI/Register disconnect, exiting.\n");
1592 schedule_work(&ha->board_disable);
1593 return SUCCESS;
1594 }
1595
f4f051e2005-04-17 15:02:26 -05001596 id = cmd->device->id;
1597 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001598
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001599 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001600 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Chad Dupuis63ee7072014-04-11 16:54:46 -04001602 /*
1603 * No point in issuing another reset if one is active. Also do not
1604 * attempt a reset if we are updating flash.
1605 */
1606 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001607 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001609 if (vha != base_vha) {
1610 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001611 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001613 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001614 if (!qla82xx_fcoe_ctx_reset(vha)) {
1615 /* Ctx reset success */
1616 ret = SUCCESS;
1617 goto eh_host_reset_lock;
1618 }
1619 /* fall thru if ctx reset failed */
1620 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001621 if (ha->wq)
1622 flush_workqueue(ha->wq);
1623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001624 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001625 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001626 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1627 /* failed. schedule dpc to try */
1628 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1629
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001630 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1631 ql_log(ql_log_warn, vha, 0x802a,
1632 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001633 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001634 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001635 }
1636 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001639 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001640 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001642 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
f4f051e2005-04-17 15:02:26 -05001644eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001645 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001646 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001647 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
f4f051e2005-04-17 15:02:26 -05001649 return ret;
1650}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652/*
1653* qla2x00_loop_reset
1654* Issue loop reset.
1655*
1656* Input:
1657* ha = adapter block pointer.
1658*
1659* Returns:
1660* 0 = success
1661*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001662int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001665 int ret;
bdf79622005-04-17 15:06:53 -05001666 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Armen Baloyan58547712013-08-27 01:37:33 -04001669 if (IS_QLAFX00(ha)) {
1670 return qlafx00_loop_reset(vha);
1671 }
1672
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001673 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001674 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1675 if (fcport->port_type != FCT_TARGET)
1676 continue;
1677
1678 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1679 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001680 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001681 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001682 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001683 }
1684 }
1685 }
1686
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001687
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001688 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001689 atomic_set(&vha->loop_state, LOOP_DOWN);
1690 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1691 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001692 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001693 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001694 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1695 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 }
1698
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001699 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001701 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001702 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1703 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001704 }
1705
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001707 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001709 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Quinn Tranbbead492017-12-28 12:33:13 -08001712static void
1713__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001714{
Quinn Tranbbead492017-12-28 12:33:13 -08001715 int cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001716 unsigned long flags;
1717 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001718 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001719 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001720 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001721 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1722 struct qla_tgt_cmd *cmd;
1723 uint8_t trace = 0;
Arun Easic0cb4492014-09-25 06:14:51 -04001724
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001725 if (!ha->req_q_map)
1726 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001727 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1728 req = qp->req;
1729 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1730 sp = req->outstanding_cmds[cnt];
1731 if (sp) {
1732 req->outstanding_cmds[cnt] = NULL;
1733 if (sp->cmd_type == TYPE_SRB) {
1734 if (sp->type == SRB_NVME_CMD ||
1735 sp->type == SRB_NVME_LS) {
1736 sp_get(sp);
1737 spin_unlock_irqrestore(qp->qp_lock_ptr,
1738 flags);
Darren Trapp623ee8242018-03-20 23:09:38 -07001739 qla_nvme_abort(ha, sp, res);
Quinn Tranbbead492017-12-28 12:33:13 -08001740 spin_lock_irqsave(qp->qp_lock_ptr,
1741 flags);
1742 } else if (GET_CMD_SP(sp) &&
1743 !ha->flags.eeh_busy &&
1744 (!test_bit(ABORT_ISP_ACTIVE,
1745 &vha->dpc_flags)) &&
1746 (sp->type == SRB_SCSI_CMD)) {
1747 /*
1748 * Don't abort commands in
1749 * adapter during EEH
1750 * recovery as it's not
1751 * accessible/responding.
1752 *
1753 * Get a reference to the sp
1754 * and drop the lock. The
1755 * reference ensures this
1756 * sp->done() call and not the
1757 * call in qla2xxx_eh_abort()
1758 * ends the SCSI command (with
1759 * result 'res').
1760 */
1761 sp_get(sp);
1762 spin_unlock_irqrestore(qp->qp_lock_ptr,
1763 flags);
1764 status = qla2xxx_eh_abort(
1765 GET_CMD_SP(sp));
1766 spin_lock_irqsave(qp->qp_lock_ptr,
1767 flags);
1768 /*
1769 * Get rid of extra reference
1770 * if immediate exit from
1771 * ql2xxx_eh_abort
1772 */
1773 if (status == FAILED &&
1774 (qla2x00_isp_reg_stat(ha)))
1775 atomic_dec(
1776 &sp->ref_count);
Quinn Tranc5419e22017-06-13 20:47:16 -07001777 }
Quinn Tranbbead492017-12-28 12:33:13 -08001778 sp->done(sp, res);
1779 } else {
1780 if (!vha->hw->tgt.tgt_ops || !tgt ||
1781 qla_ini_mode_enabled(vha)) {
1782 if (!trace)
1783 ql_dbg(ql_dbg_tgt_mgt,
1784 vha, 0xf003,
1785 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1786 vha->dpc_flags);
1787 continue;
1788 }
1789 cmd = (struct qla_tgt_cmd *)sp;
1790 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001791 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001792 }
1793 }
Quinn Tranbbead492017-12-28 12:33:13 -08001794 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1795}
1796
1797void
1798qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1799{
1800 int que;
1801 struct qla_hw_data *ha = vha->hw;
1802
1803 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1804
1805 for (que = 0; que < ha->max_qpairs; que++) {
1806 if (!ha->queue_pair_map[que])
1807 continue;
1808
1809 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1810 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001811}
1812
f4f051e2005-04-17 15:02:26 -05001813static int
1814qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
bdf79622005-04-17 15:06:53 -05001816 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001818 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001819 return -ENXIO;
1820
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001821 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001822
1823 return 0;
1824}
1825
1826static int
1827qla2xxx_slave_configure(struct scsi_device *sdev)
1828{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001829 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001830 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001831
Arun Easi9e522cd2012-08-22 14:21:31 -04001832 if (IS_T10_PI_CAPABLE(vha->hw))
1833 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1834
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001835 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001836 return 0;
1837}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
f4f051e2005-04-17 15:02:26 -05001839static void
1840qla2xxx_slave_destroy(struct scsi_device *sdev)
1841{
1842 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843}
1844
1845/**
1846 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1847 * @ha: HA context
1848 *
1849 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1850 * supported addressing method.
1851 */
1852static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001853qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001855 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
Yang Hongyang6a355282009-04-06 19:01:13 -07001858 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001859 /* Any upper-dword bits set? */
1860 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001861 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001862 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001864 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1865 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001866 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001869
Yang Hongyang284901a2009-04-06 19:01:15 -07001870 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1871 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872}
1873
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001874static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001875qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001876{
1877 unsigned long flags = 0;
1878 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1879
1880 spin_lock_irqsave(&ha->hardware_lock, flags);
1881 ha->interrupts_on = 1;
1882 /* enable risc and host interrupts */
1883 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1884 RD_REG_WORD(&reg->ictrl);
1885 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1886
1887}
1888
1889static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001890qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001891{
1892 unsigned long flags = 0;
1893 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1894
1895 spin_lock_irqsave(&ha->hardware_lock, flags);
1896 ha->interrupts_on = 0;
1897 /* disable risc and host interrupts */
1898 WRT_REG_WORD(&reg->ictrl, 0);
1899 RD_REG_WORD(&reg->ictrl);
1900 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1901}
1902
1903static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001905{
1906 unsigned long flags = 0;
1907 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1908
1909 spin_lock_irqsave(&ha->hardware_lock, flags);
1910 ha->interrupts_on = 1;
1911 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1912 RD_REG_DWORD(&reg->ictrl);
1913 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1914}
1915
1916static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001918{
1919 unsigned long flags = 0;
1920 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1921
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001922 if (IS_NOPOLLING_TYPE(ha))
1923 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001924 spin_lock_irqsave(&ha->hardware_lock, flags);
1925 ha->interrupts_on = 0;
1926 WRT_REG_DWORD(&reg->ictrl, 0);
1927 RD_REG_DWORD(&reg->ictrl);
1928 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1929}
1930
Giridhar Malavali706f4572011-11-18 09:03:16 -08001931static int
1932qla2x00_iospace_config(struct qla_hw_data *ha)
1933{
1934 resource_size_t pio;
1935 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001936
Giridhar Malavali706f4572011-11-18 09:03:16 -08001937 if (pci_request_selected_regions(ha->pdev, ha->bars,
1938 QLA2XXX_DRIVER_NAME)) {
1939 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1940 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1941 pci_name(ha->pdev));
1942 goto iospace_error_exit;
1943 }
1944 if (!(ha->bars & 1))
1945 goto skip_pio;
1946
1947 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1948 pio = pci_resource_start(ha->pdev, 0);
1949 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1950 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1951 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1952 "Invalid pci I/O region size (%s).\n",
1953 pci_name(ha->pdev));
1954 pio = 0;
1955 }
1956 } else {
1957 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1958 "Region #0 no a PIO resource (%s).\n",
1959 pci_name(ha->pdev));
1960 pio = 0;
1961 }
1962 ha->pio_address = pio;
1963 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1964 "PIO address=%llu.\n",
1965 (unsigned long long)ha->pio_address);
1966
1967skip_pio:
1968 /* Use MMIO operations for all accesses. */
1969 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1970 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1971 "Region #1 not an MMIO resource (%s), aborting.\n",
1972 pci_name(ha->pdev));
1973 goto iospace_error_exit;
1974 }
1975 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1976 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1977 "Invalid PCI mem region size (%s), aborting.\n",
1978 pci_name(ha->pdev));
1979 goto iospace_error_exit;
1980 }
1981
1982 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1983 if (!ha->iobase) {
1984 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1985 "Cannot remap MMIO (%s), aborting.\n",
1986 pci_name(ha->pdev));
1987 goto iospace_error_exit;
1988 }
1989
1990 /* Determine queue resources */
1991 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001992 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07001993 if (!ql2xmqsupport || !ql2xnvmeenable ||
1994 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08001995 goto mqiobase_exit;
1996
1997 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1998 pci_resource_len(ha->pdev, 3));
1999 if (ha->mqiobase) {
2000 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2001 "MQIO Base=%p.\n", ha->mqiobase);
2002 /* Read MSIX vector size of the board */
2003 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002004 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002005 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002006 /* MB interrupt uses 1 vector */
2007 ha->max_req_queues = ha->msix_count - 1;
2008 ha->max_rsp_queues = ha->max_req_queues;
2009 /* Queue pairs is the max value minus the base queue pair */
2010 ha->max_qpairs = ha->max_rsp_queues - 1;
2011 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2012 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2013
Giridhar Malavali706f4572011-11-18 09:03:16 -08002014 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002015 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002016 } else
2017 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2018 "BAR 3 not enabled.\n");
2019
2020mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002021 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002022 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002023 return (0);
2024
2025iospace_error_exit:
2026 return (-ENOMEM);
2027}
2028
2029
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002030static int
2031qla83xx_iospace_config(struct qla_hw_data *ha)
2032{
2033 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002034
2035 if (pci_request_selected_regions(ha->pdev, ha->bars,
2036 QLA2XXX_DRIVER_NAME)) {
2037 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2038 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2039 pci_name(ha->pdev));
2040
2041 goto iospace_error_exit;
2042 }
2043
2044 /* Use MMIO operations for all accesses. */
2045 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2046 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2047 "Invalid pci I/O region size (%s).\n",
2048 pci_name(ha->pdev));
2049 goto iospace_error_exit;
2050 }
2051 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2052 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2053 "Invalid PCI mem region size (%s), aborting\n",
2054 pci_name(ha->pdev));
2055 goto iospace_error_exit;
2056 }
2057
2058 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2059 if (!ha->iobase) {
2060 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2061 "Cannot remap MMIO (%s), aborting.\n",
2062 pci_name(ha->pdev));
2063 goto iospace_error_exit;
2064 }
2065
2066 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2067 /* 83XX 26XX always use MQ type access for queues
2068 * - mbar 2, a.k.a region 4 */
2069 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002070 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002071 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2072 pci_resource_len(ha->pdev, 4));
2073
2074 if (!ha->mqiobase) {
2075 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2076 "BAR2/region4 not enabled\n");
2077 goto mqiobase_exit;
2078 }
2079
2080 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2081 pci_resource_len(ha->pdev, 2));
2082 if (ha->msixbase) {
2083 /* Read MSIX vector size of the board */
2084 pci_read_config_word(ha->pdev,
2085 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002086 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002087 /*
2088 * By default, driver uses at least two msix vectors
2089 * (default & rspq)
2090 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002091 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002092 /* MB interrupt uses 1 vector */
2093 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002094
2095 /* ATIOQ needs 1 vector. That's 1 less QPair */
2096 if (QLA_TGT_MODE_ENABLED())
2097 ha->max_req_queues--;
2098
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002099 ha->max_rsp_queues = ha->max_req_queues;
2100
Michael Hernandezd7459522016-12-12 14:40:07 -08002101 /* Queue pairs is the max value minus
2102 * the base queue pair */
2103 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002104 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002105 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002106 }
2107 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002108 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002109 } else
2110 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2111 "BAR 1 not enabled.\n");
2112
2113mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002114 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002115 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002116 return 0;
2117
2118iospace_error_exit:
2119 return -ENOMEM;
2120}
2121
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002122static struct isp_operations qla2100_isp_ops = {
2123 .pci_config = qla2100_pci_config,
2124 .reset_chip = qla2x00_reset_chip,
2125 .chip_diag = qla2x00_chip_diag,
2126 .config_rings = qla2x00_config_rings,
2127 .reset_adapter = qla2x00_reset_adapter,
2128 .nvram_config = qla2x00_nvram_config,
2129 .update_fw_options = qla2x00_update_fw_options,
2130 .load_risc = qla2x00_load_risc,
2131 .pci_info_str = qla2x00_pci_info_str,
2132 .fw_version_str = qla2x00_fw_version_str,
2133 .intr_handler = qla2100_intr_handler,
2134 .enable_intrs = qla2x00_enable_intrs,
2135 .disable_intrs = qla2x00_disable_intrs,
2136 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002137 .target_reset = qla2x00_abort_target,
2138 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002139 .fabric_login = qla2x00_login_fabric,
2140 .fabric_logout = qla2x00_fabric_logout,
2141 .calc_req_entries = qla2x00_calc_iocbs_32,
2142 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2143 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2144 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2145 .read_nvram = qla2x00_read_nvram_data,
2146 .write_nvram = qla2x00_write_nvram_data,
2147 .fw_dump = qla2100_fw_dump,
2148 .beacon_on = NULL,
2149 .beacon_off = NULL,
2150 .beacon_blink = NULL,
2151 .read_optrom = qla2x00_read_optrom_data,
2152 .write_optrom = qla2x00_write_optrom_data,
2153 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002155 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002156 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002157 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002158 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002159};
2160
2161static struct isp_operations qla2300_isp_ops = {
2162 .pci_config = qla2300_pci_config,
2163 .reset_chip = qla2x00_reset_chip,
2164 .chip_diag = qla2x00_chip_diag,
2165 .config_rings = qla2x00_config_rings,
2166 .reset_adapter = qla2x00_reset_adapter,
2167 .nvram_config = qla2x00_nvram_config,
2168 .update_fw_options = qla2x00_update_fw_options,
2169 .load_risc = qla2x00_load_risc,
2170 .pci_info_str = qla2x00_pci_info_str,
2171 .fw_version_str = qla2x00_fw_version_str,
2172 .intr_handler = qla2300_intr_handler,
2173 .enable_intrs = qla2x00_enable_intrs,
2174 .disable_intrs = qla2x00_disable_intrs,
2175 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002176 .target_reset = qla2x00_abort_target,
2177 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002178 .fabric_login = qla2x00_login_fabric,
2179 .fabric_logout = qla2x00_fabric_logout,
2180 .calc_req_entries = qla2x00_calc_iocbs_32,
2181 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2182 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2183 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2184 .read_nvram = qla2x00_read_nvram_data,
2185 .write_nvram = qla2x00_write_nvram_data,
2186 .fw_dump = qla2300_fw_dump,
2187 .beacon_on = qla2x00_beacon_on,
2188 .beacon_off = qla2x00_beacon_off,
2189 .beacon_blink = qla2x00_beacon_blink,
2190 .read_optrom = qla2x00_read_optrom_data,
2191 .write_optrom = qla2x00_write_optrom_data,
2192 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002194 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002195 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002196 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002197 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002198};
2199
2200static struct isp_operations qla24xx_isp_ops = {
2201 .pci_config = qla24xx_pci_config,
2202 .reset_chip = qla24xx_reset_chip,
2203 .chip_diag = qla24xx_chip_diag,
2204 .config_rings = qla24xx_config_rings,
2205 .reset_adapter = qla24xx_reset_adapter,
2206 .nvram_config = qla24xx_nvram_config,
2207 .update_fw_options = qla24xx_update_fw_options,
2208 .load_risc = qla24xx_load_risc,
2209 .pci_info_str = qla24xx_pci_info_str,
2210 .fw_version_str = qla24xx_fw_version_str,
2211 .intr_handler = qla24xx_intr_handler,
2212 .enable_intrs = qla24xx_enable_intrs,
2213 .disable_intrs = qla24xx_disable_intrs,
2214 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002215 .target_reset = qla24xx_abort_target,
2216 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002217 .fabric_login = qla24xx_login_fabric,
2218 .fabric_logout = qla24xx_fabric_logout,
2219 .calc_req_entries = NULL,
2220 .build_iocbs = NULL,
2221 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2222 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2223 .read_nvram = qla24xx_read_nvram_data,
2224 .write_nvram = qla24xx_write_nvram_data,
2225 .fw_dump = qla24xx_fw_dump,
2226 .beacon_on = qla24xx_beacon_on,
2227 .beacon_off = qla24xx_beacon_off,
2228 .beacon_blink = qla24xx_beacon_blink,
2229 .read_optrom = qla24xx_read_optrom_data,
2230 .write_optrom = qla24xx_write_optrom_data,
2231 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002232 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002233 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002234 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002235 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002236 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002237};
2238
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002239static struct isp_operations qla25xx_isp_ops = {
2240 .pci_config = qla25xx_pci_config,
2241 .reset_chip = qla24xx_reset_chip,
2242 .chip_diag = qla24xx_chip_diag,
2243 .config_rings = qla24xx_config_rings,
2244 .reset_adapter = qla24xx_reset_adapter,
2245 .nvram_config = qla24xx_nvram_config,
2246 .update_fw_options = qla24xx_update_fw_options,
2247 .load_risc = qla24xx_load_risc,
2248 .pci_info_str = qla24xx_pci_info_str,
2249 .fw_version_str = qla24xx_fw_version_str,
2250 .intr_handler = qla24xx_intr_handler,
2251 .enable_intrs = qla24xx_enable_intrs,
2252 .disable_intrs = qla24xx_disable_intrs,
2253 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002254 .target_reset = qla24xx_abort_target,
2255 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002256 .fabric_login = qla24xx_login_fabric,
2257 .fabric_logout = qla24xx_fabric_logout,
2258 .calc_req_entries = NULL,
2259 .build_iocbs = NULL,
2260 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2261 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2262 .read_nvram = qla25xx_read_nvram_data,
2263 .write_nvram = qla25xx_write_nvram_data,
2264 .fw_dump = qla25xx_fw_dump,
2265 .beacon_on = qla24xx_beacon_on,
2266 .beacon_off = qla24xx_beacon_off,
2267 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002268 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002269 .write_optrom = qla24xx_write_optrom_data,
2270 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002271 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002272 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002273 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002274 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002275 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002276};
2277
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002278static struct isp_operations qla81xx_isp_ops = {
2279 .pci_config = qla25xx_pci_config,
2280 .reset_chip = qla24xx_reset_chip,
2281 .chip_diag = qla24xx_chip_diag,
2282 .config_rings = qla24xx_config_rings,
2283 .reset_adapter = qla24xx_reset_adapter,
2284 .nvram_config = qla81xx_nvram_config,
2285 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002286 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002287 .pci_info_str = qla24xx_pci_info_str,
2288 .fw_version_str = qla24xx_fw_version_str,
2289 .intr_handler = qla24xx_intr_handler,
2290 .enable_intrs = qla24xx_enable_intrs,
2291 .disable_intrs = qla24xx_disable_intrs,
2292 .abort_command = qla24xx_abort_command,
2293 .target_reset = qla24xx_abort_target,
2294 .lun_reset = qla24xx_lun_reset,
2295 .fabric_login = qla24xx_login_fabric,
2296 .fabric_logout = qla24xx_fabric_logout,
2297 .calc_req_entries = NULL,
2298 .build_iocbs = NULL,
2299 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2300 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002301 .read_nvram = NULL,
2302 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002303 .fw_dump = qla81xx_fw_dump,
2304 .beacon_on = qla24xx_beacon_on,
2305 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002306 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002307 .read_optrom = qla25xx_read_optrom_data,
2308 .write_optrom = qla24xx_write_optrom_data,
2309 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002310 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002311 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002312 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002313 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002314 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002315};
2316
2317static struct isp_operations qla82xx_isp_ops = {
2318 .pci_config = qla82xx_pci_config,
2319 .reset_chip = qla82xx_reset_chip,
2320 .chip_diag = qla24xx_chip_diag,
2321 .config_rings = qla82xx_config_rings,
2322 .reset_adapter = qla24xx_reset_adapter,
2323 .nvram_config = qla81xx_nvram_config,
2324 .update_fw_options = qla24xx_update_fw_options,
2325 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002326 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002327 .fw_version_str = qla24xx_fw_version_str,
2328 .intr_handler = qla82xx_intr_handler,
2329 .enable_intrs = qla82xx_enable_intrs,
2330 .disable_intrs = qla82xx_disable_intrs,
2331 .abort_command = qla24xx_abort_command,
2332 .target_reset = qla24xx_abort_target,
2333 .lun_reset = qla24xx_lun_reset,
2334 .fabric_login = qla24xx_login_fabric,
2335 .fabric_logout = qla24xx_fabric_logout,
2336 .calc_req_entries = NULL,
2337 .build_iocbs = NULL,
2338 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2339 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2340 .read_nvram = qla24xx_read_nvram_data,
2341 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002342 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002343 .beacon_on = qla82xx_beacon_on,
2344 .beacon_off = qla82xx_beacon_off,
2345 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002346 .read_optrom = qla82xx_read_optrom_data,
2347 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002348 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002349 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002350 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002351 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002352 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002353 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002354};
2355
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002356static struct isp_operations qla8044_isp_ops = {
2357 .pci_config = qla82xx_pci_config,
2358 .reset_chip = qla82xx_reset_chip,
2359 .chip_diag = qla24xx_chip_diag,
2360 .config_rings = qla82xx_config_rings,
2361 .reset_adapter = qla24xx_reset_adapter,
2362 .nvram_config = qla81xx_nvram_config,
2363 .update_fw_options = qla24xx_update_fw_options,
2364 .load_risc = qla82xx_load_risc,
2365 .pci_info_str = qla24xx_pci_info_str,
2366 .fw_version_str = qla24xx_fw_version_str,
2367 .intr_handler = qla8044_intr_handler,
2368 .enable_intrs = qla82xx_enable_intrs,
2369 .disable_intrs = qla82xx_disable_intrs,
2370 .abort_command = qla24xx_abort_command,
2371 .target_reset = qla24xx_abort_target,
2372 .lun_reset = qla24xx_lun_reset,
2373 .fabric_login = qla24xx_login_fabric,
2374 .fabric_logout = qla24xx_fabric_logout,
2375 .calc_req_entries = NULL,
2376 .build_iocbs = NULL,
2377 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2378 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2379 .read_nvram = NULL,
2380 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002381 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002382 .beacon_on = qla82xx_beacon_on,
2383 .beacon_off = qla82xx_beacon_off,
2384 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002385 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002386 .write_optrom = qla8044_write_optrom_data,
2387 .get_flash_version = qla82xx_get_flash_version,
2388 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002389 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002390 .abort_isp = qla8044_abort_isp,
2391 .iospace_config = qla82xx_iospace_config,
2392 .initialize_adapter = qla2x00_initialize_adapter,
2393};
2394
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002395static struct isp_operations qla83xx_isp_ops = {
2396 .pci_config = qla25xx_pci_config,
2397 .reset_chip = qla24xx_reset_chip,
2398 .chip_diag = qla24xx_chip_diag,
2399 .config_rings = qla24xx_config_rings,
2400 .reset_adapter = qla24xx_reset_adapter,
2401 .nvram_config = qla81xx_nvram_config,
2402 .update_fw_options = qla81xx_update_fw_options,
2403 .load_risc = qla81xx_load_risc,
2404 .pci_info_str = qla24xx_pci_info_str,
2405 .fw_version_str = qla24xx_fw_version_str,
2406 .intr_handler = qla24xx_intr_handler,
2407 .enable_intrs = qla24xx_enable_intrs,
2408 .disable_intrs = qla24xx_disable_intrs,
2409 .abort_command = qla24xx_abort_command,
2410 .target_reset = qla24xx_abort_target,
2411 .lun_reset = qla24xx_lun_reset,
2412 .fabric_login = qla24xx_login_fabric,
2413 .fabric_logout = qla24xx_fabric_logout,
2414 .calc_req_entries = NULL,
2415 .build_iocbs = NULL,
2416 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2417 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2418 .read_nvram = NULL,
2419 .write_nvram = NULL,
2420 .fw_dump = qla83xx_fw_dump,
2421 .beacon_on = qla24xx_beacon_on,
2422 .beacon_off = qla24xx_beacon_off,
2423 .beacon_blink = qla83xx_beacon_blink,
2424 .read_optrom = qla25xx_read_optrom_data,
2425 .write_optrom = qla24xx_write_optrom_data,
2426 .get_flash_version = qla24xx_get_flash_version,
2427 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002428 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002429 .abort_isp = qla2x00_abort_isp,
2430 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002431 .initialize_adapter = qla2x00_initialize_adapter,
2432};
2433
2434static struct isp_operations qlafx00_isp_ops = {
2435 .pci_config = qlafx00_pci_config,
2436 .reset_chip = qlafx00_soft_reset,
2437 .chip_diag = qlafx00_chip_diag,
2438 .config_rings = qlafx00_config_rings,
2439 .reset_adapter = qlafx00_soft_reset,
2440 .nvram_config = NULL,
2441 .update_fw_options = NULL,
2442 .load_risc = NULL,
2443 .pci_info_str = qlafx00_pci_info_str,
2444 .fw_version_str = qlafx00_fw_version_str,
2445 .intr_handler = qlafx00_intr_handler,
2446 .enable_intrs = qlafx00_enable_intrs,
2447 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002448 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002449 .target_reset = qlafx00_abort_target,
2450 .lun_reset = qlafx00_lun_reset,
2451 .fabric_login = NULL,
2452 .fabric_logout = NULL,
2453 .calc_req_entries = NULL,
2454 .build_iocbs = NULL,
2455 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2456 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2457 .read_nvram = qla24xx_read_nvram_data,
2458 .write_nvram = qla24xx_write_nvram_data,
2459 .fw_dump = NULL,
2460 .beacon_on = qla24xx_beacon_on,
2461 .beacon_off = qla24xx_beacon_off,
2462 .beacon_blink = NULL,
2463 .read_optrom = qla24xx_read_optrom_data,
2464 .write_optrom = qla24xx_write_optrom_data,
2465 .get_flash_version = qla24xx_get_flash_version,
2466 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002467 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002468 .abort_isp = qlafx00_abort_isp,
2469 .iospace_config = qlafx00_iospace_config,
2470 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002471};
2472
Chad Dupuisf73cb692014-02-26 04:15:06 -05002473static struct isp_operations qla27xx_isp_ops = {
2474 .pci_config = qla25xx_pci_config,
2475 .reset_chip = qla24xx_reset_chip,
2476 .chip_diag = qla24xx_chip_diag,
2477 .config_rings = qla24xx_config_rings,
2478 .reset_adapter = qla24xx_reset_adapter,
2479 .nvram_config = qla81xx_nvram_config,
2480 .update_fw_options = qla81xx_update_fw_options,
2481 .load_risc = qla81xx_load_risc,
2482 .pci_info_str = qla24xx_pci_info_str,
2483 .fw_version_str = qla24xx_fw_version_str,
2484 .intr_handler = qla24xx_intr_handler,
2485 .enable_intrs = qla24xx_enable_intrs,
2486 .disable_intrs = qla24xx_disable_intrs,
2487 .abort_command = qla24xx_abort_command,
2488 .target_reset = qla24xx_abort_target,
2489 .lun_reset = qla24xx_lun_reset,
2490 .fabric_login = qla24xx_login_fabric,
2491 .fabric_logout = qla24xx_fabric_logout,
2492 .calc_req_entries = NULL,
2493 .build_iocbs = NULL,
2494 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2495 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2496 .read_nvram = NULL,
2497 .write_nvram = NULL,
2498 .fw_dump = qla27xx_fwdump,
2499 .beacon_on = qla24xx_beacon_on,
2500 .beacon_off = qla24xx_beacon_off,
2501 .beacon_blink = qla83xx_beacon_blink,
2502 .read_optrom = qla25xx_read_optrom_data,
2503 .write_optrom = qla24xx_write_optrom_data,
2504 .get_flash_version = qla24xx_get_flash_version,
2505 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002506 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002507 .abort_isp = qla2x00_abort_isp,
2508 .iospace_config = qla83xx_iospace_config,
2509 .initialize_adapter = qla2x00_initialize_adapter,
2510};
2511
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002512static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002514{
2515 ha->device_type = DT_EXTENDED_IDS;
2516 switch (ha->pdev->device) {
2517 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002518 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002519 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002520 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002521 break;
2522 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002523 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002524 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002525 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002526 break;
2527 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002528 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002529 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002530 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002531 break;
2532 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002533 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002534 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002535 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002536 break;
2537 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002538 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002539 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002540 if (ha->pdev->subsystem_vendor == 0x1028 &&
2541 ha->pdev->subsystem_device == 0x0170)
2542 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002543 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002544 break;
2545 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002546 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002547 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002548 break;
2549 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002550 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002551 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002552 break;
2553 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002554 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002555 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002556 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002557 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002558 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002559 break;
2560 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002561 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002562 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002563 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002564 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002565 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002566 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002567 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002568 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002569 ha->device_type |= DT_ZIO_SUPPORTED;
2570 ha->device_type |= DT_FWI2;
2571 ha->device_type |= DT_IIDMA;
2572 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2573 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002574 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002575 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002576 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002577 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002578 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002579 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002580 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002581 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002582 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002583 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002584 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002585 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002586 ha->device_type |= DT_ZIO_SUPPORTED;
2587 ha->device_type |= DT_FWI2;
2588 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002589 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2590 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002591 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002592 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002593 ha->device_type |= DT_ZIO_SUPPORTED;
2594 ha->device_type |= DT_FWI2;
2595 ha->device_type |= DT_IIDMA;
2596 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2597 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002598 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002599 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002600 ha->device_type |= DT_ZIO_SUPPORTED;
2601 ha->device_type |= DT_FWI2;
2602 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2603 /* Initialize 82XX ISP flags */
2604 qla82xx_init_flags(ha);
2605 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002606 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002607 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002608 ha->device_type |= DT_ZIO_SUPPORTED;
2609 ha->device_type |= DT_FWI2;
2610 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2611 /* Initialize 82XX ISP flags */
2612 qla82xx_init_flags(ha);
2613 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002614 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002615 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002616 ha->device_type |= DT_ZIO_SUPPORTED;
2617 ha->device_type |= DT_FWI2;
2618 ha->device_type |= DT_IIDMA;
2619 ha->device_type |= DT_T10_PI;
2620 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2621 break;
2622 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002623 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002624 ha->device_type |= DT_ZIO_SUPPORTED;
2625 ha->device_type |= DT_FWI2;
2626 ha->device_type |= DT_IIDMA;
2627 ha->device_type |= DT_T10_PI;
2628 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2629 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002630 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002631 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002632 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002633 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002634 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002635 ha->device_type |= DT_ZIO_SUPPORTED;
2636 ha->device_type |= DT_FWI2;
2637 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002638 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002639 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2640 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002641 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002642 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002643 ha->device_type |= DT_ZIO_SUPPORTED;
2644 ha->device_type |= DT_FWI2;
2645 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002646 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002647 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2648 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002649 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002650 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002651 ha->device_type |= DT_ZIO_SUPPORTED;
2652 ha->device_type |= DT_FWI2;
2653 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002654 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002655 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2656 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002657 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002658
Giridhar Malavalia9083012010-04-12 17:59:55 -07002659 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002660 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002661 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002662 /* Get adapter physical port no from interrupt pin register. */
2663 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002664 if (IS_QLA27XX(ha))
2665 ha->port_no--;
2666 else
2667 ha->port_no = !(ha->port_no & 1);
2668 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002669
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002670 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002671 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002672 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002673}
2674
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002675static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002676qla2xxx_scan_start(struct Scsi_Host *shost)
2677{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002678 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002679
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002680 if (vha->hw->flags.running_gold_fw)
2681 return;
2682
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2684 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2685 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2686 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002687}
2688
2689static int
2690qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2691{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002693
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002694 if (test_bit(UNLOADING, &vha->dpc_flags))
2695 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002697 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002699 return 1;
2700
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002702}
2703
Quinn Tranec7193e2017-03-15 09:48:55 -07002704static void qla2x00_iocb_work_fn(struct work_struct *work)
2705{
2706 struct scsi_qla_host *vha = container_of(work,
2707 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002708 struct qla_hw_data *ha = vha->hw;
2709 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2710 int i = 20;
2711 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002712
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002713 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2714 return;
2715
2716 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002717 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002718 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002719 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002720
2721 spin_lock_irqsave(&vha->work_lock, flags);
2722 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2723 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002724}
2725
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726/*
2727 * PCI driver interface
2728 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002729static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002730qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002732 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 scsi_qla_host_t *base_vha = NULL;
2735 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002736 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002737 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002738 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002739 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002741 struct req_que *req = NULL;
2742 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002743 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002744
Andrew Vasquez285d0322007-10-19 15:59:17 -07002745 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002746 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002747 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2748 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002749 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002750 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2751 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002752 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002753 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002754 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2755 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002756 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002757 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002758 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002759 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002760 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2761 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002762 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002763 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002764 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2765 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002766 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002767 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2768 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002769
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002770 if (mem_only) {
2771 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002772 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002773 } else {
2774 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002775 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
Jesse Barnes09276782008-10-18 17:33:19 -07002778 /* This may fail but that's ok */
2779 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2782 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002783 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2784 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002785 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002787 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2788 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002790 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2791 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002792 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002793 spin_lock_init(&ha->tgt.atio_lock);
2794
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002795 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
2797 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002798 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002799 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002800 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002801 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002802 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002803 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002805 /* Set ISP-type information. */
2806 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002807
2808 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002809 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002810 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002811 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002812
Chad Dupuiscba1e472011-11-18 09:03:21 -08002813 ha->prev_topology = 0;
2814 ha->init_cb_size = sizeof(init_cb_t);
2815 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2816 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002817 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002818
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002819 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002821 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 req_length = REQUEST_ENTRY_CNT_2100;
2824 rsp_length = RESPONSE_ENTRY_CNT_2100;
2825 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002826 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002827 ha->flash_conf_off = ~0;
2828 ha->flash_data_off = ~0;
2829 ha->nvram_conf_off = ~0;
2830 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002831 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002833 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002834 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 req_length = REQUEST_ENTRY_CNT_2200;
2836 rsp_length = RESPONSE_ENTRY_CNT_2100;
2837 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002838 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002839 ha->flash_conf_off = ~0;
2840 ha->flash_data_off = ~0;
2841 ha->nvram_conf_off = ~0;
2842 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002843 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002844 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002845 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 req_length = REQUEST_ENTRY_CNT_2200;
2848 rsp_length = RESPONSE_ENTRY_CNT_2300;
2849 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002850 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002851 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2852 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002853 ha->flash_conf_off = ~0;
2854 ha->flash_data_off = ~0;
2855 ha->nvram_conf_off = ~0;
2856 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002857 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002858 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002859 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002860 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 req_length = REQUEST_ENTRY_CNT_24XX;
2862 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002863 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002865 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002866 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002867 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002868 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002869 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002870 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2871 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2872 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2873 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002874 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002875 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002876 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002877 req_length = REQUEST_ENTRY_CNT_24XX;
2878 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002879 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002881 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002882 ha->gid_list_info_size = 8;
2883 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002884 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002885 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002886 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2887 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2888 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2889 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2890 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002891 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002892 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2893 req_length = REQUEST_ENTRY_CNT_24XX;
2894 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002895 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002896 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2897 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2898 ha->gid_list_info_size = 8;
2899 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002900 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002901 ha->isp_ops = &qla81xx_isp_ops;
2902 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2903 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2904 ha->nvram_conf_off = ~0;
2905 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002906 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002907 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002908 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2909 req_length = REQUEST_ENTRY_CNT_82XX;
2910 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2911 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2912 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2913 ha->gid_list_info_size = 8;
2914 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002915 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002916 ha->isp_ops = &qla82xx_isp_ops;
2917 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2918 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2919 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2920 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002921 } else if (IS_QLA8044(ha)) {
2922 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2923 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2924 req_length = REQUEST_ENTRY_CNT_82XX;
2925 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2926 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2927 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2928 ha->gid_list_info_size = 8;
2929 ha->optrom_size = OPTROM_SIZE_83XX;
2930 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2931 ha->isp_ops = &qla8044_isp_ops;
2932 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2933 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2934 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2935 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002936 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002937 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002938 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002939 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002940 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002941 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002942 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002943 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2944 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2945 ha->gid_list_info_size = 8;
2946 ha->optrom_size = OPTROM_SIZE_83XX;
2947 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2948 ha->isp_ops = &qla83xx_isp_ops;
2949 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2950 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2951 ha->nvram_conf_off = ~0;
2952 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002953 } else if (IS_QLAFX00(ha)) {
2954 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2955 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2956 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2957 req_length = REQUEST_ENTRY_CNT_FX00;
2958 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002959 ha->isp_ops = &qlafx00_isp_ops;
2960 ha->port_down_retry_count = 30; /* default value */
2961 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2962 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002963 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002964 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002965 ha->mr.host_info_resend = false;
2966 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002967 } else if (IS_QLA27XX(ha)) {
2968 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2969 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2970 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002971 req_length = REQUEST_ENTRY_CNT_83XX;
2972 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002973 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002974 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2975 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2976 ha->gid_list_info_size = 8;
2977 ha->optrom_size = OPTROM_SIZE_83XX;
2978 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2979 ha->isp_ops = &qla27xx_isp_ops;
2980 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2981 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2982 ha->nvram_conf_off = ~0;
2983 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002985
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002986 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2987 "mbx_count=%d, req_length=%d, "
2988 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002989 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2990 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002991 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2992 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002993 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002994 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2995 "isp_ops=%p, flash_conf_off=%d, "
2996 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2997 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2998 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002999
3000 /* Configure PCI I/O space */
3001 ret = ha->isp_ops->iospace_config(ha);
3002 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003003 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003004
3005 ql_log_pci(ql_log_info, pdev, 0x001d,
3006 "Found an ISP%04X irq %d iobase 0x%p.\n",
3007 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003008 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003009 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003010 init_completion(&ha->mbx_cmd_comp);
3011 complete(&ha->mbx_cmd_comp);
3012 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003013 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003014 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003016 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017
Andrew Vasquez53303c42009-01-22 09:45:37 -08003018 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003019 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3020 "64 Bit addressing is %s.\n",
3021 ha->flags.enable_64bit_addressing ? "enable" :
3022 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003023 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003024 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003025 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3026 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 goto probe_hw_failed;
3029 }
3030
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003031 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003033 req->max_q_depth = ql2xmaxqdepth;
3034
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003035
3036 base_vha = qla2x00_create_host(sht, ha);
3037 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003038 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003039 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 }
3041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003043 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003046 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003047 if (IS_QLA2XXX_MIDTYPE(ha))
himanshu.madhani@cavium.com1429f042017-12-28 12:33:25 -08003048 base_vha->mgmt_svr_loop_id = NPH_MGMT_SERVER;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003049 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003050 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3051 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003052
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003053 /* Setup fcport template structure. */
3054 ha->mr.fcport.vha = base_vha;
3055 ha->mr.fcport.port_type = FCT_UNKNOWN;
3056 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3057 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3058 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3059 ha->mr.fcport.scan_state = 1;
3060
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003061 /* Set the SG table size based on ISP type */
3062 if (!IS_FWI2_CAPABLE(ha)) {
3063 if (IS_QLA2100(ha))
3064 host->sg_tablesize = 32;
3065 } else {
3066 if (!IS_QLA82XX(ha))
3067 host->sg_tablesize = QLA_SG_ALL;
3068 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003069 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003070 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003071 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003072 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003073 host->max_cmd_len = 32;
3074 else
3075 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003076 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003077 /* Older HBAs support only 16-bit LUNs */
3078 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3079 ql2xmaxlun > 0xffff)
3080 host->max_lun = 0xffff;
3081 else
3082 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003083 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003084 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003085
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003086 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3087 "max_id=%d this_id=%d "
3088 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003089 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003090 host->this_id, host->cmd_per_lun, host->unique_id,
3091 host->max_cmd_len, host->max_channel, host->max_lun,
3092 host->transportt, sht->vendor_id);
3093
Himanshu Madhani1010f212017-10-16 11:26:05 -07003094 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3095
Michael Hernandezd7459522016-12-12 14:40:07 -08003096 /* Set up the irqs */
3097 ret = qla2x00_request_irqs(ha, rsp);
3098 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003099 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003100
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003101 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003102 ret = qla2x00_alloc_queues(ha, req, rsp);
3103 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003104 ql_log(ql_log_fatal, base_vha, 0x003d,
3105 "Failed to allocate memory for queue pointers..."
3106 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003107 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003108 }
3109
Michael Hernandez56012362016-12-12 14:40:08 -08003110 if (ha->mqenable && shost_use_blk_mq(host)) {
3111 /* number of hardware queues supported by blk/scsi-mq*/
3112 host->nr_hw_queues = ha->max_qpairs;
3113
3114 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3115 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003116 } else {
3117 if (ql2xnvmeenable) {
3118 host->nr_hw_queues = ha->max_qpairs;
3119 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3120 "FC-NVMe support is enabled, HW queues=%d\n",
3121 host->nr_hw_queues);
3122 } else {
3123 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3124 "blk/scsi-mq disabled.\n");
3125 }
3126 }
Michael Hernandez56012362016-12-12 14:40:08 -08003127
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003128 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003129
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003130 pci_save_state(pdev);
3131
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003132 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003133 rsp->req = req;
3134 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003135
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003136 if (IS_QLAFX00(ha)) {
3137 ha->rsp_q_map[0] = rsp;
3138 ha->req_q_map[0] = req;
3139 set_bit(0, ha->req_qid_map);
3140 set_bit(0, ha->rsp_qid_map);
3141 }
3142
Andrew Vasquez08029992009-03-24 09:07:55 -07003143 /* FWI2-capable only. */
3144 req->req_q_in = &ha->iobase->isp24.req_q_in;
3145 req->req_q_out = &ha->iobase->isp24.req_q_out;
3146 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3147 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003148 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003149 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3150 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3151 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3152 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003153 }
3154
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003155 if (IS_QLAFX00(ha)) {
3156 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3157 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3158 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3159 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3160 }
3161
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003162 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003163 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3164 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3165 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3166 }
3167
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003168 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3169 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3170 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3171 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3172 "req->req_q_in=%p req->req_q_out=%p "
3173 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3174 req->req_q_in, req->req_q_out,
3175 rsp->rsp_q_in, rsp->rsp_q_out);
3176 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3177 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3178 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3179 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3180 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3181 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003183 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003184 ql_log(ql_log_fatal, base_vha, 0x00d6,
3185 "Failed to initialize adapter - Adapter flags %x.\n",
3186 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187
Giridhar Malavalia9083012010-04-12 17:59:55 -07003188 if (IS_QLA82XX(ha)) {
3189 qla82xx_idc_lock(ha);
3190 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003191 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003192 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003193 ql_log(ql_log_fatal, base_vha, 0x00d7,
3194 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003195 } else if (IS_QLA8044(ha)) {
3196 qla8044_idc_lock(ha);
3197 qla8044_wr_direct(base_vha,
3198 QLA8044_CRB_DEV_STATE_INDEX,
3199 QLA8XXX_DEV_FAILED);
3200 qla8044_idc_unlock(ha);
3201 ql_log(ql_log_fatal, base_vha, 0x0150,
3202 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003203 }
3204
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003205 ret = -ENODEV;
3206 goto probe_failed;
3207 }
3208
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003209 if (IS_QLAFX00(ha))
3210 host->can_queue = QLAFX00_MAX_CANQUEUE;
3211 else
3212 host->can_queue = req->num_outstanding_cmds - 10;
3213
3214 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3215 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3216 host->can_queue, base_vha->req,
3217 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3218
Quinn Tran9b3e0f42017-12-28 12:33:16 -08003219 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
Quinn Trana01c77d2017-12-04 14:44:58 -08003220
Quinn Trane326d222017-06-13 20:47:18 -07003221 if (ha->mqenable) {
3222 bool mq = false;
3223 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003224
3225 if (QLA_TGT_MODE_ENABLED()) {
3226 mq = true;
3227 startit = false;
3228 }
3229
3230 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3231 shost_use_blk_mq(host)) {
3232 mq = true;
3233 startit = true;
3234 }
3235
3236 if (mq) {
3237 /* Create start of day qpairs for Block MQ */
Michael Hernandez56012362016-12-12 14:40:08 -08003238 for (i = 0; i < ha->max_qpairs; i++)
Quinn Trane326d222017-06-13 20:47:18 -07003239 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003240 }
3241 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003242
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003243 if (ha->flags.running_gold_fw)
3244 goto skip_dpc;
3245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 /*
3247 * Startup the kernel thread for this host adapter
3248 */
3249 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003250 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003252 ql_log(ql_log_fatal, base_vha, 0x00ed,
3253 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003254 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003255 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 goto probe_failed;
3257 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003258 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3259 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003261 /*
3262 * If we're not coming up in initiator mode, we might sit for
3263 * a while without waking up the dpc thread, which leads to a
3264 * stuck process warning. So just kick the dpc once here and
3265 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3266 */
3267 qla2xxx_wake_dpc(base_vha);
3268
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003269 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3270
Saurav Kashyap81178772012-08-22 14:21:04 -04003271 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3272 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3273 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3274 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3275
3276 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3277 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3278 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3279 INIT_WORK(&ha->idc_state_handler,
3280 qla83xx_idc_state_handler_work);
3281 INIT_WORK(&ha->nic_core_unrecoverable,
3282 qla83xx_nic_core_unrecoverable_work);
3283 }
3284
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003285skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286 list_add_tail(&base_vha->list, &ha->vp_list);
3287 base_vha->host->irq = ha->pdev->irq;
3288
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003290 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003291 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3292 "Started qla2x00_timer with "
3293 "interval=%d.\n", WATCH_INTERVAL);
3294 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3295 "Detected hba at address=%p.\n",
3296 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
Arun Easie02587d2011-08-16 11:29:23 -07003298 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003299 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003300 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003301 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003302 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3303 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003304 if (ql2xenabledif == 1)
3305 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003306 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003307 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003308 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003309 | SHOST_DIF_TYPE3_PROTECTION
3310 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003311 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003312 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003313
3314 guard = SHOST_DIX_GUARD_CRC;
3315
3316 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3317 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3318 guard |= SHOST_DIX_GUARD_IP;
3319
3320 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003321 } else
3322 base_vha->flags.difdix_supported = 0;
3323 }
3324
Giridhar Malavalia9083012010-04-12 17:59:55 -07003325 ha->isp_ops->enable_intrs(ha);
3326
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003327 if (IS_QLAFX00(ha)) {
3328 ret = qlafx00_fx_disc(base_vha,
3329 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3330 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3331 QLA_SG_ALL : 128;
3332 }
3333
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003334 ret = scsi_add_host(host, &pdev->dev);
3335 if (ret)
3336 goto probe_failed;
3337
Michael Reed14864002009-12-02 09:11:16 -06003338 base_vha->flags.init_done = 1;
3339 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003340 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003341
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003342 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3343 "Init done and hba is online.\n");
3344
Quinn Tran726b8542017-01-19 22:28:00 -08003345 if (qla_ini_mode_enabled(base_vha) ||
3346 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003347 scsi_scan_host(host);
3348 else
3349 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3350 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003351
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003353
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003354 if (IS_QLAFX00(ha)) {
3355 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003356 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3357
3358 /* Register system information */
3359 ret = qlafx00_fx_disc(base_vha,
3360 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3361 }
3362
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003363 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003365 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003366
Armen Baloyan03eb9122013-10-30 03:38:22 -04003367 ql_log(ql_log_info, base_vha, 0x00fb,
3368 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003369 ql_log(ql_log_info, base_vha, 0x00fc,
3370 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3371 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3372 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3373 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003374 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003376 qlt_add_target(ha, base_vha);
3377
Joe Lawrence6b383972014-08-26 17:12:29 -04003378 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003379
3380 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3381 return -ENODEV;
3382
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003383 if (ha->flags.detected_lr_sfp) {
3384 ql_log(ql_log_info, base_vha, 0xffff,
3385 "Reset chip to pick up LR SFP setting\n");
3386 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3387 qla2xxx_wake_dpc(base_vha);
3388 }
3389
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 return 0;
3391
3392probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003393 if (base_vha->timer_active)
3394 qla2x00_stop_timer(base_vha);
3395 base_vha->flags.online = 0;
3396 if (ha->dpc_thread) {
3397 struct task_struct *t = ha->dpc_thread;
3398
3399 ha->dpc_thread = NULL;
3400 kthread_stop(t);
3401 }
3402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003405 /*
3406 * Need to NULL out local req/rsp after
3407 * qla2x00_free_device => qla2x00_free_queues frees
3408 * what these are pointing to. Or else we'll
3409 * fall over below in qla2x00_free_req/rsp_que.
3410 */
3411 req = NULL;
3412 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003415 qla2x00_mem_free(ha);
3416 qla2x00_free_req_que(ha, req);
3417 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003418 qla2x00_clear_drv_active(ha);
3419
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003420iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003421 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003422 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003423 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003424 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003425 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003426 } else {
3427 if (ha->iobase)
3428 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003429 if (ha->cregbase)
3430 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003431 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 pci_release_selected_regions(ha->pdev, ha->bars);
3433 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003435disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003437 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
Adrian Bunk4c993f72008-01-14 00:55:16 -08003440static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003441qla2x00_shutdown(struct pci_dev *pdev)
3442{
3443 scsi_qla_host_t *vha;
3444 struct qla_hw_data *ha;
3445
3446 vha = pci_get_drvdata(pdev);
3447 ha = vha->hw;
3448
Sawan Chandakefdb5762017-08-23 15:05:00 -07003449 ql_log(ql_log_info, vha, 0xfffa,
3450 "Adapter shutdown\n");
3451
3452 /*
3453 * Prevent future board_disable and wait
3454 * until any pending board_disable has completed.
3455 */
3456 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3457 cancel_work_sync(&ha->board_disable);
3458
3459 if (!atomic_read(&pdev->enable_cnt))
3460 return;
3461
Armen Baloyan42479342013-08-27 01:37:37 -04003462 /* Notify ISPFX00 firmware */
3463 if (IS_QLAFX00(ha))
3464 qlafx00_driver_shutdown(vha, 20);
3465
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003466 /* Turn-off FCE trace */
3467 if (ha->flags.fce_enabled) {
3468 qla2x00_disable_fce_trace(vha, NULL, NULL);
3469 ha->flags.fce_enabled = 0;
3470 }
3471
3472 /* Turn-off EFT trace */
3473 if (ha->eft)
3474 qla2x00_disable_eft_trace(vha);
3475
Quinn Tran3407fc32017-12-28 12:33:11 -08003476 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3477 if (ha->flags.fw_started)
3478 qla2x00_abort_isp_cleanup(vha);
3479 } else {
3480 /* Stop currently executing firmware. */
3481 qla2x00_try_to_stop_firmware(vha);
3482 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003483
3484 /* Turn adapter off line */
3485 vha->flags.online = 0;
3486
3487 /* turn-off interrupts on the card */
3488 if (ha->interrupts_on) {
3489 vha->flags.init_done = 0;
3490 ha->isp_ops->disable_intrs(ha);
3491 }
3492
3493 qla2x00_free_irqs(vha);
3494
3495 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003496
Chad Dupuis61d41f62014-09-25 05:17:02 -04003497 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003498 ql_log(ql_log_info, vha, 0xfffe,
3499 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003500}
3501
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003502/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003503static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003504qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003506 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003507 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
Arun Easi43ebf162011-05-10 11:18:16 -07003509 mutex_lock(&ha->vport_lock);
3510 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003511 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003512
Arun Easi43ebf162011-05-10 11:18:16 -07003513 BUG_ON(base_vha->list.next == &ha->vp_list);
3514 /* This assumes first entry in ha->vp_list is always base vha */
3515 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003516 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003517
Arun Easi43ebf162011-05-10 11:18:16 -07003518 spin_unlock_irqrestore(&ha->vport_slock, flags);
3519 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003520
Arun Easi43ebf162011-05-10 11:18:16 -07003521 fc_vport_terminate(vha->fc_vport);
3522 scsi_host_put(vha->host);
3523
3524 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 }
Arun Easi43ebf162011-05-10 11:18:16 -07003526 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003527}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003528
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003529/* Stops all deferred work threads */
3530static void
3531qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3532{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003533 /* Cancel all work and destroy DPC workqueues */
3534 if (ha->dpc_lp_wq) {
3535 cancel_work_sync(&ha->idc_aen);
3536 destroy_workqueue(ha->dpc_lp_wq);
3537 ha->dpc_lp_wq = NULL;
3538 }
3539
3540 if (ha->dpc_hp_wq) {
3541 cancel_work_sync(&ha->nic_core_reset);
3542 cancel_work_sync(&ha->idc_state_handler);
3543 cancel_work_sync(&ha->nic_core_unrecoverable);
3544 destroy_workqueue(ha->dpc_hp_wq);
3545 ha->dpc_hp_wq = NULL;
3546 }
3547
Andrew Vasquezb9978762009-03-24 09:08:05 -07003548 /* Kill the kernel thread for this host */
3549 if (ha->dpc_thread) {
3550 struct task_struct *t = ha->dpc_thread;
3551
3552 /*
3553 * qla2xxx_wake_dpc checks for ->dpc_thread
3554 * so we need to zero it out.
3555 */
3556 ha->dpc_thread = NULL;
3557 kthread_stop(t);
3558 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003559}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003560
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003561static void
3562qla2x00_unmap_iobases(struct qla_hw_data *ha)
3563{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003564 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003565
Chad Dupuisf73cb692014-02-26 04:15:06 -05003566 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003567 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003568 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003569 } else {
3570 if (ha->iobase)
3571 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003573 if (ha->cregbase)
3574 iounmap(ha->cregbase);
3575
Giridhar Malavalia9083012010-04-12 17:59:55 -07003576 if (ha->mqiobase)
3577 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003578
Chad Dupuisf73cb692014-02-26 04:15:06 -05003579 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003580 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003581 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003582}
3583
3584static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003585qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003586{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003587 if (IS_QLA8044(ha)) {
3588 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003589 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003590 qla8044_idc_unlock(ha);
3591 } else if (IS_QLA82XX(ha)) {
3592 qla82xx_idc_lock(ha);
3593 qla82xx_clear_drv_active(ha);
3594 qla82xx_idc_unlock(ha);
3595 }
3596}
3597
3598static void
3599qla2x00_remove_one(struct pci_dev *pdev)
3600{
3601 scsi_qla_host_t *base_vha;
3602 struct qla_hw_data *ha;
3603
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003604 base_vha = pci_get_drvdata(pdev);
3605 ha = base_vha->hw;
3606
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003607 /* Indicate device removal to prevent future board_disable and wait
3608 * until any pending board_disable has completed. */
3609 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3610 cancel_work_sync(&ha->board_disable);
3611
3612 /*
3613 * If the PCI device is disabled then there was a PCI-disconnect and
3614 * qla2x00_disable_board_on_pci_error has taken care of most of the
3615 * resources.
3616 */
3617 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003618 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3619 base_vha->gnl.l, base_vha->gnl.ldma);
3620
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003621 scsi_host_put(base_vha->host);
3622 kfree(ha);
3623 pci_set_drvdata(pdev, NULL);
3624 return;
3625 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003626 qla2x00_wait_for_hba_ready(base_vha);
3627
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003628 qla2x00_wait_for_sess_deletion(base_vha);
3629
Quinn Tran726b8542017-01-19 22:28:00 -08003630 /*
3631 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003632 * where it was set first.
3633 */
3634 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3635 return;
3636
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003637 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003638
3639 qla_nvme_delete(base_vha);
3640
Quinn Tran726b8542017-01-19 22:28:00 -08003641 dma_free_coherent(&ha->pdev->dev,
3642 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003643
Quinn Trana4239942017-12-28 12:33:26 -08003644 vfree(base_vha->scan.l);
3645
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003646 if (IS_QLAFX00(ha))
3647 qlafx00_driver_shutdown(base_vha, 20);
3648
3649 qla2x00_delete_all_vps(ha, base_vha);
3650
3651 if (IS_QLA8031(ha)) {
3652 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3653 "Clearing fcoe driver presence.\n");
3654 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3655 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3656 "Error while clearing DRV-Presence.\n");
3657 }
3658
3659 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3660
3661 qla2x00_dfs_remove(base_vha);
3662
3663 qla84xx_put_chip(base_vha);
3664
3665 /* Disable timer */
3666 if (base_vha->timer_active)
3667 qla2x00_stop_timer(base_vha);
3668
3669 base_vha->flags.online = 0;
3670
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003671 /* free DMA memory */
3672 if (ha->exlogin_buf)
3673 qla2x00_free_exlogin_buffer(ha);
3674
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003675 /* free DMA memory */
3676 if (ha->exchoffld_buf)
3677 qla2x00_free_exchoffld_buffer(ha);
3678
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003679 qla2x00_destroy_deferred_work(ha);
3680
3681 qlt_remove_target(ha, base_vha);
3682
3683 qla2x00_free_sysfs_attr(base_vha, true);
3684
3685 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003686 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003687
3688 scsi_remove_host(base_vha->host);
3689
3690 qla2x00_free_device(base_vha);
3691
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003692 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003693
Arun Easid2749ff2014-09-25 05:16:51 -04003694 scsi_host_put(base_vha->host);
3695
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003696 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003698 pci_release_selected_regions(ha->pdev, ha->bars);
3699 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003701 pci_disable_pcie_error_reporting(pdev);
3702
Bernhard Walle665db932007-03-28 00:49:49 +02003703 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
3706static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003707qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003709 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710
Andrew Vasquez85880802009-12-15 21:29:46 -08003711 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3712
3713 /* Disable timer */
3714 if (vha->timer_active)
3715 qla2x00_stop_timer(vha);
3716
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003717 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003718
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003719 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003721
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003722 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003723 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003724
Quinn Tran3407fc32017-12-28 12:33:11 -08003725 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3726 if (ha->flags.fw_started)
3727 qla2x00_abort_isp_cleanup(vha);
3728 } else {
3729 if (ha->flags.fw_started) {
3730 /* Stop currently executing firmware. */
3731 qla2x00_try_to_stop_firmware(vha);
3732 ha->flags.fw_started = 0;
3733 }
3734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
Andrew Vasquez85880802009-12-15 21:29:46 -08003736 vha->flags.online = 0;
3737
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003738 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003739 if (ha->interrupts_on) {
3740 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003741 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003742 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003743
Quinn Tran093df732016-12-12 14:40:09 -08003744 qla2x00_free_fcports(vha);
3745
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003746 qla2x00_free_irqs(vha);
3747
Quinn Tran093df732016-12-12 14:40:09 -08003748 /* Flush the work queue and remove it */
3749 if (ha->wq) {
3750 flush_workqueue(ha->wq);
3751 destroy_workqueue(ha->wq);
3752 ha->wq = NULL;
3753 }
3754
Chad Dupuis88670482010-07-23 15:28:30 +05003755
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003756 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003757
Giridhar Malavali08de2842011-08-16 11:31:44 -07003758 qla82xx_md_free(vha);
3759
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003760 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761}
3762
Chad Dupuis88670482010-07-23 15:28:30 +05003763void qla2x00_free_fcports(struct scsi_qla_host *vha)
3764{
3765 fc_port_t *fcport, *tfcport;
3766
3767 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3768 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003769 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003770 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003771 }
3772}
3773
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003774static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003775qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003776 int defer)
3777{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003778 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003779 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003780 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003781
3782 if (!fcport->rport)
3783 return;
3784
3785 rport = fcport->rport;
3786 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003787 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003788 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003789 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003790 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003791 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003792 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3793 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003794 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003795 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003796 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003797 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3798 "%s %8phN. rport %p roles %x\n",
3799 __func__, fcport->port_name, rport,
3800 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003801 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003802 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003803 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003804 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003805}
3806
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3809 *
3810 * Input: ha = adapter block pointer. fcport = port structure pointer.
3811 *
3812 * Return: None.
3813 *
3814 * Context:
3815 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003817 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003819 if (IS_QLAFX00(vha->hw)) {
3820 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3821 qla2x00_schedule_rport_del(vha, fcport, defer);
3822 return;
3823 }
3824
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003825 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003826 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003827 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828 qla2x00_schedule_rport_del(vha, fcport, defer);
3829 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003830 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 * We may need to retry the login, so don't change the state of the
3832 * port but do the retries.
3833 */
3834 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003835 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836
3837 if (!do_login)
3838 return;
3839
Arun Easia1d02852015-08-04 13:38:02 -04003840 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3841
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003843 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844
Quinn Tran83548fe2017-06-02 09:12:01 -07003845 ql_dbg(ql_dbg_disc, vha, 0x20a3,
Quinn Tran726b8542017-01-19 22:28:00 -08003846 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003847 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 }
3849}
3850
3851/*
3852 * qla2x00_mark_all_devices_lost
3853 * Updates fcport state when device goes offline.
3854 *
3855 * Input:
3856 * ha = adapter block pointer.
3857 * fcport = port structure pointer.
3858 *
3859 * Return:
3860 * None.
3861 *
3862 * Context:
3863 */
3864void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866{
3867 fc_port_t *fcport;
3868
Quinn Tran83548fe2017-06-02 09:12:01 -07003869 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3870 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003873 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003874 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003875
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003876 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003878
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 /*
3880 * No point in marking the device as lost, if the device is
3881 * already DEAD.
3882 */
3883 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3884 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003885 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003886 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003887 if (defer)
3888 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003889 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003890 qla2x00_schedule_rport_del(vha, fcport, defer);
3891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 }
3893}
3894
3895/*
3896* qla2x00_mem_alloc
3897* Allocates adapter memory.
3898*
3899* Returns:
3900* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003901* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003903static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003904qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3905 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906{
3907 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
Andrew Vasqueze8711082008-01-31 12:33:48 -08003909 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003910 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003911 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003914 if (qlt_mem_alloc(ha) < 0)
3915 goto fail_free_init_cb;
3916
Chad Dupuis642ef982012-02-09 11:15:57 -08003917 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3918 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003919 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003920 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921
Andrew Vasqueze8711082008-01-31 12:33:48 -08003922 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3923 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003924 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003926 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003927 /* Allocate cache for CT6 Ctx. */
3928 if (!ctx_cachep) {
3929 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3930 sizeof(struct ct6_dsd), 0,
3931 SLAB_HWCACHE_ALIGN, NULL);
3932 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003933 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003934 }
3935 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3936 ctx_cachep);
3937 if (!ha->ctx_mempool)
3938 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003939 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3940 "ctx_cachep=%p ctx_mempool=%p.\n",
3941 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003942 }
3943
Andrew Vasqueze8711082008-01-31 12:33:48 -08003944 /* Get memory for cached NVRAM */
3945 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3946 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003947 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003949 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3950 ha->pdev->device);
3951 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3952 DMA_POOL_SIZE, 8, 0);
3953 if (!ha->s_dma_pool)
3954 goto fail_free_nvram;
3955
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003956 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3957 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3958 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3959
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003960 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003961 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3962 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3963 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003964 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3965 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003966 goto fail_s_dma_pool;
3967 }
3968
3969 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3970 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3971 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003972 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3973 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003974 goto fail_dl_dma_pool;
3975 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003976 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3977 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3978 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003979 }
3980
Andrew Vasqueze8711082008-01-31 12:33:48 -08003981 /* Allocate memory for SNS commands */
3982 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003984 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003985 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003986 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003987 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003988 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003989 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003990 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003991 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003992 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003993 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003994 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003995 goto fail_dma_pool;
3996 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003997 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003998 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003999 if (!ha->ct_sns)
4000 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004001 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4002 "ms_iocb=%p ct_sns=%p.\n",
4003 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 }
4005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004007 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4008 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004009 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4010 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004011 goto fail_req;
4012 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004013 (*req)->length = req_len;
4014 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4015 ((*req)->length + 1) * sizeof(request_t),
4016 &(*req)->dma, GFP_KERNEL);
4017 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004018 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4019 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 goto fail_req_ring;
4021 }
4022 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004023 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4024 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004025 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4026 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027 goto fail_rsp;
4028 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004029 (*rsp)->hw = ha;
4030 (*rsp)->length = rsp_len;
4031 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4032 ((*rsp)->length + 1) * sizeof(response_t),
4033 &(*rsp)->dma, GFP_KERNEL);
4034 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004035 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4036 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004037 goto fail_rsp_ring;
4038 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004039 (*req)->rsp = *rsp;
4040 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004041 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4042 "req=%p req->length=%d req->ring=%p rsp=%p "
4043 "rsp->length=%d rsp->ring=%p.\n",
4044 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4045 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004046 /* Allocate memory for NVRAM data for vports */
4047 if (ha->nvram_npiv_size) {
4048 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004049 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004050 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004051 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4052 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004053 goto fail_npiv_info;
4054 }
4055 } else
4056 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004058 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004059 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004060 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4061 &ha->ex_init_cb_dma);
4062 if (!ha->ex_init_cb)
4063 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004064 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4065 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004066 }
4067
Giridhar Malavalia9083012010-04-12 17:59:55 -07004068 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4069
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004070 /* Get consistent memory allocated for Async Port-Database. */
4071 if (!IS_FWI2_CAPABLE(ha)) {
4072 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4073 &ha->async_pd_dma);
4074 if (!ha->async_pd)
4075 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004076 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4077 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004078 }
4079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004080 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004081
4082 /* Allocate memory for our loop_id bitmap */
4083 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
4084 GFP_KERNEL);
4085 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004086 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004087 else {
4088 qla2x00_set_reserved_loop_ids(ha);
4089 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004090 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004091 }
4092
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004093 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4094 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4095 if (!ha->sfp_data) {
4096 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4097 "Unable to allocate memory for SFP read-data.\n");
4098 goto fail_sfp_data;
4099 }
4100
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004101 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004102
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004103fail_sfp_data:
4104 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004105fail_loop_id_map:
4106 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004107fail_async_pd:
4108 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004109fail_ex_init_cb:
4110 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004111fail_npiv_info:
4112 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4113 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4114 (*rsp)->ring = NULL;
4115 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004117 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004118 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004120 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4121 sizeof(request_t), (*req)->ring, (*req)->dma);
4122 (*req)->ring = NULL;
4123 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004124fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004125 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004126 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127fail_req:
4128 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4129 ha->ct_sns, ha->ct_sns_dma);
4130 ha->ct_sns = NULL;
4131 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004132fail_free_ms_iocb:
4133 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4134 ha->ms_iocb = NULL;
4135 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004136
4137 if (ha->sns_cmd)
4138 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4139 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004140fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004141 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004142 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4143 ha->fcp_cmnd_dma_pool = NULL;
4144 }
4145fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004146 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004147 dma_pool_destroy(ha->dl_dma_pool);
4148 ha->dl_dma_pool = NULL;
4149 }
4150fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151 dma_pool_destroy(ha->s_dma_pool);
4152 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004153fail_free_nvram:
4154 kfree(ha->nvram);
4155 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004156fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004157 if (ha->ctx_mempool)
4158 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004159 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004160fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004161 if (ha->srb_mempool)
4162 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004163 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004164fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004165 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4166 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004167 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004168 ha->gid_list = NULL;
4169 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004170fail_free_tgt_mem:
4171 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172fail_free_init_cb:
4173 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4174 ha->init_cb_dma);
4175 ha->init_cb = NULL;
4176 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004177fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004178 ql_log(ql_log_fatal, NULL, 0x0030,
4179 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004180 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181}
4182
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004183int
4184qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4185{
4186 int rval;
4187 uint16_t size, max_cnt, temp;
4188 struct qla_hw_data *ha = vha->hw;
4189
4190 /* Return if we don't need to alloacate any extended logins */
4191 if (!ql2xexlogins)
4192 return QLA_SUCCESS;
4193
Quinn Tran99e1b682017-06-02 09:12:03 -07004194 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4195 return QLA_SUCCESS;
4196
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004197 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4198 max_cnt = 0;
4199 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4200 if (rval != QLA_SUCCESS) {
4201 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4202 "Failed to get exlogin status.\n");
4203 return rval;
4204 }
4205
4206 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004207 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004208
Quinn Tran99e1b682017-06-02 09:12:03 -07004209 if (temp != ha->exlogin_size) {
4210 qla2x00_free_exlogin_buffer(ha);
4211 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004212
Quinn Tran99e1b682017-06-02 09:12:03 -07004213 ql_log(ql_log_info, vha, 0xd024,
4214 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4215 max_cnt, size, temp);
4216
4217 ql_log(ql_log_info, vha, 0xd025,
4218 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4219
4220 /* Get consistent memory for extended logins */
4221 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4222 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4223 if (!ha->exlogin_buf) {
4224 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004225 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004226 return -ENOMEM;
4227 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004228 }
4229
4230 /* Now configure the dma buffer */
4231 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4232 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004233 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004234 "Setup extended login buffer ****FAILED****.\n");
4235 qla2x00_free_exlogin_buffer(ha);
4236 }
4237
4238 return rval;
4239}
4240
4241/*
4242* qla2x00_free_exlogin_buffer
4243*
4244* Input:
4245* ha = adapter block pointer
4246*/
4247void
4248qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4249{
4250 if (ha->exlogin_buf) {
4251 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4252 ha->exlogin_buf, ha->exlogin_buf_dma);
4253 ha->exlogin_buf = NULL;
4254 ha->exlogin_size = 0;
4255 }
4256}
4257
Quinn Tran99e1b682017-06-02 09:12:03 -07004258static void
4259qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4260{
4261 u32 temp;
4262 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4263
Quinn Trand1e36352017-12-28 12:33:12 -08004264 if (max_cnt > vha->hw->max_exchg)
4265 max_cnt = vha->hw->max_exchg;
4266
Quinn Tran99e1b682017-06-02 09:12:03 -07004267 if (qla_ini_mode_enabled(vha)) {
4268 if (ql2xiniexchg > max_cnt)
4269 ql2xiniexchg = max_cnt;
4270
4271 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4272 *ret_cnt = ql2xiniexchg;
4273 } else if (qla_tgt_mode_enabled(vha)) {
4274 if (ql2xexchoffld > max_cnt)
4275 ql2xexchoffld = max_cnt;
4276
4277 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4278 *ret_cnt = ql2xexchoffld;
4279 } else if (qla_dual_mode_enabled(vha)) {
4280 temp = ql2xiniexchg + ql2xexchoffld;
4281 if (temp > max_cnt) {
4282 ql2xiniexchg -= (temp - max_cnt)/2;
4283 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4284 temp = max_cnt;
4285 }
4286
4287 if (temp > FW_DEF_EXCHANGES_CNT)
4288 *ret_cnt = temp;
4289 }
4290}
4291
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004292int
4293qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4294{
4295 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004296 u16 size, max_cnt;
4297 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004298 struct qla_hw_data *ha = vha->hw;
4299
Quinn Tran99e1b682017-06-02 09:12:03 -07004300 if (!ha->flags.exchoffld_enabled)
4301 return QLA_SUCCESS;
4302
4303 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004304 return QLA_SUCCESS;
4305
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004306 max_cnt = 0;
4307 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4308 if (rval != QLA_SUCCESS) {
4309 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4310 "Failed to get exlogin status.\n");
4311 return rval;
4312 }
4313
Quinn Trand1e36352017-12-28 12:33:12 -08004314 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4315 ql_log(ql_log_info, vha, 0xd014,
4316 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004317
Quinn Trand1e36352017-12-28 12:33:12 -08004318 totsz = actual_cnt * size;
4319
4320 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004321 qla2x00_free_exchoffld_buffer(ha);
Quinn Trand1e36352017-12-28 12:33:12 -08004322 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004323
Quinn Tran99e1b682017-06-02 09:12:03 -07004324 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004325 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4326 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004327
4328 ql_log(ql_log_info, vha, 0xd017,
4329 "Exchange Buffers requested size = 0x%x\n",
4330 ha->exchoffld_size);
4331
4332 /* Get consistent memory for extended logins */
4333 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4334 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4335 if (!ha->exchoffld_buf) {
4336 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004337 "Failed to allocate memory for Exchange Offload.\n");
4338
4339 if (ha->max_exchg >
4340 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4341 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4342 } else if (ha->max_exchg >
4343 (FW_DEF_EXCHANGES_CNT + 512)) {
4344 ha->max_exchg -= 512;
4345 } else {
4346 ha->flags.exchoffld_enabled = 0;
4347 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4348 "Disabling Exchange offload due to lack of memory\n");
4349 }
4350 ha->exchoffld_size = 0;
4351
Quinn Tran99e1b682017-06-02 09:12:03 -07004352 return -ENOMEM;
4353 }
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004354 }
4355
4356 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004357 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004358 if (rval) {
4359 ql_log(ql_log_fatal, vha, 0xd02e,
4360 "Setup exchange offload buffer ****FAILED****.\n");
4361 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004362 } else {
4363 /* re-adjust number of target exchange */
4364 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4365
4366 if (qla_ini_mode_enabled(vha))
4367 icb->exchange_count = 0;
4368 else
4369 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004370 }
4371
4372 return rval;
4373}
4374
4375/*
4376* qla2x00_free_exchoffld_buffer
4377*
4378* Input:
4379* ha = adapter block pointer
4380*/
4381void
4382qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4383{
4384 if (ha->exchoffld_buf) {
4385 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4386 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4387 ha->exchoffld_buf = NULL;
4388 ha->exchoffld_size = 0;
4389 }
4390}
4391
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004393* qla2x00_free_fw_dump
4394* Frees fw dump stuff.
4395*
4396* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004397* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004398*/
4399static void
4400qla2x00_free_fw_dump(struct qla_hw_data *ha)
4401{
4402 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004403 dma_free_coherent(&ha->pdev->dev,
4404 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004405
Chad Dupuisf73cb692014-02-26 04:15:06 -05004406 if (ha->eft)
4407 dma_free_coherent(&ha->pdev->dev,
4408 EFT_SIZE, ha->eft, ha->eft_dma);
4409
4410 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004411 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004412 if (ha->fw_dump_template)
4413 vfree(ha->fw_dump_template);
4414
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004415 ha->fce = NULL;
4416 ha->fce_dma = 0;
4417 ha->eft = NULL;
4418 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004419 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004420 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004421 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004422 ha->fw_dump = NULL;
4423 ha->fw_dump_len = 0;
4424 ha->fw_dump_template = NULL;
4425 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004426}
4427
4428/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429* qla2x00_mem_free
4430* Frees all adapter allocated memory.
4431*
4432* Input:
4433* ha = adapter block pointer.
4434*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004435static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004438 qla2x00_free_fw_dump(ha);
4439
Saurav Kashyap81178772012-08-22 14:21:04 -04004440 if (ha->mctp_dump)
4441 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4442 ha->mctp_dump_dma);
4443
Andrew Vasqueze8711082008-01-31 12:33:48 -08004444 if (ha->srb_mempool)
4445 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004447 if (ha->dcbx_tlv)
4448 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4449 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4450
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004451 if (ha->xgmac_data)
4452 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4453 ha->xgmac_data, ha->xgmac_data_dma);
4454
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 if (ha->sns_cmd)
4456 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004457 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458
4459 if (ha->ct_sns)
4460 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462
Andrew Vasquez88729e52006-06-23 16:10:50 -07004463 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004464 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4465 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004466
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 if (ha->ms_iocb)
4468 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4469
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004470 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004471 dma_pool_free(ha->s_dma_pool,
4472 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004473
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004474 if (ha->async_pd)
4475 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4476
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 if (ha->s_dma_pool)
4478 dma_pool_destroy(ha->s_dma_pool);
4479
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004481 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4482 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483
Giridhar Malavalia9083012010-04-12 17:59:55 -07004484 if (IS_QLA82XX(ha)) {
4485 if (!list_empty(&ha->gbl_dsd_list)) {
4486 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4487
4488 /* clean up allocated prev pool */
4489 list_for_each_entry_safe(dsd_ptr,
4490 tdsd_ptr, &ha->gbl_dsd_list, list) {
4491 dma_pool_free(ha->dl_dma_pool,
4492 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4493 list_del(&dsd_ptr->list);
4494 kfree(dsd_ptr);
4495 }
4496 }
4497 }
4498
4499 if (ha->dl_dma_pool)
4500 dma_pool_destroy(ha->dl_dma_pool);
4501
4502 if (ha->fcp_cmnd_dma_pool)
4503 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4504
4505 if (ha->ctx_mempool)
4506 mempool_destroy(ha->ctx_mempool);
4507
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004508 qlt_mem_free(ha);
4509
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004510 if (ha->init_cb)
4511 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004512 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004513
Bill Kuzeja6d634062018-03-23 10:37:25 -04004514 vfree(ha->optrom_buffer);
4515 kfree(ha->nvram);
4516 kfree(ha->npiv_info);
4517 kfree(ha->swl);
4518 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519
Andrew Vasqueze8711082008-01-31 12:33:48 -08004520 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004521 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 ha->sns_cmd = NULL;
4523 ha->sns_cmd_dma = 0;
4524 ha->ct_sns = NULL;
4525 ha->ct_sns_dma = 0;
4526 ha->ms_iocb = NULL;
4527 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 ha->init_cb = NULL;
4529 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004530 ha->ex_init_cb = NULL;
4531 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004532 ha->async_pd = NULL;
4533 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004534 ha->loop_id_map = NULL;
4535 ha->npiv_info = NULL;
4536 ha->optrom_buffer = NULL;
4537 ha->swl = NULL;
4538 ha->nvram = NULL;
4539 ha->mctp_dump = NULL;
4540 ha->dcbx_tlv = NULL;
4541 ha->xgmac_data = NULL;
4542 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543
4544 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004545 ha->dl_dma_pool = NULL;
4546 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 ha->gid_list = NULL;
4549 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004550
4551 ha->tgt.atio_ring = NULL;
4552 ha->tgt.atio_dma = 0;
4553 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004554}
4555
4556struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4557 struct qla_hw_data *ha)
4558{
4559 struct Scsi_Host *host;
4560 struct scsi_qla_host *vha = NULL;
4561
4562 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004563 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004564 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4565 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004566 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004567 }
4568
4569 /* Clear our data area */
4570 vha = shost_priv(host);
4571 memset(vha, 0, sizeof(scsi_qla_host_t));
4572
4573 vha->host = host;
4574 vha->host_no = host->host_no;
4575 vha->hw = ha;
4576
4577 INIT_LIST_HEAD(&vha->vp_fcports);
4578 INIT_LIST_HEAD(&vha->work_list);
4579 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004580 INIT_LIST_HEAD(&vha->qla_cmd_list);
4581 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004582 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004583 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004584 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004585 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004586 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004587 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004588 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004589
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004590 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004591 spin_lock_init(&vha->cmd_list_lock);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004592 spin_lock_init(&vha->gnl.fcports_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004593 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004594 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004595
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004596 vha->gnl.size = sizeof(struct get_name_list_extended) *
4597 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004598 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4599 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4600 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004601 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004602 "Alloc failed for name list.\n");
4603 scsi_remove_host(vha->host);
4604 return NULL;
4605 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004606
Quinn Trana4239942017-12-28 12:33:26 -08004607 /* todo: what about ext login? */
4608 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4609 vha->scan.l = vmalloc(vha->scan.size);
4610 if (!vha->scan.l) {
4611 ql_log(ql_log_fatal, vha, 0xd04a,
4612 "Alloc failed for scan database.\n");
4613 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4614 vha->gnl.l, vha->gnl.ldma);
4615 scsi_remove_host(vha->host);
4616 return NULL;
4617 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004618 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004619
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004620 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004621 ql_dbg(ql_dbg_init, vha, 0x0041,
4622 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4623 vha->host, vha->hw, vha,
4624 dev_name(&(ha->pdev->dev)));
4625
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004626 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627}
4628
Quinn Tran726b8542017-01-19 22:28:00 -08004629struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004630qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004631{
4632 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004633 uint8_t bail;
4634
4635 QLA_VHA_MARK_BUSY(vha, bail);
4636 if (bail)
4637 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004638
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004639 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004640 if (!e) {
4641 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004642 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004643 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004644
4645 INIT_LIST_HEAD(&e->list);
4646 e->type = type;
4647 e->flags = QLA_EVT_FLAG_FREE;
4648 return e;
4649}
4650
Quinn Tran726b8542017-01-19 22:28:00 -08004651int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004652qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004653{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004654 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004655 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004656
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004657 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004658 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004659
4660 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4661 q = true;
4662
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004663 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004664
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004665 if (q)
4666 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004667
Andrew Vasquez0971de72008-04-03 13:13:18 -07004668 return QLA_SUCCESS;
4669}
4670
4671int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004672qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004673 u32 data)
4674{
4675 struct qla_work_evt *e;
4676
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004677 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004678 if (!e)
4679 return QLA_FUNCTION_FAILED;
4680
4681 e->u.aen.code = code;
4682 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004683 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004684}
4685
Andrew Vasquez8a659572009-02-08 20:50:12 -08004686int
4687qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4688{
4689 struct qla_work_evt *e;
4690
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004691 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004692 if (!e)
4693 return QLA_FUNCTION_FAILED;
4694
4695 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004696 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004697}
4698
Andrew Vasquezac280b62009-08-20 11:06:05 -07004699#define qla2x00_post_async_work(name, type) \
4700int qla2x00_post_async_##name##_work( \
4701 struct scsi_qla_host *vha, \
4702 fc_port_t *fcport, uint16_t *data) \
4703{ \
4704 struct qla_work_evt *e; \
4705 \
4706 e = qla2x00_alloc_work(vha, type); \
4707 if (!e) \
4708 return QLA_FUNCTION_FAILED; \
4709 \
4710 e->u.logio.fcport = fcport; \
4711 if (data) { \
4712 e->u.logio.data[0] = data[0]; \
4713 e->u.logio.data[1] = data[1]; \
4714 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004715 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004716 return qla2x00_post_work(vha, e); \
4717}
4718
4719qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004720qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4721qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004722qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4723qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Quinn Tran11aea162017-12-28 12:33:20 -08004724qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4725qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004726
Andrew Vasquez3420d362009-10-13 15:16:45 -07004727int
4728qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4729{
4730 struct qla_work_evt *e;
4731
4732 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4733 if (!e)
4734 return QLA_FUNCTION_FAILED;
4735
4736 e->u.uevent.code = code;
4737 return qla2x00_post_work(vha, e);
4738}
4739
4740static void
4741qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4742{
4743 char event_string[40];
4744 char *envp[] = { event_string, NULL };
4745
4746 switch (code) {
4747 case QLA_UEVENT_CODE_FW_DUMP:
4748 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4749 vha->host_no);
4750 break;
4751 default:
4752 /* do nothing */
4753 break;
4754 }
4755 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4756}
4757
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004758int
4759qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4760 uint32_t *data, int cnt)
4761{
4762 struct qla_work_evt *e;
4763
4764 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4765 if (!e)
4766 return QLA_FUNCTION_FAILED;
4767
4768 e->u.aenfx.evtcode = evtcode;
4769 e->u.aenfx.count = cnt;
4770 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4771 return qla2x00_post_work(vha, e);
4772}
4773
Quinn Tran726b8542017-01-19 22:28:00 -08004774int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4775{
4776 struct qla_work_evt *e;
4777
4778 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4779 if (!e)
4780 return QLA_FUNCTION_FAILED;
4781
4782 e->u.fcport.fcport = fcport;
4783 return qla2x00_post_work(vha, e);
4784}
4785
4786static
4787void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4788{
4789 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07004790 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08004791 struct qlt_plogi_ack_t *pla =
4792 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07004793 uint8_t free_fcport = 0;
Quinn Trana4239942017-12-28 12:33:26 -08004794 u64 wwn;
Quinn Tran726b8542017-01-19 22:28:00 -08004795
Quinn Tran9cd883f2017-12-28 12:33:24 -08004796 ql_dbg(ql_dbg_disc, vha, 0xffff,
4797 "%s %d %8phC enter\n",
4798 __func__, __LINE__, e->u.new_sess.port_name);
4799
Quinn Tran726b8542017-01-19 22:28:00 -08004800 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4801 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4802 if (fcport) {
4803 fcport->d_id = e->u.new_sess.id;
4804 if (pla) {
4805 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004806 memcpy(fcport->node_name,
4807 pla->iocb.u.isp24.u.plogi.node_name,
4808 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08004809 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4810 /* we took an extra ref_count to prevent PLOGI ACK when
4811 * fcport/sess has not been created.
4812 */
4813 pla->ref_count--;
4814 }
4815 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07004816 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004817 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4818 if (fcport) {
4819 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08004820 fcport->flags |= FCF_FABRIC_DEVICE;
4821 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran33b28352018-03-20 23:09:40 -07004822 if (e->u.new_sess.fc4_type & FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08004823 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08004824
Quinn Tran33b28352018-03-20 23:09:40 -07004825 if (e->u.new_sess.fc4_type & FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08004826 fcport->fc4_type = FC4_TYPE_OTHER;
4827 fcport->fc4f_nvme = FC4_TYPE_NVME;
4828 }
Quinn Tran33b28352018-03-20 23:09:40 -07004829
Quinn Tran726b8542017-01-19 22:28:00 -08004830 memcpy(fcport->port_name, e->u.new_sess.port_name,
4831 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07004832 } else {
4833 ql_dbg(ql_dbg_disc, vha, 0xffff,
4834 "%s %8phC mem alloc fail.\n",
4835 __func__, e->u.new_sess.port_name);
4836
4837 if (pla)
4838 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4839 return;
4840 }
4841
4842 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004843 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07004844 tfcp = qla2x00_find_fcport_by_wwpn(vha,
4845 e->u.new_sess.port_name, 1);
4846 if (tfcp) {
4847 /* should rarily happen */
4848 ql_dbg(ql_dbg_disc, vha, 0xffff,
4849 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
4850 __func__, tfcp->port_name, tfcp->disc_state,
4851 tfcp->fw_login_state);
4852
4853 free_fcport = 1;
4854 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08004855 list_add_tail(&fcport->list, &vha->vp_fcports);
4856
Quinn Tran19759032017-12-04 14:45:15 -08004857 }
4858 if (pla) {
4859 qlt_plogi_ack_link(vha, pla, fcport,
4860 QLT_PLOGI_LINK_SAME_WWN);
4861 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08004862 }
4863 }
4864 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4865
4866 if (fcport) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004867 if (N2N_TOPO(vha->hw))
4868 fcport->flags &= ~FCF_FABRIC_DEVICE;
4869
Quinn Trana4239942017-12-28 12:33:26 -08004870 fcport->id_changed = 1;
4871 fcport->scan_state = QLA_FCPORT_FOUND;
4872 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
4873
Quinn Tran5ef696a2017-12-04 14:45:05 -08004874 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004875 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
4876 u16 wd3_lo;
4877
4878 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4879 fcport->local = 0;
4880 fcport->loop_id =
4881 le16_to_cpu(
4882 pla->iocb.u.isp24.nport_handle);
4883 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4884 wd3_lo =
4885 le16_to_cpu(
4886 pla->iocb.u.isp24.u.prli.wd3_lo);
4887
4888 if (wd3_lo & BIT_7)
4889 fcport->conf_compl_supported = 1;
4890
4891 if ((wd3_lo & BIT_4) == 0)
4892 fcport->port_type = FCT_INITIATOR;
4893 else
4894 fcport->port_type = FCT_TARGET;
4895 }
Quinn Tran726b8542017-01-19 22:28:00 -08004896 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004897 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004898 fc_port_t *dfcp = NULL;
4899
Quinn Tran5ef696a2017-12-04 14:45:05 -08004900 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4901 tfcp = qla2x00_find_fcport_by_nportid(vha,
4902 &e->u.new_sess.id, 1);
4903 if (tfcp && (tfcp != fcport)) {
4904 /*
4905 * We have a conflict fcport with same NportID.
4906 */
4907 ql_dbg(ql_dbg_disc, vha, 0xffff,
4908 "%s %8phC found conflict b4 add. DS %d LS %d\n",
4909 __func__, tfcp->port_name, tfcp->disc_state,
4910 tfcp->fw_login_state);
4911
4912 switch (tfcp->disc_state) {
4913 case DSC_DELETED:
4914 break;
4915 case DSC_DELETE_PEND:
4916 fcport->login_pause = 1;
4917 tfcp->conflict = fcport;
4918 break;
4919 default:
4920 fcport->login_pause = 1;
4921 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004922 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08004923 break;
4924 }
4925 }
4926 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004927 if (dfcp)
4928 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08004929
4930 wwn = wwn_to_u64(fcport->node_name);
4931
4932 if (!wwn)
4933 qla24xx_async_gnnid(vha, fcport);
4934 else
4935 qla24xx_async_gnl(vha, fcport);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004936 }
Quinn Tran726b8542017-01-19 22:28:00 -08004937 }
Quinn Tranb5d15312017-08-30 10:16:49 -07004938
4939 if (free_fcport) {
4940 qla2x00_free_fcport(fcport);
4941 if (pla)
4942 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4943 }
Quinn Tran726b8542017-01-19 22:28:00 -08004944}
4945
Quinn Trane374f9f2017-12-28 12:33:31 -08004946static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
4947{
4948 struct srb *sp = e->u.iosb.sp;
4949 int rval;
4950
4951 rval = qla2x00_start_sp(sp);
4952 if (rval != QLA_SUCCESS) {
4953 ql_dbg(ql_dbg_disc, vha, 0x2043,
4954 "%s: %s: Re-issue IOCB failed (%d).\n",
4955 __func__, sp->name, rval);
4956 qla24xx_sp_unmap(vha, sp);
4957 }
4958}
4959
Andrew Vasquezac280b62009-08-20 11:06:05 -07004960void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004961qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004962{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004963 struct qla_work_evt *e, *tmp;
4964 unsigned long flags;
4965 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004966
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004967 spin_lock_irqsave(&vha->work_lock, flags);
4968 list_splice_init(&vha->work_list, &work);
4969 spin_unlock_irqrestore(&vha->work_lock, flags);
4970
4971 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004972 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004973
4974 switch (e->type) {
4975 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004976 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004977 e->u.aen.code, e->u.aen.data);
4978 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004979 case QLA_EVT_IDC_ACK:
4980 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4981 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004982 case QLA_EVT_ASYNC_LOGIN:
4983 qla2x00_async_login(vha, e->u.logio.fcport,
4984 e->u.logio.data);
4985 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004986 case QLA_EVT_ASYNC_LOGOUT:
4987 qla2x00_async_logout(vha, e->u.logio.fcport);
4988 break;
4989 case QLA_EVT_ASYNC_LOGOUT_DONE:
4990 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4991 e->u.logio.data);
4992 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004993 case QLA_EVT_ASYNC_ADISC:
4994 qla2x00_async_adisc(vha, e->u.logio.fcport,
4995 e->u.logio.data);
4996 break;
4997 case QLA_EVT_ASYNC_ADISC_DONE:
4998 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4999 e->u.logio.data);
5000 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005001 case QLA_EVT_UEVENT:
5002 qla2x00_uevent_emit(vha, e->u.uevent.code);
5003 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005004 case QLA_EVT_AENFX:
5005 qlafx00_process_aen(vha, e);
5006 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005007 case QLA_EVT_GIDPN:
5008 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
5009 break;
5010 case QLA_EVT_GPNID:
5011 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5012 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005013 case QLA_EVT_UNMAP:
5014 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005015 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005016 case QLA_EVT_RELOGIN:
5017 qla2x00_relogin(vha);
5018 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005019 case QLA_EVT_NEW_SESS:
5020 qla24xx_create_new_sess(vha, e);
5021 break;
5022 case QLA_EVT_GPDB:
5023 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5024 e->u.fcport.opt);
5025 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005026 case QLA_EVT_PRLI:
5027 qla24xx_async_prli(vha, e->u.fcport.fcport);
5028 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005029 case QLA_EVT_GPSC:
5030 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5031 break;
5032 case QLA_EVT_UPD_FCPORT:
5033 qla2x00_update_fcport(vha, e->u.fcport.fcport);
5034 break;
5035 case QLA_EVT_GNL:
5036 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5037 break;
5038 case QLA_EVT_NACK:
5039 qla24xx_do_nack_work(vha, e);
5040 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005041 case QLA_EVT_ASYNC_PRLO:
5042 qla2x00_async_prlo(vha, e->u.logio.fcport);
5043 break;
5044 case QLA_EVT_ASYNC_PRLO_DONE:
5045 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5046 e->u.logio.data);
5047 break;
Quinn Trana4239942017-12-28 12:33:26 -08005048 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005049 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5050 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005051 break;
5052 case QLA_EVT_GPNFT_DONE:
5053 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5054 break;
5055 case QLA_EVT_GNNFT_DONE:
5056 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5057 break;
5058 case QLA_EVT_GNNID:
5059 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5060 break;
5061 case QLA_EVT_GFPNID:
5062 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5063 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005064 case QLA_EVT_SP_RETRY:
5065 qla_sp_retry(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005066 }
5067 if (e->flags & QLA_EVT_FLAG_FREE)
5068 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005069
5070 /* For each work completed decrement vha ref count */
5071 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005072 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005073}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005074
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005075int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5076{
5077 struct qla_work_evt *e;
5078
5079 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5080
5081 if (!e) {
5082 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5083 return QLA_FUNCTION_FAILED;
5084 }
5085
5086 return qla2x00_post_work(vha, e);
5087}
5088
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005089/* Relogins all the fcports of a vport
5090 * Context: dpc thread
5091 */
5092void qla2x00_relogin(struct scsi_qla_host *vha)
5093{
5094 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08005095 int status;
Quinn Tran726b8542017-01-19 22:28:00 -08005096 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005097
5098 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005099 /*
5100 * If the port is not ONLINE then try to login
5101 * to it if we haven't run out of retries.
5102 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005103 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran6d6749272017-12-28 12:33:41 -08005104 fcport->login_retry &&
5105 !(fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE))) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005106 if (vha->hw->current_topology != ISP_CFG_NL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005107 ql_dbg(ql_dbg_disc, fcport->vha, 0x2108,
Quinn Tran726b8542017-01-19 22:28:00 -08005108 "%s %8phC DS %d LS %d\n", __func__,
5109 fcport->port_name, fcport->disc_state,
5110 fcport->fw_login_state);
5111 memset(&ea, 0, sizeof(ea));
5112 ea.event = FCME_RELOGIN;
5113 ea.fcport = fcport;
5114 qla2x00_fcport_event_handler(vha, &ea);
Quinn Tran9cd883f2017-12-28 12:33:24 -08005115 } else if (vha->hw->current_topology == ISP_CFG_NL) {
Quinn Tran4005a992017-12-04 14:45:06 -08005116 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005117 status = qla2x00_local_device_login(vha,
5118 fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08005119 if (status == QLA_SUCCESS) {
5120 fcport->old_loop_id = fcport->loop_id;
5121 ql_dbg(ql_dbg_disc, vha, 0x2003,
5122 "Port login OK: logged in ID 0x%x.\n",
5123 fcport->loop_id);
5124 qla2x00_update_fcport(vha, fcport);
5125 } else if (status == 1) {
5126 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5127 /* retry the login again */
5128 ql_dbg(ql_dbg_disc, vha, 0x2007,
5129 "Retrying %d login again loop_id 0x%x.\n",
5130 fcport->login_retry,
5131 fcport->loop_id);
5132 } else {
5133 fcport->login_retry = 0;
5134 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005135
Quinn Tran726b8542017-01-19 22:28:00 -08005136 if (fcport->login_retry == 0 &&
5137 status != QLA_SUCCESS)
5138 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005139 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005140 }
5141 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5142 break;
5143 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005144
5145 ql_dbg(ql_dbg_disc, vha, 0x400e,
5146 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005147}
5148
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005149/* Schedule work on any of the dpc-workqueues */
5150void
5151qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5152{
5153 struct qla_hw_data *ha = base_vha->hw;
5154
5155 switch (work_code) {
5156 case MBA_IDC_AEN: /* 0x8200 */
5157 if (ha->dpc_lp_wq)
5158 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5159 break;
5160
5161 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5162 if (!ha->flags.nic_core_reset_hdlr_active) {
5163 if (ha->dpc_hp_wq)
5164 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5165 } else
5166 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5167 "NIC Core reset is already active. Skip "
5168 "scheduling it again.\n");
5169 break;
5170 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5171 if (ha->dpc_hp_wq)
5172 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5173 break;
5174 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5175 if (ha->dpc_hp_wq)
5176 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5177 break;
5178 default:
5179 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005180 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005181 }
5182
5183 return;
5184}
5185
5186/* Work: Perform NIC Core Unrecoverable state handling */
5187void
5188qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5189{
5190 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005191 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005192 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5193 uint32_t dev_state = 0;
5194
5195 qla83xx_idc_lock(base_vha, 0);
5196 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5197 qla83xx_reset_ownership(base_vha);
5198 if (ha->flags.nic_core_reset_owner) {
5199 ha->flags.nic_core_reset_owner = 0;
5200 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5201 QLA8XXX_DEV_FAILED);
5202 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5203 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5204 }
5205 qla83xx_idc_unlock(base_vha, 0);
5206}
5207
5208/* Work: Execute IDC state handler */
5209void
5210qla83xx_idc_state_handler_work(struct work_struct *work)
5211{
5212 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005213 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005214 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5215 uint32_t dev_state = 0;
5216
5217 qla83xx_idc_lock(base_vha, 0);
5218 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5219 if (dev_state == QLA8XXX_DEV_FAILED ||
5220 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5221 qla83xx_idc_state_handler(base_vha);
5222 qla83xx_idc_unlock(base_vha, 0);
5223}
5224
Saurav Kashyapfa492632012-11-21 02:40:29 -05005225static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005226qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5227{
5228 int rval = QLA_SUCCESS;
5229 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5230 uint32_t heart_beat_counter1, heart_beat_counter2;
5231
5232 do {
5233 if (time_after(jiffies, heart_beat_wait)) {
5234 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5235 "Nic Core f/w is not alive.\n");
5236 rval = QLA_FUNCTION_FAILED;
5237 break;
5238 }
5239
5240 qla83xx_idc_lock(base_vha, 0);
5241 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5242 &heart_beat_counter1);
5243 qla83xx_idc_unlock(base_vha, 0);
5244 msleep(100);
5245 qla83xx_idc_lock(base_vha, 0);
5246 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5247 &heart_beat_counter2);
5248 qla83xx_idc_unlock(base_vha, 0);
5249 } while (heart_beat_counter1 == heart_beat_counter2);
5250
5251 return rval;
5252}
5253
5254/* Work: Perform NIC Core Reset handling */
5255void
5256qla83xx_nic_core_reset_work(struct work_struct *work)
5257{
5258 struct qla_hw_data *ha =
5259 container_of(work, struct qla_hw_data, nic_core_reset);
5260 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5261 uint32_t dev_state = 0;
5262
Saurav Kashyap81178772012-08-22 14:21:04 -04005263 if (IS_QLA2031(ha)) {
5264 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5265 ql_log(ql_log_warn, base_vha, 0xb081,
5266 "Failed to dump mctp\n");
5267 return;
5268 }
5269
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005270 if (!ha->flags.nic_core_reset_hdlr_active) {
5271 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5272 qla83xx_idc_lock(base_vha, 0);
5273 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5274 &dev_state);
5275 qla83xx_idc_unlock(base_vha, 0);
5276 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5277 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5278 "Nic Core f/w is alive.\n");
5279 return;
5280 }
5281 }
5282
5283 ha->flags.nic_core_reset_hdlr_active = 1;
5284 if (qla83xx_nic_core_reset(base_vha)) {
5285 /* NIC Core reset failed. */
5286 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5287 "NIC Core reset failed.\n");
5288 }
5289 ha->flags.nic_core_reset_hdlr_active = 0;
5290 }
5291}
5292
5293/* Work: Handle 8200 IDC aens */
5294void
5295qla83xx_service_idc_aen(struct work_struct *work)
5296{
5297 struct qla_hw_data *ha =
5298 container_of(work, struct qla_hw_data, idc_aen);
5299 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5300 uint32_t dev_state, idc_control;
5301
5302 qla83xx_idc_lock(base_vha, 0);
5303 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5304 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5305 qla83xx_idc_unlock(base_vha, 0);
5306 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5307 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5308 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5309 "Application requested NIC Core Reset.\n");
5310 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5311 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5312 QLA_SUCCESS) {
5313 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5314 "Other protocol driver requested NIC Core Reset.\n");
5315 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5316 }
5317 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5318 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5319 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5320 }
5321}
5322
5323static void
5324qla83xx_wait_logic(void)
5325{
5326 int i;
5327
5328 /* Yield CPU */
5329 if (!in_interrupt()) {
5330 /*
5331 * Wait about 200ms before retrying again.
5332 * This controls the number of retries for single
5333 * lock operation.
5334 */
5335 msleep(100);
5336 schedule();
5337 } else {
5338 for (i = 0; i < 20; i++)
5339 cpu_relax(); /* This a nop instr on i386 */
5340 }
5341}
5342
Saurav Kashyapfa492632012-11-21 02:40:29 -05005343static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005344qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5345{
5346 int rval;
5347 uint32_t data;
5348 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5349 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5350 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005351 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5352 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005353
5354 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5355 if (rval)
5356 return rval;
5357
5358 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5359 return QLA_SUCCESS;
5360 } else {
5361 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5362 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5363 data);
5364 if (rval)
5365 return rval;
5366
5367 msleep(200);
5368
5369 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5370 &data);
5371 if (rval)
5372 return rval;
5373
5374 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5375 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5376 ~(idc_lck_rcvry_stage_mask));
5377 rval = qla83xx_wr_reg(base_vha,
5378 QLA83XX_IDC_LOCK_RECOVERY, data);
5379 if (rval)
5380 return rval;
5381
5382 /* Forcefully perform IDC UnLock */
5383 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5384 &data);
5385 if (rval)
5386 return rval;
5387 /* Clear lock-id by setting 0xff */
5388 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5389 0xff);
5390 if (rval)
5391 return rval;
5392 /* Clear lock-recovery by setting 0x0 */
5393 rval = qla83xx_wr_reg(base_vha,
5394 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5395 if (rval)
5396 return rval;
5397 } else
5398 return QLA_SUCCESS;
5399 }
5400
5401 return rval;
5402}
5403
Saurav Kashyapfa492632012-11-21 02:40:29 -05005404static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005405qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5406{
5407 int rval = QLA_SUCCESS;
5408 uint32_t o_drv_lockid, n_drv_lockid;
5409 unsigned long lock_recovery_timeout;
5410
5411 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5412retry_lockid:
5413 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5414 if (rval)
5415 goto exit;
5416
5417 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5418 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5419 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5420 return QLA_SUCCESS;
5421 else
5422 return QLA_FUNCTION_FAILED;
5423 }
5424
5425 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5426 if (rval)
5427 goto exit;
5428
5429 if (o_drv_lockid == n_drv_lockid) {
5430 qla83xx_wait_logic();
5431 goto retry_lockid;
5432 } else
5433 return QLA_SUCCESS;
5434
5435exit:
5436 return rval;
5437}
5438
5439void
5440qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5441{
5442 uint16_t options = (requester_id << 15) | BIT_6;
5443 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005444 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005445 struct qla_hw_data *ha = base_vha->hw;
5446
5447 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5448retry_lock:
5449 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5450 == QLA_SUCCESS) {
5451 if (data) {
5452 /* Setting lock-id to our function-number */
5453 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5454 ha->portnum);
5455 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005456 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5457 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005458 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005459 "Failed to acquire IDC lock, acquired by %d, "
5460 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005461
5462 /* Retry/Perform IDC-Lock recovery */
5463 if (qla83xx_idc_lock_recovery(base_vha)
5464 == QLA_SUCCESS) {
5465 qla83xx_wait_logic();
5466 goto retry_lock;
5467 } else
5468 ql_log(ql_log_warn, base_vha, 0xb075,
5469 "IDC Lock recovery FAILED.\n");
5470 }
5471
5472 }
5473
5474 return;
5475
5476 /* XXX: IDC-lock implementation using access-control mbx */
5477retry_lock2:
5478 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5479 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5480 "Failed to acquire IDC lock. retrying...\n");
5481 /* Retry/Perform IDC-Lock recovery */
5482 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5483 qla83xx_wait_logic();
5484 goto retry_lock2;
5485 } else
5486 ql_log(ql_log_warn, base_vha, 0xb076,
5487 "IDC Lock recovery FAILED.\n");
5488 }
5489
5490 return;
5491}
5492
5493void
5494qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5495{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005496#if 0
5497 uint16_t options = (requester_id << 15) | BIT_7;
5498#endif
5499 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005500 uint32_t data;
5501 struct qla_hw_data *ha = base_vha->hw;
5502
5503 /* IDC-unlock implementation using driver-unlock/lock-id
5504 * remote registers
5505 */
5506 retry = 0;
5507retry_unlock:
5508 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5509 == QLA_SUCCESS) {
5510 if (data == ha->portnum) {
5511 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5512 /* Clearing lock-id by setting 0xff */
5513 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5514 } else if (retry < 10) {
5515 /* SV: XXX: IDC unlock retrying needed here? */
5516
5517 /* Retry for IDC-unlock */
5518 qla83xx_wait_logic();
5519 retry++;
5520 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005521 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005522 goto retry_unlock;
5523 }
5524 } else if (retry < 10) {
5525 /* Retry for IDC-unlock */
5526 qla83xx_wait_logic();
5527 retry++;
5528 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005529 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005530 goto retry_unlock;
5531 }
5532
5533 return;
5534
Bart Van Assche5897cb22015-06-04 15:57:20 -07005535#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005536 /* XXX: IDC-unlock implementation using access-control mbx */
5537 retry = 0;
5538retry_unlock2:
5539 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5540 if (retry < 10) {
5541 /* Retry for IDC-unlock */
5542 qla83xx_wait_logic();
5543 retry++;
5544 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005545 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005546 goto retry_unlock2;
5547 }
5548 }
5549
5550 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005551#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005552}
5553
5554int
5555__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5556{
5557 int rval = QLA_SUCCESS;
5558 struct qla_hw_data *ha = vha->hw;
5559 uint32_t drv_presence;
5560
5561 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5562 if (rval == QLA_SUCCESS) {
5563 drv_presence |= (1 << ha->portnum);
5564 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5565 drv_presence);
5566 }
5567
5568 return rval;
5569}
5570
5571int
5572qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5573{
5574 int rval = QLA_SUCCESS;
5575
5576 qla83xx_idc_lock(vha, 0);
5577 rval = __qla83xx_set_drv_presence(vha);
5578 qla83xx_idc_unlock(vha, 0);
5579
5580 return rval;
5581}
5582
5583int
5584__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5585{
5586 int rval = QLA_SUCCESS;
5587 struct qla_hw_data *ha = vha->hw;
5588 uint32_t drv_presence;
5589
5590 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5591 if (rval == QLA_SUCCESS) {
5592 drv_presence &= ~(1 << ha->portnum);
5593 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5594 drv_presence);
5595 }
5596
5597 return rval;
5598}
5599
5600int
5601qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5602{
5603 int rval = QLA_SUCCESS;
5604
5605 qla83xx_idc_lock(vha, 0);
5606 rval = __qla83xx_clear_drv_presence(vha);
5607 qla83xx_idc_unlock(vha, 0);
5608
5609 return rval;
5610}
5611
Saurav Kashyapfa492632012-11-21 02:40:29 -05005612static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005613qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5614{
5615 struct qla_hw_data *ha = vha->hw;
5616 uint32_t drv_ack, drv_presence;
5617 unsigned long ack_timeout;
5618
5619 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5620 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5621 while (1) {
5622 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5623 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005624 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005625 break;
5626
5627 if (time_after_eq(jiffies, ack_timeout)) {
5628 ql_log(ql_log_warn, vha, 0xb067,
5629 "RESET ACK TIMEOUT! drv_presence=0x%x "
5630 "drv_ack=0x%x\n", drv_presence, drv_ack);
5631 /*
5632 * The function(s) which did not ack in time are forced
5633 * to withdraw any further participation in the IDC
5634 * reset.
5635 */
5636 if (drv_ack != drv_presence)
5637 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5638 drv_ack);
5639 break;
5640 }
5641
5642 qla83xx_idc_unlock(vha, 0);
5643 msleep(1000);
5644 qla83xx_idc_lock(vha, 0);
5645 }
5646
5647 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5648 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5649}
5650
Saurav Kashyapfa492632012-11-21 02:40:29 -05005651static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005652qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5653{
5654 int rval = QLA_SUCCESS;
5655 uint32_t idc_control;
5656
5657 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5658 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5659
5660 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5661 __qla83xx_get_idc_control(vha, &idc_control);
5662 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5663 __qla83xx_set_idc_control(vha, 0);
5664
5665 qla83xx_idc_unlock(vha, 0);
5666 rval = qla83xx_restart_nic_firmware(vha);
5667 qla83xx_idc_lock(vha, 0);
5668
5669 if (rval != QLA_SUCCESS) {
5670 ql_log(ql_log_fatal, vha, 0xb06a,
5671 "Failed to restart NIC f/w.\n");
5672 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5673 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5674 } else {
5675 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5676 "Success in restarting nic f/w.\n");
5677 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5678 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5679 }
5680
5681 return rval;
5682}
5683
5684/* Assumes idc_lock always held on entry */
5685int
5686qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5687{
5688 struct qla_hw_data *ha = base_vha->hw;
5689 int rval = QLA_SUCCESS;
5690 unsigned long dev_init_timeout;
5691 uint32_t dev_state;
5692
5693 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5694 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5695
5696 while (1) {
5697
5698 if (time_after_eq(jiffies, dev_init_timeout)) {
5699 ql_log(ql_log_warn, base_vha, 0xb06e,
5700 "Initialization TIMEOUT!\n");
5701 /* Init timeout. Disable further NIC Core
5702 * communication.
5703 */
5704 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5705 QLA8XXX_DEV_FAILED);
5706 ql_log(ql_log_info, base_vha, 0xb06f,
5707 "HW State: FAILED.\n");
5708 }
5709
5710 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5711 switch (dev_state) {
5712 case QLA8XXX_DEV_READY:
5713 if (ha->flags.nic_core_reset_owner)
5714 qla83xx_idc_audit(base_vha,
5715 IDC_AUDIT_COMPLETION);
5716 ha->flags.nic_core_reset_owner = 0;
5717 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5718 "Reset_owner reset by 0x%x.\n",
5719 ha->portnum);
5720 goto exit;
5721 case QLA8XXX_DEV_COLD:
5722 if (ha->flags.nic_core_reset_owner)
5723 rval = qla83xx_device_bootstrap(base_vha);
5724 else {
5725 /* Wait for AEN to change device-state */
5726 qla83xx_idc_unlock(base_vha, 0);
5727 msleep(1000);
5728 qla83xx_idc_lock(base_vha, 0);
5729 }
5730 break;
5731 case QLA8XXX_DEV_INITIALIZING:
5732 /* Wait for AEN to change device-state */
5733 qla83xx_idc_unlock(base_vha, 0);
5734 msleep(1000);
5735 qla83xx_idc_lock(base_vha, 0);
5736 break;
5737 case QLA8XXX_DEV_NEED_RESET:
5738 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5739 qla83xx_need_reset_handler(base_vha);
5740 else {
5741 /* Wait for AEN to change device-state */
5742 qla83xx_idc_unlock(base_vha, 0);
5743 msleep(1000);
5744 qla83xx_idc_lock(base_vha, 0);
5745 }
5746 /* reset timeout value after need reset handler */
5747 dev_init_timeout = jiffies +
5748 (ha->fcoe_dev_init_timeout * HZ);
5749 break;
5750 case QLA8XXX_DEV_NEED_QUIESCENT:
5751 /* XXX: DEBUG for now */
5752 qla83xx_idc_unlock(base_vha, 0);
5753 msleep(1000);
5754 qla83xx_idc_lock(base_vha, 0);
5755 break;
5756 case QLA8XXX_DEV_QUIESCENT:
5757 /* XXX: DEBUG for now */
5758 if (ha->flags.quiesce_owner)
5759 goto exit;
5760
5761 qla83xx_idc_unlock(base_vha, 0);
5762 msleep(1000);
5763 qla83xx_idc_lock(base_vha, 0);
5764 dev_init_timeout = jiffies +
5765 (ha->fcoe_dev_init_timeout * HZ);
5766 break;
5767 case QLA8XXX_DEV_FAILED:
5768 if (ha->flags.nic_core_reset_owner)
5769 qla83xx_idc_audit(base_vha,
5770 IDC_AUDIT_COMPLETION);
5771 ha->flags.nic_core_reset_owner = 0;
5772 __qla83xx_clear_drv_presence(base_vha);
5773 qla83xx_idc_unlock(base_vha, 0);
5774 qla8xxx_dev_failed_handler(base_vha);
5775 rval = QLA_FUNCTION_FAILED;
5776 qla83xx_idc_lock(base_vha, 0);
5777 goto exit;
5778 case QLA8XXX_BAD_VALUE:
5779 qla83xx_idc_unlock(base_vha, 0);
5780 msleep(1000);
5781 qla83xx_idc_lock(base_vha, 0);
5782 break;
5783 default:
5784 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005785 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005786 qla83xx_idc_unlock(base_vha, 0);
5787 qla8xxx_dev_failed_handler(base_vha);
5788 rval = QLA_FUNCTION_FAILED;
5789 qla83xx_idc_lock(base_vha, 0);
5790 goto exit;
5791 }
5792 }
5793
5794exit:
5795 return rval;
5796}
5797
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005798void
5799qla2x00_disable_board_on_pci_error(struct work_struct *work)
5800{
5801 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5802 board_disable);
5803 struct pci_dev *pdev = ha->pdev;
5804 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5805
Quinn Tran726b8542017-01-19 22:28:00 -08005806 /*
5807 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005808 * where it was set first.
5809 */
5810 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5811 return;
5812
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005813 ql_log(ql_log_warn, base_vha, 0x015b,
5814 "Disabling adapter.\n");
5815
Sawan Chandakefdb5762017-08-23 15:05:00 -07005816 if (!atomic_read(&pdev->enable_cnt)) {
5817 ql_log(ql_log_info, base_vha, 0xfffc,
5818 "PCI device disabled, no action req for PCI error=%lx\n",
5819 base_vha->pci_flags);
5820 return;
5821 }
5822
Quinn Tran726b8542017-01-19 22:28:00 -08005823 qla2x00_wait_for_sess_deletion(base_vha);
5824
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005825 set_bit(UNLOADING, &base_vha->dpc_flags);
5826
5827 qla2x00_delete_all_vps(ha, base_vha);
5828
5829 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5830
5831 qla2x00_dfs_remove(base_vha);
5832
5833 qla84xx_put_chip(base_vha);
5834
5835 if (base_vha->timer_active)
5836 qla2x00_stop_timer(base_vha);
5837
5838 base_vha->flags.online = 0;
5839
5840 qla2x00_destroy_deferred_work(ha);
5841
5842 /*
5843 * Do not try to stop beacon blink as it will issue a mailbox
5844 * command.
5845 */
5846 qla2x00_free_sysfs_attr(base_vha, false);
5847
5848 fc_remove_host(base_vha->host);
5849
5850 scsi_remove_host(base_vha->host);
5851
5852 base_vha->flags.init_done = 0;
5853 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005854 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005855 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005856 qla2x00_mem_free(ha);
5857 qla82xx_md_free(base_vha);
5858 qla2x00_free_queues(ha);
5859
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005860 qla2x00_unmap_iobases(ha);
5861
5862 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005863 pci_disable_pcie_error_reporting(pdev);
5864 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005865
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005866 /*
5867 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5868 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005869}
5870
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871/**************************************************************************
5872* qla2x00_do_dpc
5873* This kernel thread is a task that is schedule by the interrupt handler
5874* to perform the background processing for interrupts.
5875*
5876* Notes:
5877* This task always run in the context of a kernel thread. It
5878* is kick-off by the driver's detect code and starts up
5879* up one per adapter. It immediately goes to sleep and waits for
5880* some fibre event. When either the interrupt handler or
5881* the timer routine detects a event it will one of the task
5882* bits then wake us up.
5883**************************************************************************/
5884static int
5885qla2x00_do_dpc(void *data)
5886{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005887 scsi_qla_host_t *base_vha;
5888 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005889 uint32_t online;
5890 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005892 ha = (struct qla_hw_data *)data;
5893 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894
Dongsheng Yang8698a742014-03-11 18:09:12 +08005895 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896
James Bottomley563585e2011-01-27 16:12:37 -05005897 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005898 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005899 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5900 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901
Christoph Hellwig39a11242006-02-14 18:46:22 +01005902 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005904 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5905 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906
Andrew Vasquez85880802009-12-15 21:29:46 -08005907 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005908 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5909 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005910 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005911 }
5912
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913 ha->dpc_active = 1;
5914
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005915 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5916 "DPC handler waking up, dpc_flags=0x%lx.\n",
5917 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005919 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5920 break;
5921
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005922 if (IS_P3P_TYPE(ha)) {
5923 if (IS_QLA8044(ha)) {
5924 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5925 &base_vha->dpc_flags)) {
5926 qla8044_idc_lock(ha);
5927 qla8044_wr_direct(base_vha,
5928 QLA8044_CRB_DEV_STATE_INDEX,
5929 QLA8XXX_DEV_FAILED);
5930 qla8044_idc_unlock(ha);
5931 ql_log(ql_log_info, base_vha, 0x4004,
5932 "HW State: FAILED.\n");
5933 qla8044_device_state_handler(base_vha);
5934 continue;
5935 }
5936
5937 } else {
5938 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5939 &base_vha->dpc_flags)) {
5940 qla82xx_idc_lock(ha);
5941 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5942 QLA8XXX_DEV_FAILED);
5943 qla82xx_idc_unlock(ha);
5944 ql_log(ql_log_info, base_vha, 0x0151,
5945 "HW State: FAILED.\n");
5946 qla82xx_device_state_handler(base_vha);
5947 continue;
5948 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005949 }
5950
5951 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5952 &base_vha->dpc_flags)) {
5953
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005954 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5955 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005956 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5957 &base_vha->dpc_flags))) {
5958 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5959 /* FCoE-ctx reset failed.
5960 * Escalate to chip-reset
5961 */
5962 set_bit(ISP_ABORT_NEEDED,
5963 &base_vha->dpc_flags);
5964 }
5965 clear_bit(ABORT_ISP_ACTIVE,
5966 &base_vha->dpc_flags);
5967 }
5968
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005969 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5970 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005971 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005972 } else if (IS_QLAFX00(ha)) {
5973 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5974 &base_vha->dpc_flags)) {
5975 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5976 "Firmware Reset Recovery\n");
5977 if (qlafx00_reset_initialize(base_vha)) {
5978 /* Failed. Abort isp later. */
5979 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005980 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005981 set_bit(ISP_UNRECOVERABLE,
5982 &base_vha->dpc_flags);
5983 ql_dbg(ql_dbg_dpc, base_vha,
5984 0x4021,
5985 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005986 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005987 }
5988 }
5989
5990 if (test_and_clear_bit(FX00_TARGET_SCAN,
5991 &base_vha->dpc_flags)) {
5992 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5993 "ISPFx00 Target Scan scheduled\n");
5994 if (qlafx00_rescan_isp(base_vha)) {
5995 if (!test_bit(UNLOADING,
5996 &base_vha->dpc_flags))
5997 set_bit(ISP_UNRECOVERABLE,
5998 &base_vha->dpc_flags);
5999 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6000 "ISPFx00 Target Scan Failed\n");
6001 }
6002 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6003 "ISPFx00 Target Scan End\n");
6004 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006005 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6006 &base_vha->dpc_flags)) {
6007 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6008 "ISPFx00 Host Info resend scheduled\n");
6009 qlafx00_fx_disc(base_vha,
6010 &base_vha->hw->mr.fcport,
6011 FXDISC_REG_HOST_INFO);
6012 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006013 }
6014
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006015 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6016 &base_vha->dpc_flags) &&
6017 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6018 qla24xx_detect_sfp(base_vha);
6019
6020 if (ha->flags.detected_lr_sfp !=
6021 ha->flags.using_lr_setting)
6022 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6023 }
6024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006025 if (test_and_clear_bit(ISP_ABORT_NEEDED,
6026 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006028 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6029 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006031 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032
Giridhar Malavalia9083012010-04-12 17:59:55 -07006033 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 /* failed. retry later */
6035 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006036 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006038 clear_bit(ABORT_ISP_ACTIVE,
6039 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08006040 }
6041
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006042 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6043 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 }
6045
David Jefferya394aac2012-11-21 02:39:54 -05006046 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6047 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006048 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006049 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006050
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006051 if (IS_QLAFX00(ha))
6052 goto loop_resync_check;
6053
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006054 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006055 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6056 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006057 if (IS_P3P_TYPE(ha)) {
6058 if (IS_QLA82XX(ha))
6059 qla82xx_device_state_handler(base_vha);
6060 if (IS_QLA8044(ha))
6061 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006062 clear_bit(ISP_QUIESCE_NEEDED,
6063 &base_vha->dpc_flags);
6064 if (!ha->flags.quiesce_owner) {
6065 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006066 if (IS_QLA82XX(ha)) {
6067 qla82xx_idc_lock(ha);
6068 qla82xx_clear_qsnt_ready(
6069 base_vha);
6070 qla82xx_idc_unlock(ha);
6071 } else if (IS_QLA8044(ha)) {
6072 qla8044_idc_lock(ha);
6073 qla8044_clear_qsnt_ready(
6074 base_vha);
6075 qla8044_idc_unlock(ha);
6076 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006077 }
6078 } else {
6079 clear_bit(ISP_QUIESCE_NEEDED,
6080 &base_vha->dpc_flags);
6081 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006082 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006083 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6084 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006085 }
6086
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006087 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006088 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006089 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006091 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6092 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006093 qla2x00_rst_aen(base_vha);
6094 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006095 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6096 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 }
6098
6099 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006100 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006101 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6102 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103
Quinn Tran4005a992017-12-04 14:45:06 -08006104 if (!base_vha->relogin_jif ||
6105 time_after_eq(jiffies, base_vha->relogin_jif)) {
6106 base_vha->relogin_jif = jiffies + HZ;
6107 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6108
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006109 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006110 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006111 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006114loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006115 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006116 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006118 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6119 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120
6121 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006122 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123
Bart Van Assche52c82822015-07-09 07:23:26 -07006124 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006126 clear_bit(LOOP_RESYNC_ACTIVE,
6127 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 }
6129
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006130 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6131 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132 }
6133
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006134 if (IS_QLAFX00(ha))
6135 goto intr_on_check;
6136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006137 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6138 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6139 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6140 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006141 }
6142
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006143intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006145 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006147 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006148 &base_vha->dpc_flags)) {
6149 if (ha->beacon_blink_led == 1)
6150 ha->isp_ops->beacon_blink(base_vha);
6151 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006152
Michael Hernandezd7459522016-12-12 14:40:07 -08006153 /* qpair online check */
6154 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6155 &base_vha->dpc_flags)) {
6156 if (ha->flags.eeh_busy ||
6157 ha->flags.pci_channel_io_perm_failure)
6158 online = 0;
6159 else
6160 online = 1;
6161
6162 mutex_lock(&ha->mq_lock);
6163 list_for_each_entry(qpair, &base_vha->qp_list,
6164 qp_list_elem)
6165 qpair->online = online;
6166 mutex_unlock(&ha->mq_lock);
6167 }
6168
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006169 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED, &base_vha->dpc_flags)) {
6170 ql_log(ql_log_info, base_vha, 0xffffff,
6171 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6172 ha->nvme_last_rptd_aen);
6173 if (qla27xx_set_zio_threshold(base_vha, ha->nvme_last_rptd_aen)) {
6174 ql_log(ql_log_info, base_vha, 0xffffff,
6175 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6176 ha->nvme_last_rptd_aen);
6177 }
6178 }
6179
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006180 if (!IS_QLAFX00(ha))
6181 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006182
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006184end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006185 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006187 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006189 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6190 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191
6192 /*
6193 * Make sure that nobody tries to wake us up again.
6194 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 ha->dpc_active = 0;
6196
Andrew Vasquezac280b62009-08-20 11:06:05 -07006197 /* Cleanup any residual CTX SRBs. */
6198 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6199
Christoph Hellwig39a11242006-02-14 18:46:22 +01006200 return 0;
6201}
6202
6203void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006204qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006205{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006206 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006207 struct task_struct *t = ha->dpc_thread;
6208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006209 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006210 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211}
6212
6213/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214* qla2x00_rst_aen
6215* Processes asynchronous reset.
6216*
6217* Input:
6218* ha = adapter block pointer.
6219*/
6220static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006221qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006223 if (vha->flags.online && !vha->flags.reset_active &&
6224 !atomic_read(&vha->loop_down_timer) &&
6225 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006227 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228
6229 /*
6230 * Issue marker command only when we are going to start
6231 * the I/O.
6232 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006233 vha->marker_needed = 1;
6234 } while (!atomic_read(&vha->loop_down_timer) &&
6235 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 }
6237}
6238
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239/**************************************************************************
6240* qla2x00_timer
6241*
6242* Description:
6243* One second timer
6244*
6245* Context: Interrupt
6246***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006247void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006248qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006250 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 int start_dpc = 0;
6253 int index;
6254 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006255 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006256 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006257 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006258
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006259 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006260 ql_dbg(ql_dbg_timer, vha, 0x6000,
6261 "EEH = %d, restarting timer.\n",
6262 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006263 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6264 return;
6265 }
6266
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006267 /*
6268 * Hardware read to raise pending EEH errors during mailbox waits. If
6269 * the read returns -1 then disable the board.
6270 */
6271 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006272 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006273 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006276 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006277 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006278 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6279 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006280 if (IS_QLA82XX(ha))
6281 qla82xx_watchdog(vha);
6282 else if (IS_QLA8044(ha))
6283 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006284 }
6285
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006286 if (!vha->vp_idx && IS_QLAFX00(ha))
6287 qlafx00_timer_routine(vha);
6288
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006290 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006291 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6292 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006293 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006295 if (atomic_read(&vha->loop_down_timer) ==
6296 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006298 ql_log(ql_log_info, vha, 0x6008,
6299 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006301 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6302 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006304 /*
6305 * Schedule an ISP abort to return any FCP2-device
6306 * commands.
6307 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006308 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006309 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006310 spin_lock_irqsave(&ha->hardware_lock,
6311 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006312 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006313 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006314 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006315 index++) {
6316 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006317
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006318 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006319 if (!sp)
6320 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006321 if (sp->cmd_type != TYPE_SRB)
6322 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006323 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006324 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006325 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006326 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006327 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006329 if (IS_QLA82XX(ha))
6330 set_bit(FCOE_CTX_RESET_NEEDED,
6331 &vha->dpc_flags);
6332 else
6333 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006334 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006335 break;
6336 }
6337 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006338 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 start_dpc++;
6341 }
6342
6343 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006344 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006345 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006346 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347 "Loop down - aborting ISP.\n");
6348
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006349 if (IS_QLA82XX(ha))
6350 set_bit(FCOE_CTX_RESET_NEEDED,
6351 &vha->dpc_flags);
6352 else
6353 set_bit(ISP_ABORT_NEEDED,
6354 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 }
6356 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006357 ql_dbg(ql_dbg_timer, vha, 0x600a,
6358 "Loop down - seconds remaining %d.\n",
6359 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006361 /* Check if beacon LED needs to be blinked for physical host only */
6362 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006363 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006364 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006365 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6366 start_dpc++;
6367 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006368 }
6369
Andrew Vasquez550bf572008-04-24 15:21:23 -07006370 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006371 if (!list_empty(&vha->work_list)) {
6372 unsigned long flags;
6373 bool q = false;
6374
6375 spin_lock_irqsave(&vha->work_lock, flags);
6376 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6377 q = true;
6378 spin_unlock_irqrestore(&vha->work_lock, flags);
6379 if (q)
6380 queue_work(vha->hw->wq, &vha->iocb_work);
6381 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006382
Duane Grigsby7401bc12017-06-21 13:48:42 -07006383 /*
6384 * FC-NVME
6385 * see if the active AEN count has changed from what was last reported.
6386 */
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006387 if (!vha->vp_idx &&
6388 atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen &&
6389 ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006390 ql_log(ql_log_info, vha, 0x3002,
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006391 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6392 ha->nvme_last_rptd_aen);
6393 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
6394 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6395 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006396 }
6397
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006399 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6400 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6401 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006403 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6404 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006405 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6406 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006407 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006408 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006409 ql_dbg(ql_dbg_timer, vha, 0x600b,
6410 "isp_abort_needed=%d loop_resync_needed=%d "
6411 "fcport_update_needed=%d start_dpc=%d "
6412 "reset_marker_needed=%d",
6413 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6414 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6415 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6416 start_dpc,
6417 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6418 ql_dbg(ql_dbg_timer, vha, 0x600c,
6419 "beacon_blink_needed=%d isp_unrecoverable=%d "
6420 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006421 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006422 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6423 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6424 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6425 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006426 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006427 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006430 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431}
6432
Andrew Vasquez54333832005-11-09 15:49:04 -08006433/* Firmware interface routines. */
6434
Chad Dupuisf73cb692014-02-26 04:15:06 -05006435#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006436#define FW_ISP21XX 0
6437#define FW_ISP22XX 1
6438#define FW_ISP2300 2
6439#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006440#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006441#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006442#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006443#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006444#define FW_ISP2031 8
6445#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006446#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006447
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006448#define FW_FILE_ISP21XX "ql2100_fw.bin"
6449#define FW_FILE_ISP22XX "ql2200_fw.bin"
6450#define FW_FILE_ISP2300 "ql2300_fw.bin"
6451#define FW_FILE_ISP2322 "ql2322_fw.bin"
6452#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006453#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006454#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006455#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006456#define FW_FILE_ISP2031 "ql2600_fw.bin"
6457#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006458#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006459
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006460
Daniel Walkere1e82b62008-05-12 22:21:10 -07006461static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006462
6463static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006464 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6465 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6466 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6467 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6468 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006469 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006470 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006471 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006472 { .name = FW_FILE_ISP2031, },
6473 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006474 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006475};
6476
6477struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006478qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006479{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006480 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006481 struct fw_blob *blob;
6482
Andrew Vasquez54333832005-11-09 15:49:04 -08006483 if (IS_QLA2100(ha)) {
6484 blob = &qla_fw_blobs[FW_ISP21XX];
6485 } else if (IS_QLA2200(ha)) {
6486 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006487 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006488 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006489 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006490 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006491 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006492 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006493 } else if (IS_QLA25XX(ha)) {
6494 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006495 } else if (IS_QLA81XX(ha)) {
6496 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006497 } else if (IS_QLA82XX(ha)) {
6498 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006499 } else if (IS_QLA2031(ha)) {
6500 blob = &qla_fw_blobs[FW_ISP2031];
6501 } else if (IS_QLA8031(ha)) {
6502 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006503 } else if (IS_QLA27XX(ha)) {
6504 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006505 } else {
6506 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006507 }
6508
Daniel Walkere1e82b62008-05-12 22:21:10 -07006509 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006510 if (blob->fw)
6511 goto out;
6512
6513 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006514 ql_log(ql_log_warn, vha, 0x0063,
6515 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006516 blob->fw = NULL;
6517 blob = NULL;
6518 goto out;
6519 }
6520
6521out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006522 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006523 return blob;
6524}
6525
6526static void
6527qla2x00_release_firmware(void)
6528{
6529 int idx;
6530
Daniel Walkere1e82b62008-05-12 22:21:10 -07006531 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006532 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006533 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006534 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006535}
6536
Seokmann Ju14e660e2007-09-20 14:07:36 -07006537static pci_ers_result_t
6538qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6539{
Andrew Vasquez85880802009-12-15 21:29:46 -08006540 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6541 struct qla_hw_data *ha = vha->hw;
6542
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006543 ql_dbg(ql_dbg_aer, vha, 0x9000,
6544 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006545
Sawan Chandakefdb5762017-08-23 15:05:00 -07006546 if (!atomic_read(&pdev->enable_cnt)) {
6547 ql_log(ql_log_info, vha, 0xffff,
6548 "PCI device is disabled,state %x\n", state);
6549 return PCI_ERS_RESULT_NEED_RESET;
6550 }
6551
Seokmann Ju14e660e2007-09-20 14:07:36 -07006552 switch (state) {
6553 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006554 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006555 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006556 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6557 qla2xxx_wake_dpc(vha);
6558 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006559 return PCI_ERS_RESULT_CAN_RECOVER;
6560 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006561 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006562 /* For ISP82XX complete any pending mailbox cmd */
6563 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006564 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006565 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6566 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006567 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006568 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006569 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006570 /* Return back all IOs */
6571 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006572 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006573 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6574 qla2xxx_wake_dpc(vha);
6575 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006576 return PCI_ERS_RESULT_NEED_RESET;
6577 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006578 ha->flags.pci_channel_io_perm_failure = 1;
6579 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006580 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006581 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6582 qla2xxx_wake_dpc(vha);
6583 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006584 return PCI_ERS_RESULT_DISCONNECT;
6585 }
6586 return PCI_ERS_RESULT_NEED_RESET;
6587}
6588
6589static pci_ers_result_t
6590qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6591{
6592 int risc_paused = 0;
6593 uint32_t stat;
6594 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006595 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6596 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006597 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6598 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6599
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006600 if (IS_QLA82XX(ha))
6601 return PCI_ERS_RESULT_RECOVERED;
6602
Seokmann Ju14e660e2007-09-20 14:07:36 -07006603 spin_lock_irqsave(&ha->hardware_lock, flags);
6604 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6605 stat = RD_REG_DWORD(&reg->hccr);
6606 if (stat & HCCR_RISC_PAUSE)
6607 risc_paused = 1;
6608 } else if (IS_QLA23XX(ha)) {
6609 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6610 if (stat & HSR_RISC_PAUSED)
6611 risc_paused = 1;
6612 } else if (IS_FWI2_CAPABLE(ha)) {
6613 stat = RD_REG_DWORD(&reg24->host_status);
6614 if (stat & HSRX_RISC_PAUSED)
6615 risc_paused = 1;
6616 }
6617 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6618
6619 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006620 ql_log(ql_log_info, base_vha, 0x9003,
6621 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006622 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006623
6624 return PCI_ERS_RESULT_NEED_RESET;
6625 } else
6626 return PCI_ERS_RESULT_RECOVERED;
6627}
6628
Saurav Kashyapfa492632012-11-21 02:40:29 -05006629static uint32_t
6630qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006631{
6632 uint32_t rval = QLA_FUNCTION_FAILED;
6633 uint32_t drv_active = 0;
6634 struct qla_hw_data *ha = base_vha->hw;
6635 int fn;
6636 struct pci_dev *other_pdev = NULL;
6637
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006638 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6639 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006640
6641 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6642
6643 if (base_vha->flags.online) {
6644 /* Abort all outstanding commands,
6645 * so as to be requeued later */
6646 qla2x00_abort_isp_cleanup(base_vha);
6647 }
6648
6649
6650 fn = PCI_FUNC(ha->pdev->devfn);
6651 while (fn > 0) {
6652 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006653 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6654 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006655 other_pdev =
6656 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6657 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6658 fn));
6659
6660 if (!other_pdev)
6661 continue;
6662 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006663 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6664 "Found PCI func available and enable at 0x%x.\n",
6665 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006666 pci_dev_put(other_pdev);
6667 break;
6668 }
6669 pci_dev_put(other_pdev);
6670 }
6671
6672 if (!fn) {
6673 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006674 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6675 "This devfn is reset owner = 0x%x.\n",
6676 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006677 qla82xx_idc_lock(ha);
6678
6679 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006680 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006681
6682 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6683 QLA82XX_IDC_VERSION);
6684
6685 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006686 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6687 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006688
6689 qla82xx_idc_unlock(ha);
6690 /* Reset if device is not already reset
6691 * drv_active would be 0 if a reset has already been done
6692 */
6693 if (drv_active)
6694 rval = qla82xx_start_firmware(base_vha);
6695 else
6696 rval = QLA_SUCCESS;
6697 qla82xx_idc_lock(ha);
6698
6699 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006700 ql_log(ql_log_info, base_vha, 0x900b,
6701 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006702 qla82xx_clear_drv_active(ha);
6703 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006704 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006705 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006706 ql_log(ql_log_info, base_vha, 0x900c,
6707 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006708 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006709 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006710 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006711 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006712 rval = qla82xx_restart_isp(base_vha);
6713 qla82xx_idc_lock(ha);
6714 /* Clear driver state register */
6715 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6716 qla82xx_set_drv_active(base_vha);
6717 }
6718 qla82xx_idc_unlock(ha);
6719 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006720 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6721 "This devfn is not reset owner = 0x%x.\n",
6722 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006723 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006724 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006725 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006726 rval = qla82xx_restart_isp(base_vha);
6727 qla82xx_idc_lock(ha);
6728 qla82xx_set_drv_active(base_vha);
6729 qla82xx_idc_unlock(ha);
6730 }
6731 }
6732 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6733
6734 return rval;
6735}
6736
Seokmann Ju14e660e2007-09-20 14:07:36 -07006737static pci_ers_result_t
6738qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6739{
6740 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006741 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6742 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006743 struct rsp_que *rsp;
6744 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006745
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006746 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6747 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006748
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006749 /* Workaround: qla2xxx driver which access hardware earlier
6750 * needs error state to be pci_channel_io_online.
6751 * Otherwise mailbox command timesout.
6752 */
6753 pdev->error_state = pci_channel_io_normal;
6754
6755 pci_restore_state(pdev);
6756
Richard Lary8c1496b2010-02-18 10:07:29 -08006757 /* pci_restore_state() clears the saved_state flag of the device
6758 * save restored state which resets saved_state flag
6759 */
6760 pci_save_state(pdev);
6761
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006762 if (ha->mem_only)
6763 rc = pci_enable_device_mem(pdev);
6764 else
6765 rc = pci_enable_device(pdev);
6766
6767 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006768 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006769 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006770 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006771 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006772
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006773 rsp = ha->rsp_q_map[0];
6774 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006775 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006776
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006777 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006778 goto exit_slot_reset;
6779
6780 if (IS_QLA82XX(ha)) {
6781 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6782 ret = PCI_ERS_RESULT_RECOVERED;
6783 goto exit_slot_reset;
6784 } else
6785 goto exit_slot_reset;
6786 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006787
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006788 while (ha->flags.mbox_busy && retries--)
6789 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006791 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006792 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006793 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006794 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006795
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006796
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006797exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006798 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6799 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006800
Seokmann Ju14e660e2007-09-20 14:07:36 -07006801 return ret;
6802}
6803
6804static void
6805qla2xxx_pci_resume(struct pci_dev *pdev)
6806{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006807 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6808 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006809 int ret;
6810
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006811 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6812 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006814 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006815 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006816 ql_log(ql_log_fatal, base_vha, 0x9002,
6817 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006818 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006819
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006820 pci_cleanup_aer_uncorrect_error_status(pdev);
6821
Andrew Vasquez85880802009-12-15 21:29:46 -08006822 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006823}
6824
Michael Hernandez56012362016-12-12 14:40:08 -08006825static int qla2xxx_map_queues(struct Scsi_Host *shost)
6826{
Quinn Trand68b8502017-12-04 14:44:59 -08006827 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006828 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6829
Quinn Trand68b8502017-12-04 14:44:59 -08006830 if (USER_CTRL_IRQ(vha->hw))
6831 rc = blk_mq_map_queues(&shost->tag_set);
6832 else
Keith Buschf23f5bec2018-03-27 09:39:06 -06006833 rc = blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev, 0);
Quinn Trand68b8502017-12-04 14:44:59 -08006834 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006835}
6836
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006837static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006838 .error_detected = qla2xxx_pci_error_detected,
6839 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6840 .slot_reset = qla2xxx_pci_slot_reset,
6841 .resume = qla2xxx_pci_resume,
6842};
6843
Andrew Vasquez54333832005-11-09 15:49:04 -08006844static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006845 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6846 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6847 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6848 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6849 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6850 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6851 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6852 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6853 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006854 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006855 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6856 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006857 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006858 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006859 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006860 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006861 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006862 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006863 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006864 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006865 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006866 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006867 { 0 },
6868};
6869MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6870
Andrew Vasquezfca29702005-07-06 10:31:47 -07006871static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006872 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006873 .driver = {
6874 .owner = THIS_MODULE,
6875 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006876 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006877 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006878 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006879 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006880 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006881};
6882
Al Viro75ef9de2013-04-04 19:09:41 -04006883static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006884 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006885 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006886};
6887
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888/**
6889 * qla2x00_module_init - Module initialization.
6890 **/
6891static int __init
6892qla2x00_module_init(void)
6893{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006894 int ret = 0;
6895
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006897 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006898 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006900 ql_log(ql_log_fatal, NULL, 0x0001,
6901 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 return -ENOMEM;
6903 }
6904
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006905 /* Initialize target kmem_cache and mem_pools */
6906 ret = qlt_init();
6907 if (ret < 0) {
6908 kmem_cache_destroy(srb_cachep);
6909 return ret;
6910 } else if (ret > 0) {
6911 /*
6912 * If initiator mode is explictly disabled by qlt_init(),
6913 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6914 * performing scsi_scan_target() during LOOP UP event.
6915 */
6916 qla2xxx_transport_functions.disable_target_scan = 1;
6917 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6918 }
6919
Linus Torvalds1da177e2005-04-16 15:20:36 -07006920 /* Derive version string. */
6921 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006922 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006923 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07006924 if (ql2xextended_error_logging == 1)
6925 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07006926
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006927 qla2xxx_transport_template =
6928 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006929 if (!qla2xxx_transport_template) {
6930 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006931 ql_log(ql_log_fatal, NULL, 0x0002,
6932 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006933 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006934 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006935 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006936
6937 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6938 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006939 ql_log(ql_log_fatal, NULL, 0x0003,
6940 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006941 }
6942
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006943 qla2xxx_transport_vport_template =
6944 fc_attach_transport(&qla2xxx_transport_vport_functions);
6945 if (!qla2xxx_transport_vport_template) {
6946 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006947 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006948 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006949 ql_log(ql_log_fatal, NULL, 0x0004,
6950 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006951 return -ENODEV;
6952 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006953 ql_log(ql_log_info, NULL, 0x0005,
6954 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006955 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006956 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006957 if (ret) {
6958 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006959 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006960 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006961 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006962 ql_log(ql_log_fatal, NULL, 0x0006,
6963 "pci_register_driver failed...ret=%d Failing load!.\n",
6964 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006965 }
6966 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006967}
6968
6969/**
6970 * qla2x00_module_exit - Module cleanup.
6971 **/
6972static void __exit
6973qla2x00_module_exit(void)
6974{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006975 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006976 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006977 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006978 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006979 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006980 if (ctx_cachep)
6981 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006982 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006983 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984}
6985
6986module_init(qla2x00_module_init);
6987module_exit(qla2x00_module_exit);
6988
6989MODULE_AUTHOR("QLogic Corporation");
6990MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6991MODULE_LICENSE("GPL");
6992MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006993MODULE_FIRMWARE(FW_FILE_ISP21XX);
6994MODULE_FIRMWARE(FW_FILE_ISP22XX);
6995MODULE_FIRMWARE(FW_FILE_ISP2300);
6996MODULE_FIRMWARE(FW_FILE_ISP2322);
6997MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006998MODULE_FIRMWARE(FW_FILE_ISP25XX);