blob: 94630d4738e66c57ababaa6f782b7a098ba274a6 [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;
Sawan Chandak64e74692017-03-31 14:37:03 -0700971 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -0400972
Sawan Chandak64e74692017-03-31 14:37:03 -0700973 if (IS_P3P_TYPE(ha))
974 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
975 else
976 return ((RD_REG_DWORD(&reg->host_status)) ==
977 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -0400978}
979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980/**************************************************************************
981* qla2xxx_eh_abort
982*
983* Description:
984* The abort function will abort the specified command.
985*
986* Input:
987* cmd = Linux SCSI command packet to be aborted.
988*
989* Returns:
990* Either SUCCESS or FAILED.
991*
992* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700993* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800995static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996qla2xxx_eh_abort(struct scsi_cmnd *cmd)
997{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800998 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500999 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001000 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001001 unsigned int id;
1002 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001003 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001004 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001005 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Sawan Chandaka4655372016-07-06 11:14:32 -04001007 if (qla2x00_isp_reg_stat(ha)) {
1008 ql_log(ql_log_info, vha, 0x8042,
1009 "PCI/Register disconnect, exiting.\n");
1010 return FAILED;
1011 }
f4f051e2005-04-17 15:02:26 -05001012 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001013 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001015 ret = fc_block_scsi_eh(cmd);
1016 if (ret != 0)
1017 return ret;
1018 ret = SUCCESS;
1019
f4f051e2005-04-17 15:02:26 -05001020 id = cmd->device->id;
1021 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001023 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001024 sp = (srb_t *) CMD_SP(cmd);
1025 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001026 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001027 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001028 }
Mike Christie170babc2010-10-15 11:27:47 -07001029
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001030 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001031 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1032 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001033
1034 /* Get a reference to the sp and drop the lock.*/
1035 sp_get(sp);
1036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001038 rval = ha->isp_ops->abort_command(sp);
1039 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001040 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001041 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001042 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001043 ret = FAILED;
1044
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001045 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001046 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001047 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001048 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001049 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001050 wait = 1;
1051 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001052
1053 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001054 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001055 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001056
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001057 /* Did the command return during mailbox execution? */
1058 if (ret == FAILED && !CMD_SP(cmd))
1059 ret = SUCCESS;
1060
f4f051e2005-04-17 15:02:26 -05001061 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001062 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001064 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001065 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001066 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001070 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001071 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001072 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
f4f051e2005-04-17 15:02:26 -05001074 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001077int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001079 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001081 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001082 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001083 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001084 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001085 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001086 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Andrew Vasquez523ec772008-04-03 13:13:24 -07001088 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001089
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001090 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001091 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001092 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001093 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001094 sp = req->outstanding_cmds[cnt];
1095 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001096 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001097 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001098 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001099 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1100 continue;
1101 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001102 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001103 switch (type) {
1104 case WAIT_HOST:
1105 match = 1;
1106 break;
1107 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001108 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001109 break;
1110 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001111 match = (cmd->device->id == t &&
1112 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001113 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001115 if (!match)
1116 continue;
1117
1118 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001119 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001120 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001123
1124 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
Andrew Vasquez523ec772008-04-03 13:13:24 -07001127static char *reset_errors[] = {
1128 "HBA not online",
1129 "HBA not ready",
1130 "Task management failed",
1131 "Waiting for command completions",
1132};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Andrew Vasquez523ec772008-04-03 13:13:24 -07001134static int
1135__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001136 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001137{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001139 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1140 int err;
1141
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001142 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001143 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001144 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001145
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001146 err = fc_block_scsi_eh(cmd);
1147 if (err != 0)
1148 return err;
1149
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001150 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001151 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001152 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001153
1154 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001155 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1156 ql_log(ql_log_warn, vha, 0x800a,
1157 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001158 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001159 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001160 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001161 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001162 != QLA_SUCCESS) {
1163 ql_log(ql_log_warn, vha, 0x800c,
1164 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001165 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001166 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001167 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001169 cmd->device->lun, type) != QLA_SUCCESS) {
1170 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001171 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001172 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001173 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001174
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001175 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001176 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001177 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001178
1179 return SUCCESS;
1180
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001181eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001182 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001183 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001184 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1185 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001186 return FAILED;
1187}
1188
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001189static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1191{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001192 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1193 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Sawan Chandaka4655372016-07-06 11:14:32 -04001195 if (qla2x00_isp_reg_stat(ha)) {
1196 ql_log(ql_log_info, vha, 0x803e,
1197 "PCI/Register disconnect, exiting.\n");
1198 return FAILED;
1199 }
1200
Andrew Vasquez523ec772008-04-03 13:13:24 -07001201 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1202 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001206qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1209 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Sawan Chandaka4655372016-07-06 11:14:32 -04001211 if (qla2x00_isp_reg_stat(ha)) {
1212 ql_log(ql_log_info, vha, 0x803f,
1213 "PCI/Register disconnect, exiting.\n");
1214 return FAILED;
1215 }
1216
Andrew Vasquez523ec772008-04-03 13:13:24 -07001217 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1218 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221/**************************************************************************
1222* qla2xxx_eh_bus_reset
1223*
1224* Description:
1225* The bus reset function will reset the bus and abort any executing
1226* commands.
1227*
1228* Input:
1229* cmd = Linux SCSI command packet of the command that cause the
1230* bus reset.
1231*
1232* Returns:
1233* SUCCESS/FAILURE (defined as macro in scsi.h).
1234*
1235**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001236static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1238{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001240 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001241 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001242 unsigned int id;
1243 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001244 struct qla_hw_data *ha = vha->hw;
1245
1246 if (qla2x00_isp_reg_stat(ha)) {
1247 ql_log(ql_log_info, vha, 0x8040,
1248 "PCI/Register disconnect, exiting.\n");
1249 return FAILED;
1250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
f4f051e2005-04-17 15:02:26 -05001252 id = cmd->device->id;
1253 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001254
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001255 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001256 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001259 ret = fc_block_scsi_eh(cmd);
1260 if (ret != 0)
1261 return ret;
1262 ret = FAILED;
1263
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001264 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001265 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001267 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001268 ql_log(ql_log_fatal, vha, 0x8013,
1269 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001270 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 }
1272
Saurav Kashyapad537682011-11-18 09:02:09 -08001273 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1274 ret = SUCCESS;
1275
f4f051e2005-04-17 15:02:26 -05001276 if (ret == FAILED)
1277 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001279 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001280 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001281 QLA_SUCCESS) {
1282 ql_log(ql_log_warn, vha, 0x8014,
1283 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001284 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
f4f051e2005-04-17 15:02:26 -05001287eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001288 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001289 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001290 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
f4f051e2005-04-17 15:02:26 -05001292 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
1295/**************************************************************************
1296* qla2xxx_eh_host_reset
1297*
1298* Description:
1299* The reset function will reset the Adapter.
1300*
1301* Input:
1302* cmd = Linux SCSI command packet of the command that cause the
1303* adapter reset.
1304*
1305* Returns:
1306* Either SUCCESS or FAILED.
1307*
1308* Note:
1309**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001310static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1312{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001314 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001315 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001316 unsigned int id;
1317 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001318 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Sawan Chandaka4655372016-07-06 11:14:32 -04001320 if (qla2x00_isp_reg_stat(ha)) {
1321 ql_log(ql_log_info, vha, 0x8041,
1322 "PCI/Register disconnect, exiting.\n");
1323 schedule_work(&ha->board_disable);
1324 return SUCCESS;
1325 }
1326
f4f051e2005-04-17 15:02:26 -05001327 id = cmd->device->id;
1328 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001329
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001330 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001331 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Chad Dupuis63ee7072014-04-11 16:54:46 -04001333 /*
1334 * No point in issuing another reset if one is active. Also do not
1335 * attempt a reset if we are updating flash.
1336 */
1337 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001338 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340 if (vha != base_vha) {
1341 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001342 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001344 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001345 if (!qla82xx_fcoe_ctx_reset(vha)) {
1346 /* Ctx reset success */
1347 ret = SUCCESS;
1348 goto eh_host_reset_lock;
1349 }
1350 /* fall thru if ctx reset failed */
1351 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001352 if (ha->wq)
1353 flush_workqueue(ha->wq);
1354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001356 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001357 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1358 /* failed. schedule dpc to try */
1359 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1360
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001361 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1362 ql_log(ql_log_warn, vha, 0x802a,
1363 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001364 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001365 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001366 }
1367 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001370 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001371 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001372 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001373 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
f4f051e2005-04-17 15:02:26 -05001375eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001376 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001377 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001378 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
f4f051e2005-04-17 15:02:26 -05001380 return ret;
1381}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383/*
1384* qla2x00_loop_reset
1385* Issue loop reset.
1386*
1387* Input:
1388* ha = adapter block pointer.
1389*
1390* Returns:
1391* 0 = success
1392*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001393int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001394qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001396 int ret;
bdf79622005-04-17 15:06:53 -05001397 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001398 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Armen Baloyan58547712013-08-27 01:37:33 -04001400 if (IS_QLAFX00(ha)) {
1401 return qlafx00_loop_reset(vha);
1402 }
1403
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001404 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001405 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1406 if (fcport->port_type != FCT_TARGET)
1407 continue;
1408
1409 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1410 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001412 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001413 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001414 }
1415 }
1416 }
1417
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001418
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001419 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001420 atomic_set(&vha->loop_state, LOOP_DOWN);
1421 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1422 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001423 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001424 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001425 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1426 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001430 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001431 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001432 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001433 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1434 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001435 }
1436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001438 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001440 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001443void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001445{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001446 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001447 unsigned long flags;
1448 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001450 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001451
Arun Easic0cb4492014-09-25 06:14:51 -04001452 qlt_host_reset_handler(ha);
1453
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001454 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001455 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001456 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001457 if (!req)
1458 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001459 if (!req->outstanding_cmds)
1460 continue;
1461 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001462 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001463 if (sp) {
Mauricio Faria de Oliveirac733ab32016-11-14 19:26:22 -02001464 /* Don't abort commands in adapter during EEH
1465 * recovery as it's not accessible/responding.
Mauricio Faria de Oliveira1535aa72016-11-07 17:53:31 -02001466 */
Bill Kuzeja76aa65a2017-03-14 13:28:44 -04001467 if (GET_CMD_SP(sp) && !ha->flags.eeh_busy &&
1468 (sp->type == SRB_SCSI_CMD)) {
Mauricio Faria de Oliveirac733ab32016-11-14 19:26:22 -02001469 /* Get a reference to the sp and drop the lock.
1470 * The reference ensures this sp->done() call
1471 * - and not the call in qla2xxx_eh_abort() -
1472 * ends the SCSI command (with result 'res').
1473 */
1474 sp_get(sp);
1475 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1476 qla2xxx_eh_abort(GET_CMD_SP(sp));
1477 spin_lock_irqsave(&ha->hardware_lock, flags);
1478 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001479 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001480 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001481 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001482 }
1483 }
1484 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1485}
1486
f4f051e2005-04-17 15:02:26 -05001487static int
1488qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
bdf79622005-04-17 15:06:53 -05001490 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001492 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001493 return -ENXIO;
1494
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001495 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001496
1497 return 0;
1498}
1499
1500static int
1501qla2xxx_slave_configure(struct scsi_device *sdev)
1502{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001503 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001504 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001505
Arun Easi9e522cd2012-08-22 14:21:31 -04001506 if (IS_T10_PI_CAPABLE(vha->hw))
1507 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1508
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001509 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001510 return 0;
1511}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
f4f051e2005-04-17 15:02:26 -05001513static void
1514qla2xxx_slave_destroy(struct scsi_device *sdev)
1515{
1516 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
1519/**
1520 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1521 * @ha: HA context
1522 *
1523 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1524 * supported addressing method.
1525 */
1526static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001527qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001529 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Yang Hongyang6a355282009-04-06 19:01:13 -07001532 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001533 /* Any upper-dword bits set? */
1534 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001535 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001536 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001538 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1539 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001540 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001543
Yang Hongyang284901a2009-04-06 19:01:15 -07001544 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1545 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001548static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001550{
1551 unsigned long flags = 0;
1552 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1553
1554 spin_lock_irqsave(&ha->hardware_lock, flags);
1555 ha->interrupts_on = 1;
1556 /* enable risc and host interrupts */
1557 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1558 RD_REG_WORD(&reg->ictrl);
1559 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1560
1561}
1562
1563static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001565{
1566 unsigned long flags = 0;
1567 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1568
1569 spin_lock_irqsave(&ha->hardware_lock, flags);
1570 ha->interrupts_on = 0;
1571 /* disable risc and host interrupts */
1572 WRT_REG_WORD(&reg->ictrl, 0);
1573 RD_REG_WORD(&reg->ictrl);
1574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1575}
1576
1577static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001578qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001579{
1580 unsigned long flags = 0;
1581 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1582
1583 spin_lock_irqsave(&ha->hardware_lock, flags);
1584 ha->interrupts_on = 1;
1585 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1586 RD_REG_DWORD(&reg->ictrl);
1587 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1588}
1589
1590static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001591qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001592{
1593 unsigned long flags = 0;
1594 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1595
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001596 if (IS_NOPOLLING_TYPE(ha))
1597 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001598 spin_lock_irqsave(&ha->hardware_lock, flags);
1599 ha->interrupts_on = 0;
1600 WRT_REG_DWORD(&reg->ictrl, 0);
1601 RD_REG_DWORD(&reg->ictrl);
1602 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1603}
1604
Giridhar Malavali706f4572011-11-18 09:03:16 -08001605static int
1606qla2x00_iospace_config(struct qla_hw_data *ha)
1607{
1608 resource_size_t pio;
1609 uint16_t msix;
1610 int cpus;
1611
Giridhar Malavali706f4572011-11-18 09:03:16 -08001612 if (pci_request_selected_regions(ha->pdev, ha->bars,
1613 QLA2XXX_DRIVER_NAME)) {
1614 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1615 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1616 pci_name(ha->pdev));
1617 goto iospace_error_exit;
1618 }
1619 if (!(ha->bars & 1))
1620 goto skip_pio;
1621
1622 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1623 pio = pci_resource_start(ha->pdev, 0);
1624 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1625 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1626 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1627 "Invalid pci I/O region size (%s).\n",
1628 pci_name(ha->pdev));
1629 pio = 0;
1630 }
1631 } else {
1632 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1633 "Region #0 no a PIO resource (%s).\n",
1634 pci_name(ha->pdev));
1635 pio = 0;
1636 }
1637 ha->pio_address = pio;
1638 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1639 "PIO address=%llu.\n",
1640 (unsigned long long)ha->pio_address);
1641
1642skip_pio:
1643 /* Use MMIO operations for all accesses. */
1644 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1645 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1646 "Region #1 not an MMIO resource (%s), aborting.\n",
1647 pci_name(ha->pdev));
1648 goto iospace_error_exit;
1649 }
1650 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1651 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1652 "Invalid PCI mem region size (%s), aborting.\n",
1653 pci_name(ha->pdev));
1654 goto iospace_error_exit;
1655 }
1656
1657 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1658 if (!ha->iobase) {
1659 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1660 "Cannot remap MMIO (%s), aborting.\n",
1661 pci_name(ha->pdev));
1662 goto iospace_error_exit;
1663 }
1664
1665 /* Determine queue resources */
1666 ha->max_req_queues = ha->max_rsp_queues = 1;
1667 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1668 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1669 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1670 goto mqiobase_exit;
1671
1672 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1673 pci_resource_len(ha->pdev, 3));
1674 if (ha->mqiobase) {
1675 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1676 "MQIO Base=%p.\n", ha->mqiobase);
1677 /* Read MSIX vector size of the board */
1678 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1679 ha->msix_count = msix;
1680 /* Max queues are bounded by available msix vectors */
1681 /* queue 0 uses two msix vectors */
1682 if (ql2xmultique_tag) {
1683 cpus = num_online_cpus();
1684 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1685 (cpus + 1) : (ha->msix_count - 1);
1686 ha->max_req_queues = 2;
1687 } else if (ql2xmaxqueues > 1) {
1688 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1689 QLA_MQ_SIZE : ql2xmaxqueues;
1690 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1691 "QoS mode set, max no of request queues:%d.\n",
1692 ha->max_req_queues);
1693 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1694 "QoS mode set, max no of request queues:%d.\n",
1695 ha->max_req_queues);
1696 }
1697 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1698 "MSI-X vector count: %d.\n", msix);
1699 } else
1700 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1701 "BAR 3 not enabled.\n");
1702
1703mqiobase_exit:
1704 ha->msix_count = ha->max_rsp_queues + 1;
1705 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1706 "MSIX Count:%d.\n", ha->msix_count);
1707 return (0);
1708
1709iospace_error_exit:
1710 return (-ENOMEM);
1711}
1712
1713
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001714static int
1715qla83xx_iospace_config(struct qla_hw_data *ha)
1716{
1717 uint16_t msix;
1718 int cpus;
1719
1720 if (pci_request_selected_regions(ha->pdev, ha->bars,
1721 QLA2XXX_DRIVER_NAME)) {
1722 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1723 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1724 pci_name(ha->pdev));
1725
1726 goto iospace_error_exit;
1727 }
1728
1729 /* Use MMIO operations for all accesses. */
1730 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1731 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1732 "Invalid pci I/O region size (%s).\n",
1733 pci_name(ha->pdev));
1734 goto iospace_error_exit;
1735 }
1736 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1737 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1738 "Invalid PCI mem region size (%s), aborting\n",
1739 pci_name(ha->pdev));
1740 goto iospace_error_exit;
1741 }
1742
1743 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1744 if (!ha->iobase) {
1745 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1746 "Cannot remap MMIO (%s), aborting.\n",
1747 pci_name(ha->pdev));
1748 goto iospace_error_exit;
1749 }
1750
1751 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1752 /* 83XX 26XX always use MQ type access for queues
1753 * - mbar 2, a.k.a region 4 */
1754 ha->max_req_queues = ha->max_rsp_queues = 1;
1755 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1756 pci_resource_len(ha->pdev, 4));
1757
1758 if (!ha->mqiobase) {
1759 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1760 "BAR2/region4 not enabled\n");
1761 goto mqiobase_exit;
1762 }
1763
1764 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1765 pci_resource_len(ha->pdev, 2));
1766 if (ha->msixbase) {
1767 /* Read MSIX vector size of the board */
1768 pci_read_config_word(ha->pdev,
1769 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1770 ha->msix_count = msix;
1771 /* Max queues are bounded by available msix vectors */
1772 /* queue 0 uses two msix vectors */
1773 if (ql2xmultique_tag) {
1774 cpus = num_online_cpus();
1775 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1776 (cpus + 1) : (ha->msix_count - 1);
1777 ha->max_req_queues = 2;
1778 } else if (ql2xmaxqueues > 1) {
1779 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1780 QLA_MQ_SIZE : ql2xmaxqueues;
1781 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1782 "QoS mode set, max no of request queues:%d.\n",
1783 ha->max_req_queues);
1784 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1785 "QoS mode set, max no of request queues:%d.\n",
1786 ha->max_req_queues);
1787 }
1788 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1789 "MSI-X vector count: %d.\n", msix);
1790 } else
1791 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1792 "BAR 1 not enabled.\n");
1793
1794mqiobase_exit:
1795 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001796
1797 qlt_83xx_iospace_config(ha);
1798
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001799 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1800 "MSIX Count:%d.\n", ha->msix_count);
1801 return 0;
1802
1803iospace_error_exit:
1804 return -ENOMEM;
1805}
1806
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001807static struct isp_operations qla2100_isp_ops = {
1808 .pci_config = qla2100_pci_config,
1809 .reset_chip = qla2x00_reset_chip,
1810 .chip_diag = qla2x00_chip_diag,
1811 .config_rings = qla2x00_config_rings,
1812 .reset_adapter = qla2x00_reset_adapter,
1813 .nvram_config = qla2x00_nvram_config,
1814 .update_fw_options = qla2x00_update_fw_options,
1815 .load_risc = qla2x00_load_risc,
1816 .pci_info_str = qla2x00_pci_info_str,
1817 .fw_version_str = qla2x00_fw_version_str,
1818 .intr_handler = qla2100_intr_handler,
1819 .enable_intrs = qla2x00_enable_intrs,
1820 .disable_intrs = qla2x00_disable_intrs,
1821 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001822 .target_reset = qla2x00_abort_target,
1823 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001824 .fabric_login = qla2x00_login_fabric,
1825 .fabric_logout = qla2x00_fabric_logout,
1826 .calc_req_entries = qla2x00_calc_iocbs_32,
1827 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1828 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1829 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1830 .read_nvram = qla2x00_read_nvram_data,
1831 .write_nvram = qla2x00_write_nvram_data,
1832 .fw_dump = qla2100_fw_dump,
1833 .beacon_on = NULL,
1834 .beacon_off = NULL,
1835 .beacon_blink = NULL,
1836 .read_optrom = qla2x00_read_optrom_data,
1837 .write_optrom = qla2x00_write_optrom_data,
1838 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001839 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001840 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001841 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001842 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001843};
1844
1845static struct isp_operations qla2300_isp_ops = {
1846 .pci_config = qla2300_pci_config,
1847 .reset_chip = qla2x00_reset_chip,
1848 .chip_diag = qla2x00_chip_diag,
1849 .config_rings = qla2x00_config_rings,
1850 .reset_adapter = qla2x00_reset_adapter,
1851 .nvram_config = qla2x00_nvram_config,
1852 .update_fw_options = qla2x00_update_fw_options,
1853 .load_risc = qla2x00_load_risc,
1854 .pci_info_str = qla2x00_pci_info_str,
1855 .fw_version_str = qla2x00_fw_version_str,
1856 .intr_handler = qla2300_intr_handler,
1857 .enable_intrs = qla2x00_enable_intrs,
1858 .disable_intrs = qla2x00_disable_intrs,
1859 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001860 .target_reset = qla2x00_abort_target,
1861 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001862 .fabric_login = qla2x00_login_fabric,
1863 .fabric_logout = qla2x00_fabric_logout,
1864 .calc_req_entries = qla2x00_calc_iocbs_32,
1865 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1866 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1867 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1868 .read_nvram = qla2x00_read_nvram_data,
1869 .write_nvram = qla2x00_write_nvram_data,
1870 .fw_dump = qla2300_fw_dump,
1871 .beacon_on = qla2x00_beacon_on,
1872 .beacon_off = qla2x00_beacon_off,
1873 .beacon_blink = qla2x00_beacon_blink,
1874 .read_optrom = qla2x00_read_optrom_data,
1875 .write_optrom = qla2x00_write_optrom_data,
1876 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001877 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001878 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001879 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001880 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001881};
1882
1883static struct isp_operations qla24xx_isp_ops = {
1884 .pci_config = qla24xx_pci_config,
1885 .reset_chip = qla24xx_reset_chip,
1886 .chip_diag = qla24xx_chip_diag,
1887 .config_rings = qla24xx_config_rings,
1888 .reset_adapter = qla24xx_reset_adapter,
1889 .nvram_config = qla24xx_nvram_config,
1890 .update_fw_options = qla24xx_update_fw_options,
1891 .load_risc = qla24xx_load_risc,
1892 .pci_info_str = qla24xx_pci_info_str,
1893 .fw_version_str = qla24xx_fw_version_str,
1894 .intr_handler = qla24xx_intr_handler,
1895 .enable_intrs = qla24xx_enable_intrs,
1896 .disable_intrs = qla24xx_disable_intrs,
1897 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001898 .target_reset = qla24xx_abort_target,
1899 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001900 .fabric_login = qla24xx_login_fabric,
1901 .fabric_logout = qla24xx_fabric_logout,
1902 .calc_req_entries = NULL,
1903 .build_iocbs = NULL,
1904 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1905 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1906 .read_nvram = qla24xx_read_nvram_data,
1907 .write_nvram = qla24xx_write_nvram_data,
1908 .fw_dump = qla24xx_fw_dump,
1909 .beacon_on = qla24xx_beacon_on,
1910 .beacon_off = qla24xx_beacon_off,
1911 .beacon_blink = qla24xx_beacon_blink,
1912 .read_optrom = qla24xx_read_optrom_data,
1913 .write_optrom = qla24xx_write_optrom_data,
1914 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001916 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001917 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001918 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001919};
1920
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001921static struct isp_operations qla25xx_isp_ops = {
1922 .pci_config = qla25xx_pci_config,
1923 .reset_chip = qla24xx_reset_chip,
1924 .chip_diag = qla24xx_chip_diag,
1925 .config_rings = qla24xx_config_rings,
1926 .reset_adapter = qla24xx_reset_adapter,
1927 .nvram_config = qla24xx_nvram_config,
1928 .update_fw_options = qla24xx_update_fw_options,
1929 .load_risc = qla24xx_load_risc,
1930 .pci_info_str = qla24xx_pci_info_str,
1931 .fw_version_str = qla24xx_fw_version_str,
1932 .intr_handler = qla24xx_intr_handler,
1933 .enable_intrs = qla24xx_enable_intrs,
1934 .disable_intrs = qla24xx_disable_intrs,
1935 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001936 .target_reset = qla24xx_abort_target,
1937 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001938 .fabric_login = qla24xx_login_fabric,
1939 .fabric_logout = qla24xx_fabric_logout,
1940 .calc_req_entries = NULL,
1941 .build_iocbs = NULL,
1942 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1943 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1944 .read_nvram = qla25xx_read_nvram_data,
1945 .write_nvram = qla25xx_write_nvram_data,
1946 .fw_dump = qla25xx_fw_dump,
1947 .beacon_on = qla24xx_beacon_on,
1948 .beacon_off = qla24xx_beacon_off,
1949 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001950 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001951 .write_optrom = qla24xx_write_optrom_data,
1952 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001953 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001954 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001955 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001956 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001957};
1958
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001959static struct isp_operations qla81xx_isp_ops = {
1960 .pci_config = qla25xx_pci_config,
1961 .reset_chip = qla24xx_reset_chip,
1962 .chip_diag = qla24xx_chip_diag,
1963 .config_rings = qla24xx_config_rings,
1964 .reset_adapter = qla24xx_reset_adapter,
1965 .nvram_config = qla81xx_nvram_config,
1966 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001967 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001968 .pci_info_str = qla24xx_pci_info_str,
1969 .fw_version_str = qla24xx_fw_version_str,
1970 .intr_handler = qla24xx_intr_handler,
1971 .enable_intrs = qla24xx_enable_intrs,
1972 .disable_intrs = qla24xx_disable_intrs,
1973 .abort_command = qla24xx_abort_command,
1974 .target_reset = qla24xx_abort_target,
1975 .lun_reset = qla24xx_lun_reset,
1976 .fabric_login = qla24xx_login_fabric,
1977 .fabric_logout = qla24xx_fabric_logout,
1978 .calc_req_entries = NULL,
1979 .build_iocbs = NULL,
1980 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1981 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001982 .read_nvram = NULL,
1983 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001984 .fw_dump = qla81xx_fw_dump,
1985 .beacon_on = qla24xx_beacon_on,
1986 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001987 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001988 .read_optrom = qla25xx_read_optrom_data,
1989 .write_optrom = qla24xx_write_optrom_data,
1990 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001991 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001992 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001993 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001994 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001995};
1996
1997static struct isp_operations qla82xx_isp_ops = {
1998 .pci_config = qla82xx_pci_config,
1999 .reset_chip = qla82xx_reset_chip,
2000 .chip_diag = qla24xx_chip_diag,
2001 .config_rings = qla82xx_config_rings,
2002 .reset_adapter = qla24xx_reset_adapter,
2003 .nvram_config = qla81xx_nvram_config,
2004 .update_fw_options = qla24xx_update_fw_options,
2005 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002006 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002007 .fw_version_str = qla24xx_fw_version_str,
2008 .intr_handler = qla82xx_intr_handler,
2009 .enable_intrs = qla82xx_enable_intrs,
2010 .disable_intrs = qla82xx_disable_intrs,
2011 .abort_command = qla24xx_abort_command,
2012 .target_reset = qla24xx_abort_target,
2013 .lun_reset = qla24xx_lun_reset,
2014 .fabric_login = qla24xx_login_fabric,
2015 .fabric_logout = qla24xx_fabric_logout,
2016 .calc_req_entries = NULL,
2017 .build_iocbs = NULL,
2018 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2019 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2020 .read_nvram = qla24xx_read_nvram_data,
2021 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002022 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002023 .beacon_on = qla82xx_beacon_on,
2024 .beacon_off = qla82xx_beacon_off,
2025 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002026 .read_optrom = qla82xx_read_optrom_data,
2027 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002028 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002029 .start_scsi = qla82xx_start_scsi,
2030 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002031 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002032 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002033};
2034
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002035static struct isp_operations qla8044_isp_ops = {
2036 .pci_config = qla82xx_pci_config,
2037 .reset_chip = qla82xx_reset_chip,
2038 .chip_diag = qla24xx_chip_diag,
2039 .config_rings = qla82xx_config_rings,
2040 .reset_adapter = qla24xx_reset_adapter,
2041 .nvram_config = qla81xx_nvram_config,
2042 .update_fw_options = qla24xx_update_fw_options,
2043 .load_risc = qla82xx_load_risc,
2044 .pci_info_str = qla24xx_pci_info_str,
2045 .fw_version_str = qla24xx_fw_version_str,
2046 .intr_handler = qla8044_intr_handler,
2047 .enable_intrs = qla82xx_enable_intrs,
2048 .disable_intrs = qla82xx_disable_intrs,
2049 .abort_command = qla24xx_abort_command,
2050 .target_reset = qla24xx_abort_target,
2051 .lun_reset = qla24xx_lun_reset,
2052 .fabric_login = qla24xx_login_fabric,
2053 .fabric_logout = qla24xx_fabric_logout,
2054 .calc_req_entries = NULL,
2055 .build_iocbs = NULL,
2056 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2057 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2058 .read_nvram = NULL,
2059 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002060 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002061 .beacon_on = qla82xx_beacon_on,
2062 .beacon_off = qla82xx_beacon_off,
2063 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002064 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002065 .write_optrom = qla8044_write_optrom_data,
2066 .get_flash_version = qla82xx_get_flash_version,
2067 .start_scsi = qla82xx_start_scsi,
2068 .abort_isp = qla8044_abort_isp,
2069 .iospace_config = qla82xx_iospace_config,
2070 .initialize_adapter = qla2x00_initialize_adapter,
2071};
2072
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002073static struct isp_operations qla83xx_isp_ops = {
2074 .pci_config = qla25xx_pci_config,
2075 .reset_chip = qla24xx_reset_chip,
2076 .chip_diag = qla24xx_chip_diag,
2077 .config_rings = qla24xx_config_rings,
2078 .reset_adapter = qla24xx_reset_adapter,
2079 .nvram_config = qla81xx_nvram_config,
2080 .update_fw_options = qla81xx_update_fw_options,
2081 .load_risc = qla81xx_load_risc,
2082 .pci_info_str = qla24xx_pci_info_str,
2083 .fw_version_str = qla24xx_fw_version_str,
2084 .intr_handler = qla24xx_intr_handler,
2085 .enable_intrs = qla24xx_enable_intrs,
2086 .disable_intrs = qla24xx_disable_intrs,
2087 .abort_command = qla24xx_abort_command,
2088 .target_reset = qla24xx_abort_target,
2089 .lun_reset = qla24xx_lun_reset,
2090 .fabric_login = qla24xx_login_fabric,
2091 .fabric_logout = qla24xx_fabric_logout,
2092 .calc_req_entries = NULL,
2093 .build_iocbs = NULL,
2094 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2095 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2096 .read_nvram = NULL,
2097 .write_nvram = NULL,
2098 .fw_dump = qla83xx_fw_dump,
2099 .beacon_on = qla24xx_beacon_on,
2100 .beacon_off = qla24xx_beacon_off,
2101 .beacon_blink = qla83xx_beacon_blink,
2102 .read_optrom = qla25xx_read_optrom_data,
2103 .write_optrom = qla24xx_write_optrom_data,
2104 .get_flash_version = qla24xx_get_flash_version,
2105 .start_scsi = qla24xx_dif_start_scsi,
2106 .abort_isp = qla2x00_abort_isp,
2107 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002108 .initialize_adapter = qla2x00_initialize_adapter,
2109};
2110
2111static struct isp_operations qlafx00_isp_ops = {
2112 .pci_config = qlafx00_pci_config,
2113 .reset_chip = qlafx00_soft_reset,
2114 .chip_diag = qlafx00_chip_diag,
2115 .config_rings = qlafx00_config_rings,
2116 .reset_adapter = qlafx00_soft_reset,
2117 .nvram_config = NULL,
2118 .update_fw_options = NULL,
2119 .load_risc = NULL,
2120 .pci_info_str = qlafx00_pci_info_str,
2121 .fw_version_str = qlafx00_fw_version_str,
2122 .intr_handler = qlafx00_intr_handler,
2123 .enable_intrs = qlafx00_enable_intrs,
2124 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002125 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002126 .target_reset = qlafx00_abort_target,
2127 .lun_reset = qlafx00_lun_reset,
2128 .fabric_login = NULL,
2129 .fabric_logout = NULL,
2130 .calc_req_entries = NULL,
2131 .build_iocbs = NULL,
2132 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2133 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2134 .read_nvram = qla24xx_read_nvram_data,
2135 .write_nvram = qla24xx_write_nvram_data,
2136 .fw_dump = NULL,
2137 .beacon_on = qla24xx_beacon_on,
2138 .beacon_off = qla24xx_beacon_off,
2139 .beacon_blink = NULL,
2140 .read_optrom = qla24xx_read_optrom_data,
2141 .write_optrom = qla24xx_write_optrom_data,
2142 .get_flash_version = qla24xx_get_flash_version,
2143 .start_scsi = qlafx00_start_scsi,
2144 .abort_isp = qlafx00_abort_isp,
2145 .iospace_config = qlafx00_iospace_config,
2146 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002147};
2148
Chad Dupuisf73cb692014-02-26 04:15:06 -05002149static struct isp_operations qla27xx_isp_ops = {
2150 .pci_config = qla25xx_pci_config,
2151 .reset_chip = qla24xx_reset_chip,
2152 .chip_diag = qla24xx_chip_diag,
2153 .config_rings = qla24xx_config_rings,
2154 .reset_adapter = qla24xx_reset_adapter,
2155 .nvram_config = qla81xx_nvram_config,
2156 .update_fw_options = qla81xx_update_fw_options,
2157 .load_risc = qla81xx_load_risc,
2158 .pci_info_str = qla24xx_pci_info_str,
2159 .fw_version_str = qla24xx_fw_version_str,
2160 .intr_handler = qla24xx_intr_handler,
2161 .enable_intrs = qla24xx_enable_intrs,
2162 .disable_intrs = qla24xx_disable_intrs,
2163 .abort_command = qla24xx_abort_command,
2164 .target_reset = qla24xx_abort_target,
2165 .lun_reset = qla24xx_lun_reset,
2166 .fabric_login = qla24xx_login_fabric,
2167 .fabric_logout = qla24xx_fabric_logout,
2168 .calc_req_entries = NULL,
2169 .build_iocbs = NULL,
2170 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2171 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2172 .read_nvram = NULL,
2173 .write_nvram = NULL,
2174 .fw_dump = qla27xx_fwdump,
2175 .beacon_on = qla24xx_beacon_on,
2176 .beacon_off = qla24xx_beacon_off,
2177 .beacon_blink = qla83xx_beacon_blink,
2178 .read_optrom = qla25xx_read_optrom_data,
2179 .write_optrom = qla24xx_write_optrom_data,
2180 .get_flash_version = qla24xx_get_flash_version,
2181 .start_scsi = qla24xx_dif_start_scsi,
2182 .abort_isp = qla2x00_abort_isp,
2183 .iospace_config = qla83xx_iospace_config,
2184 .initialize_adapter = qla2x00_initialize_adapter,
2185};
2186
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002187static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002188qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002189{
2190 ha->device_type = DT_EXTENDED_IDS;
2191 switch (ha->pdev->device) {
2192 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002193 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002194 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002195 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002196 break;
2197 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002198 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002199 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002200 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002201 break;
2202 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002203 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002204 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002205 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002206 break;
2207 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002208 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002209 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002210 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002211 break;
2212 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002213 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002214 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002215 if (ha->pdev->subsystem_vendor == 0x1028 &&
2216 ha->pdev->subsystem_device == 0x0170)
2217 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002218 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002219 break;
2220 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002221 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002222 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002223 break;
2224 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002225 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002226 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002227 break;
2228 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002229 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002230 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002231 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002232 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002233 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002234 break;
2235 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002236 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002237 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002238 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002239 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002240 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002241 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002242 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002243 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002244 ha->device_type |= DT_ZIO_SUPPORTED;
2245 ha->device_type |= DT_FWI2;
2246 ha->device_type |= DT_IIDMA;
2247 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2248 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002249 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002250 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002251 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002252 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002253 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002254 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002255 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002256 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002257 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002258 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002259 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002260 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002261 ha->device_type |= DT_ZIO_SUPPORTED;
2262 ha->device_type |= DT_FWI2;
2263 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002264 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2265 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002266 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002267 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002268 ha->device_type |= DT_ZIO_SUPPORTED;
2269 ha->device_type |= DT_FWI2;
2270 ha->device_type |= DT_IIDMA;
2271 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2272 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002273 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002274 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002275 ha->device_type |= DT_ZIO_SUPPORTED;
2276 ha->device_type |= DT_FWI2;
2277 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2278 /* Initialize 82XX ISP flags */
2279 qla82xx_init_flags(ha);
2280 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002281 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002282 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002283 ha->device_type |= DT_ZIO_SUPPORTED;
2284 ha->device_type |= DT_FWI2;
2285 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2286 /* Initialize 82XX ISP flags */
2287 qla82xx_init_flags(ha);
2288 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002289 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002290 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002291 ha->device_type |= DT_ZIO_SUPPORTED;
2292 ha->device_type |= DT_FWI2;
2293 ha->device_type |= DT_IIDMA;
2294 ha->device_type |= DT_T10_PI;
2295 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2296 break;
2297 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002298 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002299 ha->device_type |= DT_ZIO_SUPPORTED;
2300 ha->device_type |= DT_FWI2;
2301 ha->device_type |= DT_IIDMA;
2302 ha->device_type |= DT_T10_PI;
2303 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2304 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002305 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002306 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002307 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002308 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002309 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002310 ha->device_type |= DT_ZIO_SUPPORTED;
2311 ha->device_type |= DT_FWI2;
2312 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002313 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002314 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2315 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002316 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002317 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002318 ha->device_type |= DT_ZIO_SUPPORTED;
2319 ha->device_type |= DT_FWI2;
2320 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002321 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002322 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2323 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002324 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002325 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002326 ha->device_type |= DT_ZIO_SUPPORTED;
2327 ha->device_type |= DT_FWI2;
2328 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002329 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002330 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2331 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002332 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002333
Giridhar Malavalia9083012010-04-12 17:59:55 -07002334 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002335 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002336 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002337 /* Get adapter physical port no from interrupt pin register. */
2338 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002339 if (IS_QLA27XX(ha))
2340 ha->port_no--;
2341 else
2342 ha->port_no = !(ha->port_no & 1);
2343 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002344
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002345 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002346 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002347 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002348}
2349
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002350static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002351qla2xxx_scan_start(struct Scsi_Host *shost)
2352{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002353 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002354
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002355 if (vha->hw->flags.running_gold_fw)
2356 return;
2357
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2359 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2360 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2361 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002362}
2363
2364static int
2365qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2366{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002368
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002369 if (test_bit(UNLOADING, &vha->dpc_flags))
2370 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002372 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002374 return 1;
2375
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002377}
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379/*
2380 * PCI driver interface
2381 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002382static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002383qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002385 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 scsi_qla_host_t *base_vha = NULL;
2388 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002389 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002390 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002391 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002392 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002394 struct req_que *req = NULL;
2395 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002396 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002397 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002398 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2399 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002400 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002401 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2402 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002403 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002404 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002405 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2406 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002407 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002408 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002409 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002410 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002411 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2412 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002413 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002414 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002415 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2416 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002417 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002418 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2419 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002420
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002421 if (mem_only) {
2422 if (pci_enable_device_mem(pdev))
Johannes Thumshirnfe424722017-05-23 16:50:47 +02002423 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002424 } else {
2425 if (pci_enable_device(pdev))
Johannes Thumshirnfe424722017-05-23 16:50:47 +02002426 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Jesse Barnes09276782008-10-18 17:33:19 -07002429 /* This may fail but that's ok */
2430 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2433 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002434 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2435 "Unable to allocate memory for ha.\n");
Johannes Thumshirnfe424722017-05-23 16:50:47 +02002436 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002438 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2439 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002441 ha->tgt.enable_class_2 = ql2xenableclass2;
Quinn Tran33e79972014-09-25 06:14:55 -04002442 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2443 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002444 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002445 spin_lock_init(&ha->tgt.atio_lock);
2446
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
2448 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002449 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002450 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002451 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002452 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002453 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002454 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002456 /* Set ISP-type information. */
2457 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002458
2459 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002460 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002461 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002462 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002463
Chad Dupuiscba1e472011-11-18 09:03:21 -08002464 ha->prev_topology = 0;
2465 ha->init_cb_size = sizeof(init_cb_t);
2466 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2467 ha->optrom_size = OPTROM_SIZE_2300;
2468
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002469 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002471 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 req_length = REQUEST_ENTRY_CNT_2100;
2474 rsp_length = RESPONSE_ENTRY_CNT_2100;
2475 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002476 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002477 ha->flash_conf_off = ~0;
2478 ha->flash_data_off = ~0;
2479 ha->nvram_conf_off = ~0;
2480 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002481 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002483 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002484 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 req_length = REQUEST_ENTRY_CNT_2200;
2486 rsp_length = RESPONSE_ENTRY_CNT_2100;
2487 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002488 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002489 ha->flash_conf_off = ~0;
2490 ha->flash_data_off = ~0;
2491 ha->nvram_conf_off = ~0;
2492 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002493 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002494 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002495 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 req_length = REQUEST_ENTRY_CNT_2200;
2498 rsp_length = RESPONSE_ENTRY_CNT_2300;
2499 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002500 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002501 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2502 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002503 ha->flash_conf_off = ~0;
2504 ha->flash_data_off = ~0;
2505 ha->nvram_conf_off = ~0;
2506 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002507 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002508 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002509 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002510 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002511 req_length = REQUEST_ENTRY_CNT_24XX;
2512 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002513 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002514 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002515 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002516 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002517 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002518 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002519 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002520 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2521 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2522 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2523 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002524 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002525 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002526 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 req_length = REQUEST_ENTRY_CNT_24XX;
2528 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002529 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002531 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002532 ha->gid_list_info_size = 8;
2533 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002534 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002535 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002536 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2537 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2538 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2539 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2540 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002541 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002542 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2543 req_length = REQUEST_ENTRY_CNT_24XX;
2544 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002545 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002546 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2547 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2548 ha->gid_list_info_size = 8;
2549 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002550 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002551 ha->isp_ops = &qla81xx_isp_ops;
2552 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2553 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2554 ha->nvram_conf_off = ~0;
2555 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002556 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002557 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002558 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2559 req_length = REQUEST_ENTRY_CNT_82XX;
2560 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2561 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2562 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2563 ha->gid_list_info_size = 8;
2564 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002565 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002566 ha->isp_ops = &qla82xx_isp_ops;
2567 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2568 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2569 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2570 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002571 } else if (IS_QLA8044(ha)) {
2572 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2573 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2574 req_length = REQUEST_ENTRY_CNT_82XX;
2575 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2576 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2577 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2578 ha->gid_list_info_size = 8;
2579 ha->optrom_size = OPTROM_SIZE_83XX;
2580 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2581 ha->isp_ops = &qla8044_isp_ops;
2582 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2583 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2584 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2585 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002586 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002587 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002588 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002589 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002590 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002591 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002592 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002593 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2594 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2595 ha->gid_list_info_size = 8;
2596 ha->optrom_size = OPTROM_SIZE_83XX;
2597 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2598 ha->isp_ops = &qla83xx_isp_ops;
2599 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2600 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2601 ha->nvram_conf_off = ~0;
2602 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002603 } else if (IS_QLAFX00(ha)) {
2604 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2605 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2606 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2607 req_length = REQUEST_ENTRY_CNT_FX00;
2608 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002609 ha->isp_ops = &qlafx00_isp_ops;
2610 ha->port_down_retry_count = 30; /* default value */
2611 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2612 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002613 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002614 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002615 ha->mr.host_info_resend = false;
2616 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002617 } else if (IS_QLA27XX(ha)) {
2618 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2619 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2620 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002621 req_length = REQUEST_ENTRY_CNT_83XX;
2622 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002623 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002624 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2625 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2626 ha->gid_list_info_size = 8;
2627 ha->optrom_size = OPTROM_SIZE_83XX;
2628 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2629 ha->isp_ops = &qla27xx_isp_ops;
2630 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2631 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2632 ha->nvram_conf_off = ~0;
2633 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002635
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002636 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2637 "mbx_count=%d, req_length=%d, "
2638 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002639 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2640 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002641 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2642 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002643 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002644 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2645 "isp_ops=%p, flash_conf_off=%d, "
2646 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2647 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2648 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002649
2650 /* Configure PCI I/O space */
2651 ret = ha->isp_ops->iospace_config(ha);
2652 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002653 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002654
2655 ql_log_pci(ql_log_info, pdev, 0x001d,
2656 "Found an ISP%04X irq %d iobase 0x%p.\n",
2657 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002658 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002659 init_completion(&ha->mbx_cmd_comp);
2660 complete(&ha->mbx_cmd_comp);
2661 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002662 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002663 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002665 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Andrew Vasquez53303c42009-01-22 09:45:37 -08002667 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002668 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2669 "64 Bit addressing is %s.\n",
2670 ha->flags.enable_64bit_addressing ? "enable" :
2671 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002672 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002673 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002674 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2675 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 goto probe_hw_failed;
2678 }
2679
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002680 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002682 req->max_q_depth = ql2xmaxqdepth;
2683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684
2685 base_vha = qla2x00_create_host(sht, ha);
2686 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002687 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002688 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002689 qla2x00_free_req_que(ha, req);
2690 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002691 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 }
2693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002695 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002698 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002699 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002701 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002702 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2703 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002704
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002705 /* Setup fcport template structure. */
2706 ha->mr.fcport.vha = base_vha;
2707 ha->mr.fcport.port_type = FCT_UNKNOWN;
2708 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2709 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2710 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2711 ha->mr.fcport.scan_state = 1;
2712
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002713 /* Set the SG table size based on ISP type */
2714 if (!IS_FWI2_CAPABLE(ha)) {
2715 if (IS_QLA2100(ha))
2716 host->sg_tablesize = 32;
2717 } else {
2718 if (!IS_QLA82XX(ha))
2719 host->sg_tablesize = QLA_SG_ALL;
2720 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002721 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002722 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002723 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002724 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002725 host->max_cmd_len = 32;
2726 else
2727 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002728 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002729 /* Older HBAs support only 16-bit LUNs */
2730 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2731 ql2xmaxlun > 0xffff)
2732 host->max_lun = 0xffff;
2733 else
2734 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002735 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002736 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002737
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002738 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2739 "max_id=%d this_id=%d "
2740 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002741 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002742 host->this_id, host->cmd_per_lun, host->unique_id,
2743 host->max_cmd_len, host->max_channel, host->max_lun,
2744 host->transportt, sht->vendor_id);
2745
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002746que_init:
2747 /* Alloc arrays of request and response ring ptrs */
2748 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2749 ql_log(ql_log_fatal, base_vha, 0x003d,
2750 "Failed to allocate memory for queue pointers..."
2751 "aborting.\n");
2752 goto probe_init_failed;
2753 }
2754
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002755 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002756
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002757 /* Set up the irqs */
2758 ret = qla2x00_request_irqs(ha, rsp);
2759 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002760 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002761
2762 pci_save_state(pdev);
2763
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002764 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002765 rsp->req = req;
2766 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002767
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002768 if (IS_QLAFX00(ha)) {
2769 ha->rsp_q_map[0] = rsp;
2770 ha->req_q_map[0] = req;
2771 set_bit(0, ha->req_qid_map);
2772 set_bit(0, ha->rsp_qid_map);
2773 }
2774
Andrew Vasquez08029992009-03-24 09:07:55 -07002775 /* FWI2-capable only. */
2776 req->req_q_in = &ha->iobase->isp24.req_q_in;
2777 req->req_q_out = &ha->iobase->isp24.req_q_out;
2778 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2779 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002780 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002781 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2782 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2783 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2784 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002785 }
2786
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002787 if (IS_QLAFX00(ha)) {
2788 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2789 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2790 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2791 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2792 }
2793
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002794 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002795 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2796 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2797 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2798 }
2799
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002800 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2801 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2802 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2803 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2804 "req->req_q_in=%p req->req_q_out=%p "
2805 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2806 req->req_q_in, req->req_q_out,
2807 rsp->rsp_q_in, rsp->rsp_q_out);
2808 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2809 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2810 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2811 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2812 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2813 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002815 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002816 ql_log(ql_log_fatal, base_vha, 0x00d6,
2817 "Failed to initialize adapter - Adapter flags %x.\n",
2818 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819
Giridhar Malavalia9083012010-04-12 17:59:55 -07002820 if (IS_QLA82XX(ha)) {
2821 qla82xx_idc_lock(ha);
2822 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002823 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002824 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 ql_log(ql_log_fatal, base_vha, 0x00d7,
2826 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002827 } else if (IS_QLA8044(ha)) {
2828 qla8044_idc_lock(ha);
2829 qla8044_wr_direct(base_vha,
2830 QLA8044_CRB_DEV_STATE_INDEX,
2831 QLA8XXX_DEV_FAILED);
2832 qla8044_idc_unlock(ha);
2833 ql_log(ql_log_fatal, base_vha, 0x0150,
2834 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002835 }
2836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 ret = -ENODEV;
2838 goto probe_failed;
2839 }
2840
Chad Dupuis3b1bef62014-02-26 04:15:04 -05002841 if (IS_QLAFX00(ha))
2842 host->can_queue = QLAFX00_MAX_CANQUEUE;
2843 else
2844 host->can_queue = req->num_outstanding_cmds - 10;
2845
2846 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2847 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2848 host->can_queue, base_vha->req,
2849 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2850
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002851 if (ha->mqenable) {
2852 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002853 ql_log(ql_log_warn, base_vha, 0x00ec,
2854 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002855 goto que_init;
2856 }
2857 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002858
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002859 if (ha->flags.running_gold_fw)
2860 goto skip_dpc;
2861
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 /*
2863 * Startup the kernel thread for this host adapter
2864 */
2865 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002866 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002868 ql_log(ql_log_fatal, base_vha, 0x00ed,
2869 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002870 ret = PTR_ERR(ha->dpc_thread);
2871 goto probe_failed;
2872 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002873 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2874 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002876 /*
2877 * If we're not coming up in initiator mode, we might sit for
2878 * a while without waking up the dpc thread, which leads to a
2879 * stuck process warning. So just kick the dpc once here and
2880 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2881 */
2882 qla2xxx_wake_dpc(base_vha);
2883
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002884 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2885
Saurav Kashyap81178772012-08-22 14:21:04 -04002886 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2887 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2888 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2889 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2890
2891 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2892 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2893 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2894 INIT_WORK(&ha->idc_state_handler,
2895 qla83xx_idc_state_handler_work);
2896 INIT_WORK(&ha->nic_core_unrecoverable,
2897 qla83xx_nic_core_unrecoverable_work);
2898 }
2899
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002900skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 list_add_tail(&base_vha->list, &ha->vp_list);
2902 base_vha->host->irq = ha->pdev->irq;
2903
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002906 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2907 "Started qla2x00_timer with "
2908 "interval=%d.\n", WATCH_INTERVAL);
2909 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2910 "Detected hba at address=%p.\n",
2911 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
Arun Easie02587d2011-08-16 11:29:23 -07002913 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002914 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002915 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002916 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002917 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2918 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002919 if (ql2xenabledif == 1)
2920 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002921 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002922 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002923 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002924 | SHOST_DIF_TYPE3_PROTECTION
2925 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002926 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002927 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002928
2929 guard = SHOST_DIX_GUARD_CRC;
2930
2931 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2932 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2933 guard |= SHOST_DIX_GUARD_IP;
2934
2935 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002936 } else
2937 base_vha->flags.difdix_supported = 0;
2938 }
2939
Giridhar Malavalia9083012010-04-12 17:59:55 -07002940 ha->isp_ops->enable_intrs(ha);
2941
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002942 if (IS_QLAFX00(ha)) {
2943 ret = qlafx00_fx_disc(base_vha,
2944 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2945 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2946 QLA_SG_ALL : 128;
2947 }
2948
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002949 ret = scsi_add_host(host, &pdev->dev);
2950 if (ret)
2951 goto probe_failed;
2952
Michael Reed14864002009-12-02 09:11:16 -06002953 base_vha->flags.init_done = 1;
2954 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04002955 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06002956
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002957 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2958 "Init done and hba is online.\n");
2959
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002960 if (qla_ini_mode_enabled(base_vha))
2961 scsi_scan_host(host);
2962 else
2963 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2964 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002967
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002968 if (IS_QLAFX00(ha)) {
2969 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002970 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2971
2972 /* Register system information */
2973 ret = qlafx00_fx_disc(base_vha,
2974 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2975 }
2976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002980
Armen Baloyan03eb9122013-10-30 03:38:22 -04002981 ql_log(ql_log_info, base_vha, 0x00fb,
2982 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002983 ql_log(ql_log_info, base_vha, 0x00fc,
2984 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2985 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2986 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2987 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002988 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002990 qlt_add_target(ha, base_vha);
2991
Joe Lawrence6b383972014-08-26 17:12:29 -04002992 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04002993
2994 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2995 return -ENODEV;
2996
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 return 0;
2998
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002999probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003000 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003001 ha->req_q_map[0] = NULL;
3002 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003003 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003004 ha->rsp_q_map[0] = NULL;
3005 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003006 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003007
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003009 if (base_vha->timer_active)
3010 qla2x00_stop_timer(base_vha);
3011 base_vha->flags.online = 0;
3012 if (ha->dpc_thread) {
3013 struct task_struct *t = ha->dpc_thread;
3014
3015 ha->dpc_thread = NULL;
3016 kthread_stop(t);
3017 }
3018
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003021 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003024 qla2x00_clear_drv_active(ha);
3025
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003026iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003027 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003028 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003029 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003030 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003031 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003032 } else {
3033 if (ha->iobase)
3034 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003035 if (ha->cregbase)
3036 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003037 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 pci_release_selected_regions(ha->pdev, ha->bars);
3039 kfree(ha);
3040 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
Johannes Thumshirnfe424722017-05-23 16:50:47 +02003042disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003043 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003044 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
Adrian Bunk4c993f72008-01-14 00:55:16 -08003047static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003048qla2x00_shutdown(struct pci_dev *pdev)
3049{
3050 scsi_qla_host_t *vha;
3051 struct qla_hw_data *ha;
3052
Masanari Iida552f3f92013-02-08 01:57:44 -05003053 if (!atomic_read(&pdev->enable_cnt))
3054 return;
3055
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003056 vha = pci_get_drvdata(pdev);
3057 ha = vha->hw;
3058
Armen Baloyan42479342013-08-27 01:37:37 -04003059 /* Notify ISPFX00 firmware */
3060 if (IS_QLAFX00(ha))
3061 qlafx00_driver_shutdown(vha, 20);
3062
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003063 /* Turn-off FCE trace */
3064 if (ha->flags.fce_enabled) {
3065 qla2x00_disable_fce_trace(vha, NULL, NULL);
3066 ha->flags.fce_enabled = 0;
3067 }
3068
3069 /* Turn-off EFT trace */
3070 if (ha->eft)
3071 qla2x00_disable_eft_trace(vha);
3072
3073 /* Stop currently executing firmware. */
3074 qla2x00_try_to_stop_firmware(vha);
3075
3076 /* Turn adapter off line */
3077 vha->flags.online = 0;
3078
3079 /* turn-off interrupts on the card */
3080 if (ha->interrupts_on) {
3081 vha->flags.init_done = 0;
3082 ha->isp_ops->disable_intrs(ha);
3083 }
3084
3085 qla2x00_free_irqs(vha);
3086
3087 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003088
3089 pci_disable_pcie_error_reporting(pdev);
3090 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003091}
3092
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003093/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003094static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003095qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003097 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003098 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099
Arun Easi43ebf162011-05-10 11:18:16 -07003100 mutex_lock(&ha->vport_lock);
3101 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003102 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003103
Arun Easi43ebf162011-05-10 11:18:16 -07003104 BUG_ON(base_vha->list.next == &ha->vp_list);
3105 /* This assumes first entry in ha->vp_list is always base vha */
3106 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003107 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003108
Arun Easi43ebf162011-05-10 11:18:16 -07003109 spin_unlock_irqrestore(&ha->vport_slock, flags);
3110 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003111
Arun Easi43ebf162011-05-10 11:18:16 -07003112 fc_vport_terminate(vha->fc_vport);
3113 scsi_host_put(vha->host);
3114
3115 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 }
Arun Easi43ebf162011-05-10 11:18:16 -07003117 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003118}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003119
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003120/* Stops all deferred work threads */
3121static void
3122qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3123{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003124 /* Flush the work queue and remove it */
3125 if (ha->wq) {
3126 flush_workqueue(ha->wq);
3127 destroy_workqueue(ha->wq);
3128 ha->wq = NULL;
3129 }
3130
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003131 /* Cancel all work and destroy DPC workqueues */
3132 if (ha->dpc_lp_wq) {
3133 cancel_work_sync(&ha->idc_aen);
3134 destroy_workqueue(ha->dpc_lp_wq);
3135 ha->dpc_lp_wq = NULL;
3136 }
3137
3138 if (ha->dpc_hp_wq) {
3139 cancel_work_sync(&ha->nic_core_reset);
3140 cancel_work_sync(&ha->idc_state_handler);
3141 cancel_work_sync(&ha->nic_core_unrecoverable);
3142 destroy_workqueue(ha->dpc_hp_wq);
3143 ha->dpc_hp_wq = NULL;
3144 }
3145
Andrew Vasquezb9978762009-03-24 09:08:05 -07003146 /* Kill the kernel thread for this host */
3147 if (ha->dpc_thread) {
3148 struct task_struct *t = ha->dpc_thread;
3149
3150 /*
3151 * qla2xxx_wake_dpc checks for ->dpc_thread
3152 * so we need to zero it out.
3153 */
3154 ha->dpc_thread = NULL;
3155 kthread_stop(t);
3156 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003157}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003158
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003159static void
3160qla2x00_unmap_iobases(struct qla_hw_data *ha)
3161{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003162 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003163
Chad Dupuisf73cb692014-02-26 04:15:06 -05003164 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003165 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003166 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003167 } else {
3168 if (ha->iobase)
3169 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003171 if (ha->cregbase)
3172 iounmap(ha->cregbase);
3173
Giridhar Malavalia9083012010-04-12 17:59:55 -07003174 if (ha->mqiobase)
3175 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003176
Chad Dupuisf73cb692014-02-26 04:15:06 -05003177 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003178 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003179 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003180}
3181
3182static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003183qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003184{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003185 if (IS_QLA8044(ha)) {
3186 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003187 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003188 qla8044_idc_unlock(ha);
3189 } else if (IS_QLA82XX(ha)) {
3190 qla82xx_idc_lock(ha);
3191 qla82xx_clear_drv_active(ha);
3192 qla82xx_idc_unlock(ha);
3193 }
3194}
3195
3196static void
3197qla2x00_remove_one(struct pci_dev *pdev)
3198{
3199 scsi_qla_host_t *base_vha;
3200 struct qla_hw_data *ha;
3201
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003202 base_vha = pci_get_drvdata(pdev);
3203 ha = base_vha->hw;
3204
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003205 /* Indicate device removal to prevent future board_disable and wait
3206 * until any pending board_disable has completed. */
3207 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3208 cancel_work_sync(&ha->board_disable);
3209
3210 /*
3211 * If the PCI device is disabled then there was a PCI-disconnect and
3212 * qla2x00_disable_board_on_pci_error has taken care of most of the
3213 * resources.
3214 */
3215 if (!atomic_read(&pdev->enable_cnt)) {
3216 scsi_host_put(base_vha->host);
3217 kfree(ha);
3218 pci_set_drvdata(pdev, NULL);
3219 return;
3220 }
3221
Sawan Chandak638a1a02014-04-11 16:54:38 -04003222 qla2x00_wait_for_hba_ready(base_vha);
3223
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003224 /* if UNLOAD flag is already set, then continue unload,
3225 * where it was set first.
3226 */
3227 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3228 return;
3229
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003230 set_bit(UNLOADING, &base_vha->dpc_flags);
3231
3232 if (IS_QLAFX00(ha))
3233 qlafx00_driver_shutdown(base_vha, 20);
3234
3235 qla2x00_delete_all_vps(ha, base_vha);
3236
3237 if (IS_QLA8031(ha)) {
3238 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3239 "Clearing fcoe driver presence.\n");
3240 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3241 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3242 "Error while clearing DRV-Presence.\n");
3243 }
3244
3245 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3246
3247 qla2x00_dfs_remove(base_vha);
3248
3249 qla84xx_put_chip(base_vha);
3250
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003251 /* Laser should be disabled only for ISP2031 */
3252 if (IS_QLA2031(ha))
3253 qla83xx_disable_laser(base_vha);
3254
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003255 /* Disable timer */
3256 if (base_vha->timer_active)
3257 qla2x00_stop_timer(base_vha);
3258
3259 base_vha->flags.online = 0;
3260
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003261 /* free DMA memory */
3262 if (ha->exlogin_buf)
3263 qla2x00_free_exlogin_buffer(ha);
3264
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003265 /* free DMA memory */
3266 if (ha->exchoffld_buf)
3267 qla2x00_free_exchoffld_buffer(ha);
3268
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003269 qla2x00_destroy_deferred_work(ha);
3270
3271 qlt_remove_target(ha, base_vha);
3272
3273 qla2x00_free_sysfs_attr(base_vha, true);
3274
3275 fc_remove_host(base_vha->host);
3276
3277 scsi_remove_host(base_vha->host);
3278
3279 qla2x00_free_device(base_vha);
3280
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003281 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003282
Arun Easid2749ff2014-09-25 05:16:51 -04003283 scsi_host_put(base_vha->host);
3284
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003285 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003286
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 pci_release_selected_regions(ha->pdev, ha->bars);
3288 kfree(ha);
3289 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003291 pci_disable_pcie_error_reporting(pdev);
3292
Bernhard Walle665db932007-03-28 00:49:49 +02003293 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
3296static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003299 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
Andrew Vasquez85880802009-12-15 21:29:46 -08003301 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3302
3303 /* Disable timer */
3304 if (vha->timer_active)
3305 qla2x00_stop_timer(vha);
3306
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003307 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003308
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003309 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003311
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003312 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003314
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003315 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
Andrew Vasquez85880802009-12-15 21:29:46 -08003318 vha->flags.online = 0;
3319
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003320 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003321 if (ha->interrupts_on) {
3322 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003323 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003324 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003325
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003326 qla2x00_free_irqs(vha);
3327
Chad Dupuis88670482010-07-23 15:28:30 +05003328 qla2x00_free_fcports(vha);
3329
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003330 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003331
Giridhar Malavali08de2842011-08-16 11:31:44 -07003332 qla82xx_md_free(vha);
3333
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003334 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
Chad Dupuis88670482010-07-23 15:28:30 +05003337void qla2x00_free_fcports(struct scsi_qla_host *vha)
3338{
3339 fc_port_t *fcport, *tfcport;
3340
3341 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3342 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003343 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003344 kfree(fcport);
3345 fcport = NULL;
3346 }
3347}
3348
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003349static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003351 int defer)
3352{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003353 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003354 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003355 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003356
3357 if (!fcport->rport)
3358 return;
3359
3360 rport = fcport->rport;
3361 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003362 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003363 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003364 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003365 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003366 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003367 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3368 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003369 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003370 int now;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003371 if (rport)
3372 fc_remote_port_delete(rport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003373 qlt_do_generation_tick(vha, &now);
3374 qlt_fc_port_deleted(vha, fcport, now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003375 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003376}
3377
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3380 *
3381 * Input: ha = adapter block pointer. fcport = port structure pointer.
3382 *
3383 * Return: None.
3384 *
3385 * Context:
3386 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003388 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003390 if (IS_QLAFX00(vha->hw)) {
3391 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3392 qla2x00_schedule_rport_del(vha, fcport, defer);
3393 return;
3394 }
3395
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003396 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003397 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003398 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003399 qla2x00_schedule_rport_del(vha, fcport, defer);
3400 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003401 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 * We may need to retry the login, so don't change the state of the
3403 * port but do the retries.
3404 */
3405 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003406 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
3408 if (!do_login)
3409 return;
3410
Arun Easia1d02852015-08-04 13:38:02 -04003411 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3412
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003416 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003417 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3418 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 }
3420}
3421
3422/*
3423 * qla2x00_mark_all_devices_lost
3424 * Updates fcport state when device goes offline.
3425 *
3426 * Input:
3427 * ha = adapter block pointer.
3428 * fcport = port structure pointer.
3429 *
3430 * Return:
3431 * None.
3432 *
3433 * Context:
3434 */
3435void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437{
3438 fc_port_t *fcport;
3439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003441 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003443
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 /*
3445 * No point in marking the device as lost, if the device is
3446 * already DEAD.
3447 */
3448 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3449 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003451 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003452 if (defer)
3453 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003454 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003455 qla2x00_schedule_rport_del(vha, fcport, defer);
3456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 }
3458}
3459
3460/*
3461* qla2x00_mem_alloc
3462* Allocates adapter memory.
3463*
3464* Returns:
3465* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003466* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003468static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003469qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3470 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471{
3472 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
Andrew Vasqueze8711082008-01-31 12:33:48 -08003474 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003476 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003479 if (qlt_mem_alloc(ha) < 0)
3480 goto fail_free_init_cb;
3481
Chad Dupuis642ef982012-02-09 11:15:57 -08003482 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3483 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003485 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
Andrew Vasqueze8711082008-01-31 12:33:48 -08003487 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3488 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003491 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003492 /* Allocate cache for CT6 Ctx. */
3493 if (!ctx_cachep) {
3494 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3495 sizeof(struct ct6_dsd), 0,
3496 SLAB_HWCACHE_ALIGN, NULL);
3497 if (!ctx_cachep)
Quinn Tranbeecb1e2016-12-23 18:06:10 -08003498 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003499 }
3500 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3501 ctx_cachep);
3502 if (!ha->ctx_mempool)
3503 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003504 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3505 "ctx_cachep=%p ctx_mempool=%p.\n",
3506 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003507 }
3508
Andrew Vasqueze8711082008-01-31 12:33:48 -08003509 /* Get memory for cached NVRAM */
3510 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3511 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003512 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3515 ha->pdev->device);
3516 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3517 DMA_POOL_SIZE, 8, 0);
3518 if (!ha->s_dma_pool)
3519 goto fail_free_nvram;
3520
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003521 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3522 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3523 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3524
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003525 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003526 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3527 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3528 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003529 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3530 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003531 goto fail_s_dma_pool;
3532 }
3533
3534 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3535 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3536 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003537 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3538 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003539 goto fail_dl_dma_pool;
3540 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003541 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3542 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3543 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003544 }
3545
Andrew Vasqueze8711082008-01-31 12:33:48 -08003546 /* Allocate memory for SNS commands */
3547 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003549 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003551 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003553 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003554 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003555 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003557 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003559 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 goto fail_dma_pool;
3561 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003562 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003564 if (!ha->ct_sns)
3565 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003566 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3567 "ms_iocb=%p ct_sns=%p.\n",
3568 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 }
3570
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003572 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3573 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003574 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3575 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 goto fail_req;
3577 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003578 (*req)->length = req_len;
3579 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3580 ((*req)->length + 1) * sizeof(request_t),
3581 &(*req)->dma, GFP_KERNEL);
3582 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003583 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3584 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003585 goto fail_req_ring;
3586 }
3587 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003588 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3589 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003590 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3591 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592 goto fail_rsp;
3593 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003594 (*rsp)->hw = ha;
3595 (*rsp)->length = rsp_len;
3596 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3597 ((*rsp)->length + 1) * sizeof(response_t),
3598 &(*rsp)->dma, GFP_KERNEL);
3599 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003600 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3601 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 goto fail_rsp_ring;
3603 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003604 (*req)->rsp = *rsp;
3605 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003606 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3607 "req=%p req->length=%d req->ring=%p rsp=%p "
3608 "rsp->length=%d rsp->ring=%p.\n",
3609 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3610 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003611 /* Allocate memory for NVRAM data for vports */
3612 if (ha->nvram_npiv_size) {
3613 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003614 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003615 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003616 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3617 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003618 goto fail_npiv_info;
3619 }
3620 } else
3621 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003622
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003623 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003624 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003625 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3626 &ha->ex_init_cb_dma);
3627 if (!ha->ex_init_cb)
3628 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003629 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3630 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003631 }
3632
Giridhar Malavalia9083012010-04-12 17:59:55 -07003633 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3634
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003635 /* Get consistent memory allocated for Async Port-Database. */
3636 if (!IS_FWI2_CAPABLE(ha)) {
3637 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3638 &ha->async_pd_dma);
3639 if (!ha->async_pd)
3640 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003641 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3642 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003643 }
3644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003646
3647 /* Allocate memory for our loop_id bitmap */
3648 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3649 GFP_KERNEL);
3650 if (!ha->loop_id_map)
Quinn Tranbeecb1e2016-12-23 18:06:10 -08003651 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003652 else {
3653 qla2x00_set_reserved_loop_ids(ha);
3654 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003655 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003656 }
3657
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003658 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003659
Quinn Tranbeecb1e2016-12-23 18:06:10 -08003660fail_loop_id_map:
3661 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003662fail_async_pd:
3663 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003664fail_ex_init_cb:
3665 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003666fail_npiv_info:
3667 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3668 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3669 (*rsp)->ring = NULL;
3670 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003671fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003672 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003673fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003674 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3675 sizeof(request_t), (*req)->ring, (*req)->dma);
3676 (*req)->ring = NULL;
3677 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003679 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003680fail_req:
3681 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3682 ha->ct_sns, ha->ct_sns_dma);
3683 ha->ct_sns = NULL;
3684 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003685fail_free_ms_iocb:
3686 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3687 ha->ms_iocb = NULL;
3688 ha->ms_iocb_dma = 0;
Quinn Tranbeecb1e2016-12-23 18:06:10 -08003689
3690 if (ha->sns_cmd)
3691 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3692 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003693fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003694 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003695 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3696 ha->fcp_cmnd_dma_pool = NULL;
3697 }
3698fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003699 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003700 dma_pool_destroy(ha->dl_dma_pool);
3701 ha->dl_dma_pool = NULL;
3702 }
3703fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003704 dma_pool_destroy(ha->s_dma_pool);
3705 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003706fail_free_nvram:
3707 kfree(ha->nvram);
3708 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003709fail_free_ctx_mempool:
Quinn Tranbeecb1e2016-12-23 18:06:10 -08003710 if (ha->ctx_mempool)
3711 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003712 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003713fail_free_srb_mempool:
Quinn Tranbeecb1e2016-12-23 18:06:10 -08003714 if (ha->srb_mempool)
3715 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003716 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003717fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003718 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3719 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003721 ha->gid_list = NULL;
3722 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003723fail_free_tgt_mem:
3724 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003725fail_free_init_cb:
3726 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3727 ha->init_cb_dma);
3728 ha->init_cb = NULL;
3729 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003730fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003731 ql_log(ql_log_fatal, NULL, 0x0030,
3732 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003733 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734}
3735
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003736int
3737qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
3738{
3739 int rval;
3740 uint16_t size, max_cnt, temp;
3741 struct qla_hw_data *ha = vha->hw;
3742
3743 /* Return if we don't need to alloacate any extended logins */
3744 if (!ql2xexlogins)
3745 return QLA_SUCCESS;
3746
3747 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
3748 max_cnt = 0;
3749 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
3750 if (rval != QLA_SUCCESS) {
3751 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
3752 "Failed to get exlogin status.\n");
3753 return rval;
3754 }
3755
3756 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
3757 ha->exlogin_size = (size * temp);
3758 ql_log(ql_log_info, vha, 0xd024,
3759 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
3760 max_cnt, size, temp);
3761
3762 ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
3763 ha->exlogin_size);
3764
3765 /* Get consistent memory for extended logins */
3766 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
3767 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
3768 if (!ha->exlogin_buf) {
3769 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
3770 "Failed to allocate memory for exlogin_buf_dma.\n");
3771 return -ENOMEM;
3772 }
3773
3774 /* Now configure the dma buffer */
3775 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
3776 if (rval) {
3777 ql_log(ql_log_fatal, vha, 0x00cf,
3778 "Setup extended login buffer ****FAILED****.\n");
3779 qla2x00_free_exlogin_buffer(ha);
3780 }
3781
3782 return rval;
3783}
3784
3785/*
3786* qla2x00_free_exlogin_buffer
3787*
3788* Input:
3789* ha = adapter block pointer
3790*/
3791void
3792qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
3793{
3794 if (ha->exlogin_buf) {
3795 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
3796 ha->exlogin_buf, ha->exlogin_buf_dma);
3797 ha->exlogin_buf = NULL;
3798 ha->exlogin_size = 0;
3799 }
3800}
3801
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003802int
3803qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
3804{
3805 int rval;
3806 uint16_t size, max_cnt, temp;
3807 struct qla_hw_data *ha = vha->hw;
3808
3809 /* Return if we don't need to alloacate any extended logins */
3810 if (!ql2xexchoffld)
3811 return QLA_SUCCESS;
3812
3813 ql_log(ql_log_info, vha, 0xd014,
3814 "Exchange offload count: %d.\n", ql2xexlogins);
3815
3816 max_cnt = 0;
3817 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
3818 if (rval != QLA_SUCCESS) {
3819 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
3820 "Failed to get exlogin status.\n");
3821 return rval;
3822 }
3823
3824 temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
3825 ha->exchoffld_size = (size * temp);
3826 ql_log(ql_log_info, vha, 0xd016,
3827 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
3828 max_cnt, size, temp);
3829
3830 ql_log(ql_log_info, vha, 0xd017,
3831 "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
3832
3833 /* Get consistent memory for extended logins */
3834 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
3835 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
3836 if (!ha->exchoffld_buf) {
3837 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
3838 "Failed to allocate memory for exchoffld_buf_dma.\n");
3839 return -ENOMEM;
3840 }
3841
3842 /* Now configure the dma buffer */
3843 rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
3844 if (rval) {
3845 ql_log(ql_log_fatal, vha, 0xd02e,
3846 "Setup exchange offload buffer ****FAILED****.\n");
3847 qla2x00_free_exchoffld_buffer(ha);
3848 }
3849
3850 return rval;
3851}
3852
3853/*
3854* qla2x00_free_exchoffld_buffer
3855*
3856* Input:
3857* ha = adapter block pointer
3858*/
3859void
3860qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
3861{
3862 if (ha->exchoffld_buf) {
3863 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
3864 ha->exchoffld_buf, ha->exchoffld_buf_dma);
3865 ha->exchoffld_buf = NULL;
3866 ha->exchoffld_size = 0;
3867 }
3868}
3869
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003871* qla2x00_free_fw_dump
3872* Frees fw dump stuff.
3873*
3874* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003875* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003876*/
3877static void
3878qla2x00_free_fw_dump(struct qla_hw_data *ha)
3879{
3880 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003881 dma_free_coherent(&ha->pdev->dev,
3882 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003883
Chad Dupuisf73cb692014-02-26 04:15:06 -05003884 if (ha->eft)
3885 dma_free_coherent(&ha->pdev->dev,
3886 EFT_SIZE, ha->eft, ha->eft_dma);
3887
3888 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003889 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05003890 if (ha->fw_dump_template)
3891 vfree(ha->fw_dump_template);
3892
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003893 ha->fce = NULL;
3894 ha->fce_dma = 0;
3895 ha->eft = NULL;
3896 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003897 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04003898 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003899 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003900 ha->fw_dump = NULL;
3901 ha->fw_dump_len = 0;
3902 ha->fw_dump_template = NULL;
3903 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003904}
3905
3906/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907* qla2x00_mem_free
3908* Frees all adapter allocated memory.
3909*
3910* Input:
3911* ha = adapter block pointer.
3912*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003913static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003914qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003916 qla2x00_free_fw_dump(ha);
3917
Saurav Kashyap81178772012-08-22 14:21:04 -04003918 if (ha->mctp_dump)
3919 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3920 ha->mctp_dump_dma);
3921
Andrew Vasqueze8711082008-01-31 12:33:48 -08003922 if (ha->srb_mempool)
3923 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003925 if (ha->dcbx_tlv)
3926 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3927 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3928
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003929 if (ha->xgmac_data)
3930 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3931 ha->xgmac_data, ha->xgmac_data_dma);
3932
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 if (ha->sns_cmd)
3934 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936
3937 if (ha->ct_sns)
3938 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003939 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940
Andrew Vasquez88729e52006-06-23 16:10:50 -07003941 if (ha->sfp_data)
3942 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3943
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 if (ha->ms_iocb)
3945 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3946
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003947 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003948 dma_pool_free(ha->s_dma_pool,
3949 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003950
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003951 if (ha->async_pd)
3952 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3953
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 if (ha->s_dma_pool)
3955 dma_pool_destroy(ha->s_dma_pool);
3956
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003958 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3959 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
Giridhar Malavalia9083012010-04-12 17:59:55 -07003961 if (IS_QLA82XX(ha)) {
3962 if (!list_empty(&ha->gbl_dsd_list)) {
3963 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3964
3965 /* clean up allocated prev pool */
3966 list_for_each_entry_safe(dsd_ptr,
3967 tdsd_ptr, &ha->gbl_dsd_list, list) {
3968 dma_pool_free(ha->dl_dma_pool,
3969 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3970 list_del(&dsd_ptr->list);
3971 kfree(dsd_ptr);
3972 }
3973 }
3974 }
3975
3976 if (ha->dl_dma_pool)
3977 dma_pool_destroy(ha->dl_dma_pool);
3978
3979 if (ha->fcp_cmnd_dma_pool)
3980 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3981
3982 if (ha->ctx_mempool)
3983 mempool_destroy(ha->ctx_mempool);
3984
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003985 qlt_mem_free(ha);
3986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003987 if (ha->init_cb)
3988 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003989 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003990 vfree(ha->optrom_buffer);
3991 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003992 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003993 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003994 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995
Andrew Vasqueze8711082008-01-31 12:33:48 -08003996 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003997 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 ha->sns_cmd = NULL;
3999 ha->sns_cmd_dma = 0;
4000 ha->ct_sns = NULL;
4001 ha->ct_sns_dma = 0;
4002 ha->ms_iocb = NULL;
4003 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 ha->init_cb = NULL;
4005 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004006 ha->ex_init_cb = NULL;
4007 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004008 ha->async_pd = NULL;
4009 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010
4011 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004012 ha->dl_dma_pool = NULL;
4013 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 ha->gid_list = NULL;
4016 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004017
4018 ha->tgt.atio_ring = NULL;
4019 ha->tgt.atio_dma = 0;
4020 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021}
4022
4023struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4024 struct qla_hw_data *ha)
4025{
4026 struct Scsi_Host *host;
4027 struct scsi_qla_host *vha = NULL;
4028
4029 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4030 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004031 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4032 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004033 goto fail;
4034 }
4035
4036 /* Clear our data area */
4037 vha = shost_priv(host);
4038 memset(vha, 0, sizeof(scsi_qla_host_t));
4039
4040 vha->host = host;
4041 vha->host_no = host->host_no;
4042 vha->hw = ha;
4043
4044 INIT_LIST_HEAD(&vha->vp_fcports);
4045 INIT_LIST_HEAD(&vha->work_list);
4046 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004047 INIT_LIST_HEAD(&vha->qla_cmd_list);
4048 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004049 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004050 INIT_LIST_HEAD(&vha->plogi_ack_list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004052 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004053 spin_lock_init(&vha->cmd_list_lock);
Joe Carnuccioc1716f02017-03-15 09:48:43 -07004054 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004057 ql_dbg(ql_dbg_init, vha, 0x0041,
4058 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4059 vha->host, vha->hw, vha,
4060 dev_name(&(ha->pdev->dev)));
4061
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 return vha;
4063
4064fail:
4065 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066}
4067
Adrian Bunk01ef66b2008-04-24 15:21:27 -07004068static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004069qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004070{
4071 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004072 uint8_t bail;
4073
4074 QLA_VHA_MARK_BUSY(vha, bail);
4075 if (bail)
4076 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004077
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004078 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004079 if (!e) {
4080 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004081 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004082 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004083
4084 INIT_LIST_HEAD(&e->list);
4085 e->type = type;
4086 e->flags = QLA_EVT_FLAG_FREE;
4087 return e;
4088}
4089
Adrian Bunk01ef66b2008-04-24 15:21:27 -07004090static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004091qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004092{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004093 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004094
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004095 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004096 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004097 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004098 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004099
Andrew Vasquez0971de72008-04-03 13:13:18 -07004100 return QLA_SUCCESS;
4101}
4102
4103int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004104qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004105 u32 data)
4106{
4107 struct qla_work_evt *e;
4108
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004109 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004110 if (!e)
4111 return QLA_FUNCTION_FAILED;
4112
4113 e->u.aen.code = code;
4114 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004115 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004116}
4117
Andrew Vasquez8a659572009-02-08 20:50:12 -08004118int
4119qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4120{
4121 struct qla_work_evt *e;
4122
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004123 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004124 if (!e)
4125 return QLA_FUNCTION_FAILED;
4126
4127 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004128 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004129}
4130
Andrew Vasquezac280b62009-08-20 11:06:05 -07004131#define qla2x00_post_async_work(name, type) \
4132int qla2x00_post_async_##name##_work( \
4133 struct scsi_qla_host *vha, \
4134 fc_port_t *fcport, uint16_t *data) \
4135{ \
4136 struct qla_work_evt *e; \
4137 \
4138 e = qla2x00_alloc_work(vha, type); \
4139 if (!e) \
4140 return QLA_FUNCTION_FAILED; \
4141 \
4142 e->u.logio.fcport = fcport; \
4143 if (data) { \
4144 e->u.logio.data[0] = data[0]; \
4145 e->u.logio.data[1] = data[1]; \
4146 } \
4147 return qla2x00_post_work(vha, e); \
4148}
4149
4150qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4151qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
4152qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4153qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004154qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4155qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004156
Andrew Vasquez3420d362009-10-13 15:16:45 -07004157int
4158qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4159{
4160 struct qla_work_evt *e;
4161
4162 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4163 if (!e)
4164 return QLA_FUNCTION_FAILED;
4165
4166 e->u.uevent.code = code;
4167 return qla2x00_post_work(vha, e);
4168}
4169
4170static void
4171qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4172{
4173 char event_string[40];
4174 char *envp[] = { event_string, NULL };
4175
4176 switch (code) {
4177 case QLA_UEVENT_CODE_FW_DUMP:
4178 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4179 vha->host_no);
4180 break;
4181 default:
4182 /* do nothing */
4183 break;
4184 }
4185 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4186}
4187
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004188int
4189qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4190 uint32_t *data, int cnt)
4191{
4192 struct qla_work_evt *e;
4193
4194 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4195 if (!e)
4196 return QLA_FUNCTION_FAILED;
4197
4198 e->u.aenfx.evtcode = evtcode;
4199 e->u.aenfx.count = cnt;
4200 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4201 return qla2x00_post_work(vha, e);
4202}
4203
Andrew Vasquezac280b62009-08-20 11:06:05 -07004204void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004206{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004207 struct qla_work_evt *e, *tmp;
4208 unsigned long flags;
4209 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004210
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004211 spin_lock_irqsave(&vha->work_lock, flags);
4212 list_splice_init(&vha->work_list, &work);
4213 spin_unlock_irqrestore(&vha->work_lock, flags);
4214
4215 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004216 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004217
4218 switch (e->type) {
4219 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004220 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004221 e->u.aen.code, e->u.aen.data);
4222 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004223 case QLA_EVT_IDC_ACK:
4224 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4225 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004226 case QLA_EVT_ASYNC_LOGIN:
4227 qla2x00_async_login(vha, e->u.logio.fcport,
4228 e->u.logio.data);
4229 break;
4230 case QLA_EVT_ASYNC_LOGIN_DONE:
4231 qla2x00_async_login_done(vha, e->u.logio.fcport,
4232 e->u.logio.data);
4233 break;
4234 case QLA_EVT_ASYNC_LOGOUT:
4235 qla2x00_async_logout(vha, e->u.logio.fcport);
4236 break;
4237 case QLA_EVT_ASYNC_LOGOUT_DONE:
4238 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4239 e->u.logio.data);
4240 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004241 case QLA_EVT_ASYNC_ADISC:
4242 qla2x00_async_adisc(vha, e->u.logio.fcport,
4243 e->u.logio.data);
4244 break;
4245 case QLA_EVT_ASYNC_ADISC_DONE:
4246 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4247 e->u.logio.data);
4248 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004249 case QLA_EVT_UEVENT:
4250 qla2x00_uevent_emit(vha, e->u.uevent.code);
4251 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004252 case QLA_EVT_AENFX:
4253 qlafx00_process_aen(vha, e);
4254 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004255 }
4256 if (e->flags & QLA_EVT_FLAG_FREE)
4257 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004258
4259 /* For each work completed decrement vha ref count */
4260 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004261 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004262}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004264/* Relogins all the fcports of a vport
4265 * Context: dpc thread
4266 */
4267void qla2x00_relogin(struct scsi_qla_host *vha)
4268{
4269 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004270 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004271 uint16_t next_loopid = 0;
4272 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004273 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004274
4275 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4276 /*
4277 * If the port is not ONLINE then try to login
4278 * to it if we haven't run out of retries.
4279 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004280 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4281 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004282 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004283 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004284 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004285 ha->isp_ops->fabric_logout(vha,
4286 fcport->loop_id,
4287 fcport->d_id.b.domain,
4288 fcport->d_id.b.area,
4289 fcport->d_id.b.al_pa);
4290
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004291 if (fcport->loop_id == FC_NO_LOOP_ID) {
4292 fcport->loop_id = next_loopid =
4293 ha->min_external_loopid;
4294 status = qla2x00_find_new_loop_id(
4295 vha, fcport);
4296 if (status != QLA_SUCCESS) {
4297 /* Ran out of IDs to use */
4298 break;
4299 }
4300 }
4301
Andrew Vasquezac280b62009-08-20 11:06:05 -07004302 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004303 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004304 data[0] = 0;
4305 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4306 status = qla2x00_post_async_login_work(
4307 vha, fcport, data);
4308 if (status == QLA_SUCCESS)
4309 continue;
4310 /* Attempt a retry. */
4311 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004312 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004313 status = qla2x00_fabric_login(vha,
4314 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004315 if (status == QLA_SUCCESS) {
4316 int status2;
4317 uint8_t opts;
4318
4319 opts = 0;
4320 if (fcport->flags &
4321 FCF_FCP2_DEVICE)
4322 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004323 status2 =
4324 qla2x00_get_port_database(
4325 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004326 if (status2 != QLA_SUCCESS)
4327 status = 1;
4328 }
4329 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004330 } else
4331 status = qla2x00_local_device_login(vha,
4332 fcport);
4333
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004334 if (status == QLA_SUCCESS) {
4335 fcport->old_loop_id = fcport->loop_id;
4336
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004337 ql_dbg(ql_dbg_disc, vha, 0x2003,
4338 "Port login OK: logged in ID 0x%x.\n",
4339 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004340
4341 qla2x00_update_fcport(vha, fcport);
4342
4343 } else if (status == 1) {
4344 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4345 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004346 ql_dbg(ql_dbg_disc, vha, 0x2007,
4347 "Retrying %d login again loop_id 0x%x.\n",
4348 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004349 } else {
4350 fcport->login_retry = 0;
4351 }
4352
4353 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004354 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004355 }
4356 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4357 break;
4358 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004359}
4360
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004361/* Schedule work on any of the dpc-workqueues */
4362void
4363qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4364{
4365 struct qla_hw_data *ha = base_vha->hw;
4366
4367 switch (work_code) {
4368 case MBA_IDC_AEN: /* 0x8200 */
4369 if (ha->dpc_lp_wq)
4370 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4371 break;
4372
4373 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4374 if (!ha->flags.nic_core_reset_hdlr_active) {
4375 if (ha->dpc_hp_wq)
4376 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4377 } else
4378 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4379 "NIC Core reset is already active. Skip "
4380 "scheduling it again.\n");
4381 break;
4382 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4383 if (ha->dpc_hp_wq)
4384 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4385 break;
4386 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4387 if (ha->dpc_hp_wq)
4388 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4389 break;
4390 default:
4391 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004392 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004393 }
4394
4395 return;
4396}
4397
4398/* Work: Perform NIC Core Unrecoverable state handling */
4399void
4400qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4401{
4402 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004403 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004404 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4405 uint32_t dev_state = 0;
4406
4407 qla83xx_idc_lock(base_vha, 0);
4408 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4409 qla83xx_reset_ownership(base_vha);
4410 if (ha->flags.nic_core_reset_owner) {
4411 ha->flags.nic_core_reset_owner = 0;
4412 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4413 QLA8XXX_DEV_FAILED);
4414 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4415 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4416 }
4417 qla83xx_idc_unlock(base_vha, 0);
4418}
4419
4420/* Work: Execute IDC state handler */
4421void
4422qla83xx_idc_state_handler_work(struct work_struct *work)
4423{
4424 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004425 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004426 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4427 uint32_t dev_state = 0;
4428
4429 qla83xx_idc_lock(base_vha, 0);
4430 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4431 if (dev_state == QLA8XXX_DEV_FAILED ||
4432 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4433 qla83xx_idc_state_handler(base_vha);
4434 qla83xx_idc_unlock(base_vha, 0);
4435}
4436
Saurav Kashyapfa492632012-11-21 02:40:29 -05004437static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004438qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4439{
4440 int rval = QLA_SUCCESS;
4441 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4442 uint32_t heart_beat_counter1, heart_beat_counter2;
4443
4444 do {
4445 if (time_after(jiffies, heart_beat_wait)) {
4446 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4447 "Nic Core f/w is not alive.\n");
4448 rval = QLA_FUNCTION_FAILED;
4449 break;
4450 }
4451
4452 qla83xx_idc_lock(base_vha, 0);
4453 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4454 &heart_beat_counter1);
4455 qla83xx_idc_unlock(base_vha, 0);
4456 msleep(100);
4457 qla83xx_idc_lock(base_vha, 0);
4458 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4459 &heart_beat_counter2);
4460 qla83xx_idc_unlock(base_vha, 0);
4461 } while (heart_beat_counter1 == heart_beat_counter2);
4462
4463 return rval;
4464}
4465
4466/* Work: Perform NIC Core Reset handling */
4467void
4468qla83xx_nic_core_reset_work(struct work_struct *work)
4469{
4470 struct qla_hw_data *ha =
4471 container_of(work, struct qla_hw_data, nic_core_reset);
4472 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4473 uint32_t dev_state = 0;
4474
Saurav Kashyap81178772012-08-22 14:21:04 -04004475 if (IS_QLA2031(ha)) {
4476 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4477 ql_log(ql_log_warn, base_vha, 0xb081,
4478 "Failed to dump mctp\n");
4479 return;
4480 }
4481
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004482 if (!ha->flags.nic_core_reset_hdlr_active) {
4483 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4484 qla83xx_idc_lock(base_vha, 0);
4485 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4486 &dev_state);
4487 qla83xx_idc_unlock(base_vha, 0);
4488 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4489 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4490 "Nic Core f/w is alive.\n");
4491 return;
4492 }
4493 }
4494
4495 ha->flags.nic_core_reset_hdlr_active = 1;
4496 if (qla83xx_nic_core_reset(base_vha)) {
4497 /* NIC Core reset failed. */
4498 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4499 "NIC Core reset failed.\n");
4500 }
4501 ha->flags.nic_core_reset_hdlr_active = 0;
4502 }
4503}
4504
4505/* Work: Handle 8200 IDC aens */
4506void
4507qla83xx_service_idc_aen(struct work_struct *work)
4508{
4509 struct qla_hw_data *ha =
4510 container_of(work, struct qla_hw_data, idc_aen);
4511 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4512 uint32_t dev_state, idc_control;
4513
4514 qla83xx_idc_lock(base_vha, 0);
4515 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4516 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4517 qla83xx_idc_unlock(base_vha, 0);
4518 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4519 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4520 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4521 "Application requested NIC Core Reset.\n");
4522 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4523 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4524 QLA_SUCCESS) {
4525 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4526 "Other protocol driver requested NIC Core Reset.\n");
4527 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4528 }
4529 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4530 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4531 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4532 }
4533}
4534
4535static void
4536qla83xx_wait_logic(void)
4537{
4538 int i;
4539
4540 /* Yield CPU */
4541 if (!in_interrupt()) {
4542 /*
4543 * Wait about 200ms before retrying again.
4544 * This controls the number of retries for single
4545 * lock operation.
4546 */
4547 msleep(100);
4548 schedule();
4549 } else {
4550 for (i = 0; i < 20; i++)
4551 cpu_relax(); /* This a nop instr on i386 */
4552 }
4553}
4554
Saurav Kashyapfa492632012-11-21 02:40:29 -05004555static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004556qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4557{
4558 int rval;
4559 uint32_t data;
4560 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4561 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4562 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004563 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4564 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004565
4566 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4567 if (rval)
4568 return rval;
4569
4570 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4571 return QLA_SUCCESS;
4572 } else {
4573 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4574 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4575 data);
4576 if (rval)
4577 return rval;
4578
4579 msleep(200);
4580
4581 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4582 &data);
4583 if (rval)
4584 return rval;
4585
4586 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4587 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4588 ~(idc_lck_rcvry_stage_mask));
4589 rval = qla83xx_wr_reg(base_vha,
4590 QLA83XX_IDC_LOCK_RECOVERY, data);
4591 if (rval)
4592 return rval;
4593
4594 /* Forcefully perform IDC UnLock */
4595 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4596 &data);
4597 if (rval)
4598 return rval;
4599 /* Clear lock-id by setting 0xff */
4600 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4601 0xff);
4602 if (rval)
4603 return rval;
4604 /* Clear lock-recovery by setting 0x0 */
4605 rval = qla83xx_wr_reg(base_vha,
4606 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4607 if (rval)
4608 return rval;
4609 } else
4610 return QLA_SUCCESS;
4611 }
4612
4613 return rval;
4614}
4615
Saurav Kashyapfa492632012-11-21 02:40:29 -05004616static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004617qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4618{
4619 int rval = QLA_SUCCESS;
4620 uint32_t o_drv_lockid, n_drv_lockid;
4621 unsigned long lock_recovery_timeout;
4622
4623 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4624retry_lockid:
4625 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4626 if (rval)
4627 goto exit;
4628
4629 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4630 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4631 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4632 return QLA_SUCCESS;
4633 else
4634 return QLA_FUNCTION_FAILED;
4635 }
4636
4637 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4638 if (rval)
4639 goto exit;
4640
4641 if (o_drv_lockid == n_drv_lockid) {
4642 qla83xx_wait_logic();
4643 goto retry_lockid;
4644 } else
4645 return QLA_SUCCESS;
4646
4647exit:
4648 return rval;
4649}
4650
4651void
4652qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4653{
4654 uint16_t options = (requester_id << 15) | BIT_6;
4655 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004656 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004657 struct qla_hw_data *ha = base_vha->hw;
4658
4659 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4660retry_lock:
4661 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4662 == QLA_SUCCESS) {
4663 if (data) {
4664 /* Setting lock-id to our function-number */
4665 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4666 ha->portnum);
4667 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004668 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4669 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004670 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004671 "Failed to acquire IDC lock, acquired by %d, "
4672 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004673
4674 /* Retry/Perform IDC-Lock recovery */
4675 if (qla83xx_idc_lock_recovery(base_vha)
4676 == QLA_SUCCESS) {
4677 qla83xx_wait_logic();
4678 goto retry_lock;
4679 } else
4680 ql_log(ql_log_warn, base_vha, 0xb075,
4681 "IDC Lock recovery FAILED.\n");
4682 }
4683
4684 }
4685
4686 return;
4687
4688 /* XXX: IDC-lock implementation using access-control mbx */
4689retry_lock2:
4690 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4691 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4692 "Failed to acquire IDC lock. retrying...\n");
4693 /* Retry/Perform IDC-Lock recovery */
4694 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4695 qla83xx_wait_logic();
4696 goto retry_lock2;
4697 } else
4698 ql_log(ql_log_warn, base_vha, 0xb076,
4699 "IDC Lock recovery FAILED.\n");
4700 }
4701
4702 return;
4703}
4704
4705void
4706qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4707{
Bart Van Assche5897cb22015-06-04 15:57:20 -07004708#if 0
4709 uint16_t options = (requester_id << 15) | BIT_7;
4710#endif
4711 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004712 uint32_t data;
4713 struct qla_hw_data *ha = base_vha->hw;
4714
4715 /* IDC-unlock implementation using driver-unlock/lock-id
4716 * remote registers
4717 */
4718 retry = 0;
4719retry_unlock:
4720 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4721 == QLA_SUCCESS) {
4722 if (data == ha->portnum) {
4723 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4724 /* Clearing lock-id by setting 0xff */
4725 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4726 } else if (retry < 10) {
4727 /* SV: XXX: IDC unlock retrying needed here? */
4728
4729 /* Retry for IDC-unlock */
4730 qla83xx_wait_logic();
4731 retry++;
4732 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01004733 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004734 goto retry_unlock;
4735 }
4736 } else if (retry < 10) {
4737 /* Retry for IDC-unlock */
4738 qla83xx_wait_logic();
4739 retry++;
4740 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01004741 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004742 goto retry_unlock;
4743 }
4744
4745 return;
4746
Bart Van Assche5897cb22015-06-04 15:57:20 -07004747#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004748 /* XXX: IDC-unlock implementation using access-control mbx */
4749 retry = 0;
4750retry_unlock2:
4751 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4752 if (retry < 10) {
4753 /* Retry for IDC-unlock */
4754 qla83xx_wait_logic();
4755 retry++;
4756 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01004757 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004758 goto retry_unlock2;
4759 }
4760 }
4761
4762 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07004763#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004764}
4765
4766int
4767__qla83xx_set_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_set_drv_presence(scsi_qla_host_t *vha)
4785{
4786 int rval = QLA_SUCCESS;
4787
4788 qla83xx_idc_lock(vha, 0);
4789 rval = __qla83xx_set_drv_presence(vha);
4790 qla83xx_idc_unlock(vha, 0);
4791
4792 return rval;
4793}
4794
4795int
4796__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4797{
4798 int rval = QLA_SUCCESS;
4799 struct qla_hw_data *ha = vha->hw;
4800 uint32_t drv_presence;
4801
4802 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4803 if (rval == QLA_SUCCESS) {
4804 drv_presence &= ~(1 << ha->portnum);
4805 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4806 drv_presence);
4807 }
4808
4809 return rval;
4810}
4811
4812int
4813qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4814{
4815 int rval = QLA_SUCCESS;
4816
4817 qla83xx_idc_lock(vha, 0);
4818 rval = __qla83xx_clear_drv_presence(vha);
4819 qla83xx_idc_unlock(vha, 0);
4820
4821 return rval;
4822}
4823
Saurav Kashyapfa492632012-11-21 02:40:29 -05004824static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004825qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4826{
4827 struct qla_hw_data *ha = vha->hw;
4828 uint32_t drv_ack, drv_presence;
4829 unsigned long ack_timeout;
4830
4831 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4832 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4833 while (1) {
4834 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4835 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004836 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004837 break;
4838
4839 if (time_after_eq(jiffies, ack_timeout)) {
4840 ql_log(ql_log_warn, vha, 0xb067,
4841 "RESET ACK TIMEOUT! drv_presence=0x%x "
4842 "drv_ack=0x%x\n", drv_presence, drv_ack);
4843 /*
4844 * The function(s) which did not ack in time are forced
4845 * to withdraw any further participation in the IDC
4846 * reset.
4847 */
4848 if (drv_ack != drv_presence)
4849 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4850 drv_ack);
4851 break;
4852 }
4853
4854 qla83xx_idc_unlock(vha, 0);
4855 msleep(1000);
4856 qla83xx_idc_lock(vha, 0);
4857 }
4858
4859 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4860 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4861}
4862
Saurav Kashyapfa492632012-11-21 02:40:29 -05004863static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004864qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4865{
4866 int rval = QLA_SUCCESS;
4867 uint32_t idc_control;
4868
4869 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4870 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4871
4872 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4873 __qla83xx_get_idc_control(vha, &idc_control);
4874 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4875 __qla83xx_set_idc_control(vha, 0);
4876
4877 qla83xx_idc_unlock(vha, 0);
4878 rval = qla83xx_restart_nic_firmware(vha);
4879 qla83xx_idc_lock(vha, 0);
4880
4881 if (rval != QLA_SUCCESS) {
4882 ql_log(ql_log_fatal, vha, 0xb06a,
4883 "Failed to restart NIC f/w.\n");
4884 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4885 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4886 } else {
4887 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4888 "Success in restarting nic f/w.\n");
4889 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4890 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4891 }
4892
4893 return rval;
4894}
4895
4896/* Assumes idc_lock always held on entry */
4897int
4898qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4899{
4900 struct qla_hw_data *ha = base_vha->hw;
4901 int rval = QLA_SUCCESS;
4902 unsigned long dev_init_timeout;
4903 uint32_t dev_state;
4904
4905 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4906 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4907
4908 while (1) {
4909
4910 if (time_after_eq(jiffies, dev_init_timeout)) {
4911 ql_log(ql_log_warn, base_vha, 0xb06e,
4912 "Initialization TIMEOUT!\n");
4913 /* Init timeout. Disable further NIC Core
4914 * communication.
4915 */
4916 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4917 QLA8XXX_DEV_FAILED);
4918 ql_log(ql_log_info, base_vha, 0xb06f,
4919 "HW State: FAILED.\n");
4920 }
4921
4922 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4923 switch (dev_state) {
4924 case QLA8XXX_DEV_READY:
4925 if (ha->flags.nic_core_reset_owner)
4926 qla83xx_idc_audit(base_vha,
4927 IDC_AUDIT_COMPLETION);
4928 ha->flags.nic_core_reset_owner = 0;
4929 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4930 "Reset_owner reset by 0x%x.\n",
4931 ha->portnum);
4932 goto exit;
4933 case QLA8XXX_DEV_COLD:
4934 if (ha->flags.nic_core_reset_owner)
4935 rval = qla83xx_device_bootstrap(base_vha);
4936 else {
4937 /* Wait for AEN to change device-state */
4938 qla83xx_idc_unlock(base_vha, 0);
4939 msleep(1000);
4940 qla83xx_idc_lock(base_vha, 0);
4941 }
4942 break;
4943 case QLA8XXX_DEV_INITIALIZING:
4944 /* Wait for AEN to change device-state */
4945 qla83xx_idc_unlock(base_vha, 0);
4946 msleep(1000);
4947 qla83xx_idc_lock(base_vha, 0);
4948 break;
4949 case QLA8XXX_DEV_NEED_RESET:
4950 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4951 qla83xx_need_reset_handler(base_vha);
4952 else {
4953 /* Wait for AEN to change device-state */
4954 qla83xx_idc_unlock(base_vha, 0);
4955 msleep(1000);
4956 qla83xx_idc_lock(base_vha, 0);
4957 }
4958 /* reset timeout value after need reset handler */
4959 dev_init_timeout = jiffies +
4960 (ha->fcoe_dev_init_timeout * HZ);
4961 break;
4962 case QLA8XXX_DEV_NEED_QUIESCENT:
4963 /* XXX: DEBUG for now */
4964 qla83xx_idc_unlock(base_vha, 0);
4965 msleep(1000);
4966 qla83xx_idc_lock(base_vha, 0);
4967 break;
4968 case QLA8XXX_DEV_QUIESCENT:
4969 /* XXX: DEBUG for now */
4970 if (ha->flags.quiesce_owner)
4971 goto exit;
4972
4973 qla83xx_idc_unlock(base_vha, 0);
4974 msleep(1000);
4975 qla83xx_idc_lock(base_vha, 0);
4976 dev_init_timeout = jiffies +
4977 (ha->fcoe_dev_init_timeout * HZ);
4978 break;
4979 case QLA8XXX_DEV_FAILED:
4980 if (ha->flags.nic_core_reset_owner)
4981 qla83xx_idc_audit(base_vha,
4982 IDC_AUDIT_COMPLETION);
4983 ha->flags.nic_core_reset_owner = 0;
4984 __qla83xx_clear_drv_presence(base_vha);
4985 qla83xx_idc_unlock(base_vha, 0);
4986 qla8xxx_dev_failed_handler(base_vha);
4987 rval = QLA_FUNCTION_FAILED;
4988 qla83xx_idc_lock(base_vha, 0);
4989 goto exit;
4990 case QLA8XXX_BAD_VALUE:
4991 qla83xx_idc_unlock(base_vha, 0);
4992 msleep(1000);
4993 qla83xx_idc_lock(base_vha, 0);
4994 break;
4995 default:
4996 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09004997 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004998 qla83xx_idc_unlock(base_vha, 0);
4999 qla8xxx_dev_failed_handler(base_vha);
5000 rval = QLA_FUNCTION_FAILED;
5001 qla83xx_idc_lock(base_vha, 0);
5002 goto exit;
5003 }
5004 }
5005
5006exit:
5007 return rval;
5008}
5009
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005010void
5011qla2x00_disable_board_on_pci_error(struct work_struct *work)
5012{
5013 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5014 board_disable);
5015 struct pci_dev *pdev = ha->pdev;
5016 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5017
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005018 /* if UNLOAD flag is already set, then continue unload,
5019 * where it was set first.
5020 */
5021 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5022 return;
5023
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005024 ql_log(ql_log_warn, base_vha, 0x015b,
5025 "Disabling adapter.\n");
5026
5027 set_bit(UNLOADING, &base_vha->dpc_flags);
5028
5029 qla2x00_delete_all_vps(ha, base_vha);
5030
5031 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5032
5033 qla2x00_dfs_remove(base_vha);
5034
5035 qla84xx_put_chip(base_vha);
5036
5037 if (base_vha->timer_active)
5038 qla2x00_stop_timer(base_vha);
5039
5040 base_vha->flags.online = 0;
5041
5042 qla2x00_destroy_deferred_work(ha);
5043
5044 /*
5045 * Do not try to stop beacon blink as it will issue a mailbox
5046 * command.
5047 */
5048 qla2x00_free_sysfs_attr(base_vha, false);
5049
5050 fc_remove_host(base_vha->host);
5051
5052 scsi_remove_host(base_vha->host);
5053
5054 base_vha->flags.init_done = 0;
5055 qla25xx_delete_queues(base_vha);
5056 qla2x00_free_irqs(base_vha);
5057 qla2x00_free_fcports(base_vha);
5058 qla2x00_mem_free(ha);
5059 qla82xx_md_free(base_vha);
5060 qla2x00_free_queues(ha);
5061
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005062 qla2x00_unmap_iobases(ha);
5063
5064 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005065 pci_disable_pcie_error_reporting(pdev);
5066 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005067
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005068 /*
5069 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5070 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005071}
5072
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073/**************************************************************************
5074* qla2x00_do_dpc
5075* This kernel thread is a task that is schedule by the interrupt handler
5076* to perform the background processing for interrupts.
5077*
5078* Notes:
5079* This task always run in the context of a kernel thread. It
5080* is kick-off by the driver's detect code and starts up
5081* up one per adapter. It immediately goes to sleep and waits for
5082* some fibre event. When either the interrupt handler or
5083* the timer routine detects a event it will one of the task
5084* bits then wake us up.
5085**************************************************************************/
5086static int
5087qla2x00_do_dpc(void *data)
5088{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005089 scsi_qla_host_t *base_vha;
5090 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005091
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005092 ha = (struct qla_hw_data *)data;
5093 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094
Dongsheng Yang8698a742014-03-11 18:09:12 +08005095 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096
James Bottomley563585e2011-01-27 16:12:37 -05005097 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005098 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005099 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5100 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101
Christoph Hellwig39a11242006-02-14 18:46:22 +01005102 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005104 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5105 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
Andrew Vasquez85880802009-12-15 21:29:46 -08005107 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005108 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5109 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005110 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005111 }
5112
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 ha->dpc_active = 1;
5114
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005115 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5116 "DPC handler waking up, dpc_flags=0x%lx.\n",
5117 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005119 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5120 break;
5121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005122 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005123
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005124 if (IS_P3P_TYPE(ha)) {
5125 if (IS_QLA8044(ha)) {
5126 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5127 &base_vha->dpc_flags)) {
5128 qla8044_idc_lock(ha);
5129 qla8044_wr_direct(base_vha,
5130 QLA8044_CRB_DEV_STATE_INDEX,
5131 QLA8XXX_DEV_FAILED);
5132 qla8044_idc_unlock(ha);
5133 ql_log(ql_log_info, base_vha, 0x4004,
5134 "HW State: FAILED.\n");
5135 qla8044_device_state_handler(base_vha);
5136 continue;
5137 }
5138
5139 } else {
5140 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5141 &base_vha->dpc_flags)) {
5142 qla82xx_idc_lock(ha);
5143 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5144 QLA8XXX_DEV_FAILED);
5145 qla82xx_idc_unlock(ha);
5146 ql_log(ql_log_info, base_vha, 0x0151,
5147 "HW State: FAILED.\n");
5148 qla82xx_device_state_handler(base_vha);
5149 continue;
5150 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005151 }
5152
5153 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5154 &base_vha->dpc_flags)) {
5155
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005156 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5157 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005158 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5159 &base_vha->dpc_flags))) {
5160 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5161 /* FCoE-ctx reset failed.
5162 * Escalate to chip-reset
5163 */
5164 set_bit(ISP_ABORT_NEEDED,
5165 &base_vha->dpc_flags);
5166 }
5167 clear_bit(ABORT_ISP_ACTIVE,
5168 &base_vha->dpc_flags);
5169 }
5170
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005171 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5172 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005173 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005174 } else if (IS_QLAFX00(ha)) {
5175 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5176 &base_vha->dpc_flags)) {
5177 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5178 "Firmware Reset Recovery\n");
5179 if (qlafx00_reset_initialize(base_vha)) {
5180 /* Failed. Abort isp later. */
5181 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005182 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005183 set_bit(ISP_UNRECOVERABLE,
5184 &base_vha->dpc_flags);
5185 ql_dbg(ql_dbg_dpc, base_vha,
5186 0x4021,
5187 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005188 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005189 }
5190 }
5191
5192 if (test_and_clear_bit(FX00_TARGET_SCAN,
5193 &base_vha->dpc_flags)) {
5194 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5195 "ISPFx00 Target Scan scheduled\n");
5196 if (qlafx00_rescan_isp(base_vha)) {
5197 if (!test_bit(UNLOADING,
5198 &base_vha->dpc_flags))
5199 set_bit(ISP_UNRECOVERABLE,
5200 &base_vha->dpc_flags);
5201 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5202 "ISPFx00 Target Scan Failed\n");
5203 }
5204 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5205 "ISPFx00 Target Scan End\n");
5206 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005207 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5208 &base_vha->dpc_flags)) {
5209 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5210 "ISPFx00 Host Info resend scheduled\n");
5211 qlafx00_fx_disc(base_vha,
5212 &base_vha->hw->mr.fcport,
5213 FXDISC_REG_HOST_INFO);
5214 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005215 }
5216
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005217 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5218 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005220 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5221 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005223 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224
Giridhar Malavalia9083012010-04-12 17:59:55 -07005225 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 /* failed. retry later */
5227 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005228 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005230 clear_bit(ABORT_ISP_ACTIVE,
5231 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005232 }
5233
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005234 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5235 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 }
5237
David Jefferya394aac2012-11-21 02:39:54 -05005238 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5239 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005240 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005241 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005242
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005243 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
5244 int ret;
5245 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
5246 if (ret != QLA_SUCCESS)
5247 ql_log(ql_log_warn, base_vha, 0x121,
5248 "Failed to enable receiving of RSCN "
5249 "requests: 0x%x.\n", ret);
5250 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
5251 }
5252
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005253 if (IS_QLAFX00(ha))
5254 goto loop_resync_check;
5255
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005256 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005257 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5258 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005259 if (IS_P3P_TYPE(ha)) {
5260 if (IS_QLA82XX(ha))
5261 qla82xx_device_state_handler(base_vha);
5262 if (IS_QLA8044(ha))
5263 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005264 clear_bit(ISP_QUIESCE_NEEDED,
5265 &base_vha->dpc_flags);
5266 if (!ha->flags.quiesce_owner) {
5267 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005268 if (IS_QLA82XX(ha)) {
5269 qla82xx_idc_lock(ha);
5270 qla82xx_clear_qsnt_ready(
5271 base_vha);
5272 qla82xx_idc_unlock(ha);
5273 } else if (IS_QLA8044(ha)) {
5274 qla8044_idc_lock(ha);
5275 qla8044_clear_qsnt_ready(
5276 base_vha);
5277 qla8044_idc_unlock(ha);
5278 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005279 }
5280 } else {
5281 clear_bit(ISP_QUIESCE_NEEDED,
5282 &base_vha->dpc_flags);
5283 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005284 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005285 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5286 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005287 }
5288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005289 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005290 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005291 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005293 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5294 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005295 qla2x00_rst_aen(base_vha);
5296 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005297 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5298 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 }
5300
5301 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005302 if ((test_and_clear_bit(RELOGIN_NEEDED,
5303 &base_vha->dpc_flags)) &&
5304 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5305 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005307 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5308 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005309 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005310 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5311 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005313loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005314 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005315 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005317 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5318 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
5320 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005321 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322
Bart Van Assche52c82822015-07-09 07:23:26 -07005323 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005325 clear_bit(LOOP_RESYNC_ACTIVE,
5326 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 }
5328
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005329 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5330 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331 }
5332
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005333 if (IS_QLAFX00(ha))
5334 goto intr_on_check;
5335
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005336 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5337 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5338 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5339 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005340 }
5341
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005342intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005344 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005346 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005347 &base_vha->dpc_flags)) {
5348 if (ha->beacon_blink_led == 1)
5349 ha->isp_ops->beacon_blink(base_vha);
5350 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005351
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005352 if (!IS_QLAFX00(ha))
5353 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005354
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005356end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005357 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005359 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005361 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5362 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363
5364 /*
5365 * Make sure that nobody tries to wake us up again.
5366 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367 ha->dpc_active = 0;
5368
Andrew Vasquezac280b62009-08-20 11:06:05 -07005369 /* Cleanup any residual CTX SRBs. */
5370 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5371
Christoph Hellwig39a11242006-02-14 18:46:22 +01005372 return 0;
5373}
5374
5375void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005376qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005377{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005378 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005379 struct task_struct *t = ha->dpc_thread;
5380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005381 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005382 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383}
5384
5385/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386* qla2x00_rst_aen
5387* Processes asynchronous reset.
5388*
5389* Input:
5390* ha = adapter block pointer.
5391*/
5392static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005393qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005395 if (vha->flags.online && !vha->flags.reset_active &&
5396 !atomic_read(&vha->loop_down_timer) &&
5397 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005399 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400
5401 /*
5402 * Issue marker command only when we are going to start
5403 * the I/O.
5404 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005405 vha->marker_needed = 1;
5406 } while (!atomic_read(&vha->loop_down_timer) &&
5407 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408 }
5409}
5410
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411/**************************************************************************
5412* qla2x00_timer
5413*
5414* Description:
5415* One second timer
5416*
5417* Context: Interrupt
5418***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005419void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005420qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 int start_dpc = 0;
5424 int index;
5425 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005426 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005427 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005428 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005429
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005430 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005431 ql_dbg(ql_dbg_timer, vha, 0x6000,
5432 "EEH = %d, restarting timer.\n",
5433 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005434 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5435 return;
5436 }
5437
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005438 /*
5439 * Hardware read to raise pending EEH errors during mailbox waits. If
5440 * the read returns -1 then disable the board.
5441 */
5442 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005443 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005444 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005447 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005448 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005449 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5450 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005451 if (IS_QLA82XX(ha))
5452 qla82xx_watchdog(vha);
5453 else if (IS_QLA8044(ha))
5454 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005455 }
5456
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005457 if (!vha->vp_idx && IS_QLAFX00(ha))
5458 qlafx00_timer_routine(vha);
5459
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005461 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005462 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5463 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005464 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005466 if (atomic_read(&vha->loop_down_timer) ==
5467 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005469 ql_log(ql_log_info, vha, 0x6008,
5470 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005472 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5473 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005475 /*
5476 * Schedule an ISP abort to return any FCP2-device
5477 * commands.
5478 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005479 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005480 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005481 spin_lock_irqsave(&ha->hardware_lock,
5482 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005483 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005484 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005485 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005486 index++) {
5487 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005488
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005489 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005490 if (!sp)
5491 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005492 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005493 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005494 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005495 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005496 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005498 if (IS_QLA82XX(ha))
5499 set_bit(FCOE_CTX_RESET_NEEDED,
5500 &vha->dpc_flags);
5501 else
5502 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005503 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005504 break;
5505 }
5506 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005507 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509 start_dpc++;
5510 }
5511
5512 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005513 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005514 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005515 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 "Loop down - aborting ISP.\n");
5517
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005518 if (IS_QLA82XX(ha))
5519 set_bit(FCOE_CTX_RESET_NEEDED,
5520 &vha->dpc_flags);
5521 else
5522 set_bit(ISP_ABORT_NEEDED,
5523 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 }
5525 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005526 ql_dbg(ql_dbg_timer, vha, 0x600a,
5527 "Loop down - seconds remaining %d.\n",
5528 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005530 /* Check if beacon LED needs to be blinked for physical host only */
5531 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005532 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005533 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005534 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5535 start_dpc++;
5536 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005537 }
5538
Andrew Vasquez550bf572008-04-24 15:21:23 -07005539 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005540 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005541 start_dpc++;
5542
Linus Torvalds1da177e2005-04-16 15:20:36 -07005543 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005544 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5545 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5546 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005547 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005548 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5549 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005550 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5551 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005552 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005553 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005554 ql_dbg(ql_dbg_timer, vha, 0x600b,
5555 "isp_abort_needed=%d loop_resync_needed=%d "
5556 "fcport_update_needed=%d start_dpc=%d "
5557 "reset_marker_needed=%d",
5558 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5559 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5560 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5561 start_dpc,
5562 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5563 ql_dbg(ql_dbg_timer, vha, 0x600c,
5564 "beacon_blink_needed=%d isp_unrecoverable=%d "
5565 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005566 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005567 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5568 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5569 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5570 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005571 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005572 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005575 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576}
5577
Andrew Vasquez54333832005-11-09 15:49:04 -08005578/* Firmware interface routines. */
5579
Chad Dupuisf73cb692014-02-26 04:15:06 -05005580#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08005581#define FW_ISP21XX 0
5582#define FW_ISP22XX 1
5583#define FW_ISP2300 2
5584#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005585#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005586#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005587#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005588#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005589#define FW_ISP2031 8
5590#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005591#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005592
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005593#define FW_FILE_ISP21XX "ql2100_fw.bin"
5594#define FW_FILE_ISP22XX "ql2200_fw.bin"
5595#define FW_FILE_ISP2300 "ql2300_fw.bin"
5596#define FW_FILE_ISP2322 "ql2322_fw.bin"
5597#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005598#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005599#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005600#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005601#define FW_FILE_ISP2031 "ql2600_fw.bin"
5602#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005603#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05005604
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005605
Daniel Walkere1e82b62008-05-12 22:21:10 -07005606static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005607
5608static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005609 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5610 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5611 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5612 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5613 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005614 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005615 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005616 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005617 { .name = FW_FILE_ISP2031, },
5618 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005619 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005620};
5621
5622struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005623qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005624{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005625 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005626 struct fw_blob *blob;
5627
Andrew Vasquez54333832005-11-09 15:49:04 -08005628 if (IS_QLA2100(ha)) {
5629 blob = &qla_fw_blobs[FW_ISP21XX];
5630 } else if (IS_QLA2200(ha)) {
5631 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005632 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005633 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005634 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005635 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005636 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005637 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005638 } else if (IS_QLA25XX(ha)) {
5639 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005640 } else if (IS_QLA81XX(ha)) {
5641 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005642 } else if (IS_QLA82XX(ha)) {
5643 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005644 } else if (IS_QLA2031(ha)) {
5645 blob = &qla_fw_blobs[FW_ISP2031];
5646 } else if (IS_QLA8031(ha)) {
5647 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005648 } else if (IS_QLA27XX(ha)) {
5649 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03005650 } else {
5651 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005652 }
5653
Daniel Walkere1e82b62008-05-12 22:21:10 -07005654 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005655 if (blob->fw)
5656 goto out;
5657
5658 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005659 ql_log(ql_log_warn, vha, 0x0063,
5660 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005661 blob->fw = NULL;
5662 blob = NULL;
5663 goto out;
5664 }
5665
5666out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005667 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005668 return blob;
5669}
5670
5671static void
5672qla2x00_release_firmware(void)
5673{
5674 int idx;
5675
Daniel Walkere1e82b62008-05-12 22:21:10 -07005676 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005677 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005678 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005679 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005680}
5681
Seokmann Ju14e660e2007-09-20 14:07:36 -07005682static pci_ers_result_t
5683qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5684{
Andrew Vasquez85880802009-12-15 21:29:46 -08005685 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5686 struct qla_hw_data *ha = vha->hw;
5687
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005688 ql_dbg(ql_dbg_aer, vha, 0x9000,
5689 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005690
Seokmann Ju14e660e2007-09-20 14:07:36 -07005691 switch (state) {
5692 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005693 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005694 return PCI_ERS_RESULT_CAN_RECOVER;
5695 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005696 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005697 /* For ISP82XX complete any pending mailbox cmd */
5698 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005699 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005700 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5701 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005702 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005703 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005704 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005705 /* Return back all IOs */
5706 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005707 return PCI_ERS_RESULT_NEED_RESET;
5708 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005709 ha->flags.pci_channel_io_perm_failure = 1;
5710 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005711 return PCI_ERS_RESULT_DISCONNECT;
5712 }
5713 return PCI_ERS_RESULT_NEED_RESET;
5714}
5715
5716static pci_ers_result_t
5717qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5718{
5719 int risc_paused = 0;
5720 uint32_t stat;
5721 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005722 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5723 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005724 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5725 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5726
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005727 if (IS_QLA82XX(ha))
5728 return PCI_ERS_RESULT_RECOVERED;
5729
Seokmann Ju14e660e2007-09-20 14:07:36 -07005730 spin_lock_irqsave(&ha->hardware_lock, flags);
5731 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5732 stat = RD_REG_DWORD(&reg->hccr);
5733 if (stat & HCCR_RISC_PAUSE)
5734 risc_paused = 1;
5735 } else if (IS_QLA23XX(ha)) {
5736 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5737 if (stat & HSR_RISC_PAUSED)
5738 risc_paused = 1;
5739 } else if (IS_FWI2_CAPABLE(ha)) {
5740 stat = RD_REG_DWORD(&reg24->host_status);
5741 if (stat & HSRX_RISC_PAUSED)
5742 risc_paused = 1;
5743 }
5744 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5745
5746 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005747 ql_log(ql_log_info, base_vha, 0x9003,
5748 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005749 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005750
5751 return PCI_ERS_RESULT_NEED_RESET;
5752 } else
5753 return PCI_ERS_RESULT_RECOVERED;
5754}
5755
Saurav Kashyapfa492632012-11-21 02:40:29 -05005756static uint32_t
5757qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005758{
5759 uint32_t rval = QLA_FUNCTION_FAILED;
5760 uint32_t drv_active = 0;
5761 struct qla_hw_data *ha = base_vha->hw;
5762 int fn;
5763 struct pci_dev *other_pdev = NULL;
5764
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005765 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5766 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005767
5768 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5769
5770 if (base_vha->flags.online) {
5771 /* Abort all outstanding commands,
5772 * so as to be requeued later */
5773 qla2x00_abort_isp_cleanup(base_vha);
5774 }
5775
5776
5777 fn = PCI_FUNC(ha->pdev->devfn);
5778 while (fn > 0) {
5779 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005780 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5781 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005782 other_pdev =
5783 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5784 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5785 fn));
5786
5787 if (!other_pdev)
5788 continue;
5789 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005790 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5791 "Found PCI func available and enable at 0x%x.\n",
5792 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005793 pci_dev_put(other_pdev);
5794 break;
5795 }
5796 pci_dev_put(other_pdev);
5797 }
5798
5799 if (!fn) {
5800 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005801 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5802 "This devfn is reset owner = 0x%x.\n",
5803 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005804 qla82xx_idc_lock(ha);
5805
5806 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005807 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005808
5809 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5810 QLA82XX_IDC_VERSION);
5811
5812 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005813 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5814 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005815
5816 qla82xx_idc_unlock(ha);
5817 /* Reset if device is not already reset
5818 * drv_active would be 0 if a reset has already been done
5819 */
5820 if (drv_active)
5821 rval = qla82xx_start_firmware(base_vha);
5822 else
5823 rval = QLA_SUCCESS;
5824 qla82xx_idc_lock(ha);
5825
5826 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005827 ql_log(ql_log_info, base_vha, 0x900b,
5828 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005829 qla82xx_clear_drv_active(ha);
5830 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005831 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005832 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005833 ql_log(ql_log_info, base_vha, 0x900c,
5834 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005835 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005836 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005837 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005838 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005839 rval = qla82xx_restart_isp(base_vha);
5840 qla82xx_idc_lock(ha);
5841 /* Clear driver state register */
5842 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5843 qla82xx_set_drv_active(base_vha);
5844 }
5845 qla82xx_idc_unlock(ha);
5846 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005847 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5848 "This devfn is not reset owner = 0x%x.\n",
5849 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005850 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005851 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005852 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005853 rval = qla82xx_restart_isp(base_vha);
5854 qla82xx_idc_lock(ha);
5855 qla82xx_set_drv_active(base_vha);
5856 qla82xx_idc_unlock(ha);
5857 }
5858 }
5859 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5860
5861 return rval;
5862}
5863
Seokmann Ju14e660e2007-09-20 14:07:36 -07005864static pci_ers_result_t
5865qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5866{
5867 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005868 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5869 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005870 struct rsp_que *rsp;
5871 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005872
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005873 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5874 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005875
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005876 /* Workaround: qla2xxx driver which access hardware earlier
5877 * needs error state to be pci_channel_io_online.
5878 * Otherwise mailbox command timesout.
5879 */
5880 pdev->error_state = pci_channel_io_normal;
5881
5882 pci_restore_state(pdev);
5883
Richard Lary8c1496b2010-02-18 10:07:29 -08005884 /* pci_restore_state() clears the saved_state flag of the device
5885 * save restored state which resets saved_state flag
5886 */
5887 pci_save_state(pdev);
5888
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005889 if (ha->mem_only)
5890 rc = pci_enable_device_mem(pdev);
5891 else
5892 rc = pci_enable_device(pdev);
5893
5894 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005895 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005896 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005897 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005898 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005899
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005900 rsp = ha->rsp_q_map[0];
5901 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005902 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005904 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005905 goto exit_slot_reset;
5906
5907 if (IS_QLA82XX(ha)) {
5908 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5909 ret = PCI_ERS_RESULT_RECOVERED;
5910 goto exit_slot_reset;
5911 } else
5912 goto exit_slot_reset;
5913 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005914
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005915 while (ha->flags.mbox_busy && retries--)
5916 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005918 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005919 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005920 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005921 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005922
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005923
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005924exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005925 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5926 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005927
Seokmann Ju14e660e2007-09-20 14:07:36 -07005928 return ret;
5929}
5930
5931static void
5932qla2xxx_pci_resume(struct pci_dev *pdev)
5933{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005934 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5935 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005936 int ret;
5937
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005938 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5939 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005941 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005942 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005943 ql_log(ql_log_fatal, base_vha, 0x9002,
5944 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005945 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005946
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005947 pci_cleanup_aer_uncorrect_error_status(pdev);
5948
Andrew Vasquez85880802009-12-15 21:29:46 -08005949 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005950}
5951
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04005952static void
5953qla83xx_disable_laser(scsi_qla_host_t *vha)
5954{
5955 uint32_t reg, data, fn;
5956 struct qla_hw_data *ha = vha->hw;
5957 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5958
5959 /* pci func #/port # */
5960 ql_dbg(ql_dbg_init, vha, 0x004b,
5961 "Disabling Laser for hba: %p\n", vha);
5962
5963 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5964 (BIT_15|BIT_14|BIT_13|BIT_12));
5965
5966 fn = (fn >> 12);
5967
5968 if (fn & 1)
5969 reg = PORT_1_2031;
5970 else
5971 reg = PORT_0_2031;
5972
5973 data = LASER_OFF_2031;
5974
5975 qla83xx_wr_reg(vha, reg, data);
5976}
5977
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005978static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005979 .error_detected = qla2xxx_pci_error_detected,
5980 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5981 .slot_reset = qla2xxx_pci_slot_reset,
5982 .resume = qla2xxx_pci_resume,
5983};
5984
Andrew Vasquez54333832005-11-09 15:49:04 -08005985static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005986 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5987 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5988 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5989 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5990 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5991 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5992 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5993 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5994 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005995 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005996 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5997 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005998 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005999 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006000 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006001 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006002 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006003 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006004 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006005 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006006 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006007 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006008 { 0 },
6009};
6010MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6011
Andrew Vasquezfca29702005-07-06 10:31:47 -07006012static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006013 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006014 .driver = {
6015 .owner = THIS_MODULE,
6016 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006017 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006018 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006019 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006020 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006021 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006022};
6023
Al Viro75ef9de2013-04-04 19:09:41 -04006024static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006025 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006026 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006027};
6028
Linus Torvalds1da177e2005-04-16 15:20:36 -07006029/**
6030 * qla2x00_module_init - Module initialization.
6031 **/
6032static int __init
6033qla2x00_module_init(void)
6034{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006035 int ret = 0;
6036
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006038 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006039 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006041 ql_log(ql_log_fatal, NULL, 0x0001,
6042 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043 return -ENOMEM;
6044 }
6045
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006046 /* Initialize target kmem_cache and mem_pools */
6047 ret = qlt_init();
6048 if (ret < 0) {
6049 kmem_cache_destroy(srb_cachep);
6050 return ret;
6051 } else if (ret > 0) {
6052 /*
6053 * If initiator mode is explictly disabled by qlt_init(),
6054 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6055 * performing scsi_scan_target() during LOOP UP event.
6056 */
6057 qla2xxx_transport_functions.disable_target_scan = 1;
6058 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6059 }
6060
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 /* Derive version string. */
6062 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006063 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006064 strcat(qla2x00_version_str, "-debug");
6065
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006066 qla2xxx_transport_template =
6067 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006068 if (!qla2xxx_transport_template) {
6069 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006070 ql_log(ql_log_fatal, NULL, 0x0002,
6071 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006072 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006074 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006075
6076 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6077 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006078 ql_log(ql_log_fatal, NULL, 0x0003,
6079 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006080 }
6081
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006082 qla2xxx_transport_vport_template =
6083 fc_attach_transport(&qla2xxx_transport_vport_functions);
6084 if (!qla2xxx_transport_vport_template) {
6085 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006086 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006087 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006088 ql_log(ql_log_fatal, NULL, 0x0004,
6089 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006090 return -ENODEV;
6091 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006092 ql_log(ql_log_info, NULL, 0x0005,
6093 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006094 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006095 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006096 if (ret) {
6097 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006098 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006099 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006100 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006101 ql_log(ql_log_fatal, NULL, 0x0006,
6102 "pci_register_driver failed...ret=%d Failing load!.\n",
6103 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006104 }
6105 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106}
6107
6108/**
6109 * qla2x00_module_exit - Module cleanup.
6110 **/
6111static void __exit
6112qla2x00_module_exit(void)
6113{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006114 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006115 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006116 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006117 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006118 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006119 if (ctx_cachep)
6120 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006122 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123}
6124
6125module_init(qla2x00_module_init);
6126module_exit(qla2x00_module_exit);
6127
6128MODULE_AUTHOR("QLogic Corporation");
6129MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6130MODULE_LICENSE("GPL");
6131MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006132MODULE_FIRMWARE(FW_FILE_ISP21XX);
6133MODULE_FIRMWARE(FW_FILE_ISP22XX);
6134MODULE_FIRMWARE(FW_FILE_ISP2300);
6135MODULE_FIRMWARE(FW_FILE_ISP2322);
6136MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006137MODULE_FIRMWARE(FW_FILE_ISP25XX);