blob: 56bd086b79ea140db249ac23dd72822bb705e639 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700272 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 */
274static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500275static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800276static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
277static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500278static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500279static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static int qla2xxx_eh_abort(struct scsi_cmnd *);
281static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700282static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
284static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400286static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400287static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400288static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Michael Hernandez56012362016-12-12 14:40:08 -0800289static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700290static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700291
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700292struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700294 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700295 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700296
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100297 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700298 .eh_abort_handler = qla2xxx_eh_abort,
299 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700300 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700301 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
302 .eh_host_reset_handler = qla2xxx_eh_host_reset,
303
304 .slave_configure = qla2xxx_slave_configure,
305
306 .slave_alloc = qla2xxx_slave_alloc,
307 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700308 .scan_finished = qla2xxx_scan_finished,
309 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100310 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800311 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700312 .this_id = -1,
313 .cmd_per_lun = 3,
314 .use_clustering = ENABLE_CLUSTERING,
315 .sg_tablesize = SG_ALL,
316
317 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700318 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400319
320 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100321 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700322};
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700325struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/* TODO Convert to inlines
328 *
329 * Timer routines
330 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700332__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800335 init_timer(&vha->timer);
336 vha->timer.expires = jiffies + interval * HZ;
337 vha->timer.data = (unsigned long)vha;
338 vha->timer.function = (void (*)(unsigned long))func;
339 add_timer(&vha->timer);
340 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
343static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800344qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700346 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700347 if (vha->device_flags & DFLG_DEV_FAILED) {
348 ql_dbg(ql_dbg_timer, vha, 0x600d,
349 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700350 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700351 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
Adrian Bunka824ebb2008-01-17 09:02:15 -0800356static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800357qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800359 del_timer_sync(&vha->timer);
360 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363static int qla2x00_do_dpc(void *data);
364
365static void qla2x00_rst_aen(scsi_qla_host_t *);
366
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800367static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
368 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700369static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800370static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800371int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
372 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700375static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
376 struct rsp_que *rsp)
377{
378 struct qla_hw_data *ha = vha->hw;
379 rsp->qpair = ha->base_qpair;
380 rsp->req = req;
381 ha->base_qpair->req = req;
382 ha->base_qpair->rsp = rsp;
383 ha->base_qpair->vha = vha;
384 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
385 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
386 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
387 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -0700388 INIT_LIST_HEAD(&ha->base_qpair->nvme_done_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700389 ha->base_qpair->enable_class_2 = ql2xenableclass2;
390 /* init qpair to this cpu. Will adjust at run time. */
391 qla_cpu_update(rsp->qpair, smp_processor_id());
392 ha->base_qpair->pdev = ha->pdev;
393
394 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
395 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
396}
397
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400398static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
399 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800400{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700401 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700402 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800403 GFP_KERNEL);
404 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700405 ql_log(ql_log_fatal, vha, 0x003b,
406 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800407 goto fail_req_map;
408 }
409
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700410 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800411 GFP_KERNEL);
412 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700413 ql_log(ql_log_fatal, vha, 0x003c,
414 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415 goto fail_rsp_map;
416 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800417
Quinn Trane326d222017-06-13 20:47:18 -0700418 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
419 if (ha->base_qpair == NULL) {
420 ql_log(ql_log_warn, vha, 0x00e0,
421 "Failed to allocate base queue pair memory.\n");
422 goto fail_base_qpair;
423 }
424
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700425 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700426
Michael Hernandezd7459522016-12-12 14:40:07 -0800427 if (ql2xmqsupport && ha->max_qpairs) {
428 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
429 GFP_KERNEL);
430 if (!ha->queue_pair_map) {
431 ql_log(ql_log_fatal, vha, 0x0180,
432 "Unable to allocate memory for queue pair ptrs.\n");
433 goto fail_qpair_map;
434 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800435 }
436
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400437 /*
438 * Make sure we record at least the request and response queue zero in
439 * case we need to free them if part of the probe fails.
440 */
441 ha->rsp_q_map[0] = rsp;
442 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800443 set_bit(0, ha->rsp_qid_map);
444 set_bit(0, ha->req_qid_map);
445 return 1;
446
Michael Hernandezd7459522016-12-12 14:40:07 -0800447fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700448 kfree(ha->base_qpair);
449 ha->base_qpair = NULL;
450fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800451 kfree(ha->rsp_q_map);
452 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800453fail_rsp_map:
454 kfree(ha->req_q_map);
455 ha->req_q_map = NULL;
456fail_req_map:
457 return -ENOMEM;
458}
459
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700460static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800461{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400462 if (IS_QLAFX00(ha)) {
463 if (req && req->ring_fx00)
464 dma_free_coherent(&ha->pdev->dev,
465 (req->length_fx00 + 1) * sizeof(request_t),
466 req->ring_fx00, req->dma_fx00);
467 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800468 dma_free_coherent(&ha->pdev->dev,
469 (req->length + 1) * sizeof(request_t),
470 req->ring, req->dma);
471
Chad Dupuis8d93f552013-01-30 03:34:37 -0500472 if (req)
473 kfree(req->outstanding_cmds);
474
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800475 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800476}
477
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700478static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
479{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400480 if (IS_QLAFX00(ha)) {
481 if (rsp && rsp->ring)
482 dma_free_coherent(&ha->pdev->dev,
483 (rsp->length_fx00 + 1) * sizeof(request_t),
484 rsp->ring_fx00, rsp->dma_fx00);
485 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700486 dma_free_coherent(&ha->pdev->dev,
487 (rsp->length + 1) * sizeof(response_t),
488 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400489 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700490 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700491}
492
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800493static void qla2x00_free_queues(struct qla_hw_data *ha)
494{
495 struct req_que *req;
496 struct rsp_que *rsp;
497 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800498 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800499
Quinn Tran82de8022017-06-13 20:47:17 -0700500 if (ha->queue_pair_map) {
501 kfree(ha->queue_pair_map);
502 ha->queue_pair_map = NULL;
503 }
504 if (ha->base_qpair) {
505 kfree(ha->base_qpair);
506 ha->base_qpair = NULL;
507 }
508
Quinn Tran093df732016-12-12 14:40:09 -0800509 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700510 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500511 if (!test_bit(cnt, ha->req_qid_map))
512 continue;
513
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800514 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800515 clear_bit(cnt, ha->req_qid_map);
516 ha->req_q_map[cnt] = NULL;
517
518 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700519 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800520 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700521 }
Quinn Tran093df732016-12-12 14:40:09 -0800522 spin_unlock_irqrestore(&ha->hardware_lock, flags);
523
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700524 kfree(ha->req_q_map);
525 ha->req_q_map = NULL;
526
Quinn Tran093df732016-12-12 14:40:09 -0800527
528 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700529 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500530 if (!test_bit(cnt, ha->rsp_qid_map))
531 continue;
532
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700533 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500534 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800535 ha->rsp_q_map[cnt] = NULL;
536 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700537 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800538 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800539 }
Quinn Tran093df732016-12-12 14:40:09 -0800540 spin_unlock_irqrestore(&ha->hardware_lock, flags);
541
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800542 kfree(ha->rsp_q_map);
543 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800544}
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800547qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 static char *pci_bus_modes[] = {
551 "33", "66", "100", "133",
552 };
553 uint16_t pci_bus;
554
555 strcpy(str, "PCI");
556 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
557 if (pci_bus) {
558 strcat(str, "-X (");
559 strcat(str, pci_bus_modes[pci_bus]);
560 } else {
561 pci_bus = (ha->pci_attr & BIT_8) >> 8;
562 strcat(str, " (");
563 strcat(str, pci_bus_modes[pci_bus]);
564 }
565 strcat(str, " MHz)");
566
567 return (str);
568}
569
Andrew Vasquezfca29702005-07-06 10:31:47 -0700570static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700572{
573 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800574 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700575 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700576
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600577 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700578 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600579 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700580
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600581 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
582 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
583 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700584
585 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500586 switch (lspeed) {
587 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700588 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500589 break;
590 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700591 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500592 break;
593 case 3:
594 strcat(str, "8.0GT/s ");
595 break;
596 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700597 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500598 break;
599 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700600 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
601 strcat(str, lwstr);
602
603 return str;
604 }
605
606 strcpy(str, "PCI");
607 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
608 if (pci_bus == 0 || pci_bus == 8) {
609 strcat(str, " (");
610 strcat(str, pci_bus_modes[pci_bus >> 3]);
611 } else {
612 strcat(str, "-X ");
613 if (pci_bus & BIT_2)
614 strcat(str, "Mode 2");
615 else
616 strcat(str, "Mode 1");
617 strcat(str, " (");
618 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
619 }
620 strcat(str, " MHz)");
621
622 return str;
623}
624
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800625static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400626qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
628 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800629 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700630
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400631 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
632 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 if (ha->fw_attributes & BIT_9) {
635 strcat(str, "FLX");
636 return (str);
637 }
638
639 switch (ha->fw_attributes & 0xFF) {
640 case 0x7:
641 strcat(str, "EF");
642 break;
643 case 0x17:
644 strcat(str, "TP");
645 break;
646 case 0x37:
647 strcat(str, "IP");
648 break;
649 case 0x77:
650 strcat(str, "VI");
651 break;
652 default:
653 sprintf(un_str, "(%x)", ha->fw_attributes);
654 strcat(str, un_str);
655 break;
656 }
657 if (ha->fw_attributes & 0x100)
658 strcat(str, "X");
659
660 return (str);
661}
662
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800663static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400664qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700665{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800666 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700667
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400668 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800669 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700670 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700671}
672
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800673void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800674qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700675{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800676 srb_t *sp = ptr;
677 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800678 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800679 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700680
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800681 if (sp->flags & SRB_DMA_VALID) {
682 scsi_dma_unmap(cmd);
683 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700684 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700685
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800686 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
687 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
688 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
689 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
690 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700691
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700692 if (!ctx)
693 goto end;
694
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800695 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
696 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700697 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800698 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
699 }
700
701 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700702 struct crc_context *ctx0 = ctx;
703
704 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800705 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
706 }
707
708 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700709 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800710
711 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700712 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800713 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
714 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
715 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
716 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800717 }
718
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700719end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700720 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700721 CMD_SP(cmd) = NULL;
722 qla2x00_rel_sp(sp);
723 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800724}
725
Michael Hernandezd7459522016-12-12 14:40:07 -0800726void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800727qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800728{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800729 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800730 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
731
732 cmd->result = res;
733
734 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800735 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800736 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
737 sp, GET_CMD_SP(sp));
738 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400739 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800740 return;
741 }
742 if (!atomic_dec_and_test(&sp->ref_count))
743 return;
744
Joe Carnucciof3caa992017-08-23 15:05:09 -0700745 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800746 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700747}
748
Michael Hernandezd7459522016-12-12 14:40:07 -0800749void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800750qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800751{
752 srb_t *sp = (srb_t *)ptr;
753 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
754 struct qla_hw_data *ha = sp->fcport->vha->hw;
755 void *ctx = GET_CMD_CTX_SP(sp);
756
757 if (sp->flags & SRB_DMA_VALID) {
758 scsi_dma_unmap(cmd);
759 sp->flags &= ~SRB_DMA_VALID;
760 }
761
762 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
763 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
764 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
765 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
766 }
767
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700768 if (!ctx)
769 goto end;
770
Michael Hernandezd7459522016-12-12 14:40:07 -0800771 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
772 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700773 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800774 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
775 }
776
777 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700778 struct crc_context *ctx0 = ctx;
779
780 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800781 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
782 }
783
784 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700785 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800786 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
787 ctx1->fcp_cmnd_dma);
788 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
789 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
790 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
791 mempool_free(ctx1, ha->ctx_mempool);
792 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700793end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800794 CMD_SP(cmd) = NULL;
795 qla2xxx_rel_qpair_sp(sp->qpair, sp);
796}
797
798void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800799qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800800{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800801 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800802 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
803
804 cmd->result = res;
805
806 if (atomic_read(&sp->ref_count) == 0) {
807 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
808 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
809 sp, GET_CMD_SP(sp));
810 if (ql2xextended_error_logging & ql_dbg_io)
811 WARN_ON(atomic_read(&sp->ref_count) == 0);
812 return;
813 }
814 if (!atomic_dec_and_test(&sp->ref_count))
815 return;
816
Joe Carnucciof3caa992017-08-23 15:05:09 -0700817 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800818 cmd->scsi_done(cmd);
819}
820
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400821/* If we are SP1 here, we need to still take and release the host_lock as SP1
822 * does not have the changes necessary to avoid taking host->host_lock.
823 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800825qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700826{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700827 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700828 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400829 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800830 struct qla_hw_data *ha = vha->hw;
831 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700832 srb_t *sp;
833 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800834 struct qla_qpair *qpair = NULL;
835 uint32_t tag;
836 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700837
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200838 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
839 cmd->result = DID_NO_CONNECT << 16;
840 goto qc24_fail_command;
841 }
842
Michael Hernandez56012362016-12-12 14:40:08 -0800843 if (ha->mqenable) {
844 if (shost_use_blk_mq(vha->host)) {
845 tag = blk_mq_unique_tag(cmd->request);
846 hwq = blk_mq_unique_tag_to_hwq(tag);
847 qpair = ha->queue_pair_map[hwq];
848 } else if (vha->vp_idx && vha->qpair) {
849 qpair = vha->qpair;
850 }
851
852 if (qpair)
853 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800854 }
855
Andrew Vasquez85880802009-12-15 21:29:46 -0800856 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700857 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400858 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700859 "PCI Channel IO permanent failure, exiting "
860 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700861 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700862 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400863 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700864 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800865 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700866 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700867 goto qc24_fail_command;
868 }
869
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400870 rval = fc_remote_port_chkready(rport);
871 if (rval) {
872 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400873 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
875 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700876 goto qc24_fail_command;
877 }
878
Arun Easibad75002010-05-04 15:01:30 -0700879 if (!vha->flags.difdix_supported &&
880 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700881 ql_dbg(ql_dbg_io, vha, 0x3004,
882 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
883 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700884 cmd->result = DID_NO_CONNECT << 16;
885 goto qc24_fail_command;
886 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800887
888 if (!fcport) {
889 cmd->result = DID_NO_CONNECT << 16;
890 goto qc24_fail_command;
891 }
892
Andrew Vasquezfca29702005-07-06 10:31:47 -0700893 if (atomic_read(&fcport->state) != FCS_ONLINE) {
894 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700895 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700896 ql_dbg(ql_dbg_io, vha, 0x3005,
897 "Returning DNC, fcport_state=%d loop_state=%d.\n",
898 atomic_read(&fcport->state),
899 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700900 cmd->result = DID_NO_CONNECT << 16;
901 goto qc24_fail_command;
902 }
Mike Christie7b594132008-08-17 15:24:40 -0500903 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700904 }
905
Chad Dupuise05fe292014-09-25 05:16:59 -0400906 /*
907 * Return target busy if we've received a non-zero retry_delay_timer
908 * in a FCP_RSP.
909 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100910 if (fcport->retry_delay_timestamp == 0) {
911 /* retry delay not set */
912 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400913 fcport->retry_delay_timestamp = 0;
914 else
915 goto qc24_target_busy;
916
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500917 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400918 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800919 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700920
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800921 sp->u.scmd.cmd = cmd;
922 sp->type = SRB_SCSI_CMD;
923 atomic_set(&sp->ref_count, 1);
924 CMD_SP(cmd) = (void *)sp;
925 sp->free = qla2x00_sp_free_dma;
926 sp->done = qla2x00_sp_compl;
927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700929 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500930 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700931 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700932 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700933 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700934
Andrew Vasquezfca29702005-07-06 10:31:47 -0700935 return 0;
936
937qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700938 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700939
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800940qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700941 return SCSI_MLQUEUE_HOST_BUSY;
942
Mike Christie7b594132008-08-17 15:24:40 -0500943qc24_target_busy:
944 return SCSI_MLQUEUE_TARGET_BUSY;
945
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800947 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700948
949 return 0;
950}
951
Michael Hernandezd7459522016-12-12 14:40:07 -0800952/* For MQ supported I/O */
953int
954qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
955 struct qla_qpair *qpair)
956{
957 scsi_qla_host_t *vha = shost_priv(host);
958 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
959 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
960 struct qla_hw_data *ha = vha->hw;
961 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
962 srb_t *sp;
963 int rval;
964
965 rval = fc_remote_port_chkready(rport);
966 if (rval) {
967 cmd->result = rval;
968 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
969 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
970 cmd, rval);
971 goto qc24_fail_command;
972 }
973
974 if (!fcport) {
975 cmd->result = DID_NO_CONNECT << 16;
976 goto qc24_fail_command;
977 }
978
979 if (atomic_read(&fcport->state) != FCS_ONLINE) {
980 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
981 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
982 ql_dbg(ql_dbg_io, vha, 0x3077,
983 "Returning DNC, fcport_state=%d loop_state=%d.\n",
984 atomic_read(&fcport->state),
985 atomic_read(&base_vha->loop_state));
986 cmd->result = DID_NO_CONNECT << 16;
987 goto qc24_fail_command;
988 }
989 goto qc24_target_busy;
990 }
991
992 /*
993 * Return target busy if we've received a non-zero retry_delay_timer
994 * in a FCP_RSP.
995 */
996 if (fcport->retry_delay_timestamp == 0) {
997 /* retry delay not set */
998 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
999 fcport->retry_delay_timestamp = 0;
1000 else
1001 goto qc24_target_busy;
1002
1003 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
1004 if (!sp)
1005 goto qc24_host_busy;
1006
1007 sp->u.scmd.cmd = cmd;
1008 sp->type = SRB_SCSI_CMD;
1009 atomic_set(&sp->ref_count, 1);
1010 CMD_SP(cmd) = (void *)sp;
1011 sp->free = qla2xxx_qpair_sp_free_dma;
1012 sp->done = qla2xxx_qpair_sp_compl;
1013 sp->qpair = qpair;
1014
1015 rval = ha->isp_ops->start_scsi_mq(sp);
1016 if (rval != QLA_SUCCESS) {
1017 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1018 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1019 if (rval == QLA_INTERFACE_ERROR)
1020 goto qc24_fail_command;
1021 goto qc24_host_busy_free_sp;
1022 }
1023
1024 return 0;
1025
1026qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001027 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001028
1029qc24_host_busy:
1030 return SCSI_MLQUEUE_HOST_BUSY;
1031
1032qc24_target_busy:
1033 return SCSI_MLQUEUE_TARGET_BUSY;
1034
1035qc24_fail_command:
1036 cmd->scsi_done(cmd);
1037
1038 return 0;
1039}
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041/*
1042 * qla2x00_eh_wait_on_command
1043 * Waits for the command to be returned by the Firmware for some
1044 * max time.
1045 *
1046 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 *
1049 * Return:
1050 * Not Found : 0
1051 * Found : 1
1052 */
1053static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001054qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001056#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001057#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001058 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001059 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1060 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001061 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Andrew Vasquez85880802009-12-15 21:29:46 -08001063 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001064 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1065 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001066 return ret;
1067 }
1068
Lalit Chandivaded9704322009-08-25 11:36:18 -07001069 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001070 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001071 }
1072 if (CMD_SP(cmd))
1073 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
f4f051e2005-04-17 15:02:26 -05001075 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
1078/*
1079 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001080 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 * <= MAX_RETRIES_OF_ISP_ABORT or
1082 * finally HBA is disabled ie marked offline
1083 *
1084 * Input:
1085 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001086 *
1087 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 * Does context switching-Release SPIN_LOCK
1089 * (if any) before calling this routine.
1090 *
1091 * Return:
1092 * Success (Adapter is online) : 0
1093 * Failed (Adapter is offline/disabled) : 1
1094 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001095int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001096qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001098 int return_status;
1099 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001100 struct qla_hw_data *ha = vha->hw;
1101 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001103 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001104 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1105 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1106 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1107 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 msleep(1000);
1110 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001111 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001112 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 else
1114 return_status = QLA_FUNCTION_FAILED;
1115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 return (return_status);
1117}
1118
Quinn Tran726b8542017-01-19 22:28:00 -08001119static inline int test_fcport_count(scsi_qla_host_t *vha)
1120{
1121 struct qla_hw_data *ha = vha->hw;
1122 unsigned long flags;
1123 int res;
1124
1125 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001126 ql_dbg(ql_dbg_init, vha, 0x00ec,
1127 "tgt %p, fcport_count=%d\n",
1128 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001129 res = (vha->fcport_count == 0);
1130 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1131
1132 return res;
1133}
1134
1135/*
1136 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1137 * it has dependency on UNLOADING flag to stop device discovery
1138 */
1139static void
1140qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1141{
1142 qla2x00_mark_all_devices_lost(vha, 0);
1143
Joe Carnucciob85e0952017-08-23 15:05:11 -07001144 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001145}
1146
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001147/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001148 * qla2x00_wait_for_hba_ready
1149 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001150 *
1151 * Input:
1152 * ha - pointer to host adapter structure
1153 *
1154 * Note:
1155 * Does context switching-Release SPIN_LOCK
1156 * (if any) before calling this routine.
1157 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001158 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001159static void
1160qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001161{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001162 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001163 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001164
Dan Carpenter1d483902016-08-03 21:42:32 +03001165 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1166 ha->flags.mbox_busy) ||
1167 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1168 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1169 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1170 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001171 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001172 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001173}
1174
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001175int
1176qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1177{
1178 int return_status;
1179 unsigned long wait_reset;
1180 struct qla_hw_data *ha = vha->hw;
1181 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1182
1183 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1184 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1185 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1186 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1187 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1188
1189 msleep(1000);
1190
1191 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1192 ha->flags.chip_reset_done)
1193 break;
1194 }
1195 if (ha->flags.chip_reset_done)
1196 return_status = QLA_SUCCESS;
1197 else
1198 return_status = QLA_FUNCTION_FAILED;
1199
1200 return return_status;
1201}
1202
Giridhar Malavali083a4692010-05-28 15:08:18 -07001203static void
1204sp_get(struct srb *sp)
1205{
1206 atomic_inc(&sp->ref_count);
1207}
1208
Sawan Chandaka4655372016-07-06 11:14:32 -04001209#define ISP_REG_DISCONNECT 0xffffffffU
1210/**************************************************************************
1211* qla2x00_isp_reg_stat
1212*
1213* Description:
1214* Read the host status register of ISP before aborting the command.
1215*
1216* Input:
1217* ha = pointer to host adapter structure.
1218*
1219*
1220* Returns:
1221* Either true or false.
1222*
1223* Note: Return true if there is register disconnect.
1224**************************************************************************/
1225static inline
1226uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1227{
1228 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001229 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001230
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001231 if (IS_P3P_TYPE(ha))
1232 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1233 else
1234 return ((RD_REG_DWORD(&reg->host_status)) ==
1235 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001236}
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238/**************************************************************************
1239* qla2xxx_eh_abort
1240*
1241* Description:
1242* The abort function will abort the specified command.
1243*
1244* Input:
1245* cmd = Linux SCSI command packet to be aborted.
1246*
1247* Returns:
1248* Either SUCCESS or FAILED.
1249*
1250* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001251* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001253static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1255{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001256 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001257 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001258 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001259 unsigned int id;
1260 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001261 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001262 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Sawan Chandaka4655372016-07-06 11:14:32 -04001265 if (qla2x00_isp_reg_stat(ha)) {
1266 ql_log(ql_log_info, vha, 0x8042,
1267 "PCI/Register disconnect, exiting.\n");
1268 return FAILED;
1269 }
f4f051e2005-04-17 15:02:26 -05001270 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001271 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001273 ret = fc_block_scsi_eh(cmd);
1274 if (ret != 0)
1275 return ret;
1276 ret = SUCCESS;
1277
f4f051e2005-04-17 15:02:26 -05001278 id = cmd->device->id;
1279 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001282 sp = (srb_t *) CMD_SP(cmd);
1283 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001285 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001286 }
Mike Christie170babc2010-10-15 11:27:47 -07001287
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001288 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001289 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1290 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001291
1292 /* Get a reference to the sp and drop the lock.*/
1293 sp_get(sp);
1294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001296 rval = ha->isp_ops->abort_command(sp);
1297 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001298 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001299 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001300 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001301 ret = FAILED;
1302
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001304 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001305 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001306 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001307 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001308 wait = 1;
1309 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001310
1311 spin_lock_irqsave(&ha->hardware_lock, flags);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001312 sp->done(sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001313 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001314
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001315 /* Did the command return during mailbox execution? */
1316 if (ret == FAILED && !CMD_SP(cmd))
1317 ret = SUCCESS;
1318
f4f051e2005-04-17 15:02:26 -05001319 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001320 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001321 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001322 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001323 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001324 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001328 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001329 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001330 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
f4f051e2005-04-17 15:02:26 -05001332 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333}
1334
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001335int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001336qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001337 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001339 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001340 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001341 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001342 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001343 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001344 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Andrew Vasquez523ec772008-04-03 13:13:24 -07001346 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001347
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001349 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001350 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001351 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001352 sp = req->outstanding_cmds[cnt];
1353 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001354 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001355 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001356 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001357 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001358 continue;
1359 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001360 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001361 switch (type) {
1362 case WAIT_HOST:
1363 match = 1;
1364 break;
1365 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001367 break;
1368 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001369 match = (cmd->device->id == t &&
1370 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001371 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001373 if (!match)
1374 continue;
1375
1376 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001377 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001378 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001381
1382 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
Andrew Vasquez523ec772008-04-03 13:13:24 -07001385static char *reset_errors[] = {
1386 "HBA not online",
1387 "HBA not ready",
1388 "Task management failed",
1389 "Waiting for command completions",
1390};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Andrew Vasquez523ec772008-04-03 13:13:24 -07001392static int
1393__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001394 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001395{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001396 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001397 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1398 int err;
1399
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001400 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001401 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001402 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001403
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001404 err = fc_block_scsi_eh(cmd);
1405 if (err != 0)
1406 return err;
1407
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001408 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001409 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001411
1412 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001413 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1414 ql_log(ql_log_warn, vha, 0x800a,
1415 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001416 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001417 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001418 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001419 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001420 != QLA_SUCCESS) {
1421 ql_log(ql_log_warn, vha, 0x800c,
1422 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001423 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001424 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001425 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001426 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001427 cmd->device->lun, type) != QLA_SUCCESS) {
1428 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001429 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001430 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001432
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001433 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001434 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001435 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001436
1437 return SUCCESS;
1438
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001439eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001440 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001441 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001442 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1443 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001444 return FAILED;
1445}
1446
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001447static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1449{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001450 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1451 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Sawan Chandaka4655372016-07-06 11:14:32 -04001453 if (qla2x00_isp_reg_stat(ha)) {
1454 ql_log(ql_log_info, vha, 0x803e,
1455 "PCI/Register disconnect, exiting.\n");
1456 return FAILED;
1457 }
1458
Andrew Vasquez523ec772008-04-03 13:13:24 -07001459 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1460 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001464qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1467 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Sawan Chandaka4655372016-07-06 11:14:32 -04001469 if (qla2x00_isp_reg_stat(ha)) {
1470 ql_log(ql_log_info, vha, 0x803f,
1471 "PCI/Register disconnect, exiting.\n");
1472 return FAILED;
1473 }
1474
Andrew Vasquez523ec772008-04-03 13:13:24 -07001475 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1476 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479/**************************************************************************
1480* qla2xxx_eh_bus_reset
1481*
1482* Description:
1483* The bus reset function will reset the bus and abort any executing
1484* commands.
1485*
1486* Input:
1487* cmd = Linux SCSI command packet of the command that cause the
1488* bus reset.
1489*
1490* Returns:
1491* SUCCESS/FAILURE (defined as macro in scsi.h).
1492*
1493**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001494static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1496{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001497 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001498 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001499 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001500 unsigned int id;
1501 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001502 struct qla_hw_data *ha = vha->hw;
1503
1504 if (qla2x00_isp_reg_stat(ha)) {
1505 ql_log(ql_log_info, vha, 0x8040,
1506 "PCI/Register disconnect, exiting.\n");
1507 return FAILED;
1508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
f4f051e2005-04-17 15:02:26 -05001510 id = cmd->device->id;
1511 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001512
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001513 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001514 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001517 ret = fc_block_scsi_eh(cmd);
1518 if (ret != 0)
1519 return ret;
1520 ret = FAILED;
1521
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001522 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001523 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001525 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001526 ql_log(ql_log_fatal, vha, 0x8013,
1527 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001528 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
1530
Saurav Kashyapad5376892011-11-18 09:02:09 -08001531 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1532 ret = SUCCESS;
1533
f4f051e2005-04-17 15:02:26 -05001534 if (ret == FAILED)
1535 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001537 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001538 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001539 QLA_SUCCESS) {
1540 ql_log(ql_log_warn, vha, 0x8014,
1541 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001542 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
f4f051e2005-04-17 15:02:26 -05001545eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001546 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001547 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001548 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
f4f051e2005-04-17 15:02:26 -05001550 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
1553/**************************************************************************
1554* qla2xxx_eh_host_reset
1555*
1556* Description:
1557* The reset function will reset the Adapter.
1558*
1559* Input:
1560* cmd = Linux SCSI command packet of the command that cause the
1561* adapter reset.
1562*
1563* Returns:
1564* Either SUCCESS or FAILED.
1565*
1566* Note:
1567**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001568static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1570{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001571 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001573 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001574 unsigned int id;
1575 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Sawan Chandaka4655372016-07-06 11:14:32 -04001578 if (qla2x00_isp_reg_stat(ha)) {
1579 ql_log(ql_log_info, vha, 0x8041,
1580 "PCI/Register disconnect, exiting.\n");
1581 schedule_work(&ha->board_disable);
1582 return SUCCESS;
1583 }
1584
f4f051e2005-04-17 15:02:26 -05001585 id = cmd->device->id;
1586 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001587
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001588 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001589 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Chad Dupuis63ee7072014-04-11 16:54:46 -04001591 /*
1592 * No point in issuing another reset if one is active. Also do not
1593 * attempt a reset if we are updating flash.
1594 */
1595 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001596 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001598 if (vha != base_vha) {
1599 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001600 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001601 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001602 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001603 if (!qla82xx_fcoe_ctx_reset(vha)) {
1604 /* Ctx reset success */
1605 ret = SUCCESS;
1606 goto eh_host_reset_lock;
1607 }
1608 /* fall thru if ctx reset failed */
1609 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001610 if (ha->wq)
1611 flush_workqueue(ha->wq);
1612
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001614 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001615 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1616 /* failed. schedule dpc to try */
1617 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1618
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001619 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1620 ql_log(ql_log_warn, vha, 0x802a,
1621 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001623 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001624 }
1625 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001628 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001629 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001630 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001631 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
f4f051e2005-04-17 15:02:26 -05001633eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001634 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001635 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001636 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
f4f051e2005-04-17 15:02:26 -05001638 return ret;
1639}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641/*
1642* qla2x00_loop_reset
1643* Issue loop reset.
1644*
1645* Input:
1646* ha = adapter block pointer.
1647*
1648* Returns:
1649* 0 = success
1650*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001651int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001654 int ret;
bdf79622005-04-17 15:06:53 -05001655 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001656 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
Armen Baloyan58547712013-08-27 01:37:33 -04001658 if (IS_QLAFX00(ha)) {
1659 return qlafx00_loop_reset(vha);
1660 }
1661
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001662 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001663 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1664 if (fcport->port_type != FCT_TARGET)
1665 continue;
1666
1667 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1668 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001669 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001670 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001671 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001672 }
1673 }
1674 }
1675
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001676
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001677 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001678 atomic_set(&vha->loop_state, LOOP_DOWN);
1679 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1680 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001681 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001682 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001683 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1684 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 }
1687
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001688 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001690 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001691 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1692 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001693 }
1694
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001698 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001701void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001702qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001703{
Bill Kuzeja4cd3b6e2017-05-25 15:26:31 -04001704 int que, cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001705 unsigned long flags;
1706 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001707 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001708 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001709 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1710 struct qla_tgt_cmd *cmd;
1711 uint8_t trace = 0;
Arun Easic0cb4492014-09-25 06:14:51 -04001712
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001713 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001714 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001715 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001716 if (!req)
1717 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001718 if (!req->outstanding_cmds)
1719 continue;
1720 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001721 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001722 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001723 req->outstanding_cmds[cnt] = NULL;
Quinn Tranc5419e22017-06-13 20:47:16 -07001724 if (sp->cmd_type == TYPE_SRB) {
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -07001725 if (sp->type == SRB_NVME_CMD ||
1726 sp->type == SRB_NVME_LS) {
Duane Grigsbye84067d2017-06-21 13:48:43 -07001727 sp_get(sp);
1728 spin_unlock_irqrestore(
1729 &ha->hardware_lock, flags);
1730 qla_nvme_abort(ha, sp);
1731 spin_lock_irqsave(
1732 &ha->hardware_lock, flags);
1733 } else if (GET_CMD_SP(sp) &&
Quinn Tranc5419e22017-06-13 20:47:16 -07001734 !ha->flags.eeh_busy &&
Sawan Chandakd61cca62017-08-23 15:05:24 -07001735 (!test_bit(ABORT_ISP_ACTIVE,
1736 &vha->dpc_flags)) &&
Quinn Tranc5419e22017-06-13 20:47:16 -07001737 (sp->type == SRB_SCSI_CMD)) {
1738 /*
Duane Grigsbye84067d2017-06-21 13:48:43 -07001739 * Don't abort commands in
1740 * adapter during EEH
1741 * recovery as it's not
1742 * accessible/responding.
1743 *
Quinn Tranc5419e22017-06-13 20:47:16 -07001744 * Get a reference to the sp
1745 * and drop the lock. The
1746 * reference ensures this
1747 * sp->done() call and not the
1748 * call in qla2xxx_eh_abort()
1749 * ends the SCSI command (with
1750 * result 'res').
1751 */
1752 sp_get(sp);
1753 spin_unlock_irqrestore(
1754 &ha->hardware_lock, flags);
1755 status = qla2xxx_eh_abort(
1756 GET_CMD_SP(sp));
1757 spin_lock_irqsave(
1758 &ha->hardware_lock, flags);
1759 /*
1760 * Get rid of extra reference
1761 * if immediate exit from
1762 * ql2xxx_eh_abort
1763 */
1764 if (status == FAILED &&
1765 (qla2x00_isp_reg_stat(ha)))
1766 atomic_dec(
1767 &sp->ref_count);
1768 }
1769 sp->done(sp, res);
1770 } else {
1771 if (!vha->hw->tgt.tgt_ops || !tgt ||
1772 qla_ini_mode_enabled(vha)) {
1773 if (!trace)
1774 ql_dbg(ql_dbg_tgt_mgt,
1775 vha, 0xf003,
1776 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1777 vha->dpc_flags);
1778 continue;
1779 }
1780 cmd = (struct qla_tgt_cmd *)sp;
1781 qlt_abort_cmd_on_host_reset(cmd->vha,
1782 cmd);
1783 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001784 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001785 }
1786 }
1787 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1788}
1789
f4f051e2005-04-17 15:02:26 -05001790static int
1791qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
bdf79622005-04-17 15:06:53 -05001793 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001795 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001796 return -ENXIO;
1797
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001798 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001799
1800 return 0;
1801}
1802
1803static int
1804qla2xxx_slave_configure(struct scsi_device *sdev)
1805{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001806 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001807 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001808
Arun Easi9e522cd2012-08-22 14:21:31 -04001809 if (IS_T10_PI_CAPABLE(vha->hw))
1810 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1811
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001812 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001813 return 0;
1814}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
f4f051e2005-04-17 15:02:26 -05001816static void
1817qla2xxx_slave_destroy(struct scsi_device *sdev)
1818{
1819 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820}
1821
1822/**
1823 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1824 * @ha: HA context
1825 *
1826 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1827 * supported addressing method.
1828 */
1829static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001830qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001832 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Yang Hongyang6a355282009-04-06 19:01:13 -07001835 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001836 /* Any upper-dword bits set? */
1837 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001838 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001839 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001841 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1842 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001843 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001846
Yang Hongyang284901a2009-04-06 19:01:15 -07001847 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1848 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849}
1850
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001851static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001852qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001853{
1854 unsigned long flags = 0;
1855 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1856
1857 spin_lock_irqsave(&ha->hardware_lock, flags);
1858 ha->interrupts_on = 1;
1859 /* enable risc and host interrupts */
1860 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1861 RD_REG_WORD(&reg->ictrl);
1862 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1863
1864}
1865
1866static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001867qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001868{
1869 unsigned long flags = 0;
1870 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1871
1872 spin_lock_irqsave(&ha->hardware_lock, flags);
1873 ha->interrupts_on = 0;
1874 /* disable risc and host interrupts */
1875 WRT_REG_WORD(&reg->ictrl, 0);
1876 RD_REG_WORD(&reg->ictrl);
1877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1878}
1879
1880static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001881qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001882{
1883 unsigned long flags = 0;
1884 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1885
1886 spin_lock_irqsave(&ha->hardware_lock, flags);
1887 ha->interrupts_on = 1;
1888 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1889 RD_REG_DWORD(&reg->ictrl);
1890 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1891}
1892
1893static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001894qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001895{
1896 unsigned long flags = 0;
1897 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1898
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001899 if (IS_NOPOLLING_TYPE(ha))
1900 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001901 spin_lock_irqsave(&ha->hardware_lock, flags);
1902 ha->interrupts_on = 0;
1903 WRT_REG_DWORD(&reg->ictrl, 0);
1904 RD_REG_DWORD(&reg->ictrl);
1905 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1906}
1907
Giridhar Malavali706f4572011-11-18 09:03:16 -08001908static int
1909qla2x00_iospace_config(struct qla_hw_data *ha)
1910{
1911 resource_size_t pio;
1912 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001913
Giridhar Malavali706f4572011-11-18 09:03:16 -08001914 if (pci_request_selected_regions(ha->pdev, ha->bars,
1915 QLA2XXX_DRIVER_NAME)) {
1916 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1917 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1918 pci_name(ha->pdev));
1919 goto iospace_error_exit;
1920 }
1921 if (!(ha->bars & 1))
1922 goto skip_pio;
1923
1924 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1925 pio = pci_resource_start(ha->pdev, 0);
1926 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1927 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1928 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1929 "Invalid pci I/O region size (%s).\n",
1930 pci_name(ha->pdev));
1931 pio = 0;
1932 }
1933 } else {
1934 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1935 "Region #0 no a PIO resource (%s).\n",
1936 pci_name(ha->pdev));
1937 pio = 0;
1938 }
1939 ha->pio_address = pio;
1940 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1941 "PIO address=%llu.\n",
1942 (unsigned long long)ha->pio_address);
1943
1944skip_pio:
1945 /* Use MMIO operations for all accesses. */
1946 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1947 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1948 "Region #1 not an MMIO resource (%s), aborting.\n",
1949 pci_name(ha->pdev));
1950 goto iospace_error_exit;
1951 }
1952 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1953 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1954 "Invalid PCI mem region size (%s), aborting.\n",
1955 pci_name(ha->pdev));
1956 goto iospace_error_exit;
1957 }
1958
1959 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1960 if (!ha->iobase) {
1961 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1962 "Cannot remap MMIO (%s), aborting.\n",
1963 pci_name(ha->pdev));
1964 goto iospace_error_exit;
1965 }
1966
1967 /* Determine queue resources */
1968 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001969 ha->msix_count = QLA_BASE_VECTORS;
Michael Hernandezd7459522016-12-12 14:40:07 -08001970 if (!ql2xmqsupport || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08001971 goto mqiobase_exit;
1972
1973 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1974 pci_resource_len(ha->pdev, 3));
1975 if (ha->mqiobase) {
1976 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1977 "MQIO Base=%p.\n", ha->mqiobase);
1978 /* Read MSIX vector size of the board */
1979 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08001980 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001981 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08001982 /* MB interrupt uses 1 vector */
1983 ha->max_req_queues = ha->msix_count - 1;
1984 ha->max_rsp_queues = ha->max_req_queues;
1985 /* Queue pairs is the max value minus the base queue pair */
1986 ha->max_qpairs = ha->max_rsp_queues - 1;
1987 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
1988 "Max no of queues pairs: %d.\n", ha->max_qpairs);
1989
Giridhar Malavali706f4572011-11-18 09:03:16 -08001990 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08001991 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08001992 } else
1993 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1994 "BAR 3 not enabled.\n");
1995
1996mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08001997 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001998 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08001999 return (0);
2000
2001iospace_error_exit:
2002 return (-ENOMEM);
2003}
2004
2005
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002006static int
2007qla83xx_iospace_config(struct qla_hw_data *ha)
2008{
2009 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002010
2011 if (pci_request_selected_regions(ha->pdev, ha->bars,
2012 QLA2XXX_DRIVER_NAME)) {
2013 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2014 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2015 pci_name(ha->pdev));
2016
2017 goto iospace_error_exit;
2018 }
2019
2020 /* Use MMIO operations for all accesses. */
2021 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2022 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2023 "Invalid pci I/O region size (%s).\n",
2024 pci_name(ha->pdev));
2025 goto iospace_error_exit;
2026 }
2027 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2028 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2029 "Invalid PCI mem region size (%s), aborting\n",
2030 pci_name(ha->pdev));
2031 goto iospace_error_exit;
2032 }
2033
2034 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2035 if (!ha->iobase) {
2036 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2037 "Cannot remap MMIO (%s), aborting.\n",
2038 pci_name(ha->pdev));
2039 goto iospace_error_exit;
2040 }
2041
2042 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2043 /* 83XX 26XX always use MQ type access for queues
2044 * - mbar 2, a.k.a region 4 */
2045 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002046 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002047 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2048 pci_resource_len(ha->pdev, 4));
2049
2050 if (!ha->mqiobase) {
2051 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2052 "BAR2/region4 not enabled\n");
2053 goto mqiobase_exit;
2054 }
2055
2056 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2057 pci_resource_len(ha->pdev, 2));
2058 if (ha->msixbase) {
2059 /* Read MSIX vector size of the board */
2060 pci_read_config_word(ha->pdev,
2061 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002062 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002063 /*
2064 * By default, driver uses at least two msix vectors
2065 * (default & rspq)
2066 */
Michael Hernandezd7459522016-12-12 14:40:07 -08002067 if (ql2xmqsupport) {
2068 /* MB interrupt uses 1 vector */
2069 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002070
2071 /* ATIOQ needs 1 vector. That's 1 less QPair */
2072 if (QLA_TGT_MODE_ENABLED())
2073 ha->max_req_queues--;
2074
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002075 ha->max_rsp_queues = ha->max_req_queues;
2076
Michael Hernandezd7459522016-12-12 14:40:07 -08002077 /* Queue pairs is the max value minus
2078 * the base queue pair */
2079 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002080 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002081 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002082 }
2083 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002084 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002085 } else
2086 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2087 "BAR 1 not enabled.\n");
2088
2089mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002090 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002091 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002092 return 0;
2093
2094iospace_error_exit:
2095 return -ENOMEM;
2096}
2097
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002098static struct isp_operations qla2100_isp_ops = {
2099 .pci_config = qla2100_pci_config,
2100 .reset_chip = qla2x00_reset_chip,
2101 .chip_diag = qla2x00_chip_diag,
2102 .config_rings = qla2x00_config_rings,
2103 .reset_adapter = qla2x00_reset_adapter,
2104 .nvram_config = qla2x00_nvram_config,
2105 .update_fw_options = qla2x00_update_fw_options,
2106 .load_risc = qla2x00_load_risc,
2107 .pci_info_str = qla2x00_pci_info_str,
2108 .fw_version_str = qla2x00_fw_version_str,
2109 .intr_handler = qla2100_intr_handler,
2110 .enable_intrs = qla2x00_enable_intrs,
2111 .disable_intrs = qla2x00_disable_intrs,
2112 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002113 .target_reset = qla2x00_abort_target,
2114 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002115 .fabric_login = qla2x00_login_fabric,
2116 .fabric_logout = qla2x00_fabric_logout,
2117 .calc_req_entries = qla2x00_calc_iocbs_32,
2118 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2119 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2120 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2121 .read_nvram = qla2x00_read_nvram_data,
2122 .write_nvram = qla2x00_write_nvram_data,
2123 .fw_dump = qla2100_fw_dump,
2124 .beacon_on = NULL,
2125 .beacon_off = NULL,
2126 .beacon_blink = NULL,
2127 .read_optrom = qla2x00_read_optrom_data,
2128 .write_optrom = qla2x00_write_optrom_data,
2129 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002130 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002131 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002132 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002133 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002134 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002135};
2136
2137static struct isp_operations qla2300_isp_ops = {
2138 .pci_config = qla2300_pci_config,
2139 .reset_chip = qla2x00_reset_chip,
2140 .chip_diag = qla2x00_chip_diag,
2141 .config_rings = qla2x00_config_rings,
2142 .reset_adapter = qla2x00_reset_adapter,
2143 .nvram_config = qla2x00_nvram_config,
2144 .update_fw_options = qla2x00_update_fw_options,
2145 .load_risc = qla2x00_load_risc,
2146 .pci_info_str = qla2x00_pci_info_str,
2147 .fw_version_str = qla2x00_fw_version_str,
2148 .intr_handler = qla2300_intr_handler,
2149 .enable_intrs = qla2x00_enable_intrs,
2150 .disable_intrs = qla2x00_disable_intrs,
2151 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002152 .target_reset = qla2x00_abort_target,
2153 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002154 .fabric_login = qla2x00_login_fabric,
2155 .fabric_logout = qla2x00_fabric_logout,
2156 .calc_req_entries = qla2x00_calc_iocbs_32,
2157 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2158 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2159 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2160 .read_nvram = qla2x00_read_nvram_data,
2161 .write_nvram = qla2x00_write_nvram_data,
2162 .fw_dump = qla2300_fw_dump,
2163 .beacon_on = qla2x00_beacon_on,
2164 .beacon_off = qla2x00_beacon_off,
2165 .beacon_blink = qla2x00_beacon_blink,
2166 .read_optrom = qla2x00_read_optrom_data,
2167 .write_optrom = qla2x00_write_optrom_data,
2168 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002169 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002170 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002171 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002172 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002173 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002174};
2175
2176static struct isp_operations qla24xx_isp_ops = {
2177 .pci_config = qla24xx_pci_config,
2178 .reset_chip = qla24xx_reset_chip,
2179 .chip_diag = qla24xx_chip_diag,
2180 .config_rings = qla24xx_config_rings,
2181 .reset_adapter = qla24xx_reset_adapter,
2182 .nvram_config = qla24xx_nvram_config,
2183 .update_fw_options = qla24xx_update_fw_options,
2184 .load_risc = qla24xx_load_risc,
2185 .pci_info_str = qla24xx_pci_info_str,
2186 .fw_version_str = qla24xx_fw_version_str,
2187 .intr_handler = qla24xx_intr_handler,
2188 .enable_intrs = qla24xx_enable_intrs,
2189 .disable_intrs = qla24xx_disable_intrs,
2190 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002191 .target_reset = qla24xx_abort_target,
2192 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002193 .fabric_login = qla24xx_login_fabric,
2194 .fabric_logout = qla24xx_fabric_logout,
2195 .calc_req_entries = NULL,
2196 .build_iocbs = NULL,
2197 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2198 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2199 .read_nvram = qla24xx_read_nvram_data,
2200 .write_nvram = qla24xx_write_nvram_data,
2201 .fw_dump = qla24xx_fw_dump,
2202 .beacon_on = qla24xx_beacon_on,
2203 .beacon_off = qla24xx_beacon_off,
2204 .beacon_blink = qla24xx_beacon_blink,
2205 .read_optrom = qla24xx_read_optrom_data,
2206 .write_optrom = qla24xx_write_optrom_data,
2207 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002209 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002210 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002211 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002212 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002213};
2214
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002215static struct isp_operations qla25xx_isp_ops = {
2216 .pci_config = qla25xx_pci_config,
2217 .reset_chip = qla24xx_reset_chip,
2218 .chip_diag = qla24xx_chip_diag,
2219 .config_rings = qla24xx_config_rings,
2220 .reset_adapter = qla24xx_reset_adapter,
2221 .nvram_config = qla24xx_nvram_config,
2222 .update_fw_options = qla24xx_update_fw_options,
2223 .load_risc = qla24xx_load_risc,
2224 .pci_info_str = qla24xx_pci_info_str,
2225 .fw_version_str = qla24xx_fw_version_str,
2226 .intr_handler = qla24xx_intr_handler,
2227 .enable_intrs = qla24xx_enable_intrs,
2228 .disable_intrs = qla24xx_disable_intrs,
2229 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002230 .target_reset = qla24xx_abort_target,
2231 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002232 .fabric_login = qla24xx_login_fabric,
2233 .fabric_logout = qla24xx_fabric_logout,
2234 .calc_req_entries = NULL,
2235 .build_iocbs = NULL,
2236 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2237 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2238 .read_nvram = qla25xx_read_nvram_data,
2239 .write_nvram = qla25xx_write_nvram_data,
2240 .fw_dump = qla25xx_fw_dump,
2241 .beacon_on = qla24xx_beacon_on,
2242 .beacon_off = qla24xx_beacon_off,
2243 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002244 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002245 .write_optrom = qla24xx_write_optrom_data,
2246 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002247 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002248 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002249 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002250 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002251 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002252};
2253
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002254static struct isp_operations qla81xx_isp_ops = {
2255 .pci_config = qla25xx_pci_config,
2256 .reset_chip = qla24xx_reset_chip,
2257 .chip_diag = qla24xx_chip_diag,
2258 .config_rings = qla24xx_config_rings,
2259 .reset_adapter = qla24xx_reset_adapter,
2260 .nvram_config = qla81xx_nvram_config,
2261 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002262 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002263 .pci_info_str = qla24xx_pci_info_str,
2264 .fw_version_str = qla24xx_fw_version_str,
2265 .intr_handler = qla24xx_intr_handler,
2266 .enable_intrs = qla24xx_enable_intrs,
2267 .disable_intrs = qla24xx_disable_intrs,
2268 .abort_command = qla24xx_abort_command,
2269 .target_reset = qla24xx_abort_target,
2270 .lun_reset = qla24xx_lun_reset,
2271 .fabric_login = qla24xx_login_fabric,
2272 .fabric_logout = qla24xx_fabric_logout,
2273 .calc_req_entries = NULL,
2274 .build_iocbs = NULL,
2275 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2276 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002277 .read_nvram = NULL,
2278 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002279 .fw_dump = qla81xx_fw_dump,
2280 .beacon_on = qla24xx_beacon_on,
2281 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002282 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002283 .read_optrom = qla25xx_read_optrom_data,
2284 .write_optrom = qla24xx_write_optrom_data,
2285 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002286 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002287 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002288 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002289 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002290 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002291};
2292
2293static struct isp_operations qla82xx_isp_ops = {
2294 .pci_config = qla82xx_pci_config,
2295 .reset_chip = qla82xx_reset_chip,
2296 .chip_diag = qla24xx_chip_diag,
2297 .config_rings = qla82xx_config_rings,
2298 .reset_adapter = qla24xx_reset_adapter,
2299 .nvram_config = qla81xx_nvram_config,
2300 .update_fw_options = qla24xx_update_fw_options,
2301 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002302 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002303 .fw_version_str = qla24xx_fw_version_str,
2304 .intr_handler = qla82xx_intr_handler,
2305 .enable_intrs = qla82xx_enable_intrs,
2306 .disable_intrs = qla82xx_disable_intrs,
2307 .abort_command = qla24xx_abort_command,
2308 .target_reset = qla24xx_abort_target,
2309 .lun_reset = qla24xx_lun_reset,
2310 .fabric_login = qla24xx_login_fabric,
2311 .fabric_logout = qla24xx_fabric_logout,
2312 .calc_req_entries = NULL,
2313 .build_iocbs = NULL,
2314 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2315 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2316 .read_nvram = qla24xx_read_nvram_data,
2317 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002318 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002319 .beacon_on = qla82xx_beacon_on,
2320 .beacon_off = qla82xx_beacon_off,
2321 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002322 .read_optrom = qla82xx_read_optrom_data,
2323 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002324 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002325 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002326 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002327 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002328 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002329 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002330};
2331
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002332static struct isp_operations qla8044_isp_ops = {
2333 .pci_config = qla82xx_pci_config,
2334 .reset_chip = qla82xx_reset_chip,
2335 .chip_diag = qla24xx_chip_diag,
2336 .config_rings = qla82xx_config_rings,
2337 .reset_adapter = qla24xx_reset_adapter,
2338 .nvram_config = qla81xx_nvram_config,
2339 .update_fw_options = qla24xx_update_fw_options,
2340 .load_risc = qla82xx_load_risc,
2341 .pci_info_str = qla24xx_pci_info_str,
2342 .fw_version_str = qla24xx_fw_version_str,
2343 .intr_handler = qla8044_intr_handler,
2344 .enable_intrs = qla82xx_enable_intrs,
2345 .disable_intrs = qla82xx_disable_intrs,
2346 .abort_command = qla24xx_abort_command,
2347 .target_reset = qla24xx_abort_target,
2348 .lun_reset = qla24xx_lun_reset,
2349 .fabric_login = qla24xx_login_fabric,
2350 .fabric_logout = qla24xx_fabric_logout,
2351 .calc_req_entries = NULL,
2352 .build_iocbs = NULL,
2353 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2354 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2355 .read_nvram = NULL,
2356 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002357 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002358 .beacon_on = qla82xx_beacon_on,
2359 .beacon_off = qla82xx_beacon_off,
2360 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002361 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002362 .write_optrom = qla8044_write_optrom_data,
2363 .get_flash_version = qla82xx_get_flash_version,
2364 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002365 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002366 .abort_isp = qla8044_abort_isp,
2367 .iospace_config = qla82xx_iospace_config,
2368 .initialize_adapter = qla2x00_initialize_adapter,
2369};
2370
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002371static struct isp_operations qla83xx_isp_ops = {
2372 .pci_config = qla25xx_pci_config,
2373 .reset_chip = qla24xx_reset_chip,
2374 .chip_diag = qla24xx_chip_diag,
2375 .config_rings = qla24xx_config_rings,
2376 .reset_adapter = qla24xx_reset_adapter,
2377 .nvram_config = qla81xx_nvram_config,
2378 .update_fw_options = qla81xx_update_fw_options,
2379 .load_risc = qla81xx_load_risc,
2380 .pci_info_str = qla24xx_pci_info_str,
2381 .fw_version_str = qla24xx_fw_version_str,
2382 .intr_handler = qla24xx_intr_handler,
2383 .enable_intrs = qla24xx_enable_intrs,
2384 .disable_intrs = qla24xx_disable_intrs,
2385 .abort_command = qla24xx_abort_command,
2386 .target_reset = qla24xx_abort_target,
2387 .lun_reset = qla24xx_lun_reset,
2388 .fabric_login = qla24xx_login_fabric,
2389 .fabric_logout = qla24xx_fabric_logout,
2390 .calc_req_entries = NULL,
2391 .build_iocbs = NULL,
2392 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2393 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2394 .read_nvram = NULL,
2395 .write_nvram = NULL,
2396 .fw_dump = qla83xx_fw_dump,
2397 .beacon_on = qla24xx_beacon_on,
2398 .beacon_off = qla24xx_beacon_off,
2399 .beacon_blink = qla83xx_beacon_blink,
2400 .read_optrom = qla25xx_read_optrom_data,
2401 .write_optrom = qla24xx_write_optrom_data,
2402 .get_flash_version = qla24xx_get_flash_version,
2403 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002404 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002405 .abort_isp = qla2x00_abort_isp,
2406 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002407 .initialize_adapter = qla2x00_initialize_adapter,
2408};
2409
2410static struct isp_operations qlafx00_isp_ops = {
2411 .pci_config = qlafx00_pci_config,
2412 .reset_chip = qlafx00_soft_reset,
2413 .chip_diag = qlafx00_chip_diag,
2414 .config_rings = qlafx00_config_rings,
2415 .reset_adapter = qlafx00_soft_reset,
2416 .nvram_config = NULL,
2417 .update_fw_options = NULL,
2418 .load_risc = NULL,
2419 .pci_info_str = qlafx00_pci_info_str,
2420 .fw_version_str = qlafx00_fw_version_str,
2421 .intr_handler = qlafx00_intr_handler,
2422 .enable_intrs = qlafx00_enable_intrs,
2423 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002424 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002425 .target_reset = qlafx00_abort_target,
2426 .lun_reset = qlafx00_lun_reset,
2427 .fabric_login = NULL,
2428 .fabric_logout = NULL,
2429 .calc_req_entries = NULL,
2430 .build_iocbs = NULL,
2431 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2432 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2433 .read_nvram = qla24xx_read_nvram_data,
2434 .write_nvram = qla24xx_write_nvram_data,
2435 .fw_dump = NULL,
2436 .beacon_on = qla24xx_beacon_on,
2437 .beacon_off = qla24xx_beacon_off,
2438 .beacon_blink = NULL,
2439 .read_optrom = qla24xx_read_optrom_data,
2440 .write_optrom = qla24xx_write_optrom_data,
2441 .get_flash_version = qla24xx_get_flash_version,
2442 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002443 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002444 .abort_isp = qlafx00_abort_isp,
2445 .iospace_config = qlafx00_iospace_config,
2446 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002447};
2448
Chad Dupuisf73cb692014-02-26 04:15:06 -05002449static struct isp_operations qla27xx_isp_ops = {
2450 .pci_config = qla25xx_pci_config,
2451 .reset_chip = qla24xx_reset_chip,
2452 .chip_diag = qla24xx_chip_diag,
2453 .config_rings = qla24xx_config_rings,
2454 .reset_adapter = qla24xx_reset_adapter,
2455 .nvram_config = qla81xx_nvram_config,
2456 .update_fw_options = qla81xx_update_fw_options,
2457 .load_risc = qla81xx_load_risc,
2458 .pci_info_str = qla24xx_pci_info_str,
2459 .fw_version_str = qla24xx_fw_version_str,
2460 .intr_handler = qla24xx_intr_handler,
2461 .enable_intrs = qla24xx_enable_intrs,
2462 .disable_intrs = qla24xx_disable_intrs,
2463 .abort_command = qla24xx_abort_command,
2464 .target_reset = qla24xx_abort_target,
2465 .lun_reset = qla24xx_lun_reset,
2466 .fabric_login = qla24xx_login_fabric,
2467 .fabric_logout = qla24xx_fabric_logout,
2468 .calc_req_entries = NULL,
2469 .build_iocbs = NULL,
2470 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2471 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2472 .read_nvram = NULL,
2473 .write_nvram = NULL,
2474 .fw_dump = qla27xx_fwdump,
2475 .beacon_on = qla24xx_beacon_on,
2476 .beacon_off = qla24xx_beacon_off,
2477 .beacon_blink = qla83xx_beacon_blink,
2478 .read_optrom = qla25xx_read_optrom_data,
2479 .write_optrom = qla24xx_write_optrom_data,
2480 .get_flash_version = qla24xx_get_flash_version,
2481 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002482 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002483 .abort_isp = qla2x00_abort_isp,
2484 .iospace_config = qla83xx_iospace_config,
2485 .initialize_adapter = qla2x00_initialize_adapter,
2486};
2487
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002488static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002490{
2491 ha->device_type = DT_EXTENDED_IDS;
2492 switch (ha->pdev->device) {
2493 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002494 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002495 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002496 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002497 break;
2498 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002499 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002500 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002501 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002502 break;
2503 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002504 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002505 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002506 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002507 break;
2508 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002509 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002510 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002511 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002512 break;
2513 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002514 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002515 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002516 if (ha->pdev->subsystem_vendor == 0x1028 &&
2517 ha->pdev->subsystem_device == 0x0170)
2518 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002519 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002520 break;
2521 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002522 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002523 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002524 break;
2525 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002526 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002527 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002528 break;
2529 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002530 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002531 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002532 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002533 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002534 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002535 break;
2536 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002537 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002538 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002539 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002540 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002541 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002542 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002543 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002544 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002545 ha->device_type |= DT_ZIO_SUPPORTED;
2546 ha->device_type |= DT_FWI2;
2547 ha->device_type |= DT_IIDMA;
2548 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2549 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002550 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002551 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002552 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002553 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002554 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002555 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002556 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002557 ha->device_type |= DT_FWI2;
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;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002560 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002561 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002562 ha->device_type |= DT_ZIO_SUPPORTED;
2563 ha->device_type |= DT_FWI2;
2564 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002565 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2566 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002567 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002568 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002569 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;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002574 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002575 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002576 ha->device_type |= DT_ZIO_SUPPORTED;
2577 ha->device_type |= DT_FWI2;
2578 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2579 /* Initialize 82XX ISP flags */
2580 qla82xx_init_flags(ha);
2581 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002582 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002583 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002584 ha->device_type |= DT_ZIO_SUPPORTED;
2585 ha->device_type |= DT_FWI2;
2586 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2587 /* Initialize 82XX ISP flags */
2588 qla82xx_init_flags(ha);
2589 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002590 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002591 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002592 ha->device_type |= DT_ZIO_SUPPORTED;
2593 ha->device_type |= DT_FWI2;
2594 ha->device_type |= DT_IIDMA;
2595 ha->device_type |= DT_T10_PI;
2596 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2597 break;
2598 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002599 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002600 ha->device_type |= DT_ZIO_SUPPORTED;
2601 ha->device_type |= DT_FWI2;
2602 ha->device_type |= DT_IIDMA;
2603 ha->device_type |= DT_T10_PI;
2604 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2605 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002606 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002607 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002608 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002609 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002610 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002611 ha->device_type |= DT_ZIO_SUPPORTED;
2612 ha->device_type |= DT_FWI2;
2613 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002614 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002615 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2616 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002617 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002618 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002619 ha->device_type |= DT_ZIO_SUPPORTED;
2620 ha->device_type |= DT_FWI2;
2621 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002622 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002623 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2624 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002625 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002626 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002627 ha->device_type |= DT_ZIO_SUPPORTED;
2628 ha->device_type |= DT_FWI2;
2629 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002630 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002631 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2632 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002633 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002634
Giridhar Malavalia9083012010-04-12 17:59:55 -07002635 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002636 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002637 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002638 /* Get adapter physical port no from interrupt pin register. */
2639 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002640 if (IS_QLA27XX(ha))
2641 ha->port_no--;
2642 else
2643 ha->port_no = !(ha->port_no & 1);
2644 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002645
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002646 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002647 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002648 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002649}
2650
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002651static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002652qla2xxx_scan_start(struct Scsi_Host *shost)
2653{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002654 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002655
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002656 if (vha->hw->flags.running_gold_fw)
2657 return;
2658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002659 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2660 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2661 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2662 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002663}
2664
2665static int
2666qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2667{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002669
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002670 if (test_bit(UNLOADING, &vha->dpc_flags))
2671 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002673 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002675 return 1;
2676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002678}
2679
Quinn Tranec7193e2017-03-15 09:48:55 -07002680static void qla2x00_iocb_work_fn(struct work_struct *work)
2681{
2682 struct scsi_qla_host *vha = container_of(work,
2683 struct scsi_qla_host, iocb_work);
2684 int cnt = 0;
2685
2686 while (!list_empty(&vha->work_list)) {
2687 qla2x00_do_work(vha);
2688 cnt++;
2689 if (cnt > 10)
2690 break;
2691 }
2692}
2693
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694/*
2695 * PCI driver interface
2696 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002697static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002698qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002700 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002702 scsi_qla_host_t *base_vha = NULL;
2703 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002704 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002705 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002706 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002707 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002709 struct req_que *req = NULL;
2710 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002711 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002712
Andrew Vasquez285d0322007-10-19 15:59:17 -07002713 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002714 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002715 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2716 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002717 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002718 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2719 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002720 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002721 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002722 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2723 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002724 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002725 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002726 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002727 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002728 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2729 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002730 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002731 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002732 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2733 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002734 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002735 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2736 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002737
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002738 if (mem_only) {
2739 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002740 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002741 } else {
2742 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002743 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Jesse Barnes09276782008-10-18 17:33:19 -07002746 /* This may fail but that's ok */
2747 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002748
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002749 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2750 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002751 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2752 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002753 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002755 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2756 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002758 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2759 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002760 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002761 spin_lock_init(&ha->tgt.atio_lock);
2762
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002763 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
2765 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002766 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002767 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002768 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002769 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002770 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002771 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002773 /* Set ISP-type information. */
2774 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002775
2776 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002777 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002778 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002779 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002780
Chad Dupuiscba1e472011-11-18 09:03:21 -08002781 ha->prev_topology = 0;
2782 ha->init_cb_size = sizeof(init_cb_t);
2783 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2784 ha->optrom_size = OPTROM_SIZE_2300;
2785
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002786 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002788 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 req_length = REQUEST_ENTRY_CNT_2100;
2791 rsp_length = RESPONSE_ENTRY_CNT_2100;
2792 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002793 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002794 ha->flash_conf_off = ~0;
2795 ha->flash_data_off = ~0;
2796 ha->nvram_conf_off = ~0;
2797 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002798 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002800 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002801 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 req_length = REQUEST_ENTRY_CNT_2200;
2803 rsp_length = RESPONSE_ENTRY_CNT_2100;
2804 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002805 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002806 ha->flash_conf_off = ~0;
2807 ha->flash_data_off = ~0;
2808 ha->nvram_conf_off = ~0;
2809 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002810 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002811 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002812 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 req_length = REQUEST_ENTRY_CNT_2200;
2815 rsp_length = RESPONSE_ENTRY_CNT_2300;
2816 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002817 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002818 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2819 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002820 ha->flash_conf_off = ~0;
2821 ha->flash_data_off = ~0;
2822 ha->nvram_conf_off = ~0;
2823 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002824 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002825 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002826 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002827 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 req_length = REQUEST_ENTRY_CNT_24XX;
2829 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002830 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002831 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002832 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002833 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002834 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002835 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002836 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002837 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2838 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2839 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2840 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002841 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002842 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002843 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 req_length = REQUEST_ENTRY_CNT_24XX;
2845 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002846 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002848 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002849 ha->gid_list_info_size = 8;
2850 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002851 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002852 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002853 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2854 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2855 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2856 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2857 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002858 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002859 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2860 req_length = REQUEST_ENTRY_CNT_24XX;
2861 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002862 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002863 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2864 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2865 ha->gid_list_info_size = 8;
2866 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002867 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002868 ha->isp_ops = &qla81xx_isp_ops;
2869 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2870 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2871 ha->nvram_conf_off = ~0;
2872 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002873 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002874 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002875 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2876 req_length = REQUEST_ENTRY_CNT_82XX;
2877 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2878 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2879 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2880 ha->gid_list_info_size = 8;
2881 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002882 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002883 ha->isp_ops = &qla82xx_isp_ops;
2884 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2885 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2886 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2887 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002888 } else if (IS_QLA8044(ha)) {
2889 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2890 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2891 req_length = REQUEST_ENTRY_CNT_82XX;
2892 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2893 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2894 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2895 ha->gid_list_info_size = 8;
2896 ha->optrom_size = OPTROM_SIZE_83XX;
2897 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2898 ha->isp_ops = &qla8044_isp_ops;
2899 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2900 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2901 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2902 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002903 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002904 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002905 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002906 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002907 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002908 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002909 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002910 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2911 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2912 ha->gid_list_info_size = 8;
2913 ha->optrom_size = OPTROM_SIZE_83XX;
2914 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2915 ha->isp_ops = &qla83xx_isp_ops;
2916 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2917 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2918 ha->nvram_conf_off = ~0;
2919 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002920 } else if (IS_QLAFX00(ha)) {
2921 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2922 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2923 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2924 req_length = REQUEST_ENTRY_CNT_FX00;
2925 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002926 ha->isp_ops = &qlafx00_isp_ops;
2927 ha->port_down_retry_count = 30; /* default value */
2928 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2929 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002930 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002931 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002932 ha->mr.host_info_resend = false;
2933 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002934 } else if (IS_QLA27XX(ha)) {
2935 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2936 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2937 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002938 req_length = REQUEST_ENTRY_CNT_83XX;
2939 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002940 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002941 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2942 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2943 ha->gid_list_info_size = 8;
2944 ha->optrom_size = OPTROM_SIZE_83XX;
2945 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2946 ha->isp_ops = &qla27xx_isp_ops;
2947 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2948 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2949 ha->nvram_conf_off = ~0;
2950 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002952
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002953 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2954 "mbx_count=%d, req_length=%d, "
2955 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002956 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2957 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002958 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2959 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002960 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002961 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2962 "isp_ops=%p, flash_conf_off=%d, "
2963 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2964 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2965 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002966
2967 /* Configure PCI I/O space */
2968 ret = ha->isp_ops->iospace_config(ha);
2969 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002970 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002971
2972 ql_log_pci(ql_log_info, pdev, 0x001d,
2973 "Found an ISP%04X irq %d iobase 0x%p.\n",
2974 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002975 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08002976 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002977 init_completion(&ha->mbx_cmd_comp);
2978 complete(&ha->mbx_cmd_comp);
2979 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002980 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002981 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002983 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
Andrew Vasquez53303c42009-01-22 09:45:37 -08002985 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002986 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2987 "64 Bit addressing is %s.\n",
2988 ha->flags.enable_64bit_addressing ? "enable" :
2989 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002990 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002991 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002992 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2993 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 goto probe_hw_failed;
2996 }
2997
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002998 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003000 req->max_q_depth = ql2xmaxqdepth;
3001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002
3003 base_vha = qla2x00_create_host(sht, ha);
3004 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003005 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003006 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003007 qla2x00_free_req_que(ha, req);
3008 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 }
3011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003013 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003016 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003017 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003019 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3021 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003022
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003023 /* Setup fcport template structure. */
3024 ha->mr.fcport.vha = base_vha;
3025 ha->mr.fcport.port_type = FCT_UNKNOWN;
3026 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3027 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3028 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3029 ha->mr.fcport.scan_state = 1;
3030
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003031 /* Set the SG table size based on ISP type */
3032 if (!IS_FWI2_CAPABLE(ha)) {
3033 if (IS_QLA2100(ha))
3034 host->sg_tablesize = 32;
3035 } else {
3036 if (!IS_QLA82XX(ha))
3037 host->sg_tablesize = QLA_SG_ALL;
3038 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003039 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003040 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003041 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003042 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003043 host->max_cmd_len = 32;
3044 else
3045 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003046 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003047 /* Older HBAs support only 16-bit LUNs */
3048 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3049 ql2xmaxlun > 0xffff)
3050 host->max_lun = 0xffff;
3051 else
3052 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003053 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003054 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003055
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003056 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3057 "max_id=%d this_id=%d "
3058 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003059 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003060 host->this_id, host->cmd_per_lun, host->unique_id,
3061 host->max_cmd_len, host->max_channel, host->max_lun,
3062 host->transportt, sht->vendor_id);
3063
Michael Hernandezd7459522016-12-12 14:40:07 -08003064 /* Set up the irqs */
3065 ret = qla2x00_request_irqs(ha, rsp);
3066 if (ret)
3067 goto probe_init_failed;
3068
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003069 /* Alloc arrays of request and response ring ptrs */
3070 if (!qla2x00_alloc_queues(ha, req, rsp)) {
3071 ql_log(ql_log_fatal, base_vha, 0x003d,
3072 "Failed to allocate memory for queue pointers..."
3073 "aborting.\n");
3074 goto probe_init_failed;
3075 }
3076
Michael Hernandez56012362016-12-12 14:40:08 -08003077 if (ha->mqenable && shost_use_blk_mq(host)) {
3078 /* number of hardware queues supported by blk/scsi-mq*/
3079 host->nr_hw_queues = ha->max_qpairs;
3080
3081 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3082 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3083 } else
3084 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3085 "blk/scsi-mq disabled.\n");
3086
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003087 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003088
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003089 pci_save_state(pdev);
3090
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003091 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003092 rsp->req = req;
3093 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003094
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003095 if (IS_QLAFX00(ha)) {
3096 ha->rsp_q_map[0] = rsp;
3097 ha->req_q_map[0] = req;
3098 set_bit(0, ha->req_qid_map);
3099 set_bit(0, ha->rsp_qid_map);
3100 }
3101
Andrew Vasquez08029992009-03-24 09:07:55 -07003102 /* FWI2-capable only. */
3103 req->req_q_in = &ha->iobase->isp24.req_q_in;
3104 req->req_q_out = &ha->iobase->isp24.req_q_out;
3105 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3106 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003107 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003108 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3109 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3110 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3111 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003112 }
3113
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003114 if (IS_QLAFX00(ha)) {
3115 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3116 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3117 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3118 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3119 }
3120
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003121 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003122 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3123 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3124 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3125 }
3126
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003127 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3128 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3129 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3130 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3131 "req->req_q_in=%p req->req_q_out=%p "
3132 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3133 req->req_q_in, req->req_q_out,
3134 rsp->rsp_q_in, rsp->rsp_q_out);
3135 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3136 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3137 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3138 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3139 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3140 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003142 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003143 ql_log(ql_log_fatal, base_vha, 0x00d6,
3144 "Failed to initialize adapter - Adapter flags %x.\n",
3145 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146
Giridhar Malavalia9083012010-04-12 17:59:55 -07003147 if (IS_QLA82XX(ha)) {
3148 qla82xx_idc_lock(ha);
3149 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003150 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003151 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003152 ql_log(ql_log_fatal, base_vha, 0x00d7,
3153 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003154 } else if (IS_QLA8044(ha)) {
3155 qla8044_idc_lock(ha);
3156 qla8044_wr_direct(base_vha,
3157 QLA8044_CRB_DEV_STATE_INDEX,
3158 QLA8XXX_DEV_FAILED);
3159 qla8044_idc_unlock(ha);
3160 ql_log(ql_log_fatal, base_vha, 0x0150,
3161 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003162 }
3163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 ret = -ENODEV;
3165 goto probe_failed;
3166 }
3167
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003168 if (IS_QLAFX00(ha))
3169 host->can_queue = QLAFX00_MAX_CANQUEUE;
3170 else
3171 host->can_queue = req->num_outstanding_cmds - 10;
3172
3173 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3174 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3175 host->can_queue, base_vha->req,
3176 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3177
Quinn Trane326d222017-06-13 20:47:18 -07003178 if (ha->mqenable) {
3179 bool mq = false;
3180 bool startit = false;
Quinn Tran18ada182017-08-23 15:05:05 -07003181 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
Quinn Trane326d222017-06-13 20:47:18 -07003182
3183 if (QLA_TGT_MODE_ENABLED()) {
3184 mq = true;
3185 startit = false;
3186 }
3187
3188 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3189 shost_use_blk_mq(host)) {
3190 mq = true;
3191 startit = true;
3192 }
3193
3194 if (mq) {
3195 /* Create start of day qpairs for Block MQ */
Michael Hernandez56012362016-12-12 14:40:08 -08003196 for (i = 0; i < ha->max_qpairs; i++)
Quinn Trane326d222017-06-13 20:47:18 -07003197 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003198 }
3199 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003200
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003201 if (ha->flags.running_gold_fw)
3202 goto skip_dpc;
3203
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204 /*
3205 * Startup the kernel thread for this host adapter
3206 */
3207 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003208 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003210 ql_log(ql_log_fatal, base_vha, 0x00ed,
3211 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 ret = PTR_ERR(ha->dpc_thread);
3213 goto probe_failed;
3214 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003215 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3216 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003218 /*
3219 * If we're not coming up in initiator mode, we might sit for
3220 * a while without waking up the dpc thread, which leads to a
3221 * stuck process warning. So just kick the dpc once here and
3222 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3223 */
3224 qla2xxx_wake_dpc(base_vha);
3225
Quinn Tranec7193e2017-03-15 09:48:55 -07003226 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003227 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3228
Saurav Kashyap81178772012-08-22 14:21:04 -04003229 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3230 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3231 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3232 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3233
3234 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3235 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3236 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3237 INIT_WORK(&ha->idc_state_handler,
3238 qla83xx_idc_state_handler_work);
3239 INIT_WORK(&ha->nic_core_unrecoverable,
3240 qla83xx_nic_core_unrecoverable_work);
3241 }
3242
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003243skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003244 list_add_tail(&base_vha->list, &ha->vp_list);
3245 base_vha->host->irq = ha->pdev->irq;
3246
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003248 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003249 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3250 "Started qla2x00_timer with "
3251 "interval=%d.\n", WATCH_INTERVAL);
3252 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3253 "Detected hba at address=%p.\n",
3254 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
Arun Easie02587d2011-08-16 11:29:23 -07003256 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003257 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003258 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003259 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003260 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3261 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003262 if (ql2xenabledif == 1)
3263 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003264 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003265 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003266 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003267 | SHOST_DIF_TYPE3_PROTECTION
3268 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003269 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003270 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003271
3272 guard = SHOST_DIX_GUARD_CRC;
3273
3274 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3275 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3276 guard |= SHOST_DIX_GUARD_IP;
3277
3278 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003279 } else
3280 base_vha->flags.difdix_supported = 0;
3281 }
3282
Giridhar Malavalia9083012010-04-12 17:59:55 -07003283 ha->isp_ops->enable_intrs(ha);
3284
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003285 if (IS_QLAFX00(ha)) {
3286 ret = qlafx00_fx_disc(base_vha,
3287 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3288 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3289 QLA_SG_ALL : 128;
3290 }
3291
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003292 ret = scsi_add_host(host, &pdev->dev);
3293 if (ret)
3294 goto probe_failed;
3295
Michael Reed14864002009-12-02 09:11:16 -06003296 base_vha->flags.init_done = 1;
3297 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003298 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003299
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003300 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3301 "Init done and hba is online.\n");
3302
Quinn Tran726b8542017-01-19 22:28:00 -08003303 if (qla_ini_mode_enabled(base_vha) ||
3304 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003305 scsi_scan_host(host);
3306 else
3307 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3308 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003309
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003311
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003312 if (IS_QLAFX00(ha)) {
3313 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003314 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3315
3316 /* Register system information */
3317 ret = qlafx00_fx_disc(base_vha,
3318 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3319 }
3320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003321 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003324
Armen Baloyan03eb9122013-10-30 03:38:22 -04003325 ql_log(ql_log_info, base_vha, 0x00fb,
3326 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003327 ql_log(ql_log_info, base_vha, 0x00fc,
3328 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3329 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3330 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3331 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003332 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003334 qlt_add_target(ha, base_vha);
3335
Joe Lawrence6b383972014-08-26 17:12:29 -04003336 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003337
3338 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3339 return -ENODEV;
3340
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003341 if (ha->flags.detected_lr_sfp) {
3342 ql_log(ql_log_info, base_vha, 0xffff,
3343 "Reset chip to pick up LR SFP setting\n");
3344 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3345 qla2xxx_wake_dpc(base_vha);
3346 }
3347
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 return 0;
3349
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003350probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003351 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003352 ha->req_q_map[0] = NULL;
3353 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003354 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003355 ha->rsp_q_map[0] = NULL;
3356 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003357 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003358
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003360 if (base_vha->timer_active)
3361 qla2x00_stop_timer(base_vha);
3362 base_vha->flags.online = 0;
3363 if (ha->dpc_thread) {
3364 struct task_struct *t = ha->dpc_thread;
3365
3366 ha->dpc_thread = NULL;
3367 kthread_stop(t);
3368 }
3369
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003375 qla2x00_clear_drv_active(ha);
3376
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003377iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003378 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003379 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003380 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003381 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003382 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003383 } else {
3384 if (ha->iobase)
3385 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003386 if (ha->cregbase)
3387 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003388 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 pci_release_selected_regions(ha->pdev, ha->bars);
3390 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003392disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003393 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003394 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
Adrian Bunk4c993f72008-01-14 00:55:16 -08003397static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003398qla2x00_shutdown(struct pci_dev *pdev)
3399{
3400 scsi_qla_host_t *vha;
3401 struct qla_hw_data *ha;
3402
3403 vha = pci_get_drvdata(pdev);
3404 ha = vha->hw;
3405
Sawan Chandakefdb5762017-08-23 15:05:00 -07003406 ql_log(ql_log_info, vha, 0xfffa,
3407 "Adapter shutdown\n");
3408
3409 /*
3410 * Prevent future board_disable and wait
3411 * until any pending board_disable has completed.
3412 */
3413 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3414 cancel_work_sync(&ha->board_disable);
3415
3416 if (!atomic_read(&pdev->enable_cnt))
3417 return;
3418
Armen Baloyan42479342013-08-27 01:37:37 -04003419 /* Notify ISPFX00 firmware */
3420 if (IS_QLAFX00(ha))
3421 qlafx00_driver_shutdown(vha, 20);
3422
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003423 /* Turn-off FCE trace */
3424 if (ha->flags.fce_enabled) {
3425 qla2x00_disable_fce_trace(vha, NULL, NULL);
3426 ha->flags.fce_enabled = 0;
3427 }
3428
3429 /* Turn-off EFT trace */
3430 if (ha->eft)
3431 qla2x00_disable_eft_trace(vha);
3432
3433 /* Stop currently executing firmware. */
3434 qla2x00_try_to_stop_firmware(vha);
3435
3436 /* Turn adapter off line */
3437 vha->flags.online = 0;
3438
3439 /* turn-off interrupts on the card */
3440 if (ha->interrupts_on) {
3441 vha->flags.init_done = 0;
3442 ha->isp_ops->disable_intrs(ha);
3443 }
3444
3445 qla2x00_free_irqs(vha);
3446
3447 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003448
Chad Dupuis61d41f62014-09-25 05:17:02 -04003449 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003450 ql_log(ql_log_info, vha, 0xfffe,
3451 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003452}
3453
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003454/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003455static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003456qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003458 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003459 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
Arun Easi43ebf162011-05-10 11:18:16 -07003461 mutex_lock(&ha->vport_lock);
3462 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003463 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003464
Arun Easi43ebf162011-05-10 11:18:16 -07003465 BUG_ON(base_vha->list.next == &ha->vp_list);
3466 /* This assumes first entry in ha->vp_list is always base vha */
3467 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003468 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003469
Arun Easi43ebf162011-05-10 11:18:16 -07003470 spin_unlock_irqrestore(&ha->vport_slock, flags);
3471 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003472
Arun Easi43ebf162011-05-10 11:18:16 -07003473 fc_vport_terminate(vha->fc_vport);
3474 scsi_host_put(vha->host);
3475
3476 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 }
Arun Easi43ebf162011-05-10 11:18:16 -07003478 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003479}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003480
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003481/* Stops all deferred work threads */
3482static void
3483qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3484{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003485 /* Cancel all work and destroy DPC workqueues */
3486 if (ha->dpc_lp_wq) {
3487 cancel_work_sync(&ha->idc_aen);
3488 destroy_workqueue(ha->dpc_lp_wq);
3489 ha->dpc_lp_wq = NULL;
3490 }
3491
3492 if (ha->dpc_hp_wq) {
3493 cancel_work_sync(&ha->nic_core_reset);
3494 cancel_work_sync(&ha->idc_state_handler);
3495 cancel_work_sync(&ha->nic_core_unrecoverable);
3496 destroy_workqueue(ha->dpc_hp_wq);
3497 ha->dpc_hp_wq = NULL;
3498 }
3499
Andrew Vasquezb9978762009-03-24 09:08:05 -07003500 /* Kill the kernel thread for this host */
3501 if (ha->dpc_thread) {
3502 struct task_struct *t = ha->dpc_thread;
3503
3504 /*
3505 * qla2xxx_wake_dpc checks for ->dpc_thread
3506 * so we need to zero it out.
3507 */
3508 ha->dpc_thread = NULL;
3509 kthread_stop(t);
3510 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003511}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003512
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003513static void
3514qla2x00_unmap_iobases(struct qla_hw_data *ha)
3515{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003516 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003517
Chad Dupuisf73cb692014-02-26 04:15:06 -05003518 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003519 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003520 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003521 } else {
3522 if (ha->iobase)
3523 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003524
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003525 if (ha->cregbase)
3526 iounmap(ha->cregbase);
3527
Giridhar Malavalia9083012010-04-12 17:59:55 -07003528 if (ha->mqiobase)
3529 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003530
Chad Dupuisf73cb692014-02-26 04:15:06 -05003531 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003532 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003533 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003534}
3535
3536static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003537qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003538{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003539 if (IS_QLA8044(ha)) {
3540 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003541 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003542 qla8044_idc_unlock(ha);
3543 } else if (IS_QLA82XX(ha)) {
3544 qla82xx_idc_lock(ha);
3545 qla82xx_clear_drv_active(ha);
3546 qla82xx_idc_unlock(ha);
3547 }
3548}
3549
3550static void
3551qla2x00_remove_one(struct pci_dev *pdev)
3552{
3553 scsi_qla_host_t *base_vha;
3554 struct qla_hw_data *ha;
3555
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003556 base_vha = pci_get_drvdata(pdev);
3557 ha = base_vha->hw;
3558
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003559 /* Indicate device removal to prevent future board_disable and wait
3560 * until any pending board_disable has completed. */
3561 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3562 cancel_work_sync(&ha->board_disable);
3563
3564 /*
3565 * If the PCI device is disabled then there was a PCI-disconnect and
3566 * qla2x00_disable_board_on_pci_error has taken care of most of the
3567 * resources.
3568 */
3569 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003570 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3571 base_vha->gnl.l, base_vha->gnl.ldma);
3572
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003573 scsi_host_put(base_vha->host);
3574 kfree(ha);
3575 pci_set_drvdata(pdev, NULL);
3576 return;
3577 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003578 qla2x00_wait_for_hba_ready(base_vha);
3579
Quinn Tran726b8542017-01-19 22:28:00 -08003580 /*
3581 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003582 * where it was set first.
3583 */
3584 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3585 return;
3586
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003587 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003588
3589 qla_nvme_delete(base_vha);
3590
Quinn Tran726b8542017-01-19 22:28:00 -08003591 dma_free_coherent(&ha->pdev->dev,
3592 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003593
3594 if (IS_QLAFX00(ha))
3595 qlafx00_driver_shutdown(base_vha, 20);
3596
3597 qla2x00_delete_all_vps(ha, base_vha);
3598
3599 if (IS_QLA8031(ha)) {
3600 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3601 "Clearing fcoe driver presence.\n");
3602 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3603 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3604 "Error while clearing DRV-Presence.\n");
3605 }
3606
3607 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3608
3609 qla2x00_dfs_remove(base_vha);
3610
3611 qla84xx_put_chip(base_vha);
3612
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003613 /* Laser should be disabled only for ISP2031 */
3614 if (IS_QLA2031(ha))
3615 qla83xx_disable_laser(base_vha);
3616
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003617 /* Disable timer */
3618 if (base_vha->timer_active)
3619 qla2x00_stop_timer(base_vha);
3620
3621 base_vha->flags.online = 0;
3622
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003623 /* free DMA memory */
3624 if (ha->exlogin_buf)
3625 qla2x00_free_exlogin_buffer(ha);
3626
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003627 /* free DMA memory */
3628 if (ha->exchoffld_buf)
3629 qla2x00_free_exchoffld_buffer(ha);
3630
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003631 qla2x00_destroy_deferred_work(ha);
3632
3633 qlt_remove_target(ha, base_vha);
3634
3635 qla2x00_free_sysfs_attr(base_vha, true);
3636
3637 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003638 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003639
3640 scsi_remove_host(base_vha->host);
3641
3642 qla2x00_free_device(base_vha);
3643
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003644 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003645
Arun Easid2749ff2014-09-25 05:16:51 -04003646 scsi_host_put(base_vha->host);
3647
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003648 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650 pci_release_selected_regions(ha->pdev, ha->bars);
3651 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003653 pci_disable_pcie_error_reporting(pdev);
3654
Bernhard Walle665db932007-03-28 00:49:49 +02003655 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657
3658static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003659qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003661 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
Andrew Vasquez85880802009-12-15 21:29:46 -08003663 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3664
3665 /* Disable timer */
3666 if (vha->timer_active)
3667 qla2x00_stop_timer(vha);
3668
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003669 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003670
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003671 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003672 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003673
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003674 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003676
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003677 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679
Andrew Vasquez85880802009-12-15 21:29:46 -08003680 vha->flags.online = 0;
3681
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003682 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003683 if (ha->interrupts_on) {
3684 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003685 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003686 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003687
Quinn Tran093df732016-12-12 14:40:09 -08003688 qla2x00_free_fcports(vha);
3689
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003690 qla2x00_free_irqs(vha);
3691
Quinn Tran093df732016-12-12 14:40:09 -08003692 /* Flush the work queue and remove it */
3693 if (ha->wq) {
3694 flush_workqueue(ha->wq);
3695 destroy_workqueue(ha->wq);
3696 ha->wq = NULL;
3697 }
3698
Chad Dupuis88670482010-07-23 15:28:30 +05003699
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003700 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003701
Giridhar Malavali08de2842011-08-16 11:31:44 -07003702 qla82xx_md_free(vha);
3703
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003704 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705}
3706
Chad Dupuis88670482010-07-23 15:28:30 +05003707void qla2x00_free_fcports(struct scsi_qla_host *vha)
3708{
3709 fc_port_t *fcport, *tfcport;
3710
3711 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3712 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003713 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003714 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003715 }
3716}
3717
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003718static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003719qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003720 int defer)
3721{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003722 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003723 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003724 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003725
3726 if (!fcport->rport)
3727 return;
3728
3729 rport = fcport->rport;
3730 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003731 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003732 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003733 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003734 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003735 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003736 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3737 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003738 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003739 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003740 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003741 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3742 "%s %8phN. rport %p roles %x\n",
3743 __func__, fcport->port_name, rport,
3744 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003745 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003746 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003747 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003748 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003749}
3750
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3753 *
3754 * Input: ha = adapter block pointer. fcport = port structure pointer.
3755 *
3756 * Return: None.
3757 *
3758 * Context:
3759 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003760void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003761 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003763 if (IS_QLAFX00(vha->hw)) {
3764 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3765 qla2x00_schedule_rport_del(vha, fcport, defer);
3766 return;
3767 }
3768
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003769 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003770 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003771 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003772 qla2x00_schedule_rport_del(vha, fcport, defer);
3773 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003774 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 * We may need to retry the login, so don't change the state of the
3776 * port but do the retries.
3777 */
3778 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003779 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780
3781 if (!do_login)
3782 return;
3783
Arun Easia1d02852015-08-04 13:38:02 -04003784 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3785
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788
Quinn Tran83548fe2017-06-02 09:12:01 -07003789 ql_dbg(ql_dbg_disc, vha, 0x20a3,
Quinn Tran726b8542017-01-19 22:28:00 -08003790 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003791 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 }
3793}
3794
3795/*
3796 * qla2x00_mark_all_devices_lost
3797 * Updates fcport state when device goes offline.
3798 *
3799 * Input:
3800 * ha = adapter block pointer.
3801 * fcport = port structure pointer.
3802 *
3803 * Return:
3804 * None.
3805 *
3806 * Context:
3807 */
3808void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810{
3811 fc_port_t *fcport;
3812
Quinn Tran83548fe2017-06-02 09:12:01 -07003813 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3814 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003817 fcport->scan_state = 0;
3818 qlt_schedule_sess_for_deletion_lock(fcport);
3819
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003820 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003822
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 /*
3824 * No point in marking the device as lost, if the device is
3825 * already DEAD.
3826 */
3827 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3828 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003830 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003831 if (defer)
3832 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003833 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003834 qla2x00_schedule_rport_del(vha, fcport, defer);
3835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 }
3837}
3838
3839/*
3840* qla2x00_mem_alloc
3841* Allocates adapter memory.
3842*
3843* Returns:
3844* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003845* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003847static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003848qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3849 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850{
3851 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
Andrew Vasqueze8711082008-01-31 12:33:48 -08003853 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003854 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003855 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003858 if (qlt_mem_alloc(ha) < 0)
3859 goto fail_free_init_cb;
3860
Chad Dupuis642ef982012-02-09 11:15:57 -08003861 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3862 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003864 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865
Andrew Vasqueze8711082008-01-31 12:33:48 -08003866 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3867 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003868 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003870 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003871 /* Allocate cache for CT6 Ctx. */
3872 if (!ctx_cachep) {
3873 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3874 sizeof(struct ct6_dsd), 0,
3875 SLAB_HWCACHE_ALIGN, NULL);
3876 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003877 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003878 }
3879 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3880 ctx_cachep);
3881 if (!ha->ctx_mempool)
3882 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003883 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3884 "ctx_cachep=%p ctx_mempool=%p.\n",
3885 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003886 }
3887
Andrew Vasqueze8711082008-01-31 12:33:48 -08003888 /* Get memory for cached NVRAM */
3889 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3890 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003891 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003893 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3894 ha->pdev->device);
3895 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3896 DMA_POOL_SIZE, 8, 0);
3897 if (!ha->s_dma_pool)
3898 goto fail_free_nvram;
3899
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003900 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3901 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3902 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3903
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003904 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003905 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3906 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3907 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003908 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3909 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003910 goto fail_s_dma_pool;
3911 }
3912
3913 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3914 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3915 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003916 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3917 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003918 goto fail_dl_dma_pool;
3919 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003920 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3921 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3922 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003923 }
3924
Andrew Vasqueze8711082008-01-31 12:33:48 -08003925 /* Allocate memory for SNS commands */
3926 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003927 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003928 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003929 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003930 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003931 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003932 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003933 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003934 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003936 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003937 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003938 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003939 goto fail_dma_pool;
3940 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003941 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003942 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003943 if (!ha->ct_sns)
3944 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003945 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3946 "ms_iocb=%p ct_sns=%p.\n",
3947 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 }
3949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003950 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003951 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3952 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003953 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3954 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003955 goto fail_req;
3956 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003957 (*req)->length = req_len;
3958 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3959 ((*req)->length + 1) * sizeof(request_t),
3960 &(*req)->dma, GFP_KERNEL);
3961 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003962 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3963 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003964 goto fail_req_ring;
3965 }
3966 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003967 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3968 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003969 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3970 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 goto fail_rsp;
3972 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003973 (*rsp)->hw = ha;
3974 (*rsp)->length = rsp_len;
3975 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3976 ((*rsp)->length + 1) * sizeof(response_t),
3977 &(*rsp)->dma, GFP_KERNEL);
3978 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003979 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3980 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 goto fail_rsp_ring;
3982 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003983 (*req)->rsp = *rsp;
3984 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003985 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3986 "req=%p req->length=%d req->ring=%p rsp=%p "
3987 "rsp->length=%d rsp->ring=%p.\n",
3988 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3989 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003990 /* Allocate memory for NVRAM data for vports */
3991 if (ha->nvram_npiv_size) {
3992 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003993 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003994 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003995 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3996 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003997 goto fail_npiv_info;
3998 }
3999 } else
4000 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004002 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004003 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004004 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4005 &ha->ex_init_cb_dma);
4006 if (!ha->ex_init_cb)
4007 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004008 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4009 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004010 }
4011
Giridhar Malavalia9083012010-04-12 17:59:55 -07004012 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4013
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004014 /* Get consistent memory allocated for Async Port-Database. */
4015 if (!IS_FWI2_CAPABLE(ha)) {
4016 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4017 &ha->async_pd_dma);
4018 if (!ha->async_pd)
4019 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004020 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4021 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004022 }
4023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004024 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004025
4026 /* Allocate memory for our loop_id bitmap */
4027 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
4028 GFP_KERNEL);
4029 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004030 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004031 else {
4032 qla2x00_set_reserved_loop_ids(ha);
4033 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004034 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004035 }
4036
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004037 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4038 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4039 if (!ha->sfp_data) {
4040 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4041 "Unable to allocate memory for SFP read-data.\n");
4042 goto fail_sfp_data;
4043 }
4044
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004045 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004046
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004047fail_sfp_data:
4048 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004049fail_loop_id_map:
4050 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004051fail_async_pd:
4052 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004053fail_ex_init_cb:
4054 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004055fail_npiv_info:
4056 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4057 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4058 (*rsp)->ring = NULL;
4059 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004061 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004063 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4064 sizeof(request_t), (*req)->ring, (*req)->dma);
4065 (*req)->ring = NULL;
4066 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004068 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069fail_req:
4070 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4071 ha->ct_sns, ha->ct_sns_dma);
4072 ha->ct_sns = NULL;
4073 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004074fail_free_ms_iocb:
4075 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4076 ha->ms_iocb = NULL;
4077 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004078
4079 if (ha->sns_cmd)
4080 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4081 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004082fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004083 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004084 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4085 ha->fcp_cmnd_dma_pool = NULL;
4086 }
4087fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004088 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004089 dma_pool_destroy(ha->dl_dma_pool);
4090 ha->dl_dma_pool = NULL;
4091 }
4092fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004093 dma_pool_destroy(ha->s_dma_pool);
4094 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004095fail_free_nvram:
4096 kfree(ha->nvram);
4097 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004098fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004099 if (ha->ctx_mempool)
4100 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004101 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004102fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004103 if (ha->srb_mempool)
4104 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004105 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004106fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004107 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4108 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004109 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004110 ha->gid_list = NULL;
4111 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004112fail_free_tgt_mem:
4113 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004114fail_free_init_cb:
4115 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4116 ha->init_cb_dma);
4117 ha->init_cb = NULL;
4118 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004119fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004120 ql_log(ql_log_fatal, NULL, 0x0030,
4121 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004122 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123}
4124
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004125int
4126qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4127{
4128 int rval;
4129 uint16_t size, max_cnt, temp;
4130 struct qla_hw_data *ha = vha->hw;
4131
4132 /* Return if we don't need to alloacate any extended logins */
4133 if (!ql2xexlogins)
4134 return QLA_SUCCESS;
4135
Quinn Tran99e1b682017-06-02 09:12:03 -07004136 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4137 return QLA_SUCCESS;
4138
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004139 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4140 max_cnt = 0;
4141 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4142 if (rval != QLA_SUCCESS) {
4143 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4144 "Failed to get exlogin status.\n");
4145 return rval;
4146 }
4147
4148 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004149 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004150
Quinn Tran99e1b682017-06-02 09:12:03 -07004151 if (temp != ha->exlogin_size) {
4152 qla2x00_free_exlogin_buffer(ha);
4153 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004154
Quinn Tran99e1b682017-06-02 09:12:03 -07004155 ql_log(ql_log_info, vha, 0xd024,
4156 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4157 max_cnt, size, temp);
4158
4159 ql_log(ql_log_info, vha, 0xd025,
4160 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4161
4162 /* Get consistent memory for extended logins */
4163 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4164 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4165 if (!ha->exlogin_buf) {
4166 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004167 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004168 return -ENOMEM;
4169 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004170 }
4171
4172 /* Now configure the dma buffer */
4173 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4174 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004175 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004176 "Setup extended login buffer ****FAILED****.\n");
4177 qla2x00_free_exlogin_buffer(ha);
4178 }
4179
4180 return rval;
4181}
4182
4183/*
4184* qla2x00_free_exlogin_buffer
4185*
4186* Input:
4187* ha = adapter block pointer
4188*/
4189void
4190qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4191{
4192 if (ha->exlogin_buf) {
4193 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4194 ha->exlogin_buf, ha->exlogin_buf_dma);
4195 ha->exlogin_buf = NULL;
4196 ha->exlogin_size = 0;
4197 }
4198}
4199
Quinn Tran99e1b682017-06-02 09:12:03 -07004200static void
4201qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4202{
4203 u32 temp;
4204 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4205
4206 if (qla_ini_mode_enabled(vha)) {
4207 if (ql2xiniexchg > max_cnt)
4208 ql2xiniexchg = max_cnt;
4209
4210 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4211 *ret_cnt = ql2xiniexchg;
4212 } else if (qla_tgt_mode_enabled(vha)) {
4213 if (ql2xexchoffld > max_cnt)
4214 ql2xexchoffld = max_cnt;
4215
4216 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4217 *ret_cnt = ql2xexchoffld;
4218 } else if (qla_dual_mode_enabled(vha)) {
4219 temp = ql2xiniexchg + ql2xexchoffld;
4220 if (temp > max_cnt) {
4221 ql2xiniexchg -= (temp - max_cnt)/2;
4222 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4223 temp = max_cnt;
4224 }
4225
4226 if (temp > FW_DEF_EXCHANGES_CNT)
4227 *ret_cnt = temp;
4228 }
4229}
4230
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004231int
4232qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4233{
4234 int rval;
Quinn Tran99e1b682017-06-02 09:12:03 -07004235 u16 size, max_cnt;
4236 u32 temp;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004237 struct qla_hw_data *ha = vha->hw;
4238
Quinn Tran99e1b682017-06-02 09:12:03 -07004239 if (!ha->flags.exchoffld_enabled)
4240 return QLA_SUCCESS;
4241
4242 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004243 return QLA_SUCCESS;
4244
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004245 max_cnt = 0;
4246 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4247 if (rval != QLA_SUCCESS) {
4248 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4249 "Failed to get exlogin status.\n");
4250 return rval;
4251 }
4252
Quinn Tran99e1b682017-06-02 09:12:03 -07004253 qla2x00_number_of_exch(vha, &temp, max_cnt);
4254 temp *= size;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004255
Quinn Tran99e1b682017-06-02 09:12:03 -07004256 if (temp != ha->exchoffld_size) {
4257 qla2x00_free_exchoffld_buffer(ha);
4258 ha->exchoffld_size = temp;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004259
Quinn Tran99e1b682017-06-02 09:12:03 -07004260 ql_log(ql_log_info, vha, 0xd016,
4261 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
4262 max_cnt, size, temp);
4263
4264 ql_log(ql_log_info, vha, 0xd017,
4265 "Exchange Buffers requested size = 0x%x\n",
4266 ha->exchoffld_size);
4267
4268 /* Get consistent memory for extended logins */
4269 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4270 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4271 if (!ha->exchoffld_buf) {
4272 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4273 "Failed to allocate memory for exchoffld_buf_dma.\n");
4274 return -ENOMEM;
4275 }
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004276 }
4277
4278 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004279 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004280 if (rval) {
4281 ql_log(ql_log_fatal, vha, 0xd02e,
4282 "Setup exchange offload buffer ****FAILED****.\n");
4283 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004284 } else {
4285 /* re-adjust number of target exchange */
4286 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4287
4288 if (qla_ini_mode_enabled(vha))
4289 icb->exchange_count = 0;
4290 else
4291 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004292 }
4293
4294 return rval;
4295}
4296
4297/*
4298* qla2x00_free_exchoffld_buffer
4299*
4300* Input:
4301* ha = adapter block pointer
4302*/
4303void
4304qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4305{
4306 if (ha->exchoffld_buf) {
4307 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4308 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4309 ha->exchoffld_buf = NULL;
4310 ha->exchoffld_size = 0;
4311 }
4312}
4313
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004315* qla2x00_free_fw_dump
4316* Frees fw dump stuff.
4317*
4318* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004319* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004320*/
4321static void
4322qla2x00_free_fw_dump(struct qla_hw_data *ha)
4323{
4324 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004325 dma_free_coherent(&ha->pdev->dev,
4326 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004327
Chad Dupuisf73cb692014-02-26 04:15:06 -05004328 if (ha->eft)
4329 dma_free_coherent(&ha->pdev->dev,
4330 EFT_SIZE, ha->eft, ha->eft_dma);
4331
4332 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004333 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004334 if (ha->fw_dump_template)
4335 vfree(ha->fw_dump_template);
4336
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004337 ha->fce = NULL;
4338 ha->fce_dma = 0;
4339 ha->eft = NULL;
4340 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004341 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004342 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004343 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004344 ha->fw_dump = NULL;
4345 ha->fw_dump_len = 0;
4346 ha->fw_dump_template = NULL;
4347 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004348}
4349
4350/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351* qla2x00_mem_free
4352* Frees all adapter allocated memory.
4353*
4354* Input:
4355* ha = adapter block pointer.
4356*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004357static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004358qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004360 qla2x00_free_fw_dump(ha);
4361
Saurav Kashyap81178772012-08-22 14:21:04 -04004362 if (ha->mctp_dump)
4363 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4364 ha->mctp_dump_dma);
4365
Andrew Vasqueze8711082008-01-31 12:33:48 -08004366 if (ha->srb_mempool)
4367 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004369 if (ha->dcbx_tlv)
4370 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4371 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4372
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004373 if (ha->xgmac_data)
4374 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4375 ha->xgmac_data, ha->xgmac_data_dma);
4376
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 if (ha->sns_cmd)
4378 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004379 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380
4381 if (ha->ct_sns)
4382 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004383 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384
Andrew Vasquez88729e52006-06-23 16:10:50 -07004385 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004386 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4387 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004388
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 if (ha->ms_iocb)
4390 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4391
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004392 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004393 dma_pool_free(ha->s_dma_pool,
4394 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004395
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004396 if (ha->async_pd)
4397 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4398
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 if (ha->s_dma_pool)
4400 dma_pool_destroy(ha->s_dma_pool);
4401
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004403 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4404 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405
Giridhar Malavalia9083012010-04-12 17:59:55 -07004406 if (IS_QLA82XX(ha)) {
4407 if (!list_empty(&ha->gbl_dsd_list)) {
4408 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4409
4410 /* clean up allocated prev pool */
4411 list_for_each_entry_safe(dsd_ptr,
4412 tdsd_ptr, &ha->gbl_dsd_list, list) {
4413 dma_pool_free(ha->dl_dma_pool,
4414 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4415 list_del(&dsd_ptr->list);
4416 kfree(dsd_ptr);
4417 }
4418 }
4419 }
4420
4421 if (ha->dl_dma_pool)
4422 dma_pool_destroy(ha->dl_dma_pool);
4423
4424 if (ha->fcp_cmnd_dma_pool)
4425 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4426
4427 if (ha->ctx_mempool)
4428 mempool_destroy(ha->ctx_mempool);
4429
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004430 qlt_mem_free(ha);
4431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004432 if (ha->init_cb)
4433 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004434 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004435 vfree(ha->optrom_buffer);
4436 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004437 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08004438 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004439 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
Andrew Vasqueze8711082008-01-31 12:33:48 -08004441 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004442 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 ha->sns_cmd = NULL;
4444 ha->sns_cmd_dma = 0;
4445 ha->ct_sns = NULL;
4446 ha->ct_sns_dma = 0;
4447 ha->ms_iocb = NULL;
4448 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 ha->init_cb = NULL;
4450 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004451 ha->ex_init_cb = NULL;
4452 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004453 ha->async_pd = NULL;
4454 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
4456 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004457 ha->dl_dma_pool = NULL;
4458 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 ha->gid_list = NULL;
4461 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004462
4463 ha->tgt.atio_ring = NULL;
4464 ha->tgt.atio_dma = 0;
4465 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004466}
4467
4468struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4469 struct qla_hw_data *ha)
4470{
4471 struct Scsi_Host *host;
4472 struct scsi_qla_host *vha = NULL;
4473
4474 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004475 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004476 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4477 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004478 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004479 }
4480
4481 /* Clear our data area */
4482 vha = shost_priv(host);
4483 memset(vha, 0, sizeof(scsi_qla_host_t));
4484
4485 vha->host = host;
4486 vha->host_no = host->host_no;
4487 vha->hw = ha;
4488
4489 INIT_LIST_HEAD(&vha->vp_fcports);
4490 INIT_LIST_HEAD(&vha->work_list);
4491 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004492 INIT_LIST_HEAD(&vha->qla_cmd_list);
4493 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004494 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004495 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004496 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004497 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004498 INIT_LIST_HEAD(&vha->nvme_rport_list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004499
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004500 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004501 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004502 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004503 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004504
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004505 vha->gnl.size = sizeof(struct get_name_list_extended) *
4506 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004507 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4508 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4509 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004510 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004511 "Alloc failed for name list.\n");
4512 scsi_remove_host(vha->host);
4513 return NULL;
4514 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004515
4516 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004517 ql_dbg(ql_dbg_init, vha, 0x0041,
4518 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4519 vha->host, vha->hw, vha,
4520 dev_name(&(ha->pdev->dev)));
4521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004522 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523}
4524
Quinn Tran726b8542017-01-19 22:28:00 -08004525struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004526qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004527{
4528 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004529 uint8_t bail;
4530
4531 QLA_VHA_MARK_BUSY(vha, bail);
4532 if (bail)
4533 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004534
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004535 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004536 if (!e) {
4537 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004538 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004539 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004540
4541 INIT_LIST_HEAD(&e->list);
4542 e->type = type;
4543 e->flags = QLA_EVT_FLAG_FREE;
4544 return e;
4545}
4546
Quinn Tran726b8542017-01-19 22:28:00 -08004547int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004548qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004549{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004550 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004551
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004552 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004553 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004554 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004555
4556 if (QLA_EARLY_LINKUP(vha->hw))
4557 schedule_work(&vha->iocb_work);
4558 else
4559 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004560
Andrew Vasquez0971de72008-04-03 13:13:18 -07004561 return QLA_SUCCESS;
4562}
4563
4564int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004565qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004566 u32 data)
4567{
4568 struct qla_work_evt *e;
4569
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004570 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004571 if (!e)
4572 return QLA_FUNCTION_FAILED;
4573
4574 e->u.aen.code = code;
4575 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004576 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004577}
4578
Andrew Vasquez8a659572009-02-08 20:50:12 -08004579int
4580qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4581{
4582 struct qla_work_evt *e;
4583
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004584 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004585 if (!e)
4586 return QLA_FUNCTION_FAILED;
4587
4588 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004589 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004590}
4591
Andrew Vasquezac280b62009-08-20 11:06:05 -07004592#define qla2x00_post_async_work(name, type) \
4593int qla2x00_post_async_##name##_work( \
4594 struct scsi_qla_host *vha, \
4595 fc_port_t *fcport, uint16_t *data) \
4596{ \
4597 struct qla_work_evt *e; \
4598 \
4599 e = qla2x00_alloc_work(vha, type); \
4600 if (!e) \
4601 return QLA_FUNCTION_FAILED; \
4602 \
4603 e->u.logio.fcport = fcport; \
4604 if (data) { \
4605 e->u.logio.data[0] = data[0]; \
4606 e->u.logio.data[1] = data[1]; \
4607 } \
4608 return qla2x00_post_work(vha, e); \
4609}
4610
4611qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004612qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4613qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004614qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4615qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004616
Andrew Vasquez3420d362009-10-13 15:16:45 -07004617int
4618qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4619{
4620 struct qla_work_evt *e;
4621
4622 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4623 if (!e)
4624 return QLA_FUNCTION_FAILED;
4625
4626 e->u.uevent.code = code;
4627 return qla2x00_post_work(vha, e);
4628}
4629
4630static void
4631qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4632{
4633 char event_string[40];
4634 char *envp[] = { event_string, NULL };
4635
4636 switch (code) {
4637 case QLA_UEVENT_CODE_FW_DUMP:
4638 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4639 vha->host_no);
4640 break;
4641 default:
4642 /* do nothing */
4643 break;
4644 }
4645 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4646}
4647
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004648int
4649qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4650 uint32_t *data, int cnt)
4651{
4652 struct qla_work_evt *e;
4653
4654 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4655 if (!e)
4656 return QLA_FUNCTION_FAILED;
4657
4658 e->u.aenfx.evtcode = evtcode;
4659 e->u.aenfx.count = cnt;
4660 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4661 return qla2x00_post_work(vha, e);
4662}
4663
Quinn Tran726b8542017-01-19 22:28:00 -08004664int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4665{
4666 struct qla_work_evt *e;
4667
4668 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4669 if (!e)
4670 return QLA_FUNCTION_FAILED;
4671
4672 e->u.fcport.fcport = fcport;
4673 return qla2x00_post_work(vha, e);
4674}
4675
4676static
4677void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4678{
4679 unsigned long flags;
4680 fc_port_t *fcport = NULL;
4681 struct qlt_plogi_ack_t *pla =
4682 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
4683
4684 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4685 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4686 if (fcport) {
4687 fcport->d_id = e->u.new_sess.id;
4688 if (pla) {
4689 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4690 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4691 /* we took an extra ref_count to prevent PLOGI ACK when
4692 * fcport/sess has not been created.
4693 */
4694 pla->ref_count--;
4695 }
4696 } else {
4697 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4698 if (fcport) {
4699 fcport->d_id = e->u.new_sess.id;
4700 fcport->scan_state = QLA_FCPORT_FOUND;
4701 fcport->flags |= FCF_FABRIC_DEVICE;
4702 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4703
4704 memcpy(fcport->port_name, e->u.new_sess.port_name,
4705 WWN_SIZE);
4706 list_add_tail(&fcport->list, &vha->vp_fcports);
4707
4708 if (pla) {
4709 qlt_plogi_ack_link(vha, pla, fcport,
4710 QLT_PLOGI_LINK_SAME_WWN);
4711 pla->ref_count--;
4712 }
4713 }
4714 }
4715 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4716
4717 if (fcport) {
4718 if (pla)
4719 qlt_plogi_ack_unref(vha, pla);
4720 else
4721 qla24xx_async_gnl(vha, fcport);
4722 }
4723}
4724
Andrew Vasquezac280b62009-08-20 11:06:05 -07004725void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004726qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004727{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004728 struct qla_work_evt *e, *tmp;
4729 unsigned long flags;
4730 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004731
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004732 spin_lock_irqsave(&vha->work_lock, flags);
4733 list_splice_init(&vha->work_list, &work);
4734 spin_unlock_irqrestore(&vha->work_lock, flags);
4735
4736 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004737 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004738
4739 switch (e->type) {
4740 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004741 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004742 e->u.aen.code, e->u.aen.data);
4743 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004744 case QLA_EVT_IDC_ACK:
4745 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4746 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004747 case QLA_EVT_ASYNC_LOGIN:
4748 qla2x00_async_login(vha, e->u.logio.fcport,
4749 e->u.logio.data);
4750 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004751 case QLA_EVT_ASYNC_LOGOUT:
4752 qla2x00_async_logout(vha, e->u.logio.fcport);
4753 break;
4754 case QLA_EVT_ASYNC_LOGOUT_DONE:
4755 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4756 e->u.logio.data);
4757 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004758 case QLA_EVT_ASYNC_ADISC:
4759 qla2x00_async_adisc(vha, e->u.logio.fcport,
4760 e->u.logio.data);
4761 break;
4762 case QLA_EVT_ASYNC_ADISC_DONE:
4763 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4764 e->u.logio.data);
4765 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004766 case QLA_EVT_UEVENT:
4767 qla2x00_uevent_emit(vha, e->u.uevent.code);
4768 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004769 case QLA_EVT_AENFX:
4770 qlafx00_process_aen(vha, e);
4771 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004772 case QLA_EVT_GIDPN:
4773 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
4774 break;
4775 case QLA_EVT_GPNID:
4776 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
4777 break;
4778 case QLA_EVT_GPNID_DONE:
4779 qla24xx_async_gpnid_done(vha, e->u.iosb.sp);
4780 break;
4781 case QLA_EVT_NEW_SESS:
4782 qla24xx_create_new_sess(vha, e);
4783 break;
4784 case QLA_EVT_GPDB:
4785 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
4786 e->u.fcport.opt);
4787 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004788 case QLA_EVT_PRLI:
4789 qla24xx_async_prli(vha, e->u.fcport.fcport);
4790 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004791 case QLA_EVT_GPSC:
4792 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
4793 break;
4794 case QLA_EVT_UPD_FCPORT:
4795 qla2x00_update_fcport(vha, e->u.fcport.fcport);
4796 break;
4797 case QLA_EVT_GNL:
4798 qla24xx_async_gnl(vha, e->u.fcport.fcport);
4799 break;
4800 case QLA_EVT_NACK:
4801 qla24xx_do_nack_work(vha, e);
4802 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004803 }
4804 if (e->flags & QLA_EVT_FLAG_FREE)
4805 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004806
4807 /* For each work completed decrement vha ref count */
4808 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004809 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004810}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004811
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004812/* Relogins all the fcports of a vport
4813 * Context: dpc thread
4814 */
4815void qla2x00_relogin(struct scsi_qla_host *vha)
4816{
4817 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004818 int status;
Quinn Tran726b8542017-01-19 22:28:00 -08004819 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004820
4821 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4822 /*
4823 * If the port is not ONLINE then try to login
4824 * to it if we haven't run out of retries.
4825 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004826 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4827 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004828 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004829 if (fcport->flags & FCF_FABRIC_DEVICE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004830 ql_dbg(ql_dbg_disc, fcport->vha, 0x2108,
Quinn Tran726b8542017-01-19 22:28:00 -08004831 "%s %8phC DS %d LS %d\n", __func__,
4832 fcport->port_name, fcport->disc_state,
4833 fcport->fw_login_state);
4834 memset(&ea, 0, sizeof(ea));
4835 ea.event = FCME_RELOGIN;
4836 ea.fcport = fcport;
4837 qla2x00_fcport_event_handler(vha, &ea);
4838 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839 status = qla2x00_local_device_login(vha,
4840 fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004841 if (status == QLA_SUCCESS) {
4842 fcport->old_loop_id = fcport->loop_id;
4843 ql_dbg(ql_dbg_disc, vha, 0x2003,
4844 "Port login OK: logged in ID 0x%x.\n",
4845 fcport->loop_id);
4846 qla2x00_update_fcport(vha, fcport);
4847 } else if (status == 1) {
4848 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4849 /* retry the login again */
4850 ql_dbg(ql_dbg_disc, vha, 0x2007,
4851 "Retrying %d login again loop_id 0x%x.\n",
4852 fcport->login_retry,
4853 fcport->loop_id);
4854 } else {
4855 fcport->login_retry = 0;
4856 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004857
Quinn Tran726b8542017-01-19 22:28:00 -08004858 if (fcport->login_retry == 0 &&
4859 status != QLA_SUCCESS)
4860 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004861 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004862 }
4863 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4864 break;
4865 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004866}
4867
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004868/* Schedule work on any of the dpc-workqueues */
4869void
4870qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4871{
4872 struct qla_hw_data *ha = base_vha->hw;
4873
4874 switch (work_code) {
4875 case MBA_IDC_AEN: /* 0x8200 */
4876 if (ha->dpc_lp_wq)
4877 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4878 break;
4879
4880 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4881 if (!ha->flags.nic_core_reset_hdlr_active) {
4882 if (ha->dpc_hp_wq)
4883 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4884 } else
4885 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4886 "NIC Core reset is already active. Skip "
4887 "scheduling it again.\n");
4888 break;
4889 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4890 if (ha->dpc_hp_wq)
4891 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4892 break;
4893 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4894 if (ha->dpc_hp_wq)
4895 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4896 break;
4897 default:
4898 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004899 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004900 }
4901
4902 return;
4903}
4904
4905/* Work: Perform NIC Core Unrecoverable state handling */
4906void
4907qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4908{
4909 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004910 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004911 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4912 uint32_t dev_state = 0;
4913
4914 qla83xx_idc_lock(base_vha, 0);
4915 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4916 qla83xx_reset_ownership(base_vha);
4917 if (ha->flags.nic_core_reset_owner) {
4918 ha->flags.nic_core_reset_owner = 0;
4919 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4920 QLA8XXX_DEV_FAILED);
4921 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4922 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4923 }
4924 qla83xx_idc_unlock(base_vha, 0);
4925}
4926
4927/* Work: Execute IDC state handler */
4928void
4929qla83xx_idc_state_handler_work(struct work_struct *work)
4930{
4931 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004932 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004933 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4934 uint32_t dev_state = 0;
4935
4936 qla83xx_idc_lock(base_vha, 0);
4937 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4938 if (dev_state == QLA8XXX_DEV_FAILED ||
4939 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4940 qla83xx_idc_state_handler(base_vha);
4941 qla83xx_idc_unlock(base_vha, 0);
4942}
4943
Saurav Kashyapfa492632012-11-21 02:40:29 -05004944static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004945qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4946{
4947 int rval = QLA_SUCCESS;
4948 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4949 uint32_t heart_beat_counter1, heart_beat_counter2;
4950
4951 do {
4952 if (time_after(jiffies, heart_beat_wait)) {
4953 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4954 "Nic Core f/w is not alive.\n");
4955 rval = QLA_FUNCTION_FAILED;
4956 break;
4957 }
4958
4959 qla83xx_idc_lock(base_vha, 0);
4960 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4961 &heart_beat_counter1);
4962 qla83xx_idc_unlock(base_vha, 0);
4963 msleep(100);
4964 qla83xx_idc_lock(base_vha, 0);
4965 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4966 &heart_beat_counter2);
4967 qla83xx_idc_unlock(base_vha, 0);
4968 } while (heart_beat_counter1 == heart_beat_counter2);
4969
4970 return rval;
4971}
4972
4973/* Work: Perform NIC Core Reset handling */
4974void
4975qla83xx_nic_core_reset_work(struct work_struct *work)
4976{
4977 struct qla_hw_data *ha =
4978 container_of(work, struct qla_hw_data, nic_core_reset);
4979 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4980 uint32_t dev_state = 0;
4981
Saurav Kashyap81178772012-08-22 14:21:04 -04004982 if (IS_QLA2031(ha)) {
4983 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4984 ql_log(ql_log_warn, base_vha, 0xb081,
4985 "Failed to dump mctp\n");
4986 return;
4987 }
4988
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004989 if (!ha->flags.nic_core_reset_hdlr_active) {
4990 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4991 qla83xx_idc_lock(base_vha, 0);
4992 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4993 &dev_state);
4994 qla83xx_idc_unlock(base_vha, 0);
4995 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4996 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4997 "Nic Core f/w is alive.\n");
4998 return;
4999 }
5000 }
5001
5002 ha->flags.nic_core_reset_hdlr_active = 1;
5003 if (qla83xx_nic_core_reset(base_vha)) {
5004 /* NIC Core reset failed. */
5005 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5006 "NIC Core reset failed.\n");
5007 }
5008 ha->flags.nic_core_reset_hdlr_active = 0;
5009 }
5010}
5011
5012/* Work: Handle 8200 IDC aens */
5013void
5014qla83xx_service_idc_aen(struct work_struct *work)
5015{
5016 struct qla_hw_data *ha =
5017 container_of(work, struct qla_hw_data, idc_aen);
5018 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5019 uint32_t dev_state, idc_control;
5020
5021 qla83xx_idc_lock(base_vha, 0);
5022 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5023 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5024 qla83xx_idc_unlock(base_vha, 0);
5025 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5026 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5027 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5028 "Application requested NIC Core Reset.\n");
5029 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5030 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5031 QLA_SUCCESS) {
5032 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5033 "Other protocol driver requested NIC Core Reset.\n");
5034 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5035 }
5036 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5037 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5038 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5039 }
5040}
5041
5042static void
5043qla83xx_wait_logic(void)
5044{
5045 int i;
5046
5047 /* Yield CPU */
5048 if (!in_interrupt()) {
5049 /*
5050 * Wait about 200ms before retrying again.
5051 * This controls the number of retries for single
5052 * lock operation.
5053 */
5054 msleep(100);
5055 schedule();
5056 } else {
5057 for (i = 0; i < 20; i++)
5058 cpu_relax(); /* This a nop instr on i386 */
5059 }
5060}
5061
Saurav Kashyapfa492632012-11-21 02:40:29 -05005062static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005063qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5064{
5065 int rval;
5066 uint32_t data;
5067 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5068 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5069 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005070 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5071 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005072
5073 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5074 if (rval)
5075 return rval;
5076
5077 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5078 return QLA_SUCCESS;
5079 } else {
5080 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5081 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5082 data);
5083 if (rval)
5084 return rval;
5085
5086 msleep(200);
5087
5088 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5089 &data);
5090 if (rval)
5091 return rval;
5092
5093 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5094 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5095 ~(idc_lck_rcvry_stage_mask));
5096 rval = qla83xx_wr_reg(base_vha,
5097 QLA83XX_IDC_LOCK_RECOVERY, data);
5098 if (rval)
5099 return rval;
5100
5101 /* Forcefully perform IDC UnLock */
5102 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5103 &data);
5104 if (rval)
5105 return rval;
5106 /* Clear lock-id by setting 0xff */
5107 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5108 0xff);
5109 if (rval)
5110 return rval;
5111 /* Clear lock-recovery by setting 0x0 */
5112 rval = qla83xx_wr_reg(base_vha,
5113 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5114 if (rval)
5115 return rval;
5116 } else
5117 return QLA_SUCCESS;
5118 }
5119
5120 return rval;
5121}
5122
Saurav Kashyapfa492632012-11-21 02:40:29 -05005123static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005124qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5125{
5126 int rval = QLA_SUCCESS;
5127 uint32_t o_drv_lockid, n_drv_lockid;
5128 unsigned long lock_recovery_timeout;
5129
5130 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5131retry_lockid:
5132 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5133 if (rval)
5134 goto exit;
5135
5136 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5137 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5138 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5139 return QLA_SUCCESS;
5140 else
5141 return QLA_FUNCTION_FAILED;
5142 }
5143
5144 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5145 if (rval)
5146 goto exit;
5147
5148 if (o_drv_lockid == n_drv_lockid) {
5149 qla83xx_wait_logic();
5150 goto retry_lockid;
5151 } else
5152 return QLA_SUCCESS;
5153
5154exit:
5155 return rval;
5156}
5157
5158void
5159qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5160{
5161 uint16_t options = (requester_id << 15) | BIT_6;
5162 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005163 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005164 struct qla_hw_data *ha = base_vha->hw;
5165
5166 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5167retry_lock:
5168 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5169 == QLA_SUCCESS) {
5170 if (data) {
5171 /* Setting lock-id to our function-number */
5172 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5173 ha->portnum);
5174 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005175 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5176 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005177 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005178 "Failed to acquire IDC lock, acquired by %d, "
5179 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005180
5181 /* Retry/Perform IDC-Lock recovery */
5182 if (qla83xx_idc_lock_recovery(base_vha)
5183 == QLA_SUCCESS) {
5184 qla83xx_wait_logic();
5185 goto retry_lock;
5186 } else
5187 ql_log(ql_log_warn, base_vha, 0xb075,
5188 "IDC Lock recovery FAILED.\n");
5189 }
5190
5191 }
5192
5193 return;
5194
5195 /* XXX: IDC-lock implementation using access-control mbx */
5196retry_lock2:
5197 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5198 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5199 "Failed to acquire IDC lock. retrying...\n");
5200 /* Retry/Perform IDC-Lock recovery */
5201 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5202 qla83xx_wait_logic();
5203 goto retry_lock2;
5204 } else
5205 ql_log(ql_log_warn, base_vha, 0xb076,
5206 "IDC Lock recovery FAILED.\n");
5207 }
5208
5209 return;
5210}
5211
5212void
5213qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5214{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005215#if 0
5216 uint16_t options = (requester_id << 15) | BIT_7;
5217#endif
5218 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005219 uint32_t data;
5220 struct qla_hw_data *ha = base_vha->hw;
5221
5222 /* IDC-unlock implementation using driver-unlock/lock-id
5223 * remote registers
5224 */
5225 retry = 0;
5226retry_unlock:
5227 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5228 == QLA_SUCCESS) {
5229 if (data == ha->portnum) {
5230 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5231 /* Clearing lock-id by setting 0xff */
5232 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5233 } else if (retry < 10) {
5234 /* SV: XXX: IDC unlock retrying needed here? */
5235
5236 /* Retry for IDC-unlock */
5237 qla83xx_wait_logic();
5238 retry++;
5239 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005240 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005241 goto retry_unlock;
5242 }
5243 } else if (retry < 10) {
5244 /* Retry for IDC-unlock */
5245 qla83xx_wait_logic();
5246 retry++;
5247 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005248 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005249 goto retry_unlock;
5250 }
5251
5252 return;
5253
Bart Van Assche5897cb22015-06-04 15:57:20 -07005254#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005255 /* XXX: IDC-unlock implementation using access-control mbx */
5256 retry = 0;
5257retry_unlock2:
5258 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5259 if (retry < 10) {
5260 /* Retry for IDC-unlock */
5261 qla83xx_wait_logic();
5262 retry++;
5263 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005264 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005265 goto retry_unlock2;
5266 }
5267 }
5268
5269 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005270#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005271}
5272
5273int
5274__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5275{
5276 int rval = QLA_SUCCESS;
5277 struct qla_hw_data *ha = vha->hw;
5278 uint32_t drv_presence;
5279
5280 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5281 if (rval == QLA_SUCCESS) {
5282 drv_presence |= (1 << ha->portnum);
5283 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5284 drv_presence);
5285 }
5286
5287 return rval;
5288}
5289
5290int
5291qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5292{
5293 int rval = QLA_SUCCESS;
5294
5295 qla83xx_idc_lock(vha, 0);
5296 rval = __qla83xx_set_drv_presence(vha);
5297 qla83xx_idc_unlock(vha, 0);
5298
5299 return rval;
5300}
5301
5302int
5303__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5304{
5305 int rval = QLA_SUCCESS;
5306 struct qla_hw_data *ha = vha->hw;
5307 uint32_t drv_presence;
5308
5309 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5310 if (rval == QLA_SUCCESS) {
5311 drv_presence &= ~(1 << ha->portnum);
5312 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5313 drv_presence);
5314 }
5315
5316 return rval;
5317}
5318
5319int
5320qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5321{
5322 int rval = QLA_SUCCESS;
5323
5324 qla83xx_idc_lock(vha, 0);
5325 rval = __qla83xx_clear_drv_presence(vha);
5326 qla83xx_idc_unlock(vha, 0);
5327
5328 return rval;
5329}
5330
Saurav Kashyapfa492632012-11-21 02:40:29 -05005331static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005332qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5333{
5334 struct qla_hw_data *ha = vha->hw;
5335 uint32_t drv_ack, drv_presence;
5336 unsigned long ack_timeout;
5337
5338 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5339 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5340 while (1) {
5341 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5342 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005343 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005344 break;
5345
5346 if (time_after_eq(jiffies, ack_timeout)) {
5347 ql_log(ql_log_warn, vha, 0xb067,
5348 "RESET ACK TIMEOUT! drv_presence=0x%x "
5349 "drv_ack=0x%x\n", drv_presence, drv_ack);
5350 /*
5351 * The function(s) which did not ack in time are forced
5352 * to withdraw any further participation in the IDC
5353 * reset.
5354 */
5355 if (drv_ack != drv_presence)
5356 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5357 drv_ack);
5358 break;
5359 }
5360
5361 qla83xx_idc_unlock(vha, 0);
5362 msleep(1000);
5363 qla83xx_idc_lock(vha, 0);
5364 }
5365
5366 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5367 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5368}
5369
Saurav Kashyapfa492632012-11-21 02:40:29 -05005370static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005371qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5372{
5373 int rval = QLA_SUCCESS;
5374 uint32_t idc_control;
5375
5376 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5377 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5378
5379 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5380 __qla83xx_get_idc_control(vha, &idc_control);
5381 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5382 __qla83xx_set_idc_control(vha, 0);
5383
5384 qla83xx_idc_unlock(vha, 0);
5385 rval = qla83xx_restart_nic_firmware(vha);
5386 qla83xx_idc_lock(vha, 0);
5387
5388 if (rval != QLA_SUCCESS) {
5389 ql_log(ql_log_fatal, vha, 0xb06a,
5390 "Failed to restart NIC f/w.\n");
5391 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5392 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5393 } else {
5394 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5395 "Success in restarting nic f/w.\n");
5396 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5397 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5398 }
5399
5400 return rval;
5401}
5402
5403/* Assumes idc_lock always held on entry */
5404int
5405qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5406{
5407 struct qla_hw_data *ha = base_vha->hw;
5408 int rval = QLA_SUCCESS;
5409 unsigned long dev_init_timeout;
5410 uint32_t dev_state;
5411
5412 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5413 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5414
5415 while (1) {
5416
5417 if (time_after_eq(jiffies, dev_init_timeout)) {
5418 ql_log(ql_log_warn, base_vha, 0xb06e,
5419 "Initialization TIMEOUT!\n");
5420 /* Init timeout. Disable further NIC Core
5421 * communication.
5422 */
5423 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5424 QLA8XXX_DEV_FAILED);
5425 ql_log(ql_log_info, base_vha, 0xb06f,
5426 "HW State: FAILED.\n");
5427 }
5428
5429 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5430 switch (dev_state) {
5431 case QLA8XXX_DEV_READY:
5432 if (ha->flags.nic_core_reset_owner)
5433 qla83xx_idc_audit(base_vha,
5434 IDC_AUDIT_COMPLETION);
5435 ha->flags.nic_core_reset_owner = 0;
5436 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5437 "Reset_owner reset by 0x%x.\n",
5438 ha->portnum);
5439 goto exit;
5440 case QLA8XXX_DEV_COLD:
5441 if (ha->flags.nic_core_reset_owner)
5442 rval = qla83xx_device_bootstrap(base_vha);
5443 else {
5444 /* Wait for AEN to change device-state */
5445 qla83xx_idc_unlock(base_vha, 0);
5446 msleep(1000);
5447 qla83xx_idc_lock(base_vha, 0);
5448 }
5449 break;
5450 case QLA8XXX_DEV_INITIALIZING:
5451 /* Wait for AEN to change device-state */
5452 qla83xx_idc_unlock(base_vha, 0);
5453 msleep(1000);
5454 qla83xx_idc_lock(base_vha, 0);
5455 break;
5456 case QLA8XXX_DEV_NEED_RESET:
5457 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5458 qla83xx_need_reset_handler(base_vha);
5459 else {
5460 /* Wait for AEN to change device-state */
5461 qla83xx_idc_unlock(base_vha, 0);
5462 msleep(1000);
5463 qla83xx_idc_lock(base_vha, 0);
5464 }
5465 /* reset timeout value after need reset handler */
5466 dev_init_timeout = jiffies +
5467 (ha->fcoe_dev_init_timeout * HZ);
5468 break;
5469 case QLA8XXX_DEV_NEED_QUIESCENT:
5470 /* XXX: DEBUG for now */
5471 qla83xx_idc_unlock(base_vha, 0);
5472 msleep(1000);
5473 qla83xx_idc_lock(base_vha, 0);
5474 break;
5475 case QLA8XXX_DEV_QUIESCENT:
5476 /* XXX: DEBUG for now */
5477 if (ha->flags.quiesce_owner)
5478 goto exit;
5479
5480 qla83xx_idc_unlock(base_vha, 0);
5481 msleep(1000);
5482 qla83xx_idc_lock(base_vha, 0);
5483 dev_init_timeout = jiffies +
5484 (ha->fcoe_dev_init_timeout * HZ);
5485 break;
5486 case QLA8XXX_DEV_FAILED:
5487 if (ha->flags.nic_core_reset_owner)
5488 qla83xx_idc_audit(base_vha,
5489 IDC_AUDIT_COMPLETION);
5490 ha->flags.nic_core_reset_owner = 0;
5491 __qla83xx_clear_drv_presence(base_vha);
5492 qla83xx_idc_unlock(base_vha, 0);
5493 qla8xxx_dev_failed_handler(base_vha);
5494 rval = QLA_FUNCTION_FAILED;
5495 qla83xx_idc_lock(base_vha, 0);
5496 goto exit;
5497 case QLA8XXX_BAD_VALUE:
5498 qla83xx_idc_unlock(base_vha, 0);
5499 msleep(1000);
5500 qla83xx_idc_lock(base_vha, 0);
5501 break;
5502 default:
5503 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005504 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005505 qla83xx_idc_unlock(base_vha, 0);
5506 qla8xxx_dev_failed_handler(base_vha);
5507 rval = QLA_FUNCTION_FAILED;
5508 qla83xx_idc_lock(base_vha, 0);
5509 goto exit;
5510 }
5511 }
5512
5513exit:
5514 return rval;
5515}
5516
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005517void
5518qla2x00_disable_board_on_pci_error(struct work_struct *work)
5519{
5520 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5521 board_disable);
5522 struct pci_dev *pdev = ha->pdev;
5523 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5524
Quinn Tran726b8542017-01-19 22:28:00 -08005525 /*
5526 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005527 * where it was set first.
5528 */
5529 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5530 return;
5531
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005532 ql_log(ql_log_warn, base_vha, 0x015b,
5533 "Disabling adapter.\n");
5534
Sawan Chandakefdb5762017-08-23 15:05:00 -07005535 if (!atomic_read(&pdev->enable_cnt)) {
5536 ql_log(ql_log_info, base_vha, 0xfffc,
5537 "PCI device disabled, no action req for PCI error=%lx\n",
5538 base_vha->pci_flags);
5539 return;
5540 }
5541
Quinn Tran726b8542017-01-19 22:28:00 -08005542 qla2x00_wait_for_sess_deletion(base_vha);
5543
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005544 set_bit(UNLOADING, &base_vha->dpc_flags);
5545
5546 qla2x00_delete_all_vps(ha, base_vha);
5547
5548 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5549
5550 qla2x00_dfs_remove(base_vha);
5551
5552 qla84xx_put_chip(base_vha);
5553
5554 if (base_vha->timer_active)
5555 qla2x00_stop_timer(base_vha);
5556
5557 base_vha->flags.online = 0;
5558
5559 qla2x00_destroy_deferred_work(ha);
5560
5561 /*
5562 * Do not try to stop beacon blink as it will issue a mailbox
5563 * command.
5564 */
5565 qla2x00_free_sysfs_attr(base_vha, false);
5566
5567 fc_remove_host(base_vha->host);
5568
5569 scsi_remove_host(base_vha->host);
5570
5571 base_vha->flags.init_done = 0;
5572 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005573 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005574 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005575 qla2x00_mem_free(ha);
5576 qla82xx_md_free(base_vha);
5577 qla2x00_free_queues(ha);
5578
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005579 qla2x00_unmap_iobases(ha);
5580
5581 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005582 pci_disable_pcie_error_reporting(pdev);
5583 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005584
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005585 /*
5586 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5587 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005588}
5589
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590/**************************************************************************
5591* qla2x00_do_dpc
5592* This kernel thread is a task that is schedule by the interrupt handler
5593* to perform the background processing for interrupts.
5594*
5595* Notes:
5596* This task always run in the context of a kernel thread. It
5597* is kick-off by the driver's detect code and starts up
5598* up one per adapter. It immediately goes to sleep and waits for
5599* some fibre event. When either the interrupt handler or
5600* the timer routine detects a event it will one of the task
5601* bits then wake us up.
5602**************************************************************************/
5603static int
5604qla2x00_do_dpc(void *data)
5605{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005606 scsi_qla_host_t *base_vha;
5607 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005608 uint32_t online;
5609 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005611 ha = (struct qla_hw_data *)data;
5612 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005613
Dongsheng Yang8698a742014-03-11 18:09:12 +08005614 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005615
James Bottomley563585e2011-01-27 16:12:37 -05005616 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005617 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005618 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5619 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620
Christoph Hellwig39a11242006-02-14 18:46:22 +01005621 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005622
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005623 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5624 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625
Andrew Vasquez85880802009-12-15 21:29:46 -08005626 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005627 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5628 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005629 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005630 }
5631
Linus Torvalds1da177e2005-04-16 15:20:36 -07005632 ha->dpc_active = 1;
5633
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005634 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5635 "DPC handler waking up, dpc_flags=0x%lx.\n",
5636 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005638 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5639 break;
5640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005641 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005642
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005643 if (IS_P3P_TYPE(ha)) {
5644 if (IS_QLA8044(ha)) {
5645 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5646 &base_vha->dpc_flags)) {
5647 qla8044_idc_lock(ha);
5648 qla8044_wr_direct(base_vha,
5649 QLA8044_CRB_DEV_STATE_INDEX,
5650 QLA8XXX_DEV_FAILED);
5651 qla8044_idc_unlock(ha);
5652 ql_log(ql_log_info, base_vha, 0x4004,
5653 "HW State: FAILED.\n");
5654 qla8044_device_state_handler(base_vha);
5655 continue;
5656 }
5657
5658 } else {
5659 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5660 &base_vha->dpc_flags)) {
5661 qla82xx_idc_lock(ha);
5662 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5663 QLA8XXX_DEV_FAILED);
5664 qla82xx_idc_unlock(ha);
5665 ql_log(ql_log_info, base_vha, 0x0151,
5666 "HW State: FAILED.\n");
5667 qla82xx_device_state_handler(base_vha);
5668 continue;
5669 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005670 }
5671
5672 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5673 &base_vha->dpc_flags)) {
5674
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005675 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5676 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005677 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5678 &base_vha->dpc_flags))) {
5679 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5680 /* FCoE-ctx reset failed.
5681 * Escalate to chip-reset
5682 */
5683 set_bit(ISP_ABORT_NEEDED,
5684 &base_vha->dpc_flags);
5685 }
5686 clear_bit(ABORT_ISP_ACTIVE,
5687 &base_vha->dpc_flags);
5688 }
5689
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005690 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5691 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005692 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005693 } else if (IS_QLAFX00(ha)) {
5694 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5695 &base_vha->dpc_flags)) {
5696 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5697 "Firmware Reset Recovery\n");
5698 if (qlafx00_reset_initialize(base_vha)) {
5699 /* Failed. Abort isp later. */
5700 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005701 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005702 set_bit(ISP_UNRECOVERABLE,
5703 &base_vha->dpc_flags);
5704 ql_dbg(ql_dbg_dpc, base_vha,
5705 0x4021,
5706 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005707 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005708 }
5709 }
5710
5711 if (test_and_clear_bit(FX00_TARGET_SCAN,
5712 &base_vha->dpc_flags)) {
5713 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5714 "ISPFx00 Target Scan scheduled\n");
5715 if (qlafx00_rescan_isp(base_vha)) {
5716 if (!test_bit(UNLOADING,
5717 &base_vha->dpc_flags))
5718 set_bit(ISP_UNRECOVERABLE,
5719 &base_vha->dpc_flags);
5720 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5721 "ISPFx00 Target Scan Failed\n");
5722 }
5723 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5724 "ISPFx00 Target Scan End\n");
5725 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005726 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5727 &base_vha->dpc_flags)) {
5728 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5729 "ISPFx00 Host Info resend scheduled\n");
5730 qlafx00_fx_disc(base_vha,
5731 &base_vha->hw->mr.fcport,
5732 FXDISC_REG_HOST_INFO);
5733 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005734 }
5735
Quinn Trane4e3a2c2017-08-23 15:05:07 -07005736 if (test_and_clear_bit(DETECT_SFP_CHANGE,
5737 &base_vha->dpc_flags) &&
5738 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
5739 qla24xx_detect_sfp(base_vha);
5740
5741 if (ha->flags.detected_lr_sfp !=
5742 ha->flags.using_lr_setting)
5743 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
5744 }
5745
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005746 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5747 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005748
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005749 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5750 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005752 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753
Giridhar Malavalia9083012010-04-12 17:59:55 -07005754 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 /* failed. retry later */
5756 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005757 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005759 clear_bit(ABORT_ISP_ACTIVE,
5760 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005761 }
5762
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005763 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5764 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 }
5766
David Jefferya394aac2012-11-21 02:39:54 -05005767 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5768 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005769 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005770 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005771
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005772 if (IS_QLAFX00(ha))
5773 goto loop_resync_check;
5774
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005775 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005776 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5777 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005778 if (IS_P3P_TYPE(ha)) {
5779 if (IS_QLA82XX(ha))
5780 qla82xx_device_state_handler(base_vha);
5781 if (IS_QLA8044(ha))
5782 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005783 clear_bit(ISP_QUIESCE_NEEDED,
5784 &base_vha->dpc_flags);
5785 if (!ha->flags.quiesce_owner) {
5786 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005787 if (IS_QLA82XX(ha)) {
5788 qla82xx_idc_lock(ha);
5789 qla82xx_clear_qsnt_ready(
5790 base_vha);
5791 qla82xx_idc_unlock(ha);
5792 } else if (IS_QLA8044(ha)) {
5793 qla8044_idc_lock(ha);
5794 qla8044_clear_qsnt_ready(
5795 base_vha);
5796 qla8044_idc_unlock(ha);
5797 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005798 }
5799 } else {
5800 clear_bit(ISP_QUIESCE_NEEDED,
5801 &base_vha->dpc_flags);
5802 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005803 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005804 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5805 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005806 }
5807
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005808 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005809 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005810 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005812 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5813 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005814 qla2x00_rst_aen(base_vha);
5815 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005816 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5817 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 }
5819
5820 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005821 if ((test_and_clear_bit(RELOGIN_NEEDED,
5822 &base_vha->dpc_flags)) &&
5823 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5824 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005826 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5827 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005828 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005829 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5830 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005832loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005833 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005834 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005836 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5837 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838
5839 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005840 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841
Bart Van Assche52c82822015-07-09 07:23:26 -07005842 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005844 clear_bit(LOOP_RESYNC_ACTIVE,
5845 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 }
5847
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005848 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5849 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 }
5851
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005852 if (IS_QLAFX00(ha))
5853 goto intr_on_check;
5854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005855 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5856 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5857 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5858 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005859 }
5860
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005861intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005863 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005865 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005866 &base_vha->dpc_flags)) {
5867 if (ha->beacon_blink_led == 1)
5868 ha->isp_ops->beacon_blink(base_vha);
5869 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005870
Michael Hernandezd7459522016-12-12 14:40:07 -08005871 /* qpair online check */
5872 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
5873 &base_vha->dpc_flags)) {
5874 if (ha->flags.eeh_busy ||
5875 ha->flags.pci_channel_io_perm_failure)
5876 online = 0;
5877 else
5878 online = 1;
5879
5880 mutex_lock(&ha->mq_lock);
5881 list_for_each_entry(qpair, &base_vha->qp_list,
5882 qp_list_elem)
5883 qpair->online = online;
5884 mutex_unlock(&ha->mq_lock);
5885 }
5886
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07005887 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED, &base_vha->dpc_flags)) {
5888 ql_log(ql_log_info, base_vha, 0xffffff,
5889 "nvme: SET ZIO Activity exchange threshold to %d.\n",
5890 ha->nvme_last_rptd_aen);
5891 if (qla27xx_set_zio_threshold(base_vha, ha->nvme_last_rptd_aen)) {
5892 ql_log(ql_log_info, base_vha, 0xffffff,
5893 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
5894 ha->nvme_last_rptd_aen);
5895 }
5896 }
5897
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005898 if (!IS_QLAFX00(ha))
5899 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005900
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005902end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005903 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005904 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005905 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005907 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5908 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909
5910 /*
5911 * Make sure that nobody tries to wake us up again.
5912 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913 ha->dpc_active = 0;
5914
Andrew Vasquezac280b62009-08-20 11:06:05 -07005915 /* Cleanup any residual CTX SRBs. */
5916 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5917
Christoph Hellwig39a11242006-02-14 18:46:22 +01005918 return 0;
5919}
5920
5921void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005922qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005923{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005924 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005925 struct task_struct *t = ha->dpc_thread;
5926
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005927 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005928 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929}
5930
5931/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932* qla2x00_rst_aen
5933* Processes asynchronous reset.
5934*
5935* Input:
5936* ha = adapter block pointer.
5937*/
5938static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005939qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005941 if (vha->flags.online && !vha->flags.reset_active &&
5942 !atomic_read(&vha->loop_down_timer) &&
5943 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005944 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005945 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946
5947 /*
5948 * Issue marker command only when we are going to start
5949 * the I/O.
5950 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005951 vha->marker_needed = 1;
5952 } while (!atomic_read(&vha->loop_down_timer) &&
5953 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 }
5955}
5956
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957/**************************************************************************
5958* qla2x00_timer
5959*
5960* Description:
5961* One second timer
5962*
5963* Context: Interrupt
5964***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005965void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005966qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 int start_dpc = 0;
5970 int index;
5971 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005972 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005973 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005974 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005975
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005976 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005977 ql_dbg(ql_dbg_timer, vha, 0x6000,
5978 "EEH = %d, restarting timer.\n",
5979 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005980 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5981 return;
5982 }
5983
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005984 /*
5985 * Hardware read to raise pending EEH errors during mailbox waits. If
5986 * the read returns -1 then disable the board.
5987 */
5988 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005989 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005990 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005993 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005994 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005995 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5996 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005997 if (IS_QLA82XX(ha))
5998 qla82xx_watchdog(vha);
5999 else if (IS_QLA8044(ha))
6000 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006001 }
6002
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006003 if (!vha->vp_idx && IS_QLAFX00(ha))
6004 qlafx00_timer_routine(vha);
6005
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006007 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006008 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6009 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006010 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006012 if (atomic_read(&vha->loop_down_timer) ==
6013 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006015 ql_log(ql_log_info, vha, 0x6008,
6016 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006018 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6019 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006021 /*
6022 * Schedule an ISP abort to return any FCP2-device
6023 * commands.
6024 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006025 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006026 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006027 spin_lock_irqsave(&ha->hardware_lock,
6028 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006029 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006030 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006031 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006032 index++) {
6033 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006034
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006035 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006036 if (!sp)
6037 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006038 if (sp->cmd_type != TYPE_SRB)
6039 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006040 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006041 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006042 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006043 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006044 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006046 if (IS_QLA82XX(ha))
6047 set_bit(FCOE_CTX_RESET_NEEDED,
6048 &vha->dpc_flags);
6049 else
6050 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006051 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006052 break;
6053 }
6054 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006055 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057 start_dpc++;
6058 }
6059
6060 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006061 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006062 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006063 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 "Loop down - aborting ISP.\n");
6065
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006066 if (IS_QLA82XX(ha))
6067 set_bit(FCOE_CTX_RESET_NEEDED,
6068 &vha->dpc_flags);
6069 else
6070 set_bit(ISP_ABORT_NEEDED,
6071 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 }
6073 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006074 ql_dbg(ql_dbg_timer, vha, 0x600a,
6075 "Loop down - seconds remaining %d.\n",
6076 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006078 /* Check if beacon LED needs to be blinked for physical host only */
6079 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006080 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006081 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006082 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6083 start_dpc++;
6084 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006085 }
6086
Andrew Vasquez550bf572008-04-24 15:21:23 -07006087 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006088 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07006089 start_dpc++;
6090
Duane Grigsby7401bc12017-06-21 13:48:42 -07006091 /*
6092 * FC-NVME
6093 * see if the active AEN count has changed from what was last reported.
6094 */
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006095 if (!vha->vp_idx &&
6096 atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen &&
6097 ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006098 ql_log(ql_log_info, vha, 0x3002,
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006099 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6100 ha->nvme_last_rptd_aen);
6101 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
6102 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6103 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006104 }
6105
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006107 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6108 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6109 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006111 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6112 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006113 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6114 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006115 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006116 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006117 ql_dbg(ql_dbg_timer, vha, 0x600b,
6118 "isp_abort_needed=%d loop_resync_needed=%d "
6119 "fcport_update_needed=%d start_dpc=%d "
6120 "reset_marker_needed=%d",
6121 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6122 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6123 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6124 start_dpc,
6125 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6126 ql_dbg(ql_dbg_timer, vha, 0x600c,
6127 "beacon_blink_needed=%d isp_unrecoverable=%d "
6128 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006129 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006130 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6131 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6132 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6133 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006134 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006135 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006138 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139}
6140
Andrew Vasquez54333832005-11-09 15:49:04 -08006141/* Firmware interface routines. */
6142
Chad Dupuisf73cb692014-02-26 04:15:06 -05006143#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006144#define FW_ISP21XX 0
6145#define FW_ISP22XX 1
6146#define FW_ISP2300 2
6147#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006148#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006149#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006150#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006151#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006152#define FW_ISP2031 8
6153#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006154#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006155
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006156#define FW_FILE_ISP21XX "ql2100_fw.bin"
6157#define FW_FILE_ISP22XX "ql2200_fw.bin"
6158#define FW_FILE_ISP2300 "ql2300_fw.bin"
6159#define FW_FILE_ISP2322 "ql2322_fw.bin"
6160#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006161#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006162#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006163#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006164#define FW_FILE_ISP2031 "ql2600_fw.bin"
6165#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006166#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006167
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006168
Daniel Walkere1e82b62008-05-12 22:21:10 -07006169static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006170
6171static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006172 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6173 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6174 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6175 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6176 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006177 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006178 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006179 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006180 { .name = FW_FILE_ISP2031, },
6181 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006182 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006183};
6184
6185struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006186qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006187{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006188 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006189 struct fw_blob *blob;
6190
Andrew Vasquez54333832005-11-09 15:49:04 -08006191 if (IS_QLA2100(ha)) {
6192 blob = &qla_fw_blobs[FW_ISP21XX];
6193 } else if (IS_QLA2200(ha)) {
6194 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006195 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006196 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006197 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006198 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006199 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006200 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006201 } else if (IS_QLA25XX(ha)) {
6202 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006203 } else if (IS_QLA81XX(ha)) {
6204 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006205 } else if (IS_QLA82XX(ha)) {
6206 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006207 } else if (IS_QLA2031(ha)) {
6208 blob = &qla_fw_blobs[FW_ISP2031];
6209 } else if (IS_QLA8031(ha)) {
6210 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006211 } else if (IS_QLA27XX(ha)) {
6212 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006213 } else {
6214 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006215 }
6216
Daniel Walkere1e82b62008-05-12 22:21:10 -07006217 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006218 if (blob->fw)
6219 goto out;
6220
6221 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006222 ql_log(ql_log_warn, vha, 0x0063,
6223 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006224 blob->fw = NULL;
6225 blob = NULL;
6226 goto out;
6227 }
6228
6229out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006230 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006231 return blob;
6232}
6233
6234static void
6235qla2x00_release_firmware(void)
6236{
6237 int idx;
6238
Daniel Walkere1e82b62008-05-12 22:21:10 -07006239 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006240 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006241 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006242 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006243}
6244
Seokmann Ju14e660e2007-09-20 14:07:36 -07006245static pci_ers_result_t
6246qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6247{
Andrew Vasquez85880802009-12-15 21:29:46 -08006248 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6249 struct qla_hw_data *ha = vha->hw;
6250
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006251 ql_dbg(ql_dbg_aer, vha, 0x9000,
6252 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006253
Sawan Chandakefdb5762017-08-23 15:05:00 -07006254 if (!atomic_read(&pdev->enable_cnt)) {
6255 ql_log(ql_log_info, vha, 0xffff,
6256 "PCI device is disabled,state %x\n", state);
6257 return PCI_ERS_RESULT_NEED_RESET;
6258 }
6259
Seokmann Ju14e660e2007-09-20 14:07:36 -07006260 switch (state) {
6261 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006262 ha->flags.eeh_busy = 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08006263 if (ql2xmqsupport) {
6264 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6265 qla2xxx_wake_dpc(vha);
6266 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006267 return PCI_ERS_RESULT_CAN_RECOVER;
6268 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006269 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006270 /* For ISP82XX complete any pending mailbox cmd */
6271 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006272 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006273 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6274 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006275 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006276 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006277 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006278 /* Return back all IOs */
6279 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Michael Hernandezd7459522016-12-12 14:40:07 -08006280 if (ql2xmqsupport) {
6281 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6282 qla2xxx_wake_dpc(vha);
6283 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006284 return PCI_ERS_RESULT_NEED_RESET;
6285 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006286 ha->flags.pci_channel_io_perm_failure = 1;
6287 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Michael Hernandezd7459522016-12-12 14:40:07 -08006288 if (ql2xmqsupport) {
6289 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6290 qla2xxx_wake_dpc(vha);
6291 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006292 return PCI_ERS_RESULT_DISCONNECT;
6293 }
6294 return PCI_ERS_RESULT_NEED_RESET;
6295}
6296
6297static pci_ers_result_t
6298qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6299{
6300 int risc_paused = 0;
6301 uint32_t stat;
6302 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006303 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6304 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006305 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6306 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6307
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006308 if (IS_QLA82XX(ha))
6309 return PCI_ERS_RESULT_RECOVERED;
6310
Seokmann Ju14e660e2007-09-20 14:07:36 -07006311 spin_lock_irqsave(&ha->hardware_lock, flags);
6312 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6313 stat = RD_REG_DWORD(&reg->hccr);
6314 if (stat & HCCR_RISC_PAUSE)
6315 risc_paused = 1;
6316 } else if (IS_QLA23XX(ha)) {
6317 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6318 if (stat & HSR_RISC_PAUSED)
6319 risc_paused = 1;
6320 } else if (IS_FWI2_CAPABLE(ha)) {
6321 stat = RD_REG_DWORD(&reg24->host_status);
6322 if (stat & HSRX_RISC_PAUSED)
6323 risc_paused = 1;
6324 }
6325 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6326
6327 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006328 ql_log(ql_log_info, base_vha, 0x9003,
6329 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006330 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006331
6332 return PCI_ERS_RESULT_NEED_RESET;
6333 } else
6334 return PCI_ERS_RESULT_RECOVERED;
6335}
6336
Saurav Kashyapfa492632012-11-21 02:40:29 -05006337static uint32_t
6338qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006339{
6340 uint32_t rval = QLA_FUNCTION_FAILED;
6341 uint32_t drv_active = 0;
6342 struct qla_hw_data *ha = base_vha->hw;
6343 int fn;
6344 struct pci_dev *other_pdev = NULL;
6345
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006346 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6347 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006348
6349 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6350
6351 if (base_vha->flags.online) {
6352 /* Abort all outstanding commands,
6353 * so as to be requeued later */
6354 qla2x00_abort_isp_cleanup(base_vha);
6355 }
6356
6357
6358 fn = PCI_FUNC(ha->pdev->devfn);
6359 while (fn > 0) {
6360 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006361 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6362 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006363 other_pdev =
6364 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6365 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6366 fn));
6367
6368 if (!other_pdev)
6369 continue;
6370 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006371 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6372 "Found PCI func available and enable at 0x%x.\n",
6373 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006374 pci_dev_put(other_pdev);
6375 break;
6376 }
6377 pci_dev_put(other_pdev);
6378 }
6379
6380 if (!fn) {
6381 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006382 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6383 "This devfn is reset owner = 0x%x.\n",
6384 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006385 qla82xx_idc_lock(ha);
6386
6387 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006388 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006389
6390 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6391 QLA82XX_IDC_VERSION);
6392
6393 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006394 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6395 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006396
6397 qla82xx_idc_unlock(ha);
6398 /* Reset if device is not already reset
6399 * drv_active would be 0 if a reset has already been done
6400 */
6401 if (drv_active)
6402 rval = qla82xx_start_firmware(base_vha);
6403 else
6404 rval = QLA_SUCCESS;
6405 qla82xx_idc_lock(ha);
6406
6407 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006408 ql_log(ql_log_info, base_vha, 0x900b,
6409 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006410 qla82xx_clear_drv_active(ha);
6411 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006412 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006413 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006414 ql_log(ql_log_info, base_vha, 0x900c,
6415 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006416 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006417 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006418 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006419 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006420 rval = qla82xx_restart_isp(base_vha);
6421 qla82xx_idc_lock(ha);
6422 /* Clear driver state register */
6423 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6424 qla82xx_set_drv_active(base_vha);
6425 }
6426 qla82xx_idc_unlock(ha);
6427 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006428 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6429 "This devfn is not reset owner = 0x%x.\n",
6430 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006431 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006432 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006433 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006434 rval = qla82xx_restart_isp(base_vha);
6435 qla82xx_idc_lock(ha);
6436 qla82xx_set_drv_active(base_vha);
6437 qla82xx_idc_unlock(ha);
6438 }
6439 }
6440 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6441
6442 return rval;
6443}
6444
Seokmann Ju14e660e2007-09-20 14:07:36 -07006445static pci_ers_result_t
6446qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6447{
6448 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006449 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6450 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006451 struct rsp_que *rsp;
6452 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006453
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006454 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6455 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006456
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006457 /* Workaround: qla2xxx driver which access hardware earlier
6458 * needs error state to be pci_channel_io_online.
6459 * Otherwise mailbox command timesout.
6460 */
6461 pdev->error_state = pci_channel_io_normal;
6462
6463 pci_restore_state(pdev);
6464
Richard Lary8c1496b2010-02-18 10:07:29 -08006465 /* pci_restore_state() clears the saved_state flag of the device
6466 * save restored state which resets saved_state flag
6467 */
6468 pci_save_state(pdev);
6469
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006470 if (ha->mem_only)
6471 rc = pci_enable_device_mem(pdev);
6472 else
6473 rc = pci_enable_device(pdev);
6474
6475 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006476 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006477 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006478 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006479 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006480
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006481 rsp = ha->rsp_q_map[0];
6482 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006483 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006485 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006486 goto exit_slot_reset;
6487
6488 if (IS_QLA82XX(ha)) {
6489 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6490 ret = PCI_ERS_RESULT_RECOVERED;
6491 goto exit_slot_reset;
6492 } else
6493 goto exit_slot_reset;
6494 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006495
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006496 while (ha->flags.mbox_busy && retries--)
6497 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006499 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006500 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006501 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006502 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006503
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006504
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006505exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006506 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6507 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006508
Seokmann Ju14e660e2007-09-20 14:07:36 -07006509 return ret;
6510}
6511
6512static void
6513qla2xxx_pci_resume(struct pci_dev *pdev)
6514{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006515 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6516 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006517 int ret;
6518
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006519 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6520 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006522 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006523 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006524 ql_log(ql_log_fatal, base_vha, 0x9002,
6525 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006526 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006527
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006528 pci_cleanup_aer_uncorrect_error_status(pdev);
6529
Andrew Vasquez85880802009-12-15 21:29:46 -08006530 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006531}
6532
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04006533static void
6534qla83xx_disable_laser(scsi_qla_host_t *vha)
6535{
6536 uint32_t reg, data, fn;
6537 struct qla_hw_data *ha = vha->hw;
6538 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
6539
6540 /* pci func #/port # */
6541 ql_dbg(ql_dbg_init, vha, 0x004b,
6542 "Disabling Laser for hba: %p\n", vha);
6543
6544 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
6545 (BIT_15|BIT_14|BIT_13|BIT_12));
6546
6547 fn = (fn >> 12);
6548
6549 if (fn & 1)
6550 reg = PORT_1_2031;
6551 else
6552 reg = PORT_0_2031;
6553
6554 data = LASER_OFF_2031;
6555
6556 qla83xx_wr_reg(vha, reg, data);
6557}
6558
Michael Hernandez56012362016-12-12 14:40:08 -08006559static int qla2xxx_map_queues(struct Scsi_Host *shost)
6560{
6561 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6562
6563 return blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
6564}
6565
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006566static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006567 .error_detected = qla2xxx_pci_error_detected,
6568 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6569 .slot_reset = qla2xxx_pci_slot_reset,
6570 .resume = qla2xxx_pci_resume,
6571};
6572
Andrew Vasquez54333832005-11-09 15:49:04 -08006573static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006574 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6575 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6576 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6577 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6578 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6579 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6580 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6581 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6582 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006583 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006584 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6585 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006586 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006587 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006588 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006589 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006590 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006591 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006592 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006593 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006594 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006595 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006596 { 0 },
6597};
6598MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6599
Andrew Vasquezfca29702005-07-06 10:31:47 -07006600static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006601 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006602 .driver = {
6603 .owner = THIS_MODULE,
6604 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006605 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006606 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006607 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006608 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006609 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006610};
6611
Al Viro75ef9de2013-04-04 19:09:41 -04006612static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006613 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006614 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006615};
6616
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617/**
6618 * qla2x00_module_init - Module initialization.
6619 **/
6620static int __init
6621qla2x00_module_init(void)
6622{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006623 int ret = 0;
6624
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006626 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006627 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006629 ql_log(ql_log_fatal, NULL, 0x0001,
6630 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 return -ENOMEM;
6632 }
6633
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006634 /* Initialize target kmem_cache and mem_pools */
6635 ret = qlt_init();
6636 if (ret < 0) {
6637 kmem_cache_destroy(srb_cachep);
6638 return ret;
6639 } else if (ret > 0) {
6640 /*
6641 * If initiator mode is explictly disabled by qlt_init(),
6642 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6643 * performing scsi_scan_target() during LOOP UP event.
6644 */
6645 qla2xxx_transport_functions.disable_target_scan = 1;
6646 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6647 }
6648
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 /* Derive version string. */
6650 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006651 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006652 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07006653 if (ql2xextended_error_logging == 1)
6654 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07006655
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006656 qla2xxx_transport_template =
6657 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006658 if (!qla2xxx_transport_template) {
6659 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006660 ql_log(ql_log_fatal, NULL, 0x0002,
6661 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006662 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006664 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006665
6666 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6667 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006668 ql_log(ql_log_fatal, NULL, 0x0003,
6669 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006670 }
6671
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006672 qla2xxx_transport_vport_template =
6673 fc_attach_transport(&qla2xxx_transport_vport_functions);
6674 if (!qla2xxx_transport_vport_template) {
6675 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006676 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006677 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006678 ql_log(ql_log_fatal, NULL, 0x0004,
6679 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006680 return -ENODEV;
6681 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006682 ql_log(ql_log_info, NULL, 0x0005,
6683 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006684 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006685 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006686 if (ret) {
6687 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006688 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006689 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006690 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006691 ql_log(ql_log_fatal, NULL, 0x0006,
6692 "pci_register_driver failed...ret=%d Failing load!.\n",
6693 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006694 }
6695 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696}
6697
6698/**
6699 * qla2x00_module_exit - Module cleanup.
6700 **/
6701static void __exit
6702qla2x00_module_exit(void)
6703{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006704 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006705 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006706 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006707 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006708 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006709 if (ctx_cachep)
6710 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006712 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713}
6714
6715module_init(qla2x00_module_init);
6716module_exit(qla2x00_module_exit);
6717
6718MODULE_AUTHOR("QLogic Corporation");
6719MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6720MODULE_LICENSE("GPL");
6721MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006722MODULE_FIRMWARE(FW_FILE_ISP21XX);
6723MODULE_FIRMWARE(FW_FILE_ISP22XX);
6724MODULE_FIRMWARE(FW_FILE_ISP2300);
6725MODULE_FIRMWARE(FW_FILE_ISP2322);
6726MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006727MODULE_FIRMWARE(FW_FILE_ISP25XX);