blob: 82bbb6432f77f803207e9e061c429f96de59a44e [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
Chad Dupuis50280c02013-10-30 03:38:14 -0400116#define MAX_Q_DEPTH 32
117static 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. "
121 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700122
Arun Easi9e522cd2012-08-22 14:21:31 -0400123int ql2xenabledif = 2;
124module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700125MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600126 " Enable T10-CRC-DIF:\n"
127 " Default is 2.\n"
128 " 0 -- No DIF Support\n"
129 " 1 -- Enable DIF for all types\n"
130 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700131
Arun Easi8cb20492011-08-16 11:29:22 -0700132int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700133module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
134MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700135 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600136 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700137 " 0 -- Error isolation disabled\n"
138 " 1 -- Error isolation enabled only for DIX Type 0\n"
139 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700140
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700141int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800142module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700143MODULE_PARM_DESC(ql2xiidmaenable,
144 "Enables iIDMA settings "
145 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
146
Michael Hernandezd7459522016-12-12 14:40:07 -0800147int ql2xmqsupport = 1;
148module_param(ql2xmqsupport, int, S_IRUGO);
149MODULE_PARM_DESC(ql2xmqsupport,
150 "Enable on demand multiple queue pairs support "
151 "Default is 1 for supported. "
152 "Set it to 0 to turn off mq qpair support.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700153
154int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700155module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400156module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700157MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700158 "Option to specify location from which to load ISP firmware:.\n"
159 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700160 " interface.\n"
161 " 1 -- load firmware from flash.\n"
162 " 0 -- use default semantics.\n");
163
Andrew Vasquezae97c912010-02-18 10:07:28 -0800164int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800165module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800166MODULE_PARM_DESC(ql2xetsenable,
167 "Enables firmware ETS burst."
168 "Default is 0 - skip ETS enablement.");
169
Giridhar Malavali69078692010-05-28 15:08:28 -0700170int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700171module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700172MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700173 "Option to specify scheme for request queue posting.\n"
174 " 0 -- Regular doorbell.\n"
175 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700176
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700177int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800178module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700179MODULE_PARM_DESC(ql2xtargetreset,
180 "Enable target reset."
181 "Default is 1 - use hw defaults.");
182
Chad Dupuis4da26e12010-10-15 11:27:40 -0700183int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800184module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700185MODULE_PARM_DESC(ql2xgffidenable,
186 "Enables GFF_ID checks of port type. "
187 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700189int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800190module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700191MODULE_PARM_DESC(ql2xasynctmfenable,
192 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
193 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700194
195int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700196module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700197MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700198 "Option to specify reset behaviour.\n"
199 " 0 (Default) -- Reset on failure.\n"
200 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700201
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200202uint64_t ql2xmaxlun = MAX_LUNS;
203module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700204MODULE_PARM_DESC(ql2xmaxlun,
205 "Defines the maximum LU number to register with the SCSI "
206 "midlayer. Default is 65535.");
207
Giridhar Malavali08de2842011-08-16 11:31:44 -0700208int ql2xmdcapmask = 0x1F;
209module_param(ql2xmdcapmask, int, S_IRUGO);
210MODULE_PARM_DESC(ql2xmdcapmask,
211 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800212 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700213
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800214int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700215module_param(ql2xmdenable, int, S_IRUGO);
216MODULE_PARM_DESC(ql2xmdenable,
217 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800218 "0 - MiniDump disabled. "
219 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700220
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500221int ql2xexlogins = 0;
222module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
223MODULE_PARM_DESC(ql2xexlogins,
224 "Number of extended Logins. "
225 "0 (Default)- Disabled.");
226
Quinn Tran99e1b682017-06-02 09:12:03 -0700227int ql2xexchoffld = 1024;
228module_param(ql2xexchoffld, uint, 0644);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500229MODULE_PARM_DESC(ql2xexchoffld,
Quinn Tran99e1b682017-06-02 09:12:03 -0700230 "Number of target exchanges.");
231
232int ql2xiniexchg = 1024;
233module_param(ql2xiniexchg, uint, 0644);
234MODULE_PARM_DESC(ql2xiniexchg,
235 "Number of initiator exchanges.");
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500236
Himanshu Madhanif198caf2016-01-27 12:03:30 -0500237int ql2xfwholdabts = 0;
238module_param(ql2xfwholdabts, int, S_IRUGO);
239MODULE_PARM_DESC(ql2xfwholdabts,
240 "Allow FW to hold status IOCB until ABTS rsp received. "
241 "0 (Default) Do not set fw option. "
242 "1 - Set fw option to hold ABTS.");
243
Quinn Tran41dc5292017-01-19 22:28:03 -0800244int ql2xmvasynctoatio = 1;
245module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
246MODULE_PARM_DESC(ql2xmvasynctoatio,
247 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
248 "0 (Default). Do not move IOCBs"
249 "1 - Move IOCBs.");
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700252 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 */
254static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500255static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800256static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
257static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500258static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500259static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static int qla2xxx_eh_abort(struct scsi_cmnd *);
261static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700262static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
264static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400266static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400267static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400268static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Michael Hernandez56012362016-12-12 14:40:08 -0800269static int qla2xxx_map_queues(struct Scsi_Host *shost);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700270
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700271struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700273 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700274 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700275
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100276 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700277 .eh_abort_handler = qla2xxx_eh_abort,
278 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700279 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700280 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
281 .eh_host_reset_handler = qla2xxx_eh_host_reset,
282
283 .slave_configure = qla2xxx_slave_configure,
284
285 .slave_alloc = qla2xxx_slave_alloc,
286 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700287 .scan_finished = qla2xxx_scan_finished,
288 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100289 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800290 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700291 .this_id = -1,
292 .cmd_per_lun = 3,
293 .use_clustering = ENABLE_CLUSTERING,
294 .sg_tablesize = SG_ALL,
295
296 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700297 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400298
299 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100300 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700301};
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700304struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306/* TODO Convert to inlines
307 *
308 * Timer routines
309 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700311__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800312qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800314 init_timer(&vha->timer);
315 vha->timer.expires = jiffies + interval * HZ;
316 vha->timer.data = (unsigned long)vha;
317 vha->timer.function = (void (*)(unsigned long))func;
318 add_timer(&vha->timer);
319 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
321
322static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800323qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700325 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700326 if (vha->device_flags & DFLG_DEV_FAILED) {
327 ql_dbg(ql_dbg_timer, vha, 0x600d,
328 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700329 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700330 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800332 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Adrian Bunka824ebb2008-01-17 09:02:15 -0800335static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800336qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800338 del_timer_sync(&vha->timer);
339 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342static int qla2x00_do_dpc(void *data);
343
344static void qla2x00_rst_aen(scsi_qla_host_t *);
345
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800346static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
347 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700348static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800349static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800350int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
351 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400354static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
355 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800356{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700357 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700358 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800359 GFP_KERNEL);
360 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700361 ql_log(ql_log_fatal, vha, 0x003b,
362 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800363 goto fail_req_map;
364 }
365
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700366 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800367 GFP_KERNEL);
368 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700369 ql_log(ql_log_fatal, vha, 0x003c,
370 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800371 goto fail_rsp_map;
372 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800373
374 if (ql2xmqsupport && ha->max_qpairs) {
375 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
376 GFP_KERNEL);
377 if (!ha->queue_pair_map) {
378 ql_log(ql_log_fatal, vha, 0x0180,
379 "Unable to allocate memory for queue pair ptrs.\n");
380 goto fail_qpair_map;
381 }
382 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
383 if (ha->base_qpair == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700384 ql_log(ql_log_warn, vha, 0x00e0,
Michael Hernandezd7459522016-12-12 14:40:07 -0800385 "Failed to allocate base queue pair memory.\n");
386 goto fail_base_qpair;
387 }
388 ha->base_qpair->req = req;
389 ha->base_qpair->rsp = rsp;
390 }
391
Quinn Tran82de8022017-06-13 20:47:17 -0700392 rsp->qpair = ha->base_qpair;
393 rsp->req = req;
394 ha->base_qpair->vha = vha;
395 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
396 ha->queue_pair_map[0] = ha->base_qpair;
397 set_bit(0, ha->qpair_qid_map);
398
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400399 /*
400 * Make sure we record at least the request and response queue zero in
401 * case we need to free them if part of the probe fails.
402 */
403 ha->rsp_q_map[0] = rsp;
404 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800405 set_bit(0, ha->rsp_qid_map);
406 set_bit(0, ha->req_qid_map);
407 return 1;
408
Michael Hernandezd7459522016-12-12 14:40:07 -0800409fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700410 kfree(ha->base_qpair);
411 ha->base_qpair = NULL;
412fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800413 kfree(ha->rsp_q_map);
414 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415fail_rsp_map:
416 kfree(ha->req_q_map);
417 ha->req_q_map = NULL;
418fail_req_map:
419 return -ENOMEM;
420}
421
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700422static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800423{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400424 if (IS_QLAFX00(ha)) {
425 if (req && req->ring_fx00)
426 dma_free_coherent(&ha->pdev->dev,
427 (req->length_fx00 + 1) * sizeof(request_t),
428 req->ring_fx00, req->dma_fx00);
429 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800430 dma_free_coherent(&ha->pdev->dev,
431 (req->length + 1) * sizeof(request_t),
432 req->ring, req->dma);
433
Chad Dupuis8d93f552013-01-30 03:34:37 -0500434 if (req)
435 kfree(req->outstanding_cmds);
436
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800437 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800438}
439
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700440static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
441{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400442 if (IS_QLAFX00(ha)) {
443 if (rsp && rsp->ring)
444 dma_free_coherent(&ha->pdev->dev,
445 (rsp->length_fx00 + 1) * sizeof(request_t),
446 rsp->ring_fx00, rsp->dma_fx00);
447 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700448 dma_free_coherent(&ha->pdev->dev,
449 (rsp->length + 1) * sizeof(response_t),
450 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400451 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700452 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700453}
454
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800455static void qla2x00_free_queues(struct qla_hw_data *ha)
456{
457 struct req_que *req;
458 struct rsp_que *rsp;
459 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800460 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800461
Quinn Tran82de8022017-06-13 20:47:17 -0700462 if (ha->queue_pair_map) {
463 kfree(ha->queue_pair_map);
464 ha->queue_pair_map = NULL;
465 }
466 if (ha->base_qpair) {
467 kfree(ha->base_qpair);
468 ha->base_qpair = NULL;
469 }
470
Quinn Tran093df732016-12-12 14:40:09 -0800471 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700472 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500473 if (!test_bit(cnt, ha->req_qid_map))
474 continue;
475
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800476 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800477 clear_bit(cnt, ha->req_qid_map);
478 ha->req_q_map[cnt] = NULL;
479
480 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700481 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800482 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700483 }
Quinn Tran093df732016-12-12 14:40:09 -0800484 spin_unlock_irqrestore(&ha->hardware_lock, flags);
485
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700486 kfree(ha->req_q_map);
487 ha->req_q_map = NULL;
488
Quinn Tran093df732016-12-12 14:40:09 -0800489
490 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700491 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500492 if (!test_bit(cnt, ha->rsp_qid_map))
493 continue;
494
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700495 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500496 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800497 ha->rsp_q_map[cnt] = NULL;
498 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700499 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800500 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800501 }
Quinn Tran093df732016-12-12 14:40:09 -0800502 spin_unlock_irqrestore(&ha->hardware_lock, flags);
503
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800504 kfree(ha->rsp_q_map);
505 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800506}
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800509qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 static char *pci_bus_modes[] = {
513 "33", "66", "100", "133",
514 };
515 uint16_t pci_bus;
516
517 strcpy(str, "PCI");
518 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
519 if (pci_bus) {
520 strcat(str, "-X (");
521 strcat(str, pci_bus_modes[pci_bus]);
522 } else {
523 pci_bus = (ha->pci_attr & BIT_8) >> 8;
524 strcat(str, " (");
525 strcat(str, pci_bus_modes[pci_bus]);
526 }
527 strcat(str, " MHz)");
528
529 return (str);
530}
531
Andrew Vasquezfca29702005-07-06 10:31:47 -0700532static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800533qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700534{
535 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800536 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700537 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700538
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600539 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700540 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600541 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700542
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600543 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
544 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
545 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700546
547 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500548 switch (lspeed) {
549 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700550 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500551 break;
552 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700553 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500554 break;
555 case 3:
556 strcat(str, "8.0GT/s ");
557 break;
558 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700559 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500560 break;
561 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700562 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
563 strcat(str, lwstr);
564
565 return str;
566 }
567
568 strcpy(str, "PCI");
569 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
570 if (pci_bus == 0 || pci_bus == 8) {
571 strcat(str, " (");
572 strcat(str, pci_bus_modes[pci_bus >> 3]);
573 } else {
574 strcat(str, "-X ");
575 if (pci_bus & BIT_2)
576 strcat(str, "Mode 2");
577 else
578 strcat(str, "Mode 1");
579 strcat(str, " (");
580 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
581 }
582 strcat(str, " MHz)");
583
584 return str;
585}
586
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800587static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400588qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
590 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700592
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400593 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
594 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 if (ha->fw_attributes & BIT_9) {
597 strcat(str, "FLX");
598 return (str);
599 }
600
601 switch (ha->fw_attributes & 0xFF) {
602 case 0x7:
603 strcat(str, "EF");
604 break;
605 case 0x17:
606 strcat(str, "TP");
607 break;
608 case 0x37:
609 strcat(str, "IP");
610 break;
611 case 0x77:
612 strcat(str, "VI");
613 break;
614 default:
615 sprintf(un_str, "(%x)", ha->fw_attributes);
616 strcat(str, un_str);
617 break;
618 }
619 if (ha->fw_attributes & 0x100)
620 strcat(str, "X");
621
622 return (str);
623}
624
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800625static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400626qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700627{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800628 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700629
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400630 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800631 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700632 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700633}
634
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800635void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800636qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700637{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800638 srb_t *sp = ptr;
639 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800640 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800641 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700642
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800643 if (sp->flags & SRB_DMA_VALID) {
644 scsi_dma_unmap(cmd);
645 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700646 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700647
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800648 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
649 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
650 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
651 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
652 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700653
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700654 if (!ctx)
655 goto end;
656
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800657 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
658 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700659 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800660 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
661 }
662
663 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700664 struct crc_context *ctx0 = ctx;
665
666 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800667 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
668 }
669
670 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700671 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800672
673 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700674 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800675 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
676 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
677 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
678 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800679 }
680
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700681end:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800682 CMD_SP(cmd) = NULL;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800683 qla2x00_rel_sp(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800684}
685
Michael Hernandezd7459522016-12-12 14:40:07 -0800686void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800687qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800688{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800689 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800690 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
691
692 cmd->result = res;
693
694 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800695 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800696 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
697 sp, GET_CMD_SP(sp));
698 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400699 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800700 return;
701 }
702 if (!atomic_dec_and_test(&sp->ref_count))
703 return;
704
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800705 qla2x00_sp_free_dma(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800706 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700707}
708
Michael Hernandezd7459522016-12-12 14:40:07 -0800709void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800710qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800711{
712 srb_t *sp = (srb_t *)ptr;
713 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
714 struct qla_hw_data *ha = sp->fcport->vha->hw;
715 void *ctx = GET_CMD_CTX_SP(sp);
716
717 if (sp->flags & SRB_DMA_VALID) {
718 scsi_dma_unmap(cmd);
719 sp->flags &= ~SRB_DMA_VALID;
720 }
721
722 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
723 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
724 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
725 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
726 }
727
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700728 if (!ctx)
729 goto end;
730
Michael Hernandezd7459522016-12-12 14:40:07 -0800731 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
732 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700733 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800734 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
735 }
736
737 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700738 struct crc_context *ctx0 = ctx;
739
740 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800741 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
742 }
743
744 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700745 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800746 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
747 ctx1->fcp_cmnd_dma);
748 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
749 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
750 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
751 mempool_free(ctx1, ha->ctx_mempool);
752 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700753end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800754 CMD_SP(cmd) = NULL;
755 qla2xxx_rel_qpair_sp(sp->qpair, sp);
756}
757
758void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800759qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800760{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800761 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800762 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
763
764 cmd->result = res;
765
766 if (atomic_read(&sp->ref_count) == 0) {
767 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
768 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
769 sp, GET_CMD_SP(sp));
770 if (ql2xextended_error_logging & ql_dbg_io)
771 WARN_ON(atomic_read(&sp->ref_count) == 0);
772 return;
773 }
774 if (!atomic_dec_and_test(&sp->ref_count))
775 return;
776
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800777 qla2xxx_qpair_sp_free_dma(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800778 cmd->scsi_done(cmd);
779}
780
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400781/* If we are SP1 here, we need to still take and release the host_lock as SP1
782 * does not have the changes necessary to avoid taking host->host_lock.
783 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800785qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700786{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700787 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700788 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400789 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800790 struct qla_hw_data *ha = vha->hw;
791 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700792 srb_t *sp;
793 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800794 struct qla_qpair *qpair = NULL;
795 uint32_t tag;
796 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700797
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200798 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
799 cmd->result = DID_NO_CONNECT << 16;
800 goto qc24_fail_command;
801 }
802
Michael Hernandez56012362016-12-12 14:40:08 -0800803 if (ha->mqenable) {
804 if (shost_use_blk_mq(vha->host)) {
805 tag = blk_mq_unique_tag(cmd->request);
806 hwq = blk_mq_unique_tag_to_hwq(tag);
807 qpair = ha->queue_pair_map[hwq];
808 } else if (vha->vp_idx && vha->qpair) {
809 qpair = vha->qpair;
810 }
811
812 if (qpair)
813 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800814 }
815
Andrew Vasquez85880802009-12-15 21:29:46 -0800816 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700817 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400818 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700819 "PCI Channel IO permanent failure, exiting "
820 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700821 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700822 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400823 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700824 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800825 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700826 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700827 goto qc24_fail_command;
828 }
829
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400830 rval = fc_remote_port_chkready(rport);
831 if (rval) {
832 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400833 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700834 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
835 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700836 goto qc24_fail_command;
837 }
838
Arun Easibad75002010-05-04 15:01:30 -0700839 if (!vha->flags.difdix_supported &&
840 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700841 ql_dbg(ql_dbg_io, vha, 0x3004,
842 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
843 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700844 cmd->result = DID_NO_CONNECT << 16;
845 goto qc24_fail_command;
846 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800847
848 if (!fcport) {
849 cmd->result = DID_NO_CONNECT << 16;
850 goto qc24_fail_command;
851 }
852
Andrew Vasquezfca29702005-07-06 10:31:47 -0700853 if (atomic_read(&fcport->state) != FCS_ONLINE) {
854 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700855 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700856 ql_dbg(ql_dbg_io, vha, 0x3005,
857 "Returning DNC, fcport_state=%d loop_state=%d.\n",
858 atomic_read(&fcport->state),
859 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700860 cmd->result = DID_NO_CONNECT << 16;
861 goto qc24_fail_command;
862 }
Mike Christie7b594132008-08-17 15:24:40 -0500863 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700864 }
865
Chad Dupuise05fe292014-09-25 05:16:59 -0400866 /*
867 * Return target busy if we've received a non-zero retry_delay_timer
868 * in a FCP_RSP.
869 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100870 if (fcport->retry_delay_timestamp == 0) {
871 /* retry delay not set */
872 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400873 fcport->retry_delay_timestamp = 0;
874 else
875 goto qc24_target_busy;
876
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500877 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400878 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800879 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700880
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800881 sp->u.scmd.cmd = cmd;
882 sp->type = SRB_SCSI_CMD;
883 atomic_set(&sp->ref_count, 1);
884 CMD_SP(cmd) = (void *)sp;
885 sp->free = qla2x00_sp_free_dma;
886 sp->done = qla2x00_sp_compl;
887
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800888 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700889 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500890 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700891 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700892 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700893 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700894
Andrew Vasquezfca29702005-07-06 10:31:47 -0700895 return 0;
896
897qc24_host_busy_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800898 qla2x00_sp_free_dma(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700899
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800900qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700901 return SCSI_MLQUEUE_HOST_BUSY;
902
Mike Christie7b594132008-08-17 15:24:40 -0500903qc24_target_busy:
904 return SCSI_MLQUEUE_TARGET_BUSY;
905
Andrew Vasquezfca29702005-07-06 10:31:47 -0700906qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800907 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700908
909 return 0;
910}
911
Michael Hernandezd7459522016-12-12 14:40:07 -0800912/* For MQ supported I/O */
913int
914qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
915 struct qla_qpair *qpair)
916{
917 scsi_qla_host_t *vha = shost_priv(host);
918 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
919 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
920 struct qla_hw_data *ha = vha->hw;
921 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
922 srb_t *sp;
923 int rval;
924
925 rval = fc_remote_port_chkready(rport);
926 if (rval) {
927 cmd->result = rval;
928 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
929 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
930 cmd, rval);
931 goto qc24_fail_command;
932 }
933
934 if (!fcport) {
935 cmd->result = DID_NO_CONNECT << 16;
936 goto qc24_fail_command;
937 }
938
939 if (atomic_read(&fcport->state) != FCS_ONLINE) {
940 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
941 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
942 ql_dbg(ql_dbg_io, vha, 0x3077,
943 "Returning DNC, fcport_state=%d loop_state=%d.\n",
944 atomic_read(&fcport->state),
945 atomic_read(&base_vha->loop_state));
946 cmd->result = DID_NO_CONNECT << 16;
947 goto qc24_fail_command;
948 }
949 goto qc24_target_busy;
950 }
951
952 /*
953 * Return target busy if we've received a non-zero retry_delay_timer
954 * in a FCP_RSP.
955 */
956 if (fcport->retry_delay_timestamp == 0) {
957 /* retry delay not set */
958 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
959 fcport->retry_delay_timestamp = 0;
960 else
961 goto qc24_target_busy;
962
963 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
964 if (!sp)
965 goto qc24_host_busy;
966
967 sp->u.scmd.cmd = cmd;
968 sp->type = SRB_SCSI_CMD;
969 atomic_set(&sp->ref_count, 1);
970 CMD_SP(cmd) = (void *)sp;
971 sp->free = qla2xxx_qpair_sp_free_dma;
972 sp->done = qla2xxx_qpair_sp_compl;
973 sp->qpair = qpair;
974
975 rval = ha->isp_ops->start_scsi_mq(sp);
976 if (rval != QLA_SUCCESS) {
977 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
978 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
979 if (rval == QLA_INTERFACE_ERROR)
980 goto qc24_fail_command;
981 goto qc24_host_busy_free_sp;
982 }
983
984 return 0;
985
986qc24_host_busy_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800987 qla2xxx_qpair_sp_free_dma(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800988
989qc24_host_busy:
990 return SCSI_MLQUEUE_HOST_BUSY;
991
992qc24_target_busy:
993 return SCSI_MLQUEUE_TARGET_BUSY;
994
995qc24_fail_command:
996 cmd->scsi_done(cmd);
997
998 return 0;
999}
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001/*
1002 * qla2x00_eh_wait_on_command
1003 * Waits for the command to be returned by the Firmware for some
1004 * max time.
1005 *
1006 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 *
1009 * Return:
1010 * Not Found : 0
1011 * Found : 1
1012 */
1013static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001014qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001016#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001017#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001018 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001019 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1020 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001021 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Andrew Vasquez85880802009-12-15 21:29:46 -08001023 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001024 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1025 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001026 return ret;
1027 }
1028
Lalit Chandivaded9704322009-08-25 11:36:18 -07001029 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001030 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001031 }
1032 if (CMD_SP(cmd))
1033 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
f4f051e2005-04-17 15:02:26 -05001035 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
1038/*
1039 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001040 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 * <= MAX_RETRIES_OF_ISP_ABORT or
1042 * finally HBA is disabled ie marked offline
1043 *
1044 * Input:
1045 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001046 *
1047 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 * Does context switching-Release SPIN_LOCK
1049 * (if any) before calling this routine.
1050 *
1051 * Return:
1052 * Success (Adapter is online) : 0
1053 * Failed (Adapter is offline/disabled) : 1
1054 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001055int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001056qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001058 int return_status;
1059 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 struct qla_hw_data *ha = vha->hw;
1061 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001063 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001064 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1065 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1066 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1067 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 msleep(1000);
1070 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001071 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001072 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 else
1074 return_status = QLA_FUNCTION_FAILED;
1075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return (return_status);
1077}
1078
Quinn Tran726b8542017-01-19 22:28:00 -08001079static inline int test_fcport_count(scsi_qla_host_t *vha)
1080{
1081 struct qla_hw_data *ha = vha->hw;
1082 unsigned long flags;
1083 int res;
1084
1085 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001086 ql_dbg(ql_dbg_init, vha, 0x00ec,
1087 "tgt %p, fcport_count=%d\n",
1088 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001089 res = (vha->fcport_count == 0);
1090 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1091
1092 return res;
1093}
1094
1095/*
1096 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1097 * it has dependency on UNLOADING flag to stop device discovery
1098 */
1099static void
1100qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1101{
1102 qla2x00_mark_all_devices_lost(vha, 0);
1103
1104 wait_event(vha->fcport_waitQ, test_fcport_count(vha));
1105}
1106
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001107/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001108 * qla2x00_wait_for_hba_ready
1109 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001110 *
1111 * Input:
1112 * ha - pointer to host adapter structure
1113 *
1114 * Note:
1115 * Does context switching-Release SPIN_LOCK
1116 * (if any) before calling this routine.
1117 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001118 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001119static void
1120qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001121{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001122 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001123 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001124
Dan Carpenter1d483902016-08-03 21:42:32 +03001125 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1126 ha->flags.mbox_busy) ||
1127 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1128 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1129 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1130 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001131 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001132 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001133}
1134
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001135int
1136qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1137{
1138 int return_status;
1139 unsigned long wait_reset;
1140 struct qla_hw_data *ha = vha->hw;
1141 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1142
1143 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1144 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1145 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1146 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1147 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1148
1149 msleep(1000);
1150
1151 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1152 ha->flags.chip_reset_done)
1153 break;
1154 }
1155 if (ha->flags.chip_reset_done)
1156 return_status = QLA_SUCCESS;
1157 else
1158 return_status = QLA_FUNCTION_FAILED;
1159
1160 return return_status;
1161}
1162
Giridhar Malavali083a4692010-05-28 15:08:18 -07001163static void
1164sp_get(struct srb *sp)
1165{
1166 atomic_inc(&sp->ref_count);
1167}
1168
Sawan Chandaka4655372016-07-06 11:14:32 -04001169#define ISP_REG_DISCONNECT 0xffffffffU
1170/**************************************************************************
1171* qla2x00_isp_reg_stat
1172*
1173* Description:
1174* Read the host status register of ISP before aborting the command.
1175*
1176* Input:
1177* ha = pointer to host adapter structure.
1178*
1179*
1180* Returns:
1181* Either true or false.
1182*
1183* Note: Return true if there is register disconnect.
1184**************************************************************************/
1185static inline
1186uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1187{
1188 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001189 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001190
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001191 if (IS_P3P_TYPE(ha))
1192 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1193 else
1194 return ((RD_REG_DWORD(&reg->host_status)) ==
1195 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001196}
1197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198/**************************************************************************
1199* qla2xxx_eh_abort
1200*
1201* Description:
1202* The abort function will abort the specified command.
1203*
1204* Input:
1205* cmd = Linux SCSI command packet to be aborted.
1206*
1207* Returns:
1208* Either SUCCESS or FAILED.
1209*
1210* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001211* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001213static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1215{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001217 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001218 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001219 unsigned int id;
1220 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001221 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001222 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001223 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Sawan Chandaka4655372016-07-06 11:14:32 -04001225 if (qla2x00_isp_reg_stat(ha)) {
1226 ql_log(ql_log_info, vha, 0x8042,
1227 "PCI/Register disconnect, exiting.\n");
1228 return FAILED;
1229 }
f4f051e2005-04-17 15:02:26 -05001230 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001231 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001233 ret = fc_block_scsi_eh(cmd);
1234 if (ret != 0)
1235 return ret;
1236 ret = SUCCESS;
1237
f4f051e2005-04-17 15:02:26 -05001238 id = cmd->device->id;
1239 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001241 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001242 sp = (srb_t *) CMD_SP(cmd);
1243 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001244 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001245 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001246 }
Mike Christie170babc2010-10-15 11:27:47 -07001247
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001248 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001249 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1250 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001251
1252 /* Get a reference to the sp and drop the lock.*/
1253 sp_get(sp);
1254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001255 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001256 rval = ha->isp_ops->abort_command(sp);
1257 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001258 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001259 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001260 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001261 ret = FAILED;
1262
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001263 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001264 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001265 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001266 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001267 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001268 wait = 1;
1269 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001270
1271 spin_lock_irqsave(&ha->hardware_lock, flags);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001272 sp->done(sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001273 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001274
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001275 /* Did the command return during mailbox execution? */
1276 if (ret == FAILED && !CMD_SP(cmd))
1277 ret = SUCCESS;
1278
f4f051e2005-04-17 15:02:26 -05001279 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001280 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001282 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001283 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001284 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001288 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001289 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001290 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
f4f051e2005-04-17 15:02:26 -05001292 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001295int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001296qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001297 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001299 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001300 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001301 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001302 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001303 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001304 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Andrew Vasquez523ec772008-04-03 13:13:24 -07001306 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001309 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001310 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001311 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001312 sp = req->outstanding_cmds[cnt];
1313 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001314 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001315 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001316 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001317 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001318 continue;
1319 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001320 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001321 switch (type) {
1322 case WAIT_HOST:
1323 match = 1;
1324 break;
1325 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001326 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001327 break;
1328 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001329 match = (cmd->device->id == t &&
1330 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001331 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001333 if (!match)
1334 continue;
1335
1336 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001337 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001338 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001341
1342 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Andrew Vasquez523ec772008-04-03 13:13:24 -07001345static char *reset_errors[] = {
1346 "HBA not online",
1347 "HBA not ready",
1348 "Task management failed",
1349 "Waiting for command completions",
1350};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Andrew Vasquez523ec772008-04-03 13:13:24 -07001352static int
1353__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001354 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001355{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001356 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001357 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1358 int err;
1359
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001360 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001361 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001362 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001363
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001364 err = fc_block_scsi_eh(cmd);
1365 if (err != 0)
1366 return err;
1367
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001368 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001369 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001371
1372 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001373 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1374 ql_log(ql_log_warn, vha, 0x800a,
1375 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001376 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001377 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001378 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001379 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 != QLA_SUCCESS) {
1381 ql_log(ql_log_warn, vha, 0x800c,
1382 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001383 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001384 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001385 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001387 cmd->device->lun, type) != QLA_SUCCESS) {
1388 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001389 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001390 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001391 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001392
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001393 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001394 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001395 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001396
1397 return SUCCESS;
1398
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001399eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001400 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001401 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001402 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1403 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001404 return FAILED;
1405}
1406
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001407static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1409{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001410 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1411 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Sawan Chandaka4655372016-07-06 11:14:32 -04001413 if (qla2x00_isp_reg_stat(ha)) {
1414 ql_log(ql_log_info, vha, 0x803e,
1415 "PCI/Register disconnect, exiting.\n");
1416 return FAILED;
1417 }
1418
Andrew Vasquez523ec772008-04-03 13:13:24 -07001419 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1420 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421}
1422
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001424qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001426 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1427 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Sawan Chandaka4655372016-07-06 11:14:32 -04001429 if (qla2x00_isp_reg_stat(ha)) {
1430 ql_log(ql_log_info, vha, 0x803f,
1431 "PCI/Register disconnect, exiting.\n");
1432 return FAILED;
1433 }
1434
Andrew Vasquez523ec772008-04-03 13:13:24 -07001435 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1436 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439/**************************************************************************
1440* qla2xxx_eh_bus_reset
1441*
1442* Description:
1443* The bus reset function will reset the bus and abort any executing
1444* commands.
1445*
1446* Input:
1447* cmd = Linux SCSI command packet of the command that cause the
1448* bus reset.
1449*
1450* Returns:
1451* SUCCESS/FAILURE (defined as macro in scsi.h).
1452*
1453**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001454static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1456{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001458 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001459 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001460 unsigned int id;
1461 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001462 struct qla_hw_data *ha = vha->hw;
1463
1464 if (qla2x00_isp_reg_stat(ha)) {
1465 ql_log(ql_log_info, vha, 0x8040,
1466 "PCI/Register disconnect, exiting.\n");
1467 return FAILED;
1468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
f4f051e2005-04-17 15:02:26 -05001470 id = cmd->device->id;
1471 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001472
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001474 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001477 ret = fc_block_scsi_eh(cmd);
1478 if (ret != 0)
1479 return ret;
1480 ret = FAILED;
1481
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001482 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001483 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001486 ql_log(ql_log_fatal, vha, 0x8013,
1487 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001488 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 }
1490
Saurav Kashyapad5376892011-11-18 09:02:09 -08001491 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1492 ret = SUCCESS;
1493
f4f051e2005-04-17 15:02:26 -05001494 if (ret == FAILED)
1495 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001497 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001498 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001499 QLA_SUCCESS) {
1500 ql_log(ql_log_warn, vha, 0x8014,
1501 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001502 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
f4f051e2005-04-17 15:02:26 -05001505eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001506 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001507 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001508 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
f4f051e2005-04-17 15:02:26 -05001510 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511}
1512
1513/**************************************************************************
1514* qla2xxx_eh_host_reset
1515*
1516* Description:
1517* The reset function will reset the Adapter.
1518*
1519* Input:
1520* cmd = Linux SCSI command packet of the command that cause the
1521* adapter reset.
1522*
1523* Returns:
1524* Either SUCCESS or FAILED.
1525*
1526* Note:
1527**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001528static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1530{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001533 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001534 unsigned int id;
1535 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Sawan Chandaka4655372016-07-06 11:14:32 -04001538 if (qla2x00_isp_reg_stat(ha)) {
1539 ql_log(ql_log_info, vha, 0x8041,
1540 "PCI/Register disconnect, exiting.\n");
1541 schedule_work(&ha->board_disable);
1542 return SUCCESS;
1543 }
1544
f4f051e2005-04-17 15:02:26 -05001545 id = cmd->device->id;
1546 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001547
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001548 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001549 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Chad Dupuis63ee7072014-04-11 16:54:46 -04001551 /*
1552 * No point in issuing another reset if one is active. Also do not
1553 * attempt a reset if we are updating flash.
1554 */
1555 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001556 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558 if (vha != base_vha) {
1559 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001560 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001562 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001563 if (!qla82xx_fcoe_ctx_reset(vha)) {
1564 /* Ctx reset success */
1565 ret = SUCCESS;
1566 goto eh_host_reset_lock;
1567 }
1568 /* fall thru if ctx reset failed */
1569 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001570 if (ha->wq)
1571 flush_workqueue(ha->wq);
1572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001573 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001574 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1576 /* failed. schedule dpc to try */
1577 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1578
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001579 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1580 ql_log(ql_log_warn, vha, 0x802a,
1581 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001582 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001583 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001584 }
1585 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001589 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001590 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001591 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
f4f051e2005-04-17 15:02:26 -05001593eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001594 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001595 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001596 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
f4f051e2005-04-17 15:02:26 -05001598 return ret;
1599}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601/*
1602* qla2x00_loop_reset
1603* Issue loop reset.
1604*
1605* Input:
1606* ha = adapter block pointer.
1607*
1608* Returns:
1609* 0 = success
1610*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001611int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001614 int ret;
bdf79622005-04-17 15:06:53 -05001615 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Armen Baloyan58547712013-08-27 01:37:33 -04001618 if (IS_QLAFX00(ha)) {
1619 return qlafx00_loop_reset(vha);
1620 }
1621
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001622 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001623 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1624 if (fcport->port_type != FCT_TARGET)
1625 continue;
1626
1627 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1628 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001629 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001630 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001631 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001632 }
1633 }
1634 }
1635
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001636
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001637 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001638 atomic_set(&vha->loop_state, LOOP_DOWN);
1639 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1640 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001642 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001643 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1644 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 }
1647
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001648 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001650 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001651 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1652 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001653 }
1654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001656 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001658 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001661void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001663{
Bill Kuzeja4cd3b6e2017-05-25 15:26:31 -04001664 int que, cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001665 unsigned long flags;
1666 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001668 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001669 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1670 struct qla_tgt_cmd *cmd;
1671 uint8_t trace = 0;
Arun Easic0cb4492014-09-25 06:14:51 -04001672
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001673 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001674 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001675 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001676 if (!req)
1677 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001678 if (!req->outstanding_cmds)
1679 continue;
1680 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001681 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001682 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001683 req->outstanding_cmds[cnt] = NULL;
Quinn Tranc5419e22017-06-13 20:47:16 -07001684 if (sp->cmd_type == TYPE_SRB) {
1685 /*
1686 * Don't abort commands in adapter
1687 * during EEH recovery as it's not
1688 * accessible/responding.
1689 */
1690 if (GET_CMD_SP(sp) &&
1691 !ha->flags.eeh_busy &&
1692 (sp->type == SRB_SCSI_CMD)) {
1693 /*
1694 * Get a reference to the sp
1695 * and drop the lock. The
1696 * reference ensures this
1697 * sp->done() call and not the
1698 * call in qla2xxx_eh_abort()
1699 * ends the SCSI command (with
1700 * result 'res').
1701 */
1702 sp_get(sp);
1703 spin_unlock_irqrestore(
1704 &ha->hardware_lock, flags);
1705 status = qla2xxx_eh_abort(
1706 GET_CMD_SP(sp));
1707 spin_lock_irqsave(
1708 &ha->hardware_lock, flags);
1709 /*
1710 * Get rid of extra reference
1711 * if immediate exit from
1712 * ql2xxx_eh_abort
1713 */
1714 if (status == FAILED &&
1715 (qla2x00_isp_reg_stat(ha)))
1716 atomic_dec(
1717 &sp->ref_count);
1718 }
1719 sp->done(sp, res);
1720 } else {
1721 if (!vha->hw->tgt.tgt_ops || !tgt ||
1722 qla_ini_mode_enabled(vha)) {
1723 if (!trace)
1724 ql_dbg(ql_dbg_tgt_mgt,
1725 vha, 0xf003,
1726 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1727 vha->dpc_flags);
1728 continue;
1729 }
1730 cmd = (struct qla_tgt_cmd *)sp;
1731 qlt_abort_cmd_on_host_reset(cmd->vha,
1732 cmd);
1733 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001734 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001735 }
1736 }
1737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1738}
1739
f4f051e2005-04-17 15:02:26 -05001740static int
1741qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742{
bdf79622005-04-17 15:06:53 -05001743 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001745 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001746 return -ENXIO;
1747
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001748 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001749
1750 return 0;
1751}
1752
1753static int
1754qla2xxx_slave_configure(struct scsi_device *sdev)
1755{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001757 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001758
Arun Easi9e522cd2012-08-22 14:21:31 -04001759 if (IS_T10_PI_CAPABLE(vha->hw))
1760 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1761
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001762 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001763 return 0;
1764}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
f4f051e2005-04-17 15:02:26 -05001766static void
1767qla2xxx_slave_destroy(struct scsi_device *sdev)
1768{
1769 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770}
1771
1772/**
1773 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1774 * @ha: HA context
1775 *
1776 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1777 * supported addressing method.
1778 */
1779static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001780qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001782 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Yang Hongyang6a355282009-04-06 19:01:13 -07001785 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001786 /* Any upper-dword bits set? */
1787 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001788 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001789 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001791 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1792 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001793 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001796
Yang Hongyang284901a2009-04-06 19:01:15 -07001797 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1798 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001801static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001802qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001803{
1804 unsigned long flags = 0;
1805 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1806
1807 spin_lock_irqsave(&ha->hardware_lock, flags);
1808 ha->interrupts_on = 1;
1809 /* enable risc and host interrupts */
1810 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1811 RD_REG_WORD(&reg->ictrl);
1812 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1813
1814}
1815
1816static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001817qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001818{
1819 unsigned long flags = 0;
1820 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1821
1822 spin_lock_irqsave(&ha->hardware_lock, flags);
1823 ha->interrupts_on = 0;
1824 /* disable risc and host interrupts */
1825 WRT_REG_WORD(&reg->ictrl, 0);
1826 RD_REG_WORD(&reg->ictrl);
1827 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1828}
1829
1830static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001831qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001832{
1833 unsigned long flags = 0;
1834 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1835
1836 spin_lock_irqsave(&ha->hardware_lock, flags);
1837 ha->interrupts_on = 1;
1838 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1839 RD_REG_DWORD(&reg->ictrl);
1840 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1841}
1842
1843static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001845{
1846 unsigned long flags = 0;
1847 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1848
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001849 if (IS_NOPOLLING_TYPE(ha))
1850 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001851 spin_lock_irqsave(&ha->hardware_lock, flags);
1852 ha->interrupts_on = 0;
1853 WRT_REG_DWORD(&reg->ictrl, 0);
1854 RD_REG_DWORD(&reg->ictrl);
1855 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1856}
1857
Giridhar Malavali706f4572011-11-18 09:03:16 -08001858static int
1859qla2x00_iospace_config(struct qla_hw_data *ha)
1860{
1861 resource_size_t pio;
1862 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001863
Giridhar Malavali706f4572011-11-18 09:03:16 -08001864 if (pci_request_selected_regions(ha->pdev, ha->bars,
1865 QLA2XXX_DRIVER_NAME)) {
1866 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1867 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1868 pci_name(ha->pdev));
1869 goto iospace_error_exit;
1870 }
1871 if (!(ha->bars & 1))
1872 goto skip_pio;
1873
1874 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1875 pio = pci_resource_start(ha->pdev, 0);
1876 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1877 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1878 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1879 "Invalid pci I/O region size (%s).\n",
1880 pci_name(ha->pdev));
1881 pio = 0;
1882 }
1883 } else {
1884 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1885 "Region #0 no a PIO resource (%s).\n",
1886 pci_name(ha->pdev));
1887 pio = 0;
1888 }
1889 ha->pio_address = pio;
1890 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1891 "PIO address=%llu.\n",
1892 (unsigned long long)ha->pio_address);
1893
1894skip_pio:
1895 /* Use MMIO operations for all accesses. */
1896 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1897 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1898 "Region #1 not an MMIO resource (%s), aborting.\n",
1899 pci_name(ha->pdev));
1900 goto iospace_error_exit;
1901 }
1902 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1903 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1904 "Invalid PCI mem region size (%s), aborting.\n",
1905 pci_name(ha->pdev));
1906 goto iospace_error_exit;
1907 }
1908
1909 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1910 if (!ha->iobase) {
1911 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1912 "Cannot remap MMIO (%s), aborting.\n",
1913 pci_name(ha->pdev));
1914 goto iospace_error_exit;
1915 }
1916
1917 /* Determine queue resources */
1918 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001919 ha->msix_count = QLA_BASE_VECTORS;
Michael Hernandezd7459522016-12-12 14:40:07 -08001920 if (!ql2xmqsupport || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08001921 goto mqiobase_exit;
1922
1923 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1924 pci_resource_len(ha->pdev, 3));
1925 if (ha->mqiobase) {
1926 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1927 "MQIO Base=%p.\n", ha->mqiobase);
1928 /* Read MSIX vector size of the board */
1929 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08001930 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001931 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08001932 /* MB interrupt uses 1 vector */
1933 ha->max_req_queues = ha->msix_count - 1;
1934 ha->max_rsp_queues = ha->max_req_queues;
1935 /* Queue pairs is the max value minus the base queue pair */
1936 ha->max_qpairs = ha->max_rsp_queues - 1;
1937 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
1938 "Max no of queues pairs: %d.\n", ha->max_qpairs);
1939
Giridhar Malavali706f4572011-11-18 09:03:16 -08001940 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08001941 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08001942 } else
1943 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1944 "BAR 3 not enabled.\n");
1945
1946mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08001947 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001948 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08001949 return (0);
1950
1951iospace_error_exit:
1952 return (-ENOMEM);
1953}
1954
1955
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001956static int
1957qla83xx_iospace_config(struct qla_hw_data *ha)
1958{
1959 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001960
1961 if (pci_request_selected_regions(ha->pdev, ha->bars,
1962 QLA2XXX_DRIVER_NAME)) {
1963 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1964 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1965 pci_name(ha->pdev));
1966
1967 goto iospace_error_exit;
1968 }
1969
1970 /* Use MMIO operations for all accesses. */
1971 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1972 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1973 "Invalid pci I/O region size (%s).\n",
1974 pci_name(ha->pdev));
1975 goto iospace_error_exit;
1976 }
1977 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1978 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1979 "Invalid PCI mem region size (%s), aborting\n",
1980 pci_name(ha->pdev));
1981 goto iospace_error_exit;
1982 }
1983
1984 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1985 if (!ha->iobase) {
1986 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1987 "Cannot remap MMIO (%s), aborting.\n",
1988 pci_name(ha->pdev));
1989 goto iospace_error_exit;
1990 }
1991
1992 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1993 /* 83XX 26XX always use MQ type access for queues
1994 * - mbar 2, a.k.a region 4 */
1995 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001996 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001997 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1998 pci_resource_len(ha->pdev, 4));
1999
2000 if (!ha->mqiobase) {
2001 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2002 "BAR2/region4 not enabled\n");
2003 goto mqiobase_exit;
2004 }
2005
2006 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2007 pci_resource_len(ha->pdev, 2));
2008 if (ha->msixbase) {
2009 /* Read MSIX vector size of the board */
2010 pci_read_config_word(ha->pdev,
2011 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002012 ha->msix_count = msix + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002013 /*
2014 * By default, driver uses at least two msix vectors
2015 * (default & rspq)
2016 */
Michael Hernandezd7459522016-12-12 14:40:07 -08002017 if (ql2xmqsupport) {
2018 /* MB interrupt uses 1 vector */
2019 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002020
2021 /* ATIOQ needs 1 vector. That's 1 less QPair */
2022 if (QLA_TGT_MODE_ENABLED())
2023 ha->max_req_queues--;
2024
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002025 ha->max_rsp_queues = ha->max_req_queues;
2026
Michael Hernandezd7459522016-12-12 14:40:07 -08002027 /* Queue pairs is the max value minus
2028 * the base queue pair */
2029 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002030 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002031 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002032 }
2033 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002034 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002035 } else
2036 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2037 "BAR 1 not enabled.\n");
2038
2039mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002040 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002041 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002042 return 0;
2043
2044iospace_error_exit:
2045 return -ENOMEM;
2046}
2047
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002048static struct isp_operations qla2100_isp_ops = {
2049 .pci_config = qla2100_pci_config,
2050 .reset_chip = qla2x00_reset_chip,
2051 .chip_diag = qla2x00_chip_diag,
2052 .config_rings = qla2x00_config_rings,
2053 .reset_adapter = qla2x00_reset_adapter,
2054 .nvram_config = qla2x00_nvram_config,
2055 .update_fw_options = qla2x00_update_fw_options,
2056 .load_risc = qla2x00_load_risc,
2057 .pci_info_str = qla2x00_pci_info_str,
2058 .fw_version_str = qla2x00_fw_version_str,
2059 .intr_handler = qla2100_intr_handler,
2060 .enable_intrs = qla2x00_enable_intrs,
2061 .disable_intrs = qla2x00_disable_intrs,
2062 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002063 .target_reset = qla2x00_abort_target,
2064 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002065 .fabric_login = qla2x00_login_fabric,
2066 .fabric_logout = qla2x00_fabric_logout,
2067 .calc_req_entries = qla2x00_calc_iocbs_32,
2068 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2069 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2070 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2071 .read_nvram = qla2x00_read_nvram_data,
2072 .write_nvram = qla2x00_write_nvram_data,
2073 .fw_dump = qla2100_fw_dump,
2074 .beacon_on = NULL,
2075 .beacon_off = NULL,
2076 .beacon_blink = NULL,
2077 .read_optrom = qla2x00_read_optrom_data,
2078 .write_optrom = qla2x00_write_optrom_data,
2079 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002081 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002082 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002083 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002084 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002085};
2086
2087static struct isp_operations qla2300_isp_ops = {
2088 .pci_config = qla2300_pci_config,
2089 .reset_chip = qla2x00_reset_chip,
2090 .chip_diag = qla2x00_chip_diag,
2091 .config_rings = qla2x00_config_rings,
2092 .reset_adapter = qla2x00_reset_adapter,
2093 .nvram_config = qla2x00_nvram_config,
2094 .update_fw_options = qla2x00_update_fw_options,
2095 .load_risc = qla2x00_load_risc,
2096 .pci_info_str = qla2x00_pci_info_str,
2097 .fw_version_str = qla2x00_fw_version_str,
2098 .intr_handler = qla2300_intr_handler,
2099 .enable_intrs = qla2x00_enable_intrs,
2100 .disable_intrs = qla2x00_disable_intrs,
2101 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002102 .target_reset = qla2x00_abort_target,
2103 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002104 .fabric_login = qla2x00_login_fabric,
2105 .fabric_logout = qla2x00_fabric_logout,
2106 .calc_req_entries = qla2x00_calc_iocbs_32,
2107 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2108 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2109 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2110 .read_nvram = qla2x00_read_nvram_data,
2111 .write_nvram = qla2x00_write_nvram_data,
2112 .fw_dump = qla2300_fw_dump,
2113 .beacon_on = qla2x00_beacon_on,
2114 .beacon_off = qla2x00_beacon_off,
2115 .beacon_blink = qla2x00_beacon_blink,
2116 .read_optrom = qla2x00_read_optrom_data,
2117 .write_optrom = qla2x00_write_optrom_data,
2118 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002120 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002121 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002122 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002123 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002124};
2125
2126static struct isp_operations qla24xx_isp_ops = {
2127 .pci_config = qla24xx_pci_config,
2128 .reset_chip = qla24xx_reset_chip,
2129 .chip_diag = qla24xx_chip_diag,
2130 .config_rings = qla24xx_config_rings,
2131 .reset_adapter = qla24xx_reset_adapter,
2132 .nvram_config = qla24xx_nvram_config,
2133 .update_fw_options = qla24xx_update_fw_options,
2134 .load_risc = qla24xx_load_risc,
2135 .pci_info_str = qla24xx_pci_info_str,
2136 .fw_version_str = qla24xx_fw_version_str,
2137 .intr_handler = qla24xx_intr_handler,
2138 .enable_intrs = qla24xx_enable_intrs,
2139 .disable_intrs = qla24xx_disable_intrs,
2140 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002141 .target_reset = qla24xx_abort_target,
2142 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002143 .fabric_login = qla24xx_login_fabric,
2144 .fabric_logout = qla24xx_fabric_logout,
2145 .calc_req_entries = NULL,
2146 .build_iocbs = NULL,
2147 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2148 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2149 .read_nvram = qla24xx_read_nvram_data,
2150 .write_nvram = qla24xx_write_nvram_data,
2151 .fw_dump = qla24xx_fw_dump,
2152 .beacon_on = qla24xx_beacon_on,
2153 .beacon_off = qla24xx_beacon_off,
2154 .beacon_blink = qla24xx_beacon_blink,
2155 .read_optrom = qla24xx_read_optrom_data,
2156 .write_optrom = qla24xx_write_optrom_data,
2157 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002159 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002160 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002161 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002162 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002163};
2164
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002165static struct isp_operations qla25xx_isp_ops = {
2166 .pci_config = qla25xx_pci_config,
2167 .reset_chip = qla24xx_reset_chip,
2168 .chip_diag = qla24xx_chip_diag,
2169 .config_rings = qla24xx_config_rings,
2170 .reset_adapter = qla24xx_reset_adapter,
2171 .nvram_config = qla24xx_nvram_config,
2172 .update_fw_options = qla24xx_update_fw_options,
2173 .load_risc = qla24xx_load_risc,
2174 .pci_info_str = qla24xx_pci_info_str,
2175 .fw_version_str = qla24xx_fw_version_str,
2176 .intr_handler = qla24xx_intr_handler,
2177 .enable_intrs = qla24xx_enable_intrs,
2178 .disable_intrs = qla24xx_disable_intrs,
2179 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002180 .target_reset = qla24xx_abort_target,
2181 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002182 .fabric_login = qla24xx_login_fabric,
2183 .fabric_logout = qla24xx_fabric_logout,
2184 .calc_req_entries = NULL,
2185 .build_iocbs = NULL,
2186 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2187 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2188 .read_nvram = qla25xx_read_nvram_data,
2189 .write_nvram = qla25xx_write_nvram_data,
2190 .fw_dump = qla25xx_fw_dump,
2191 .beacon_on = qla24xx_beacon_on,
2192 .beacon_off = qla24xx_beacon_off,
2193 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002194 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002195 .write_optrom = qla24xx_write_optrom_data,
2196 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002197 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002198 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002199 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002200 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002201 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002202};
2203
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002204static struct isp_operations qla81xx_isp_ops = {
2205 .pci_config = qla25xx_pci_config,
2206 .reset_chip = qla24xx_reset_chip,
2207 .chip_diag = qla24xx_chip_diag,
2208 .config_rings = qla24xx_config_rings,
2209 .reset_adapter = qla24xx_reset_adapter,
2210 .nvram_config = qla81xx_nvram_config,
2211 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002212 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002213 .pci_info_str = qla24xx_pci_info_str,
2214 .fw_version_str = qla24xx_fw_version_str,
2215 .intr_handler = qla24xx_intr_handler,
2216 .enable_intrs = qla24xx_enable_intrs,
2217 .disable_intrs = qla24xx_disable_intrs,
2218 .abort_command = qla24xx_abort_command,
2219 .target_reset = qla24xx_abort_target,
2220 .lun_reset = qla24xx_lun_reset,
2221 .fabric_login = qla24xx_login_fabric,
2222 .fabric_logout = qla24xx_fabric_logout,
2223 .calc_req_entries = NULL,
2224 .build_iocbs = NULL,
2225 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2226 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002227 .read_nvram = NULL,
2228 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002229 .fw_dump = qla81xx_fw_dump,
2230 .beacon_on = qla24xx_beacon_on,
2231 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002232 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002233 .read_optrom = qla25xx_read_optrom_data,
2234 .write_optrom = qla24xx_write_optrom_data,
2235 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002236 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002237 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002238 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002239 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002240 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002241};
2242
2243static struct isp_operations qla82xx_isp_ops = {
2244 .pci_config = qla82xx_pci_config,
2245 .reset_chip = qla82xx_reset_chip,
2246 .chip_diag = qla24xx_chip_diag,
2247 .config_rings = qla82xx_config_rings,
2248 .reset_adapter = qla24xx_reset_adapter,
2249 .nvram_config = qla81xx_nvram_config,
2250 .update_fw_options = qla24xx_update_fw_options,
2251 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002252 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002253 .fw_version_str = qla24xx_fw_version_str,
2254 .intr_handler = qla82xx_intr_handler,
2255 .enable_intrs = qla82xx_enable_intrs,
2256 .disable_intrs = qla82xx_disable_intrs,
2257 .abort_command = qla24xx_abort_command,
2258 .target_reset = qla24xx_abort_target,
2259 .lun_reset = qla24xx_lun_reset,
2260 .fabric_login = qla24xx_login_fabric,
2261 .fabric_logout = qla24xx_fabric_logout,
2262 .calc_req_entries = NULL,
2263 .build_iocbs = NULL,
2264 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2265 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2266 .read_nvram = qla24xx_read_nvram_data,
2267 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002268 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002269 .beacon_on = qla82xx_beacon_on,
2270 .beacon_off = qla82xx_beacon_off,
2271 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002272 .read_optrom = qla82xx_read_optrom_data,
2273 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002274 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002275 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002276 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002277 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002278 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002279 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002280};
2281
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002282static struct isp_operations qla8044_isp_ops = {
2283 .pci_config = qla82xx_pci_config,
2284 .reset_chip = qla82xx_reset_chip,
2285 .chip_diag = qla24xx_chip_diag,
2286 .config_rings = qla82xx_config_rings,
2287 .reset_adapter = qla24xx_reset_adapter,
2288 .nvram_config = qla81xx_nvram_config,
2289 .update_fw_options = qla24xx_update_fw_options,
2290 .load_risc = qla82xx_load_risc,
2291 .pci_info_str = qla24xx_pci_info_str,
2292 .fw_version_str = qla24xx_fw_version_str,
2293 .intr_handler = qla8044_intr_handler,
2294 .enable_intrs = qla82xx_enable_intrs,
2295 .disable_intrs = qla82xx_disable_intrs,
2296 .abort_command = qla24xx_abort_command,
2297 .target_reset = qla24xx_abort_target,
2298 .lun_reset = qla24xx_lun_reset,
2299 .fabric_login = qla24xx_login_fabric,
2300 .fabric_logout = qla24xx_fabric_logout,
2301 .calc_req_entries = NULL,
2302 .build_iocbs = NULL,
2303 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2304 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2305 .read_nvram = NULL,
2306 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002307 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002308 .beacon_on = qla82xx_beacon_on,
2309 .beacon_off = qla82xx_beacon_off,
2310 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002311 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002312 .write_optrom = qla8044_write_optrom_data,
2313 .get_flash_version = qla82xx_get_flash_version,
2314 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002315 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002316 .abort_isp = qla8044_abort_isp,
2317 .iospace_config = qla82xx_iospace_config,
2318 .initialize_adapter = qla2x00_initialize_adapter,
2319};
2320
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002321static struct isp_operations qla83xx_isp_ops = {
2322 .pci_config = qla25xx_pci_config,
2323 .reset_chip = qla24xx_reset_chip,
2324 .chip_diag = qla24xx_chip_diag,
2325 .config_rings = qla24xx_config_rings,
2326 .reset_adapter = qla24xx_reset_adapter,
2327 .nvram_config = qla81xx_nvram_config,
2328 .update_fw_options = qla81xx_update_fw_options,
2329 .load_risc = qla81xx_load_risc,
2330 .pci_info_str = qla24xx_pci_info_str,
2331 .fw_version_str = qla24xx_fw_version_str,
2332 .intr_handler = qla24xx_intr_handler,
2333 .enable_intrs = qla24xx_enable_intrs,
2334 .disable_intrs = qla24xx_disable_intrs,
2335 .abort_command = qla24xx_abort_command,
2336 .target_reset = qla24xx_abort_target,
2337 .lun_reset = qla24xx_lun_reset,
2338 .fabric_login = qla24xx_login_fabric,
2339 .fabric_logout = qla24xx_fabric_logout,
2340 .calc_req_entries = NULL,
2341 .build_iocbs = NULL,
2342 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2343 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2344 .read_nvram = NULL,
2345 .write_nvram = NULL,
2346 .fw_dump = qla83xx_fw_dump,
2347 .beacon_on = qla24xx_beacon_on,
2348 .beacon_off = qla24xx_beacon_off,
2349 .beacon_blink = qla83xx_beacon_blink,
2350 .read_optrom = qla25xx_read_optrom_data,
2351 .write_optrom = qla24xx_write_optrom_data,
2352 .get_flash_version = qla24xx_get_flash_version,
2353 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002354 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002355 .abort_isp = qla2x00_abort_isp,
2356 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002357 .initialize_adapter = qla2x00_initialize_adapter,
2358};
2359
2360static struct isp_operations qlafx00_isp_ops = {
2361 .pci_config = qlafx00_pci_config,
2362 .reset_chip = qlafx00_soft_reset,
2363 .chip_diag = qlafx00_chip_diag,
2364 .config_rings = qlafx00_config_rings,
2365 .reset_adapter = qlafx00_soft_reset,
2366 .nvram_config = NULL,
2367 .update_fw_options = NULL,
2368 .load_risc = NULL,
2369 .pci_info_str = qlafx00_pci_info_str,
2370 .fw_version_str = qlafx00_fw_version_str,
2371 .intr_handler = qlafx00_intr_handler,
2372 .enable_intrs = qlafx00_enable_intrs,
2373 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002374 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002375 .target_reset = qlafx00_abort_target,
2376 .lun_reset = qlafx00_lun_reset,
2377 .fabric_login = NULL,
2378 .fabric_logout = NULL,
2379 .calc_req_entries = NULL,
2380 .build_iocbs = NULL,
2381 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2382 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2383 .read_nvram = qla24xx_read_nvram_data,
2384 .write_nvram = qla24xx_write_nvram_data,
2385 .fw_dump = NULL,
2386 .beacon_on = qla24xx_beacon_on,
2387 .beacon_off = qla24xx_beacon_off,
2388 .beacon_blink = NULL,
2389 .read_optrom = qla24xx_read_optrom_data,
2390 .write_optrom = qla24xx_write_optrom_data,
2391 .get_flash_version = qla24xx_get_flash_version,
2392 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002393 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002394 .abort_isp = qlafx00_abort_isp,
2395 .iospace_config = qlafx00_iospace_config,
2396 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002397};
2398
Chad Dupuisf73cb692014-02-26 04:15:06 -05002399static struct isp_operations qla27xx_isp_ops = {
2400 .pci_config = qla25xx_pci_config,
2401 .reset_chip = qla24xx_reset_chip,
2402 .chip_diag = qla24xx_chip_diag,
2403 .config_rings = qla24xx_config_rings,
2404 .reset_adapter = qla24xx_reset_adapter,
2405 .nvram_config = qla81xx_nvram_config,
2406 .update_fw_options = qla81xx_update_fw_options,
2407 .load_risc = qla81xx_load_risc,
2408 .pci_info_str = qla24xx_pci_info_str,
2409 .fw_version_str = qla24xx_fw_version_str,
2410 .intr_handler = qla24xx_intr_handler,
2411 .enable_intrs = qla24xx_enable_intrs,
2412 .disable_intrs = qla24xx_disable_intrs,
2413 .abort_command = qla24xx_abort_command,
2414 .target_reset = qla24xx_abort_target,
2415 .lun_reset = qla24xx_lun_reset,
2416 .fabric_login = qla24xx_login_fabric,
2417 .fabric_logout = qla24xx_fabric_logout,
2418 .calc_req_entries = NULL,
2419 .build_iocbs = NULL,
2420 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2421 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2422 .read_nvram = NULL,
2423 .write_nvram = NULL,
2424 .fw_dump = qla27xx_fwdump,
2425 .beacon_on = qla24xx_beacon_on,
2426 .beacon_off = qla24xx_beacon_off,
2427 .beacon_blink = qla83xx_beacon_blink,
2428 .read_optrom = qla25xx_read_optrom_data,
2429 .write_optrom = qla24xx_write_optrom_data,
2430 .get_flash_version = qla24xx_get_flash_version,
2431 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002432 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002433 .abort_isp = qla2x00_abort_isp,
2434 .iospace_config = qla83xx_iospace_config,
2435 .initialize_adapter = qla2x00_initialize_adapter,
2436};
2437
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002438static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002439qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002440{
2441 ha->device_type = DT_EXTENDED_IDS;
2442 switch (ha->pdev->device) {
2443 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002444 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002445 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002446 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002447 break;
2448 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002449 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002450 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002451 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002452 break;
2453 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002454 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002455 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002456 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002457 break;
2458 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002459 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002460 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002461 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002462 break;
2463 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002464 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002465 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002466 if (ha->pdev->subsystem_vendor == 0x1028 &&
2467 ha->pdev->subsystem_device == 0x0170)
2468 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002469 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002470 break;
2471 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002472 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002473 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002474 break;
2475 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002476 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002477 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002478 break;
2479 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002480 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002481 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002482 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002483 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002484 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002485 break;
2486 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002487 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002488 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002489 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002490 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002491 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002492 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002493 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002494 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002495 ha->device_type |= DT_ZIO_SUPPORTED;
2496 ha->device_type |= DT_FWI2;
2497 ha->device_type |= DT_IIDMA;
2498 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2499 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002500 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002501 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002502 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002503 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002504 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002505 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002506 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002507 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002508 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002509 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002510 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002511 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002512 ha->device_type |= DT_ZIO_SUPPORTED;
2513 ha->device_type |= DT_FWI2;
2514 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002515 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2516 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002517 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002518 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002519 ha->device_type |= DT_ZIO_SUPPORTED;
2520 ha->device_type |= DT_FWI2;
2521 ha->device_type |= DT_IIDMA;
2522 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2523 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002524 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002525 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002526 ha->device_type |= DT_ZIO_SUPPORTED;
2527 ha->device_type |= DT_FWI2;
2528 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2529 /* Initialize 82XX ISP flags */
2530 qla82xx_init_flags(ha);
2531 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002532 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002533 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002534 ha->device_type |= DT_ZIO_SUPPORTED;
2535 ha->device_type |= DT_FWI2;
2536 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2537 /* Initialize 82XX ISP flags */
2538 qla82xx_init_flags(ha);
2539 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002540 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002541 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002542 ha->device_type |= DT_ZIO_SUPPORTED;
2543 ha->device_type |= DT_FWI2;
2544 ha->device_type |= DT_IIDMA;
2545 ha->device_type |= DT_T10_PI;
2546 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2547 break;
2548 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002549 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002550 ha->device_type |= DT_ZIO_SUPPORTED;
2551 ha->device_type |= DT_FWI2;
2552 ha->device_type |= DT_IIDMA;
2553 ha->device_type |= DT_T10_PI;
2554 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2555 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002556 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002557 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002558 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002559 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002560 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002561 ha->device_type |= DT_ZIO_SUPPORTED;
2562 ha->device_type |= DT_FWI2;
2563 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002564 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002565 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2566 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002567 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002568 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002569 ha->device_type |= DT_ZIO_SUPPORTED;
2570 ha->device_type |= DT_FWI2;
2571 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002572 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002573 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2574 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002575 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002576 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002577 ha->device_type |= DT_ZIO_SUPPORTED;
2578 ha->device_type |= DT_FWI2;
2579 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002580 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002581 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2582 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002583 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002584
Giridhar Malavalia9083012010-04-12 17:59:55 -07002585 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002586 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002587 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002588 /* Get adapter physical port no from interrupt pin register. */
2589 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002590 if (IS_QLA27XX(ha))
2591 ha->port_no--;
2592 else
2593 ha->port_no = !(ha->port_no & 1);
2594 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002595
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002596 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002597 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002598 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002599}
2600
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002601static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002602qla2xxx_scan_start(struct Scsi_Host *shost)
2603{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002605
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002606 if (vha->hw->flags.running_gold_fw)
2607 return;
2608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2610 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2611 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2612 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002613}
2614
2615static int
2616qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2617{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002619
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002620 if (test_bit(UNLOADING, &vha->dpc_flags))
2621 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002623 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002625 return 1;
2626
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002628}
2629
Quinn Tranec7193e2017-03-15 09:48:55 -07002630static void qla2x00_iocb_work_fn(struct work_struct *work)
2631{
2632 struct scsi_qla_host *vha = container_of(work,
2633 struct scsi_qla_host, iocb_work);
2634 int cnt = 0;
2635
2636 while (!list_empty(&vha->work_list)) {
2637 qla2x00_do_work(vha);
2638 cnt++;
2639 if (cnt > 10)
2640 break;
2641 }
2642}
2643
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644/*
2645 * PCI driver interface
2646 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002647static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002648qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002650 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 scsi_qla_host_t *base_vha = NULL;
2653 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002654 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002655 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002656 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002657 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002659 struct req_que *req = NULL;
2660 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002661 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002662
Andrew Vasquez285d0322007-10-19 15:59:17 -07002663 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002664 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002665 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2666 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002667 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002668 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2669 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002670 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002671 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002672 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2673 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002674 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002675 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002676 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002677 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002678 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2679 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002680 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002681 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002682 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2683 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002684 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002685 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2686 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002687
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002688 if (mem_only) {
2689 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002690 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002691 } else {
2692 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002693 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
Jesse Barnes09276782008-10-18 17:33:19 -07002696 /* This may fail but that's ok */
2697 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2700 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002701 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2702 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002703 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002705 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2706 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002707 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002708 ha->tgt.enable_class_2 = ql2xenableclass2;
Quinn Tran33e79972014-09-25 06:14:55 -04002709 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2710 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002711 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002712 spin_lock_init(&ha->tgt.atio_lock);
2713
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002716 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002717 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002718 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002719 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002720 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002721 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002723 /* Set ISP-type information. */
2724 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002725
2726 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002727 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002728 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002729 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002730
Chad Dupuiscba1e472011-11-18 09:03:21 -08002731 ha->prev_topology = 0;
2732 ha->init_cb_size = sizeof(init_cb_t);
2733 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2734 ha->optrom_size = OPTROM_SIZE_2300;
2735
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002736 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002738 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 req_length = REQUEST_ENTRY_CNT_2100;
2741 rsp_length = RESPONSE_ENTRY_CNT_2100;
2742 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002743 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002744 ha->flash_conf_off = ~0;
2745 ha->flash_data_off = ~0;
2746 ha->nvram_conf_off = ~0;
2747 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002748 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002750 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002751 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 req_length = REQUEST_ENTRY_CNT_2200;
2753 rsp_length = RESPONSE_ENTRY_CNT_2100;
2754 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002755 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002756 ha->flash_conf_off = ~0;
2757 ha->flash_data_off = ~0;
2758 ha->nvram_conf_off = ~0;
2759 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002760 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002761 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002762 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 req_length = REQUEST_ENTRY_CNT_2200;
2765 rsp_length = RESPONSE_ENTRY_CNT_2300;
2766 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002767 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002768 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2769 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002770 ha->flash_conf_off = ~0;
2771 ha->flash_data_off = ~0;
2772 ha->nvram_conf_off = ~0;
2773 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002774 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002775 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002776 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002777 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778 req_length = REQUEST_ENTRY_CNT_24XX;
2779 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002780 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002782 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002783 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002784 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002785 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002786 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002787 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2788 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2789 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2790 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002791 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002792 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002793 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794 req_length = REQUEST_ENTRY_CNT_24XX;
2795 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002796 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002798 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002799 ha->gid_list_info_size = 8;
2800 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002801 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002802 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002803 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2804 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2805 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2806 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2807 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002808 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002809 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2810 req_length = REQUEST_ENTRY_CNT_24XX;
2811 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002812 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002813 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2814 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2815 ha->gid_list_info_size = 8;
2816 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002817 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002818 ha->isp_ops = &qla81xx_isp_ops;
2819 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2820 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2821 ha->nvram_conf_off = ~0;
2822 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002823 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002824 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002825 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2826 req_length = REQUEST_ENTRY_CNT_82XX;
2827 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2828 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2829 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2830 ha->gid_list_info_size = 8;
2831 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002832 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002833 ha->isp_ops = &qla82xx_isp_ops;
2834 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2835 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2836 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2837 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002838 } else if (IS_QLA8044(ha)) {
2839 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2840 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2841 req_length = REQUEST_ENTRY_CNT_82XX;
2842 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2843 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2844 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2845 ha->gid_list_info_size = 8;
2846 ha->optrom_size = OPTROM_SIZE_83XX;
2847 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2848 ha->isp_ops = &qla8044_isp_ops;
2849 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2850 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2851 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2852 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002853 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002854 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002855 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002856 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002857 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002858 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002859 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002860 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2861 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2862 ha->gid_list_info_size = 8;
2863 ha->optrom_size = OPTROM_SIZE_83XX;
2864 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2865 ha->isp_ops = &qla83xx_isp_ops;
2866 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2867 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2868 ha->nvram_conf_off = ~0;
2869 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002870 } else if (IS_QLAFX00(ha)) {
2871 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2872 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2873 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2874 req_length = REQUEST_ENTRY_CNT_FX00;
2875 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002876 ha->isp_ops = &qlafx00_isp_ops;
2877 ha->port_down_retry_count = 30; /* default value */
2878 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2879 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002880 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002881 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002882 ha->mr.host_info_resend = false;
2883 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002884 } else if (IS_QLA27XX(ha)) {
2885 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2886 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2887 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002888 req_length = REQUEST_ENTRY_CNT_83XX;
2889 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002890 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002891 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2892 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2893 ha->gid_list_info_size = 8;
2894 ha->optrom_size = OPTROM_SIZE_83XX;
2895 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2896 ha->isp_ops = &qla27xx_isp_ops;
2897 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2898 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2899 ha->nvram_conf_off = ~0;
2900 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002902
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002903 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2904 "mbx_count=%d, req_length=%d, "
2905 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002906 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2907 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002908 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2909 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002910 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002911 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2912 "isp_ops=%p, flash_conf_off=%d, "
2913 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2914 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2915 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002916
2917 /* Configure PCI I/O space */
2918 ret = ha->isp_ops->iospace_config(ha);
2919 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002920 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002921
2922 ql_log_pci(ql_log_info, pdev, 0x001d,
2923 "Found an ISP%04X irq %d iobase 0x%p.\n",
2924 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002925 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08002926 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002927 init_completion(&ha->mbx_cmd_comp);
2928 complete(&ha->mbx_cmd_comp);
2929 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002930 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002931 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002933 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
Andrew Vasquez53303c42009-01-22 09:45:37 -08002935 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002936 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2937 "64 Bit addressing is %s.\n",
2938 ha->flags.enable_64bit_addressing ? "enable" :
2939 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002940 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002941 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002942 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2943 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945 goto probe_hw_failed;
2946 }
2947
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002948 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002950 req->max_q_depth = ql2xmaxqdepth;
2951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002952
2953 base_vha = qla2x00_create_host(sht, ha);
2954 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002955 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002956 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002957 qla2x00_free_req_que(ha, req);
2958 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 }
2961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002963 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002966 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002967 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002969 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2971 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002972
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002973 /* Setup fcport template structure. */
2974 ha->mr.fcport.vha = base_vha;
2975 ha->mr.fcport.port_type = FCT_UNKNOWN;
2976 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2977 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2978 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2979 ha->mr.fcport.scan_state = 1;
2980
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002981 /* Set the SG table size based on ISP type */
2982 if (!IS_FWI2_CAPABLE(ha)) {
2983 if (IS_QLA2100(ha))
2984 host->sg_tablesize = 32;
2985 } else {
2986 if (!IS_QLA82XX(ha))
2987 host->sg_tablesize = QLA_SG_ALL;
2988 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002989 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002990 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002991 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002992 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002993 host->max_cmd_len = 32;
2994 else
2995 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002996 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002997 /* Older HBAs support only 16-bit LUNs */
2998 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2999 ql2xmaxlun > 0xffff)
3000 host->max_lun = 0xffff;
3001 else
3002 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003003 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003004 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003005
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003006 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3007 "max_id=%d this_id=%d "
3008 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003009 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003010 host->this_id, host->cmd_per_lun, host->unique_id,
3011 host->max_cmd_len, host->max_channel, host->max_lun,
3012 host->transportt, sht->vendor_id);
3013
Michael Hernandezd7459522016-12-12 14:40:07 -08003014 /* Set up the irqs */
3015 ret = qla2x00_request_irqs(ha, rsp);
3016 if (ret)
3017 goto probe_init_failed;
3018
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003019 /* Alloc arrays of request and response ring ptrs */
3020 if (!qla2x00_alloc_queues(ha, req, rsp)) {
3021 ql_log(ql_log_fatal, base_vha, 0x003d,
3022 "Failed to allocate memory for queue pointers..."
3023 "aborting.\n");
3024 goto probe_init_failed;
3025 }
3026
Michael Hernandez56012362016-12-12 14:40:08 -08003027 if (ha->mqenable && shost_use_blk_mq(host)) {
3028 /* number of hardware queues supported by blk/scsi-mq*/
3029 host->nr_hw_queues = ha->max_qpairs;
3030
3031 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3032 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3033 } else
3034 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3035 "blk/scsi-mq disabled.\n");
3036
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003037 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003038
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003039 pci_save_state(pdev);
3040
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003041 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003042 rsp->req = req;
3043 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003044
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003045 if (IS_QLAFX00(ha)) {
3046 ha->rsp_q_map[0] = rsp;
3047 ha->req_q_map[0] = req;
3048 set_bit(0, ha->req_qid_map);
3049 set_bit(0, ha->rsp_qid_map);
3050 }
3051
Andrew Vasquez08029992009-03-24 09:07:55 -07003052 /* FWI2-capable only. */
3053 req->req_q_in = &ha->iobase->isp24.req_q_in;
3054 req->req_q_out = &ha->iobase->isp24.req_q_out;
3055 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3056 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003057 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003058 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3059 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3060 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3061 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003062 }
3063
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003064 if (IS_QLAFX00(ha)) {
3065 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3066 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3067 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3068 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3069 }
3070
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003071 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003072 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3073 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3074 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3075 }
3076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003077 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3078 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3079 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3080 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3081 "req->req_q_in=%p req->req_q_out=%p "
3082 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3083 req->req_q_in, req->req_q_out,
3084 rsp->rsp_q_in, rsp->rsp_q_out);
3085 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3086 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3087 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3088 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3089 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3090 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003092 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003093 ql_log(ql_log_fatal, base_vha, 0x00d6,
3094 "Failed to initialize adapter - Adapter flags %x.\n",
3095 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096
Giridhar Malavalia9083012010-04-12 17:59:55 -07003097 if (IS_QLA82XX(ha)) {
3098 qla82xx_idc_lock(ha);
3099 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003100 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003101 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003102 ql_log(ql_log_fatal, base_vha, 0x00d7,
3103 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003104 } else if (IS_QLA8044(ha)) {
3105 qla8044_idc_lock(ha);
3106 qla8044_wr_direct(base_vha,
3107 QLA8044_CRB_DEV_STATE_INDEX,
3108 QLA8XXX_DEV_FAILED);
3109 qla8044_idc_unlock(ha);
3110 ql_log(ql_log_fatal, base_vha, 0x0150,
3111 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003112 }
3113
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003114 ret = -ENODEV;
3115 goto probe_failed;
3116 }
3117
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003118 if (IS_QLAFX00(ha))
3119 host->can_queue = QLAFX00_MAX_CANQUEUE;
3120 else
3121 host->can_queue = req->num_outstanding_cmds - 10;
3122
3123 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3124 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3125 host->can_queue, base_vha->req,
3126 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3127
Quinn Tran093df732016-12-12 14:40:09 -08003128 if (ha->mqenable && qla_ini_mode_enabled(base_vha)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08003129 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Michael Hernandez56012362016-12-12 14:40:08 -08003130 /* Create start of day qpairs for Block MQ */
3131 if (shost_use_blk_mq(host)) {
3132 for (i = 0; i < ha->max_qpairs; i++)
Quinn Tran82de8022017-06-13 20:47:17 -07003133 qla2xxx_create_qpair(base_vha, 5, 0, true);
Michael Hernandez56012362016-12-12 14:40:08 -08003134 }
3135 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003136
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003137 if (ha->flags.running_gold_fw)
3138 goto skip_dpc;
3139
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003140 /*
3141 * Startup the kernel thread for this host adapter
3142 */
3143 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003144 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003145 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003146 ql_log(ql_log_fatal, base_vha, 0x00ed,
3147 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148 ret = PTR_ERR(ha->dpc_thread);
3149 goto probe_failed;
3150 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003151 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3152 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003153
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003154 /*
3155 * If we're not coming up in initiator mode, we might sit for
3156 * a while without waking up the dpc thread, which leads to a
3157 * stuck process warning. So just kick the dpc once here and
3158 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3159 */
3160 qla2xxx_wake_dpc(base_vha);
3161
Quinn Tranec7193e2017-03-15 09:48:55 -07003162 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003163 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3164
Saurav Kashyap81178772012-08-22 14:21:04 -04003165 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3166 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3167 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3168 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3169
3170 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3171 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3172 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3173 INIT_WORK(&ha->idc_state_handler,
3174 qla83xx_idc_state_handler_work);
3175 INIT_WORK(&ha->nic_core_unrecoverable,
3176 qla83xx_nic_core_unrecoverable_work);
3177 }
3178
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003179skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 list_add_tail(&base_vha->list, &ha->vp_list);
3181 base_vha->host->irq = ha->pdev->irq;
3182
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003185 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3186 "Started qla2x00_timer with "
3187 "interval=%d.\n", WATCH_INTERVAL);
3188 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3189 "Detected hba at address=%p.\n",
3190 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
Arun Easie02587d2011-08-16 11:29:23 -07003192 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003193 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003194 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003195 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003196 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3197 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003198 if (ql2xenabledif == 1)
3199 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003200 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003201 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003202 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003203 | SHOST_DIF_TYPE3_PROTECTION
3204 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003205 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003206 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003207
3208 guard = SHOST_DIX_GUARD_CRC;
3209
3210 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3211 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3212 guard |= SHOST_DIX_GUARD_IP;
3213
3214 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003215 } else
3216 base_vha->flags.difdix_supported = 0;
3217 }
3218
Giridhar Malavalia9083012010-04-12 17:59:55 -07003219 ha->isp_ops->enable_intrs(ha);
3220
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003221 if (IS_QLAFX00(ha)) {
3222 ret = qlafx00_fx_disc(base_vha,
3223 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3224 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3225 QLA_SG_ALL : 128;
3226 }
3227
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003228 ret = scsi_add_host(host, &pdev->dev);
3229 if (ret)
3230 goto probe_failed;
3231
Michael Reed14864002009-12-02 09:11:16 -06003232 base_vha->flags.init_done = 1;
3233 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003234 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003235
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003236 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3237 "Init done and hba is online.\n");
3238
Quinn Tran726b8542017-01-19 22:28:00 -08003239 if (qla_ini_mode_enabled(base_vha) ||
3240 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003241 scsi_scan_host(host);
3242 else
3243 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3244 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003247
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003248 if (IS_QLAFX00(ha)) {
3249 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003250 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3251
3252 /* Register system information */
3253 ret = qlafx00_fx_disc(base_vha,
3254 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3255 }
3256
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003258
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003260
Armen Baloyan03eb9122013-10-30 03:38:22 -04003261 ql_log(ql_log_info, base_vha, 0x00fb,
3262 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003263 ql_log(ql_log_info, base_vha, 0x00fc,
3264 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3265 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3266 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3267 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003268 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003270 qlt_add_target(ha, base_vha);
3271
Joe Lawrence6b383972014-08-26 17:12:29 -04003272 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003273
3274 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3275 return -ENODEV;
3276
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 return 0;
3278
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003279probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003280 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003281 ha->req_q_map[0] = NULL;
3282 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003283 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003284 ha->rsp_q_map[0] = NULL;
3285 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003286 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003287
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003289 if (base_vha->timer_active)
3290 qla2x00_stop_timer(base_vha);
3291 base_vha->flags.online = 0;
3292 if (ha->dpc_thread) {
3293 struct task_struct *t = ha->dpc_thread;
3294
3295 ha->dpc_thread = NULL;
3296 kthread_stop(t);
3297 }
3298
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003299 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003304 qla2x00_clear_drv_active(ha);
3305
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003306iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003307 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003308 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003309 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003310 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003311 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003312 } else {
3313 if (ha->iobase)
3314 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003315 if (ha->cregbase)
3316 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003317 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003318 pci_release_selected_regions(ha->pdev, ha->bars);
3319 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003321disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003323 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325
Adrian Bunk4c993f72008-01-14 00:55:16 -08003326static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003327qla2x00_shutdown(struct pci_dev *pdev)
3328{
3329 scsi_qla_host_t *vha;
3330 struct qla_hw_data *ha;
3331
Masanari Iida552f3f92013-02-08 01:57:44 -05003332 if (!atomic_read(&pdev->enable_cnt))
3333 return;
3334
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003335 vha = pci_get_drvdata(pdev);
3336 ha = vha->hw;
3337
Armen Baloyan42479342013-08-27 01:37:37 -04003338 /* Notify ISPFX00 firmware */
3339 if (IS_QLAFX00(ha))
3340 qlafx00_driver_shutdown(vha, 20);
3341
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003342 /* Turn-off FCE trace */
3343 if (ha->flags.fce_enabled) {
3344 qla2x00_disable_fce_trace(vha, NULL, NULL);
3345 ha->flags.fce_enabled = 0;
3346 }
3347
3348 /* Turn-off EFT trace */
3349 if (ha->eft)
3350 qla2x00_disable_eft_trace(vha);
3351
3352 /* Stop currently executing firmware. */
3353 qla2x00_try_to_stop_firmware(vha);
3354
3355 /* Turn adapter off line */
3356 vha->flags.online = 0;
3357
3358 /* turn-off interrupts on the card */
3359 if (ha->interrupts_on) {
3360 vha->flags.init_done = 0;
3361 ha->isp_ops->disable_intrs(ha);
3362 }
3363
3364 qla2x00_free_irqs(vha);
3365
3366 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003367
3368 pci_disable_pcie_error_reporting(pdev);
3369 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003370}
3371
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003372/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003373static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003374qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003376 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003377 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Arun Easi43ebf162011-05-10 11:18:16 -07003379 mutex_lock(&ha->vport_lock);
3380 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003381 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003382
Arun Easi43ebf162011-05-10 11:18:16 -07003383 BUG_ON(base_vha->list.next == &ha->vp_list);
3384 /* This assumes first entry in ha->vp_list is always base vha */
3385 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003386 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003387
Arun Easi43ebf162011-05-10 11:18:16 -07003388 spin_unlock_irqrestore(&ha->vport_slock, flags);
3389 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003390
Arun Easi43ebf162011-05-10 11:18:16 -07003391 fc_vport_terminate(vha->fc_vport);
3392 scsi_host_put(vha->host);
3393
3394 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 }
Arun Easi43ebf162011-05-10 11:18:16 -07003396 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003397}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003398
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003399/* Stops all deferred work threads */
3400static void
3401qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3402{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003403 /* Cancel all work and destroy DPC workqueues */
3404 if (ha->dpc_lp_wq) {
3405 cancel_work_sync(&ha->idc_aen);
3406 destroy_workqueue(ha->dpc_lp_wq);
3407 ha->dpc_lp_wq = NULL;
3408 }
3409
3410 if (ha->dpc_hp_wq) {
3411 cancel_work_sync(&ha->nic_core_reset);
3412 cancel_work_sync(&ha->idc_state_handler);
3413 cancel_work_sync(&ha->nic_core_unrecoverable);
3414 destroy_workqueue(ha->dpc_hp_wq);
3415 ha->dpc_hp_wq = NULL;
3416 }
3417
Andrew Vasquezb9978762009-03-24 09:08:05 -07003418 /* Kill the kernel thread for this host */
3419 if (ha->dpc_thread) {
3420 struct task_struct *t = ha->dpc_thread;
3421
3422 /*
3423 * qla2xxx_wake_dpc checks for ->dpc_thread
3424 * so we need to zero it out.
3425 */
3426 ha->dpc_thread = NULL;
3427 kthread_stop(t);
3428 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003429}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003430
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003431static void
3432qla2x00_unmap_iobases(struct qla_hw_data *ha)
3433{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003434 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003435
Chad Dupuisf73cb692014-02-26 04:15:06 -05003436 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003437 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003438 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003439 } else {
3440 if (ha->iobase)
3441 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003442
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003443 if (ha->cregbase)
3444 iounmap(ha->cregbase);
3445
Giridhar Malavalia9083012010-04-12 17:59:55 -07003446 if (ha->mqiobase)
3447 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003448
Chad Dupuisf73cb692014-02-26 04:15:06 -05003449 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003450 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003451 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003452}
3453
3454static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003455qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003456{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003457 if (IS_QLA8044(ha)) {
3458 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003459 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003460 qla8044_idc_unlock(ha);
3461 } else if (IS_QLA82XX(ha)) {
3462 qla82xx_idc_lock(ha);
3463 qla82xx_clear_drv_active(ha);
3464 qla82xx_idc_unlock(ha);
3465 }
3466}
3467
3468static void
3469qla2x00_remove_one(struct pci_dev *pdev)
3470{
3471 scsi_qla_host_t *base_vha;
3472 struct qla_hw_data *ha;
3473
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003474 base_vha = pci_get_drvdata(pdev);
3475 ha = base_vha->hw;
3476
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003477 /* Indicate device removal to prevent future board_disable and wait
3478 * until any pending board_disable has completed. */
3479 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3480 cancel_work_sync(&ha->board_disable);
3481
3482 /*
3483 * If the PCI device is disabled then there was a PCI-disconnect and
3484 * qla2x00_disable_board_on_pci_error has taken care of most of the
3485 * resources.
3486 */
3487 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003488 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3489 base_vha->gnl.l, base_vha->gnl.ldma);
3490
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003491 scsi_host_put(base_vha->host);
3492 kfree(ha);
3493 pci_set_drvdata(pdev, NULL);
3494 return;
3495 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003496 qla2x00_wait_for_hba_ready(base_vha);
3497
Quinn Tran726b8542017-01-19 22:28:00 -08003498 /*
3499 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003500 * where it was set first.
3501 */
3502 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3503 return;
3504
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003505 set_bit(UNLOADING, &base_vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08003506 dma_free_coherent(&ha->pdev->dev,
3507 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003508
3509 if (IS_QLAFX00(ha))
3510 qlafx00_driver_shutdown(base_vha, 20);
3511
3512 qla2x00_delete_all_vps(ha, base_vha);
3513
3514 if (IS_QLA8031(ha)) {
3515 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3516 "Clearing fcoe driver presence.\n");
3517 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3518 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3519 "Error while clearing DRV-Presence.\n");
3520 }
3521
3522 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3523
3524 qla2x00_dfs_remove(base_vha);
3525
3526 qla84xx_put_chip(base_vha);
3527
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003528 /* Laser should be disabled only for ISP2031 */
3529 if (IS_QLA2031(ha))
3530 qla83xx_disable_laser(base_vha);
3531
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003532 /* Disable timer */
3533 if (base_vha->timer_active)
3534 qla2x00_stop_timer(base_vha);
3535
3536 base_vha->flags.online = 0;
3537
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003538 /* free DMA memory */
3539 if (ha->exlogin_buf)
3540 qla2x00_free_exlogin_buffer(ha);
3541
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003542 /* free DMA memory */
3543 if (ha->exchoffld_buf)
3544 qla2x00_free_exchoffld_buffer(ha);
3545
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003546 qla2x00_destroy_deferred_work(ha);
3547
3548 qlt_remove_target(ha, base_vha);
3549
3550 qla2x00_free_sysfs_attr(base_vha, true);
3551
3552 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003553 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003554
3555 scsi_remove_host(base_vha->host);
3556
3557 qla2x00_free_device(base_vha);
3558
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003559 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003560
Arun Easid2749ff2014-09-25 05:16:51 -04003561 scsi_host_put(base_vha->host);
3562
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003563 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003564
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003565 pci_release_selected_regions(ha->pdev, ha->bars);
3566 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003568 pci_disable_pcie_error_reporting(pdev);
3569
Bernhard Walle665db932007-03-28 00:49:49 +02003570 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572
3573static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577
Andrew Vasquez85880802009-12-15 21:29:46 -08003578 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3579
3580 /* Disable timer */
3581 if (vha->timer_active)
3582 qla2x00_stop_timer(vha);
3583
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003584 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003585
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003586 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003588
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003589 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003590 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003591
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003592 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
Andrew Vasquez85880802009-12-15 21:29:46 -08003595 vha->flags.online = 0;
3596
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003597 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003598 if (ha->interrupts_on) {
3599 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003600 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003601 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003602
Quinn Tran093df732016-12-12 14:40:09 -08003603 qla2x00_free_fcports(vha);
3604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605 qla2x00_free_irqs(vha);
3606
Quinn Tran093df732016-12-12 14:40:09 -08003607 /* Flush the work queue and remove it */
3608 if (ha->wq) {
3609 flush_workqueue(ha->wq);
3610 destroy_workqueue(ha->wq);
3611 ha->wq = NULL;
3612 }
3613
Chad Dupuis88670482010-07-23 15:28:30 +05003614
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003615 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003616
Giridhar Malavali08de2842011-08-16 11:31:44 -07003617 qla82xx_md_free(vha);
3618
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003619 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620}
3621
Chad Dupuis88670482010-07-23 15:28:30 +05003622void qla2x00_free_fcports(struct scsi_qla_host *vha)
3623{
3624 fc_port_t *fcport, *tfcport;
3625
3626 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3627 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003628 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003629 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003630 }
3631}
3632
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003633static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003634qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003635 int defer)
3636{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003637 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003638 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003639 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003640
3641 if (!fcport->rport)
3642 return;
3643
3644 rport = fcport->rport;
3645 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003646 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003647 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003648 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003649 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003650 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003651 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3652 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003653 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003654 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003655 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003656 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3657 "%s %8phN. rport %p roles %x\n",
3658 __func__, fcport->port_name, rport,
3659 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003660 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003661 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003662 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003663 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003664}
3665
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3668 *
3669 * Input: ha = adapter block pointer. fcport = port structure pointer.
3670 *
3671 * Return: None.
3672 *
3673 * Context:
3674 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003676 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003678 if (IS_QLAFX00(vha->hw)) {
3679 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3680 qla2x00_schedule_rport_del(vha, fcport, defer);
3681 return;
3682 }
3683
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003684 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003685 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003686 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003687 qla2x00_schedule_rport_del(vha, fcport, defer);
3688 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003689 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 * We may need to retry the login, so don't change the state of the
3691 * port but do the retries.
3692 */
3693 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003694 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695
3696 if (!do_login)
3697 return;
3698
Arun Easia1d02852015-08-04 13:38:02 -04003699 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3700
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003702 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703
Quinn Tran83548fe2017-06-02 09:12:01 -07003704 ql_dbg(ql_dbg_disc, vha, 0x20a3,
Quinn Tran726b8542017-01-19 22:28:00 -08003705 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003706 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 }
3708}
3709
3710/*
3711 * qla2x00_mark_all_devices_lost
3712 * Updates fcport state when device goes offline.
3713 *
3714 * Input:
3715 * ha = adapter block pointer.
3716 * fcport = port structure pointer.
3717 *
3718 * Return:
3719 * None.
3720 *
3721 * Context:
3722 */
3723void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003724qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725{
3726 fc_port_t *fcport;
3727
Quinn Tran83548fe2017-06-02 09:12:01 -07003728 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3729 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003730
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003731 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003732 fcport->scan_state = 0;
3733 qlt_schedule_sess_for_deletion_lock(fcport);
3734
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003735 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003737
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 /*
3739 * No point in marking the device as lost, if the device is
3740 * already DEAD.
3741 */
3742 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3743 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003744 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003745 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003746 if (defer)
3747 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003748 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003749 qla2x00_schedule_rport_del(vha, fcport, defer);
3750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 }
3752}
3753
3754/*
3755* qla2x00_mem_alloc
3756* Allocates adapter memory.
3757*
3758* Returns:
3759* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003760* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003762static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003763qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3764 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765{
3766 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
Andrew Vasqueze8711082008-01-31 12:33:48 -08003768 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003769 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003770 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003771 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003773 if (qlt_mem_alloc(ha) < 0)
3774 goto fail_free_init_cb;
3775
Chad Dupuis642ef982012-02-09 11:15:57 -08003776 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3777 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003778 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003779 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780
Andrew Vasqueze8711082008-01-31 12:33:48 -08003781 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3782 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003785 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003786 /* Allocate cache for CT6 Ctx. */
3787 if (!ctx_cachep) {
3788 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3789 sizeof(struct ct6_dsd), 0,
3790 SLAB_HWCACHE_ALIGN, NULL);
3791 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003792 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003793 }
3794 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3795 ctx_cachep);
3796 if (!ha->ctx_mempool)
3797 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003798 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3799 "ctx_cachep=%p ctx_mempool=%p.\n",
3800 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003801 }
3802
Andrew Vasqueze8711082008-01-31 12:33:48 -08003803 /* Get memory for cached NVRAM */
3804 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3805 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003806 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3809 ha->pdev->device);
3810 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3811 DMA_POOL_SIZE, 8, 0);
3812 if (!ha->s_dma_pool)
3813 goto fail_free_nvram;
3814
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003815 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3816 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3817 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3818
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003819 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003820 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3821 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3822 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003823 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3824 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003825 goto fail_s_dma_pool;
3826 }
3827
3828 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3829 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3830 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003831 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3832 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003833 goto fail_dl_dma_pool;
3834 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003835 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3836 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3837 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003838 }
3839
Andrew Vasqueze8711082008-01-31 12:33:48 -08003840 /* Allocate memory for SNS commands */
3841 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003842 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003843 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003844 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003845 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003846 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003847 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003848 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003849 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003850 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003851 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003852 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003853 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003854 goto fail_dma_pool;
3855 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003856 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003857 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003858 if (!ha->ct_sns)
3859 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003860 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3861 "ms_iocb=%p ct_sns=%p.\n",
3862 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 }
3864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003866 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3867 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003868 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3869 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870 goto fail_req;
3871 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003872 (*req)->length = req_len;
3873 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3874 ((*req)->length + 1) * sizeof(request_t),
3875 &(*req)->dma, GFP_KERNEL);
3876 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003877 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3878 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003879 goto fail_req_ring;
3880 }
3881 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003882 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3883 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003884 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3885 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886 goto fail_rsp;
3887 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003888 (*rsp)->hw = ha;
3889 (*rsp)->length = rsp_len;
3890 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3891 ((*rsp)->length + 1) * sizeof(response_t),
3892 &(*rsp)->dma, GFP_KERNEL);
3893 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003894 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3895 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003896 goto fail_rsp_ring;
3897 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003898 (*req)->rsp = *rsp;
3899 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003900 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3901 "req=%p req->length=%d req->ring=%p rsp=%p "
3902 "rsp->length=%d rsp->ring=%p.\n",
3903 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3904 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003905 /* Allocate memory for NVRAM data for vports */
3906 if (ha->nvram_npiv_size) {
3907 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003908 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003909 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003910 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3911 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003912 goto fail_npiv_info;
3913 }
3914 } else
3915 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003916
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003917 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003918 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003919 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3920 &ha->ex_init_cb_dma);
3921 if (!ha->ex_init_cb)
3922 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003923 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3924 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003925 }
3926
Giridhar Malavalia9083012010-04-12 17:59:55 -07003927 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3928
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003929 /* Get consistent memory allocated for Async Port-Database. */
3930 if (!IS_FWI2_CAPABLE(ha)) {
3931 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3932 &ha->async_pd_dma);
3933 if (!ha->async_pd)
3934 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003935 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3936 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003937 }
3938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003939 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003940
3941 /* Allocate memory for our loop_id bitmap */
3942 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3943 GFP_KERNEL);
3944 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003945 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003946 else {
3947 qla2x00_set_reserved_loop_ids(ha);
3948 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003949 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003950 }
3951
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003952 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003953
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003954fail_loop_id_map:
3955 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003956fail_async_pd:
3957 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003958fail_ex_init_cb:
3959 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003960fail_npiv_info:
3961 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3962 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3963 (*rsp)->ring = NULL;
3964 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003965fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003966 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003967fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003968 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3969 sizeof(request_t), (*req)->ring, (*req)->dma);
3970 (*req)->ring = NULL;
3971 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003972fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003973 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003974fail_req:
3975 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3976 ha->ct_sns, ha->ct_sns_dma);
3977 ha->ct_sns = NULL;
3978 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003979fail_free_ms_iocb:
3980 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3981 ha->ms_iocb = NULL;
3982 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003983
3984 if (ha->sns_cmd)
3985 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3986 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003987fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003988 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003989 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3990 ha->fcp_cmnd_dma_pool = NULL;
3991 }
3992fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003993 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003994 dma_pool_destroy(ha->dl_dma_pool);
3995 ha->dl_dma_pool = NULL;
3996 }
3997fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003998 dma_pool_destroy(ha->s_dma_pool);
3999 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004000fail_free_nvram:
4001 kfree(ha->nvram);
4002 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004003fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004004 if (ha->ctx_mempool)
4005 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004006 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004007fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004008 if (ha->srb_mempool)
4009 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004010 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004011fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004012 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4013 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004014 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004015 ha->gid_list = NULL;
4016 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004017fail_free_tgt_mem:
4018 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004019fail_free_init_cb:
4020 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4021 ha->init_cb_dma);
4022 ha->init_cb = NULL;
4023 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004024fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004025 ql_log(ql_log_fatal, NULL, 0x0030,
4026 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004027 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028}
4029
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004030int
4031qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4032{
4033 int rval;
4034 uint16_t size, max_cnt, temp;
4035 struct qla_hw_data *ha = vha->hw;
4036
4037 /* Return if we don't need to alloacate any extended logins */
4038 if (!ql2xexlogins)
4039 return QLA_SUCCESS;
4040
Quinn Tran99e1b682017-06-02 09:12:03 -07004041 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4042 return QLA_SUCCESS;
4043
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004044 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4045 max_cnt = 0;
4046 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4047 if (rval != QLA_SUCCESS) {
4048 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4049 "Failed to get exlogin status.\n");
4050 return rval;
4051 }
4052
4053 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004054 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004055
Quinn Tran99e1b682017-06-02 09:12:03 -07004056 if (temp != ha->exlogin_size) {
4057 qla2x00_free_exlogin_buffer(ha);
4058 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004059
Quinn Tran99e1b682017-06-02 09:12:03 -07004060 ql_log(ql_log_info, vha, 0xd024,
4061 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4062 max_cnt, size, temp);
4063
4064 ql_log(ql_log_info, vha, 0xd025,
4065 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4066
4067 /* Get consistent memory for extended logins */
4068 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4069 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4070 if (!ha->exlogin_buf) {
4071 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004072 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004073 return -ENOMEM;
4074 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004075 }
4076
4077 /* Now configure the dma buffer */
4078 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4079 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004080 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004081 "Setup extended login buffer ****FAILED****.\n");
4082 qla2x00_free_exlogin_buffer(ha);
4083 }
4084
4085 return rval;
4086}
4087
4088/*
4089* qla2x00_free_exlogin_buffer
4090*
4091* Input:
4092* ha = adapter block pointer
4093*/
4094void
4095qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4096{
4097 if (ha->exlogin_buf) {
4098 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4099 ha->exlogin_buf, ha->exlogin_buf_dma);
4100 ha->exlogin_buf = NULL;
4101 ha->exlogin_size = 0;
4102 }
4103}
4104
Quinn Tran99e1b682017-06-02 09:12:03 -07004105static void
4106qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4107{
4108 u32 temp;
4109 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4110
4111 if (qla_ini_mode_enabled(vha)) {
4112 if (ql2xiniexchg > max_cnt)
4113 ql2xiniexchg = max_cnt;
4114
4115 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4116 *ret_cnt = ql2xiniexchg;
4117 } else if (qla_tgt_mode_enabled(vha)) {
4118 if (ql2xexchoffld > max_cnt)
4119 ql2xexchoffld = max_cnt;
4120
4121 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4122 *ret_cnt = ql2xexchoffld;
4123 } else if (qla_dual_mode_enabled(vha)) {
4124 temp = ql2xiniexchg + ql2xexchoffld;
4125 if (temp > max_cnt) {
4126 ql2xiniexchg -= (temp - max_cnt)/2;
4127 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4128 temp = max_cnt;
4129 }
4130
4131 if (temp > FW_DEF_EXCHANGES_CNT)
4132 *ret_cnt = temp;
4133 }
4134}
4135
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004136int
4137qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4138{
4139 int rval;
Quinn Tran99e1b682017-06-02 09:12:03 -07004140 u16 size, max_cnt;
4141 u32 temp;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004142 struct qla_hw_data *ha = vha->hw;
4143
Quinn Tran99e1b682017-06-02 09:12:03 -07004144 if (!ha->flags.exchoffld_enabled)
4145 return QLA_SUCCESS;
4146
4147 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004148 return QLA_SUCCESS;
4149
4150 ql_log(ql_log_info, vha, 0xd014,
4151 "Exchange offload count: %d.\n", ql2xexlogins);
4152
4153 max_cnt = 0;
4154 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4155 if (rval != QLA_SUCCESS) {
4156 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4157 "Failed to get exlogin status.\n");
4158 return rval;
4159 }
4160
Quinn Tran99e1b682017-06-02 09:12:03 -07004161 qla2x00_number_of_exch(vha, &temp, max_cnt);
4162 temp *= size;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004163
Quinn Tran99e1b682017-06-02 09:12:03 -07004164 if (temp != ha->exchoffld_size) {
4165 qla2x00_free_exchoffld_buffer(ha);
4166 ha->exchoffld_size = temp;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004167
Quinn Tran99e1b682017-06-02 09:12:03 -07004168 ql_log(ql_log_info, vha, 0xd016,
4169 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
4170 max_cnt, size, temp);
4171
4172 ql_log(ql_log_info, vha, 0xd017,
4173 "Exchange Buffers requested size = 0x%x\n",
4174 ha->exchoffld_size);
4175
4176 /* Get consistent memory for extended logins */
4177 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4178 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4179 if (!ha->exchoffld_buf) {
4180 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4181 "Failed to allocate memory for exchoffld_buf_dma.\n");
4182 return -ENOMEM;
4183 }
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004184 }
4185
4186 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004187 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004188 if (rval) {
4189 ql_log(ql_log_fatal, vha, 0xd02e,
4190 "Setup exchange offload buffer ****FAILED****.\n");
4191 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004192 } else {
4193 /* re-adjust number of target exchange */
4194 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4195
4196 if (qla_ini_mode_enabled(vha))
4197 icb->exchange_count = 0;
4198 else
4199 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004200 }
4201
4202 return rval;
4203}
4204
4205/*
4206* qla2x00_free_exchoffld_buffer
4207*
4208* Input:
4209* ha = adapter block pointer
4210*/
4211void
4212qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4213{
4214 if (ha->exchoffld_buf) {
4215 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4216 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4217 ha->exchoffld_buf = NULL;
4218 ha->exchoffld_size = 0;
4219 }
4220}
4221
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004223* qla2x00_free_fw_dump
4224* Frees fw dump stuff.
4225*
4226* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004227* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004228*/
4229static void
4230qla2x00_free_fw_dump(struct qla_hw_data *ha)
4231{
4232 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004233 dma_free_coherent(&ha->pdev->dev,
4234 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004235
Chad Dupuisf73cb692014-02-26 04:15:06 -05004236 if (ha->eft)
4237 dma_free_coherent(&ha->pdev->dev,
4238 EFT_SIZE, ha->eft, ha->eft_dma);
4239
4240 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004241 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004242 if (ha->fw_dump_template)
4243 vfree(ha->fw_dump_template);
4244
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004245 ha->fce = NULL;
4246 ha->fce_dma = 0;
4247 ha->eft = NULL;
4248 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004249 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004250 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004251 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004252 ha->fw_dump = NULL;
4253 ha->fw_dump_len = 0;
4254 ha->fw_dump_template = NULL;
4255 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004256}
4257
4258/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259* qla2x00_mem_free
4260* Frees all adapter allocated memory.
4261*
4262* Input:
4263* ha = adapter block pointer.
4264*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004265static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004268 qla2x00_free_fw_dump(ha);
4269
Saurav Kashyap81178772012-08-22 14:21:04 -04004270 if (ha->mctp_dump)
4271 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4272 ha->mctp_dump_dma);
4273
Andrew Vasqueze8711082008-01-31 12:33:48 -08004274 if (ha->srb_mempool)
4275 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004277 if (ha->dcbx_tlv)
4278 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4279 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4280
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004281 if (ha->xgmac_data)
4282 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4283 ha->xgmac_data, ha->xgmac_data_dma);
4284
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 if (ha->sns_cmd)
4286 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004287 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288
4289 if (ha->ct_sns)
4290 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004291 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292
Andrew Vasquez88729e52006-06-23 16:10:50 -07004293 if (ha->sfp_data)
4294 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
4295
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 if (ha->ms_iocb)
4297 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4298
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004299 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004300 dma_pool_free(ha->s_dma_pool,
4301 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004302
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004303 if (ha->async_pd)
4304 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4305
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 if (ha->s_dma_pool)
4307 dma_pool_destroy(ha->s_dma_pool);
4308
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004310 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4311 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312
Giridhar Malavalia9083012010-04-12 17:59:55 -07004313 if (IS_QLA82XX(ha)) {
4314 if (!list_empty(&ha->gbl_dsd_list)) {
4315 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4316
4317 /* clean up allocated prev pool */
4318 list_for_each_entry_safe(dsd_ptr,
4319 tdsd_ptr, &ha->gbl_dsd_list, list) {
4320 dma_pool_free(ha->dl_dma_pool,
4321 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4322 list_del(&dsd_ptr->list);
4323 kfree(dsd_ptr);
4324 }
4325 }
4326 }
4327
4328 if (ha->dl_dma_pool)
4329 dma_pool_destroy(ha->dl_dma_pool);
4330
4331 if (ha->fcp_cmnd_dma_pool)
4332 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4333
4334 if (ha->ctx_mempool)
4335 mempool_destroy(ha->ctx_mempool);
4336
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004337 qlt_mem_free(ha);
4338
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004339 if (ha->init_cb)
4340 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004341 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004342 vfree(ha->optrom_buffer);
4343 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004344 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08004345 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004346 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347
Andrew Vasqueze8711082008-01-31 12:33:48 -08004348 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004349 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 ha->sns_cmd = NULL;
4351 ha->sns_cmd_dma = 0;
4352 ha->ct_sns = NULL;
4353 ha->ct_sns_dma = 0;
4354 ha->ms_iocb = NULL;
4355 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 ha->init_cb = NULL;
4357 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004358 ha->ex_init_cb = NULL;
4359 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004360 ha->async_pd = NULL;
4361 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362
4363 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004364 ha->dl_dma_pool = NULL;
4365 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 ha->gid_list = NULL;
4368 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004369
4370 ha->tgt.atio_ring = NULL;
4371 ha->tgt.atio_dma = 0;
4372 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004373}
4374
4375struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4376 struct qla_hw_data *ha)
4377{
4378 struct Scsi_Host *host;
4379 struct scsi_qla_host *vha = NULL;
4380
4381 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004382 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004383 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4384 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004385 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004386 }
4387
4388 /* Clear our data area */
4389 vha = shost_priv(host);
4390 memset(vha, 0, sizeof(scsi_qla_host_t));
4391
4392 vha->host = host;
4393 vha->host_no = host->host_no;
4394 vha->hw = ha;
4395
4396 INIT_LIST_HEAD(&vha->vp_fcports);
4397 INIT_LIST_HEAD(&vha->work_list);
4398 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004399 INIT_LIST_HEAD(&vha->qla_cmd_list);
4400 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004401 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004402 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004403 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004404 INIT_LIST_HEAD(&vha->gnl.fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004405
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004406 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004407 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004408 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004409 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004410
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004411 vha->gnl.size = sizeof(struct get_name_list_extended) *
4412 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004413 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4414 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4415 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004416 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004417 "Alloc failed for name list.\n");
4418 scsi_remove_host(vha->host);
4419 return NULL;
4420 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004421
4422 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004423 ql_dbg(ql_dbg_init, vha, 0x0041,
4424 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4425 vha->host, vha->hw, vha,
4426 dev_name(&(ha->pdev->dev)));
4427
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004428 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429}
4430
Quinn Tran726b8542017-01-19 22:28:00 -08004431struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004432qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004433{
4434 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004435 uint8_t bail;
4436
4437 QLA_VHA_MARK_BUSY(vha, bail);
4438 if (bail)
4439 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004440
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004441 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004442 if (!e) {
4443 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004444 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004445 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004446
4447 INIT_LIST_HEAD(&e->list);
4448 e->type = type;
4449 e->flags = QLA_EVT_FLAG_FREE;
4450 return e;
4451}
4452
Quinn Tran726b8542017-01-19 22:28:00 -08004453int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004454qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004455{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004456 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004457
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004458 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004459 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004460 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004461
4462 if (QLA_EARLY_LINKUP(vha->hw))
4463 schedule_work(&vha->iocb_work);
4464 else
4465 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004466
Andrew Vasquez0971de72008-04-03 13:13:18 -07004467 return QLA_SUCCESS;
4468}
4469
4470int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004471qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004472 u32 data)
4473{
4474 struct qla_work_evt *e;
4475
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004476 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004477 if (!e)
4478 return QLA_FUNCTION_FAILED;
4479
4480 e->u.aen.code = code;
4481 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004482 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004483}
4484
Andrew Vasquez8a659572009-02-08 20:50:12 -08004485int
4486qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4487{
4488 struct qla_work_evt *e;
4489
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004490 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004491 if (!e)
4492 return QLA_FUNCTION_FAILED;
4493
4494 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004495 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004496}
4497
Andrew Vasquezac280b62009-08-20 11:06:05 -07004498#define qla2x00_post_async_work(name, type) \
4499int qla2x00_post_async_##name##_work( \
4500 struct scsi_qla_host *vha, \
4501 fc_port_t *fcport, uint16_t *data) \
4502{ \
4503 struct qla_work_evt *e; \
4504 \
4505 e = qla2x00_alloc_work(vha, type); \
4506 if (!e) \
4507 return QLA_FUNCTION_FAILED; \
4508 \
4509 e->u.logio.fcport = fcport; \
4510 if (data) { \
4511 e->u.logio.data[0] = data[0]; \
4512 e->u.logio.data[1] = data[1]; \
4513 } \
4514 return qla2x00_post_work(vha, e); \
4515}
4516
4517qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004518qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4519qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004520qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4521qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004522
Andrew Vasquez3420d362009-10-13 15:16:45 -07004523int
4524qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4525{
4526 struct qla_work_evt *e;
4527
4528 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4529 if (!e)
4530 return QLA_FUNCTION_FAILED;
4531
4532 e->u.uevent.code = code;
4533 return qla2x00_post_work(vha, e);
4534}
4535
4536static void
4537qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4538{
4539 char event_string[40];
4540 char *envp[] = { event_string, NULL };
4541
4542 switch (code) {
4543 case QLA_UEVENT_CODE_FW_DUMP:
4544 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4545 vha->host_no);
4546 break;
4547 default:
4548 /* do nothing */
4549 break;
4550 }
4551 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4552}
4553
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004554int
4555qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4556 uint32_t *data, int cnt)
4557{
4558 struct qla_work_evt *e;
4559
4560 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4561 if (!e)
4562 return QLA_FUNCTION_FAILED;
4563
4564 e->u.aenfx.evtcode = evtcode;
4565 e->u.aenfx.count = cnt;
4566 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4567 return qla2x00_post_work(vha, e);
4568}
4569
Quinn Tran726b8542017-01-19 22:28:00 -08004570int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4571{
4572 struct qla_work_evt *e;
4573
4574 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4575 if (!e)
4576 return QLA_FUNCTION_FAILED;
4577
4578 e->u.fcport.fcport = fcport;
4579 return qla2x00_post_work(vha, e);
4580}
4581
4582static
4583void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4584{
4585 unsigned long flags;
4586 fc_port_t *fcport = NULL;
4587 struct qlt_plogi_ack_t *pla =
4588 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
4589
4590 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4591 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4592 if (fcport) {
4593 fcport->d_id = e->u.new_sess.id;
4594 if (pla) {
4595 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4596 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4597 /* we took an extra ref_count to prevent PLOGI ACK when
4598 * fcport/sess has not been created.
4599 */
4600 pla->ref_count--;
4601 }
4602 } else {
4603 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4604 if (fcport) {
4605 fcport->d_id = e->u.new_sess.id;
4606 fcport->scan_state = QLA_FCPORT_FOUND;
4607 fcport->flags |= FCF_FABRIC_DEVICE;
4608 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4609
4610 memcpy(fcport->port_name, e->u.new_sess.port_name,
4611 WWN_SIZE);
4612 list_add_tail(&fcport->list, &vha->vp_fcports);
4613
4614 if (pla) {
4615 qlt_plogi_ack_link(vha, pla, fcport,
4616 QLT_PLOGI_LINK_SAME_WWN);
4617 pla->ref_count--;
4618 }
4619 }
4620 }
4621 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4622
4623 if (fcport) {
4624 if (pla)
4625 qlt_plogi_ack_unref(vha, pla);
4626 else
4627 qla24xx_async_gnl(vha, fcport);
4628 }
4629}
4630
Andrew Vasquezac280b62009-08-20 11:06:05 -07004631void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004632qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004633{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004634 struct qla_work_evt *e, *tmp;
4635 unsigned long flags;
4636 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004637
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004638 spin_lock_irqsave(&vha->work_lock, flags);
4639 list_splice_init(&vha->work_list, &work);
4640 spin_unlock_irqrestore(&vha->work_lock, flags);
4641
4642 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004643 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004644
4645 switch (e->type) {
4646 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004647 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004648 e->u.aen.code, e->u.aen.data);
4649 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004650 case QLA_EVT_IDC_ACK:
4651 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4652 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004653 case QLA_EVT_ASYNC_LOGIN:
4654 qla2x00_async_login(vha, e->u.logio.fcport,
4655 e->u.logio.data);
4656 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004657 case QLA_EVT_ASYNC_LOGOUT:
4658 qla2x00_async_logout(vha, e->u.logio.fcport);
4659 break;
4660 case QLA_EVT_ASYNC_LOGOUT_DONE:
4661 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4662 e->u.logio.data);
4663 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004664 case QLA_EVT_ASYNC_ADISC:
4665 qla2x00_async_adisc(vha, e->u.logio.fcport,
4666 e->u.logio.data);
4667 break;
4668 case QLA_EVT_ASYNC_ADISC_DONE:
4669 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4670 e->u.logio.data);
4671 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004672 case QLA_EVT_UEVENT:
4673 qla2x00_uevent_emit(vha, e->u.uevent.code);
4674 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004675 case QLA_EVT_AENFX:
4676 qlafx00_process_aen(vha, e);
4677 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004678 case QLA_EVT_GIDPN:
4679 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
4680 break;
4681 case QLA_EVT_GPNID:
4682 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
4683 break;
4684 case QLA_EVT_GPNID_DONE:
4685 qla24xx_async_gpnid_done(vha, e->u.iosb.sp);
4686 break;
4687 case QLA_EVT_NEW_SESS:
4688 qla24xx_create_new_sess(vha, e);
4689 break;
4690 case QLA_EVT_GPDB:
4691 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
4692 e->u.fcport.opt);
4693 break;
4694 case QLA_EVT_GPSC:
4695 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
4696 break;
4697 case QLA_EVT_UPD_FCPORT:
4698 qla2x00_update_fcport(vha, e->u.fcport.fcport);
4699 break;
4700 case QLA_EVT_GNL:
4701 qla24xx_async_gnl(vha, e->u.fcport.fcport);
4702 break;
4703 case QLA_EVT_NACK:
4704 qla24xx_do_nack_work(vha, e);
4705 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004706 }
4707 if (e->flags & QLA_EVT_FLAG_FREE)
4708 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004709
4710 /* For each work completed decrement vha ref count */
4711 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004712 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004713}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004714
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004715/* Relogins all the fcports of a vport
4716 * Context: dpc thread
4717 */
4718void qla2x00_relogin(struct scsi_qla_host *vha)
4719{
4720 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004721 int status;
Quinn Tran726b8542017-01-19 22:28:00 -08004722 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004723
4724 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4725 /*
4726 * If the port is not ONLINE then try to login
4727 * to it if we haven't run out of retries.
4728 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004729 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4730 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004731 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004732 if (fcport->flags & FCF_FABRIC_DEVICE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004733 ql_dbg(ql_dbg_disc, fcport->vha, 0x2108,
Quinn Tran726b8542017-01-19 22:28:00 -08004734 "%s %8phC DS %d LS %d\n", __func__,
4735 fcport->port_name, fcport->disc_state,
4736 fcport->fw_login_state);
4737 memset(&ea, 0, sizeof(ea));
4738 ea.event = FCME_RELOGIN;
4739 ea.fcport = fcport;
4740 qla2x00_fcport_event_handler(vha, &ea);
4741 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004742 status = qla2x00_local_device_login(vha,
4743 fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004744 if (status == QLA_SUCCESS) {
4745 fcport->old_loop_id = fcport->loop_id;
4746 ql_dbg(ql_dbg_disc, vha, 0x2003,
4747 "Port login OK: logged in ID 0x%x.\n",
4748 fcport->loop_id);
4749 qla2x00_update_fcport(vha, fcport);
4750 } else if (status == 1) {
4751 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4752 /* retry the login again */
4753 ql_dbg(ql_dbg_disc, vha, 0x2007,
4754 "Retrying %d login again loop_id 0x%x.\n",
4755 fcport->login_retry,
4756 fcport->loop_id);
4757 } else {
4758 fcport->login_retry = 0;
4759 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004760
Quinn Tran726b8542017-01-19 22:28:00 -08004761 if (fcport->login_retry == 0 &&
4762 status != QLA_SUCCESS)
4763 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004764 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004765 }
4766 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4767 break;
4768 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004769}
4770
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004771/* Schedule work on any of the dpc-workqueues */
4772void
4773qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4774{
4775 struct qla_hw_data *ha = base_vha->hw;
4776
4777 switch (work_code) {
4778 case MBA_IDC_AEN: /* 0x8200 */
4779 if (ha->dpc_lp_wq)
4780 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4781 break;
4782
4783 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4784 if (!ha->flags.nic_core_reset_hdlr_active) {
4785 if (ha->dpc_hp_wq)
4786 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4787 } else
4788 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4789 "NIC Core reset is already active. Skip "
4790 "scheduling it again.\n");
4791 break;
4792 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4793 if (ha->dpc_hp_wq)
4794 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4795 break;
4796 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4797 if (ha->dpc_hp_wq)
4798 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4799 break;
4800 default:
4801 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004802 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004803 }
4804
4805 return;
4806}
4807
4808/* Work: Perform NIC Core Unrecoverable state handling */
4809void
4810qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4811{
4812 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004813 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004814 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4815 uint32_t dev_state = 0;
4816
4817 qla83xx_idc_lock(base_vha, 0);
4818 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4819 qla83xx_reset_ownership(base_vha);
4820 if (ha->flags.nic_core_reset_owner) {
4821 ha->flags.nic_core_reset_owner = 0;
4822 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4823 QLA8XXX_DEV_FAILED);
4824 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4825 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4826 }
4827 qla83xx_idc_unlock(base_vha, 0);
4828}
4829
4830/* Work: Execute IDC state handler */
4831void
4832qla83xx_idc_state_handler_work(struct work_struct *work)
4833{
4834 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004835 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004836 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4837 uint32_t dev_state = 0;
4838
4839 qla83xx_idc_lock(base_vha, 0);
4840 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4841 if (dev_state == QLA8XXX_DEV_FAILED ||
4842 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4843 qla83xx_idc_state_handler(base_vha);
4844 qla83xx_idc_unlock(base_vha, 0);
4845}
4846
Saurav Kashyapfa492632012-11-21 02:40:29 -05004847static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004848qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4849{
4850 int rval = QLA_SUCCESS;
4851 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4852 uint32_t heart_beat_counter1, heart_beat_counter2;
4853
4854 do {
4855 if (time_after(jiffies, heart_beat_wait)) {
4856 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4857 "Nic Core f/w is not alive.\n");
4858 rval = QLA_FUNCTION_FAILED;
4859 break;
4860 }
4861
4862 qla83xx_idc_lock(base_vha, 0);
4863 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4864 &heart_beat_counter1);
4865 qla83xx_idc_unlock(base_vha, 0);
4866 msleep(100);
4867 qla83xx_idc_lock(base_vha, 0);
4868 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4869 &heart_beat_counter2);
4870 qla83xx_idc_unlock(base_vha, 0);
4871 } while (heart_beat_counter1 == heart_beat_counter2);
4872
4873 return rval;
4874}
4875
4876/* Work: Perform NIC Core Reset handling */
4877void
4878qla83xx_nic_core_reset_work(struct work_struct *work)
4879{
4880 struct qla_hw_data *ha =
4881 container_of(work, struct qla_hw_data, nic_core_reset);
4882 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4883 uint32_t dev_state = 0;
4884
Saurav Kashyap81178772012-08-22 14:21:04 -04004885 if (IS_QLA2031(ha)) {
4886 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4887 ql_log(ql_log_warn, base_vha, 0xb081,
4888 "Failed to dump mctp\n");
4889 return;
4890 }
4891
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004892 if (!ha->flags.nic_core_reset_hdlr_active) {
4893 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4894 qla83xx_idc_lock(base_vha, 0);
4895 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4896 &dev_state);
4897 qla83xx_idc_unlock(base_vha, 0);
4898 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4899 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4900 "Nic Core f/w is alive.\n");
4901 return;
4902 }
4903 }
4904
4905 ha->flags.nic_core_reset_hdlr_active = 1;
4906 if (qla83xx_nic_core_reset(base_vha)) {
4907 /* NIC Core reset failed. */
4908 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4909 "NIC Core reset failed.\n");
4910 }
4911 ha->flags.nic_core_reset_hdlr_active = 0;
4912 }
4913}
4914
4915/* Work: Handle 8200 IDC aens */
4916void
4917qla83xx_service_idc_aen(struct work_struct *work)
4918{
4919 struct qla_hw_data *ha =
4920 container_of(work, struct qla_hw_data, idc_aen);
4921 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4922 uint32_t dev_state, idc_control;
4923
4924 qla83xx_idc_lock(base_vha, 0);
4925 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4926 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4927 qla83xx_idc_unlock(base_vha, 0);
4928 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4929 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4930 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4931 "Application requested NIC Core Reset.\n");
4932 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4933 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4934 QLA_SUCCESS) {
4935 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4936 "Other protocol driver requested NIC Core Reset.\n");
4937 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4938 }
4939 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4940 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4941 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4942 }
4943}
4944
4945static void
4946qla83xx_wait_logic(void)
4947{
4948 int i;
4949
4950 /* Yield CPU */
4951 if (!in_interrupt()) {
4952 /*
4953 * Wait about 200ms before retrying again.
4954 * This controls the number of retries for single
4955 * lock operation.
4956 */
4957 msleep(100);
4958 schedule();
4959 } else {
4960 for (i = 0; i < 20; i++)
4961 cpu_relax(); /* This a nop instr on i386 */
4962 }
4963}
4964
Saurav Kashyapfa492632012-11-21 02:40:29 -05004965static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004966qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4967{
4968 int rval;
4969 uint32_t data;
4970 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4971 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4972 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004973 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4974 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004975
4976 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4977 if (rval)
4978 return rval;
4979
4980 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4981 return QLA_SUCCESS;
4982 } else {
4983 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4984 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4985 data);
4986 if (rval)
4987 return rval;
4988
4989 msleep(200);
4990
4991 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4992 &data);
4993 if (rval)
4994 return rval;
4995
4996 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4997 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4998 ~(idc_lck_rcvry_stage_mask));
4999 rval = qla83xx_wr_reg(base_vha,
5000 QLA83XX_IDC_LOCK_RECOVERY, data);
5001 if (rval)
5002 return rval;
5003
5004 /* Forcefully perform IDC UnLock */
5005 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5006 &data);
5007 if (rval)
5008 return rval;
5009 /* Clear lock-id by setting 0xff */
5010 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5011 0xff);
5012 if (rval)
5013 return rval;
5014 /* Clear lock-recovery by setting 0x0 */
5015 rval = qla83xx_wr_reg(base_vha,
5016 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5017 if (rval)
5018 return rval;
5019 } else
5020 return QLA_SUCCESS;
5021 }
5022
5023 return rval;
5024}
5025
Saurav Kashyapfa492632012-11-21 02:40:29 -05005026static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005027qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5028{
5029 int rval = QLA_SUCCESS;
5030 uint32_t o_drv_lockid, n_drv_lockid;
5031 unsigned long lock_recovery_timeout;
5032
5033 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5034retry_lockid:
5035 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5036 if (rval)
5037 goto exit;
5038
5039 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5040 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5041 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5042 return QLA_SUCCESS;
5043 else
5044 return QLA_FUNCTION_FAILED;
5045 }
5046
5047 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5048 if (rval)
5049 goto exit;
5050
5051 if (o_drv_lockid == n_drv_lockid) {
5052 qla83xx_wait_logic();
5053 goto retry_lockid;
5054 } else
5055 return QLA_SUCCESS;
5056
5057exit:
5058 return rval;
5059}
5060
5061void
5062qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5063{
5064 uint16_t options = (requester_id << 15) | BIT_6;
5065 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005066 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005067 struct qla_hw_data *ha = base_vha->hw;
5068
5069 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5070retry_lock:
5071 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5072 == QLA_SUCCESS) {
5073 if (data) {
5074 /* Setting lock-id to our function-number */
5075 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5076 ha->portnum);
5077 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005078 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5079 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005080 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005081 "Failed to acquire IDC lock, acquired by %d, "
5082 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005083
5084 /* Retry/Perform IDC-Lock recovery */
5085 if (qla83xx_idc_lock_recovery(base_vha)
5086 == QLA_SUCCESS) {
5087 qla83xx_wait_logic();
5088 goto retry_lock;
5089 } else
5090 ql_log(ql_log_warn, base_vha, 0xb075,
5091 "IDC Lock recovery FAILED.\n");
5092 }
5093
5094 }
5095
5096 return;
5097
5098 /* XXX: IDC-lock implementation using access-control mbx */
5099retry_lock2:
5100 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5101 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5102 "Failed to acquire IDC lock. retrying...\n");
5103 /* Retry/Perform IDC-Lock recovery */
5104 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5105 qla83xx_wait_logic();
5106 goto retry_lock2;
5107 } else
5108 ql_log(ql_log_warn, base_vha, 0xb076,
5109 "IDC Lock recovery FAILED.\n");
5110 }
5111
5112 return;
5113}
5114
5115void
5116qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5117{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005118#if 0
5119 uint16_t options = (requester_id << 15) | BIT_7;
5120#endif
5121 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005122 uint32_t data;
5123 struct qla_hw_data *ha = base_vha->hw;
5124
5125 /* IDC-unlock implementation using driver-unlock/lock-id
5126 * remote registers
5127 */
5128 retry = 0;
5129retry_unlock:
5130 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5131 == QLA_SUCCESS) {
5132 if (data == ha->portnum) {
5133 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5134 /* Clearing lock-id by setting 0xff */
5135 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5136 } else if (retry < 10) {
5137 /* SV: XXX: IDC unlock retrying needed here? */
5138
5139 /* Retry for IDC-unlock */
5140 qla83xx_wait_logic();
5141 retry++;
5142 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005143 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005144 goto retry_unlock;
5145 }
5146 } else if (retry < 10) {
5147 /* Retry for IDC-unlock */
5148 qla83xx_wait_logic();
5149 retry++;
5150 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005151 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005152 goto retry_unlock;
5153 }
5154
5155 return;
5156
Bart Van Assche5897cb22015-06-04 15:57:20 -07005157#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005158 /* XXX: IDC-unlock implementation using access-control mbx */
5159 retry = 0;
5160retry_unlock2:
5161 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5162 if (retry < 10) {
5163 /* Retry for IDC-unlock */
5164 qla83xx_wait_logic();
5165 retry++;
5166 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005167 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005168 goto retry_unlock2;
5169 }
5170 }
5171
5172 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005173#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005174}
5175
5176int
5177__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5178{
5179 int rval = QLA_SUCCESS;
5180 struct qla_hw_data *ha = vha->hw;
5181 uint32_t drv_presence;
5182
5183 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5184 if (rval == QLA_SUCCESS) {
5185 drv_presence |= (1 << ha->portnum);
5186 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5187 drv_presence);
5188 }
5189
5190 return rval;
5191}
5192
5193int
5194qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5195{
5196 int rval = QLA_SUCCESS;
5197
5198 qla83xx_idc_lock(vha, 0);
5199 rval = __qla83xx_set_drv_presence(vha);
5200 qla83xx_idc_unlock(vha, 0);
5201
5202 return rval;
5203}
5204
5205int
5206__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5207{
5208 int rval = QLA_SUCCESS;
5209 struct qla_hw_data *ha = vha->hw;
5210 uint32_t drv_presence;
5211
5212 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5213 if (rval == QLA_SUCCESS) {
5214 drv_presence &= ~(1 << ha->portnum);
5215 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5216 drv_presence);
5217 }
5218
5219 return rval;
5220}
5221
5222int
5223qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5224{
5225 int rval = QLA_SUCCESS;
5226
5227 qla83xx_idc_lock(vha, 0);
5228 rval = __qla83xx_clear_drv_presence(vha);
5229 qla83xx_idc_unlock(vha, 0);
5230
5231 return rval;
5232}
5233
Saurav Kashyapfa492632012-11-21 02:40:29 -05005234static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005235qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5236{
5237 struct qla_hw_data *ha = vha->hw;
5238 uint32_t drv_ack, drv_presence;
5239 unsigned long ack_timeout;
5240
5241 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5242 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5243 while (1) {
5244 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5245 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005246 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005247 break;
5248
5249 if (time_after_eq(jiffies, ack_timeout)) {
5250 ql_log(ql_log_warn, vha, 0xb067,
5251 "RESET ACK TIMEOUT! drv_presence=0x%x "
5252 "drv_ack=0x%x\n", drv_presence, drv_ack);
5253 /*
5254 * The function(s) which did not ack in time are forced
5255 * to withdraw any further participation in the IDC
5256 * reset.
5257 */
5258 if (drv_ack != drv_presence)
5259 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5260 drv_ack);
5261 break;
5262 }
5263
5264 qla83xx_idc_unlock(vha, 0);
5265 msleep(1000);
5266 qla83xx_idc_lock(vha, 0);
5267 }
5268
5269 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5270 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5271}
5272
Saurav Kashyapfa492632012-11-21 02:40:29 -05005273static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005274qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5275{
5276 int rval = QLA_SUCCESS;
5277 uint32_t idc_control;
5278
5279 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5280 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5281
5282 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5283 __qla83xx_get_idc_control(vha, &idc_control);
5284 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5285 __qla83xx_set_idc_control(vha, 0);
5286
5287 qla83xx_idc_unlock(vha, 0);
5288 rval = qla83xx_restart_nic_firmware(vha);
5289 qla83xx_idc_lock(vha, 0);
5290
5291 if (rval != QLA_SUCCESS) {
5292 ql_log(ql_log_fatal, vha, 0xb06a,
5293 "Failed to restart NIC f/w.\n");
5294 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5295 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5296 } else {
5297 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5298 "Success in restarting nic f/w.\n");
5299 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5300 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5301 }
5302
5303 return rval;
5304}
5305
5306/* Assumes idc_lock always held on entry */
5307int
5308qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5309{
5310 struct qla_hw_data *ha = base_vha->hw;
5311 int rval = QLA_SUCCESS;
5312 unsigned long dev_init_timeout;
5313 uint32_t dev_state;
5314
5315 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5316 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5317
5318 while (1) {
5319
5320 if (time_after_eq(jiffies, dev_init_timeout)) {
5321 ql_log(ql_log_warn, base_vha, 0xb06e,
5322 "Initialization TIMEOUT!\n");
5323 /* Init timeout. Disable further NIC Core
5324 * communication.
5325 */
5326 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5327 QLA8XXX_DEV_FAILED);
5328 ql_log(ql_log_info, base_vha, 0xb06f,
5329 "HW State: FAILED.\n");
5330 }
5331
5332 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5333 switch (dev_state) {
5334 case QLA8XXX_DEV_READY:
5335 if (ha->flags.nic_core_reset_owner)
5336 qla83xx_idc_audit(base_vha,
5337 IDC_AUDIT_COMPLETION);
5338 ha->flags.nic_core_reset_owner = 0;
5339 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5340 "Reset_owner reset by 0x%x.\n",
5341 ha->portnum);
5342 goto exit;
5343 case QLA8XXX_DEV_COLD:
5344 if (ha->flags.nic_core_reset_owner)
5345 rval = qla83xx_device_bootstrap(base_vha);
5346 else {
5347 /* Wait for AEN to change device-state */
5348 qla83xx_idc_unlock(base_vha, 0);
5349 msleep(1000);
5350 qla83xx_idc_lock(base_vha, 0);
5351 }
5352 break;
5353 case QLA8XXX_DEV_INITIALIZING:
5354 /* Wait for AEN to change device-state */
5355 qla83xx_idc_unlock(base_vha, 0);
5356 msleep(1000);
5357 qla83xx_idc_lock(base_vha, 0);
5358 break;
5359 case QLA8XXX_DEV_NEED_RESET:
5360 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5361 qla83xx_need_reset_handler(base_vha);
5362 else {
5363 /* Wait for AEN to change device-state */
5364 qla83xx_idc_unlock(base_vha, 0);
5365 msleep(1000);
5366 qla83xx_idc_lock(base_vha, 0);
5367 }
5368 /* reset timeout value after need reset handler */
5369 dev_init_timeout = jiffies +
5370 (ha->fcoe_dev_init_timeout * HZ);
5371 break;
5372 case QLA8XXX_DEV_NEED_QUIESCENT:
5373 /* XXX: DEBUG for now */
5374 qla83xx_idc_unlock(base_vha, 0);
5375 msleep(1000);
5376 qla83xx_idc_lock(base_vha, 0);
5377 break;
5378 case QLA8XXX_DEV_QUIESCENT:
5379 /* XXX: DEBUG for now */
5380 if (ha->flags.quiesce_owner)
5381 goto exit;
5382
5383 qla83xx_idc_unlock(base_vha, 0);
5384 msleep(1000);
5385 qla83xx_idc_lock(base_vha, 0);
5386 dev_init_timeout = jiffies +
5387 (ha->fcoe_dev_init_timeout * HZ);
5388 break;
5389 case QLA8XXX_DEV_FAILED:
5390 if (ha->flags.nic_core_reset_owner)
5391 qla83xx_idc_audit(base_vha,
5392 IDC_AUDIT_COMPLETION);
5393 ha->flags.nic_core_reset_owner = 0;
5394 __qla83xx_clear_drv_presence(base_vha);
5395 qla83xx_idc_unlock(base_vha, 0);
5396 qla8xxx_dev_failed_handler(base_vha);
5397 rval = QLA_FUNCTION_FAILED;
5398 qla83xx_idc_lock(base_vha, 0);
5399 goto exit;
5400 case QLA8XXX_BAD_VALUE:
5401 qla83xx_idc_unlock(base_vha, 0);
5402 msleep(1000);
5403 qla83xx_idc_lock(base_vha, 0);
5404 break;
5405 default:
5406 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005407 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005408 qla83xx_idc_unlock(base_vha, 0);
5409 qla8xxx_dev_failed_handler(base_vha);
5410 rval = QLA_FUNCTION_FAILED;
5411 qla83xx_idc_lock(base_vha, 0);
5412 goto exit;
5413 }
5414 }
5415
5416exit:
5417 return rval;
5418}
5419
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005420void
5421qla2x00_disable_board_on_pci_error(struct work_struct *work)
5422{
5423 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5424 board_disable);
5425 struct pci_dev *pdev = ha->pdev;
5426 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5427
Quinn Tran726b8542017-01-19 22:28:00 -08005428 /*
5429 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005430 * where it was set first.
5431 */
5432 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5433 return;
5434
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005435 ql_log(ql_log_warn, base_vha, 0x015b,
5436 "Disabling adapter.\n");
5437
Quinn Tran726b8542017-01-19 22:28:00 -08005438 qla2x00_wait_for_sess_deletion(base_vha);
5439
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005440 set_bit(UNLOADING, &base_vha->dpc_flags);
5441
5442 qla2x00_delete_all_vps(ha, base_vha);
5443
5444 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5445
5446 qla2x00_dfs_remove(base_vha);
5447
5448 qla84xx_put_chip(base_vha);
5449
5450 if (base_vha->timer_active)
5451 qla2x00_stop_timer(base_vha);
5452
5453 base_vha->flags.online = 0;
5454
5455 qla2x00_destroy_deferred_work(ha);
5456
5457 /*
5458 * Do not try to stop beacon blink as it will issue a mailbox
5459 * command.
5460 */
5461 qla2x00_free_sysfs_attr(base_vha, false);
5462
5463 fc_remove_host(base_vha->host);
5464
5465 scsi_remove_host(base_vha->host);
5466
5467 base_vha->flags.init_done = 0;
5468 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005469 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005470 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005471 qla2x00_mem_free(ha);
5472 qla82xx_md_free(base_vha);
5473 qla2x00_free_queues(ha);
5474
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005475 qla2x00_unmap_iobases(ha);
5476
5477 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005478 pci_disable_pcie_error_reporting(pdev);
5479 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005480
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005481 /*
5482 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5483 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005484}
5485
Linus Torvalds1da177e2005-04-16 15:20:36 -07005486/**************************************************************************
5487* qla2x00_do_dpc
5488* This kernel thread is a task that is schedule by the interrupt handler
5489* to perform the background processing for interrupts.
5490*
5491* Notes:
5492* This task always run in the context of a kernel thread. It
5493* is kick-off by the driver's detect code and starts up
5494* up one per adapter. It immediately goes to sleep and waits for
5495* some fibre event. When either the interrupt handler or
5496* the timer routine detects a event it will one of the task
5497* bits then wake us up.
5498**************************************************************************/
5499static int
5500qla2x00_do_dpc(void *data)
5501{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005502 scsi_qla_host_t *base_vha;
5503 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005504 uint32_t online;
5505 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005507 ha = (struct qla_hw_data *)data;
5508 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509
Dongsheng Yang8698a742014-03-11 18:09:12 +08005510 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005511
James Bottomley563585e2011-01-27 16:12:37 -05005512 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005513 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005514 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5515 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516
Christoph Hellwig39a11242006-02-14 18:46:22 +01005517 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005519 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5520 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521
Andrew Vasquez85880802009-12-15 21:29:46 -08005522 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005523 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5524 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005525 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005526 }
5527
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528 ha->dpc_active = 1;
5529
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005530 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5531 "DPC handler waking up, dpc_flags=0x%lx.\n",
5532 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005534 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5535 break;
5536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005537 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005538
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005539 if (IS_P3P_TYPE(ha)) {
5540 if (IS_QLA8044(ha)) {
5541 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5542 &base_vha->dpc_flags)) {
5543 qla8044_idc_lock(ha);
5544 qla8044_wr_direct(base_vha,
5545 QLA8044_CRB_DEV_STATE_INDEX,
5546 QLA8XXX_DEV_FAILED);
5547 qla8044_idc_unlock(ha);
5548 ql_log(ql_log_info, base_vha, 0x4004,
5549 "HW State: FAILED.\n");
5550 qla8044_device_state_handler(base_vha);
5551 continue;
5552 }
5553
5554 } else {
5555 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5556 &base_vha->dpc_flags)) {
5557 qla82xx_idc_lock(ha);
5558 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5559 QLA8XXX_DEV_FAILED);
5560 qla82xx_idc_unlock(ha);
5561 ql_log(ql_log_info, base_vha, 0x0151,
5562 "HW State: FAILED.\n");
5563 qla82xx_device_state_handler(base_vha);
5564 continue;
5565 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005566 }
5567
5568 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5569 &base_vha->dpc_flags)) {
5570
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005571 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5572 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005573 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5574 &base_vha->dpc_flags))) {
5575 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5576 /* FCoE-ctx reset failed.
5577 * Escalate to chip-reset
5578 */
5579 set_bit(ISP_ABORT_NEEDED,
5580 &base_vha->dpc_flags);
5581 }
5582 clear_bit(ABORT_ISP_ACTIVE,
5583 &base_vha->dpc_flags);
5584 }
5585
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005586 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5587 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005588 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005589 } else if (IS_QLAFX00(ha)) {
5590 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5591 &base_vha->dpc_flags)) {
5592 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5593 "Firmware Reset Recovery\n");
5594 if (qlafx00_reset_initialize(base_vha)) {
5595 /* Failed. Abort isp later. */
5596 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005597 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005598 set_bit(ISP_UNRECOVERABLE,
5599 &base_vha->dpc_flags);
5600 ql_dbg(ql_dbg_dpc, base_vha,
5601 0x4021,
5602 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005603 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005604 }
5605 }
5606
5607 if (test_and_clear_bit(FX00_TARGET_SCAN,
5608 &base_vha->dpc_flags)) {
5609 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5610 "ISPFx00 Target Scan scheduled\n");
5611 if (qlafx00_rescan_isp(base_vha)) {
5612 if (!test_bit(UNLOADING,
5613 &base_vha->dpc_flags))
5614 set_bit(ISP_UNRECOVERABLE,
5615 &base_vha->dpc_flags);
5616 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5617 "ISPFx00 Target Scan Failed\n");
5618 }
5619 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5620 "ISPFx00 Target Scan End\n");
5621 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005622 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5623 &base_vha->dpc_flags)) {
5624 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5625 "ISPFx00 Host Info resend scheduled\n");
5626 qlafx00_fx_disc(base_vha,
5627 &base_vha->hw->mr.fcport,
5628 FXDISC_REG_HOST_INFO);
5629 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005630 }
5631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005632 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5633 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005635 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5636 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005638 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639
Giridhar Malavalia9083012010-04-12 17:59:55 -07005640 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641 /* failed. retry later */
5642 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005643 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005645 clear_bit(ABORT_ISP_ACTIVE,
5646 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005647 }
5648
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005649 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5650 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651 }
5652
David Jefferya394aac2012-11-21 02:39:54 -05005653 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5654 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005655 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005656 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005657
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005658 if (IS_QLAFX00(ha))
5659 goto loop_resync_check;
5660
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005661 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005662 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5663 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005664 if (IS_P3P_TYPE(ha)) {
5665 if (IS_QLA82XX(ha))
5666 qla82xx_device_state_handler(base_vha);
5667 if (IS_QLA8044(ha))
5668 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005669 clear_bit(ISP_QUIESCE_NEEDED,
5670 &base_vha->dpc_flags);
5671 if (!ha->flags.quiesce_owner) {
5672 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005673 if (IS_QLA82XX(ha)) {
5674 qla82xx_idc_lock(ha);
5675 qla82xx_clear_qsnt_ready(
5676 base_vha);
5677 qla82xx_idc_unlock(ha);
5678 } else if (IS_QLA8044(ha)) {
5679 qla8044_idc_lock(ha);
5680 qla8044_clear_qsnt_ready(
5681 base_vha);
5682 qla8044_idc_unlock(ha);
5683 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005684 }
5685 } else {
5686 clear_bit(ISP_QUIESCE_NEEDED,
5687 &base_vha->dpc_flags);
5688 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005689 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005690 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5691 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005692 }
5693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005694 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005695 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005696 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005698 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5699 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005700 qla2x00_rst_aen(base_vha);
5701 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005702 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5703 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704 }
5705
5706 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005707 if ((test_and_clear_bit(RELOGIN_NEEDED,
5708 &base_vha->dpc_flags)) &&
5709 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5710 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005712 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5713 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005714 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005715 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5716 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005718loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005719 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005720 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005722 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5723 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724
5725 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005726 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727
Bart Van Assche52c82822015-07-09 07:23:26 -07005728 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005730 clear_bit(LOOP_RESYNC_ACTIVE,
5731 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732 }
5733
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005734 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5735 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 }
5737
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005738 if (IS_QLAFX00(ha))
5739 goto intr_on_check;
5740
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005741 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5742 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5743 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5744 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005745 }
5746
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005747intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005748 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005749 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005751 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005752 &base_vha->dpc_flags)) {
5753 if (ha->beacon_blink_led == 1)
5754 ha->isp_ops->beacon_blink(base_vha);
5755 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005756
Michael Hernandezd7459522016-12-12 14:40:07 -08005757 /* qpair online check */
5758 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
5759 &base_vha->dpc_flags)) {
5760 if (ha->flags.eeh_busy ||
5761 ha->flags.pci_channel_io_perm_failure)
5762 online = 0;
5763 else
5764 online = 1;
5765
5766 mutex_lock(&ha->mq_lock);
5767 list_for_each_entry(qpair, &base_vha->qp_list,
5768 qp_list_elem)
5769 qpair->online = online;
5770 mutex_unlock(&ha->mq_lock);
5771 }
5772
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005773 if (!IS_QLAFX00(ha))
5774 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005775
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005777end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005778 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005780 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005781
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005782 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5783 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784
5785 /*
5786 * Make sure that nobody tries to wake us up again.
5787 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 ha->dpc_active = 0;
5789
Andrew Vasquezac280b62009-08-20 11:06:05 -07005790 /* Cleanup any residual CTX SRBs. */
5791 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5792
Christoph Hellwig39a11242006-02-14 18:46:22 +01005793 return 0;
5794}
5795
5796void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005797qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005798{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005799 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005800 struct task_struct *t = ha->dpc_thread;
5801
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005802 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005803 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804}
5805
5806/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807* qla2x00_rst_aen
5808* Processes asynchronous reset.
5809*
5810* Input:
5811* ha = adapter block pointer.
5812*/
5813static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005814qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005816 if (vha->flags.online && !vha->flags.reset_active &&
5817 !atomic_read(&vha->loop_down_timer) &&
5818 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005820 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821
5822 /*
5823 * Issue marker command only when we are going to start
5824 * the I/O.
5825 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005826 vha->marker_needed = 1;
5827 } while (!atomic_read(&vha->loop_down_timer) &&
5828 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 }
5830}
5831
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832/**************************************************************************
5833* qla2x00_timer
5834*
5835* Description:
5836* One second timer
5837*
5838* Context: Interrupt
5839***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005840void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005841qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 int start_dpc = 0;
5845 int index;
5846 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005847 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005848 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005849 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005850
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005851 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005852 ql_dbg(ql_dbg_timer, vha, 0x6000,
5853 "EEH = %d, restarting timer.\n",
5854 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005855 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5856 return;
5857 }
5858
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005859 /*
5860 * Hardware read to raise pending EEH errors during mailbox waits. If
5861 * the read returns -1 then disable the board.
5862 */
5863 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005864 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005865 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005868 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005869 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005870 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5871 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005872 if (IS_QLA82XX(ha))
5873 qla82xx_watchdog(vha);
5874 else if (IS_QLA8044(ha))
5875 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005876 }
5877
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005878 if (!vha->vp_idx && IS_QLAFX00(ha))
5879 qlafx00_timer_routine(vha);
5880
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005882 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005883 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5884 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005885 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005887 if (atomic_read(&vha->loop_down_timer) ==
5888 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005890 ql_log(ql_log_info, vha, 0x6008,
5891 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005893 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5894 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005896 /*
5897 * Schedule an ISP abort to return any FCP2-device
5898 * commands.
5899 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005900 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005901 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005902 spin_lock_irqsave(&ha->hardware_lock,
5903 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005904 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005905 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005906 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005907 index++) {
5908 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005910 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005911 if (!sp)
5912 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07005913 if (sp->cmd_type != TYPE_SRB)
5914 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005915 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005916 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005917 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005918 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005919 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005921 if (IS_QLA82XX(ha))
5922 set_bit(FCOE_CTX_RESET_NEEDED,
5923 &vha->dpc_flags);
5924 else
5925 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005926 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005927 break;
5928 }
5929 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005930 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 start_dpc++;
5933 }
5934
5935 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005936 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005937 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005938 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 "Loop down - aborting ISP.\n");
5940
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005941 if (IS_QLA82XX(ha))
5942 set_bit(FCOE_CTX_RESET_NEEDED,
5943 &vha->dpc_flags);
5944 else
5945 set_bit(ISP_ABORT_NEEDED,
5946 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947 }
5948 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005949 ql_dbg(ql_dbg_timer, vha, 0x600a,
5950 "Loop down - seconds remaining %d.\n",
5951 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005953 /* Check if beacon LED needs to be blinked for physical host only */
5954 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005955 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005956 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005957 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5958 start_dpc++;
5959 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005960 }
5961
Andrew Vasquez550bf572008-04-24 15:21:23 -07005962 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005963 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005964 start_dpc++;
5965
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005967 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5968 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5969 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005971 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5972 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005973 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5974 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005975 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005976 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005977 ql_dbg(ql_dbg_timer, vha, 0x600b,
5978 "isp_abort_needed=%d loop_resync_needed=%d "
5979 "fcport_update_needed=%d start_dpc=%d "
5980 "reset_marker_needed=%d",
5981 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5982 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5983 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5984 start_dpc,
5985 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5986 ql_dbg(ql_dbg_timer, vha, 0x600c,
5987 "beacon_blink_needed=%d isp_unrecoverable=%d "
5988 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005989 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005990 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5991 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5992 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5993 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005994 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005995 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005998 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999}
6000
Andrew Vasquez54333832005-11-09 15:49:04 -08006001/* Firmware interface routines. */
6002
Chad Dupuisf73cb692014-02-26 04:15:06 -05006003#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006004#define FW_ISP21XX 0
6005#define FW_ISP22XX 1
6006#define FW_ISP2300 2
6007#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006008#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006009#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006010#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006011#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006012#define FW_ISP2031 8
6013#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006014#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006015
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006016#define FW_FILE_ISP21XX "ql2100_fw.bin"
6017#define FW_FILE_ISP22XX "ql2200_fw.bin"
6018#define FW_FILE_ISP2300 "ql2300_fw.bin"
6019#define FW_FILE_ISP2322 "ql2322_fw.bin"
6020#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006021#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006022#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006023#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006024#define FW_FILE_ISP2031 "ql2600_fw.bin"
6025#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006026#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006027
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006028
Daniel Walkere1e82b62008-05-12 22:21:10 -07006029static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006030
6031static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006032 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6033 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6034 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6035 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6036 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006037 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006038 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006039 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006040 { .name = FW_FILE_ISP2031, },
6041 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006042 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006043};
6044
6045struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006046qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006047{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006048 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006049 struct fw_blob *blob;
6050
Andrew Vasquez54333832005-11-09 15:49:04 -08006051 if (IS_QLA2100(ha)) {
6052 blob = &qla_fw_blobs[FW_ISP21XX];
6053 } else if (IS_QLA2200(ha)) {
6054 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006055 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006056 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006057 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006058 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006059 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006060 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006061 } else if (IS_QLA25XX(ha)) {
6062 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006063 } else if (IS_QLA81XX(ha)) {
6064 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006065 } else if (IS_QLA82XX(ha)) {
6066 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006067 } else if (IS_QLA2031(ha)) {
6068 blob = &qla_fw_blobs[FW_ISP2031];
6069 } else if (IS_QLA8031(ha)) {
6070 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006071 } else if (IS_QLA27XX(ha)) {
6072 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006073 } else {
6074 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006075 }
6076
Daniel Walkere1e82b62008-05-12 22:21:10 -07006077 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006078 if (blob->fw)
6079 goto out;
6080
6081 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006082 ql_log(ql_log_warn, vha, 0x0063,
6083 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006084 blob->fw = NULL;
6085 blob = NULL;
6086 goto out;
6087 }
6088
6089out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006090 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006091 return blob;
6092}
6093
6094static void
6095qla2x00_release_firmware(void)
6096{
6097 int idx;
6098
Daniel Walkere1e82b62008-05-12 22:21:10 -07006099 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006100 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006101 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006102 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006103}
6104
Seokmann Ju14e660e2007-09-20 14:07:36 -07006105static pci_ers_result_t
6106qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6107{
Andrew Vasquez85880802009-12-15 21:29:46 -08006108 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6109 struct qla_hw_data *ha = vha->hw;
6110
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006111 ql_dbg(ql_dbg_aer, vha, 0x9000,
6112 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006113
Seokmann Ju14e660e2007-09-20 14:07:36 -07006114 switch (state) {
6115 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006116 ha->flags.eeh_busy = 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08006117 if (ql2xmqsupport) {
6118 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6119 qla2xxx_wake_dpc(vha);
6120 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006121 return PCI_ERS_RESULT_CAN_RECOVER;
6122 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006123 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006124 /* For ISP82XX complete any pending mailbox cmd */
6125 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006126 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006127 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6128 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006129 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006130 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006131 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006132 /* Return back all IOs */
6133 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Michael Hernandezd7459522016-12-12 14:40:07 -08006134 if (ql2xmqsupport) {
6135 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6136 qla2xxx_wake_dpc(vha);
6137 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006138 return PCI_ERS_RESULT_NEED_RESET;
6139 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006140 ha->flags.pci_channel_io_perm_failure = 1;
6141 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Michael Hernandezd7459522016-12-12 14:40:07 -08006142 if (ql2xmqsupport) {
6143 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6144 qla2xxx_wake_dpc(vha);
6145 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006146 return PCI_ERS_RESULT_DISCONNECT;
6147 }
6148 return PCI_ERS_RESULT_NEED_RESET;
6149}
6150
6151static pci_ers_result_t
6152qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6153{
6154 int risc_paused = 0;
6155 uint32_t stat;
6156 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006157 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6158 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006159 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6160 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6161
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006162 if (IS_QLA82XX(ha))
6163 return PCI_ERS_RESULT_RECOVERED;
6164
Seokmann Ju14e660e2007-09-20 14:07:36 -07006165 spin_lock_irqsave(&ha->hardware_lock, flags);
6166 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6167 stat = RD_REG_DWORD(&reg->hccr);
6168 if (stat & HCCR_RISC_PAUSE)
6169 risc_paused = 1;
6170 } else if (IS_QLA23XX(ha)) {
6171 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6172 if (stat & HSR_RISC_PAUSED)
6173 risc_paused = 1;
6174 } else if (IS_FWI2_CAPABLE(ha)) {
6175 stat = RD_REG_DWORD(&reg24->host_status);
6176 if (stat & HSRX_RISC_PAUSED)
6177 risc_paused = 1;
6178 }
6179 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6180
6181 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006182 ql_log(ql_log_info, base_vha, 0x9003,
6183 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006184 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006185
6186 return PCI_ERS_RESULT_NEED_RESET;
6187 } else
6188 return PCI_ERS_RESULT_RECOVERED;
6189}
6190
Saurav Kashyapfa492632012-11-21 02:40:29 -05006191static uint32_t
6192qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006193{
6194 uint32_t rval = QLA_FUNCTION_FAILED;
6195 uint32_t drv_active = 0;
6196 struct qla_hw_data *ha = base_vha->hw;
6197 int fn;
6198 struct pci_dev *other_pdev = NULL;
6199
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006200 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6201 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006202
6203 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6204
6205 if (base_vha->flags.online) {
6206 /* Abort all outstanding commands,
6207 * so as to be requeued later */
6208 qla2x00_abort_isp_cleanup(base_vha);
6209 }
6210
6211
6212 fn = PCI_FUNC(ha->pdev->devfn);
6213 while (fn > 0) {
6214 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006215 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6216 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006217 other_pdev =
6218 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6219 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6220 fn));
6221
6222 if (!other_pdev)
6223 continue;
6224 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006225 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6226 "Found PCI func available and enable at 0x%x.\n",
6227 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006228 pci_dev_put(other_pdev);
6229 break;
6230 }
6231 pci_dev_put(other_pdev);
6232 }
6233
6234 if (!fn) {
6235 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006236 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6237 "This devfn is reset owner = 0x%x.\n",
6238 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006239 qla82xx_idc_lock(ha);
6240
6241 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006242 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006243
6244 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6245 QLA82XX_IDC_VERSION);
6246
6247 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006248 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6249 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006250
6251 qla82xx_idc_unlock(ha);
6252 /* Reset if device is not already reset
6253 * drv_active would be 0 if a reset has already been done
6254 */
6255 if (drv_active)
6256 rval = qla82xx_start_firmware(base_vha);
6257 else
6258 rval = QLA_SUCCESS;
6259 qla82xx_idc_lock(ha);
6260
6261 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006262 ql_log(ql_log_info, base_vha, 0x900b,
6263 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006264 qla82xx_clear_drv_active(ha);
6265 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006266 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006267 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006268 ql_log(ql_log_info, base_vha, 0x900c,
6269 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006270 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006271 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006272 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006273 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006274 rval = qla82xx_restart_isp(base_vha);
6275 qla82xx_idc_lock(ha);
6276 /* Clear driver state register */
6277 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6278 qla82xx_set_drv_active(base_vha);
6279 }
6280 qla82xx_idc_unlock(ha);
6281 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006282 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6283 "This devfn is not reset owner = 0x%x.\n",
6284 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006285 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006286 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006287 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006288 rval = qla82xx_restart_isp(base_vha);
6289 qla82xx_idc_lock(ha);
6290 qla82xx_set_drv_active(base_vha);
6291 qla82xx_idc_unlock(ha);
6292 }
6293 }
6294 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6295
6296 return rval;
6297}
6298
Seokmann Ju14e660e2007-09-20 14:07:36 -07006299static pci_ers_result_t
6300qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6301{
6302 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
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;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006305 struct rsp_que *rsp;
6306 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006307
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006308 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6309 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006310
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006311 /* Workaround: qla2xxx driver which access hardware earlier
6312 * needs error state to be pci_channel_io_online.
6313 * Otherwise mailbox command timesout.
6314 */
6315 pdev->error_state = pci_channel_io_normal;
6316
6317 pci_restore_state(pdev);
6318
Richard Lary8c1496b2010-02-18 10:07:29 -08006319 /* pci_restore_state() clears the saved_state flag of the device
6320 * save restored state which resets saved_state flag
6321 */
6322 pci_save_state(pdev);
6323
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006324 if (ha->mem_only)
6325 rc = pci_enable_device_mem(pdev);
6326 else
6327 rc = pci_enable_device(pdev);
6328
6329 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006330 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006331 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006332 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006333 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006334
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006335 rsp = ha->rsp_q_map[0];
6336 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006337 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006338
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006339 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006340 goto exit_slot_reset;
6341
6342 if (IS_QLA82XX(ha)) {
6343 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6344 ret = PCI_ERS_RESULT_RECOVERED;
6345 goto exit_slot_reset;
6346 } else
6347 goto exit_slot_reset;
6348 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006349
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006350 while (ha->flags.mbox_busy && retries--)
6351 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006353 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006354 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006355 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006356 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006357
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006358
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006359exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006360 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6361 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006362
Seokmann Ju14e660e2007-09-20 14:07:36 -07006363 return ret;
6364}
6365
6366static void
6367qla2xxx_pci_resume(struct pci_dev *pdev)
6368{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006369 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6370 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006371 int ret;
6372
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006373 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6374 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006375
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006376 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006377 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006378 ql_log(ql_log_fatal, base_vha, 0x9002,
6379 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006380 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006381
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006382 pci_cleanup_aer_uncorrect_error_status(pdev);
6383
Andrew Vasquez85880802009-12-15 21:29:46 -08006384 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006385}
6386
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04006387static void
6388qla83xx_disable_laser(scsi_qla_host_t *vha)
6389{
6390 uint32_t reg, data, fn;
6391 struct qla_hw_data *ha = vha->hw;
6392 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
6393
6394 /* pci func #/port # */
6395 ql_dbg(ql_dbg_init, vha, 0x004b,
6396 "Disabling Laser for hba: %p\n", vha);
6397
6398 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
6399 (BIT_15|BIT_14|BIT_13|BIT_12));
6400
6401 fn = (fn >> 12);
6402
6403 if (fn & 1)
6404 reg = PORT_1_2031;
6405 else
6406 reg = PORT_0_2031;
6407
6408 data = LASER_OFF_2031;
6409
6410 qla83xx_wr_reg(vha, reg, data);
6411}
6412
Michael Hernandez56012362016-12-12 14:40:08 -08006413static int qla2xxx_map_queues(struct Scsi_Host *shost)
6414{
6415 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6416
6417 return blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
6418}
6419
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006420static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006421 .error_detected = qla2xxx_pci_error_detected,
6422 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6423 .slot_reset = qla2xxx_pci_slot_reset,
6424 .resume = qla2xxx_pci_resume,
6425};
6426
Andrew Vasquez54333832005-11-09 15:49:04 -08006427static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006428 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6429 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6430 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6431 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6432 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6433 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6434 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6435 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6436 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006437 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006438 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6439 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006440 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006441 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006442 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006443 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006444 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006445 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006446 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006447 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006448 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006449 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006450 { 0 },
6451};
6452MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6453
Andrew Vasquezfca29702005-07-06 10:31:47 -07006454static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006455 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006456 .driver = {
6457 .owner = THIS_MODULE,
6458 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006459 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006460 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006461 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006462 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006463 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006464};
6465
Al Viro75ef9de2013-04-04 19:09:41 -04006466static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006467 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006468 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006469};
6470
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471/**
6472 * qla2x00_module_init - Module initialization.
6473 **/
6474static int __init
6475qla2x00_module_init(void)
6476{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006477 int ret = 0;
6478
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006480 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006481 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006483 ql_log(ql_log_fatal, NULL, 0x0001,
6484 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 return -ENOMEM;
6486 }
6487
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006488 /* Initialize target kmem_cache and mem_pools */
6489 ret = qlt_init();
6490 if (ret < 0) {
6491 kmem_cache_destroy(srb_cachep);
6492 return ret;
6493 } else if (ret > 0) {
6494 /*
6495 * If initiator mode is explictly disabled by qlt_init(),
6496 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6497 * performing scsi_scan_target() during LOOP UP event.
6498 */
6499 qla2xxx_transport_functions.disable_target_scan = 1;
6500 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6501 }
6502
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 /* Derive version string. */
6504 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006505 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006506 strcat(qla2x00_version_str, "-debug");
6507
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006508 qla2xxx_transport_template =
6509 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006510 if (!qla2xxx_transport_template) {
6511 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006512 ql_log(ql_log_fatal, NULL, 0x0002,
6513 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006514 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006516 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006517
6518 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6519 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006520 ql_log(ql_log_fatal, NULL, 0x0003,
6521 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006522 }
6523
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006524 qla2xxx_transport_vport_template =
6525 fc_attach_transport(&qla2xxx_transport_vport_functions);
6526 if (!qla2xxx_transport_vport_template) {
6527 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006528 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006529 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006530 ql_log(ql_log_fatal, NULL, 0x0004,
6531 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006532 return -ENODEV;
6533 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006534 ql_log(ql_log_info, NULL, 0x0005,
6535 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006536 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006537 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006538 if (ret) {
6539 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006540 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006541 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006542 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006543 ql_log(ql_log_fatal, NULL, 0x0006,
6544 "pci_register_driver failed...ret=%d Failing load!.\n",
6545 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006546 }
6547 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548}
6549
6550/**
6551 * qla2x00_module_exit - Module cleanup.
6552 **/
6553static void __exit
6554qla2x00_module_exit(void)
6555{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006556 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006557 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006558 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006559 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006560 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006561 if (ctx_cachep)
6562 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006564 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565}
6566
6567module_init(qla2x00_module_init);
6568module_exit(qla2x00_module_exit);
6569
6570MODULE_AUTHOR("QLogic Corporation");
6571MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6572MODULE_LICENSE("GPL");
6573MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006574MODULE_FIRMWARE(FW_FILE_ISP21XX);
6575MODULE_FIRMWARE(FW_FILE_ISP22XX);
6576MODULE_FIRMWARE(FW_FILE_ISP2300);
6577MODULE_FIRMWARE(FW_FILE_ISP2322);
6578MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006579MODULE_FIRMWARE(FW_FILE_ISP25XX);