blob: 95bee6807f46e5bdab9b2861dcb9ed491a0d33fa [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);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070083MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070084 "Option to enable extended error logging,\n"
85 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
86 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
87 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
88 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
89 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
90 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
91 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
92 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050093 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
94 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070095 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080096 "\t\t0x1e400000 - Preferred value for capturing essential "
97 "debug information (equivalent to old "
98 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070099 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700100
Giridhar Malavalia9083012010-04-12 17:59:55 -0700101int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800102module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700103MODULE_PARM_DESC(ql2xshiftctondsd,
104 "Set to control shifting of command type processing "
105 "based on total number of SG elements.");
106
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700107int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400108module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700109MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100110 "Enables FDMI registrations. "
111 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700112
Chad Dupuis50280c02013-10-30 03:38:14 -0400113#define MAX_Q_DEPTH 32
114static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700115module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
116MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400117 "Maximum queue depth to set for each LUN. "
118 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700119
Arun Easi9e522cd2012-08-22 14:21:31 -0400120int ql2xenabledif = 2;
121module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700122MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600123 " Enable T10-CRC-DIF:\n"
124 " Default is 2.\n"
125 " 0 -- No DIF Support\n"
126 " 1 -- Enable DIF for all types\n"
127 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700128
Arun Easi8cb20492011-08-16 11:29:22 -0700129int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700130module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
131MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700132 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600133 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700134 " 0 -- Error isolation disabled\n"
135 " 1 -- Error isolation enabled only for DIX Type 0\n"
136 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700137
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700138int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800139module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700140MODULE_PARM_DESC(ql2xiidmaenable,
141 "Enables iIDMA settings "
142 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
143
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800144int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800145module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800146MODULE_PARM_DESC(ql2xmaxqueues,
147 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700148 "Default is 1 for single queue. Set it to number "
149 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700150
151int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800152module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700153MODULE_PARM_DESC(ql2xmultique_tag,
154 "Enables CPU affinity settings for the driver "
155 "Default is 0 for no affinity of request and response IO. "
156 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700157
158int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700159module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700160MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 "Option to specify location from which to load ISP firmware:.\n"
162 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700163 " interface.\n"
164 " 1 -- load firmware from flash.\n"
165 " 0 -- use default semantics.\n");
166
Andrew Vasquezae97c912010-02-18 10:07:28 -0800167int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800168module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800169MODULE_PARM_DESC(ql2xetsenable,
170 "Enables firmware ETS burst."
171 "Default is 0 - skip ETS enablement.");
172
Giridhar Malavali69078692010-05-28 15:08:28 -0700173int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700174module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700175MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700176 "Option to specify scheme for request queue posting.\n"
177 " 0 -- Regular doorbell.\n"
178 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700179
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700180int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800181module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700182MODULE_PARM_DESC(ql2xtargetreset,
183 "Enable target reset."
184 "Default is 1 - use hw defaults.");
185
Chad Dupuis4da26e12010-10-15 11:27:40 -0700186int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800187module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700188MODULE_PARM_DESC(ql2xgffidenable,
189 "Enables GFF_ID checks of port type. "
190 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700191
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700192int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800193module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700194MODULE_PARM_DESC(ql2xasynctmfenable,
195 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
196 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700197
198int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700199module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700200MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700201 "Option to specify reset behaviour.\n"
202 " 0 (Default) -- Reset on failure.\n"
203 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700204
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200205uint64_t ql2xmaxlun = MAX_LUNS;
206module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700207MODULE_PARM_DESC(ql2xmaxlun,
208 "Defines the maximum LU number to register with the SCSI "
209 "midlayer. Default is 65535.");
210
Giridhar Malavali08de2842011-08-16 11:31:44 -0700211int ql2xmdcapmask = 0x1F;
212module_param(ql2xmdcapmask, int, S_IRUGO);
213MODULE_PARM_DESC(ql2xmdcapmask,
214 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800215 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700216
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800217int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700218module_param(ql2xmdenable, int, S_IRUGO);
219MODULE_PARM_DESC(ql2xmdenable,
220 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800221 "0 - MiniDump disabled. "
222 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700225 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 */
227static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500228static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800229static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
230static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500231static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500232static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static int qla2xxx_eh_abort(struct scsi_cmnd *);
234static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700235static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
237static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400239static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400240static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400241static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700242
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700243struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700245 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700246 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700247
248 .eh_abort_handler = qla2xxx_eh_abort,
249 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700250 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700251 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
252 .eh_host_reset_handler = qla2xxx_eh_host_reset,
253
254 .slave_configure = qla2xxx_slave_configure,
255
256 .slave_alloc = qla2xxx_slave_alloc,
257 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700258 .scan_finished = qla2xxx_scan_finished,
259 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100260 .change_queue_depth = scsi_change_queue_depth,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700261 .this_id = -1,
262 .cmd_per_lun = 3,
263 .use_clustering = ENABLE_CLUSTERING,
264 .sg_tablesize = SG_ALL,
265
266 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700267 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400268
269 .supported_mode = MODE_INITIATOR,
Christoph Hellwig2ecb2042014-11-03 14:09:02 +0100270 .use_blk_tags = 1,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100271 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700272};
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700275struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/* TODO Convert to inlines
278 *
279 * Timer routines
280 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700282__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800283qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800285 init_timer(&vha->timer);
286 vha->timer.expires = jiffies + interval * HZ;
287 vha->timer.data = (unsigned long)vha;
288 vha->timer.function = (void (*)(unsigned long))func;
289 add_timer(&vha->timer);
290 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800294qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700296 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700297 if (vha->device_flags & DFLG_DEV_FAILED) {
298 ql_dbg(ql_dbg_timer, vha, 0x600d,
299 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700300 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700301 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700302
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800303 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304}
305
Adrian Bunka824ebb2008-01-17 09:02:15 -0800306static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800307qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800309 del_timer_sync(&vha->timer);
310 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313static int qla2x00_do_dpc(void *data);
314
315static void qla2x00_rst_aen(scsi_qla_host_t *);
316
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800317static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
318 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700319static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800320static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400323static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
324 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800325{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700326 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700327 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800328 GFP_KERNEL);
329 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700330 ql_log(ql_log_fatal, vha, 0x003b,
331 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800332 goto fail_req_map;
333 }
334
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700335 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800336 GFP_KERNEL);
337 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700338 ql_log(ql_log_fatal, vha, 0x003c,
339 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800340 goto fail_rsp_map;
341 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400342 /*
343 * Make sure we record at least the request and response queue zero in
344 * case we need to free them if part of the probe fails.
345 */
346 ha->rsp_q_map[0] = rsp;
347 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800348 set_bit(0, ha->rsp_qid_map);
349 set_bit(0, ha->req_qid_map);
350 return 1;
351
352fail_rsp_map:
353 kfree(ha->req_q_map);
354 ha->req_q_map = NULL;
355fail_req_map:
356 return -ENOMEM;
357}
358
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700359static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800360{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400361 if (IS_QLAFX00(ha)) {
362 if (req && req->ring_fx00)
363 dma_free_coherent(&ha->pdev->dev,
364 (req->length_fx00 + 1) * sizeof(request_t),
365 req->ring_fx00, req->dma_fx00);
366 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800367 dma_free_coherent(&ha->pdev->dev,
368 (req->length + 1) * sizeof(request_t),
369 req->ring, req->dma);
370
Chad Dupuis8d93f552013-01-30 03:34:37 -0500371 if (req)
372 kfree(req->outstanding_cmds);
373
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800374 kfree(req);
375 req = NULL;
376}
377
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700378static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
379{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400380 if (IS_QLAFX00(ha)) {
381 if (rsp && rsp->ring)
382 dma_free_coherent(&ha->pdev->dev,
383 (rsp->length_fx00 + 1) * sizeof(request_t),
384 rsp->ring_fx00, rsp->dma_fx00);
385 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700386 dma_free_coherent(&ha->pdev->dev,
387 (rsp->length + 1) * sizeof(response_t),
388 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400389 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700390 kfree(rsp);
391 rsp = NULL;
392}
393
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800394static void qla2x00_free_queues(struct qla_hw_data *ha)
395{
396 struct req_que *req;
397 struct rsp_que *rsp;
398 int cnt;
399
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700400 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800401 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700402 qla2x00_free_req_que(ha, req);
403 }
404 kfree(ha->req_q_map);
405 ha->req_q_map = NULL;
406
407 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
408 rsp = ha->rsp_q_map[cnt];
409 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800410 }
411 kfree(ha->rsp_q_map);
412 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800413}
414
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700415static int qla25xx_setup_mode(struct scsi_qla_host *vha)
416{
417 uint16_t options = 0;
418 int ques, req, ret;
419 struct qla_hw_data *ha = vha->hw;
420
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700421 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700422 ql_log(ql_log_warn, vha, 0x00d8,
423 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700424 goto fail;
425 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700426 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700427 /* create a request queue for IO */
428 options |= BIT_7;
429 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
430 QLA_DEFAULT_QUE_QOS);
431 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700432 ql_log(ql_log_warn, vha, 0x00e0,
433 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700434 goto fail;
435 }
Tejun Heo278274d2011-02-01 11:42:42 +0100436 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700437 vha->req = ha->req_q_map[req];
438 options |= BIT_1;
439 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
440 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
441 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700442 ql_log(ql_log_warn, vha, 0x00e8,
443 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700444 goto fail2;
445 }
446 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700447 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700448 ql_dbg(ql_dbg_multiq, vha, 0xc007,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100449 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700450 "no. of response queues:%d no. of request queues:%d.\n",
451 ha->max_rsp_queues, ha->max_req_queues);
452 ql_dbg(ql_dbg_init, vha, 0x00e9,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100453 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700454 "no. of response queues:%d no. of request queues:%d.\n",
455 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700456 }
457 return 0;
458fail2:
459 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700460 destroy_workqueue(ha->wq);
461 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800462 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700463fail:
464 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700465 kfree(ha->req_q_map);
466 kfree(ha->rsp_q_map);
467 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700468 return 1;
469}
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800472qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800474 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 static char *pci_bus_modes[] = {
476 "33", "66", "100", "133",
477 };
478 uint16_t pci_bus;
479
480 strcpy(str, "PCI");
481 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
482 if (pci_bus) {
483 strcat(str, "-X (");
484 strcat(str, pci_bus_modes[pci_bus]);
485 } else {
486 pci_bus = (ha->pci_attr & BIT_8) >> 8;
487 strcat(str, " (");
488 strcat(str, pci_bus_modes[pci_bus]);
489 }
490 strcat(str, " MHz)");
491
492 return (str);
493}
494
Andrew Vasquezfca29702005-07-06 10:31:47 -0700495static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800496qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700497{
498 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700500 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700501
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600502 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700503 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600504 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700505
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600506 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
507 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
508 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700509
510 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500511 switch (lspeed) {
512 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700513 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500514 break;
515 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700516 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500517 break;
518 case 3:
519 strcat(str, "8.0GT/s ");
520 break;
521 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500523 break;
524 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700525 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
526 strcat(str, lwstr);
527
528 return str;
529 }
530
531 strcpy(str, "PCI");
532 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
533 if (pci_bus == 0 || pci_bus == 8) {
534 strcat(str, " (");
535 strcat(str, pci_bus_modes[pci_bus >> 3]);
536 } else {
537 strcat(str, "-X ");
538 if (pci_bus & BIT_2)
539 strcat(str, "Mode 2");
540 else
541 strcat(str, "Mode 1");
542 strcat(str, " (");
543 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
544 }
545 strcat(str, " MHz)");
546
547 return str;
548}
549
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800550static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400551qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700555
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400556 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
557 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 if (ha->fw_attributes & BIT_9) {
560 strcat(str, "FLX");
561 return (str);
562 }
563
564 switch (ha->fw_attributes & 0xFF) {
565 case 0x7:
566 strcat(str, "EF");
567 break;
568 case 0x17:
569 strcat(str, "TP");
570 break;
571 case 0x37:
572 strcat(str, "IP");
573 break;
574 case 0x77:
575 strcat(str, "VI");
576 break;
577 default:
578 sprintf(un_str, "(%x)", ha->fw_attributes);
579 strcat(str, un_str);
580 break;
581 }
582 if (ha->fw_attributes & 0x100)
583 strcat(str, "X");
584
585 return (str);
586}
587
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800588static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400589qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700590{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700592
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400593 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800594 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700595 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700596}
597
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800598void
599qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700600{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800601 srb_t *sp = (srb_t *)ptr;
602 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
603 struct qla_hw_data *ha = sp->fcport->vha->hw;
604 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700605
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800606 if (sp->flags & SRB_DMA_VALID) {
607 scsi_dma_unmap(cmd);
608 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700609 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700610
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800611 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
612 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
613 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
614 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
615 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700616
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800617 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
618 /* List assured to be having elements */
Quinn Tranf83adb62014-04-11 16:54:43 -0400619 qla2x00_clean_dsd_pool(ha, sp, NULL);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800620 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
621 }
622
623 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
624 dma_pool_free(ha->dl_dma_pool, ctx,
625 ((struct crc_context *)ctx)->crc_ctx_dma);
626 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
627 }
628
629 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
630 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
631
632 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
633 ctx1->fcp_cmnd_dma);
634 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
635 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
636 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
637 mempool_free(ctx1, ha->ctx_mempool);
638 ctx1 = NULL;
639 }
640
641 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500642 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800643}
644
Fengguang Wu14b06802013-04-25 01:29:19 -0400645static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800646qla2x00_sp_compl(void *data, void *ptr, int res)
647{
648 struct qla_hw_data *ha = (struct qla_hw_data *)data;
649 srb_t *sp = (srb_t *)ptr;
650 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
651
652 cmd->result = res;
653
654 if (atomic_read(&sp->ref_count) == 0) {
655 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
656 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
657 sp, GET_CMD_SP(sp));
658 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400659 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800660 return;
661 }
662 if (!atomic_dec_and_test(&sp->ref_count))
663 return;
664
665 qla2x00_sp_free_dma(ha, sp);
666 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700667}
668
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400669/* If we are SP1 here, we need to still take and release the host_lock as SP1
670 * does not have the changes necessary to avoid taking host->host_lock.
671 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800673qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700674{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700675 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700676 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400677 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 struct qla_hw_data *ha = vha->hw;
679 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700680 srb_t *sp;
681 int rval;
682
Andrew Vasquez85880802009-12-15 21:29:46 -0800683 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700684 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400685 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700686 "PCI Channel IO permanent failure, exiting "
687 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700688 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700689 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400690 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800692 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700693 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700694 goto qc24_fail_command;
695 }
696
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400697 rval = fc_remote_port_chkready(rport);
698 if (rval) {
699 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400700 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700701 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
702 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700703 goto qc24_fail_command;
704 }
705
Arun Easibad75002010-05-04 15:01:30 -0700706 if (!vha->flags.difdix_supported &&
707 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700708 ql_dbg(ql_dbg_io, vha, 0x3004,
709 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
710 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700711 cmd->result = DID_NO_CONNECT << 16;
712 goto qc24_fail_command;
713 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800714
715 if (!fcport) {
716 cmd->result = DID_NO_CONNECT << 16;
717 goto qc24_fail_command;
718 }
719
Andrew Vasquezfca29702005-07-06 10:31:47 -0700720 if (atomic_read(&fcport->state) != FCS_ONLINE) {
721 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700722 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700723 ql_dbg(ql_dbg_io, vha, 0x3005,
724 "Returning DNC, fcport_state=%d loop_state=%d.\n",
725 atomic_read(&fcport->state),
726 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700727 cmd->result = DID_NO_CONNECT << 16;
728 goto qc24_fail_command;
729 }
Mike Christie7b594132008-08-17 15:24:40 -0500730 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700731 }
732
Chad Dupuise05fe292014-09-25 05:16:59 -0400733 /*
734 * Return target busy if we've received a non-zero retry_delay_timer
735 * in a FCP_RSP.
736 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100737 if (fcport->retry_delay_timestamp == 0) {
738 /* retry delay not set */
739 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400740 fcport->retry_delay_timestamp = 0;
741 else
742 goto qc24_target_busy;
743
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500744 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400745 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800746 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700747
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800748 sp->u.scmd.cmd = cmd;
749 sp->type = SRB_SCSI_CMD;
750 atomic_set(&sp->ref_count, 1);
751 CMD_SP(cmd) = (void *)sp;
752 sp->free = qla2x00_sp_free_dma;
753 sp->done = qla2x00_sp_compl;
754
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700756 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500757 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700758 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700759 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700760 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700761
Andrew Vasquezfca29702005-07-06 10:31:47 -0700762 return 0;
763
764qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800765 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700766
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800767qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700768 return SCSI_MLQUEUE_HOST_BUSY;
769
Mike Christie7b594132008-08-17 15:24:40 -0500770qc24_target_busy:
771 return SCSI_MLQUEUE_TARGET_BUSY;
772
Andrew Vasquezfca29702005-07-06 10:31:47 -0700773qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800774 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700775
776 return 0;
777}
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*
780 * qla2x00_eh_wait_on_command
781 * Waits for the command to be returned by the Firmware for some
782 * max time.
783 *
784 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 *
787 * Return:
788 * Not Found : 0
789 * Found : 1
790 */
791static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700794#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -0400795#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500796 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800797 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
798 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500799 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Andrew Vasquez85880802009-12-15 21:29:46 -0800801 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700802 ql_dbg(ql_dbg_taskm, vha, 0x8005,
803 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800804 return ret;
805 }
806
Lalit Chandivaded9704322009-08-25 11:36:18 -0700807 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700808 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500809 }
810 if (CMD_SP(cmd))
811 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
f4f051e2005-04-17 15:02:26 -0500813 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
816/*
817 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700818 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 * <= MAX_RETRIES_OF_ISP_ABORT or
820 * finally HBA is disabled ie marked offline
821 *
822 * Input:
823 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700824 *
825 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 * Does context switching-Release SPIN_LOCK
827 * (if any) before calling this routine.
828 *
829 * Return:
830 * Success (Adapter is online) : 0
831 * Failed (Adapter is offline/disabled) : 1
832 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800833int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700836 int return_status;
837 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 struct qla_hw_data *ha = vha->hw;
839 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700841 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
843 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
844 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
845 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 msleep(1000);
848 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800849 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700850 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 else
852 return_status = QLA_FUNCTION_FAILED;
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return (return_status);
855}
856
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700857/*
Sawan Chandak638a1a02014-04-11 16:54:38 -0400858 * qla2x00_wait_for_hba_ready
859 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700860 *
861 * Input:
862 * ha - pointer to host adapter structure
863 *
864 * Note:
865 * Does context switching-Release SPIN_LOCK
866 * (if any) before calling this routine.
867 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700868 */
Sawan Chandak638a1a02014-04-11 16:54:38 -0400869static void
870qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700871{
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700872 struct qla_hw_data *ha = vha->hw;
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700873
Sawan Chandak9d35894d2014-09-25 05:16:52 -0400874 while (((qla2x00_reset_active(vha)) || ha->dpc_active ||
875 ha->flags.mbox_busy) ||
876 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
877 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags))
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700878 msleep(1000);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700879}
880
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700881int
882qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
883{
884 int return_status;
885 unsigned long wait_reset;
886 struct qla_hw_data *ha = vha->hw;
887 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
888
889 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
890 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
891 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
892 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
893 ha->dpc_active) && time_before(jiffies, wait_reset)) {
894
895 msleep(1000);
896
897 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
898 ha->flags.chip_reset_done)
899 break;
900 }
901 if (ha->flags.chip_reset_done)
902 return_status = QLA_SUCCESS;
903 else
904 return_status = QLA_FUNCTION_FAILED;
905
906 return return_status;
907}
908
Giridhar Malavali083a4692010-05-28 15:08:18 -0700909static void
910sp_get(struct srb *sp)
911{
912 atomic_inc(&sp->ref_count);
913}
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915/**************************************************************************
916* qla2xxx_eh_abort
917*
918* Description:
919* The abort function will abort the specified command.
920*
921* Input:
922* cmd = Linux SCSI command packet to be aborted.
923*
924* Returns:
925* Either SUCCESS or FAILED.
926*
927* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700928* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800930static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931qla2xxx_eh_abort(struct scsi_cmnd *cmd)
932{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800933 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500934 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800935 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200936 unsigned int id;
937 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700938 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400939 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
f4f051e2005-04-17 15:02:26 -0500942 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700943 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800945 ret = fc_block_scsi_eh(cmd);
946 if (ret != 0)
947 return ret;
948 ret = SUCCESS;
949
f4f051e2005-04-17 15:02:26 -0500950 id = cmd->device->id;
951 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800953 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700954 sp = (srb_t *) CMD_SP(cmd);
955 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800956 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700957 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500958 }
Mike Christie170babc2010-10-15 11:27:47 -0700959
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700960 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -0400961 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
962 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -0700963
964 /* Get a reference to the sp and drop the lock.*/
965 sp_get(sp);
966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400968 rval = ha->isp_ops->abort_command(sp);
969 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -0400970 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400971 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -0400972 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400973 ret = FAILED;
974
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700975 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400976 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -0700977 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700978 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800979 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700980 wait = 1;
981 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700982
983 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400984 /*
985 * Clear the slot in the oustanding_cmds array if we can't find the
986 * command to reclaim the resources.
987 */
988 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
989 vha->req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800990 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700991 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500992
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700993 /* Did the command return during mailbox execution? */
994 if (ret == FAILED && !CMD_SP(cmd))
995 ret = SUCCESS;
996
f4f051e2005-04-17 15:02:26 -0500997 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700998 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800999 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001000 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001001 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001002 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001006 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001007 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001008 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
f4f051e2005-04-17 15:02:26 -05001010 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001013int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001014qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001015 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001017 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001018 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001019 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001020 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001021 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001022 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Andrew Vasquez523ec772008-04-03 13:13:24 -07001024 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001026 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001027 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001028 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001029 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001030 sp = req->outstanding_cmds[cnt];
1031 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001032 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001033 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001034 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001035 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1036 continue;
1037 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001038 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001039 switch (type) {
1040 case WAIT_HOST:
1041 match = 1;
1042 break;
1043 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001044 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001045 break;
1046 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001047 match = (cmd->device->id == t &&
1048 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001049 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001051 if (!match)
1052 continue;
1053
1054 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001055 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001056 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001058 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001059
1060 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Andrew Vasquez523ec772008-04-03 13:13:24 -07001063static char *reset_errors[] = {
1064 "HBA not online",
1065 "HBA not ready",
1066 "Task management failed",
1067 "Waiting for command completions",
1068};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Andrew Vasquez523ec772008-04-03 13:13:24 -07001070static int
1071__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001072 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001073{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001074 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001075 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1076 int err;
1077
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001078 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001079 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001081
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001082 err = fc_block_scsi_eh(cmd);
1083 if (err != 0)
1084 return err;
1085
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001086 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001087 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001088 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001089
1090 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001091 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1092 ql_log(ql_log_warn, vha, 0x800a,
1093 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001094 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001095 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001096 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001097 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001098 != QLA_SUCCESS) {
1099 ql_log(ql_log_warn, vha, 0x800c,
1100 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001101 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001102 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001103 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001104 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001105 cmd->device->lun, type) != QLA_SUCCESS) {
1106 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001107 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001108 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001109 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001110
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001111 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001112 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001113 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001114
1115 return SUCCESS;
1116
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001117eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001118 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001119 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001120 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1121 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001122 return FAILED;
1123}
1124
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001125static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1127{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1129 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Andrew Vasquez523ec772008-04-03 13:13:24 -07001131 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1132 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001136qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1139 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Andrew Vasquez523ec772008-04-03 13:13:24 -07001141 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1142 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143}
1144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145/**************************************************************************
1146* qla2xxx_eh_bus_reset
1147*
1148* Description:
1149* The bus reset function will reset the bus and abort any executing
1150* commands.
1151*
1152* Input:
1153* cmd = Linux SCSI command packet of the command that cause the
1154* bus reset.
1155*
1156* Returns:
1157* SUCCESS/FAILURE (defined as macro in scsi.h).
1158*
1159**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001160static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1162{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001164 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001165 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001166 unsigned int id;
1167 uint64_t lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
f4f051e2005-04-17 15:02:26 -05001169 id = cmd->device->id;
1170 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001171
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001172 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001173 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001176 ret = fc_block_scsi_eh(cmd);
1177 if (ret != 0)
1178 return ret;
1179 ret = FAILED;
1180
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001181 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001182 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001184 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001185 ql_log(ql_log_fatal, vha, 0x8013,
1186 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001187 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
1189
Saurav Kashyapad5376892011-11-18 09:02:09 -08001190 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1191 ret = SUCCESS;
1192
f4f051e2005-04-17 15:02:26 -05001193 if (ret == FAILED)
1194 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001196 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001197 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001198 QLA_SUCCESS) {
1199 ql_log(ql_log_warn, vha, 0x8014,
1200 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001201 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
f4f051e2005-04-17 15:02:26 -05001204eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001205 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001206 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001207 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
f4f051e2005-04-17 15:02:26 -05001209 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
1212/**************************************************************************
1213* qla2xxx_eh_host_reset
1214*
1215* Description:
1216* The reset function will reset the Adapter.
1217*
1218* Input:
1219* cmd = Linux SCSI command packet of the command that cause the
1220* adapter reset.
1221*
1222* Returns:
1223* Either SUCCESS or FAILED.
1224*
1225* Note:
1226**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001227static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1229{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001230 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001231 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001232 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001233 unsigned int id;
1234 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
f4f051e2005-04-17 15:02:26 -05001237 id = cmd->device->id;
1238 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001239
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001240 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001241 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Chad Dupuis63ee7072014-04-11 16:54:46 -04001243 /*
1244 * No point in issuing another reset if one is active. Also do not
1245 * attempt a reset if we are updating flash.
1246 */
1247 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001248 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001250 if (vha != base_vha) {
1251 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001252 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001254 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001255 if (!qla82xx_fcoe_ctx_reset(vha)) {
1256 /* Ctx reset success */
1257 ret = SUCCESS;
1258 goto eh_host_reset_lock;
1259 }
1260 /* fall thru if ctx reset failed */
1261 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001262 if (ha->wq)
1263 flush_workqueue(ha->wq);
1264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001265 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001266 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001267 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1268 /* failed. schedule dpc to try */
1269 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1270
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001271 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1272 ql_log(ql_log_warn, vha, 0x802a,
1273 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001274 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001275 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001276 }
1277 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001280 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001281 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001282 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001283 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
f4f051e2005-04-17 15:02:26 -05001285eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001286 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001287 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001288 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
f4f051e2005-04-17 15:02:26 -05001290 return ret;
1291}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293/*
1294* qla2x00_loop_reset
1295* Issue loop reset.
1296*
1297* Input:
1298* ha = adapter block pointer.
1299*
1300* Returns:
1301* 0 = success
1302*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001303int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001306 int ret;
bdf79622005-04-17 15:06:53 -05001307 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Armen Baloyan58547712013-08-27 01:37:33 -04001310 if (IS_QLAFX00(ha)) {
1311 return qlafx00_loop_reset(vha);
1312 }
1313
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001314 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001315 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1316 if (fcport->port_type != FCT_TARGET)
1317 continue;
1318
1319 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1320 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001321 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001322 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001323 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001324 }
1325 }
1326 }
1327
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001328
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001329 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001330 atomic_set(&vha->loop_state, LOOP_DOWN);
1331 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1332 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001334 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001335 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1336 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
1339
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001340 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001341 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001342 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001343 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1344 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001345 }
1346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001350 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
1352
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001353void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001354qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001355{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001356 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001357 unsigned long flags;
1358 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001360 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001361
Arun Easic0cb4492014-09-25 06:14:51 -04001362 qlt_host_reset_handler(ha);
1363
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001364 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001365 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001366 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001367 if (!req)
1368 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001369 if (!req->outstanding_cmds)
1370 continue;
1371 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001372 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001373 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001374 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001375 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001376 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001377 }
1378 }
1379 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1380}
1381
f4f051e2005-04-17 15:02:26 -05001382static int
1383qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
bdf79622005-04-17 15:06:53 -05001385 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001387 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001388 return -ENXIO;
1389
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001390 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001391
1392 return 0;
1393}
1394
1395static int
1396qla2xxx_slave_configure(struct scsi_device *sdev)
1397{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001398 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001399 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001400
Arun Easi9e522cd2012-08-22 14:21:31 -04001401 if (IS_T10_PI_CAPABLE(vha->hw))
1402 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1403
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001404 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001405 return 0;
1406}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
f4f051e2005-04-17 15:02:26 -05001408static void
1409qla2xxx_slave_destroy(struct scsi_device *sdev)
1410{
1411 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412}
1413
1414/**
1415 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1416 * @ha: HA context
1417 *
1418 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1419 * supported addressing method.
1420 */
1421static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001422qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001424 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Yang Hongyang6a355282009-04-06 19:01:13 -07001427 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001428 /* Any upper-dword bits set? */
1429 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001430 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001431 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001433 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1434 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001435 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001438
Yang Hongyang284901a2009-04-06 19:01:15 -07001439 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1440 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001443static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001445{
1446 unsigned long flags = 0;
1447 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1448
1449 spin_lock_irqsave(&ha->hardware_lock, flags);
1450 ha->interrupts_on = 1;
1451 /* enable risc and host interrupts */
1452 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1453 RD_REG_WORD(&reg->ictrl);
1454 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1455
1456}
1457
1458static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001459qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001460{
1461 unsigned long flags = 0;
1462 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1463
1464 spin_lock_irqsave(&ha->hardware_lock, flags);
1465 ha->interrupts_on = 0;
1466 /* disable risc and host interrupts */
1467 WRT_REG_WORD(&reg->ictrl, 0);
1468 RD_REG_WORD(&reg->ictrl);
1469 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1470}
1471
1472static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001474{
1475 unsigned long flags = 0;
1476 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1477
1478 spin_lock_irqsave(&ha->hardware_lock, flags);
1479 ha->interrupts_on = 1;
1480 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1481 RD_REG_DWORD(&reg->ictrl);
1482 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1483}
1484
1485static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001486qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001487{
1488 unsigned long flags = 0;
1489 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1490
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001491 if (IS_NOPOLLING_TYPE(ha))
1492 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001493 spin_lock_irqsave(&ha->hardware_lock, flags);
1494 ha->interrupts_on = 0;
1495 WRT_REG_DWORD(&reg->ictrl, 0);
1496 RD_REG_DWORD(&reg->ictrl);
1497 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1498}
1499
Giridhar Malavali706f4572011-11-18 09:03:16 -08001500static int
1501qla2x00_iospace_config(struct qla_hw_data *ha)
1502{
1503 resource_size_t pio;
1504 uint16_t msix;
1505 int cpus;
1506
Giridhar Malavali706f4572011-11-18 09:03:16 -08001507 if (pci_request_selected_regions(ha->pdev, ha->bars,
1508 QLA2XXX_DRIVER_NAME)) {
1509 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1510 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1511 pci_name(ha->pdev));
1512 goto iospace_error_exit;
1513 }
1514 if (!(ha->bars & 1))
1515 goto skip_pio;
1516
1517 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1518 pio = pci_resource_start(ha->pdev, 0);
1519 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1520 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1521 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1522 "Invalid pci I/O region size (%s).\n",
1523 pci_name(ha->pdev));
1524 pio = 0;
1525 }
1526 } else {
1527 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1528 "Region #0 no a PIO resource (%s).\n",
1529 pci_name(ha->pdev));
1530 pio = 0;
1531 }
1532 ha->pio_address = pio;
1533 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1534 "PIO address=%llu.\n",
1535 (unsigned long long)ha->pio_address);
1536
1537skip_pio:
1538 /* Use MMIO operations for all accesses. */
1539 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1540 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1541 "Region #1 not an MMIO resource (%s), aborting.\n",
1542 pci_name(ha->pdev));
1543 goto iospace_error_exit;
1544 }
1545 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1546 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1547 "Invalid PCI mem region size (%s), aborting.\n",
1548 pci_name(ha->pdev));
1549 goto iospace_error_exit;
1550 }
1551
1552 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1553 if (!ha->iobase) {
1554 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1555 "Cannot remap MMIO (%s), aborting.\n",
1556 pci_name(ha->pdev));
1557 goto iospace_error_exit;
1558 }
1559
1560 /* Determine queue resources */
1561 ha->max_req_queues = ha->max_rsp_queues = 1;
1562 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1563 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1564 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1565 goto mqiobase_exit;
1566
1567 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1568 pci_resource_len(ha->pdev, 3));
1569 if (ha->mqiobase) {
1570 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1571 "MQIO Base=%p.\n", ha->mqiobase);
1572 /* Read MSIX vector size of the board */
1573 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1574 ha->msix_count = msix;
1575 /* Max queues are bounded by available msix vectors */
1576 /* queue 0 uses two msix vectors */
1577 if (ql2xmultique_tag) {
1578 cpus = num_online_cpus();
1579 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1580 (cpus + 1) : (ha->msix_count - 1);
1581 ha->max_req_queues = 2;
1582 } else if (ql2xmaxqueues > 1) {
1583 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1584 QLA_MQ_SIZE : ql2xmaxqueues;
1585 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1586 "QoS mode set, max no of request queues:%d.\n",
1587 ha->max_req_queues);
1588 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1589 "QoS mode set, max no of request queues:%d.\n",
1590 ha->max_req_queues);
1591 }
1592 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1593 "MSI-X vector count: %d.\n", msix);
1594 } else
1595 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1596 "BAR 3 not enabled.\n");
1597
1598mqiobase_exit:
1599 ha->msix_count = ha->max_rsp_queues + 1;
1600 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1601 "MSIX Count:%d.\n", ha->msix_count);
1602 return (0);
1603
1604iospace_error_exit:
1605 return (-ENOMEM);
1606}
1607
1608
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001609static int
1610qla83xx_iospace_config(struct qla_hw_data *ha)
1611{
1612 uint16_t msix;
1613 int cpus;
1614
1615 if (pci_request_selected_regions(ha->pdev, ha->bars,
1616 QLA2XXX_DRIVER_NAME)) {
1617 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1618 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1619 pci_name(ha->pdev));
1620
1621 goto iospace_error_exit;
1622 }
1623
1624 /* Use MMIO operations for all accesses. */
1625 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1626 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1627 "Invalid pci I/O region size (%s).\n",
1628 pci_name(ha->pdev));
1629 goto iospace_error_exit;
1630 }
1631 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1632 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1633 "Invalid PCI mem region size (%s), aborting\n",
1634 pci_name(ha->pdev));
1635 goto iospace_error_exit;
1636 }
1637
1638 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1639 if (!ha->iobase) {
1640 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1641 "Cannot remap MMIO (%s), aborting.\n",
1642 pci_name(ha->pdev));
1643 goto iospace_error_exit;
1644 }
1645
1646 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1647 /* 83XX 26XX always use MQ type access for queues
1648 * - mbar 2, a.k.a region 4 */
1649 ha->max_req_queues = ha->max_rsp_queues = 1;
1650 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1651 pci_resource_len(ha->pdev, 4));
1652
1653 if (!ha->mqiobase) {
1654 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1655 "BAR2/region4 not enabled\n");
1656 goto mqiobase_exit;
1657 }
1658
1659 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1660 pci_resource_len(ha->pdev, 2));
1661 if (ha->msixbase) {
1662 /* Read MSIX vector size of the board */
1663 pci_read_config_word(ha->pdev,
1664 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1665 ha->msix_count = msix;
1666 /* Max queues are bounded by available msix vectors */
1667 /* queue 0 uses two msix vectors */
1668 if (ql2xmultique_tag) {
1669 cpus = num_online_cpus();
1670 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1671 (cpus + 1) : (ha->msix_count - 1);
1672 ha->max_req_queues = 2;
1673 } else if (ql2xmaxqueues > 1) {
1674 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1675 QLA_MQ_SIZE : ql2xmaxqueues;
1676 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1677 "QoS mode set, max no of request queues:%d.\n",
1678 ha->max_req_queues);
1679 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1680 "QoS mode set, max no of request queues:%d.\n",
1681 ha->max_req_queues);
1682 }
1683 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1684 "MSI-X vector count: %d.\n", msix);
1685 } else
1686 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1687 "BAR 1 not enabled.\n");
1688
1689mqiobase_exit:
1690 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001691
1692 qlt_83xx_iospace_config(ha);
1693
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001694 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1695 "MSIX Count:%d.\n", ha->msix_count);
1696 return 0;
1697
1698iospace_error_exit:
1699 return -ENOMEM;
1700}
1701
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001702static struct isp_operations qla2100_isp_ops = {
1703 .pci_config = qla2100_pci_config,
1704 .reset_chip = qla2x00_reset_chip,
1705 .chip_diag = qla2x00_chip_diag,
1706 .config_rings = qla2x00_config_rings,
1707 .reset_adapter = qla2x00_reset_adapter,
1708 .nvram_config = qla2x00_nvram_config,
1709 .update_fw_options = qla2x00_update_fw_options,
1710 .load_risc = qla2x00_load_risc,
1711 .pci_info_str = qla2x00_pci_info_str,
1712 .fw_version_str = qla2x00_fw_version_str,
1713 .intr_handler = qla2100_intr_handler,
1714 .enable_intrs = qla2x00_enable_intrs,
1715 .disable_intrs = qla2x00_disable_intrs,
1716 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001717 .target_reset = qla2x00_abort_target,
1718 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001719 .fabric_login = qla2x00_login_fabric,
1720 .fabric_logout = qla2x00_fabric_logout,
1721 .calc_req_entries = qla2x00_calc_iocbs_32,
1722 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1723 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1724 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1725 .read_nvram = qla2x00_read_nvram_data,
1726 .write_nvram = qla2x00_write_nvram_data,
1727 .fw_dump = qla2100_fw_dump,
1728 .beacon_on = NULL,
1729 .beacon_off = NULL,
1730 .beacon_blink = NULL,
1731 .read_optrom = qla2x00_read_optrom_data,
1732 .write_optrom = qla2x00_write_optrom_data,
1733 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001734 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001735 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001736 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001737 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001738};
1739
1740static struct isp_operations qla2300_isp_ops = {
1741 .pci_config = qla2300_pci_config,
1742 .reset_chip = qla2x00_reset_chip,
1743 .chip_diag = qla2x00_chip_diag,
1744 .config_rings = qla2x00_config_rings,
1745 .reset_adapter = qla2x00_reset_adapter,
1746 .nvram_config = qla2x00_nvram_config,
1747 .update_fw_options = qla2x00_update_fw_options,
1748 .load_risc = qla2x00_load_risc,
1749 .pci_info_str = qla2x00_pci_info_str,
1750 .fw_version_str = qla2x00_fw_version_str,
1751 .intr_handler = qla2300_intr_handler,
1752 .enable_intrs = qla2x00_enable_intrs,
1753 .disable_intrs = qla2x00_disable_intrs,
1754 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001755 .target_reset = qla2x00_abort_target,
1756 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001757 .fabric_login = qla2x00_login_fabric,
1758 .fabric_logout = qla2x00_fabric_logout,
1759 .calc_req_entries = qla2x00_calc_iocbs_32,
1760 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1761 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1762 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1763 .read_nvram = qla2x00_read_nvram_data,
1764 .write_nvram = qla2x00_write_nvram_data,
1765 .fw_dump = qla2300_fw_dump,
1766 .beacon_on = qla2x00_beacon_on,
1767 .beacon_off = qla2x00_beacon_off,
1768 .beacon_blink = qla2x00_beacon_blink,
1769 .read_optrom = qla2x00_read_optrom_data,
1770 .write_optrom = qla2x00_write_optrom_data,
1771 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001773 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001774 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001775 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001776};
1777
1778static struct isp_operations qla24xx_isp_ops = {
1779 .pci_config = qla24xx_pci_config,
1780 .reset_chip = qla24xx_reset_chip,
1781 .chip_diag = qla24xx_chip_diag,
1782 .config_rings = qla24xx_config_rings,
1783 .reset_adapter = qla24xx_reset_adapter,
1784 .nvram_config = qla24xx_nvram_config,
1785 .update_fw_options = qla24xx_update_fw_options,
1786 .load_risc = qla24xx_load_risc,
1787 .pci_info_str = qla24xx_pci_info_str,
1788 .fw_version_str = qla24xx_fw_version_str,
1789 .intr_handler = qla24xx_intr_handler,
1790 .enable_intrs = qla24xx_enable_intrs,
1791 .disable_intrs = qla24xx_disable_intrs,
1792 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001793 .target_reset = qla24xx_abort_target,
1794 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001795 .fabric_login = qla24xx_login_fabric,
1796 .fabric_logout = qla24xx_fabric_logout,
1797 .calc_req_entries = NULL,
1798 .build_iocbs = NULL,
1799 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1800 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1801 .read_nvram = qla24xx_read_nvram_data,
1802 .write_nvram = qla24xx_write_nvram_data,
1803 .fw_dump = qla24xx_fw_dump,
1804 .beacon_on = qla24xx_beacon_on,
1805 .beacon_off = qla24xx_beacon_off,
1806 .beacon_blink = qla24xx_beacon_blink,
1807 .read_optrom = qla24xx_read_optrom_data,
1808 .write_optrom = qla24xx_write_optrom_data,
1809 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001810 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001811 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001812 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001813 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001814};
1815
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001816static struct isp_operations qla25xx_isp_ops = {
1817 .pci_config = qla25xx_pci_config,
1818 .reset_chip = qla24xx_reset_chip,
1819 .chip_diag = qla24xx_chip_diag,
1820 .config_rings = qla24xx_config_rings,
1821 .reset_adapter = qla24xx_reset_adapter,
1822 .nvram_config = qla24xx_nvram_config,
1823 .update_fw_options = qla24xx_update_fw_options,
1824 .load_risc = qla24xx_load_risc,
1825 .pci_info_str = qla24xx_pci_info_str,
1826 .fw_version_str = qla24xx_fw_version_str,
1827 .intr_handler = qla24xx_intr_handler,
1828 .enable_intrs = qla24xx_enable_intrs,
1829 .disable_intrs = qla24xx_disable_intrs,
1830 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001831 .target_reset = qla24xx_abort_target,
1832 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001833 .fabric_login = qla24xx_login_fabric,
1834 .fabric_logout = qla24xx_fabric_logout,
1835 .calc_req_entries = NULL,
1836 .build_iocbs = NULL,
1837 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1838 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1839 .read_nvram = qla25xx_read_nvram_data,
1840 .write_nvram = qla25xx_write_nvram_data,
1841 .fw_dump = qla25xx_fw_dump,
1842 .beacon_on = qla24xx_beacon_on,
1843 .beacon_off = qla24xx_beacon_off,
1844 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001845 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001846 .write_optrom = qla24xx_write_optrom_data,
1847 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001848 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001849 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001850 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001851 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001852};
1853
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001854static struct isp_operations qla81xx_isp_ops = {
1855 .pci_config = qla25xx_pci_config,
1856 .reset_chip = qla24xx_reset_chip,
1857 .chip_diag = qla24xx_chip_diag,
1858 .config_rings = qla24xx_config_rings,
1859 .reset_adapter = qla24xx_reset_adapter,
1860 .nvram_config = qla81xx_nvram_config,
1861 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001862 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001863 .pci_info_str = qla24xx_pci_info_str,
1864 .fw_version_str = qla24xx_fw_version_str,
1865 .intr_handler = qla24xx_intr_handler,
1866 .enable_intrs = qla24xx_enable_intrs,
1867 .disable_intrs = qla24xx_disable_intrs,
1868 .abort_command = qla24xx_abort_command,
1869 .target_reset = qla24xx_abort_target,
1870 .lun_reset = qla24xx_lun_reset,
1871 .fabric_login = qla24xx_login_fabric,
1872 .fabric_logout = qla24xx_fabric_logout,
1873 .calc_req_entries = NULL,
1874 .build_iocbs = NULL,
1875 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1876 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001877 .read_nvram = NULL,
1878 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001879 .fw_dump = qla81xx_fw_dump,
1880 .beacon_on = qla24xx_beacon_on,
1881 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001882 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001883 .read_optrom = qla25xx_read_optrom_data,
1884 .write_optrom = qla24xx_write_optrom_data,
1885 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001886 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001887 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001888 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001889 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001890};
1891
1892static struct isp_operations qla82xx_isp_ops = {
1893 .pci_config = qla82xx_pci_config,
1894 .reset_chip = qla82xx_reset_chip,
1895 .chip_diag = qla24xx_chip_diag,
1896 .config_rings = qla82xx_config_rings,
1897 .reset_adapter = qla24xx_reset_adapter,
1898 .nvram_config = qla81xx_nvram_config,
1899 .update_fw_options = qla24xx_update_fw_options,
1900 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001901 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001902 .fw_version_str = qla24xx_fw_version_str,
1903 .intr_handler = qla82xx_intr_handler,
1904 .enable_intrs = qla82xx_enable_intrs,
1905 .disable_intrs = qla82xx_disable_intrs,
1906 .abort_command = qla24xx_abort_command,
1907 .target_reset = qla24xx_abort_target,
1908 .lun_reset = qla24xx_lun_reset,
1909 .fabric_login = qla24xx_login_fabric,
1910 .fabric_logout = qla24xx_fabric_logout,
1911 .calc_req_entries = NULL,
1912 .build_iocbs = NULL,
1913 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1914 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1915 .read_nvram = qla24xx_read_nvram_data,
1916 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001917 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001918 .beacon_on = qla82xx_beacon_on,
1919 .beacon_off = qla82xx_beacon_off,
1920 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001921 .read_optrom = qla82xx_read_optrom_data,
1922 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001923 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001924 .start_scsi = qla82xx_start_scsi,
1925 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001926 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001927 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001928};
1929
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001930static struct isp_operations qla8044_isp_ops = {
1931 .pci_config = qla82xx_pci_config,
1932 .reset_chip = qla82xx_reset_chip,
1933 .chip_diag = qla24xx_chip_diag,
1934 .config_rings = qla82xx_config_rings,
1935 .reset_adapter = qla24xx_reset_adapter,
1936 .nvram_config = qla81xx_nvram_config,
1937 .update_fw_options = qla24xx_update_fw_options,
1938 .load_risc = qla82xx_load_risc,
1939 .pci_info_str = qla24xx_pci_info_str,
1940 .fw_version_str = qla24xx_fw_version_str,
1941 .intr_handler = qla8044_intr_handler,
1942 .enable_intrs = qla82xx_enable_intrs,
1943 .disable_intrs = qla82xx_disable_intrs,
1944 .abort_command = qla24xx_abort_command,
1945 .target_reset = qla24xx_abort_target,
1946 .lun_reset = qla24xx_lun_reset,
1947 .fabric_login = qla24xx_login_fabric,
1948 .fabric_logout = qla24xx_fabric_logout,
1949 .calc_req_entries = NULL,
1950 .build_iocbs = NULL,
1951 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1952 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1953 .read_nvram = NULL,
1954 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001955 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001956 .beacon_on = qla82xx_beacon_on,
1957 .beacon_off = qla82xx_beacon_off,
1958 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05001959 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001960 .write_optrom = qla8044_write_optrom_data,
1961 .get_flash_version = qla82xx_get_flash_version,
1962 .start_scsi = qla82xx_start_scsi,
1963 .abort_isp = qla8044_abort_isp,
1964 .iospace_config = qla82xx_iospace_config,
1965 .initialize_adapter = qla2x00_initialize_adapter,
1966};
1967
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001968static struct isp_operations qla83xx_isp_ops = {
1969 .pci_config = qla25xx_pci_config,
1970 .reset_chip = qla24xx_reset_chip,
1971 .chip_diag = qla24xx_chip_diag,
1972 .config_rings = qla24xx_config_rings,
1973 .reset_adapter = qla24xx_reset_adapter,
1974 .nvram_config = qla81xx_nvram_config,
1975 .update_fw_options = qla81xx_update_fw_options,
1976 .load_risc = qla81xx_load_risc,
1977 .pci_info_str = qla24xx_pci_info_str,
1978 .fw_version_str = qla24xx_fw_version_str,
1979 .intr_handler = qla24xx_intr_handler,
1980 .enable_intrs = qla24xx_enable_intrs,
1981 .disable_intrs = qla24xx_disable_intrs,
1982 .abort_command = qla24xx_abort_command,
1983 .target_reset = qla24xx_abort_target,
1984 .lun_reset = qla24xx_lun_reset,
1985 .fabric_login = qla24xx_login_fabric,
1986 .fabric_logout = qla24xx_fabric_logout,
1987 .calc_req_entries = NULL,
1988 .build_iocbs = NULL,
1989 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1990 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1991 .read_nvram = NULL,
1992 .write_nvram = NULL,
1993 .fw_dump = qla83xx_fw_dump,
1994 .beacon_on = qla24xx_beacon_on,
1995 .beacon_off = qla24xx_beacon_off,
1996 .beacon_blink = qla83xx_beacon_blink,
1997 .read_optrom = qla25xx_read_optrom_data,
1998 .write_optrom = qla24xx_write_optrom_data,
1999 .get_flash_version = qla24xx_get_flash_version,
2000 .start_scsi = qla24xx_dif_start_scsi,
2001 .abort_isp = qla2x00_abort_isp,
2002 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002003 .initialize_adapter = qla2x00_initialize_adapter,
2004};
2005
2006static struct isp_operations qlafx00_isp_ops = {
2007 .pci_config = qlafx00_pci_config,
2008 .reset_chip = qlafx00_soft_reset,
2009 .chip_diag = qlafx00_chip_diag,
2010 .config_rings = qlafx00_config_rings,
2011 .reset_adapter = qlafx00_soft_reset,
2012 .nvram_config = NULL,
2013 .update_fw_options = NULL,
2014 .load_risc = NULL,
2015 .pci_info_str = qlafx00_pci_info_str,
2016 .fw_version_str = qlafx00_fw_version_str,
2017 .intr_handler = qlafx00_intr_handler,
2018 .enable_intrs = qlafx00_enable_intrs,
2019 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002020 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002021 .target_reset = qlafx00_abort_target,
2022 .lun_reset = qlafx00_lun_reset,
2023 .fabric_login = NULL,
2024 .fabric_logout = NULL,
2025 .calc_req_entries = NULL,
2026 .build_iocbs = NULL,
2027 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2028 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2029 .read_nvram = qla24xx_read_nvram_data,
2030 .write_nvram = qla24xx_write_nvram_data,
2031 .fw_dump = NULL,
2032 .beacon_on = qla24xx_beacon_on,
2033 .beacon_off = qla24xx_beacon_off,
2034 .beacon_blink = NULL,
2035 .read_optrom = qla24xx_read_optrom_data,
2036 .write_optrom = qla24xx_write_optrom_data,
2037 .get_flash_version = qla24xx_get_flash_version,
2038 .start_scsi = qlafx00_start_scsi,
2039 .abort_isp = qlafx00_abort_isp,
2040 .iospace_config = qlafx00_iospace_config,
2041 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002042};
2043
Chad Dupuisf73cb692014-02-26 04:15:06 -05002044static struct isp_operations qla27xx_isp_ops = {
2045 .pci_config = qla25xx_pci_config,
2046 .reset_chip = qla24xx_reset_chip,
2047 .chip_diag = qla24xx_chip_diag,
2048 .config_rings = qla24xx_config_rings,
2049 .reset_adapter = qla24xx_reset_adapter,
2050 .nvram_config = qla81xx_nvram_config,
2051 .update_fw_options = qla81xx_update_fw_options,
2052 .load_risc = qla81xx_load_risc,
2053 .pci_info_str = qla24xx_pci_info_str,
2054 .fw_version_str = qla24xx_fw_version_str,
2055 .intr_handler = qla24xx_intr_handler,
2056 .enable_intrs = qla24xx_enable_intrs,
2057 .disable_intrs = qla24xx_disable_intrs,
2058 .abort_command = qla24xx_abort_command,
2059 .target_reset = qla24xx_abort_target,
2060 .lun_reset = qla24xx_lun_reset,
2061 .fabric_login = qla24xx_login_fabric,
2062 .fabric_logout = qla24xx_fabric_logout,
2063 .calc_req_entries = NULL,
2064 .build_iocbs = NULL,
2065 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2066 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2067 .read_nvram = NULL,
2068 .write_nvram = NULL,
2069 .fw_dump = qla27xx_fwdump,
2070 .beacon_on = qla24xx_beacon_on,
2071 .beacon_off = qla24xx_beacon_off,
2072 .beacon_blink = qla83xx_beacon_blink,
2073 .read_optrom = qla25xx_read_optrom_data,
2074 .write_optrom = qla24xx_write_optrom_data,
2075 .get_flash_version = qla24xx_get_flash_version,
2076 .start_scsi = qla24xx_dif_start_scsi,
2077 .abort_isp = qla2x00_abort_isp,
2078 .iospace_config = qla83xx_iospace_config,
2079 .initialize_adapter = qla2x00_initialize_adapter,
2080};
2081
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002082static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002084{
2085 ha->device_type = DT_EXTENDED_IDS;
2086 switch (ha->pdev->device) {
2087 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2088 ha->device_type |= DT_ISP2100;
2089 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002090 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002091 break;
2092 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2093 ha->device_type |= DT_ISP2200;
2094 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002095 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002096 break;
2097 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2098 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002099 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002100 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002101 break;
2102 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2103 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002104 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002105 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002106 break;
2107 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2108 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002109 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002110 if (ha->pdev->subsystem_vendor == 0x1028 &&
2111 ha->pdev->subsystem_device == 0x0170)
2112 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002113 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002114 break;
2115 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2116 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002117 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002118 break;
2119 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2120 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002121 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002122 break;
2123 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2124 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002125 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002126 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002127 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002128 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002129 break;
2130 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2131 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002132 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002133 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002134 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002135 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002136 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002137 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2138 ha->device_type |= DT_ISP8432;
2139 ha->device_type |= DT_ZIO_SUPPORTED;
2140 ha->device_type |= DT_FWI2;
2141 ha->device_type |= DT_IIDMA;
2142 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2143 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002144 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2145 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002146 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002147 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002148 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002149 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2150 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002151 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002152 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002153 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002154 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2155 ha->device_type |= DT_ISP2532;
2156 ha->device_type |= DT_ZIO_SUPPORTED;
2157 ha->device_type |= DT_FWI2;
2158 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002159 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2160 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002161 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2162 ha->device_type |= DT_ISP8001;
2163 ha->device_type |= DT_ZIO_SUPPORTED;
2164 ha->device_type |= DT_FWI2;
2165 ha->device_type |= DT_IIDMA;
2166 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2167 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002168 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2169 ha->device_type |= DT_ISP8021;
2170 ha->device_type |= DT_ZIO_SUPPORTED;
2171 ha->device_type |= DT_FWI2;
2172 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2173 /* Initialize 82XX ISP flags */
2174 qla82xx_init_flags(ha);
2175 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002176 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2177 ha->device_type |= DT_ISP8044;
2178 ha->device_type |= DT_ZIO_SUPPORTED;
2179 ha->device_type |= DT_FWI2;
2180 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2181 /* Initialize 82XX ISP flags */
2182 qla82xx_init_flags(ha);
2183 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002184 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2185 ha->device_type |= DT_ISP2031;
2186 ha->device_type |= DT_ZIO_SUPPORTED;
2187 ha->device_type |= DT_FWI2;
2188 ha->device_type |= DT_IIDMA;
2189 ha->device_type |= DT_T10_PI;
2190 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2191 break;
2192 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2193 ha->device_type |= DT_ISP8031;
2194 ha->device_type |= DT_ZIO_SUPPORTED;
2195 ha->device_type |= DT_FWI2;
2196 ha->device_type |= DT_IIDMA;
2197 ha->device_type |= DT_T10_PI;
2198 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2199 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002200 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2201 ha->device_type |= DT_ISPFX00;
2202 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002203 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2204 ha->device_type |= DT_ISP2071;
2205 ha->device_type |= DT_ZIO_SUPPORTED;
2206 ha->device_type |= DT_FWI2;
2207 ha->device_type |= DT_IIDMA;
2208 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2209 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002210 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2211 ha->device_type |= DT_ISP2271;
2212 ha->device_type |= DT_ZIO_SUPPORTED;
2213 ha->device_type |= DT_FWI2;
2214 ha->device_type |= DT_IIDMA;
2215 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2216 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002217 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002218
Giridhar Malavalia9083012010-04-12 17:59:55 -07002219 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002220 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002221 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002222 /* Get adapter physical port no from interrupt pin register. */
2223 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002224 if (IS_QLA27XX(ha))
2225 ha->port_no--;
2226 else
2227 ha->port_no = !(ha->port_no & 1);
2228 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002229
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002230 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002231 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002232 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002233}
2234
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002235static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002236qla2xxx_scan_start(struct Scsi_Host *shost)
2237{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002238 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002239
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002240 if (vha->hw->flags.running_gold_fw)
2241 return;
2242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2244 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2245 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2246 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002247}
2248
2249static int
2250qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2251{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002252 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002253
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002254 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002255 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002256 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002257 return 1;
2258
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002259 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002260}
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262/*
2263 * PCI driver interface
2264 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002265static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002266qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002268 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270 scsi_qla_host_t *base_vha = NULL;
2271 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002272 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002273 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002274 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002275 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002277 struct req_que *req = NULL;
2278 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002279 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002280 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002281 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2282 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002283 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002284 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2285 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002286 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002287 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002288 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2289 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002290 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002291 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002292 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002293 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2294 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002295 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002296 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002297 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2298 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002299 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002300 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2301 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002302
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002303 if (mem_only) {
2304 if (pci_enable_device_mem(pdev))
2305 goto probe_out;
2306 } else {
2307 if (pci_enable_device(pdev))
2308 goto probe_out;
2309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Jesse Barnes09276782008-10-18 17:33:19 -07002311 /* This may fail but that's ok */
2312 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002313
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002314 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2315 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002316 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2317 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002318 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002320 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2321 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002322 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002323 ha->tgt.enable_class_2 = ql2xenableclass2;
Quinn Tran33e79972014-09-25 06:14:55 -04002324 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2325 spin_lock_init(&ha->tgt.q_full_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
2327 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002328 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002329 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002330 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002331 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002332 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002333 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002335 /* Set ISP-type information. */
2336 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002337
2338 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002339 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002340 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002341 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002342
Chad Dupuiscba1e472011-11-18 09:03:21 -08002343 ha->prev_topology = 0;
2344 ha->init_cb_size = sizeof(init_cb_t);
2345 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2346 ha->optrom_size = OPTROM_SIZE_2300;
2347
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002348 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002350 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 req_length = REQUEST_ENTRY_CNT_2100;
2353 rsp_length = RESPONSE_ENTRY_CNT_2100;
2354 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002355 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002356 ha->flash_conf_off = ~0;
2357 ha->flash_data_off = ~0;
2358 ha->nvram_conf_off = ~0;
2359 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002360 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002362 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002363 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 req_length = REQUEST_ENTRY_CNT_2200;
2365 rsp_length = RESPONSE_ENTRY_CNT_2100;
2366 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002367 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002368 ha->flash_conf_off = ~0;
2369 ha->flash_data_off = ~0;
2370 ha->nvram_conf_off = ~0;
2371 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002372 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002373 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002374 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 req_length = REQUEST_ENTRY_CNT_2200;
2377 rsp_length = RESPONSE_ENTRY_CNT_2300;
2378 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002379 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002380 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2381 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002382 ha->flash_conf_off = ~0;
2383 ha->flash_data_off = ~0;
2384 ha->nvram_conf_off = ~0;
2385 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002386 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002387 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002388 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002389 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 req_length = REQUEST_ENTRY_CNT_24XX;
2391 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002392 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002394 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002395 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002396 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002397 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002398 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002399 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2400 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2401 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2402 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002403 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002404 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002405 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 req_length = REQUEST_ENTRY_CNT_24XX;
2407 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002408 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002410 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002411 ha->gid_list_info_size = 8;
2412 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002413 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002414 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002415 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2416 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2417 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2418 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2419 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002420 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002421 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2422 req_length = REQUEST_ENTRY_CNT_24XX;
2423 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002424 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002425 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2426 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2427 ha->gid_list_info_size = 8;
2428 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002429 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002430 ha->isp_ops = &qla81xx_isp_ops;
2431 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2432 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2433 ha->nvram_conf_off = ~0;
2434 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002435 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002436 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002437 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2438 req_length = REQUEST_ENTRY_CNT_82XX;
2439 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2440 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2441 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2442 ha->gid_list_info_size = 8;
2443 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002444 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002445 ha->isp_ops = &qla82xx_isp_ops;
2446 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2447 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2448 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2449 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002450 } else if (IS_QLA8044(ha)) {
2451 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2452 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2453 req_length = REQUEST_ENTRY_CNT_82XX;
2454 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2455 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2456 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2457 ha->gid_list_info_size = 8;
2458 ha->optrom_size = OPTROM_SIZE_83XX;
2459 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2460 ha->isp_ops = &qla8044_isp_ops;
2461 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2462 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2463 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2464 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002465 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002466 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002467 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002468 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002469 req_length = REQUEST_ENTRY_CNT_83XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002470 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002471 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002472 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2473 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2474 ha->gid_list_info_size = 8;
2475 ha->optrom_size = OPTROM_SIZE_83XX;
2476 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2477 ha->isp_ops = &qla83xx_isp_ops;
2478 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2479 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2480 ha->nvram_conf_off = ~0;
2481 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002482 } else if (IS_QLAFX00(ha)) {
2483 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2484 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2485 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2486 req_length = REQUEST_ENTRY_CNT_FX00;
2487 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002488 ha->isp_ops = &qlafx00_isp_ops;
2489 ha->port_down_retry_count = 30; /* default value */
2490 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2491 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002492 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002493 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002494 ha->mr.host_info_resend = false;
2495 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002496 } else if (IS_QLA27XX(ha)) {
2497 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2498 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2499 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2500 req_length = REQUEST_ENTRY_CNT_24XX;
2501 rsp_length = RESPONSE_ENTRY_CNT_2300;
2502 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2503 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2504 ha->gid_list_info_size = 8;
2505 ha->optrom_size = OPTROM_SIZE_83XX;
2506 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2507 ha->isp_ops = &qla27xx_isp_ops;
2508 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2509 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2510 ha->nvram_conf_off = ~0;
2511 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002513
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002514 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2515 "mbx_count=%d, req_length=%d, "
2516 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002517 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2518 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002519 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2520 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002521 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002522 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2523 "isp_ops=%p, flash_conf_off=%d, "
2524 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2525 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2526 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002527
2528 /* Configure PCI I/O space */
2529 ret = ha->isp_ops->iospace_config(ha);
2530 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002531 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002532
2533 ql_log_pci(ql_log_info, pdev, 0x001d,
2534 "Found an ISP%04X irq %d iobase 0x%p.\n",
2535 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002536 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002537 init_completion(&ha->mbx_cmd_comp);
2538 complete(&ha->mbx_cmd_comp);
2539 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002540 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002541 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002543 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Andrew Vasquez53303c42009-01-22 09:45:37 -08002545 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002546 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2547 "64 Bit addressing is %s.\n",
2548 ha->flags.enable_64bit_addressing ? "enable" :
2549 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002550 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002551 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002552 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2553 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 goto probe_hw_failed;
2556 }
2557
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002558 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002560 req->max_q_depth = ql2xmaxqdepth;
2561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562
2563 base_vha = qla2x00_create_host(sht, ha);
2564 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002565 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002566 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002567 qla2x00_free_req_que(ha, req);
2568 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 }
2571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002572 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002573 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002576 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002577 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002579 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2581 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002582
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002583 /* Setup fcport template structure. */
2584 ha->mr.fcport.vha = base_vha;
2585 ha->mr.fcport.port_type = FCT_UNKNOWN;
2586 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2587 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2588 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2589 ha->mr.fcport.scan_state = 1;
2590
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002591 /* Set the SG table size based on ISP type */
2592 if (!IS_FWI2_CAPABLE(ha)) {
2593 if (IS_QLA2100(ha))
2594 host->sg_tablesize = 32;
2595 } else {
2596 if (!IS_QLA82XX(ha))
2597 host->sg_tablesize = QLA_SG_ALL;
2598 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002599 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002600 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002601 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002602 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002603 host->max_cmd_len = 32;
2604 else
2605 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002606 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002607 /* Older HBAs support only 16-bit LUNs */
2608 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2609 ql2xmaxlun > 0xffff)
2610 host->max_lun = 0xffff;
2611 else
2612 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002613 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002614 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002615
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002616 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2617 "max_id=%d this_id=%d "
2618 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002619 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002620 host->this_id, host->cmd_per_lun, host->unique_id,
2621 host->max_cmd_len, host->max_channel, host->max_lun,
2622 host->transportt, sht->vendor_id);
2623
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002624que_init:
2625 /* Alloc arrays of request and response ring ptrs */
2626 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2627 ql_log(ql_log_fatal, base_vha, 0x003d,
2628 "Failed to allocate memory for queue pointers..."
2629 "aborting.\n");
2630 goto probe_init_failed;
2631 }
2632
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002633 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002634
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002635 /* Set up the irqs */
2636 ret = qla2x00_request_irqs(ha, rsp);
2637 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002638 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002639
2640 pci_save_state(pdev);
2641
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002642 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002643 rsp->req = req;
2644 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002645
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002646 if (IS_QLAFX00(ha)) {
2647 ha->rsp_q_map[0] = rsp;
2648 ha->req_q_map[0] = req;
2649 set_bit(0, ha->req_qid_map);
2650 set_bit(0, ha->rsp_qid_map);
2651 }
2652
Andrew Vasquez08029992009-03-24 09:07:55 -07002653 /* FWI2-capable only. */
2654 req->req_q_in = &ha->iobase->isp24.req_q_in;
2655 req->req_q_out = &ha->iobase->isp24.req_q_out;
2656 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2657 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002658 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002659 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2660 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2661 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2662 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002663 }
2664
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002665 if (IS_QLAFX00(ha)) {
2666 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2667 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2668 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2669 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2670 }
2671
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002672 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002673 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2674 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2675 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2676 }
2677
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002678 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2679 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2680 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2681 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2682 "req->req_q_in=%p req->req_q_out=%p "
2683 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2684 req->req_q_in, req->req_q_out,
2685 rsp->rsp_q_in, rsp->rsp_q_out);
2686 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2687 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2688 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2689 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2690 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2691 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002693 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002694 ql_log(ql_log_fatal, base_vha, 0x00d6,
2695 "Failed to initialize adapter - Adapter flags %x.\n",
2696 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697
Giridhar Malavalia9083012010-04-12 17:59:55 -07002698 if (IS_QLA82XX(ha)) {
2699 qla82xx_idc_lock(ha);
2700 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002701 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002702 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002703 ql_log(ql_log_fatal, base_vha, 0x00d7,
2704 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002705 } else if (IS_QLA8044(ha)) {
2706 qla8044_idc_lock(ha);
2707 qla8044_wr_direct(base_vha,
2708 QLA8044_CRB_DEV_STATE_INDEX,
2709 QLA8XXX_DEV_FAILED);
2710 qla8044_idc_unlock(ha);
2711 ql_log(ql_log_fatal, base_vha, 0x0150,
2712 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002713 }
2714
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 ret = -ENODEV;
2716 goto probe_failed;
2717 }
2718
Chad Dupuis3b1bef62014-02-26 04:15:04 -05002719 if (IS_QLAFX00(ha))
2720 host->can_queue = QLAFX00_MAX_CANQUEUE;
2721 else
2722 host->can_queue = req->num_outstanding_cmds - 10;
2723
2724 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2725 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2726 host->can_queue, base_vha->req,
2727 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2728
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002729 if (ha->mqenable) {
2730 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002731 ql_log(ql_log_warn, base_vha, 0x00ec,
2732 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002733 goto que_init;
2734 }
2735 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002736
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002737 if (ha->flags.running_gold_fw)
2738 goto skip_dpc;
2739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 /*
2741 * Startup the kernel thread for this host adapter
2742 */
2743 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002744 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002746 ql_log(ql_log_fatal, base_vha, 0x00ed,
2747 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 ret = PTR_ERR(ha->dpc_thread);
2749 goto probe_failed;
2750 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002751 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2752 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002754 /*
2755 * If we're not coming up in initiator mode, we might sit for
2756 * a while without waking up the dpc thread, which leads to a
2757 * stuck process warning. So just kick the dpc once here and
2758 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2759 */
2760 qla2xxx_wake_dpc(base_vha);
2761
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002762 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2763
Saurav Kashyap81178772012-08-22 14:21:04 -04002764 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2765 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2766 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2767 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2768
2769 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2770 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2771 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2772 INIT_WORK(&ha->idc_state_handler,
2773 qla83xx_idc_state_handler_work);
2774 INIT_WORK(&ha->nic_core_unrecoverable,
2775 qla83xx_nic_core_unrecoverable_work);
2776 }
2777
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002778skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 list_add_tail(&base_vha->list, &ha->vp_list);
2780 base_vha->host->irq = ha->pdev->irq;
2781
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002784 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2785 "Started qla2x00_timer with "
2786 "interval=%d.\n", WATCH_INTERVAL);
2787 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2788 "Detected hba at address=%p.\n",
2789 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
Arun Easie02587d2011-08-16 11:29:23 -07002791 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002792 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002793 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002794 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002795 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2796 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002797 if (ql2xenabledif == 1)
2798 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002799 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002800 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002801 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002802 | SHOST_DIF_TYPE3_PROTECTION
2803 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002804 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002805 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002806
2807 guard = SHOST_DIX_GUARD_CRC;
2808
2809 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2810 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2811 guard |= SHOST_DIX_GUARD_IP;
2812
2813 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002814 } else
2815 base_vha->flags.difdix_supported = 0;
2816 }
2817
Giridhar Malavalia9083012010-04-12 17:59:55 -07002818 ha->isp_ops->enable_intrs(ha);
2819
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002820 if (IS_QLAFX00(ha)) {
2821 ret = qlafx00_fx_disc(base_vha,
2822 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2823 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2824 QLA_SG_ALL : 128;
2825 }
2826
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002827 ret = scsi_add_host(host, &pdev->dev);
2828 if (ret)
2829 goto probe_failed;
2830
Michael Reed14864002009-12-02 09:11:16 -06002831 base_vha->flags.init_done = 1;
2832 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04002833 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06002834
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002835 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2836 "Init done and hba is online.\n");
2837
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002838 if (qla_ini_mode_enabled(base_vha))
2839 scsi_scan_host(host);
2840 else
2841 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2842 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002845
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002846 if (IS_QLAFX00(ha)) {
2847 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002848 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2849
2850 /* Register system information */
2851 ret = qlafx00_fx_disc(base_vha,
2852 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2853 }
2854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002856
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002858
Armen Baloyan03eb9122013-10-30 03:38:22 -04002859 ql_log(ql_log_info, base_vha, 0x00fb,
2860 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002861 ql_log(ql_log_info, base_vha, 0x00fc,
2862 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2863 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2864 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2865 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002866 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002868 qlt_add_target(ha, base_vha);
2869
Joe Lawrence6b383972014-08-26 17:12:29 -04002870 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 return 0;
2872
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002873probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002874 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002875 ha->req_q_map[0] = NULL;
2876 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002877 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002878 ha->rsp_q_map[0] = NULL;
2879 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002880 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002883 if (base_vha->timer_active)
2884 qla2x00_stop_timer(base_vha);
2885 base_vha->flags.online = 0;
2886 if (ha->dpc_thread) {
2887 struct task_struct *t = ha->dpc_thread;
2888
2889 ha->dpc_thread = NULL;
2890 kthread_stop(t);
2891 }
2892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002893 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002897probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04002898 qla2x00_clear_drv_active(ha);
2899
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002900iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002901 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002902 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002903 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002904 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002905 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002906 } else {
2907 if (ha->iobase)
2908 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002909 if (ha->cregbase)
2910 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002911 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912 pci_release_selected_regions(ha->pdev, ha->bars);
2913 kfree(ha);
2914 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002916probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002918 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920
Adrian Bunk4c993f72008-01-14 00:55:16 -08002921static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002922qla2x00_shutdown(struct pci_dev *pdev)
2923{
2924 scsi_qla_host_t *vha;
2925 struct qla_hw_data *ha;
2926
Masanari Iida552f3f92013-02-08 01:57:44 -05002927 if (!atomic_read(&pdev->enable_cnt))
2928 return;
2929
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002930 vha = pci_get_drvdata(pdev);
2931 ha = vha->hw;
2932
Armen Baloyan42479342013-08-27 01:37:37 -04002933 /* Notify ISPFX00 firmware */
2934 if (IS_QLAFX00(ha))
2935 qlafx00_driver_shutdown(vha, 20);
2936
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002937 /* Turn-off FCE trace */
2938 if (ha->flags.fce_enabled) {
2939 qla2x00_disable_fce_trace(vha, NULL, NULL);
2940 ha->flags.fce_enabled = 0;
2941 }
2942
2943 /* Turn-off EFT trace */
2944 if (ha->eft)
2945 qla2x00_disable_eft_trace(vha);
2946
2947 /* Stop currently executing firmware. */
2948 qla2x00_try_to_stop_firmware(vha);
2949
2950 /* Turn adapter off line */
2951 vha->flags.online = 0;
2952
2953 /* turn-off interrupts on the card */
2954 if (ha->interrupts_on) {
2955 vha->flags.init_done = 0;
2956 ha->isp_ops->disable_intrs(ha);
2957 }
2958
2959 qla2x00_free_irqs(vha);
2960
2961 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04002962
2963 pci_disable_pcie_error_reporting(pdev);
2964 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002965}
2966
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002967/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002968static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002969qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002971 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002972 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
Arun Easi43ebf162011-05-10 11:18:16 -07002974 mutex_lock(&ha->vport_lock);
2975 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07002976 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002977
Arun Easi43ebf162011-05-10 11:18:16 -07002978 BUG_ON(base_vha->list.next == &ha->vp_list);
2979 /* This assumes first entry in ha->vp_list is always base vha */
2980 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07002981 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002982
Arun Easi43ebf162011-05-10 11:18:16 -07002983 spin_unlock_irqrestore(&ha->vport_slock, flags);
2984 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002985
Arun Easi43ebf162011-05-10 11:18:16 -07002986 fc_vport_terminate(vha->fc_vport);
2987 scsi_host_put(vha->host);
2988
2989 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 }
Arun Easi43ebf162011-05-10 11:18:16 -07002991 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002992}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002993
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002994/* Stops all deferred work threads */
2995static void
2996qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
2997{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002998 /* Flush the work queue and remove it */
2999 if (ha->wq) {
3000 flush_workqueue(ha->wq);
3001 destroy_workqueue(ha->wq);
3002 ha->wq = NULL;
3003 }
3004
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003005 /* Cancel all work and destroy DPC workqueues */
3006 if (ha->dpc_lp_wq) {
3007 cancel_work_sync(&ha->idc_aen);
3008 destroy_workqueue(ha->dpc_lp_wq);
3009 ha->dpc_lp_wq = NULL;
3010 }
3011
3012 if (ha->dpc_hp_wq) {
3013 cancel_work_sync(&ha->nic_core_reset);
3014 cancel_work_sync(&ha->idc_state_handler);
3015 cancel_work_sync(&ha->nic_core_unrecoverable);
3016 destroy_workqueue(ha->dpc_hp_wq);
3017 ha->dpc_hp_wq = NULL;
3018 }
3019
Andrew Vasquezb9978762009-03-24 09:08:05 -07003020 /* Kill the kernel thread for this host */
3021 if (ha->dpc_thread) {
3022 struct task_struct *t = ha->dpc_thread;
3023
3024 /*
3025 * qla2xxx_wake_dpc checks for ->dpc_thread
3026 * so we need to zero it out.
3027 */
3028 ha->dpc_thread = NULL;
3029 kthread_stop(t);
3030 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003031}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003032
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003033static void
3034qla2x00_unmap_iobases(struct qla_hw_data *ha)
3035{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003036 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003037
Chad Dupuisf73cb692014-02-26 04:15:06 -05003038 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003039 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003040 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003041 } else {
3042 if (ha->iobase)
3043 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003045 if (ha->cregbase)
3046 iounmap(ha->cregbase);
3047
Giridhar Malavalia9083012010-04-12 17:59:55 -07003048 if (ha->mqiobase)
3049 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003050
Chad Dupuisf73cb692014-02-26 04:15:06 -05003051 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003052 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003053 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003054}
3055
3056static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003057qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003058{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003059 if (IS_QLA8044(ha)) {
3060 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003061 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003062 qla8044_idc_unlock(ha);
3063 } else if (IS_QLA82XX(ha)) {
3064 qla82xx_idc_lock(ha);
3065 qla82xx_clear_drv_active(ha);
3066 qla82xx_idc_unlock(ha);
3067 }
3068}
3069
3070static void
3071qla2x00_remove_one(struct pci_dev *pdev)
3072{
3073 scsi_qla_host_t *base_vha;
3074 struct qla_hw_data *ha;
3075
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003076 base_vha = pci_get_drvdata(pdev);
3077 ha = base_vha->hw;
3078
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003079 /* Indicate device removal to prevent future board_disable and wait
3080 * until any pending board_disable has completed. */
3081 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3082 cancel_work_sync(&ha->board_disable);
3083
3084 /*
3085 * If the PCI device is disabled then there was a PCI-disconnect and
3086 * qla2x00_disable_board_on_pci_error has taken care of most of the
3087 * resources.
3088 */
3089 if (!atomic_read(&pdev->enable_cnt)) {
3090 scsi_host_put(base_vha->host);
3091 kfree(ha);
3092 pci_set_drvdata(pdev, NULL);
3093 return;
3094 }
3095
Sawan Chandak638a1a02014-04-11 16:54:38 -04003096 qla2x00_wait_for_hba_ready(base_vha);
3097
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003098 set_bit(UNLOADING, &base_vha->dpc_flags);
3099
3100 if (IS_QLAFX00(ha))
3101 qlafx00_driver_shutdown(base_vha, 20);
3102
3103 qla2x00_delete_all_vps(ha, base_vha);
3104
3105 if (IS_QLA8031(ha)) {
3106 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3107 "Clearing fcoe driver presence.\n");
3108 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3109 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3110 "Error while clearing DRV-Presence.\n");
3111 }
3112
3113 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3114
3115 qla2x00_dfs_remove(base_vha);
3116
3117 qla84xx_put_chip(base_vha);
3118
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003119 /* Laser should be disabled only for ISP2031 */
3120 if (IS_QLA2031(ha))
3121 qla83xx_disable_laser(base_vha);
3122
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003123 /* Disable timer */
3124 if (base_vha->timer_active)
3125 qla2x00_stop_timer(base_vha);
3126
3127 base_vha->flags.online = 0;
3128
3129 qla2x00_destroy_deferred_work(ha);
3130
3131 qlt_remove_target(ha, base_vha);
3132
3133 qla2x00_free_sysfs_attr(base_vha, true);
3134
3135 fc_remove_host(base_vha->host);
3136
3137 scsi_remove_host(base_vha->host);
3138
3139 qla2x00_free_device(base_vha);
3140
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003141 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003142
Arun Easid2749ff2014-09-25 05:16:51 -04003143 scsi_host_put(base_vha->host);
3144
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003145 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147 pci_release_selected_regions(ha->pdev, ha->bars);
3148 kfree(ha);
3149 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003151 pci_disable_pcie_error_reporting(pdev);
3152
Bernhard Walle665db932007-03-28 00:49:49 +02003153 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155
3156static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
Andrew Vasquez85880802009-12-15 21:29:46 -08003161 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3162
3163 /* Disable timer */
3164 if (vha->timer_active)
3165 qla2x00_stop_timer(vha);
3166
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003167 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003168
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003169 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003171
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003172 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003174
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003175 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Andrew Vasquez85880802009-12-15 21:29:46 -08003178 vha->flags.online = 0;
3179
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003180 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003181 if (ha->interrupts_on) {
3182 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003183 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003184 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 qla2x00_free_irqs(vha);
3187
Chad Dupuis88670482010-07-23 15:28:30 +05003188 qla2x00_free_fcports(vha);
3189
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003190 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003191
Giridhar Malavali08de2842011-08-16 11:31:44 -07003192 qla82xx_md_free(vha);
3193
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003194 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195}
3196
Chad Dupuis88670482010-07-23 15:28:30 +05003197void qla2x00_free_fcports(struct scsi_qla_host *vha)
3198{
3199 fc_port_t *fcport, *tfcport;
3200
3201 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3202 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003203 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003204 kfree(fcport);
3205 fcport = NULL;
3206 }
3207}
3208
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003209static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003211 int defer)
3212{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003213 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003214 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003215 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003216
3217 if (!fcport->rport)
3218 return;
3219
3220 rport = fcport->rport;
3221 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003222 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003223 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003224 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003225 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003226 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3227 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003228 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003229 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003230 qlt_fc_port_deleted(vha, fcport);
3231 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003232}
3233
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3236 *
3237 * Input: ha = adapter block pointer. fcport = port structure pointer.
3238 *
3239 * Return: None.
3240 *
3241 * Context:
3242 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003243void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003244 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003246 if (IS_QLAFX00(vha->hw)) {
3247 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3248 qla2x00_schedule_rport_del(vha, fcport, defer);
3249 return;
3250 }
3251
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003252 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003253 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003254 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 qla2x00_schedule_rport_del(vha, fcport, defer);
3256 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003257 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 * We may need to retry the login, so don't change the state of the
3259 * port but do the retries.
3260 */
3261 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003262 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 if (!do_login)
3265 return;
3266
3267 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 fcport->login_retry = vha->hw->login_retry_count;
3269 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003271 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003272 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3273 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 }
3275}
3276
3277/*
3278 * qla2x00_mark_all_devices_lost
3279 * Updates fcport state when device goes offline.
3280 *
3281 * Input:
3282 * ha = adapter block pointer.
3283 * fcport = port structure pointer.
3284 *
3285 * Return:
3286 * None.
3287 *
3288 * Context:
3289 */
3290void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292{
3293 fc_port_t *fcport;
3294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003295 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003296 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003298
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 /*
3300 * No point in marking the device as lost, if the device is
3301 * already DEAD.
3302 */
3303 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3304 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003306 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003307 if (defer)
3308 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003309 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003310 qla2x00_schedule_rport_del(vha, fcport, defer);
3311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 }
3313}
3314
3315/*
3316* qla2x00_mem_alloc
3317* Allocates adapter memory.
3318*
3319* Returns:
3320* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003321* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003323static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003324qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3325 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326{
3327 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328
Andrew Vasqueze8711082008-01-31 12:33:48 -08003329 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003331 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003334 if (qlt_mem_alloc(ha) < 0)
3335 goto fail_free_init_cb;
3336
Chad Dupuis642ef982012-02-09 11:15:57 -08003337 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3338 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003339 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003340 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
Andrew Vasqueze8711082008-01-31 12:33:48 -08003342 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3343 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003346 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003347 /* Allocate cache for CT6 Ctx. */
3348 if (!ctx_cachep) {
3349 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3350 sizeof(struct ct6_dsd), 0,
3351 SLAB_HWCACHE_ALIGN, NULL);
3352 if (!ctx_cachep)
3353 goto fail_free_gid_list;
3354 }
3355 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3356 ctx_cachep);
3357 if (!ha->ctx_mempool)
3358 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003359 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3360 "ctx_cachep=%p ctx_mempool=%p.\n",
3361 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003362 }
3363
Andrew Vasqueze8711082008-01-31 12:33:48 -08003364 /* Get memory for cached NVRAM */
3365 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3366 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003367 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3370 ha->pdev->device);
3371 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3372 DMA_POOL_SIZE, 8, 0);
3373 if (!ha->s_dma_pool)
3374 goto fail_free_nvram;
3375
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003376 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3377 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3378 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3379
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003380 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003381 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3382 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3383 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003384 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3385 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003386 goto fail_s_dma_pool;
3387 }
3388
3389 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3390 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3391 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003392 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3393 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003394 goto fail_dl_dma_pool;
3395 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003396 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3397 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3398 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003399 }
3400
Andrew Vasqueze8711082008-01-31 12:33:48 -08003401 /* Allocate memory for SNS commands */
3402 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003404 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003406 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003408 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003409 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003410 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003412 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003414 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003415 goto fail_dma_pool;
3416 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003417 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003419 if (!ha->ct_sns)
3420 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003421 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3422 "ms_iocb=%p ct_sns=%p.\n",
3423 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
3425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003426 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003427 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3428 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003429 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3430 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 goto fail_req;
3432 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003433 (*req)->length = req_len;
3434 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3435 ((*req)->length + 1) * sizeof(request_t),
3436 &(*req)->dma, GFP_KERNEL);
3437 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003438 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3439 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440 goto fail_req_ring;
3441 }
3442 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003443 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3444 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003445 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3446 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003447 goto fail_rsp;
3448 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003449 (*rsp)->hw = ha;
3450 (*rsp)->length = rsp_len;
3451 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3452 ((*rsp)->length + 1) * sizeof(response_t),
3453 &(*rsp)->dma, GFP_KERNEL);
3454 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003455 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3456 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003457 goto fail_rsp_ring;
3458 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003459 (*req)->rsp = *rsp;
3460 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003461 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3462 "req=%p req->length=%d req->ring=%p rsp=%p "
3463 "rsp->length=%d rsp->ring=%p.\n",
3464 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3465 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003466 /* Allocate memory for NVRAM data for vports */
3467 if (ha->nvram_npiv_size) {
3468 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003469 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003470 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003471 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3472 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003473 goto fail_npiv_info;
3474 }
3475 } else
3476 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003478 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003479 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003480 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3481 &ha->ex_init_cb_dma);
3482 if (!ha->ex_init_cb)
3483 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003484 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3485 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003486 }
3487
Giridhar Malavalia9083012010-04-12 17:59:55 -07003488 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3489
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003490 /* Get consistent memory allocated for Async Port-Database. */
3491 if (!IS_FWI2_CAPABLE(ha)) {
3492 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3493 &ha->async_pd_dma);
3494 if (!ha->async_pd)
3495 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003496 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3497 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003498 }
3499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003501
3502 /* Allocate memory for our loop_id bitmap */
3503 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3504 GFP_KERNEL);
3505 if (!ha->loop_id_map)
3506 goto fail_async_pd;
3507 else {
3508 qla2x00_set_reserved_loop_ids(ha);
3509 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003510 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003511 }
3512
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003513 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003515fail_async_pd:
3516 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003517fail_ex_init_cb:
3518 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003519fail_npiv_info:
3520 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3521 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3522 (*rsp)->ring = NULL;
3523 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003524fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003525 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003526fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003527 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3528 sizeof(request_t), (*req)->ring, (*req)->dma);
3529 (*req)->ring = NULL;
3530 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003532 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533fail_req:
3534 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3535 ha->ct_sns, ha->ct_sns_dma);
3536 ha->ct_sns = NULL;
3537 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003538fail_free_ms_iocb:
3539 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3540 ha->ms_iocb = NULL;
3541 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003543 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003544 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3545 ha->fcp_cmnd_dma_pool = NULL;
3546 }
3547fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003548 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003549 dma_pool_destroy(ha->dl_dma_pool);
3550 ha->dl_dma_pool = NULL;
3551 }
3552fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003553 dma_pool_destroy(ha->s_dma_pool);
3554 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003555fail_free_nvram:
3556 kfree(ha->nvram);
3557 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003558fail_free_ctx_mempool:
3559 mempool_destroy(ha->ctx_mempool);
3560 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003561fail_free_srb_mempool:
3562 mempool_destroy(ha->srb_mempool);
3563 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003564fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003565 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3566 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003567 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003568 ha->gid_list = NULL;
3569 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003570fail_free_tgt_mem:
3571 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572fail_free_init_cb:
3573 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3574 ha->init_cb_dma);
3575 ha->init_cb = NULL;
3576 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003577fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003578 ql_log(ql_log_fatal, NULL, 0x0030,
3579 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003580 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581}
3582
3583/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003584* qla2x00_free_fw_dump
3585* Frees fw dump stuff.
3586*
3587* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003588* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003589*/
3590static void
3591qla2x00_free_fw_dump(struct qla_hw_data *ha)
3592{
3593 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003594 dma_free_coherent(&ha->pdev->dev,
3595 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003596
Chad Dupuisf73cb692014-02-26 04:15:06 -05003597 if (ha->eft)
3598 dma_free_coherent(&ha->pdev->dev,
3599 EFT_SIZE, ha->eft, ha->eft_dma);
3600
3601 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003602 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05003603 if (ha->fw_dump_template)
3604 vfree(ha->fw_dump_template);
3605
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003606 ha->fce = NULL;
3607 ha->fce_dma = 0;
3608 ha->eft = NULL;
3609 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003610 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04003611 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003612 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003613 ha->fw_dump = NULL;
3614 ha->fw_dump_len = 0;
3615 ha->fw_dump_template = NULL;
3616 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003617}
3618
3619/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620* qla2x00_mem_free
3621* Frees all adapter allocated memory.
3622*
3623* Input:
3624* ha = adapter block pointer.
3625*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003626static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003627qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003629 qla2x00_free_fw_dump(ha);
3630
Saurav Kashyap81178772012-08-22 14:21:04 -04003631 if (ha->mctp_dump)
3632 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3633 ha->mctp_dump_dma);
3634
Andrew Vasqueze8711082008-01-31 12:33:48 -08003635 if (ha->srb_mempool)
3636 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003638 if (ha->dcbx_tlv)
3639 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3640 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3641
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003642 if (ha->xgmac_data)
3643 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3644 ha->xgmac_data, ha->xgmac_data_dma);
3645
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 if (ha->sns_cmd)
3647 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649
3650 if (ha->ct_sns)
3651 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003652 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653
Andrew Vasquez88729e52006-06-23 16:10:50 -07003654 if (ha->sfp_data)
3655 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3656
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 if (ha->ms_iocb)
3658 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3659
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003660 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003661 dma_pool_free(ha->s_dma_pool,
3662 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003663
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003664 if (ha->async_pd)
3665 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3666
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 if (ha->s_dma_pool)
3668 dma_pool_destroy(ha->s_dma_pool);
3669
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003671 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3672 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
Giridhar Malavalia9083012010-04-12 17:59:55 -07003674 if (IS_QLA82XX(ha)) {
3675 if (!list_empty(&ha->gbl_dsd_list)) {
3676 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3677
3678 /* clean up allocated prev pool */
3679 list_for_each_entry_safe(dsd_ptr,
3680 tdsd_ptr, &ha->gbl_dsd_list, list) {
3681 dma_pool_free(ha->dl_dma_pool,
3682 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3683 list_del(&dsd_ptr->list);
3684 kfree(dsd_ptr);
3685 }
3686 }
3687 }
3688
3689 if (ha->dl_dma_pool)
3690 dma_pool_destroy(ha->dl_dma_pool);
3691
3692 if (ha->fcp_cmnd_dma_pool)
3693 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3694
3695 if (ha->ctx_mempool)
3696 mempool_destroy(ha->ctx_mempool);
3697
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003698 qlt_mem_free(ha);
3699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003700 if (ha->init_cb)
3701 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003702 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003703 vfree(ha->optrom_buffer);
3704 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003705 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003706 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003707 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708
Andrew Vasqueze8711082008-01-31 12:33:48 -08003709 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003710 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 ha->sns_cmd = NULL;
3712 ha->sns_cmd_dma = 0;
3713 ha->ct_sns = NULL;
3714 ha->ct_sns_dma = 0;
3715 ha->ms_iocb = NULL;
3716 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 ha->init_cb = NULL;
3718 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003719 ha->ex_init_cb = NULL;
3720 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003721 ha->async_pd = NULL;
3722 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723
3724 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003725 ha->dl_dma_pool = NULL;
3726 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 ha->gid_list = NULL;
3729 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003730
3731 ha->tgt.atio_ring = NULL;
3732 ha->tgt.atio_dma = 0;
3733 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003734}
3735
3736struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3737 struct qla_hw_data *ha)
3738{
3739 struct Scsi_Host *host;
3740 struct scsi_qla_host *vha = NULL;
3741
3742 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3743 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003744 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3745 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003746 goto fail;
3747 }
3748
3749 /* Clear our data area */
3750 vha = shost_priv(host);
3751 memset(vha, 0, sizeof(scsi_qla_host_t));
3752
3753 vha->host = host;
3754 vha->host_no = host->host_no;
3755 vha->hw = ha;
3756
3757 INIT_LIST_HEAD(&vha->vp_fcports);
3758 INIT_LIST_HEAD(&vha->work_list);
3759 INIT_LIST_HEAD(&vha->list);
3760
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003761 spin_lock_init(&vha->work_lock);
3762
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003764 ql_dbg(ql_dbg_init, vha, 0x0041,
3765 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3766 vha->host, vha->hw, vha,
3767 dev_name(&(ha->pdev->dev)));
3768
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003769 return vha;
3770
3771fail:
3772 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773}
3774
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003775static struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003776qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003777{
3778 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003779 uint8_t bail;
3780
3781 QLA_VHA_MARK_BUSY(vha, bail);
3782 if (bail)
3783 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003784
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003785 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003786 if (!e) {
3787 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003788 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003789 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003790
3791 INIT_LIST_HEAD(&e->list);
3792 e->type = type;
3793 e->flags = QLA_EVT_FLAG_FREE;
3794 return e;
3795}
3796
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003797static int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003798qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003799{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003800 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003801
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003802 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003803 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003804 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003806
Andrew Vasquez0971de72008-04-03 13:13:18 -07003807 return QLA_SUCCESS;
3808}
3809
3810int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003812 u32 data)
3813{
3814 struct qla_work_evt *e;
3815
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003816 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003817 if (!e)
3818 return QLA_FUNCTION_FAILED;
3819
3820 e->u.aen.code = code;
3821 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003822 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003823}
3824
Andrew Vasquez8a659572009-02-08 20:50:12 -08003825int
3826qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3827{
3828 struct qla_work_evt *e;
3829
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003830 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003831 if (!e)
3832 return QLA_FUNCTION_FAILED;
3833
3834 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003835 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003836}
3837
Andrew Vasquezac280b62009-08-20 11:06:05 -07003838#define qla2x00_post_async_work(name, type) \
3839int qla2x00_post_async_##name##_work( \
3840 struct scsi_qla_host *vha, \
3841 fc_port_t *fcport, uint16_t *data) \
3842{ \
3843 struct qla_work_evt *e; \
3844 \
3845 e = qla2x00_alloc_work(vha, type); \
3846 if (!e) \
3847 return QLA_FUNCTION_FAILED; \
3848 \
3849 e->u.logio.fcport = fcport; \
3850 if (data) { \
3851 e->u.logio.data[0] = data[0]; \
3852 e->u.logio.data[1] = data[1]; \
3853 } \
3854 return qla2x00_post_work(vha, e); \
3855}
3856
3857qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3858qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3859qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3860qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003861qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3862qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003863
Andrew Vasquez3420d362009-10-13 15:16:45 -07003864int
3865qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3866{
3867 struct qla_work_evt *e;
3868
3869 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3870 if (!e)
3871 return QLA_FUNCTION_FAILED;
3872
3873 e->u.uevent.code = code;
3874 return qla2x00_post_work(vha, e);
3875}
3876
3877static void
3878qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3879{
3880 char event_string[40];
3881 char *envp[] = { event_string, NULL };
3882
3883 switch (code) {
3884 case QLA_UEVENT_CODE_FW_DUMP:
3885 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3886 vha->host_no);
3887 break;
3888 default:
3889 /* do nothing */
3890 break;
3891 }
3892 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3893}
3894
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003895int
3896qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
3897 uint32_t *data, int cnt)
3898{
3899 struct qla_work_evt *e;
3900
3901 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
3902 if (!e)
3903 return QLA_FUNCTION_FAILED;
3904
3905 e->u.aenfx.evtcode = evtcode;
3906 e->u.aenfx.count = cnt;
3907 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
3908 return qla2x00_post_work(vha, e);
3909}
3910
Andrew Vasquezac280b62009-08-20 11:06:05 -07003911void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003913{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003914 struct qla_work_evt *e, *tmp;
3915 unsigned long flags;
3916 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003917
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003918 spin_lock_irqsave(&vha->work_lock, flags);
3919 list_splice_init(&vha->work_list, &work);
3920 spin_unlock_irqrestore(&vha->work_lock, flags);
3921
3922 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003923 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003924
3925 switch (e->type) {
3926 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003927 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003928 e->u.aen.code, e->u.aen.data);
3929 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003930 case QLA_EVT_IDC_ACK:
3931 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3932 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003933 case QLA_EVT_ASYNC_LOGIN:
3934 qla2x00_async_login(vha, e->u.logio.fcport,
3935 e->u.logio.data);
3936 break;
3937 case QLA_EVT_ASYNC_LOGIN_DONE:
3938 qla2x00_async_login_done(vha, e->u.logio.fcport,
3939 e->u.logio.data);
3940 break;
3941 case QLA_EVT_ASYNC_LOGOUT:
3942 qla2x00_async_logout(vha, e->u.logio.fcport);
3943 break;
3944 case QLA_EVT_ASYNC_LOGOUT_DONE:
3945 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3946 e->u.logio.data);
3947 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003948 case QLA_EVT_ASYNC_ADISC:
3949 qla2x00_async_adisc(vha, e->u.logio.fcport,
3950 e->u.logio.data);
3951 break;
3952 case QLA_EVT_ASYNC_ADISC_DONE:
3953 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3954 e->u.logio.data);
3955 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003956 case QLA_EVT_UEVENT:
3957 qla2x00_uevent_emit(vha, e->u.uevent.code);
3958 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003959 case QLA_EVT_AENFX:
3960 qlafx00_process_aen(vha, e);
3961 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003962 }
3963 if (e->flags & QLA_EVT_FLAG_FREE)
3964 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003965
3966 /* For each work completed decrement vha ref count */
3967 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003968 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971/* Relogins all the fcports of a vport
3972 * Context: dpc thread
3973 */
3974void qla2x00_relogin(struct scsi_qla_host *vha)
3975{
3976 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003977 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 uint16_t next_loopid = 0;
3979 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003980 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981
3982 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3983 /*
3984 * If the port is not ONLINE then try to login
3985 * to it if we haven't run out of retries.
3986 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003987 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3988 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003989 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003990 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003991 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003992 ha->isp_ops->fabric_logout(vha,
3993 fcport->loop_id,
3994 fcport->d_id.b.domain,
3995 fcport->d_id.b.area,
3996 fcport->d_id.b.al_pa);
3997
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003998 if (fcport->loop_id == FC_NO_LOOP_ID) {
3999 fcport->loop_id = next_loopid =
4000 ha->min_external_loopid;
4001 status = qla2x00_find_new_loop_id(
4002 vha, fcport);
4003 if (status != QLA_SUCCESS) {
4004 /* Ran out of IDs to use */
4005 break;
4006 }
4007 }
4008
Andrew Vasquezac280b62009-08-20 11:06:05 -07004009 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004010 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004011 data[0] = 0;
4012 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4013 status = qla2x00_post_async_login_work(
4014 vha, fcport, data);
4015 if (status == QLA_SUCCESS)
4016 continue;
4017 /* Attempt a retry. */
4018 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004019 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004020 status = qla2x00_fabric_login(vha,
4021 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004022 if (status == QLA_SUCCESS) {
4023 int status2;
4024 uint8_t opts;
4025
4026 opts = 0;
4027 if (fcport->flags &
4028 FCF_FCP2_DEVICE)
4029 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004030 status2 =
4031 qla2x00_get_port_database(
4032 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004033 if (status2 != QLA_SUCCESS)
4034 status = 1;
4035 }
4036 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004037 } else
4038 status = qla2x00_local_device_login(vha,
4039 fcport);
4040
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004041 if (status == QLA_SUCCESS) {
4042 fcport->old_loop_id = fcport->loop_id;
4043
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004044 ql_dbg(ql_dbg_disc, vha, 0x2003,
4045 "Port login OK: logged in ID 0x%x.\n",
4046 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004047
4048 qla2x00_update_fcport(vha, fcport);
4049
4050 } else if (status == 1) {
4051 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4052 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004053 ql_dbg(ql_dbg_disc, vha, 0x2007,
4054 "Retrying %d login again loop_id 0x%x.\n",
4055 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 } else {
4057 fcport->login_retry = 0;
4058 }
4059
4060 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004061 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 }
4063 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4064 break;
4065 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004066}
4067
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004068/* Schedule work on any of the dpc-workqueues */
4069void
4070qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4071{
4072 struct qla_hw_data *ha = base_vha->hw;
4073
4074 switch (work_code) {
4075 case MBA_IDC_AEN: /* 0x8200 */
4076 if (ha->dpc_lp_wq)
4077 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4078 break;
4079
4080 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4081 if (!ha->flags.nic_core_reset_hdlr_active) {
4082 if (ha->dpc_hp_wq)
4083 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4084 } else
4085 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4086 "NIC Core reset is already active. Skip "
4087 "scheduling it again.\n");
4088 break;
4089 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4090 if (ha->dpc_hp_wq)
4091 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4092 break;
4093 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4094 if (ha->dpc_hp_wq)
4095 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4096 break;
4097 default:
4098 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004099 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004100 }
4101
4102 return;
4103}
4104
4105/* Work: Perform NIC Core Unrecoverable state handling */
4106void
4107qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4108{
4109 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004110 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004111 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4112 uint32_t dev_state = 0;
4113
4114 qla83xx_idc_lock(base_vha, 0);
4115 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4116 qla83xx_reset_ownership(base_vha);
4117 if (ha->flags.nic_core_reset_owner) {
4118 ha->flags.nic_core_reset_owner = 0;
4119 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4120 QLA8XXX_DEV_FAILED);
4121 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4122 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4123 }
4124 qla83xx_idc_unlock(base_vha, 0);
4125}
4126
4127/* Work: Execute IDC state handler */
4128void
4129qla83xx_idc_state_handler_work(struct work_struct *work)
4130{
4131 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004132 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004133 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4134 uint32_t dev_state = 0;
4135
4136 qla83xx_idc_lock(base_vha, 0);
4137 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4138 if (dev_state == QLA8XXX_DEV_FAILED ||
4139 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4140 qla83xx_idc_state_handler(base_vha);
4141 qla83xx_idc_unlock(base_vha, 0);
4142}
4143
Saurav Kashyapfa492632012-11-21 02:40:29 -05004144static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004145qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4146{
4147 int rval = QLA_SUCCESS;
4148 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4149 uint32_t heart_beat_counter1, heart_beat_counter2;
4150
4151 do {
4152 if (time_after(jiffies, heart_beat_wait)) {
4153 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4154 "Nic Core f/w is not alive.\n");
4155 rval = QLA_FUNCTION_FAILED;
4156 break;
4157 }
4158
4159 qla83xx_idc_lock(base_vha, 0);
4160 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4161 &heart_beat_counter1);
4162 qla83xx_idc_unlock(base_vha, 0);
4163 msleep(100);
4164 qla83xx_idc_lock(base_vha, 0);
4165 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4166 &heart_beat_counter2);
4167 qla83xx_idc_unlock(base_vha, 0);
4168 } while (heart_beat_counter1 == heart_beat_counter2);
4169
4170 return rval;
4171}
4172
4173/* Work: Perform NIC Core Reset handling */
4174void
4175qla83xx_nic_core_reset_work(struct work_struct *work)
4176{
4177 struct qla_hw_data *ha =
4178 container_of(work, struct qla_hw_data, nic_core_reset);
4179 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4180 uint32_t dev_state = 0;
4181
Saurav Kashyap81178772012-08-22 14:21:04 -04004182 if (IS_QLA2031(ha)) {
4183 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4184 ql_log(ql_log_warn, base_vha, 0xb081,
4185 "Failed to dump mctp\n");
4186 return;
4187 }
4188
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004189 if (!ha->flags.nic_core_reset_hdlr_active) {
4190 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4191 qla83xx_idc_lock(base_vha, 0);
4192 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4193 &dev_state);
4194 qla83xx_idc_unlock(base_vha, 0);
4195 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4196 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4197 "Nic Core f/w is alive.\n");
4198 return;
4199 }
4200 }
4201
4202 ha->flags.nic_core_reset_hdlr_active = 1;
4203 if (qla83xx_nic_core_reset(base_vha)) {
4204 /* NIC Core reset failed. */
4205 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4206 "NIC Core reset failed.\n");
4207 }
4208 ha->flags.nic_core_reset_hdlr_active = 0;
4209 }
4210}
4211
4212/* Work: Handle 8200 IDC aens */
4213void
4214qla83xx_service_idc_aen(struct work_struct *work)
4215{
4216 struct qla_hw_data *ha =
4217 container_of(work, struct qla_hw_data, idc_aen);
4218 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4219 uint32_t dev_state, idc_control;
4220
4221 qla83xx_idc_lock(base_vha, 0);
4222 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4223 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4224 qla83xx_idc_unlock(base_vha, 0);
4225 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4226 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4227 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4228 "Application requested NIC Core Reset.\n");
4229 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4230 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4231 QLA_SUCCESS) {
4232 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4233 "Other protocol driver requested NIC Core Reset.\n");
4234 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4235 }
4236 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4237 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4238 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4239 }
4240}
4241
4242static void
4243qla83xx_wait_logic(void)
4244{
4245 int i;
4246
4247 /* Yield CPU */
4248 if (!in_interrupt()) {
4249 /*
4250 * Wait about 200ms before retrying again.
4251 * This controls the number of retries for single
4252 * lock operation.
4253 */
4254 msleep(100);
4255 schedule();
4256 } else {
4257 for (i = 0; i < 20; i++)
4258 cpu_relax(); /* This a nop instr on i386 */
4259 }
4260}
4261
Saurav Kashyapfa492632012-11-21 02:40:29 -05004262static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004263qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4264{
4265 int rval;
4266 uint32_t data;
4267 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4268 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4269 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004270 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4271 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004272
4273 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4274 if (rval)
4275 return rval;
4276
4277 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4278 return QLA_SUCCESS;
4279 } else {
4280 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4281 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4282 data);
4283 if (rval)
4284 return rval;
4285
4286 msleep(200);
4287
4288 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4289 &data);
4290 if (rval)
4291 return rval;
4292
4293 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4294 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4295 ~(idc_lck_rcvry_stage_mask));
4296 rval = qla83xx_wr_reg(base_vha,
4297 QLA83XX_IDC_LOCK_RECOVERY, data);
4298 if (rval)
4299 return rval;
4300
4301 /* Forcefully perform IDC UnLock */
4302 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4303 &data);
4304 if (rval)
4305 return rval;
4306 /* Clear lock-id by setting 0xff */
4307 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4308 0xff);
4309 if (rval)
4310 return rval;
4311 /* Clear lock-recovery by setting 0x0 */
4312 rval = qla83xx_wr_reg(base_vha,
4313 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4314 if (rval)
4315 return rval;
4316 } else
4317 return QLA_SUCCESS;
4318 }
4319
4320 return rval;
4321}
4322
Saurav Kashyapfa492632012-11-21 02:40:29 -05004323static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004324qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4325{
4326 int rval = QLA_SUCCESS;
4327 uint32_t o_drv_lockid, n_drv_lockid;
4328 unsigned long lock_recovery_timeout;
4329
4330 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4331retry_lockid:
4332 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4333 if (rval)
4334 goto exit;
4335
4336 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4337 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4338 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4339 return QLA_SUCCESS;
4340 else
4341 return QLA_FUNCTION_FAILED;
4342 }
4343
4344 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4345 if (rval)
4346 goto exit;
4347
4348 if (o_drv_lockid == n_drv_lockid) {
4349 qla83xx_wait_logic();
4350 goto retry_lockid;
4351 } else
4352 return QLA_SUCCESS;
4353
4354exit:
4355 return rval;
4356}
4357
4358void
4359qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4360{
4361 uint16_t options = (requester_id << 15) | BIT_6;
4362 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004363 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004364 struct qla_hw_data *ha = base_vha->hw;
4365
4366 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4367retry_lock:
4368 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4369 == QLA_SUCCESS) {
4370 if (data) {
4371 /* Setting lock-id to our function-number */
4372 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4373 ha->portnum);
4374 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004375 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4376 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004377 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004378 "Failed to acquire IDC lock, acquired by %d, "
4379 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004380
4381 /* Retry/Perform IDC-Lock recovery */
4382 if (qla83xx_idc_lock_recovery(base_vha)
4383 == QLA_SUCCESS) {
4384 qla83xx_wait_logic();
4385 goto retry_lock;
4386 } else
4387 ql_log(ql_log_warn, base_vha, 0xb075,
4388 "IDC Lock recovery FAILED.\n");
4389 }
4390
4391 }
4392
4393 return;
4394
4395 /* XXX: IDC-lock implementation using access-control mbx */
4396retry_lock2:
4397 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4398 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4399 "Failed to acquire IDC lock. retrying...\n");
4400 /* Retry/Perform IDC-Lock recovery */
4401 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4402 qla83xx_wait_logic();
4403 goto retry_lock2;
4404 } else
4405 ql_log(ql_log_warn, base_vha, 0xb076,
4406 "IDC Lock recovery FAILED.\n");
4407 }
4408
4409 return;
4410}
4411
4412void
4413qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4414{
Bart Van Assche5897cb22015-06-04 15:57:20 -07004415#if 0
4416 uint16_t options = (requester_id << 15) | BIT_7;
4417#endif
4418 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004419 uint32_t data;
4420 struct qla_hw_data *ha = base_vha->hw;
4421
4422 /* IDC-unlock implementation using driver-unlock/lock-id
4423 * remote registers
4424 */
4425 retry = 0;
4426retry_unlock:
4427 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4428 == QLA_SUCCESS) {
4429 if (data == ha->portnum) {
4430 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4431 /* Clearing lock-id by setting 0xff */
4432 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4433 } else if (retry < 10) {
4434 /* SV: XXX: IDC unlock retrying needed here? */
4435
4436 /* Retry for IDC-unlock */
4437 qla83xx_wait_logic();
4438 retry++;
4439 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4440 "Failed to release IDC lock, retyring=%d\n", retry);
4441 goto retry_unlock;
4442 }
4443 } else if (retry < 10) {
4444 /* Retry for IDC-unlock */
4445 qla83xx_wait_logic();
4446 retry++;
4447 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4448 "Failed to read drv-lockid, retyring=%d\n", retry);
4449 goto retry_unlock;
4450 }
4451
4452 return;
4453
Bart Van Assche5897cb22015-06-04 15:57:20 -07004454#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004455 /* XXX: IDC-unlock implementation using access-control mbx */
4456 retry = 0;
4457retry_unlock2:
4458 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4459 if (retry < 10) {
4460 /* Retry for IDC-unlock */
4461 qla83xx_wait_logic();
4462 retry++;
4463 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4464 "Failed to release IDC lock, retyring=%d\n", retry);
4465 goto retry_unlock2;
4466 }
4467 }
4468
4469 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07004470#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004471}
4472
4473int
4474__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4475{
4476 int rval = QLA_SUCCESS;
4477 struct qla_hw_data *ha = vha->hw;
4478 uint32_t drv_presence;
4479
4480 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4481 if (rval == QLA_SUCCESS) {
4482 drv_presence |= (1 << ha->portnum);
4483 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4484 drv_presence);
4485 }
4486
4487 return rval;
4488}
4489
4490int
4491qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4492{
4493 int rval = QLA_SUCCESS;
4494
4495 qla83xx_idc_lock(vha, 0);
4496 rval = __qla83xx_set_drv_presence(vha);
4497 qla83xx_idc_unlock(vha, 0);
4498
4499 return rval;
4500}
4501
4502int
4503__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4504{
4505 int rval = QLA_SUCCESS;
4506 struct qla_hw_data *ha = vha->hw;
4507 uint32_t drv_presence;
4508
4509 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4510 if (rval == QLA_SUCCESS) {
4511 drv_presence &= ~(1 << ha->portnum);
4512 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4513 drv_presence);
4514 }
4515
4516 return rval;
4517}
4518
4519int
4520qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4521{
4522 int rval = QLA_SUCCESS;
4523
4524 qla83xx_idc_lock(vha, 0);
4525 rval = __qla83xx_clear_drv_presence(vha);
4526 qla83xx_idc_unlock(vha, 0);
4527
4528 return rval;
4529}
4530
Saurav Kashyapfa492632012-11-21 02:40:29 -05004531static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004532qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4533{
4534 struct qla_hw_data *ha = vha->hw;
4535 uint32_t drv_ack, drv_presence;
4536 unsigned long ack_timeout;
4537
4538 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4539 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4540 while (1) {
4541 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4542 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004543 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004544 break;
4545
4546 if (time_after_eq(jiffies, ack_timeout)) {
4547 ql_log(ql_log_warn, vha, 0xb067,
4548 "RESET ACK TIMEOUT! drv_presence=0x%x "
4549 "drv_ack=0x%x\n", drv_presence, drv_ack);
4550 /*
4551 * The function(s) which did not ack in time are forced
4552 * to withdraw any further participation in the IDC
4553 * reset.
4554 */
4555 if (drv_ack != drv_presence)
4556 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4557 drv_ack);
4558 break;
4559 }
4560
4561 qla83xx_idc_unlock(vha, 0);
4562 msleep(1000);
4563 qla83xx_idc_lock(vha, 0);
4564 }
4565
4566 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4567 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4568}
4569
Saurav Kashyapfa492632012-11-21 02:40:29 -05004570static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004571qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4572{
4573 int rval = QLA_SUCCESS;
4574 uint32_t idc_control;
4575
4576 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4577 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4578
4579 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4580 __qla83xx_get_idc_control(vha, &idc_control);
4581 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4582 __qla83xx_set_idc_control(vha, 0);
4583
4584 qla83xx_idc_unlock(vha, 0);
4585 rval = qla83xx_restart_nic_firmware(vha);
4586 qla83xx_idc_lock(vha, 0);
4587
4588 if (rval != QLA_SUCCESS) {
4589 ql_log(ql_log_fatal, vha, 0xb06a,
4590 "Failed to restart NIC f/w.\n");
4591 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4592 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4593 } else {
4594 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4595 "Success in restarting nic f/w.\n");
4596 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4597 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4598 }
4599
4600 return rval;
4601}
4602
4603/* Assumes idc_lock always held on entry */
4604int
4605qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4606{
4607 struct qla_hw_data *ha = base_vha->hw;
4608 int rval = QLA_SUCCESS;
4609 unsigned long dev_init_timeout;
4610 uint32_t dev_state;
4611
4612 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4613 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4614
4615 while (1) {
4616
4617 if (time_after_eq(jiffies, dev_init_timeout)) {
4618 ql_log(ql_log_warn, base_vha, 0xb06e,
4619 "Initialization TIMEOUT!\n");
4620 /* Init timeout. Disable further NIC Core
4621 * communication.
4622 */
4623 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4624 QLA8XXX_DEV_FAILED);
4625 ql_log(ql_log_info, base_vha, 0xb06f,
4626 "HW State: FAILED.\n");
4627 }
4628
4629 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4630 switch (dev_state) {
4631 case QLA8XXX_DEV_READY:
4632 if (ha->flags.nic_core_reset_owner)
4633 qla83xx_idc_audit(base_vha,
4634 IDC_AUDIT_COMPLETION);
4635 ha->flags.nic_core_reset_owner = 0;
4636 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4637 "Reset_owner reset by 0x%x.\n",
4638 ha->portnum);
4639 goto exit;
4640 case QLA8XXX_DEV_COLD:
4641 if (ha->flags.nic_core_reset_owner)
4642 rval = qla83xx_device_bootstrap(base_vha);
4643 else {
4644 /* Wait for AEN to change device-state */
4645 qla83xx_idc_unlock(base_vha, 0);
4646 msleep(1000);
4647 qla83xx_idc_lock(base_vha, 0);
4648 }
4649 break;
4650 case QLA8XXX_DEV_INITIALIZING:
4651 /* Wait for AEN to change device-state */
4652 qla83xx_idc_unlock(base_vha, 0);
4653 msleep(1000);
4654 qla83xx_idc_lock(base_vha, 0);
4655 break;
4656 case QLA8XXX_DEV_NEED_RESET:
4657 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4658 qla83xx_need_reset_handler(base_vha);
4659 else {
4660 /* Wait for AEN to change device-state */
4661 qla83xx_idc_unlock(base_vha, 0);
4662 msleep(1000);
4663 qla83xx_idc_lock(base_vha, 0);
4664 }
4665 /* reset timeout value after need reset handler */
4666 dev_init_timeout = jiffies +
4667 (ha->fcoe_dev_init_timeout * HZ);
4668 break;
4669 case QLA8XXX_DEV_NEED_QUIESCENT:
4670 /* XXX: DEBUG for now */
4671 qla83xx_idc_unlock(base_vha, 0);
4672 msleep(1000);
4673 qla83xx_idc_lock(base_vha, 0);
4674 break;
4675 case QLA8XXX_DEV_QUIESCENT:
4676 /* XXX: DEBUG for now */
4677 if (ha->flags.quiesce_owner)
4678 goto exit;
4679
4680 qla83xx_idc_unlock(base_vha, 0);
4681 msleep(1000);
4682 qla83xx_idc_lock(base_vha, 0);
4683 dev_init_timeout = jiffies +
4684 (ha->fcoe_dev_init_timeout * HZ);
4685 break;
4686 case QLA8XXX_DEV_FAILED:
4687 if (ha->flags.nic_core_reset_owner)
4688 qla83xx_idc_audit(base_vha,
4689 IDC_AUDIT_COMPLETION);
4690 ha->flags.nic_core_reset_owner = 0;
4691 __qla83xx_clear_drv_presence(base_vha);
4692 qla83xx_idc_unlock(base_vha, 0);
4693 qla8xxx_dev_failed_handler(base_vha);
4694 rval = QLA_FUNCTION_FAILED;
4695 qla83xx_idc_lock(base_vha, 0);
4696 goto exit;
4697 case QLA8XXX_BAD_VALUE:
4698 qla83xx_idc_unlock(base_vha, 0);
4699 msleep(1000);
4700 qla83xx_idc_lock(base_vha, 0);
4701 break;
4702 default:
4703 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09004704 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004705 qla83xx_idc_unlock(base_vha, 0);
4706 qla8xxx_dev_failed_handler(base_vha);
4707 rval = QLA_FUNCTION_FAILED;
4708 qla83xx_idc_lock(base_vha, 0);
4709 goto exit;
4710 }
4711 }
4712
4713exit:
4714 return rval;
4715}
4716
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004717void
4718qla2x00_disable_board_on_pci_error(struct work_struct *work)
4719{
4720 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
4721 board_disable);
4722 struct pci_dev *pdev = ha->pdev;
4723 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4724
4725 ql_log(ql_log_warn, base_vha, 0x015b,
4726 "Disabling adapter.\n");
4727
4728 set_bit(UNLOADING, &base_vha->dpc_flags);
4729
4730 qla2x00_delete_all_vps(ha, base_vha);
4731
4732 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4733
4734 qla2x00_dfs_remove(base_vha);
4735
4736 qla84xx_put_chip(base_vha);
4737
4738 if (base_vha->timer_active)
4739 qla2x00_stop_timer(base_vha);
4740
4741 base_vha->flags.online = 0;
4742
4743 qla2x00_destroy_deferred_work(ha);
4744
4745 /*
4746 * Do not try to stop beacon blink as it will issue a mailbox
4747 * command.
4748 */
4749 qla2x00_free_sysfs_attr(base_vha, false);
4750
4751 fc_remove_host(base_vha->host);
4752
4753 scsi_remove_host(base_vha->host);
4754
4755 base_vha->flags.init_done = 0;
4756 qla25xx_delete_queues(base_vha);
4757 qla2x00_free_irqs(base_vha);
4758 qla2x00_free_fcports(base_vha);
4759 qla2x00_mem_free(ha);
4760 qla82xx_md_free(base_vha);
4761 qla2x00_free_queues(ha);
4762
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004763 qla2x00_unmap_iobases(ha);
4764
4765 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004766 pci_disable_pcie_error_reporting(pdev);
4767 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004768
Joe Lawrencebeb9e312014-08-26 17:12:14 -04004769 /*
4770 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
4771 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004772}
4773
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774/**************************************************************************
4775* qla2x00_do_dpc
4776* This kernel thread is a task that is schedule by the interrupt handler
4777* to perform the background processing for interrupts.
4778*
4779* Notes:
4780* This task always run in the context of a kernel thread. It
4781* is kick-off by the driver's detect code and starts up
4782* up one per adapter. It immediately goes to sleep and waits for
4783* some fibre event. When either the interrupt handler or
4784* the timer routine detects a event it will one of the task
4785* bits then wake us up.
4786**************************************************************************/
4787static int
4788qla2x00_do_dpc(void *data)
4789{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004790 scsi_qla_host_t *base_vha;
4791 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004793 ha = (struct qla_hw_data *)data;
4794 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795
Dongsheng Yang8698a742014-03-11 18:09:12 +08004796 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797
James Bottomley563585e2011-01-27 16:12:37 -05004798 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004799 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004800 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4801 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802
Christoph Hellwig39a11242006-02-14 18:46:22 +01004803 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004805 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4806 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807
Andrew Vasquez85880802009-12-15 21:29:46 -08004808 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004809 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4810 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004811 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004812 }
4813
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 ha->dpc_active = 1;
4815
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004816 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4817 "DPC handler waking up, dpc_flags=0x%lx.\n",
4818 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004820 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004821
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004822 if (IS_P3P_TYPE(ha)) {
4823 if (IS_QLA8044(ha)) {
4824 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4825 &base_vha->dpc_flags)) {
4826 qla8044_idc_lock(ha);
4827 qla8044_wr_direct(base_vha,
4828 QLA8044_CRB_DEV_STATE_INDEX,
4829 QLA8XXX_DEV_FAILED);
4830 qla8044_idc_unlock(ha);
4831 ql_log(ql_log_info, base_vha, 0x4004,
4832 "HW State: FAILED.\n");
4833 qla8044_device_state_handler(base_vha);
4834 continue;
4835 }
4836
4837 } else {
4838 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4839 &base_vha->dpc_flags)) {
4840 qla82xx_idc_lock(ha);
4841 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4842 QLA8XXX_DEV_FAILED);
4843 qla82xx_idc_unlock(ha);
4844 ql_log(ql_log_info, base_vha, 0x0151,
4845 "HW State: FAILED.\n");
4846 qla82xx_device_state_handler(base_vha);
4847 continue;
4848 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004849 }
4850
4851 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4852 &base_vha->dpc_flags)) {
4853
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004854 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4855 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004856 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4857 &base_vha->dpc_flags))) {
4858 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4859 /* FCoE-ctx reset failed.
4860 * Escalate to chip-reset
4861 */
4862 set_bit(ISP_ABORT_NEEDED,
4863 &base_vha->dpc_flags);
4864 }
4865 clear_bit(ABORT_ISP_ACTIVE,
4866 &base_vha->dpc_flags);
4867 }
4868
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004869 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4870 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004871 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004872 } else if (IS_QLAFX00(ha)) {
4873 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4874 &base_vha->dpc_flags)) {
4875 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
4876 "Firmware Reset Recovery\n");
4877 if (qlafx00_reset_initialize(base_vha)) {
4878 /* Failed. Abort isp later. */
4879 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03004880 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004881 set_bit(ISP_UNRECOVERABLE,
4882 &base_vha->dpc_flags);
4883 ql_dbg(ql_dbg_dpc, base_vha,
4884 0x4021,
4885 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03004886 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004887 }
4888 }
4889
4890 if (test_and_clear_bit(FX00_TARGET_SCAN,
4891 &base_vha->dpc_flags)) {
4892 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
4893 "ISPFx00 Target Scan scheduled\n");
4894 if (qlafx00_rescan_isp(base_vha)) {
4895 if (!test_bit(UNLOADING,
4896 &base_vha->dpc_flags))
4897 set_bit(ISP_UNRECOVERABLE,
4898 &base_vha->dpc_flags);
4899 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
4900 "ISPFx00 Target Scan Failed\n");
4901 }
4902 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
4903 "ISPFx00 Target Scan End\n");
4904 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04004905 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
4906 &base_vha->dpc_flags)) {
4907 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
4908 "ISPFx00 Host Info resend scheduled\n");
4909 qlafx00_fx_disc(base_vha,
4910 &base_vha->hw->mr.fcport,
4911 FXDISC_REG_HOST_INFO);
4912 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004913 }
4914
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004915 if (test_and_clear_bit(ISP_ABORT_NEEDED,
4916 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004918 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
4919 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004921 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922
Giridhar Malavalia9083012010-04-12 17:59:55 -07004923 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 /* failed. retry later */
4925 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004926 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004928 clear_bit(ABORT_ISP_ACTIVE,
4929 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08004930 }
4931
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004932 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
4933 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934 }
4935
David Jefferya394aac2012-11-21 02:39:54 -05004936 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
4937 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004938 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07004939 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004940
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004941 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
4942 int ret;
4943 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
4944 if (ret != QLA_SUCCESS)
4945 ql_log(ql_log_warn, base_vha, 0x121,
4946 "Failed to enable receiving of RSCN "
4947 "requests: 0x%x.\n", ret);
4948 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
4949 }
4950
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004951 if (IS_QLAFX00(ha))
4952 goto loop_resync_check;
4953
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004954 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004955 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
4956 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004957 if (IS_P3P_TYPE(ha)) {
4958 if (IS_QLA82XX(ha))
4959 qla82xx_device_state_handler(base_vha);
4960 if (IS_QLA8044(ha))
4961 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004962 clear_bit(ISP_QUIESCE_NEEDED,
4963 &base_vha->dpc_flags);
4964 if (!ha->flags.quiesce_owner) {
4965 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004966 if (IS_QLA82XX(ha)) {
4967 qla82xx_idc_lock(ha);
4968 qla82xx_clear_qsnt_ready(
4969 base_vha);
4970 qla82xx_idc_unlock(ha);
4971 } else if (IS_QLA8044(ha)) {
4972 qla8044_idc_lock(ha);
4973 qla8044_clear_qsnt_ready(
4974 base_vha);
4975 qla8044_idc_unlock(ha);
4976 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004977 }
4978 } else {
4979 clear_bit(ISP_QUIESCE_NEEDED,
4980 &base_vha->dpc_flags);
4981 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004982 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004983 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
4984 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004985 }
4986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004987 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004988 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004989 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004991 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
4992 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004993 qla2x00_rst_aen(base_vha);
4994 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004995 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
4996 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 }
4998
4999 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005000 if ((test_and_clear_bit(RELOGIN_NEEDED,
5001 &base_vha->dpc_flags)) &&
5002 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5003 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005005 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5006 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005007 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005008 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5009 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005011loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005012 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005013 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005015 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5016 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017
5018 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005019 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020
Bart Van Assche52c82822015-07-09 07:23:26 -07005021 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005023 clear_bit(LOOP_RESYNC_ACTIVE,
5024 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 }
5026
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005027 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5028 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 }
5030
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005031 if (IS_QLAFX00(ha))
5032 goto intr_on_check;
5033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005034 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5035 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5036 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5037 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005038 }
5039
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005040intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005042 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005044 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005045 &base_vha->dpc_flags)) {
5046 if (ha->beacon_blink_led == 1)
5047 ha->isp_ops->beacon_blink(base_vha);
5048 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005049
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005050 if (!IS_QLAFX00(ha))
5051 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005052
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005054end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005055 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005057 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005059 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5060 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
5062 /*
5063 * Make sure that nobody tries to wake us up again.
5064 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 ha->dpc_active = 0;
5066
Andrew Vasquezac280b62009-08-20 11:06:05 -07005067 /* Cleanup any residual CTX SRBs. */
5068 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5069
Christoph Hellwig39a11242006-02-14 18:46:22 +01005070 return 0;
5071}
5072
5073void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005074qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005075{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005076 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005077 struct task_struct *t = ha->dpc_thread;
5078
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005079 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005080 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081}
5082
5083/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084* qla2x00_rst_aen
5085* Processes asynchronous reset.
5086*
5087* Input:
5088* ha = adapter block pointer.
5089*/
5090static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005091qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005093 if (vha->flags.online && !vha->flags.reset_active &&
5094 !atomic_read(&vha->loop_down_timer) &&
5095 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005097 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098
5099 /*
5100 * Issue marker command only when we are going to start
5101 * the I/O.
5102 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005103 vha->marker_needed = 1;
5104 } while (!atomic_read(&vha->loop_down_timer) &&
5105 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 }
5107}
5108
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109/**************************************************************************
5110* qla2x00_timer
5111*
5112* Description:
5113* One second timer
5114*
5115* Context: Interrupt
5116***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005117void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005118qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121 int start_dpc = 0;
5122 int index;
5123 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005124 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005125 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005126 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005127
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005128 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005129 ql_dbg(ql_dbg_timer, vha, 0x6000,
5130 "EEH = %d, restarting timer.\n",
5131 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005132 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5133 return;
5134 }
5135
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005136 /*
5137 * Hardware read to raise pending EEH errors during mailbox waits. If
5138 * the read returns -1 then disable the board.
5139 */
5140 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005141 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005142 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005145 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005146 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005147 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5148 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005149 if (IS_QLA82XX(ha))
5150 qla82xx_watchdog(vha);
5151 else if (IS_QLA8044(ha))
5152 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005153 }
5154
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005155 if (!vha->vp_idx && IS_QLAFX00(ha))
5156 qlafx00_timer_routine(vha);
5157
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005159 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005160 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5161 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005162 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005164 if (atomic_read(&vha->loop_down_timer) ==
5165 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005167 ql_log(ql_log_info, vha, 0x6008,
5168 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005170 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5171 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005173 /*
5174 * Schedule an ISP abort to return any FCP2-device
5175 * commands.
5176 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005177 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005178 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005179 spin_lock_irqsave(&ha->hardware_lock,
5180 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005181 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005182 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005183 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005184 index++) {
5185 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005187 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005188 if (!sp)
5189 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005190 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005191 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005192 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005193 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005194 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005196 if (IS_QLA82XX(ha))
5197 set_bit(FCOE_CTX_RESET_NEEDED,
5198 &vha->dpc_flags);
5199 else
5200 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005201 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005202 break;
5203 }
5204 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005205 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 start_dpc++;
5208 }
5209
5210 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005211 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005212 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005213 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 "Loop down - aborting ISP.\n");
5215
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005216 if (IS_QLA82XX(ha))
5217 set_bit(FCOE_CTX_RESET_NEEDED,
5218 &vha->dpc_flags);
5219 else
5220 set_bit(ISP_ABORT_NEEDED,
5221 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 }
5223 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005224 ql_dbg(ql_dbg_timer, vha, 0x600a,
5225 "Loop down - seconds remaining %d.\n",
5226 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005228 /* Check if beacon LED needs to be blinked for physical host only */
5229 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005230 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005231 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005232 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5233 start_dpc++;
5234 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005235 }
5236
Andrew Vasquez550bf572008-04-24 15:21:23 -07005237 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005238 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005239 start_dpc++;
5240
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005242 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5243 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5244 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005246 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5247 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005248 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5249 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005250 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005251 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005252 ql_dbg(ql_dbg_timer, vha, 0x600b,
5253 "isp_abort_needed=%d loop_resync_needed=%d "
5254 "fcport_update_needed=%d start_dpc=%d "
5255 "reset_marker_needed=%d",
5256 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5257 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5258 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5259 start_dpc,
5260 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5261 ql_dbg(ql_dbg_timer, vha, 0x600c,
5262 "beacon_blink_needed=%d isp_unrecoverable=%d "
5263 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005264 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005265 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5266 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5267 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5268 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005269 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005270 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005273 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274}
5275
Andrew Vasquez54333832005-11-09 15:49:04 -08005276/* Firmware interface routines. */
5277
Chad Dupuisf73cb692014-02-26 04:15:06 -05005278#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08005279#define FW_ISP21XX 0
5280#define FW_ISP22XX 1
5281#define FW_ISP2300 2
5282#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005283#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005284#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005285#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005286#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005287#define FW_ISP2031 8
5288#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005289#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005290
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005291#define FW_FILE_ISP21XX "ql2100_fw.bin"
5292#define FW_FILE_ISP22XX "ql2200_fw.bin"
5293#define FW_FILE_ISP2300 "ql2300_fw.bin"
5294#define FW_FILE_ISP2322 "ql2322_fw.bin"
5295#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005296#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005297#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005298#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005299#define FW_FILE_ISP2031 "ql2600_fw.bin"
5300#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005301#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05005302
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005303
Daniel Walkere1e82b62008-05-12 22:21:10 -07005304static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005305
5306static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005307 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5308 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5309 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5310 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5311 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005312 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005313 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005314 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005315 { .name = FW_FILE_ISP2031, },
5316 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005317 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005318};
5319
5320struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005321qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005322{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005323 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005324 struct fw_blob *blob;
5325
Andrew Vasquez54333832005-11-09 15:49:04 -08005326 if (IS_QLA2100(ha)) {
5327 blob = &qla_fw_blobs[FW_ISP21XX];
5328 } else if (IS_QLA2200(ha)) {
5329 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005330 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005331 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005332 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005333 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005334 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005335 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005336 } else if (IS_QLA25XX(ha)) {
5337 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005338 } else if (IS_QLA81XX(ha)) {
5339 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005340 } else if (IS_QLA82XX(ha)) {
5341 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005342 } else if (IS_QLA2031(ha)) {
5343 blob = &qla_fw_blobs[FW_ISP2031];
5344 } else if (IS_QLA8031(ha)) {
5345 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005346 } else if (IS_QLA27XX(ha)) {
5347 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03005348 } else {
5349 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005350 }
5351
Daniel Walkere1e82b62008-05-12 22:21:10 -07005352 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005353 if (blob->fw)
5354 goto out;
5355
5356 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005357 ql_log(ql_log_warn, vha, 0x0063,
5358 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005359 blob->fw = NULL;
5360 blob = NULL;
5361 goto out;
5362 }
5363
5364out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005365 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005366 return blob;
5367}
5368
5369static void
5370qla2x00_release_firmware(void)
5371{
5372 int idx;
5373
Daniel Walkere1e82b62008-05-12 22:21:10 -07005374 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005375 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005376 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005377 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005378}
5379
Seokmann Ju14e660e2007-09-20 14:07:36 -07005380static pci_ers_result_t
5381qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5382{
Andrew Vasquez85880802009-12-15 21:29:46 -08005383 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5384 struct qla_hw_data *ha = vha->hw;
5385
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005386 ql_dbg(ql_dbg_aer, vha, 0x9000,
5387 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005388
Seokmann Ju14e660e2007-09-20 14:07:36 -07005389 switch (state) {
5390 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005391 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005392 return PCI_ERS_RESULT_CAN_RECOVER;
5393 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005394 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005395 /* For ISP82XX complete any pending mailbox cmd */
5396 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005397 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005398 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5399 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005400 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005401 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005402 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005403 /* Return back all IOs */
5404 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005405 return PCI_ERS_RESULT_NEED_RESET;
5406 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005407 ha->flags.pci_channel_io_perm_failure = 1;
5408 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005409 return PCI_ERS_RESULT_DISCONNECT;
5410 }
5411 return PCI_ERS_RESULT_NEED_RESET;
5412}
5413
5414static pci_ers_result_t
5415qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5416{
5417 int risc_paused = 0;
5418 uint32_t stat;
5419 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005420 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5421 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005422 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5423 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5424
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005425 if (IS_QLA82XX(ha))
5426 return PCI_ERS_RESULT_RECOVERED;
5427
Seokmann Ju14e660e2007-09-20 14:07:36 -07005428 spin_lock_irqsave(&ha->hardware_lock, flags);
5429 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5430 stat = RD_REG_DWORD(&reg->hccr);
5431 if (stat & HCCR_RISC_PAUSE)
5432 risc_paused = 1;
5433 } else if (IS_QLA23XX(ha)) {
5434 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5435 if (stat & HSR_RISC_PAUSED)
5436 risc_paused = 1;
5437 } else if (IS_FWI2_CAPABLE(ha)) {
5438 stat = RD_REG_DWORD(&reg24->host_status);
5439 if (stat & HSRX_RISC_PAUSED)
5440 risc_paused = 1;
5441 }
5442 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5443
5444 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005445 ql_log(ql_log_info, base_vha, 0x9003,
5446 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005447 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005448
5449 return PCI_ERS_RESULT_NEED_RESET;
5450 } else
5451 return PCI_ERS_RESULT_RECOVERED;
5452}
5453
Saurav Kashyapfa492632012-11-21 02:40:29 -05005454static uint32_t
5455qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005456{
5457 uint32_t rval = QLA_FUNCTION_FAILED;
5458 uint32_t drv_active = 0;
5459 struct qla_hw_data *ha = base_vha->hw;
5460 int fn;
5461 struct pci_dev *other_pdev = NULL;
5462
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005463 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5464 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005465
5466 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5467
5468 if (base_vha->flags.online) {
5469 /* Abort all outstanding commands,
5470 * so as to be requeued later */
5471 qla2x00_abort_isp_cleanup(base_vha);
5472 }
5473
5474
5475 fn = PCI_FUNC(ha->pdev->devfn);
5476 while (fn > 0) {
5477 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005478 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5479 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005480 other_pdev =
5481 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5482 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5483 fn));
5484
5485 if (!other_pdev)
5486 continue;
5487 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005488 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5489 "Found PCI func available and enable at 0x%x.\n",
5490 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005491 pci_dev_put(other_pdev);
5492 break;
5493 }
5494 pci_dev_put(other_pdev);
5495 }
5496
5497 if (!fn) {
5498 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005499 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5500 "This devfn is reset owner = 0x%x.\n",
5501 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005502 qla82xx_idc_lock(ha);
5503
5504 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005505 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005506
5507 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5508 QLA82XX_IDC_VERSION);
5509
5510 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005511 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5512 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005513
5514 qla82xx_idc_unlock(ha);
5515 /* Reset if device is not already reset
5516 * drv_active would be 0 if a reset has already been done
5517 */
5518 if (drv_active)
5519 rval = qla82xx_start_firmware(base_vha);
5520 else
5521 rval = QLA_SUCCESS;
5522 qla82xx_idc_lock(ha);
5523
5524 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005525 ql_log(ql_log_info, base_vha, 0x900b,
5526 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005527 qla82xx_clear_drv_active(ha);
5528 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005529 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005530 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005531 ql_log(ql_log_info, base_vha, 0x900c,
5532 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005533 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005534 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005535 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005536 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005537 rval = qla82xx_restart_isp(base_vha);
5538 qla82xx_idc_lock(ha);
5539 /* Clear driver state register */
5540 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5541 qla82xx_set_drv_active(base_vha);
5542 }
5543 qla82xx_idc_unlock(ha);
5544 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005545 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5546 "This devfn is not reset owner = 0x%x.\n",
5547 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005548 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005549 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005550 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005551 rval = qla82xx_restart_isp(base_vha);
5552 qla82xx_idc_lock(ha);
5553 qla82xx_set_drv_active(base_vha);
5554 qla82xx_idc_unlock(ha);
5555 }
5556 }
5557 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5558
5559 return rval;
5560}
5561
Seokmann Ju14e660e2007-09-20 14:07:36 -07005562static pci_ers_result_t
5563qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5564{
5565 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005566 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5567 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005568 struct rsp_que *rsp;
5569 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005570
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005571 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5572 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005573
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005574 /* Workaround: qla2xxx driver which access hardware earlier
5575 * needs error state to be pci_channel_io_online.
5576 * Otherwise mailbox command timesout.
5577 */
5578 pdev->error_state = pci_channel_io_normal;
5579
5580 pci_restore_state(pdev);
5581
Richard Lary8c1496b2010-02-18 10:07:29 -08005582 /* pci_restore_state() clears the saved_state flag of the device
5583 * save restored state which resets saved_state flag
5584 */
5585 pci_save_state(pdev);
5586
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005587 if (ha->mem_only)
5588 rc = pci_enable_device_mem(pdev);
5589 else
5590 rc = pci_enable_device(pdev);
5591
5592 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005593 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005594 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005595 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005596 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005597
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005598 rsp = ha->rsp_q_map[0];
5599 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005600 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005602 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005603 goto exit_slot_reset;
5604
5605 if (IS_QLA82XX(ha)) {
5606 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5607 ret = PCI_ERS_RESULT_RECOVERED;
5608 goto exit_slot_reset;
5609 } else
5610 goto exit_slot_reset;
5611 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005612
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005613 while (ha->flags.mbox_busy && retries--)
5614 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005615
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005616 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005617 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005618 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005619 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005620
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005621
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005622exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005623 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5624 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005625
Seokmann Ju14e660e2007-09-20 14:07:36 -07005626 return ret;
5627}
5628
5629static void
5630qla2xxx_pci_resume(struct pci_dev *pdev)
5631{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005632 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5633 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005634 int ret;
5635
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005636 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5637 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005639 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005640 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005641 ql_log(ql_log_fatal, base_vha, 0x9002,
5642 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005643 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005644
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005645 pci_cleanup_aer_uncorrect_error_status(pdev);
5646
Andrew Vasquez85880802009-12-15 21:29:46 -08005647 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005648}
5649
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04005650static void
5651qla83xx_disable_laser(scsi_qla_host_t *vha)
5652{
5653 uint32_t reg, data, fn;
5654 struct qla_hw_data *ha = vha->hw;
5655 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5656
5657 /* pci func #/port # */
5658 ql_dbg(ql_dbg_init, vha, 0x004b,
5659 "Disabling Laser for hba: %p\n", vha);
5660
5661 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5662 (BIT_15|BIT_14|BIT_13|BIT_12));
5663
5664 fn = (fn >> 12);
5665
5666 if (fn & 1)
5667 reg = PORT_1_2031;
5668 else
5669 reg = PORT_0_2031;
5670
5671 data = LASER_OFF_2031;
5672
5673 qla83xx_wr_reg(vha, reg, data);
5674}
5675
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005676static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005677 .error_detected = qla2xxx_pci_error_detected,
5678 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5679 .slot_reset = qla2xxx_pci_slot_reset,
5680 .resume = qla2xxx_pci_resume,
5681};
5682
Andrew Vasquez54333832005-11-09 15:49:04 -08005683static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005684 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5685 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5686 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5687 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5688 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5689 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5690 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5691 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5692 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005693 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005694 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5695 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005696 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005697 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005698 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005699 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005700 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005701 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005702 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05005703 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005704 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005705 { 0 },
5706};
5707MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5708
Andrew Vasquezfca29702005-07-06 10:31:47 -07005709static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005710 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005711 .driver = {
5712 .owner = THIS_MODULE,
5713 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005714 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005715 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005716 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005717 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005718 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005719};
5720
Al Viro75ef9de2013-04-04 19:09:41 -04005721static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005722 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005723 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005724};
5725
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726/**
5727 * qla2x00_module_init - Module initialization.
5728 **/
5729static int __init
5730qla2x00_module_init(void)
5731{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005732 int ret = 0;
5733
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005735 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005736 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005738 ql_log(ql_log_fatal, NULL, 0x0001,
5739 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 return -ENOMEM;
5741 }
5742
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005743 /* Initialize target kmem_cache and mem_pools */
5744 ret = qlt_init();
5745 if (ret < 0) {
5746 kmem_cache_destroy(srb_cachep);
5747 return ret;
5748 } else if (ret > 0) {
5749 /*
5750 * If initiator mode is explictly disabled by qlt_init(),
5751 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5752 * performing scsi_scan_target() during LOOP UP event.
5753 */
5754 qla2xxx_transport_functions.disable_target_scan = 1;
5755 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5756 }
5757
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 /* Derive version string. */
5759 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005760 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005761 strcat(qla2x00_version_str, "-debug");
5762
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005763 qla2xxx_transport_template =
5764 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005765 if (!qla2xxx_transport_template) {
5766 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005767 ql_log(ql_log_fatal, NULL, 0x0002,
5768 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005769 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005771 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005772
5773 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5774 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005775 ql_log(ql_log_fatal, NULL, 0x0003,
5776 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005777 }
5778
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005779 qla2xxx_transport_vport_template =
5780 fc_attach_transport(&qla2xxx_transport_vport_functions);
5781 if (!qla2xxx_transport_vport_template) {
5782 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005783 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005784 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005785 ql_log(ql_log_fatal, NULL, 0x0004,
5786 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005787 return -ENODEV;
5788 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005789 ql_log(ql_log_info, NULL, 0x0005,
5790 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005791 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005792 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005793 if (ret) {
5794 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005795 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005796 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005797 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005798 ql_log(ql_log_fatal, NULL, 0x0006,
5799 "pci_register_driver failed...ret=%d Failing load!.\n",
5800 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005801 }
5802 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803}
5804
5805/**
5806 * qla2x00_module_exit - Module cleanup.
5807 **/
5808static void __exit
5809qla2x00_module_exit(void)
5810{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005811 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005812 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005813 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005814 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005815 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005816 if (ctx_cachep)
5817 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005819 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005820}
5821
5822module_init(qla2x00_module_init);
5823module_exit(qla2x00_module_exit);
5824
5825MODULE_AUTHOR("QLogic Corporation");
5826MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5827MODULE_LICENSE("GPL");
5828MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005829MODULE_FIRMWARE(FW_FILE_ISP21XX);
5830MODULE_FIRMWARE(FW_FILE_ISP22XX);
5831MODULE_FIRMWARE(FW_FILE_ISP2300);
5832MODULE_FIRMWARE(FW_FILE_ISP2322);
5833MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005834MODULE_FIRMWARE(FW_FILE_ISP25XX);
Sawan Chandakf1458cd2015-04-09 14:59:59 -04005835MODULE_FIRMWARE(FW_FILE_ISP2031);
5836MODULE_FIRMWARE(FW_FILE_ISP8031);
5837MODULE_FIRMWARE(FW_FILE_ISP27XX);