blob: e5db474436688739f76842a38ab3351dd1e2133d [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <scsi/scsi_tcq.h>
17#include <scsi/scsicam.h>
18#include <scsi/scsi_transport.h>
19#include <scsi/scsi_transport_fc.h>
20
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040021#include "qla_target.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24 * Driver version
25 */
26char qla2x00_version_str[40];
27
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070028static int apidev_major;
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/*
31 * SRB allocation cache
32 */
Christoph Lametere18b8902006-12-06 20:33:20 -080033static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Giridhar Malavalia9083012010-04-12 17:59:55 -070035/*
36 * CT6 CTX allocation cache
37 */
38static struct kmem_cache *ctx_cachep;
Saurav Kashyap3ce88662011-07-14 12:00:12 -070039/*
40 * error level for logging
41 */
42int ql_errlev = ql_log_all;
Giridhar Malavalia9083012010-04-12 17:59:55 -070043
Saurav Kashyapfa492632012-11-21 02:40:29 -050044static int ql2xenableclass2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040045module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
46MODULE_PARM_DESC(ql2xenableclass2,
47 "Specify if Class 2 operations are supported from the very "
48 "beginning. Default is 0 - class 2 not supported.");
49
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080052module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053MODULE_PARM_DESC(ql2xlogintimeout,
54 "Login timeout value in seconds.");
55
Andrew Vasqueza7b61842007-05-07 07:42:59 -070056int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080057module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070059 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 "a PORT-DOWN status.");
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int ql2xplogiabsentdevice;
63module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
64MODULE_PARM_DESC(ql2xplogiabsentdevice,
65 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070066 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080070module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071MODULE_PARM_DESC(ql2xloginretrycount,
72 "Specify an alternate value for the NVRAM login retry count.");
73
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070074int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080075module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070076MODULE_PARM_DESC(ql2xallocfwdump,
77 "Option to enable allocation of memory for a firmware dump "
78 "during HBA initialization. Memory allocation requirements "
79 "vary by ISP type. Default is 1 - allocate memory.");
80
Andrew Vasquez11010fe2006-10-06 09:54:59 -070081int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070082module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -040083module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070084MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070085 "Option to enable extended error logging,\n"
86 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
87 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
88 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
89 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
90 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
91 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
92 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
93 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050094 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
95 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070096 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080097 "\t\t0x1e400000 - Preferred value for capturing essential "
98 "debug information (equivalent to old "
99 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -0700100 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700101
Giridhar Malavalia9083012010-04-12 17:59:55 -0700102int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800103module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700104MODULE_PARM_DESC(ql2xshiftctondsd,
105 "Set to control shifting of command type processing "
106 "based on total number of SG elements.");
107
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700108int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400109module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400110module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700111MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100112 "Enables FDMI registrations. "
113 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700114
Chad Dupuis50280c02013-10-30 03:38:14 -0400115#define MAX_Q_DEPTH 32
116static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700117module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
118MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400119 "Maximum queue depth to set for each LUN. "
120 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700121
Arun Easi9e522cd2012-08-22 14:21:31 -0400122int ql2xenabledif = 2;
123module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700124MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600125 " Enable T10-CRC-DIF:\n"
126 " Default is 2.\n"
127 " 0 -- No DIF Support\n"
128 " 1 -- Enable DIF for all types\n"
129 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700130
Arun Easi8cb20492011-08-16 11:29:22 -0700131int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700132module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
133MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700134 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600135 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700136 " 0 -- Error isolation disabled\n"
137 " 1 -- Error isolation enabled only for DIX Type 0\n"
138 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700139
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700140int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800141module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700142MODULE_PARM_DESC(ql2xiidmaenable,
143 "Enables iIDMA settings "
144 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
145
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800146int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800147module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800148MODULE_PARM_DESC(ql2xmaxqueues,
149 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700150 "Default is 1 for single queue. Set it to number "
151 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700152
153int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800154module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700155MODULE_PARM_DESC(ql2xmultique_tag,
156 "Enables CPU affinity settings for the driver "
157 "Default is 0 for no affinity of request and response IO. "
158 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700159
160int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700161module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400162module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700163MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700164 "Option to specify location from which to load ISP firmware:.\n"
165 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700166 " interface.\n"
167 " 1 -- load firmware from flash.\n"
168 " 0 -- use default semantics.\n");
169
Andrew Vasquezae97c912010-02-18 10:07:28 -0800170int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800171module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800172MODULE_PARM_DESC(ql2xetsenable,
173 "Enables firmware ETS burst."
174 "Default is 0 - skip ETS enablement.");
175
Giridhar Malavali69078692010-05-28 15:08:28 -0700176int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700177module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700178MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700179 "Option to specify scheme for request queue posting.\n"
180 " 0 -- Regular doorbell.\n"
181 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700182
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700183int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800184module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700185MODULE_PARM_DESC(ql2xtargetreset,
186 "Enable target reset."
187 "Default is 1 - use hw defaults.");
188
Chad Dupuis4da26e12010-10-15 11:27:40 -0700189int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800190module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700191MODULE_PARM_DESC(ql2xgffidenable,
192 "Enables GFF_ID checks of port type. "
193 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700194
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700195int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800196module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700197MODULE_PARM_DESC(ql2xasynctmfenable,
198 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
199 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700200
201int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700202module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700203MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700204 "Option to specify reset behaviour.\n"
205 " 0 (Default) -- Reset on failure.\n"
206 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700207
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200208uint64_t ql2xmaxlun = MAX_LUNS;
209module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700210MODULE_PARM_DESC(ql2xmaxlun,
211 "Defines the maximum LU number to register with the SCSI "
212 "midlayer. Default is 65535.");
213
Giridhar Malavali08de2842011-08-16 11:31:44 -0700214int ql2xmdcapmask = 0x1F;
215module_param(ql2xmdcapmask, int, S_IRUGO);
216MODULE_PARM_DESC(ql2xmdcapmask,
217 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800218 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700219
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800220int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700221module_param(ql2xmdenable, int, S_IRUGO);
222MODULE_PARM_DESC(ql2xmdenable,
223 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800224 "0 - MiniDump disabled. "
225 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700226
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500227int ql2xexlogins = 0;
228module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
229MODULE_PARM_DESC(ql2xexlogins,
230 "Number of extended Logins. "
231 "0 (Default)- Disabled.");
232
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500233int ql2xexchoffld = 0;
234module_param(ql2xexchoffld, uint, S_IRUGO|S_IWUSR);
235MODULE_PARM_DESC(ql2xexchoffld,
236 "Number of exchanges to offload. "
237 "0 (Default)- Disabled.");
238
Himanshu Madhanif198caf2016-01-27 12:03:30 -0500239int ql2xfwholdabts = 0;
240module_param(ql2xfwholdabts, int, S_IRUGO);
241MODULE_PARM_DESC(ql2xfwholdabts,
242 "Allow FW to hold status IOCB until ABTS rsp received. "
243 "0 (Default) Do not set fw option. "
244 "1 - Set fw option to hold ABTS.");
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700247 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 */
249static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500250static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800251static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
252static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500253static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500254static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255static int qla2xxx_eh_abort(struct scsi_cmnd *);
256static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700257static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
259static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400261static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400262static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400263static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700264
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700265struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700267 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700268 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700269
270 .eh_abort_handler = qla2xxx_eh_abort,
271 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700272 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700273 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
274 .eh_host_reset_handler = qla2xxx_eh_host_reset,
275
276 .slave_configure = qla2xxx_slave_configure,
277
278 .slave_alloc = qla2xxx_slave_alloc,
279 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700280 .scan_finished = qla2xxx_scan_finished,
281 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100282 .change_queue_depth = scsi_change_queue_depth,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700283 .this_id = -1,
284 .cmd_per_lun = 3,
285 .use_clustering = ENABLE_CLUSTERING,
286 .sg_tablesize = SG_ALL,
287
288 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700289 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400290
291 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100292 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700293};
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700296struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298/* TODO Convert to inlines
299 *
300 * Timer routines
301 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700303__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800304qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306 init_timer(&vha->timer);
307 vha->timer.expires = jiffies + interval * HZ;
308 vha->timer.data = (unsigned long)vha;
309 vha->timer.function = (void (*)(unsigned long))func;
310 add_timer(&vha->timer);
311 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
314static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800315qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700317 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700318 if (vha->device_flags & DFLG_DEV_FAILED) {
319 ql_dbg(ql_dbg_timer, vha, 0x600d,
320 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700321 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700322 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700323
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800324 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
Adrian Bunka824ebb2008-01-17 09:02:15 -0800327static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800328qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800330 del_timer_sync(&vha->timer);
331 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334static int qla2x00_do_dpc(void *data);
335
336static void qla2x00_rst_aen(scsi_qla_host_t *);
337
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800338static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
339 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700340static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800341static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400344static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
345 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800346{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700347 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700348 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800349 GFP_KERNEL);
350 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700351 ql_log(ql_log_fatal, vha, 0x003b,
352 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800353 goto fail_req_map;
354 }
355
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700356 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800357 GFP_KERNEL);
358 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700359 ql_log(ql_log_fatal, vha, 0x003c,
360 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800361 goto fail_rsp_map;
362 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400363 /*
364 * Make sure we record at least the request and response queue zero in
365 * case we need to free them if part of the probe fails.
366 */
367 ha->rsp_q_map[0] = rsp;
368 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800369 set_bit(0, ha->rsp_qid_map);
370 set_bit(0, ha->req_qid_map);
371 return 1;
372
373fail_rsp_map:
374 kfree(ha->req_q_map);
375 ha->req_q_map = NULL;
376fail_req_map:
377 return -ENOMEM;
378}
379
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700380static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800381{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400382 if (IS_QLAFX00(ha)) {
383 if (req && req->ring_fx00)
384 dma_free_coherent(&ha->pdev->dev,
385 (req->length_fx00 + 1) * sizeof(request_t),
386 req->ring_fx00, req->dma_fx00);
387 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800388 dma_free_coherent(&ha->pdev->dev,
389 (req->length + 1) * sizeof(request_t),
390 req->ring, req->dma);
391
Chad Dupuis8d93f552013-01-30 03:34:37 -0500392 if (req)
393 kfree(req->outstanding_cmds);
394
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800395 kfree(req);
396 req = NULL;
397}
398
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700399static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
400{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400401 if (IS_QLAFX00(ha)) {
402 if (rsp && rsp->ring)
403 dma_free_coherent(&ha->pdev->dev,
404 (rsp->length_fx00 + 1) * sizeof(request_t),
405 rsp->ring_fx00, rsp->dma_fx00);
406 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700407 dma_free_coherent(&ha->pdev->dev,
408 (rsp->length + 1) * sizeof(response_t),
409 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400410 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700411 kfree(rsp);
412 rsp = NULL;
413}
414
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415static void qla2x00_free_queues(struct qla_hw_data *ha)
416{
417 struct req_que *req;
418 struct rsp_que *rsp;
419 int cnt;
420
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700421 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500422 if (!test_bit(cnt, ha->req_qid_map))
423 continue;
424
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800425 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700426 qla2x00_free_req_que(ha, req);
427 }
428 kfree(ha->req_q_map);
429 ha->req_q_map = NULL;
430
431 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500432 if (!test_bit(cnt, ha->rsp_qid_map))
433 continue;
434
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700435 rsp = ha->rsp_q_map[cnt];
436 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800437 }
438 kfree(ha->rsp_q_map);
439 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800440}
441
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700442static int qla25xx_setup_mode(struct scsi_qla_host *vha)
443{
444 uint16_t options = 0;
445 int ques, req, ret;
446 struct qla_hw_data *ha = vha->hw;
447
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700448 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700449 ql_log(ql_log_warn, vha, 0x00d8,
450 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700451 goto fail;
452 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700453 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700454 /* create a request queue for IO */
455 options |= BIT_7;
456 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
457 QLA_DEFAULT_QUE_QOS);
458 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700459 ql_log(ql_log_warn, vha, 0x00e0,
460 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700461 goto fail;
462 }
Tejun Heo278274d2011-02-01 11:42:42 +0100463 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700464 vha->req = ha->req_q_map[req];
465 options |= BIT_1;
466 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
467 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
468 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700469 ql_log(ql_log_warn, vha, 0x00e8,
470 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700471 goto fail2;
472 }
473 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700474 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700475 ql_dbg(ql_dbg_multiq, vha, 0xc007,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100476 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700477 "no. of response queues:%d no. of request queues:%d.\n",
478 ha->max_rsp_queues, ha->max_req_queues);
479 ql_dbg(ql_dbg_init, vha, 0x00e9,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100480 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700481 "no. of response queues:%d no. of request queues:%d.\n",
482 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700483 }
484 return 0;
485fail2:
486 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700487 destroy_workqueue(ha->wq);
488 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800489 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700490fail:
491 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700492 kfree(ha->req_q_map);
493 kfree(ha->rsp_q_map);
494 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700495 return 1;
496}
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 static char *pci_bus_modes[] = {
503 "33", "66", "100", "133",
504 };
505 uint16_t pci_bus;
506
507 strcpy(str, "PCI");
508 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
509 if (pci_bus) {
510 strcat(str, "-X (");
511 strcat(str, pci_bus_modes[pci_bus]);
512 } else {
513 pci_bus = (ha->pci_attr & BIT_8) >> 8;
514 strcat(str, " (");
515 strcat(str, pci_bus_modes[pci_bus]);
516 }
517 strcat(str, " MHz)");
518
519 return (str);
520}
521
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700524{
525 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700527 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700528
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600529 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700530 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600531 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700532
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600533 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
534 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
535 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700536
537 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500538 switch (lspeed) {
539 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700540 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500541 break;
542 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700543 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500544 break;
545 case 3:
546 strcat(str, "8.0GT/s ");
547 break;
548 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700549 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500550 break;
551 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700552 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
553 strcat(str, lwstr);
554
555 return str;
556 }
557
558 strcpy(str, "PCI");
559 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
560 if (pci_bus == 0 || pci_bus == 8) {
561 strcat(str, " (");
562 strcat(str, pci_bus_modes[pci_bus >> 3]);
563 } else {
564 strcat(str, "-X ");
565 if (pci_bus & BIT_2)
566 strcat(str, "Mode 2");
567 else
568 strcat(str, "Mode 1");
569 strcat(str, " (");
570 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
571 }
572 strcat(str, " MHz)");
573
574 return str;
575}
576
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800577static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400578qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
580 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800581 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700582
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400583 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
584 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 if (ha->fw_attributes & BIT_9) {
587 strcat(str, "FLX");
588 return (str);
589 }
590
591 switch (ha->fw_attributes & 0xFF) {
592 case 0x7:
593 strcat(str, "EF");
594 break;
595 case 0x17:
596 strcat(str, "TP");
597 break;
598 case 0x37:
599 strcat(str, "IP");
600 break;
601 case 0x77:
602 strcat(str, "VI");
603 break;
604 default:
605 sprintf(un_str, "(%x)", ha->fw_attributes);
606 strcat(str, un_str);
607 break;
608 }
609 if (ha->fw_attributes & 0x100)
610 strcat(str, "X");
611
612 return (str);
613}
614
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800615static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400616qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700617{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800618 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700619
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400620 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800621 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700622 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700623}
624
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800625void
626qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700627{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800628 srb_t *sp = (srb_t *)ptr;
629 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
630 struct qla_hw_data *ha = sp->fcport->vha->hw;
631 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700632
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800633 if (sp->flags & SRB_DMA_VALID) {
634 scsi_dma_unmap(cmd);
635 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700636 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700637
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800638 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
639 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
640 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
641 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
642 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700643
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800644 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
645 /* List assured to be having elements */
Quinn Tranf83adb62014-04-11 16:54:43 -0400646 qla2x00_clean_dsd_pool(ha, sp, NULL);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800647 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
648 }
649
650 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
651 dma_pool_free(ha->dl_dma_pool, ctx,
652 ((struct crc_context *)ctx)->crc_ctx_dma);
653 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
654 }
655
656 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
657 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
658
659 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
660 ctx1->fcp_cmnd_dma);
661 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
662 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
663 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
664 mempool_free(ctx1, ha->ctx_mempool);
665 ctx1 = NULL;
666 }
667
668 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500669 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800670}
671
Fengguang Wu14b06802013-04-25 01:29:19 -0400672static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800673qla2x00_sp_compl(void *data, void *ptr, int res)
674{
675 struct qla_hw_data *ha = (struct qla_hw_data *)data;
676 srb_t *sp = (srb_t *)ptr;
677 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
678
679 cmd->result = res;
680
681 if (atomic_read(&sp->ref_count) == 0) {
682 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
683 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
684 sp, GET_CMD_SP(sp));
685 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400686 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800687 return;
688 }
689 if (!atomic_dec_and_test(&sp->ref_count))
690 return;
691
692 qla2x00_sp_free_dma(ha, sp);
693 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700694}
695
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400696/* If we are SP1 here, we need to still take and release the host_lock as SP1
697 * does not have the changes necessary to avoid taking host->host_lock.
698 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800700qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700701{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700702 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700703 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400704 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705 struct qla_hw_data *ha = vha->hw;
706 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700707 srb_t *sp;
708 int rval;
709
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200710 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
711 cmd->result = DID_NO_CONNECT << 16;
712 goto qc24_fail_command;
713 }
714
Andrew Vasquez85880802009-12-15 21:29:46 -0800715 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700716 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400717 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700718 "PCI Channel IO permanent failure, exiting "
719 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700720 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700721 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400722 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700723 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800724 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700725 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700726 goto qc24_fail_command;
727 }
728
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400729 rval = fc_remote_port_chkready(rport);
730 if (rval) {
731 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400732 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700733 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
734 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700735 goto qc24_fail_command;
736 }
737
Arun Easibad75002010-05-04 15:01:30 -0700738 if (!vha->flags.difdix_supported &&
739 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700740 ql_dbg(ql_dbg_io, vha, 0x3004,
741 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
742 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700743 cmd->result = DID_NO_CONNECT << 16;
744 goto qc24_fail_command;
745 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800746
747 if (!fcport) {
748 cmd->result = DID_NO_CONNECT << 16;
749 goto qc24_fail_command;
750 }
751
Andrew Vasquezfca29702005-07-06 10:31:47 -0700752 if (atomic_read(&fcport->state) != FCS_ONLINE) {
753 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700754 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700755 ql_dbg(ql_dbg_io, vha, 0x3005,
756 "Returning DNC, fcport_state=%d loop_state=%d.\n",
757 atomic_read(&fcport->state),
758 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700759 cmd->result = DID_NO_CONNECT << 16;
760 goto qc24_fail_command;
761 }
Mike Christie7b594132008-08-17 15:24:40 -0500762 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700763 }
764
Chad Dupuise05fe292014-09-25 05:16:59 -0400765 /*
766 * Return target busy if we've received a non-zero retry_delay_timer
767 * in a FCP_RSP.
768 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100769 if (fcport->retry_delay_timestamp == 0) {
770 /* retry delay not set */
771 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400772 fcport->retry_delay_timestamp = 0;
773 else
774 goto qc24_target_busy;
775
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500776 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400777 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800778 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700779
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800780 sp->u.scmd.cmd = cmd;
781 sp->type = SRB_SCSI_CMD;
782 atomic_set(&sp->ref_count, 1);
783 CMD_SP(cmd) = (void *)sp;
784 sp->free = qla2x00_sp_free_dma;
785 sp->done = qla2x00_sp_compl;
786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800787 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700788 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500789 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700790 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700791 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700792 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700793
Andrew Vasquezfca29702005-07-06 10:31:47 -0700794 return 0;
795
796qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800797 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700798
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800799qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700800 return SCSI_MLQUEUE_HOST_BUSY;
801
Mike Christie7b594132008-08-17 15:24:40 -0500802qc24_target_busy:
803 return SCSI_MLQUEUE_TARGET_BUSY;
804
Andrew Vasquezfca29702005-07-06 10:31:47 -0700805qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800806 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700807
808 return 0;
809}
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811/*
812 * qla2x00_eh_wait_on_command
813 * Waits for the command to be returned by the Firmware for some
814 * max time.
815 *
816 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 *
819 * Return:
820 * Not Found : 0
821 * Found : 1
822 */
823static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800824qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700826#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -0400827#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500828 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800829 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
830 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500831 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Andrew Vasquez85880802009-12-15 21:29:46 -0800833 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700834 ql_dbg(ql_dbg_taskm, vha, 0x8005,
835 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800836 return ret;
837 }
838
Lalit Chandivaded9704322009-08-25 11:36:18 -0700839 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700840 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500841 }
842 if (CMD_SP(cmd))
843 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
f4f051e2005-04-17 15:02:26 -0500845 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
848/*
849 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700850 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 * <= MAX_RETRIES_OF_ISP_ABORT or
852 * finally HBA is disabled ie marked offline
853 *
854 * Input:
855 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700856 *
857 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 * Does context switching-Release SPIN_LOCK
859 * (if any) before calling this routine.
860 *
861 * Return:
862 * Success (Adapter is online) : 0
863 * Failed (Adapter is offline/disabled) : 1
864 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800865int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800866qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700868 int return_status;
869 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800870 struct qla_hw_data *ha = vha->hw;
871 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700873 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800874 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
875 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
876 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
877 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 msleep(1000);
880 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800881 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700882 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 else
884 return_status = QLA_FUNCTION_FAILED;
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 return (return_status);
887}
888
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700889/*
Sawan Chandak638a1a02014-04-11 16:54:38 -0400890 * qla2x00_wait_for_hba_ready
891 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700892 *
893 * Input:
894 * ha - pointer to host adapter structure
895 *
896 * Note:
897 * Does context switching-Release SPIN_LOCK
898 * (if any) before calling this routine.
899 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700900 */
Sawan Chandak638a1a02014-04-11 16:54:38 -0400901static void
902qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700903{
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700904 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400905 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700906
Dan Carpenter1d483902016-08-03 21:42:32 +0300907 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
908 ha->flags.mbox_busy) ||
909 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
910 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
911 if (test_bit(UNLOADING, &base_vha->dpc_flags))
912 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700913 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400914 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700915}
916
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700917int
918qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
919{
920 int return_status;
921 unsigned long wait_reset;
922 struct qla_hw_data *ha = vha->hw;
923 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
924
925 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
926 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
927 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
928 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
929 ha->dpc_active) && time_before(jiffies, wait_reset)) {
930
931 msleep(1000);
932
933 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
934 ha->flags.chip_reset_done)
935 break;
936 }
937 if (ha->flags.chip_reset_done)
938 return_status = QLA_SUCCESS;
939 else
940 return_status = QLA_FUNCTION_FAILED;
941
942 return return_status;
943}
944
Giridhar Malavali083a4692010-05-28 15:08:18 -0700945static void
946sp_get(struct srb *sp)
947{
948 atomic_inc(&sp->ref_count);
949}
950
Sawan Chandaka4655372016-07-06 11:14:32 -0400951#define ISP_REG_DISCONNECT 0xffffffffU
952/**************************************************************************
953* qla2x00_isp_reg_stat
954*
955* Description:
956* Read the host status register of ISP before aborting the command.
957*
958* Input:
959* ha = pointer to host adapter structure.
960*
961*
962* Returns:
963* Either true or false.
964*
965* Note: Return true if there is register disconnect.
966**************************************************************************/
967static inline
968uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
969{
970 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
971
972 return ((RD_REG_DWORD(&reg->host_status)) == ISP_REG_DISCONNECT);
973}
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975/**************************************************************************
976* qla2xxx_eh_abort
977*
978* Description:
979* The abort function will abort the specified command.
980*
981* Input:
982* cmd = Linux SCSI command packet to be aborted.
983*
984* Returns:
985* Either SUCCESS or FAILED.
986*
987* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700988* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800990static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991qla2xxx_eh_abort(struct scsi_cmnd *cmd)
992{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800993 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500994 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800995 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200996 unsigned int id;
997 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700998 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400999 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001000 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Sawan Chandaka4655372016-07-06 11:14:32 -04001002 if (qla2x00_isp_reg_stat(ha)) {
1003 ql_log(ql_log_info, vha, 0x8042,
1004 "PCI/Register disconnect, exiting.\n");
1005 return FAILED;
1006 }
f4f051e2005-04-17 15:02:26 -05001007 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001008 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001010 ret = fc_block_scsi_eh(cmd);
1011 if (ret != 0)
1012 return ret;
1013 ret = SUCCESS;
1014
f4f051e2005-04-17 15:02:26 -05001015 id = cmd->device->id;
1016 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001019 sp = (srb_t *) CMD_SP(cmd);
1020 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001021 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001022 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001023 }
Mike Christie170babc2010-10-15 11:27:47 -07001024
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001025 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001026 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1027 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001028
1029 /* Get a reference to the sp and drop the lock.*/
1030 sp_get(sp);
1031
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001033 rval = ha->isp_ops->abort_command(sp);
1034 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001035 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001036 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001037 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001038 ret = FAILED;
1039
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001040 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001041 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001042 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001043 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001044 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001045 wait = 1;
1046 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001047
1048 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001049 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001051
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001052 /* Did the command return during mailbox execution? */
1053 if (ret == FAILED && !CMD_SP(cmd))
1054 ret = SUCCESS;
1055
f4f051e2005-04-17 15:02:26 -05001056 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001057 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001058 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001059 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001060 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001061 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001065 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001066 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001067 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
f4f051e2005-04-17 15:02:26 -05001069 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001072int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001074 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001076 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001077 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001079 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001080 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001081 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Andrew Vasquez523ec772008-04-03 13:13:24 -07001083 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001084
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001086 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001087 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001088 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001089 sp = req->outstanding_cmds[cnt];
1090 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001091 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001092 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001093 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001094 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1095 continue;
1096 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001097 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001098 switch (type) {
1099 case WAIT_HOST:
1100 match = 1;
1101 break;
1102 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001103 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001104 break;
1105 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001106 match = (cmd->device->id == t &&
1107 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001108 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001110 if (!match)
1111 continue;
1112
1113 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001114 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001115 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001117 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001118
1119 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andrew Vasquez523ec772008-04-03 13:13:24 -07001122static char *reset_errors[] = {
1123 "HBA not online",
1124 "HBA not ready",
1125 "Task management failed",
1126 "Waiting for command completions",
1127};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Andrew Vasquez523ec772008-04-03 13:13:24 -07001129static int
1130__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001131 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001132{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001134 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1135 int err;
1136
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001137 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001138 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001139 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001140
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001141 err = fc_block_scsi_eh(cmd);
1142 if (err != 0)
1143 return err;
1144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001146 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001147 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001148
1149 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001150 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1151 ql_log(ql_log_warn, vha, 0x800a,
1152 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001153 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001154 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001155 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001156 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001157 != QLA_SUCCESS) {
1158 ql_log(ql_log_warn, vha, 0x800c,
1159 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001160 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001161 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001162 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001164 cmd->device->lun, type) != QLA_SUCCESS) {
1165 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001166 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001167 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001168 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001169
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001170 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001171 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001172 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001173
1174 return SUCCESS;
1175
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001176eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001178 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001179 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1180 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001181 return FAILED;
1182}
1183
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001184static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1186{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001187 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1188 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Sawan Chandaka4655372016-07-06 11:14:32 -04001190 if (qla2x00_isp_reg_stat(ha)) {
1191 ql_log(ql_log_info, vha, 0x803e,
1192 "PCI/Register disconnect, exiting.\n");
1193 return FAILED;
1194 }
1195
Andrew Vasquez523ec772008-04-03 13:13:24 -07001196 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1197 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001201qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001203 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1204 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Sawan Chandaka4655372016-07-06 11:14:32 -04001206 if (qla2x00_isp_reg_stat(ha)) {
1207 ql_log(ql_log_info, vha, 0x803f,
1208 "PCI/Register disconnect, exiting.\n");
1209 return FAILED;
1210 }
1211
Andrew Vasquez523ec772008-04-03 13:13:24 -07001212 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1213 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216/**************************************************************************
1217* qla2xxx_eh_bus_reset
1218*
1219* Description:
1220* The bus reset function will reset the bus and abort any executing
1221* commands.
1222*
1223* Input:
1224* cmd = Linux SCSI command packet of the command that cause the
1225* bus reset.
1226*
1227* Returns:
1228* SUCCESS/FAILURE (defined as macro in scsi.h).
1229*
1230**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001231static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1233{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001234 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001235 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001236 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001237 unsigned int id;
1238 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001239 struct qla_hw_data *ha = vha->hw;
1240
1241 if (qla2x00_isp_reg_stat(ha)) {
1242 ql_log(ql_log_info, vha, 0x8040,
1243 "PCI/Register disconnect, exiting.\n");
1244 return FAILED;
1245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
f4f051e2005-04-17 15:02:26 -05001247 id = cmd->device->id;
1248 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001249
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001250 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001251 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001254 ret = fc_block_scsi_eh(cmd);
1255 if (ret != 0)
1256 return ret;
1257 ret = FAILED;
1258
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001259 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001260 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001262 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001263 ql_log(ql_log_fatal, vha, 0x8013,
1264 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001265 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
1267
Saurav Kashyapad5376892011-11-18 09:02:09 -08001268 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1269 ret = SUCCESS;
1270
f4f051e2005-04-17 15:02:26 -05001271 if (ret == FAILED)
1272 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001274 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001275 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001276 QLA_SUCCESS) {
1277 ql_log(ql_log_warn, vha, 0x8014,
1278 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001279 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
f4f051e2005-04-17 15:02:26 -05001282eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001283 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001284 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001285 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
f4f051e2005-04-17 15:02:26 -05001287 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
1290/**************************************************************************
1291* qla2xxx_eh_host_reset
1292*
1293* Description:
1294* The reset function will reset the Adapter.
1295*
1296* Input:
1297* cmd = Linux SCSI command packet of the command that cause the
1298* adapter reset.
1299*
1300* Returns:
1301* Either SUCCESS or FAILED.
1302*
1303* Note:
1304**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001305static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1307{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001309 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001310 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001311 unsigned int id;
1312 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Sawan Chandaka4655372016-07-06 11:14:32 -04001315 if (qla2x00_isp_reg_stat(ha)) {
1316 ql_log(ql_log_info, vha, 0x8041,
1317 "PCI/Register disconnect, exiting.\n");
1318 schedule_work(&ha->board_disable);
1319 return SUCCESS;
1320 }
1321
f4f051e2005-04-17 15:02:26 -05001322 id = cmd->device->id;
1323 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001324
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001326 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Chad Dupuis63ee7072014-04-11 16:54:46 -04001328 /*
1329 * No point in issuing another reset if one is active. Also do not
1330 * attempt a reset if we are updating flash.
1331 */
1332 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001333 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335 if (vha != base_vha) {
1336 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001337 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001338 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001339 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001340 if (!qla82xx_fcoe_ctx_reset(vha)) {
1341 /* Ctx reset success */
1342 ret = SUCCESS;
1343 goto eh_host_reset_lock;
1344 }
1345 /* fall thru if ctx reset failed */
1346 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001347 if (ha->wq)
1348 flush_workqueue(ha->wq);
1349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001350 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001351 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1353 /* failed. schedule dpc to try */
1354 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1355
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001356 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1357 ql_log(ql_log_warn, vha, 0x802a,
1358 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001360 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001361 }
1362 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001366 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001367 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001368 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
f4f051e2005-04-17 15:02:26 -05001370eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001371 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001372 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001373 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
f4f051e2005-04-17 15:02:26 -05001375 return ret;
1376}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378/*
1379* qla2x00_loop_reset
1380* Issue loop reset.
1381*
1382* Input:
1383* ha = adapter block pointer.
1384*
1385* Returns:
1386* 0 = success
1387*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001388int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001389qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001391 int ret;
bdf79622005-04-17 15:06:53 -05001392 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001393 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Armen Baloyan58547712013-08-27 01:37:33 -04001395 if (IS_QLAFX00(ha)) {
1396 return qlafx00_loop_reset(vha);
1397 }
1398
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001399 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001400 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1401 if (fcport->port_type != FCT_TARGET)
1402 continue;
1403
1404 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1405 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001406 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001407 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001408 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001409 }
1410 }
1411 }
1412
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001413
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001414 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001415 atomic_set(&vha->loop_state, LOOP_DOWN);
1416 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1417 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001418 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001419 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001420 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1421 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
1424
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001425 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001426 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001427 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001428 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1429 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001430 }
1431
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001433 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001435 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001438void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001439qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001440{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001441 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001442 unsigned long flags;
1443 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001445 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001446
Arun Easic0cb4492014-09-25 06:14:51 -04001447 qlt_host_reset_handler(ha);
1448
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001449 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001450 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001451 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001452 if (!req)
1453 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001454 if (!req->outstanding_cmds)
1455 continue;
1456 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001457 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001458 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001459 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001460 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001461 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001462 }
1463 }
1464 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1465}
1466
f4f051e2005-04-17 15:02:26 -05001467static int
1468qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
bdf79622005-04-17 15:06:53 -05001470 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001472 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001473 return -ENXIO;
1474
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001475 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001476
1477 return 0;
1478}
1479
1480static int
1481qla2xxx_slave_configure(struct scsi_device *sdev)
1482{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001484 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001485
Arun Easi9e522cd2012-08-22 14:21:31 -04001486 if (IS_T10_PI_CAPABLE(vha->hw))
1487 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1488
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001489 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001490 return 0;
1491}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
f4f051e2005-04-17 15:02:26 -05001493static void
1494qla2xxx_slave_destroy(struct scsi_device *sdev)
1495{
1496 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
1499/**
1500 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1501 * @ha: HA context
1502 *
1503 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1504 * supported addressing method.
1505 */
1506static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001507qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001509 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Yang Hongyang6a355282009-04-06 19:01:13 -07001512 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001513 /* Any upper-dword bits set? */
1514 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001515 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001516 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001518 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1519 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001520 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001523
Yang Hongyang284901a2009-04-06 19:01:15 -07001524 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1525 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001528static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001530{
1531 unsigned long flags = 0;
1532 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1533
1534 spin_lock_irqsave(&ha->hardware_lock, flags);
1535 ha->interrupts_on = 1;
1536 /* enable risc and host interrupts */
1537 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1538 RD_REG_WORD(&reg->ictrl);
1539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1540
1541}
1542
1543static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001545{
1546 unsigned long flags = 0;
1547 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1548
1549 spin_lock_irqsave(&ha->hardware_lock, flags);
1550 ha->interrupts_on = 0;
1551 /* disable risc and host interrupts */
1552 WRT_REG_WORD(&reg->ictrl, 0);
1553 RD_REG_WORD(&reg->ictrl);
1554 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1555}
1556
1557static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001559{
1560 unsigned long flags = 0;
1561 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1562
1563 spin_lock_irqsave(&ha->hardware_lock, flags);
1564 ha->interrupts_on = 1;
1565 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1566 RD_REG_DWORD(&reg->ictrl);
1567 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1568}
1569
1570static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001571qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001572{
1573 unsigned long flags = 0;
1574 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1575
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001576 if (IS_NOPOLLING_TYPE(ha))
1577 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001578 spin_lock_irqsave(&ha->hardware_lock, flags);
1579 ha->interrupts_on = 0;
1580 WRT_REG_DWORD(&reg->ictrl, 0);
1581 RD_REG_DWORD(&reg->ictrl);
1582 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1583}
1584
Giridhar Malavali706f4572011-11-18 09:03:16 -08001585static int
1586qla2x00_iospace_config(struct qla_hw_data *ha)
1587{
1588 resource_size_t pio;
1589 uint16_t msix;
1590 int cpus;
1591
Giridhar Malavali706f4572011-11-18 09:03:16 -08001592 if (pci_request_selected_regions(ha->pdev, ha->bars,
1593 QLA2XXX_DRIVER_NAME)) {
1594 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1595 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1596 pci_name(ha->pdev));
1597 goto iospace_error_exit;
1598 }
1599 if (!(ha->bars & 1))
1600 goto skip_pio;
1601
1602 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1603 pio = pci_resource_start(ha->pdev, 0);
1604 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1605 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1606 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1607 "Invalid pci I/O region size (%s).\n",
1608 pci_name(ha->pdev));
1609 pio = 0;
1610 }
1611 } else {
1612 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1613 "Region #0 no a PIO resource (%s).\n",
1614 pci_name(ha->pdev));
1615 pio = 0;
1616 }
1617 ha->pio_address = pio;
1618 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1619 "PIO address=%llu.\n",
1620 (unsigned long long)ha->pio_address);
1621
1622skip_pio:
1623 /* Use MMIO operations for all accesses. */
1624 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1625 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1626 "Region #1 not an MMIO resource (%s), aborting.\n",
1627 pci_name(ha->pdev));
1628 goto iospace_error_exit;
1629 }
1630 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1631 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1632 "Invalid PCI mem region size (%s), aborting.\n",
1633 pci_name(ha->pdev));
1634 goto iospace_error_exit;
1635 }
1636
1637 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1638 if (!ha->iobase) {
1639 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1640 "Cannot remap MMIO (%s), aborting.\n",
1641 pci_name(ha->pdev));
1642 goto iospace_error_exit;
1643 }
1644
1645 /* Determine queue resources */
1646 ha->max_req_queues = ha->max_rsp_queues = 1;
1647 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1648 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1649 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1650 goto mqiobase_exit;
1651
1652 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1653 pci_resource_len(ha->pdev, 3));
1654 if (ha->mqiobase) {
1655 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1656 "MQIO Base=%p.\n", ha->mqiobase);
1657 /* Read MSIX vector size of the board */
1658 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1659 ha->msix_count = msix;
1660 /* Max queues are bounded by available msix vectors */
1661 /* queue 0 uses two msix vectors */
1662 if (ql2xmultique_tag) {
1663 cpus = num_online_cpus();
1664 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1665 (cpus + 1) : (ha->msix_count - 1);
1666 ha->max_req_queues = 2;
1667 } else if (ql2xmaxqueues > 1) {
1668 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1669 QLA_MQ_SIZE : ql2xmaxqueues;
1670 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1671 "QoS mode set, max no of request queues:%d.\n",
1672 ha->max_req_queues);
1673 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1674 "QoS mode set, max no of request queues:%d.\n",
1675 ha->max_req_queues);
1676 }
1677 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1678 "MSI-X vector count: %d.\n", msix);
1679 } else
1680 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1681 "BAR 3 not enabled.\n");
1682
1683mqiobase_exit:
1684 ha->msix_count = ha->max_rsp_queues + 1;
1685 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1686 "MSIX Count:%d.\n", ha->msix_count);
1687 return (0);
1688
1689iospace_error_exit:
1690 return (-ENOMEM);
1691}
1692
1693
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001694static int
1695qla83xx_iospace_config(struct qla_hw_data *ha)
1696{
1697 uint16_t msix;
1698 int cpus;
1699
1700 if (pci_request_selected_regions(ha->pdev, ha->bars,
1701 QLA2XXX_DRIVER_NAME)) {
1702 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1703 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1704 pci_name(ha->pdev));
1705
1706 goto iospace_error_exit;
1707 }
1708
1709 /* Use MMIO operations for all accesses. */
1710 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1711 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1712 "Invalid pci I/O region size (%s).\n",
1713 pci_name(ha->pdev));
1714 goto iospace_error_exit;
1715 }
1716 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1717 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1718 "Invalid PCI mem region size (%s), aborting\n",
1719 pci_name(ha->pdev));
1720 goto iospace_error_exit;
1721 }
1722
1723 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1724 if (!ha->iobase) {
1725 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1726 "Cannot remap MMIO (%s), aborting.\n",
1727 pci_name(ha->pdev));
1728 goto iospace_error_exit;
1729 }
1730
1731 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1732 /* 83XX 26XX always use MQ type access for queues
1733 * - mbar 2, a.k.a region 4 */
1734 ha->max_req_queues = ha->max_rsp_queues = 1;
1735 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1736 pci_resource_len(ha->pdev, 4));
1737
1738 if (!ha->mqiobase) {
1739 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1740 "BAR2/region4 not enabled\n");
1741 goto mqiobase_exit;
1742 }
1743
1744 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1745 pci_resource_len(ha->pdev, 2));
1746 if (ha->msixbase) {
1747 /* Read MSIX vector size of the board */
1748 pci_read_config_word(ha->pdev,
1749 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1750 ha->msix_count = msix;
1751 /* Max queues are bounded by available msix vectors */
1752 /* queue 0 uses two msix vectors */
1753 if (ql2xmultique_tag) {
1754 cpus = num_online_cpus();
1755 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1756 (cpus + 1) : (ha->msix_count - 1);
1757 ha->max_req_queues = 2;
1758 } else if (ql2xmaxqueues > 1) {
1759 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1760 QLA_MQ_SIZE : ql2xmaxqueues;
1761 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1762 "QoS mode set, max no of request queues:%d.\n",
1763 ha->max_req_queues);
1764 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1765 "QoS mode set, max no of request queues:%d.\n",
1766 ha->max_req_queues);
1767 }
1768 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1769 "MSI-X vector count: %d.\n", msix);
1770 } else
1771 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1772 "BAR 1 not enabled.\n");
1773
1774mqiobase_exit:
1775 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001776
1777 qlt_83xx_iospace_config(ha);
1778
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001779 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1780 "MSIX Count:%d.\n", ha->msix_count);
1781 return 0;
1782
1783iospace_error_exit:
1784 return -ENOMEM;
1785}
1786
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001787static struct isp_operations qla2100_isp_ops = {
1788 .pci_config = qla2100_pci_config,
1789 .reset_chip = qla2x00_reset_chip,
1790 .chip_diag = qla2x00_chip_diag,
1791 .config_rings = qla2x00_config_rings,
1792 .reset_adapter = qla2x00_reset_adapter,
1793 .nvram_config = qla2x00_nvram_config,
1794 .update_fw_options = qla2x00_update_fw_options,
1795 .load_risc = qla2x00_load_risc,
1796 .pci_info_str = qla2x00_pci_info_str,
1797 .fw_version_str = qla2x00_fw_version_str,
1798 .intr_handler = qla2100_intr_handler,
1799 .enable_intrs = qla2x00_enable_intrs,
1800 .disable_intrs = qla2x00_disable_intrs,
1801 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001802 .target_reset = qla2x00_abort_target,
1803 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001804 .fabric_login = qla2x00_login_fabric,
1805 .fabric_logout = qla2x00_fabric_logout,
1806 .calc_req_entries = qla2x00_calc_iocbs_32,
1807 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1808 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1809 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1810 .read_nvram = qla2x00_read_nvram_data,
1811 .write_nvram = qla2x00_write_nvram_data,
1812 .fw_dump = qla2100_fw_dump,
1813 .beacon_on = NULL,
1814 .beacon_off = NULL,
1815 .beacon_blink = NULL,
1816 .read_optrom = qla2x00_read_optrom_data,
1817 .write_optrom = qla2x00_write_optrom_data,
1818 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001819 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001820 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001821 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001822 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001823};
1824
1825static struct isp_operations qla2300_isp_ops = {
1826 .pci_config = qla2300_pci_config,
1827 .reset_chip = qla2x00_reset_chip,
1828 .chip_diag = qla2x00_chip_diag,
1829 .config_rings = qla2x00_config_rings,
1830 .reset_adapter = qla2x00_reset_adapter,
1831 .nvram_config = qla2x00_nvram_config,
1832 .update_fw_options = qla2x00_update_fw_options,
1833 .load_risc = qla2x00_load_risc,
1834 .pci_info_str = qla2x00_pci_info_str,
1835 .fw_version_str = qla2x00_fw_version_str,
1836 .intr_handler = qla2300_intr_handler,
1837 .enable_intrs = qla2x00_enable_intrs,
1838 .disable_intrs = qla2x00_disable_intrs,
1839 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001840 .target_reset = qla2x00_abort_target,
1841 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001842 .fabric_login = qla2x00_login_fabric,
1843 .fabric_logout = qla2x00_fabric_logout,
1844 .calc_req_entries = qla2x00_calc_iocbs_32,
1845 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1846 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1847 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1848 .read_nvram = qla2x00_read_nvram_data,
1849 .write_nvram = qla2x00_write_nvram_data,
1850 .fw_dump = qla2300_fw_dump,
1851 .beacon_on = qla2x00_beacon_on,
1852 .beacon_off = qla2x00_beacon_off,
1853 .beacon_blink = qla2x00_beacon_blink,
1854 .read_optrom = qla2x00_read_optrom_data,
1855 .write_optrom = qla2x00_write_optrom_data,
1856 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001858 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001859 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001860 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001861};
1862
1863static struct isp_operations qla24xx_isp_ops = {
1864 .pci_config = qla24xx_pci_config,
1865 .reset_chip = qla24xx_reset_chip,
1866 .chip_diag = qla24xx_chip_diag,
1867 .config_rings = qla24xx_config_rings,
1868 .reset_adapter = qla24xx_reset_adapter,
1869 .nvram_config = qla24xx_nvram_config,
1870 .update_fw_options = qla24xx_update_fw_options,
1871 .load_risc = qla24xx_load_risc,
1872 .pci_info_str = qla24xx_pci_info_str,
1873 .fw_version_str = qla24xx_fw_version_str,
1874 .intr_handler = qla24xx_intr_handler,
1875 .enable_intrs = qla24xx_enable_intrs,
1876 .disable_intrs = qla24xx_disable_intrs,
1877 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001878 .target_reset = qla24xx_abort_target,
1879 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001880 .fabric_login = qla24xx_login_fabric,
1881 .fabric_logout = qla24xx_fabric_logout,
1882 .calc_req_entries = NULL,
1883 .build_iocbs = NULL,
1884 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1885 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1886 .read_nvram = qla24xx_read_nvram_data,
1887 .write_nvram = qla24xx_write_nvram_data,
1888 .fw_dump = qla24xx_fw_dump,
1889 .beacon_on = qla24xx_beacon_on,
1890 .beacon_off = qla24xx_beacon_off,
1891 .beacon_blink = qla24xx_beacon_blink,
1892 .read_optrom = qla24xx_read_optrom_data,
1893 .write_optrom = qla24xx_write_optrom_data,
1894 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001896 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001897 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001898 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001899};
1900
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001901static struct isp_operations qla25xx_isp_ops = {
1902 .pci_config = qla25xx_pci_config,
1903 .reset_chip = qla24xx_reset_chip,
1904 .chip_diag = qla24xx_chip_diag,
1905 .config_rings = qla24xx_config_rings,
1906 .reset_adapter = qla24xx_reset_adapter,
1907 .nvram_config = qla24xx_nvram_config,
1908 .update_fw_options = qla24xx_update_fw_options,
1909 .load_risc = qla24xx_load_risc,
1910 .pci_info_str = qla24xx_pci_info_str,
1911 .fw_version_str = qla24xx_fw_version_str,
1912 .intr_handler = qla24xx_intr_handler,
1913 .enable_intrs = qla24xx_enable_intrs,
1914 .disable_intrs = qla24xx_disable_intrs,
1915 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001916 .target_reset = qla24xx_abort_target,
1917 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001918 .fabric_login = qla24xx_login_fabric,
1919 .fabric_logout = qla24xx_fabric_logout,
1920 .calc_req_entries = NULL,
1921 .build_iocbs = NULL,
1922 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1923 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1924 .read_nvram = qla25xx_read_nvram_data,
1925 .write_nvram = qla25xx_write_nvram_data,
1926 .fw_dump = qla25xx_fw_dump,
1927 .beacon_on = qla24xx_beacon_on,
1928 .beacon_off = qla24xx_beacon_off,
1929 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001930 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001931 .write_optrom = qla24xx_write_optrom_data,
1932 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001933 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001934 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001935 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001936 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001937};
1938
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001939static struct isp_operations qla81xx_isp_ops = {
1940 .pci_config = qla25xx_pci_config,
1941 .reset_chip = qla24xx_reset_chip,
1942 .chip_diag = qla24xx_chip_diag,
1943 .config_rings = qla24xx_config_rings,
1944 .reset_adapter = qla24xx_reset_adapter,
1945 .nvram_config = qla81xx_nvram_config,
1946 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001947 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001948 .pci_info_str = qla24xx_pci_info_str,
1949 .fw_version_str = qla24xx_fw_version_str,
1950 .intr_handler = qla24xx_intr_handler,
1951 .enable_intrs = qla24xx_enable_intrs,
1952 .disable_intrs = qla24xx_disable_intrs,
1953 .abort_command = qla24xx_abort_command,
1954 .target_reset = qla24xx_abort_target,
1955 .lun_reset = qla24xx_lun_reset,
1956 .fabric_login = qla24xx_login_fabric,
1957 .fabric_logout = qla24xx_fabric_logout,
1958 .calc_req_entries = NULL,
1959 .build_iocbs = NULL,
1960 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1961 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001962 .read_nvram = NULL,
1963 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001964 .fw_dump = qla81xx_fw_dump,
1965 .beacon_on = qla24xx_beacon_on,
1966 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001967 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001968 .read_optrom = qla25xx_read_optrom_data,
1969 .write_optrom = qla24xx_write_optrom_data,
1970 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001971 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001972 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001973 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001974 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001975};
1976
1977static struct isp_operations qla82xx_isp_ops = {
1978 .pci_config = qla82xx_pci_config,
1979 .reset_chip = qla82xx_reset_chip,
1980 .chip_diag = qla24xx_chip_diag,
1981 .config_rings = qla82xx_config_rings,
1982 .reset_adapter = qla24xx_reset_adapter,
1983 .nvram_config = qla81xx_nvram_config,
1984 .update_fw_options = qla24xx_update_fw_options,
1985 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001986 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001987 .fw_version_str = qla24xx_fw_version_str,
1988 .intr_handler = qla82xx_intr_handler,
1989 .enable_intrs = qla82xx_enable_intrs,
1990 .disable_intrs = qla82xx_disable_intrs,
1991 .abort_command = qla24xx_abort_command,
1992 .target_reset = qla24xx_abort_target,
1993 .lun_reset = qla24xx_lun_reset,
1994 .fabric_login = qla24xx_login_fabric,
1995 .fabric_logout = qla24xx_fabric_logout,
1996 .calc_req_entries = NULL,
1997 .build_iocbs = NULL,
1998 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1999 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2000 .read_nvram = qla24xx_read_nvram_data,
2001 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002002 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002003 .beacon_on = qla82xx_beacon_on,
2004 .beacon_off = qla82xx_beacon_off,
2005 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002006 .read_optrom = qla82xx_read_optrom_data,
2007 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002008 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002009 .start_scsi = qla82xx_start_scsi,
2010 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002011 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002012 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002013};
2014
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002015static struct isp_operations qla8044_isp_ops = {
2016 .pci_config = qla82xx_pci_config,
2017 .reset_chip = qla82xx_reset_chip,
2018 .chip_diag = qla24xx_chip_diag,
2019 .config_rings = qla82xx_config_rings,
2020 .reset_adapter = qla24xx_reset_adapter,
2021 .nvram_config = qla81xx_nvram_config,
2022 .update_fw_options = qla24xx_update_fw_options,
2023 .load_risc = qla82xx_load_risc,
2024 .pci_info_str = qla24xx_pci_info_str,
2025 .fw_version_str = qla24xx_fw_version_str,
2026 .intr_handler = qla8044_intr_handler,
2027 .enable_intrs = qla82xx_enable_intrs,
2028 .disable_intrs = qla82xx_disable_intrs,
2029 .abort_command = qla24xx_abort_command,
2030 .target_reset = qla24xx_abort_target,
2031 .lun_reset = qla24xx_lun_reset,
2032 .fabric_login = qla24xx_login_fabric,
2033 .fabric_logout = qla24xx_fabric_logout,
2034 .calc_req_entries = NULL,
2035 .build_iocbs = NULL,
2036 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2037 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2038 .read_nvram = NULL,
2039 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002040 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002041 .beacon_on = qla82xx_beacon_on,
2042 .beacon_off = qla82xx_beacon_off,
2043 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002044 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002045 .write_optrom = qla8044_write_optrom_data,
2046 .get_flash_version = qla82xx_get_flash_version,
2047 .start_scsi = qla82xx_start_scsi,
2048 .abort_isp = qla8044_abort_isp,
2049 .iospace_config = qla82xx_iospace_config,
2050 .initialize_adapter = qla2x00_initialize_adapter,
2051};
2052
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002053static struct isp_operations qla83xx_isp_ops = {
2054 .pci_config = qla25xx_pci_config,
2055 .reset_chip = qla24xx_reset_chip,
2056 .chip_diag = qla24xx_chip_diag,
2057 .config_rings = qla24xx_config_rings,
2058 .reset_adapter = qla24xx_reset_adapter,
2059 .nvram_config = qla81xx_nvram_config,
2060 .update_fw_options = qla81xx_update_fw_options,
2061 .load_risc = qla81xx_load_risc,
2062 .pci_info_str = qla24xx_pci_info_str,
2063 .fw_version_str = qla24xx_fw_version_str,
2064 .intr_handler = qla24xx_intr_handler,
2065 .enable_intrs = qla24xx_enable_intrs,
2066 .disable_intrs = qla24xx_disable_intrs,
2067 .abort_command = qla24xx_abort_command,
2068 .target_reset = qla24xx_abort_target,
2069 .lun_reset = qla24xx_lun_reset,
2070 .fabric_login = qla24xx_login_fabric,
2071 .fabric_logout = qla24xx_fabric_logout,
2072 .calc_req_entries = NULL,
2073 .build_iocbs = NULL,
2074 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2075 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2076 .read_nvram = NULL,
2077 .write_nvram = NULL,
2078 .fw_dump = qla83xx_fw_dump,
2079 .beacon_on = qla24xx_beacon_on,
2080 .beacon_off = qla24xx_beacon_off,
2081 .beacon_blink = qla83xx_beacon_blink,
2082 .read_optrom = qla25xx_read_optrom_data,
2083 .write_optrom = qla24xx_write_optrom_data,
2084 .get_flash_version = qla24xx_get_flash_version,
2085 .start_scsi = qla24xx_dif_start_scsi,
2086 .abort_isp = qla2x00_abort_isp,
2087 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002088 .initialize_adapter = qla2x00_initialize_adapter,
2089};
2090
2091static struct isp_operations qlafx00_isp_ops = {
2092 .pci_config = qlafx00_pci_config,
2093 .reset_chip = qlafx00_soft_reset,
2094 .chip_diag = qlafx00_chip_diag,
2095 .config_rings = qlafx00_config_rings,
2096 .reset_adapter = qlafx00_soft_reset,
2097 .nvram_config = NULL,
2098 .update_fw_options = NULL,
2099 .load_risc = NULL,
2100 .pci_info_str = qlafx00_pci_info_str,
2101 .fw_version_str = qlafx00_fw_version_str,
2102 .intr_handler = qlafx00_intr_handler,
2103 .enable_intrs = qlafx00_enable_intrs,
2104 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002105 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002106 .target_reset = qlafx00_abort_target,
2107 .lun_reset = qlafx00_lun_reset,
2108 .fabric_login = NULL,
2109 .fabric_logout = NULL,
2110 .calc_req_entries = NULL,
2111 .build_iocbs = NULL,
2112 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2113 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2114 .read_nvram = qla24xx_read_nvram_data,
2115 .write_nvram = qla24xx_write_nvram_data,
2116 .fw_dump = NULL,
2117 .beacon_on = qla24xx_beacon_on,
2118 .beacon_off = qla24xx_beacon_off,
2119 .beacon_blink = NULL,
2120 .read_optrom = qla24xx_read_optrom_data,
2121 .write_optrom = qla24xx_write_optrom_data,
2122 .get_flash_version = qla24xx_get_flash_version,
2123 .start_scsi = qlafx00_start_scsi,
2124 .abort_isp = qlafx00_abort_isp,
2125 .iospace_config = qlafx00_iospace_config,
2126 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002127};
2128
Chad Dupuisf73cb692014-02-26 04:15:06 -05002129static struct isp_operations qla27xx_isp_ops = {
2130 .pci_config = qla25xx_pci_config,
2131 .reset_chip = qla24xx_reset_chip,
2132 .chip_diag = qla24xx_chip_diag,
2133 .config_rings = qla24xx_config_rings,
2134 .reset_adapter = qla24xx_reset_adapter,
2135 .nvram_config = qla81xx_nvram_config,
2136 .update_fw_options = qla81xx_update_fw_options,
2137 .load_risc = qla81xx_load_risc,
2138 .pci_info_str = qla24xx_pci_info_str,
2139 .fw_version_str = qla24xx_fw_version_str,
2140 .intr_handler = qla24xx_intr_handler,
2141 .enable_intrs = qla24xx_enable_intrs,
2142 .disable_intrs = qla24xx_disable_intrs,
2143 .abort_command = qla24xx_abort_command,
2144 .target_reset = qla24xx_abort_target,
2145 .lun_reset = qla24xx_lun_reset,
2146 .fabric_login = qla24xx_login_fabric,
2147 .fabric_logout = qla24xx_fabric_logout,
2148 .calc_req_entries = NULL,
2149 .build_iocbs = NULL,
2150 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2151 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2152 .read_nvram = NULL,
2153 .write_nvram = NULL,
2154 .fw_dump = qla27xx_fwdump,
2155 .beacon_on = qla24xx_beacon_on,
2156 .beacon_off = qla24xx_beacon_off,
2157 .beacon_blink = qla83xx_beacon_blink,
2158 .read_optrom = qla25xx_read_optrom_data,
2159 .write_optrom = qla24xx_write_optrom_data,
2160 .get_flash_version = qla24xx_get_flash_version,
2161 .start_scsi = qla24xx_dif_start_scsi,
2162 .abort_isp = qla2x00_abort_isp,
2163 .iospace_config = qla83xx_iospace_config,
2164 .initialize_adapter = qla2x00_initialize_adapter,
2165};
2166
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002167static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002169{
2170 ha->device_type = DT_EXTENDED_IDS;
2171 switch (ha->pdev->device) {
2172 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002173 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002174 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002175 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002176 break;
2177 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002178 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002179 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002180 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002181 break;
2182 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002183 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002184 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002185 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002186 break;
2187 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002188 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002189 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002190 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002191 break;
2192 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002193 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002194 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002195 if (ha->pdev->subsystem_vendor == 0x1028 &&
2196 ha->pdev->subsystem_device == 0x0170)
2197 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002198 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002199 break;
2200 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002201 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002202 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002203 break;
2204 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002205 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002206 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002207 break;
2208 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002209 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002210 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002211 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002212 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002213 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002214 break;
2215 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002216 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002217 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002218 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002219 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002220 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002221 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002222 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002223 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002224 ha->device_type |= DT_ZIO_SUPPORTED;
2225 ha->device_type |= DT_FWI2;
2226 ha->device_type |= DT_IIDMA;
2227 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2228 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002229 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002230 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002231 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002232 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002233 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002234 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002235 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002236 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002237 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002238 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002239 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002240 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002241 ha->device_type |= DT_ZIO_SUPPORTED;
2242 ha->device_type |= DT_FWI2;
2243 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002244 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2245 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002246 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002247 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002248 ha->device_type |= DT_ZIO_SUPPORTED;
2249 ha->device_type |= DT_FWI2;
2250 ha->device_type |= DT_IIDMA;
2251 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2252 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002253 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002254 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002255 ha->device_type |= DT_ZIO_SUPPORTED;
2256 ha->device_type |= DT_FWI2;
2257 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2258 /* Initialize 82XX ISP flags */
2259 qla82xx_init_flags(ha);
2260 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002261 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002262 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002263 ha->device_type |= DT_ZIO_SUPPORTED;
2264 ha->device_type |= DT_FWI2;
2265 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2266 /* Initialize 82XX ISP flags */
2267 qla82xx_init_flags(ha);
2268 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002269 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002270 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002271 ha->device_type |= DT_ZIO_SUPPORTED;
2272 ha->device_type |= DT_FWI2;
2273 ha->device_type |= DT_IIDMA;
2274 ha->device_type |= DT_T10_PI;
2275 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2276 break;
2277 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002278 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002279 ha->device_type |= DT_ZIO_SUPPORTED;
2280 ha->device_type |= DT_FWI2;
2281 ha->device_type |= DT_IIDMA;
2282 ha->device_type |= DT_T10_PI;
2283 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2284 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002285 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002286 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002287 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002288 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002289 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002290 ha->device_type |= DT_ZIO_SUPPORTED;
2291 ha->device_type |= DT_FWI2;
2292 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002293 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002294 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2295 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002296 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002297 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002298 ha->device_type |= DT_ZIO_SUPPORTED;
2299 ha->device_type |= DT_FWI2;
2300 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002301 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002302 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2303 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002304 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002305 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002306 ha->device_type |= DT_ZIO_SUPPORTED;
2307 ha->device_type |= DT_FWI2;
2308 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002309 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002310 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2311 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002312 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002313
Giridhar Malavalia9083012010-04-12 17:59:55 -07002314 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002315 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002316 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002317 /* Get adapter physical port no from interrupt pin register. */
2318 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002319 if (IS_QLA27XX(ha))
2320 ha->port_no--;
2321 else
2322 ha->port_no = !(ha->port_no & 1);
2323 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002324
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002325 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002326 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002327 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002328}
2329
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002330static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002331qla2xxx_scan_start(struct Scsi_Host *shost)
2332{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002334
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002335 if (vha->hw->flags.running_gold_fw)
2336 return;
2337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2339 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2340 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2341 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002342}
2343
2344static int
2345qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2346{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002347 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002348
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002349 if (test_bit(UNLOADING, &vha->dpc_flags))
2350 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002351 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002352 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002353 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002354 return 1;
2355
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002357}
2358
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359/*
2360 * PCI driver interface
2361 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002362static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002363qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002365 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 scsi_qla_host_t *base_vha = NULL;
2368 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002369 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002370 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002371 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002372 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002374 struct req_que *req = NULL;
2375 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002376 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002377 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002378 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2379 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002380 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002381 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2382 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002383 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002384 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002385 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2386 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002387 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002388 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002389 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002390 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002391 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2392 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002393 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002394 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002395 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2396 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002397 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002398 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2399 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002400
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002401 if (mem_only) {
2402 if (pci_enable_device_mem(pdev))
2403 goto probe_out;
2404 } else {
2405 if (pci_enable_device(pdev))
2406 goto probe_out;
2407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Jesse Barnes09276782008-10-18 17:33:19 -07002409 /* This may fail but that's ok */
2410 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2413 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002414 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2415 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002418 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2419 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002421 ha->tgt.enable_class_2 = ql2xenableclass2;
Quinn Tran33e79972014-09-25 06:14:55 -04002422 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2423 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002424 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002425 spin_lock_init(&ha->tgt.atio_lock);
2426
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002429 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002430 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002431 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002432 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002433 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002434 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002436 /* Set ISP-type information. */
2437 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002438
2439 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002440 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002441 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002442 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002443
Chad Dupuiscba1e472011-11-18 09:03:21 -08002444 ha->prev_topology = 0;
2445 ha->init_cb_size = sizeof(init_cb_t);
2446 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2447 ha->optrom_size = OPTROM_SIZE_2300;
2448
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002449 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002451 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002453 req_length = REQUEST_ENTRY_CNT_2100;
2454 rsp_length = RESPONSE_ENTRY_CNT_2100;
2455 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002456 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002457 ha->flash_conf_off = ~0;
2458 ha->flash_data_off = ~0;
2459 ha->nvram_conf_off = ~0;
2460 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002461 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002463 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002464 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 req_length = REQUEST_ENTRY_CNT_2200;
2466 rsp_length = RESPONSE_ENTRY_CNT_2100;
2467 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002468 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002469 ha->flash_conf_off = ~0;
2470 ha->flash_data_off = ~0;
2471 ha->nvram_conf_off = ~0;
2472 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002473 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002474 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002475 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 req_length = REQUEST_ENTRY_CNT_2200;
2478 rsp_length = RESPONSE_ENTRY_CNT_2300;
2479 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002480 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002481 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2482 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002483 ha->flash_conf_off = ~0;
2484 ha->flash_data_off = ~0;
2485 ha->nvram_conf_off = ~0;
2486 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002487 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002488 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002489 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002490 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002491 req_length = REQUEST_ENTRY_CNT_24XX;
2492 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002493 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002495 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002496 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002497 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002498 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002499 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002500 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2501 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2502 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2503 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002504 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002505 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002506 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002507 req_length = REQUEST_ENTRY_CNT_24XX;
2508 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002509 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002511 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002512 ha->gid_list_info_size = 8;
2513 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002514 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002515 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002516 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2517 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2518 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2519 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2520 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002521 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002522 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2523 req_length = REQUEST_ENTRY_CNT_24XX;
2524 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002525 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002526 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2527 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2528 ha->gid_list_info_size = 8;
2529 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002530 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002531 ha->isp_ops = &qla81xx_isp_ops;
2532 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2533 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2534 ha->nvram_conf_off = ~0;
2535 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002536 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002537 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002538 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2539 req_length = REQUEST_ENTRY_CNT_82XX;
2540 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2541 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2542 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2543 ha->gid_list_info_size = 8;
2544 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002545 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002546 ha->isp_ops = &qla82xx_isp_ops;
2547 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2548 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2549 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2550 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002551 } else if (IS_QLA8044(ha)) {
2552 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2553 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2554 req_length = REQUEST_ENTRY_CNT_82XX;
2555 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2556 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2557 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2558 ha->gid_list_info_size = 8;
2559 ha->optrom_size = OPTROM_SIZE_83XX;
2560 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2561 ha->isp_ops = &qla8044_isp_ops;
2562 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2563 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2564 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2565 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002566 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002567 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002568 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002569 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002570 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002571 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002572 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002573 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2574 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2575 ha->gid_list_info_size = 8;
2576 ha->optrom_size = OPTROM_SIZE_83XX;
2577 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2578 ha->isp_ops = &qla83xx_isp_ops;
2579 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2580 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2581 ha->nvram_conf_off = ~0;
2582 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002583 } else if (IS_QLAFX00(ha)) {
2584 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2585 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2586 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2587 req_length = REQUEST_ENTRY_CNT_FX00;
2588 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002589 ha->isp_ops = &qlafx00_isp_ops;
2590 ha->port_down_retry_count = 30; /* default value */
2591 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2592 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002593 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002594 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002595 ha->mr.host_info_resend = false;
2596 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002597 } else if (IS_QLA27XX(ha)) {
2598 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2599 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2600 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002601 req_length = REQUEST_ENTRY_CNT_83XX;
2602 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002603 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002604 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2605 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2606 ha->gid_list_info_size = 8;
2607 ha->optrom_size = OPTROM_SIZE_83XX;
2608 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2609 ha->isp_ops = &qla27xx_isp_ops;
2610 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2611 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2612 ha->nvram_conf_off = ~0;
2613 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002615
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002616 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2617 "mbx_count=%d, req_length=%d, "
2618 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002619 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2620 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002621 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2622 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002623 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002624 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2625 "isp_ops=%p, flash_conf_off=%d, "
2626 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2627 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2628 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002629
2630 /* Configure PCI I/O space */
2631 ret = ha->isp_ops->iospace_config(ha);
2632 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002633 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002634
2635 ql_log_pci(ql_log_info, pdev, 0x001d,
2636 "Found an ISP%04X irq %d iobase 0x%p.\n",
2637 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002638 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002639 init_completion(&ha->mbx_cmd_comp);
2640 complete(&ha->mbx_cmd_comp);
2641 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002642 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002643 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002645 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Andrew Vasquez53303c42009-01-22 09:45:37 -08002647 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002648 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2649 "64 Bit addressing is %s.\n",
2650 ha->flags.enable_64bit_addressing ? "enable" :
2651 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002652 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002653 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002654 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2655 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002657 goto probe_hw_failed;
2658 }
2659
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002660 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002662 req->max_q_depth = ql2xmaxqdepth;
2663
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664
2665 base_vha = qla2x00_create_host(sht, ha);
2666 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002667 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002668 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002669 qla2x00_free_req_que(ha, req);
2670 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 }
2673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002675 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002678 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002679 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002681 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2683 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002684
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002685 /* Setup fcport template structure. */
2686 ha->mr.fcport.vha = base_vha;
2687 ha->mr.fcport.port_type = FCT_UNKNOWN;
2688 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2689 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2690 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2691 ha->mr.fcport.scan_state = 1;
2692
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002693 /* Set the SG table size based on ISP type */
2694 if (!IS_FWI2_CAPABLE(ha)) {
2695 if (IS_QLA2100(ha))
2696 host->sg_tablesize = 32;
2697 } else {
2698 if (!IS_QLA82XX(ha))
2699 host->sg_tablesize = QLA_SG_ALL;
2700 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002701 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002702 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002703 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002704 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002705 host->max_cmd_len = 32;
2706 else
2707 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002708 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002709 /* Older HBAs support only 16-bit LUNs */
2710 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2711 ql2xmaxlun > 0xffff)
2712 host->max_lun = 0xffff;
2713 else
2714 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002715 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002716 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002717
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002718 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2719 "max_id=%d this_id=%d "
2720 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002721 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002722 host->this_id, host->cmd_per_lun, host->unique_id,
2723 host->max_cmd_len, host->max_channel, host->max_lun,
2724 host->transportt, sht->vendor_id);
2725
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002726que_init:
2727 /* Alloc arrays of request and response ring ptrs */
2728 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2729 ql_log(ql_log_fatal, base_vha, 0x003d,
2730 "Failed to allocate memory for queue pointers..."
2731 "aborting.\n");
2732 goto probe_init_failed;
2733 }
2734
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002735 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002736
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002737 /* Set up the irqs */
2738 ret = qla2x00_request_irqs(ha, rsp);
2739 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002740 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002741
2742 pci_save_state(pdev);
2743
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002744 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002745 rsp->req = req;
2746 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002747
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002748 if (IS_QLAFX00(ha)) {
2749 ha->rsp_q_map[0] = rsp;
2750 ha->req_q_map[0] = req;
2751 set_bit(0, ha->req_qid_map);
2752 set_bit(0, ha->rsp_qid_map);
2753 }
2754
Andrew Vasquez08029992009-03-24 09:07:55 -07002755 /* FWI2-capable only. */
2756 req->req_q_in = &ha->iobase->isp24.req_q_in;
2757 req->req_q_out = &ha->iobase->isp24.req_q_out;
2758 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2759 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002760 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002761 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2762 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2763 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2764 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002765 }
2766
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002767 if (IS_QLAFX00(ha)) {
2768 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2769 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2770 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2771 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2772 }
2773
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002774 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002775 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2776 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2777 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2778 }
2779
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002780 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2781 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2782 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2783 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2784 "req->req_q_in=%p req->req_q_out=%p "
2785 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2786 req->req_q_in, req->req_q_out,
2787 rsp->rsp_q_in, rsp->rsp_q_out);
2788 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2789 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2790 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2791 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2792 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2793 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002795 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002796 ql_log(ql_log_fatal, base_vha, 0x00d6,
2797 "Failed to initialize adapter - Adapter flags %x.\n",
2798 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799
Giridhar Malavalia9083012010-04-12 17:59:55 -07002800 if (IS_QLA82XX(ha)) {
2801 qla82xx_idc_lock(ha);
2802 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002803 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002804 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002805 ql_log(ql_log_fatal, base_vha, 0x00d7,
2806 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002807 } else if (IS_QLA8044(ha)) {
2808 qla8044_idc_lock(ha);
2809 qla8044_wr_direct(base_vha,
2810 QLA8044_CRB_DEV_STATE_INDEX,
2811 QLA8XXX_DEV_FAILED);
2812 qla8044_idc_unlock(ha);
2813 ql_log(ql_log_fatal, base_vha, 0x0150,
2814 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002815 }
2816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 ret = -ENODEV;
2818 goto probe_failed;
2819 }
2820
Chad Dupuis3b1bef62014-02-26 04:15:04 -05002821 if (IS_QLAFX00(ha))
2822 host->can_queue = QLAFX00_MAX_CANQUEUE;
2823 else
2824 host->can_queue = req->num_outstanding_cmds - 10;
2825
2826 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2827 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2828 host->can_queue, base_vha->req,
2829 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2830
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002831 if (ha->mqenable) {
2832 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002833 ql_log(ql_log_warn, base_vha, 0x00ec,
2834 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002835 goto que_init;
2836 }
2837 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002838
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002839 if (ha->flags.running_gold_fw)
2840 goto skip_dpc;
2841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 /*
2843 * Startup the kernel thread for this host adapter
2844 */
2845 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002846 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002848 ql_log(ql_log_fatal, base_vha, 0x00ed,
2849 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 ret = PTR_ERR(ha->dpc_thread);
2851 goto probe_failed;
2852 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002853 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2854 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002856 /*
2857 * If we're not coming up in initiator mode, we might sit for
2858 * a while without waking up the dpc thread, which leads to a
2859 * stuck process warning. So just kick the dpc once here and
2860 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2861 */
2862 qla2xxx_wake_dpc(base_vha);
2863
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002864 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2865
Saurav Kashyap81178772012-08-22 14:21:04 -04002866 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2867 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2868 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2869 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2870
2871 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2872 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2873 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2874 INIT_WORK(&ha->idc_state_handler,
2875 qla83xx_idc_state_handler_work);
2876 INIT_WORK(&ha->nic_core_unrecoverable,
2877 qla83xx_nic_core_unrecoverable_work);
2878 }
2879
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002880skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 list_add_tail(&base_vha->list, &ha->vp_list);
2882 base_vha->host->irq = ha->pdev->irq;
2883
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002885 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002886 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2887 "Started qla2x00_timer with "
2888 "interval=%d.\n", WATCH_INTERVAL);
2889 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2890 "Detected hba at address=%p.\n",
2891 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
Arun Easie02587d2011-08-16 11:29:23 -07002893 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002894 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002895 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002896 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002897 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2898 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002899 if (ql2xenabledif == 1)
2900 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002901 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002902 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002903 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002904 | SHOST_DIF_TYPE3_PROTECTION
2905 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002906 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002907 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002908
2909 guard = SHOST_DIX_GUARD_CRC;
2910
2911 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2912 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2913 guard |= SHOST_DIX_GUARD_IP;
2914
2915 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002916 } else
2917 base_vha->flags.difdix_supported = 0;
2918 }
2919
Giridhar Malavalia9083012010-04-12 17:59:55 -07002920 ha->isp_ops->enable_intrs(ha);
2921
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002922 if (IS_QLAFX00(ha)) {
2923 ret = qlafx00_fx_disc(base_vha,
2924 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2925 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2926 QLA_SG_ALL : 128;
2927 }
2928
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002929 ret = scsi_add_host(host, &pdev->dev);
2930 if (ret)
2931 goto probe_failed;
2932
Michael Reed14864002009-12-02 09:11:16 -06002933 base_vha->flags.init_done = 1;
2934 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04002935 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06002936
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002937 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2938 "Init done and hba is online.\n");
2939
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002940 if (qla_ini_mode_enabled(base_vha))
2941 scsi_scan_host(host);
2942 else
2943 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2944 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002946 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002947
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002948 if (IS_QLAFX00(ha)) {
2949 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002950 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2951
2952 /* Register system information */
2953 ret = qlafx00_fx_disc(base_vha,
2954 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2955 }
2956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002960
Armen Baloyan03eb9122013-10-30 03:38:22 -04002961 ql_log(ql_log_info, base_vha, 0x00fb,
2962 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002963 ql_log(ql_log_info, base_vha, 0x00fc,
2964 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2965 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2966 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2967 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002968 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002970 qlt_add_target(ha, base_vha);
2971
Joe Lawrence6b383972014-08-26 17:12:29 -04002972 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04002973
2974 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2975 return -ENODEV;
2976
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return 0;
2978
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002979probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002980 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002981 ha->req_q_map[0] = NULL;
2982 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002983 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002984 ha->rsp_q_map[0] = NULL;
2985 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002986 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002987
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002989 if (base_vha->timer_active)
2990 qla2x00_stop_timer(base_vha);
2991 base_vha->flags.online = 0;
2992 if (ha->dpc_thread) {
2993 struct task_struct *t = ha->dpc_thread;
2994
2995 ha->dpc_thread = NULL;
2996 kthread_stop(t);
2997 }
2998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003004 qla2x00_clear_drv_active(ha);
3005
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003006iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003007 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003008 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003009 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003010 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003011 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003012 } else {
3013 if (ha->iobase)
3014 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003015 if (ha->cregbase)
3016 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003017 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 pci_release_selected_regions(ha->pdev, ha->bars);
3019 kfree(ha);
3020 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003022probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003024 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
Adrian Bunk4c993f72008-01-14 00:55:16 -08003027static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003028qla2x00_shutdown(struct pci_dev *pdev)
3029{
3030 scsi_qla_host_t *vha;
3031 struct qla_hw_data *ha;
3032
Masanari Iida552f3f92013-02-08 01:57:44 -05003033 if (!atomic_read(&pdev->enable_cnt))
3034 return;
3035
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003036 vha = pci_get_drvdata(pdev);
3037 ha = vha->hw;
3038
Armen Baloyan42479342013-08-27 01:37:37 -04003039 /* Notify ISPFX00 firmware */
3040 if (IS_QLAFX00(ha))
3041 qlafx00_driver_shutdown(vha, 20);
3042
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003043 /* Turn-off FCE trace */
3044 if (ha->flags.fce_enabled) {
3045 qla2x00_disable_fce_trace(vha, NULL, NULL);
3046 ha->flags.fce_enabled = 0;
3047 }
3048
3049 /* Turn-off EFT trace */
3050 if (ha->eft)
3051 qla2x00_disable_eft_trace(vha);
3052
3053 /* Stop currently executing firmware. */
3054 qla2x00_try_to_stop_firmware(vha);
3055
3056 /* Turn adapter off line */
3057 vha->flags.online = 0;
3058
3059 /* turn-off interrupts on the card */
3060 if (ha->interrupts_on) {
3061 vha->flags.init_done = 0;
3062 ha->isp_ops->disable_intrs(ha);
3063 }
3064
3065 qla2x00_free_irqs(vha);
3066
3067 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003068
3069 pci_disable_pcie_error_reporting(pdev);
3070 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003071}
3072
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003073/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003074static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003075qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003077 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003078 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
Arun Easi43ebf162011-05-10 11:18:16 -07003080 mutex_lock(&ha->vport_lock);
3081 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003082 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003083
Arun Easi43ebf162011-05-10 11:18:16 -07003084 BUG_ON(base_vha->list.next == &ha->vp_list);
3085 /* This assumes first entry in ha->vp_list is always base vha */
3086 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003087 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003088
Arun Easi43ebf162011-05-10 11:18:16 -07003089 spin_unlock_irqrestore(&ha->vport_slock, flags);
3090 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003091
Arun Easi43ebf162011-05-10 11:18:16 -07003092 fc_vport_terminate(vha->fc_vport);
3093 scsi_host_put(vha->host);
3094
3095 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096 }
Arun Easi43ebf162011-05-10 11:18:16 -07003097 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003098}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003099
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003100/* Stops all deferred work threads */
3101static void
3102qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3103{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003104 /* Flush the work queue and remove it */
3105 if (ha->wq) {
3106 flush_workqueue(ha->wq);
3107 destroy_workqueue(ha->wq);
3108 ha->wq = NULL;
3109 }
3110
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003111 /* Cancel all work and destroy DPC workqueues */
3112 if (ha->dpc_lp_wq) {
3113 cancel_work_sync(&ha->idc_aen);
3114 destroy_workqueue(ha->dpc_lp_wq);
3115 ha->dpc_lp_wq = NULL;
3116 }
3117
3118 if (ha->dpc_hp_wq) {
3119 cancel_work_sync(&ha->nic_core_reset);
3120 cancel_work_sync(&ha->idc_state_handler);
3121 cancel_work_sync(&ha->nic_core_unrecoverable);
3122 destroy_workqueue(ha->dpc_hp_wq);
3123 ha->dpc_hp_wq = NULL;
3124 }
3125
Andrew Vasquezb9978762009-03-24 09:08:05 -07003126 /* Kill the kernel thread for this host */
3127 if (ha->dpc_thread) {
3128 struct task_struct *t = ha->dpc_thread;
3129
3130 /*
3131 * qla2xxx_wake_dpc checks for ->dpc_thread
3132 * so we need to zero it out.
3133 */
3134 ha->dpc_thread = NULL;
3135 kthread_stop(t);
3136 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003137}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003138
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003139static void
3140qla2x00_unmap_iobases(struct qla_hw_data *ha)
3141{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003142 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003143
Chad Dupuisf73cb692014-02-26 04:15:06 -05003144 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003145 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003146 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003147 } else {
3148 if (ha->iobase)
3149 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003151 if (ha->cregbase)
3152 iounmap(ha->cregbase);
3153
Giridhar Malavalia9083012010-04-12 17:59:55 -07003154 if (ha->mqiobase)
3155 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003156
Chad Dupuisf73cb692014-02-26 04:15:06 -05003157 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003158 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003159 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003160}
3161
3162static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003163qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003164{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003165 if (IS_QLA8044(ha)) {
3166 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003167 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003168 qla8044_idc_unlock(ha);
3169 } else if (IS_QLA82XX(ha)) {
3170 qla82xx_idc_lock(ha);
3171 qla82xx_clear_drv_active(ha);
3172 qla82xx_idc_unlock(ha);
3173 }
3174}
3175
3176static void
3177qla2x00_remove_one(struct pci_dev *pdev)
3178{
3179 scsi_qla_host_t *base_vha;
3180 struct qla_hw_data *ha;
3181
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003182 base_vha = pci_get_drvdata(pdev);
3183 ha = base_vha->hw;
3184
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003185 /* Indicate device removal to prevent future board_disable and wait
3186 * until any pending board_disable has completed. */
3187 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3188 cancel_work_sync(&ha->board_disable);
3189
3190 /*
3191 * If the PCI device is disabled then there was a PCI-disconnect and
3192 * qla2x00_disable_board_on_pci_error has taken care of most of the
3193 * resources.
3194 */
3195 if (!atomic_read(&pdev->enable_cnt)) {
3196 scsi_host_put(base_vha->host);
3197 kfree(ha);
3198 pci_set_drvdata(pdev, NULL);
3199 return;
3200 }
3201
Sawan Chandak638a1a02014-04-11 16:54:38 -04003202 qla2x00_wait_for_hba_ready(base_vha);
3203
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003204 /* if UNLOAD flag is already set, then continue unload,
3205 * where it was set first.
3206 */
3207 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3208 return;
3209
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003210 set_bit(UNLOADING, &base_vha->dpc_flags);
3211
3212 if (IS_QLAFX00(ha))
3213 qlafx00_driver_shutdown(base_vha, 20);
3214
3215 qla2x00_delete_all_vps(ha, base_vha);
3216
3217 if (IS_QLA8031(ha)) {
3218 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3219 "Clearing fcoe driver presence.\n");
3220 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3221 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3222 "Error while clearing DRV-Presence.\n");
3223 }
3224
3225 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3226
3227 qla2x00_dfs_remove(base_vha);
3228
3229 qla84xx_put_chip(base_vha);
3230
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003231 /* Laser should be disabled only for ISP2031 */
3232 if (IS_QLA2031(ha))
3233 qla83xx_disable_laser(base_vha);
3234
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003235 /* Disable timer */
3236 if (base_vha->timer_active)
3237 qla2x00_stop_timer(base_vha);
3238
3239 base_vha->flags.online = 0;
3240
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003241 /* free DMA memory */
3242 if (ha->exlogin_buf)
3243 qla2x00_free_exlogin_buffer(ha);
3244
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003245 /* free DMA memory */
3246 if (ha->exchoffld_buf)
3247 qla2x00_free_exchoffld_buffer(ha);
3248
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003249 qla2x00_destroy_deferred_work(ha);
3250
3251 qlt_remove_target(ha, base_vha);
3252
3253 qla2x00_free_sysfs_attr(base_vha, true);
3254
3255 fc_remove_host(base_vha->host);
3256
3257 scsi_remove_host(base_vha->host);
3258
3259 qla2x00_free_device(base_vha);
3260
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003261 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003262
Arun Easid2749ff2014-09-25 05:16:51 -04003263 scsi_host_put(base_vha->host);
3264
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003265 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 pci_release_selected_regions(ha->pdev, ha->bars);
3268 kfree(ha);
3269 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003271 pci_disable_pcie_error_reporting(pdev);
3272
Bernhard Walle665db932007-03-28 00:49:49 +02003273 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275
3276static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
Andrew Vasquez85880802009-12-15 21:29:46 -08003281 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3282
3283 /* Disable timer */
3284 if (vha->timer_active)
3285 qla2x00_stop_timer(vha);
3286
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003287 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003288
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003289 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003290 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003291
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003292 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003294
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003295 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003296 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
Andrew Vasquez85880802009-12-15 21:29:46 -08003298 vha->flags.online = 0;
3299
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003300 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003301 if (ha->interrupts_on) {
3302 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003303 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003304 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 qla2x00_free_irqs(vha);
3307
Chad Dupuis88670482010-07-23 15:28:30 +05003308 qla2x00_free_fcports(vha);
3309
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003310 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003311
Giridhar Malavali08de2842011-08-16 11:31:44 -07003312 qla82xx_md_free(vha);
3313
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003314 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315}
3316
Chad Dupuis88670482010-07-23 15:28:30 +05003317void qla2x00_free_fcports(struct scsi_qla_host *vha)
3318{
3319 fc_port_t *fcport, *tfcport;
3320
3321 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3322 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003323 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003324 kfree(fcport);
3325 fcport = NULL;
3326 }
3327}
3328
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003329static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003331 int defer)
3332{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003333 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003334 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003335 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003336
3337 if (!fcport->rport)
3338 return;
3339
3340 rport = fcport->rport;
3341 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003342 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003343 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003344 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003345 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003346 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003347 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3348 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003349 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003350 int now;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003351 if (rport)
3352 fc_remote_port_delete(rport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003353 qlt_do_generation_tick(vha, &now);
3354 qlt_fc_port_deleted(vha, fcport, now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003355 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003356}
3357
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3360 *
3361 * Input: ha = adapter block pointer. fcport = port structure pointer.
3362 *
3363 * Return: None.
3364 *
3365 * Context:
3366 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003367void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003368 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003370 if (IS_QLAFX00(vha->hw)) {
3371 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3372 qla2x00_schedule_rport_del(vha, fcport, defer);
3373 return;
3374 }
3375
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003376 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003377 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003378 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003379 qla2x00_schedule_rport_del(vha, fcport, defer);
3380 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003381 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 * We may need to retry the login, so don't change the state of the
3383 * port but do the retries.
3384 */
3385 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003386 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
3388 if (!do_login)
3389 return;
3390
Arun Easia1d02852015-08-04 13:38:02 -04003391 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3392
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003396 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003397 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3398 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 }
3400}
3401
3402/*
3403 * qla2x00_mark_all_devices_lost
3404 * Updates fcport state when device goes offline.
3405 *
3406 * Input:
3407 * ha = adapter block pointer.
3408 * fcport = port structure pointer.
3409 *
3410 * Return:
3411 * None.
3412 *
3413 * Context:
3414 */
3415void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417{
3418 fc_port_t *fcport;
3419
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003421 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003423
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 /*
3425 * No point in marking the device as lost, if the device is
3426 * already DEAD.
3427 */
3428 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3429 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003431 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003432 if (defer)
3433 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003434 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003435 qla2x00_schedule_rport_del(vha, fcport, defer);
3436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
3438}
3439
3440/*
3441* qla2x00_mem_alloc
3442* Allocates adapter memory.
3443*
3444* Returns:
3445* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003446* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003448static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003449qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3450 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
3452 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Andrew Vasqueze8711082008-01-31 12:33:48 -08003454 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003455 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003456 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003457 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003459 if (qlt_mem_alloc(ha) < 0)
3460 goto fail_free_init_cb;
3461
Chad Dupuis642ef982012-02-09 11:15:57 -08003462 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3463 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003464 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003465 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466
Andrew Vasqueze8711082008-01-31 12:33:48 -08003467 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3468 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003471 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003472 /* Allocate cache for CT6 Ctx. */
3473 if (!ctx_cachep) {
3474 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3475 sizeof(struct ct6_dsd), 0,
3476 SLAB_HWCACHE_ALIGN, NULL);
3477 if (!ctx_cachep)
3478 goto fail_free_gid_list;
3479 }
3480 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3481 ctx_cachep);
3482 if (!ha->ctx_mempool)
3483 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003484 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3485 "ctx_cachep=%p ctx_mempool=%p.\n",
3486 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003487 }
3488
Andrew Vasqueze8711082008-01-31 12:33:48 -08003489 /* Get memory for cached NVRAM */
3490 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3491 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003492 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3495 ha->pdev->device);
3496 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3497 DMA_POOL_SIZE, 8, 0);
3498 if (!ha->s_dma_pool)
3499 goto fail_free_nvram;
3500
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003501 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3502 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3503 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3504
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003505 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003506 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3507 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3508 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003509 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3510 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003511 goto fail_s_dma_pool;
3512 }
3513
3514 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3515 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3516 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003517 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3518 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003519 goto fail_dl_dma_pool;
3520 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003521 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3522 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3523 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003524 }
3525
Andrew Vasqueze8711082008-01-31 12:33:48 -08003526 /* Allocate memory for SNS commands */
3527 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003529 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003531 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003533 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003534 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003535 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003536 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003537 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003539 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003540 goto fail_dma_pool;
3541 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003542 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003544 if (!ha->ct_sns)
3545 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003546 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3547 "ms_iocb=%p ct_sns=%p.\n",
3548 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 }
3550
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003552 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3553 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003554 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3555 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 goto fail_req;
3557 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003558 (*req)->length = req_len;
3559 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3560 ((*req)->length + 1) * sizeof(request_t),
3561 &(*req)->dma, GFP_KERNEL);
3562 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003563 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3564 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003565 goto fail_req_ring;
3566 }
3567 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003568 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3569 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003570 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3571 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 goto fail_rsp;
3573 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003574 (*rsp)->hw = ha;
3575 (*rsp)->length = rsp_len;
3576 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3577 ((*rsp)->length + 1) * sizeof(response_t),
3578 &(*rsp)->dma, GFP_KERNEL);
3579 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003580 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3581 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582 goto fail_rsp_ring;
3583 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003584 (*req)->rsp = *rsp;
3585 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003586 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3587 "req=%p req->length=%d req->ring=%p rsp=%p "
3588 "rsp->length=%d rsp->ring=%p.\n",
3589 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3590 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003591 /* Allocate memory for NVRAM data for vports */
3592 if (ha->nvram_npiv_size) {
3593 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003594 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003595 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003596 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3597 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003598 goto fail_npiv_info;
3599 }
3600 } else
3601 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003603 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003604 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003605 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3606 &ha->ex_init_cb_dma);
3607 if (!ha->ex_init_cb)
3608 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003609 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3610 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003611 }
3612
Giridhar Malavalia9083012010-04-12 17:59:55 -07003613 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3614
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003615 /* Get consistent memory allocated for Async Port-Database. */
3616 if (!IS_FWI2_CAPABLE(ha)) {
3617 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3618 &ha->async_pd_dma);
3619 if (!ha->async_pd)
3620 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003621 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3622 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003623 }
3624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003625 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003626
3627 /* Allocate memory for our loop_id bitmap */
3628 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3629 GFP_KERNEL);
3630 if (!ha->loop_id_map)
3631 goto fail_async_pd;
3632 else {
3633 qla2x00_set_reserved_loop_ids(ha);
3634 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003635 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003636 }
3637
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003638 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003640fail_async_pd:
3641 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003642fail_ex_init_cb:
3643 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003644fail_npiv_info:
3645 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3646 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3647 (*rsp)->ring = NULL;
3648 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003649fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003650 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003651fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003652 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3653 sizeof(request_t), (*req)->ring, (*req)->dma);
3654 (*req)->ring = NULL;
3655 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003656fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003657 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003658fail_req:
3659 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3660 ha->ct_sns, ha->ct_sns_dma);
3661 ha->ct_sns = NULL;
3662 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003663fail_free_ms_iocb:
3664 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3665 ha->ms_iocb = NULL;
3666 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003667fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003668 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003669 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3670 ha->fcp_cmnd_dma_pool = NULL;
3671 }
3672fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003673 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003674 dma_pool_destroy(ha->dl_dma_pool);
3675 ha->dl_dma_pool = NULL;
3676 }
3677fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678 dma_pool_destroy(ha->s_dma_pool);
3679 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003680fail_free_nvram:
3681 kfree(ha->nvram);
3682 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003683fail_free_ctx_mempool:
3684 mempool_destroy(ha->ctx_mempool);
3685 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003686fail_free_srb_mempool:
3687 mempool_destroy(ha->srb_mempool);
3688 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003689fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003690 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3691 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003693 ha->gid_list = NULL;
3694 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003695fail_free_tgt_mem:
3696 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697fail_free_init_cb:
3698 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3699 ha->init_cb_dma);
3700 ha->init_cb = NULL;
3701 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003702fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003703 ql_log(ql_log_fatal, NULL, 0x0030,
3704 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003705 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706}
3707
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003708int
3709qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
3710{
3711 int rval;
3712 uint16_t size, max_cnt, temp;
3713 struct qla_hw_data *ha = vha->hw;
3714
3715 /* Return if we don't need to alloacate any extended logins */
3716 if (!ql2xexlogins)
3717 return QLA_SUCCESS;
3718
3719 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
3720 max_cnt = 0;
3721 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
3722 if (rval != QLA_SUCCESS) {
3723 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
3724 "Failed to get exlogin status.\n");
3725 return rval;
3726 }
3727
3728 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
3729 ha->exlogin_size = (size * temp);
3730 ql_log(ql_log_info, vha, 0xd024,
3731 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
3732 max_cnt, size, temp);
3733
3734 ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
3735 ha->exlogin_size);
3736
3737 /* Get consistent memory for extended logins */
3738 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
3739 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
3740 if (!ha->exlogin_buf) {
3741 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
3742 "Failed to allocate memory for exlogin_buf_dma.\n");
3743 return -ENOMEM;
3744 }
3745
3746 /* Now configure the dma buffer */
3747 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
3748 if (rval) {
3749 ql_log(ql_log_fatal, vha, 0x00cf,
3750 "Setup extended login buffer ****FAILED****.\n");
3751 qla2x00_free_exlogin_buffer(ha);
3752 }
3753
3754 return rval;
3755}
3756
3757/*
3758* qla2x00_free_exlogin_buffer
3759*
3760* Input:
3761* ha = adapter block pointer
3762*/
3763void
3764qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
3765{
3766 if (ha->exlogin_buf) {
3767 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
3768 ha->exlogin_buf, ha->exlogin_buf_dma);
3769 ha->exlogin_buf = NULL;
3770 ha->exlogin_size = 0;
3771 }
3772}
3773
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003774int
3775qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
3776{
3777 int rval;
3778 uint16_t size, max_cnt, temp;
3779 struct qla_hw_data *ha = vha->hw;
3780
3781 /* Return if we don't need to alloacate any extended logins */
3782 if (!ql2xexchoffld)
3783 return QLA_SUCCESS;
3784
3785 ql_log(ql_log_info, vha, 0xd014,
3786 "Exchange offload count: %d.\n", ql2xexlogins);
3787
3788 max_cnt = 0;
3789 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
3790 if (rval != QLA_SUCCESS) {
3791 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
3792 "Failed to get exlogin status.\n");
3793 return rval;
3794 }
3795
3796 temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
3797 ha->exchoffld_size = (size * temp);
3798 ql_log(ql_log_info, vha, 0xd016,
3799 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
3800 max_cnt, size, temp);
3801
3802 ql_log(ql_log_info, vha, 0xd017,
3803 "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
3804
3805 /* Get consistent memory for extended logins */
3806 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
3807 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
3808 if (!ha->exchoffld_buf) {
3809 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
3810 "Failed to allocate memory for exchoffld_buf_dma.\n");
3811 return -ENOMEM;
3812 }
3813
3814 /* Now configure the dma buffer */
3815 rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
3816 if (rval) {
3817 ql_log(ql_log_fatal, vha, 0xd02e,
3818 "Setup exchange offload buffer ****FAILED****.\n");
3819 qla2x00_free_exchoffld_buffer(ha);
3820 }
3821
3822 return rval;
3823}
3824
3825/*
3826* qla2x00_free_exchoffld_buffer
3827*
3828* Input:
3829* ha = adapter block pointer
3830*/
3831void
3832qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
3833{
3834 if (ha->exchoffld_buf) {
3835 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
3836 ha->exchoffld_buf, ha->exchoffld_buf_dma);
3837 ha->exchoffld_buf = NULL;
3838 ha->exchoffld_size = 0;
3839 }
3840}
3841
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003843* qla2x00_free_fw_dump
3844* Frees fw dump stuff.
3845*
3846* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003847* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003848*/
3849static void
3850qla2x00_free_fw_dump(struct qla_hw_data *ha)
3851{
3852 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003853 dma_free_coherent(&ha->pdev->dev,
3854 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003855
Chad Dupuisf73cb692014-02-26 04:15:06 -05003856 if (ha->eft)
3857 dma_free_coherent(&ha->pdev->dev,
3858 EFT_SIZE, ha->eft, ha->eft_dma);
3859
3860 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003861 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05003862 if (ha->fw_dump_template)
3863 vfree(ha->fw_dump_template);
3864
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003865 ha->fce = NULL;
3866 ha->fce_dma = 0;
3867 ha->eft = NULL;
3868 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003869 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04003870 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003871 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003872 ha->fw_dump = NULL;
3873 ha->fw_dump_len = 0;
3874 ha->fw_dump_template = NULL;
3875 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003876}
3877
3878/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879* qla2x00_mem_free
3880* Frees all adapter allocated memory.
3881*
3882* Input:
3883* ha = adapter block pointer.
3884*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003885static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003888 qla2x00_free_fw_dump(ha);
3889
Saurav Kashyap81178772012-08-22 14:21:04 -04003890 if (ha->mctp_dump)
3891 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3892 ha->mctp_dump_dma);
3893
Andrew Vasqueze8711082008-01-31 12:33:48 -08003894 if (ha->srb_mempool)
3895 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003897 if (ha->dcbx_tlv)
3898 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3899 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3900
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003901 if (ha->xgmac_data)
3902 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3903 ha->xgmac_data, ha->xgmac_data_dma);
3904
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 if (ha->sns_cmd)
3906 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
3909 if (ha->ct_sns)
3910 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003911 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912
Andrew Vasquez88729e52006-06-23 16:10:50 -07003913 if (ha->sfp_data)
3914 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3915
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 if (ha->ms_iocb)
3917 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3918
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003919 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003920 dma_pool_free(ha->s_dma_pool,
3921 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003922
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003923 if (ha->async_pd)
3924 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3925
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 if (ha->s_dma_pool)
3927 dma_pool_destroy(ha->s_dma_pool);
3928
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003930 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3931 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Giridhar Malavalia9083012010-04-12 17:59:55 -07003933 if (IS_QLA82XX(ha)) {
3934 if (!list_empty(&ha->gbl_dsd_list)) {
3935 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3936
3937 /* clean up allocated prev pool */
3938 list_for_each_entry_safe(dsd_ptr,
3939 tdsd_ptr, &ha->gbl_dsd_list, list) {
3940 dma_pool_free(ha->dl_dma_pool,
3941 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3942 list_del(&dsd_ptr->list);
3943 kfree(dsd_ptr);
3944 }
3945 }
3946 }
3947
3948 if (ha->dl_dma_pool)
3949 dma_pool_destroy(ha->dl_dma_pool);
3950
3951 if (ha->fcp_cmnd_dma_pool)
3952 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3953
3954 if (ha->ctx_mempool)
3955 mempool_destroy(ha->ctx_mempool);
3956
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003957 qlt_mem_free(ha);
3958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003959 if (ha->init_cb)
3960 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003961 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003962 vfree(ha->optrom_buffer);
3963 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003964 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003965 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003966 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
Andrew Vasqueze8711082008-01-31 12:33:48 -08003968 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003969 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 ha->sns_cmd = NULL;
3971 ha->sns_cmd_dma = 0;
3972 ha->ct_sns = NULL;
3973 ha->ct_sns_dma = 0;
3974 ha->ms_iocb = NULL;
3975 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 ha->init_cb = NULL;
3977 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003978 ha->ex_init_cb = NULL;
3979 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003980 ha->async_pd = NULL;
3981 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982
3983 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003984 ha->dl_dma_pool = NULL;
3985 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 ha->gid_list = NULL;
3988 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003989
3990 ha->tgt.atio_ring = NULL;
3991 ha->tgt.atio_dma = 0;
3992 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003993}
3994
3995struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3996 struct qla_hw_data *ha)
3997{
3998 struct Scsi_Host *host;
3999 struct scsi_qla_host *vha = NULL;
4000
4001 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4002 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004003 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4004 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 goto fail;
4006 }
4007
4008 /* Clear our data area */
4009 vha = shost_priv(host);
4010 memset(vha, 0, sizeof(scsi_qla_host_t));
4011
4012 vha->host = host;
4013 vha->host_no = host->host_no;
4014 vha->hw = ha;
4015
4016 INIT_LIST_HEAD(&vha->vp_fcports);
4017 INIT_LIST_HEAD(&vha->work_list);
4018 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004019 INIT_LIST_HEAD(&vha->qla_cmd_list);
4020 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004021 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004022 INIT_LIST_HEAD(&vha->plogi_ack_list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004023
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004024 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004025 spin_lock_init(&vha->cmd_list_lock);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004028 ql_dbg(ql_dbg_init, vha, 0x0041,
4029 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4030 vha->host, vha->hw, vha,
4031 dev_name(&(ha->pdev->dev)));
4032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004033 return vha;
4034
4035fail:
4036 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037}
4038
Adrian Bunk01ef66b2008-04-24 15:21:27 -07004039static struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004040qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004041{
4042 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004043 uint8_t bail;
4044
4045 QLA_VHA_MARK_BUSY(vha, bail);
4046 if (bail)
4047 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004048
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004049 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004050 if (!e) {
4051 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004052 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004053 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004054
4055 INIT_LIST_HEAD(&e->list);
4056 e->type = type;
4057 e->flags = QLA_EVT_FLAG_FREE;
4058 return e;
4059}
4060
Adrian Bunk01ef66b2008-04-24 15:21:27 -07004061static int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004062qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004063{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004064 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004065
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004066 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004068 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004070
Andrew Vasquez0971de72008-04-03 13:13:18 -07004071 return QLA_SUCCESS;
4072}
4073
4074int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004075qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004076 u32 data)
4077{
4078 struct qla_work_evt *e;
4079
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004080 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004081 if (!e)
4082 return QLA_FUNCTION_FAILED;
4083
4084 e->u.aen.code = code;
4085 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004086 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004087}
4088
Andrew Vasquez8a659572009-02-08 20:50:12 -08004089int
4090qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4091{
4092 struct qla_work_evt *e;
4093
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004094 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004095 if (!e)
4096 return QLA_FUNCTION_FAILED;
4097
4098 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004099 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004100}
4101
Andrew Vasquezac280b62009-08-20 11:06:05 -07004102#define qla2x00_post_async_work(name, type) \
4103int qla2x00_post_async_##name##_work( \
4104 struct scsi_qla_host *vha, \
4105 fc_port_t *fcport, uint16_t *data) \
4106{ \
4107 struct qla_work_evt *e; \
4108 \
4109 e = qla2x00_alloc_work(vha, type); \
4110 if (!e) \
4111 return QLA_FUNCTION_FAILED; \
4112 \
4113 e->u.logio.fcport = fcport; \
4114 if (data) { \
4115 e->u.logio.data[0] = data[0]; \
4116 e->u.logio.data[1] = data[1]; \
4117 } \
4118 return qla2x00_post_work(vha, e); \
4119}
4120
4121qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4122qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
4123qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4124qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004125qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4126qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004127
Andrew Vasquez3420d362009-10-13 15:16:45 -07004128int
4129qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4130{
4131 struct qla_work_evt *e;
4132
4133 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4134 if (!e)
4135 return QLA_FUNCTION_FAILED;
4136
4137 e->u.uevent.code = code;
4138 return qla2x00_post_work(vha, e);
4139}
4140
4141static void
4142qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4143{
4144 char event_string[40];
4145 char *envp[] = { event_string, NULL };
4146
4147 switch (code) {
4148 case QLA_UEVENT_CODE_FW_DUMP:
4149 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4150 vha->host_no);
4151 break;
4152 default:
4153 /* do nothing */
4154 break;
4155 }
4156 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4157}
4158
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004159int
4160qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4161 uint32_t *data, int cnt)
4162{
4163 struct qla_work_evt *e;
4164
4165 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4166 if (!e)
4167 return QLA_FUNCTION_FAILED;
4168
4169 e->u.aenfx.evtcode = evtcode;
4170 e->u.aenfx.count = cnt;
4171 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4172 return qla2x00_post_work(vha, e);
4173}
4174
Andrew Vasquezac280b62009-08-20 11:06:05 -07004175void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004177{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004178 struct qla_work_evt *e, *tmp;
4179 unsigned long flags;
4180 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004181
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004182 spin_lock_irqsave(&vha->work_lock, flags);
4183 list_splice_init(&vha->work_list, &work);
4184 spin_unlock_irqrestore(&vha->work_lock, flags);
4185
4186 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004187 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004188
4189 switch (e->type) {
4190 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004192 e->u.aen.code, e->u.aen.data);
4193 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004194 case QLA_EVT_IDC_ACK:
4195 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4196 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004197 case QLA_EVT_ASYNC_LOGIN:
4198 qla2x00_async_login(vha, e->u.logio.fcport,
4199 e->u.logio.data);
4200 break;
4201 case QLA_EVT_ASYNC_LOGIN_DONE:
4202 qla2x00_async_login_done(vha, e->u.logio.fcport,
4203 e->u.logio.data);
4204 break;
4205 case QLA_EVT_ASYNC_LOGOUT:
4206 qla2x00_async_logout(vha, e->u.logio.fcport);
4207 break;
4208 case QLA_EVT_ASYNC_LOGOUT_DONE:
4209 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4210 e->u.logio.data);
4211 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004212 case QLA_EVT_ASYNC_ADISC:
4213 qla2x00_async_adisc(vha, e->u.logio.fcport,
4214 e->u.logio.data);
4215 break;
4216 case QLA_EVT_ASYNC_ADISC_DONE:
4217 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4218 e->u.logio.data);
4219 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004220 case QLA_EVT_UEVENT:
4221 qla2x00_uevent_emit(vha, e->u.uevent.code);
4222 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004223 case QLA_EVT_AENFX:
4224 qlafx00_process_aen(vha, e);
4225 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004226 }
4227 if (e->flags & QLA_EVT_FLAG_FREE)
4228 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004229
4230 /* For each work completed decrement vha ref count */
4231 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004232 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004233}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004235/* Relogins all the fcports of a vport
4236 * Context: dpc thread
4237 */
4238void qla2x00_relogin(struct scsi_qla_host *vha)
4239{
4240 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004241 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 uint16_t next_loopid = 0;
4243 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004244 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004245
4246 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4247 /*
4248 * If the port is not ONLINE then try to login
4249 * to it if we haven't run out of retries.
4250 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004251 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4252 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004253 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004254 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004255 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004256 ha->isp_ops->fabric_logout(vha,
4257 fcport->loop_id,
4258 fcport->d_id.b.domain,
4259 fcport->d_id.b.area,
4260 fcport->d_id.b.al_pa);
4261
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004262 if (fcport->loop_id == FC_NO_LOOP_ID) {
4263 fcport->loop_id = next_loopid =
4264 ha->min_external_loopid;
4265 status = qla2x00_find_new_loop_id(
4266 vha, fcport);
4267 if (status != QLA_SUCCESS) {
4268 /* Ran out of IDs to use */
4269 break;
4270 }
4271 }
4272
Andrew Vasquezac280b62009-08-20 11:06:05 -07004273 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004274 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004275 data[0] = 0;
4276 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4277 status = qla2x00_post_async_login_work(
4278 vha, fcport, data);
4279 if (status == QLA_SUCCESS)
4280 continue;
4281 /* Attempt a retry. */
4282 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004283 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004284 status = qla2x00_fabric_login(vha,
4285 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004286 if (status == QLA_SUCCESS) {
4287 int status2;
4288 uint8_t opts;
4289
4290 opts = 0;
4291 if (fcport->flags &
4292 FCF_FCP2_DEVICE)
4293 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004294 status2 =
4295 qla2x00_get_port_database(
4296 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004297 if (status2 != QLA_SUCCESS)
4298 status = 1;
4299 }
4300 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004301 } else
4302 status = qla2x00_local_device_login(vha,
4303 fcport);
4304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004305 if (status == QLA_SUCCESS) {
4306 fcport->old_loop_id = fcport->loop_id;
4307
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004308 ql_dbg(ql_dbg_disc, vha, 0x2003,
4309 "Port login OK: logged in ID 0x%x.\n",
4310 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004311
4312 qla2x00_update_fcport(vha, fcport);
4313
4314 } else if (status == 1) {
4315 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4316 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004317 ql_dbg(ql_dbg_disc, vha, 0x2007,
4318 "Retrying %d login again loop_id 0x%x.\n",
4319 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004320 } else {
4321 fcport->login_retry = 0;
4322 }
4323
4324 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004325 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004326 }
4327 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4328 break;
4329 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004330}
4331
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004332/* Schedule work on any of the dpc-workqueues */
4333void
4334qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4335{
4336 struct qla_hw_data *ha = base_vha->hw;
4337
4338 switch (work_code) {
4339 case MBA_IDC_AEN: /* 0x8200 */
4340 if (ha->dpc_lp_wq)
4341 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4342 break;
4343
4344 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4345 if (!ha->flags.nic_core_reset_hdlr_active) {
4346 if (ha->dpc_hp_wq)
4347 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4348 } else
4349 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4350 "NIC Core reset is already active. Skip "
4351 "scheduling it again.\n");
4352 break;
4353 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4354 if (ha->dpc_hp_wq)
4355 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4356 break;
4357 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4358 if (ha->dpc_hp_wq)
4359 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4360 break;
4361 default:
4362 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004363 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004364 }
4365
4366 return;
4367}
4368
4369/* Work: Perform NIC Core Unrecoverable state handling */
4370void
4371qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4372{
4373 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004374 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004375 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4376 uint32_t dev_state = 0;
4377
4378 qla83xx_idc_lock(base_vha, 0);
4379 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4380 qla83xx_reset_ownership(base_vha);
4381 if (ha->flags.nic_core_reset_owner) {
4382 ha->flags.nic_core_reset_owner = 0;
4383 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4384 QLA8XXX_DEV_FAILED);
4385 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4386 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4387 }
4388 qla83xx_idc_unlock(base_vha, 0);
4389}
4390
4391/* Work: Execute IDC state handler */
4392void
4393qla83xx_idc_state_handler_work(struct work_struct *work)
4394{
4395 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004396 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004397 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4398 uint32_t dev_state = 0;
4399
4400 qla83xx_idc_lock(base_vha, 0);
4401 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4402 if (dev_state == QLA8XXX_DEV_FAILED ||
4403 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4404 qla83xx_idc_state_handler(base_vha);
4405 qla83xx_idc_unlock(base_vha, 0);
4406}
4407
Saurav Kashyapfa492632012-11-21 02:40:29 -05004408static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004409qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4410{
4411 int rval = QLA_SUCCESS;
4412 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4413 uint32_t heart_beat_counter1, heart_beat_counter2;
4414
4415 do {
4416 if (time_after(jiffies, heart_beat_wait)) {
4417 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4418 "Nic Core f/w is not alive.\n");
4419 rval = QLA_FUNCTION_FAILED;
4420 break;
4421 }
4422
4423 qla83xx_idc_lock(base_vha, 0);
4424 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4425 &heart_beat_counter1);
4426 qla83xx_idc_unlock(base_vha, 0);
4427 msleep(100);
4428 qla83xx_idc_lock(base_vha, 0);
4429 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4430 &heart_beat_counter2);
4431 qla83xx_idc_unlock(base_vha, 0);
4432 } while (heart_beat_counter1 == heart_beat_counter2);
4433
4434 return rval;
4435}
4436
4437/* Work: Perform NIC Core Reset handling */
4438void
4439qla83xx_nic_core_reset_work(struct work_struct *work)
4440{
4441 struct qla_hw_data *ha =
4442 container_of(work, struct qla_hw_data, nic_core_reset);
4443 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4444 uint32_t dev_state = 0;
4445
Saurav Kashyap81178772012-08-22 14:21:04 -04004446 if (IS_QLA2031(ha)) {
4447 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4448 ql_log(ql_log_warn, base_vha, 0xb081,
4449 "Failed to dump mctp\n");
4450 return;
4451 }
4452
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004453 if (!ha->flags.nic_core_reset_hdlr_active) {
4454 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4455 qla83xx_idc_lock(base_vha, 0);
4456 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4457 &dev_state);
4458 qla83xx_idc_unlock(base_vha, 0);
4459 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4460 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4461 "Nic Core f/w is alive.\n");
4462 return;
4463 }
4464 }
4465
4466 ha->flags.nic_core_reset_hdlr_active = 1;
4467 if (qla83xx_nic_core_reset(base_vha)) {
4468 /* NIC Core reset failed. */
4469 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4470 "NIC Core reset failed.\n");
4471 }
4472 ha->flags.nic_core_reset_hdlr_active = 0;
4473 }
4474}
4475
4476/* Work: Handle 8200 IDC aens */
4477void
4478qla83xx_service_idc_aen(struct work_struct *work)
4479{
4480 struct qla_hw_data *ha =
4481 container_of(work, struct qla_hw_data, idc_aen);
4482 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4483 uint32_t dev_state, idc_control;
4484
4485 qla83xx_idc_lock(base_vha, 0);
4486 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4487 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4488 qla83xx_idc_unlock(base_vha, 0);
4489 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4490 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4491 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4492 "Application requested NIC Core Reset.\n");
4493 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4494 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4495 QLA_SUCCESS) {
4496 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4497 "Other protocol driver requested NIC Core Reset.\n");
4498 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4499 }
4500 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4501 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4502 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4503 }
4504}
4505
4506static void
4507qla83xx_wait_logic(void)
4508{
4509 int i;
4510
4511 /* Yield CPU */
4512 if (!in_interrupt()) {
4513 /*
4514 * Wait about 200ms before retrying again.
4515 * This controls the number of retries for single
4516 * lock operation.
4517 */
4518 msleep(100);
4519 schedule();
4520 } else {
4521 for (i = 0; i < 20; i++)
4522 cpu_relax(); /* This a nop instr on i386 */
4523 }
4524}
4525
Saurav Kashyapfa492632012-11-21 02:40:29 -05004526static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004527qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4528{
4529 int rval;
4530 uint32_t data;
4531 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4532 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4533 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004534 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4535 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004536
4537 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4538 if (rval)
4539 return rval;
4540
4541 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4542 return QLA_SUCCESS;
4543 } else {
4544 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4545 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4546 data);
4547 if (rval)
4548 return rval;
4549
4550 msleep(200);
4551
4552 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4553 &data);
4554 if (rval)
4555 return rval;
4556
4557 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4558 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4559 ~(idc_lck_rcvry_stage_mask));
4560 rval = qla83xx_wr_reg(base_vha,
4561 QLA83XX_IDC_LOCK_RECOVERY, data);
4562 if (rval)
4563 return rval;
4564
4565 /* Forcefully perform IDC UnLock */
4566 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4567 &data);
4568 if (rval)
4569 return rval;
4570 /* Clear lock-id by setting 0xff */
4571 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4572 0xff);
4573 if (rval)
4574 return rval;
4575 /* Clear lock-recovery by setting 0x0 */
4576 rval = qla83xx_wr_reg(base_vha,
4577 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4578 if (rval)
4579 return rval;
4580 } else
4581 return QLA_SUCCESS;
4582 }
4583
4584 return rval;
4585}
4586
Saurav Kashyapfa492632012-11-21 02:40:29 -05004587static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004588qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4589{
4590 int rval = QLA_SUCCESS;
4591 uint32_t o_drv_lockid, n_drv_lockid;
4592 unsigned long lock_recovery_timeout;
4593
4594 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4595retry_lockid:
4596 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4597 if (rval)
4598 goto exit;
4599
4600 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4601 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4602 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4603 return QLA_SUCCESS;
4604 else
4605 return QLA_FUNCTION_FAILED;
4606 }
4607
4608 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4609 if (rval)
4610 goto exit;
4611
4612 if (o_drv_lockid == n_drv_lockid) {
4613 qla83xx_wait_logic();
4614 goto retry_lockid;
4615 } else
4616 return QLA_SUCCESS;
4617
4618exit:
4619 return rval;
4620}
4621
4622void
4623qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4624{
4625 uint16_t options = (requester_id << 15) | BIT_6;
4626 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004627 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004628 struct qla_hw_data *ha = base_vha->hw;
4629
4630 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4631retry_lock:
4632 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4633 == QLA_SUCCESS) {
4634 if (data) {
4635 /* Setting lock-id to our function-number */
4636 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4637 ha->portnum);
4638 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004639 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4640 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004641 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004642 "Failed to acquire IDC lock, acquired by %d, "
4643 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004644
4645 /* Retry/Perform IDC-Lock recovery */
4646 if (qla83xx_idc_lock_recovery(base_vha)
4647 == QLA_SUCCESS) {
4648 qla83xx_wait_logic();
4649 goto retry_lock;
4650 } else
4651 ql_log(ql_log_warn, base_vha, 0xb075,
4652 "IDC Lock recovery FAILED.\n");
4653 }
4654
4655 }
4656
4657 return;
4658
4659 /* XXX: IDC-lock implementation using access-control mbx */
4660retry_lock2:
4661 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4662 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4663 "Failed to acquire IDC lock. retrying...\n");
4664 /* Retry/Perform IDC-Lock recovery */
4665 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4666 qla83xx_wait_logic();
4667 goto retry_lock2;
4668 } else
4669 ql_log(ql_log_warn, base_vha, 0xb076,
4670 "IDC Lock recovery FAILED.\n");
4671 }
4672
4673 return;
4674}
4675
4676void
4677qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4678{
Bart Van Assche5897cb22015-06-04 15:57:20 -07004679#if 0
4680 uint16_t options = (requester_id << 15) | BIT_7;
4681#endif
4682 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004683 uint32_t data;
4684 struct qla_hw_data *ha = base_vha->hw;
4685
4686 /* IDC-unlock implementation using driver-unlock/lock-id
4687 * remote registers
4688 */
4689 retry = 0;
4690retry_unlock:
4691 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4692 == QLA_SUCCESS) {
4693 if (data == ha->portnum) {
4694 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4695 /* Clearing lock-id by setting 0xff */
4696 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4697 } else if (retry < 10) {
4698 /* SV: XXX: IDC unlock retrying needed here? */
4699
4700 /* Retry for IDC-unlock */
4701 qla83xx_wait_logic();
4702 retry++;
4703 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01004704 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004705 goto retry_unlock;
4706 }
4707 } else if (retry < 10) {
4708 /* Retry for IDC-unlock */
4709 qla83xx_wait_logic();
4710 retry++;
4711 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01004712 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004713 goto retry_unlock;
4714 }
4715
4716 return;
4717
Bart Van Assche5897cb22015-06-04 15:57:20 -07004718#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004719 /* XXX: IDC-unlock implementation using access-control mbx */
4720 retry = 0;
4721retry_unlock2:
4722 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4723 if (retry < 10) {
4724 /* Retry for IDC-unlock */
4725 qla83xx_wait_logic();
4726 retry++;
4727 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01004728 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004729 goto retry_unlock2;
4730 }
4731 }
4732
4733 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07004734#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004735}
4736
4737int
4738__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4739{
4740 int rval = QLA_SUCCESS;
4741 struct qla_hw_data *ha = vha->hw;
4742 uint32_t drv_presence;
4743
4744 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4745 if (rval == QLA_SUCCESS) {
4746 drv_presence |= (1 << ha->portnum);
4747 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4748 drv_presence);
4749 }
4750
4751 return rval;
4752}
4753
4754int
4755qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4756{
4757 int rval = QLA_SUCCESS;
4758
4759 qla83xx_idc_lock(vha, 0);
4760 rval = __qla83xx_set_drv_presence(vha);
4761 qla83xx_idc_unlock(vha, 0);
4762
4763 return rval;
4764}
4765
4766int
4767__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4768{
4769 int rval = QLA_SUCCESS;
4770 struct qla_hw_data *ha = vha->hw;
4771 uint32_t drv_presence;
4772
4773 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4774 if (rval == QLA_SUCCESS) {
4775 drv_presence &= ~(1 << ha->portnum);
4776 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4777 drv_presence);
4778 }
4779
4780 return rval;
4781}
4782
4783int
4784qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4785{
4786 int rval = QLA_SUCCESS;
4787
4788 qla83xx_idc_lock(vha, 0);
4789 rval = __qla83xx_clear_drv_presence(vha);
4790 qla83xx_idc_unlock(vha, 0);
4791
4792 return rval;
4793}
4794
Saurav Kashyapfa492632012-11-21 02:40:29 -05004795static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004796qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4797{
4798 struct qla_hw_data *ha = vha->hw;
4799 uint32_t drv_ack, drv_presence;
4800 unsigned long ack_timeout;
4801
4802 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4803 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4804 while (1) {
4805 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4806 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004807 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004808 break;
4809
4810 if (time_after_eq(jiffies, ack_timeout)) {
4811 ql_log(ql_log_warn, vha, 0xb067,
4812 "RESET ACK TIMEOUT! drv_presence=0x%x "
4813 "drv_ack=0x%x\n", drv_presence, drv_ack);
4814 /*
4815 * The function(s) which did not ack in time are forced
4816 * to withdraw any further participation in the IDC
4817 * reset.
4818 */
4819 if (drv_ack != drv_presence)
4820 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4821 drv_ack);
4822 break;
4823 }
4824
4825 qla83xx_idc_unlock(vha, 0);
4826 msleep(1000);
4827 qla83xx_idc_lock(vha, 0);
4828 }
4829
4830 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4831 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4832}
4833
Saurav Kashyapfa492632012-11-21 02:40:29 -05004834static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004835qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4836{
4837 int rval = QLA_SUCCESS;
4838 uint32_t idc_control;
4839
4840 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4841 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4842
4843 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4844 __qla83xx_get_idc_control(vha, &idc_control);
4845 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4846 __qla83xx_set_idc_control(vha, 0);
4847
4848 qla83xx_idc_unlock(vha, 0);
4849 rval = qla83xx_restart_nic_firmware(vha);
4850 qla83xx_idc_lock(vha, 0);
4851
4852 if (rval != QLA_SUCCESS) {
4853 ql_log(ql_log_fatal, vha, 0xb06a,
4854 "Failed to restart NIC f/w.\n");
4855 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4856 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4857 } else {
4858 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4859 "Success in restarting nic f/w.\n");
4860 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4861 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4862 }
4863
4864 return rval;
4865}
4866
4867/* Assumes idc_lock always held on entry */
4868int
4869qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4870{
4871 struct qla_hw_data *ha = base_vha->hw;
4872 int rval = QLA_SUCCESS;
4873 unsigned long dev_init_timeout;
4874 uint32_t dev_state;
4875
4876 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4877 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4878
4879 while (1) {
4880
4881 if (time_after_eq(jiffies, dev_init_timeout)) {
4882 ql_log(ql_log_warn, base_vha, 0xb06e,
4883 "Initialization TIMEOUT!\n");
4884 /* Init timeout. Disable further NIC Core
4885 * communication.
4886 */
4887 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4888 QLA8XXX_DEV_FAILED);
4889 ql_log(ql_log_info, base_vha, 0xb06f,
4890 "HW State: FAILED.\n");
4891 }
4892
4893 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4894 switch (dev_state) {
4895 case QLA8XXX_DEV_READY:
4896 if (ha->flags.nic_core_reset_owner)
4897 qla83xx_idc_audit(base_vha,
4898 IDC_AUDIT_COMPLETION);
4899 ha->flags.nic_core_reset_owner = 0;
4900 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4901 "Reset_owner reset by 0x%x.\n",
4902 ha->portnum);
4903 goto exit;
4904 case QLA8XXX_DEV_COLD:
4905 if (ha->flags.nic_core_reset_owner)
4906 rval = qla83xx_device_bootstrap(base_vha);
4907 else {
4908 /* Wait for AEN to change device-state */
4909 qla83xx_idc_unlock(base_vha, 0);
4910 msleep(1000);
4911 qla83xx_idc_lock(base_vha, 0);
4912 }
4913 break;
4914 case QLA8XXX_DEV_INITIALIZING:
4915 /* Wait for AEN to change device-state */
4916 qla83xx_idc_unlock(base_vha, 0);
4917 msleep(1000);
4918 qla83xx_idc_lock(base_vha, 0);
4919 break;
4920 case QLA8XXX_DEV_NEED_RESET:
4921 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4922 qla83xx_need_reset_handler(base_vha);
4923 else {
4924 /* Wait for AEN to change device-state */
4925 qla83xx_idc_unlock(base_vha, 0);
4926 msleep(1000);
4927 qla83xx_idc_lock(base_vha, 0);
4928 }
4929 /* reset timeout value after need reset handler */
4930 dev_init_timeout = jiffies +
4931 (ha->fcoe_dev_init_timeout * HZ);
4932 break;
4933 case QLA8XXX_DEV_NEED_QUIESCENT:
4934 /* XXX: DEBUG for now */
4935 qla83xx_idc_unlock(base_vha, 0);
4936 msleep(1000);
4937 qla83xx_idc_lock(base_vha, 0);
4938 break;
4939 case QLA8XXX_DEV_QUIESCENT:
4940 /* XXX: DEBUG for now */
4941 if (ha->flags.quiesce_owner)
4942 goto exit;
4943
4944 qla83xx_idc_unlock(base_vha, 0);
4945 msleep(1000);
4946 qla83xx_idc_lock(base_vha, 0);
4947 dev_init_timeout = jiffies +
4948 (ha->fcoe_dev_init_timeout * HZ);
4949 break;
4950 case QLA8XXX_DEV_FAILED:
4951 if (ha->flags.nic_core_reset_owner)
4952 qla83xx_idc_audit(base_vha,
4953 IDC_AUDIT_COMPLETION);
4954 ha->flags.nic_core_reset_owner = 0;
4955 __qla83xx_clear_drv_presence(base_vha);
4956 qla83xx_idc_unlock(base_vha, 0);
4957 qla8xxx_dev_failed_handler(base_vha);
4958 rval = QLA_FUNCTION_FAILED;
4959 qla83xx_idc_lock(base_vha, 0);
4960 goto exit;
4961 case QLA8XXX_BAD_VALUE:
4962 qla83xx_idc_unlock(base_vha, 0);
4963 msleep(1000);
4964 qla83xx_idc_lock(base_vha, 0);
4965 break;
4966 default:
4967 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09004968 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004969 qla83xx_idc_unlock(base_vha, 0);
4970 qla8xxx_dev_failed_handler(base_vha);
4971 rval = QLA_FUNCTION_FAILED;
4972 qla83xx_idc_lock(base_vha, 0);
4973 goto exit;
4974 }
4975 }
4976
4977exit:
4978 return rval;
4979}
4980
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004981void
4982qla2x00_disable_board_on_pci_error(struct work_struct *work)
4983{
4984 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
4985 board_disable);
4986 struct pci_dev *pdev = ha->pdev;
4987 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4988
Sawan Chandak783e0dc2016-07-06 11:14:25 -04004989 /* if UNLOAD flag is already set, then continue unload,
4990 * where it was set first.
4991 */
4992 if (test_bit(UNLOADING, &base_vha->dpc_flags))
4993 return;
4994
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004995 ql_log(ql_log_warn, base_vha, 0x015b,
4996 "Disabling adapter.\n");
4997
4998 set_bit(UNLOADING, &base_vha->dpc_flags);
4999
5000 qla2x00_delete_all_vps(ha, base_vha);
5001
5002 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5003
5004 qla2x00_dfs_remove(base_vha);
5005
5006 qla84xx_put_chip(base_vha);
5007
5008 if (base_vha->timer_active)
5009 qla2x00_stop_timer(base_vha);
5010
5011 base_vha->flags.online = 0;
5012
5013 qla2x00_destroy_deferred_work(ha);
5014
5015 /*
5016 * Do not try to stop beacon blink as it will issue a mailbox
5017 * command.
5018 */
5019 qla2x00_free_sysfs_attr(base_vha, false);
5020
5021 fc_remove_host(base_vha->host);
5022
5023 scsi_remove_host(base_vha->host);
5024
5025 base_vha->flags.init_done = 0;
5026 qla25xx_delete_queues(base_vha);
5027 qla2x00_free_irqs(base_vha);
5028 qla2x00_free_fcports(base_vha);
5029 qla2x00_mem_free(ha);
5030 qla82xx_md_free(base_vha);
5031 qla2x00_free_queues(ha);
5032
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005033 qla2x00_unmap_iobases(ha);
5034
5035 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005036 pci_disable_pcie_error_reporting(pdev);
5037 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005038
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005039 /*
5040 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5041 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005042}
5043
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044/**************************************************************************
5045* qla2x00_do_dpc
5046* This kernel thread is a task that is schedule by the interrupt handler
5047* to perform the background processing for interrupts.
5048*
5049* Notes:
5050* This task always run in the context of a kernel thread. It
5051* is kick-off by the driver's detect code and starts up
5052* up one per adapter. It immediately goes to sleep and waits for
5053* some fibre event. When either the interrupt handler or
5054* the timer routine detects a event it will one of the task
5055* bits then wake us up.
5056**************************************************************************/
5057static int
5058qla2x00_do_dpc(void *data)
5059{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005060 scsi_qla_host_t *base_vha;
5061 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005062
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005063 ha = (struct qla_hw_data *)data;
5064 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065
Dongsheng Yang8698a742014-03-11 18:09:12 +08005066 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067
James Bottomley563585e2011-01-27 16:12:37 -05005068 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005069 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005070 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5071 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072
Christoph Hellwig39a11242006-02-14 18:46:22 +01005073 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005075 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5076 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077
Andrew Vasquez85880802009-12-15 21:29:46 -08005078 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005079 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5080 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005081 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005082 }
5083
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 ha->dpc_active = 1;
5085
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005086 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5087 "DPC handler waking up, dpc_flags=0x%lx.\n",
5088 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005090 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5091 break;
5092
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005093 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005094
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005095 if (IS_P3P_TYPE(ha)) {
5096 if (IS_QLA8044(ha)) {
5097 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5098 &base_vha->dpc_flags)) {
5099 qla8044_idc_lock(ha);
5100 qla8044_wr_direct(base_vha,
5101 QLA8044_CRB_DEV_STATE_INDEX,
5102 QLA8XXX_DEV_FAILED);
5103 qla8044_idc_unlock(ha);
5104 ql_log(ql_log_info, base_vha, 0x4004,
5105 "HW State: FAILED.\n");
5106 qla8044_device_state_handler(base_vha);
5107 continue;
5108 }
5109
5110 } else {
5111 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5112 &base_vha->dpc_flags)) {
5113 qla82xx_idc_lock(ha);
5114 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5115 QLA8XXX_DEV_FAILED);
5116 qla82xx_idc_unlock(ha);
5117 ql_log(ql_log_info, base_vha, 0x0151,
5118 "HW State: FAILED.\n");
5119 qla82xx_device_state_handler(base_vha);
5120 continue;
5121 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005122 }
5123
5124 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5125 &base_vha->dpc_flags)) {
5126
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005127 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5128 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005129 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5130 &base_vha->dpc_flags))) {
5131 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5132 /* FCoE-ctx reset failed.
5133 * Escalate to chip-reset
5134 */
5135 set_bit(ISP_ABORT_NEEDED,
5136 &base_vha->dpc_flags);
5137 }
5138 clear_bit(ABORT_ISP_ACTIVE,
5139 &base_vha->dpc_flags);
5140 }
5141
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005142 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5143 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005144 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005145 } else if (IS_QLAFX00(ha)) {
5146 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5147 &base_vha->dpc_flags)) {
5148 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5149 "Firmware Reset Recovery\n");
5150 if (qlafx00_reset_initialize(base_vha)) {
5151 /* Failed. Abort isp later. */
5152 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005153 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005154 set_bit(ISP_UNRECOVERABLE,
5155 &base_vha->dpc_flags);
5156 ql_dbg(ql_dbg_dpc, base_vha,
5157 0x4021,
5158 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005159 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005160 }
5161 }
5162
5163 if (test_and_clear_bit(FX00_TARGET_SCAN,
5164 &base_vha->dpc_flags)) {
5165 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5166 "ISPFx00 Target Scan scheduled\n");
5167 if (qlafx00_rescan_isp(base_vha)) {
5168 if (!test_bit(UNLOADING,
5169 &base_vha->dpc_flags))
5170 set_bit(ISP_UNRECOVERABLE,
5171 &base_vha->dpc_flags);
5172 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5173 "ISPFx00 Target Scan Failed\n");
5174 }
5175 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5176 "ISPFx00 Target Scan End\n");
5177 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005178 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5179 &base_vha->dpc_flags)) {
5180 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5181 "ISPFx00 Host Info resend scheduled\n");
5182 qlafx00_fx_disc(base_vha,
5183 &base_vha->hw->mr.fcport,
5184 FXDISC_REG_HOST_INFO);
5185 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005186 }
5187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005188 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5189 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005191 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5192 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005194 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195
Giridhar Malavalia9083012010-04-12 17:59:55 -07005196 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 /* failed. retry later */
5198 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005199 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005201 clear_bit(ABORT_ISP_ACTIVE,
5202 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005203 }
5204
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005205 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5206 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 }
5208
David Jefferya394aac2012-11-21 02:39:54 -05005209 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5210 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005211 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005212 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005213
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005214 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
5215 int ret;
5216 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
5217 if (ret != QLA_SUCCESS)
5218 ql_log(ql_log_warn, base_vha, 0x121,
5219 "Failed to enable receiving of RSCN "
5220 "requests: 0x%x.\n", ret);
5221 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
5222 }
5223
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005224 if (IS_QLAFX00(ha))
5225 goto loop_resync_check;
5226
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005227 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005228 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5229 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005230 if (IS_P3P_TYPE(ha)) {
5231 if (IS_QLA82XX(ha))
5232 qla82xx_device_state_handler(base_vha);
5233 if (IS_QLA8044(ha))
5234 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005235 clear_bit(ISP_QUIESCE_NEEDED,
5236 &base_vha->dpc_flags);
5237 if (!ha->flags.quiesce_owner) {
5238 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005239 if (IS_QLA82XX(ha)) {
5240 qla82xx_idc_lock(ha);
5241 qla82xx_clear_qsnt_ready(
5242 base_vha);
5243 qla82xx_idc_unlock(ha);
5244 } else if (IS_QLA8044(ha)) {
5245 qla8044_idc_lock(ha);
5246 qla8044_clear_qsnt_ready(
5247 base_vha);
5248 qla8044_idc_unlock(ha);
5249 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005250 }
5251 } else {
5252 clear_bit(ISP_QUIESCE_NEEDED,
5253 &base_vha->dpc_flags);
5254 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005255 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005256 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5257 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005258 }
5259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005260 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005261 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005262 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005264 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5265 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005266 qla2x00_rst_aen(base_vha);
5267 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005268 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5269 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 }
5271
5272 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005273 if ((test_and_clear_bit(RELOGIN_NEEDED,
5274 &base_vha->dpc_flags)) &&
5275 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5276 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005278 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5279 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005280 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005281 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5282 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005284loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005285 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005286 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005288 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5289 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290
5291 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005292 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293
Bart Van Assche52c82822015-07-09 07:23:26 -07005294 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005295
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005296 clear_bit(LOOP_RESYNC_ACTIVE,
5297 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 }
5299
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005300 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5301 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 }
5303
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005304 if (IS_QLAFX00(ha))
5305 goto intr_on_check;
5306
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005307 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5308 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5309 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5310 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005311 }
5312
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005313intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005315 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005317 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005318 &base_vha->dpc_flags)) {
5319 if (ha->beacon_blink_led == 1)
5320 ha->isp_ops->beacon_blink(base_vha);
5321 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005322
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005323 if (!IS_QLAFX00(ha))
5324 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005325
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005327end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005328 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005330 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005332 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5333 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334
5335 /*
5336 * Make sure that nobody tries to wake us up again.
5337 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338 ha->dpc_active = 0;
5339
Andrew Vasquezac280b62009-08-20 11:06:05 -07005340 /* Cleanup any residual CTX SRBs. */
5341 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5342
Christoph Hellwig39a11242006-02-14 18:46:22 +01005343 return 0;
5344}
5345
5346void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005347qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005348{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005349 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005350 struct task_struct *t = ha->dpc_thread;
5351
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005352 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005353 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354}
5355
5356/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357* qla2x00_rst_aen
5358* Processes asynchronous reset.
5359*
5360* Input:
5361* ha = adapter block pointer.
5362*/
5363static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005364qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005366 if (vha->flags.online && !vha->flags.reset_active &&
5367 !atomic_read(&vha->loop_down_timer) &&
5368 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005370 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371
5372 /*
5373 * Issue marker command only when we are going to start
5374 * the I/O.
5375 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005376 vha->marker_needed = 1;
5377 } while (!atomic_read(&vha->loop_down_timer) &&
5378 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379 }
5380}
5381
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382/**************************************************************************
5383* qla2x00_timer
5384*
5385* Description:
5386* One second timer
5387*
5388* Context: Interrupt
5389***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005390void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005391qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 int start_dpc = 0;
5395 int index;
5396 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005397 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005398 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005399 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005400
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005401 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005402 ql_dbg(ql_dbg_timer, vha, 0x6000,
5403 "EEH = %d, restarting timer.\n",
5404 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005405 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5406 return;
5407 }
5408
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005409 /*
5410 * Hardware read to raise pending EEH errors during mailbox waits. If
5411 * the read returns -1 then disable the board.
5412 */
5413 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005414 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005415 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005418 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005419 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005420 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5421 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005422 if (IS_QLA82XX(ha))
5423 qla82xx_watchdog(vha);
5424 else if (IS_QLA8044(ha))
5425 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005426 }
5427
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005428 if (!vha->vp_idx && IS_QLAFX00(ha))
5429 qlafx00_timer_routine(vha);
5430
Linus Torvalds1da177e2005-04-16 15:20:36 -07005431 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005432 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005433 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5434 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005435 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005437 if (atomic_read(&vha->loop_down_timer) ==
5438 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005440 ql_log(ql_log_info, vha, 0x6008,
5441 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005443 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5444 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005446 /*
5447 * Schedule an ISP abort to return any FCP2-device
5448 * commands.
5449 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005450 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005451 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005452 spin_lock_irqsave(&ha->hardware_lock,
5453 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005454 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005455 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005456 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005457 index++) {
5458 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005460 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005461 if (!sp)
5462 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005463 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005464 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005465 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005466 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005467 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005469 if (IS_QLA82XX(ha))
5470 set_bit(FCOE_CTX_RESET_NEEDED,
5471 &vha->dpc_flags);
5472 else
5473 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005474 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005475 break;
5476 }
5477 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005478 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 start_dpc++;
5481 }
5482
5483 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005484 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005485 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005486 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 "Loop down - aborting ISP.\n");
5488
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005489 if (IS_QLA82XX(ha))
5490 set_bit(FCOE_CTX_RESET_NEEDED,
5491 &vha->dpc_flags);
5492 else
5493 set_bit(ISP_ABORT_NEEDED,
5494 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 }
5496 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005497 ql_dbg(ql_dbg_timer, vha, 0x600a,
5498 "Loop down - seconds remaining %d.\n",
5499 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005500 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005501 /* Check if beacon LED needs to be blinked for physical host only */
5502 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005503 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005504 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005505 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5506 start_dpc++;
5507 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005508 }
5509
Andrew Vasquez550bf572008-04-24 15:21:23 -07005510 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005511 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005512 start_dpc++;
5513
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005515 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5516 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5517 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005519 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5520 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005521 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5522 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005523 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005524 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005525 ql_dbg(ql_dbg_timer, vha, 0x600b,
5526 "isp_abort_needed=%d loop_resync_needed=%d "
5527 "fcport_update_needed=%d start_dpc=%d "
5528 "reset_marker_needed=%d",
5529 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5530 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5531 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5532 start_dpc,
5533 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5534 ql_dbg(ql_dbg_timer, vha, 0x600c,
5535 "beacon_blink_needed=%d isp_unrecoverable=%d "
5536 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005537 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005538 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5539 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5540 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5541 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005542 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005543 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005546 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005547}
5548
Andrew Vasquez54333832005-11-09 15:49:04 -08005549/* Firmware interface routines. */
5550
Chad Dupuisf73cb692014-02-26 04:15:06 -05005551#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08005552#define FW_ISP21XX 0
5553#define FW_ISP22XX 1
5554#define FW_ISP2300 2
5555#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005556#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005557#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005558#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005559#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005560#define FW_ISP2031 8
5561#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005562#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005563
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005564#define FW_FILE_ISP21XX "ql2100_fw.bin"
5565#define FW_FILE_ISP22XX "ql2200_fw.bin"
5566#define FW_FILE_ISP2300 "ql2300_fw.bin"
5567#define FW_FILE_ISP2322 "ql2322_fw.bin"
5568#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005569#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005570#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005571#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005572#define FW_FILE_ISP2031 "ql2600_fw.bin"
5573#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005574#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05005575
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005576
Daniel Walkere1e82b62008-05-12 22:21:10 -07005577static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005578
5579static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005580 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5581 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5582 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5583 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5584 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005585 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005586 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005587 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005588 { .name = FW_FILE_ISP2031, },
5589 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005590 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005591};
5592
5593struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005594qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005595{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005596 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005597 struct fw_blob *blob;
5598
Andrew Vasquez54333832005-11-09 15:49:04 -08005599 if (IS_QLA2100(ha)) {
5600 blob = &qla_fw_blobs[FW_ISP21XX];
5601 } else if (IS_QLA2200(ha)) {
5602 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005603 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005604 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005605 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005606 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005607 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005608 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005609 } else if (IS_QLA25XX(ha)) {
5610 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005611 } else if (IS_QLA81XX(ha)) {
5612 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005613 } else if (IS_QLA82XX(ha)) {
5614 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005615 } else if (IS_QLA2031(ha)) {
5616 blob = &qla_fw_blobs[FW_ISP2031];
5617 } else if (IS_QLA8031(ha)) {
5618 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005619 } else if (IS_QLA27XX(ha)) {
5620 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03005621 } else {
5622 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005623 }
5624
Daniel Walkere1e82b62008-05-12 22:21:10 -07005625 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005626 if (blob->fw)
5627 goto out;
5628
5629 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005630 ql_log(ql_log_warn, vha, 0x0063,
5631 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005632 blob->fw = NULL;
5633 blob = NULL;
5634 goto out;
5635 }
5636
5637out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005638 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005639 return blob;
5640}
5641
5642static void
5643qla2x00_release_firmware(void)
5644{
5645 int idx;
5646
Daniel Walkere1e82b62008-05-12 22:21:10 -07005647 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005648 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005649 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005650 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005651}
5652
Seokmann Ju14e660e2007-09-20 14:07:36 -07005653static pci_ers_result_t
5654qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5655{
Andrew Vasquez85880802009-12-15 21:29:46 -08005656 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5657 struct qla_hw_data *ha = vha->hw;
5658
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005659 ql_dbg(ql_dbg_aer, vha, 0x9000,
5660 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005661
Seokmann Ju14e660e2007-09-20 14:07:36 -07005662 switch (state) {
5663 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005664 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005665 return PCI_ERS_RESULT_CAN_RECOVER;
5666 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005667 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005668 /* For ISP82XX complete any pending mailbox cmd */
5669 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005670 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005671 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5672 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005673 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005674 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005675 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005676 /* Return back all IOs */
5677 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005678 return PCI_ERS_RESULT_NEED_RESET;
5679 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005680 ha->flags.pci_channel_io_perm_failure = 1;
5681 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005682 return PCI_ERS_RESULT_DISCONNECT;
5683 }
5684 return PCI_ERS_RESULT_NEED_RESET;
5685}
5686
5687static pci_ers_result_t
5688qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5689{
5690 int risc_paused = 0;
5691 uint32_t stat;
5692 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005693 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5694 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005695 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5696 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5697
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005698 if (IS_QLA82XX(ha))
5699 return PCI_ERS_RESULT_RECOVERED;
5700
Seokmann Ju14e660e2007-09-20 14:07:36 -07005701 spin_lock_irqsave(&ha->hardware_lock, flags);
5702 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5703 stat = RD_REG_DWORD(&reg->hccr);
5704 if (stat & HCCR_RISC_PAUSE)
5705 risc_paused = 1;
5706 } else if (IS_QLA23XX(ha)) {
5707 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5708 if (stat & HSR_RISC_PAUSED)
5709 risc_paused = 1;
5710 } else if (IS_FWI2_CAPABLE(ha)) {
5711 stat = RD_REG_DWORD(&reg24->host_status);
5712 if (stat & HSRX_RISC_PAUSED)
5713 risc_paused = 1;
5714 }
5715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5716
5717 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005718 ql_log(ql_log_info, base_vha, 0x9003,
5719 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005720 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005721
5722 return PCI_ERS_RESULT_NEED_RESET;
5723 } else
5724 return PCI_ERS_RESULT_RECOVERED;
5725}
5726
Saurav Kashyapfa492632012-11-21 02:40:29 -05005727static uint32_t
5728qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005729{
5730 uint32_t rval = QLA_FUNCTION_FAILED;
5731 uint32_t drv_active = 0;
5732 struct qla_hw_data *ha = base_vha->hw;
5733 int fn;
5734 struct pci_dev *other_pdev = NULL;
5735
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005736 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5737 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005738
5739 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5740
5741 if (base_vha->flags.online) {
5742 /* Abort all outstanding commands,
5743 * so as to be requeued later */
5744 qla2x00_abort_isp_cleanup(base_vha);
5745 }
5746
5747
5748 fn = PCI_FUNC(ha->pdev->devfn);
5749 while (fn > 0) {
5750 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005751 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5752 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005753 other_pdev =
5754 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5755 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5756 fn));
5757
5758 if (!other_pdev)
5759 continue;
5760 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005761 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5762 "Found PCI func available and enable at 0x%x.\n",
5763 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005764 pci_dev_put(other_pdev);
5765 break;
5766 }
5767 pci_dev_put(other_pdev);
5768 }
5769
5770 if (!fn) {
5771 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005772 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5773 "This devfn is reset owner = 0x%x.\n",
5774 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005775 qla82xx_idc_lock(ha);
5776
5777 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005778 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005779
5780 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5781 QLA82XX_IDC_VERSION);
5782
5783 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005784 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5785 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005786
5787 qla82xx_idc_unlock(ha);
5788 /* Reset if device is not already reset
5789 * drv_active would be 0 if a reset has already been done
5790 */
5791 if (drv_active)
5792 rval = qla82xx_start_firmware(base_vha);
5793 else
5794 rval = QLA_SUCCESS;
5795 qla82xx_idc_lock(ha);
5796
5797 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005798 ql_log(ql_log_info, base_vha, 0x900b,
5799 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005800 qla82xx_clear_drv_active(ha);
5801 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005802 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005803 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005804 ql_log(ql_log_info, base_vha, 0x900c,
5805 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005806 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005807 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005808 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005809 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005810 rval = qla82xx_restart_isp(base_vha);
5811 qla82xx_idc_lock(ha);
5812 /* Clear driver state register */
5813 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5814 qla82xx_set_drv_active(base_vha);
5815 }
5816 qla82xx_idc_unlock(ha);
5817 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005818 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5819 "This devfn is not reset owner = 0x%x.\n",
5820 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005821 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005822 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005823 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005824 rval = qla82xx_restart_isp(base_vha);
5825 qla82xx_idc_lock(ha);
5826 qla82xx_set_drv_active(base_vha);
5827 qla82xx_idc_unlock(ha);
5828 }
5829 }
5830 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5831
5832 return rval;
5833}
5834
Seokmann Ju14e660e2007-09-20 14:07:36 -07005835static pci_ers_result_t
5836qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5837{
5838 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005839 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5840 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005841 struct rsp_que *rsp;
5842 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005843
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005844 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5845 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005846
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005847 /* Workaround: qla2xxx driver which access hardware earlier
5848 * needs error state to be pci_channel_io_online.
5849 * Otherwise mailbox command timesout.
5850 */
5851 pdev->error_state = pci_channel_io_normal;
5852
5853 pci_restore_state(pdev);
5854
Richard Lary8c1496b2010-02-18 10:07:29 -08005855 /* pci_restore_state() clears the saved_state flag of the device
5856 * save restored state which resets saved_state flag
5857 */
5858 pci_save_state(pdev);
5859
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005860 if (ha->mem_only)
5861 rc = pci_enable_device_mem(pdev);
5862 else
5863 rc = pci_enable_device(pdev);
5864
5865 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005866 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005867 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005868 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005869 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005870
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005871 rsp = ha->rsp_q_map[0];
5872 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005873 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005875 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005876 goto exit_slot_reset;
5877
5878 if (IS_QLA82XX(ha)) {
5879 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5880 ret = PCI_ERS_RESULT_RECOVERED;
5881 goto exit_slot_reset;
5882 } else
5883 goto exit_slot_reset;
5884 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005885
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005886 while (ha->flags.mbox_busy && retries--)
5887 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005889 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005890 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005891 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005892 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005893
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005894
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005895exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005896 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5897 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005898
Seokmann Ju14e660e2007-09-20 14:07:36 -07005899 return ret;
5900}
5901
5902static void
5903qla2xxx_pci_resume(struct pci_dev *pdev)
5904{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005905 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5906 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005907 int ret;
5908
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005909 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5910 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005912 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005913 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005914 ql_log(ql_log_fatal, base_vha, 0x9002,
5915 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005916 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005917
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005918 pci_cleanup_aer_uncorrect_error_status(pdev);
5919
Andrew Vasquez85880802009-12-15 21:29:46 -08005920 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005921}
5922
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04005923static void
5924qla83xx_disable_laser(scsi_qla_host_t *vha)
5925{
5926 uint32_t reg, data, fn;
5927 struct qla_hw_data *ha = vha->hw;
5928 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5929
5930 /* pci func #/port # */
5931 ql_dbg(ql_dbg_init, vha, 0x004b,
5932 "Disabling Laser for hba: %p\n", vha);
5933
5934 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5935 (BIT_15|BIT_14|BIT_13|BIT_12));
5936
5937 fn = (fn >> 12);
5938
5939 if (fn & 1)
5940 reg = PORT_1_2031;
5941 else
5942 reg = PORT_0_2031;
5943
5944 data = LASER_OFF_2031;
5945
5946 qla83xx_wr_reg(vha, reg, data);
5947}
5948
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005949static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005950 .error_detected = qla2xxx_pci_error_detected,
5951 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5952 .slot_reset = qla2xxx_pci_slot_reset,
5953 .resume = qla2xxx_pci_resume,
5954};
5955
Andrew Vasquez54333832005-11-09 15:49:04 -08005956static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005957 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5958 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5959 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5960 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5961 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5962 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5963 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5964 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5965 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005966 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005967 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5968 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005969 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005970 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005971 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005972 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005973 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005974 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005975 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05005976 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005977 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04005978 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005979 { 0 },
5980};
5981MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5982
Andrew Vasquezfca29702005-07-06 10:31:47 -07005983static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005984 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005985 .driver = {
5986 .owner = THIS_MODULE,
5987 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005988 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005989 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005990 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005991 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005992 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005993};
5994
Al Viro75ef9de2013-04-04 19:09:41 -04005995static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005996 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005997 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005998};
5999
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000/**
6001 * qla2x00_module_init - Module initialization.
6002 **/
6003static int __init
6004qla2x00_module_init(void)
6005{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006006 int ret = 0;
6007
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006009 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006010 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006012 ql_log(ql_log_fatal, NULL, 0x0001,
6013 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 return -ENOMEM;
6015 }
6016
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006017 /* Initialize target kmem_cache and mem_pools */
6018 ret = qlt_init();
6019 if (ret < 0) {
6020 kmem_cache_destroy(srb_cachep);
6021 return ret;
6022 } else if (ret > 0) {
6023 /*
6024 * If initiator mode is explictly disabled by qlt_init(),
6025 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6026 * performing scsi_scan_target() during LOOP UP event.
6027 */
6028 qla2xxx_transport_functions.disable_target_scan = 1;
6029 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6030 }
6031
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032 /* Derive version string. */
6033 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006034 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006035 strcat(qla2x00_version_str, "-debug");
6036
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006037 qla2xxx_transport_template =
6038 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006039 if (!qla2xxx_transport_template) {
6040 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006041 ql_log(ql_log_fatal, NULL, 0x0002,
6042 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006043 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006045 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006046
6047 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6048 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006049 ql_log(ql_log_fatal, NULL, 0x0003,
6050 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006051 }
6052
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006053 qla2xxx_transport_vport_template =
6054 fc_attach_transport(&qla2xxx_transport_vport_functions);
6055 if (!qla2xxx_transport_vport_template) {
6056 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006057 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006058 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006059 ql_log(ql_log_fatal, NULL, 0x0004,
6060 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006061 return -ENODEV;
6062 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006063 ql_log(ql_log_info, NULL, 0x0005,
6064 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006065 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006066 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006067 if (ret) {
6068 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006069 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006070 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006071 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006072 ql_log(ql_log_fatal, NULL, 0x0006,
6073 "pci_register_driver failed...ret=%d Failing load!.\n",
6074 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006075 }
6076 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077}
6078
6079/**
6080 * qla2x00_module_exit - Module cleanup.
6081 **/
6082static void __exit
6083qla2x00_module_exit(void)
6084{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006085 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006086 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006087 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006088 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006089 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006090 if (ctx_cachep)
6091 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006093 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094}
6095
6096module_init(qla2x00_module_init);
6097module_exit(qla2x00_module_exit);
6098
6099MODULE_AUTHOR("QLogic Corporation");
6100MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6101MODULE_LICENSE("GPL");
6102MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006103MODULE_FIRMWARE(FW_FILE_ISP21XX);
6104MODULE_FIRMWARE(FW_FILE_ISP22XX);
6105MODULE_FIRMWARE(FW_FILE_ISP2300);
6106MODULE_FIRMWARE(FW_FILE_ISP2322);
6107MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006108MODULE_FIRMWARE(FW_FILE_ISP25XX);