blob: 0484acb3ff165e7e7e2090dae8c9090c450db695 [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
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500224int ql2xexlogins = 0;
225module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
226MODULE_PARM_DESC(ql2xexlogins,
227 "Number of extended Logins. "
228 "0 (Default)- Disabled.");
229
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500230int ql2xexchoffld = 0;
231module_param(ql2xexchoffld, uint, S_IRUGO|S_IWUSR);
232MODULE_PARM_DESC(ql2xexchoffld,
233 "Number of exchanges to offload. "
234 "0 (Default)- Disabled.");
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700237 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 */
239static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500240static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800241static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
242static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500243static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500244static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245static int qla2xxx_eh_abort(struct scsi_cmnd *);
246static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700247static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
249static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400251static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400252static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400253static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700254
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700255struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700257 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700258 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700259
260 .eh_abort_handler = qla2xxx_eh_abort,
261 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700262 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700263 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
264 .eh_host_reset_handler = qla2xxx_eh_host_reset,
265
266 .slave_configure = qla2xxx_slave_configure,
267
268 .slave_alloc = qla2xxx_slave_alloc,
269 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700270 .scan_finished = qla2xxx_scan_finished,
271 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100272 .change_queue_depth = scsi_change_queue_depth,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700273 .this_id = -1,
274 .cmd_per_lun = 3,
275 .use_clustering = ENABLE_CLUSTERING,
276 .sg_tablesize = SG_ALL,
277
278 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700279 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400280
281 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100282 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700283};
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700286struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288/* TODO Convert to inlines
289 *
290 * Timer routines
291 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700293__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800294qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800296 init_timer(&vha->timer);
297 vha->timer.expires = jiffies + interval * HZ;
298 vha->timer.data = (unsigned long)vha;
299 vha->timer.function = (void (*)(unsigned long))func;
300 add_timer(&vha->timer);
301 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
304static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800305qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700307 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700308 if (vha->device_flags & DFLG_DEV_FAILED) {
309 ql_dbg(ql_dbg_timer, vha, 0x600d,
310 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700311 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700312 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700313
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800314 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Adrian Bunka824ebb2008-01-17 09:02:15 -0800317static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800318qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800320 del_timer_sync(&vha->timer);
321 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324static int qla2x00_do_dpc(void *data);
325
326static void qla2x00_rst_aen(scsi_qla_host_t *);
327
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800328static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
329 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700330static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800331static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400334static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
335 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800336{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700337 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700338 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800339 GFP_KERNEL);
340 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700341 ql_log(ql_log_fatal, vha, 0x003b,
342 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800343 goto fail_req_map;
344 }
345
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700346 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800347 GFP_KERNEL);
348 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700349 ql_log(ql_log_fatal, vha, 0x003c,
350 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800351 goto fail_rsp_map;
352 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400353 /*
354 * Make sure we record at least the request and response queue zero in
355 * case we need to free them if part of the probe fails.
356 */
357 ha->rsp_q_map[0] = rsp;
358 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800359 set_bit(0, ha->rsp_qid_map);
360 set_bit(0, ha->req_qid_map);
361 return 1;
362
363fail_rsp_map:
364 kfree(ha->req_q_map);
365 ha->req_q_map = NULL;
366fail_req_map:
367 return -ENOMEM;
368}
369
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700370static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800371{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400372 if (IS_QLAFX00(ha)) {
373 if (req && req->ring_fx00)
374 dma_free_coherent(&ha->pdev->dev,
375 (req->length_fx00 + 1) * sizeof(request_t),
376 req->ring_fx00, req->dma_fx00);
377 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800378 dma_free_coherent(&ha->pdev->dev,
379 (req->length + 1) * sizeof(request_t),
380 req->ring, req->dma);
381
Chad Dupuis8d93f552013-01-30 03:34:37 -0500382 if (req)
383 kfree(req->outstanding_cmds);
384
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800385 kfree(req);
386 req = NULL;
387}
388
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700389static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
390{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400391 if (IS_QLAFX00(ha)) {
392 if (rsp && rsp->ring)
393 dma_free_coherent(&ha->pdev->dev,
394 (rsp->length_fx00 + 1) * sizeof(request_t),
395 rsp->ring_fx00, rsp->dma_fx00);
396 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700397 dma_free_coherent(&ha->pdev->dev,
398 (rsp->length + 1) * sizeof(response_t),
399 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400400 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700401 kfree(rsp);
402 rsp = NULL;
403}
404
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800405static void qla2x00_free_queues(struct qla_hw_data *ha)
406{
407 struct req_que *req;
408 struct rsp_que *rsp;
409 int cnt;
410
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700411 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800412 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700413 qla2x00_free_req_que(ha, req);
414 }
415 kfree(ha->req_q_map);
416 ha->req_q_map = NULL;
417
418 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
419 rsp = ha->rsp_q_map[cnt];
420 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800421 }
422 kfree(ha->rsp_q_map);
423 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800424}
425
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700426static int qla25xx_setup_mode(struct scsi_qla_host *vha)
427{
428 uint16_t options = 0;
429 int ques, req, ret;
430 struct qla_hw_data *ha = vha->hw;
431
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700432 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700433 ql_log(ql_log_warn, vha, 0x00d8,
434 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700435 goto fail;
436 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700437 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700438 /* create a request queue for IO */
439 options |= BIT_7;
440 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
441 QLA_DEFAULT_QUE_QOS);
442 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700443 ql_log(ql_log_warn, vha, 0x00e0,
444 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700445 goto fail;
446 }
Tejun Heo278274d2011-02-01 11:42:42 +0100447 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700448 vha->req = ha->req_q_map[req];
449 options |= BIT_1;
450 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
451 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
452 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700453 ql_log(ql_log_warn, vha, 0x00e8,
454 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700455 goto fail2;
456 }
457 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700458 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700459 ql_dbg(ql_dbg_multiq, vha, 0xc007,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100460 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700461 "no. of response queues:%d no. of request queues:%d.\n",
462 ha->max_rsp_queues, ha->max_req_queues);
463 ql_dbg(ql_dbg_init, vha, 0x00e9,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100464 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700465 "no. of response queues:%d no. of request queues:%d.\n",
466 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700467 }
468 return 0;
469fail2:
470 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700471 destroy_workqueue(ha->wq);
472 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800473 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700474fail:
475 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700476 kfree(ha->req_q_map);
477 kfree(ha->rsp_q_map);
478 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700479 return 1;
480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800485 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 static char *pci_bus_modes[] = {
487 "33", "66", "100", "133",
488 };
489 uint16_t pci_bus;
490
491 strcpy(str, "PCI");
492 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
493 if (pci_bus) {
494 strcat(str, "-X (");
495 strcat(str, pci_bus_modes[pci_bus]);
496 } else {
497 pci_bus = (ha->pci_attr & BIT_8) >> 8;
498 strcat(str, " (");
499 strcat(str, pci_bus_modes[pci_bus]);
500 }
501 strcat(str, " MHz)");
502
503 return (str);
504}
505
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700508{
509 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800510 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700511 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700512
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600513 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700514 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600515 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700516
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600517 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
518 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
519 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700520
521 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500522 switch (lspeed) {
523 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700524 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500525 break;
526 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700527 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500528 break;
529 case 3:
530 strcat(str, "8.0GT/s ");
531 break;
532 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700533 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500534 break;
535 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700536 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
537 strcat(str, lwstr);
538
539 return str;
540 }
541
542 strcpy(str, "PCI");
543 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
544 if (pci_bus == 0 || pci_bus == 8) {
545 strcat(str, " (");
546 strcat(str, pci_bus_modes[pci_bus >> 3]);
547 } else {
548 strcat(str, "-X ");
549 if (pci_bus & BIT_2)
550 strcat(str, "Mode 2");
551 else
552 strcat(str, "Mode 1");
553 strcat(str, " (");
554 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
555 }
556 strcat(str, " MHz)");
557
558 return str;
559}
560
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800561static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400562qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
564 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800565 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700566
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400567 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
568 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 if (ha->fw_attributes & BIT_9) {
571 strcat(str, "FLX");
572 return (str);
573 }
574
575 switch (ha->fw_attributes & 0xFF) {
576 case 0x7:
577 strcat(str, "EF");
578 break;
579 case 0x17:
580 strcat(str, "TP");
581 break;
582 case 0x37:
583 strcat(str, "IP");
584 break;
585 case 0x77:
586 strcat(str, "VI");
587 break;
588 default:
589 sprintf(un_str, "(%x)", ha->fw_attributes);
590 strcat(str, un_str);
591 break;
592 }
593 if (ha->fw_attributes & 0x100)
594 strcat(str, "X");
595
596 return (str);
597}
598
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800599static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400600qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700601{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800602 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700603
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400604 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800605 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700606 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700607}
608
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800609void
610qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800612 srb_t *sp = (srb_t *)ptr;
613 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
614 struct qla_hw_data *ha = sp->fcport->vha->hw;
615 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700616
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800617 if (sp->flags & SRB_DMA_VALID) {
618 scsi_dma_unmap(cmd);
619 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700620 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700621
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800622 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
623 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
624 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
625 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
626 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700627
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800628 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
629 /* List assured to be having elements */
Quinn Tranf83adb62014-04-11 16:54:43 -0400630 qla2x00_clean_dsd_pool(ha, sp, NULL);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800631 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
632 }
633
634 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
635 dma_pool_free(ha->dl_dma_pool, ctx,
636 ((struct crc_context *)ctx)->crc_ctx_dma);
637 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
638 }
639
640 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
641 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
642
643 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
644 ctx1->fcp_cmnd_dma);
645 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
646 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
647 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
648 mempool_free(ctx1, ha->ctx_mempool);
649 ctx1 = NULL;
650 }
651
652 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500653 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800654}
655
Fengguang Wu14b06802013-04-25 01:29:19 -0400656static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800657qla2x00_sp_compl(void *data, void *ptr, int res)
658{
659 struct qla_hw_data *ha = (struct qla_hw_data *)data;
660 srb_t *sp = (srb_t *)ptr;
661 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
662
663 cmd->result = res;
664
665 if (atomic_read(&sp->ref_count) == 0) {
666 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
667 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
668 sp, GET_CMD_SP(sp));
669 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400670 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800671 return;
672 }
673 if (!atomic_dec_and_test(&sp->ref_count))
674 return;
675
676 qla2x00_sp_free_dma(ha, sp);
677 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700678}
679
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400680/* If we are SP1 here, we need to still take and release the host_lock as SP1
681 * does not have the changes necessary to avoid taking host->host_lock.
682 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800684qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700685{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700686 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700687 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400688 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 struct qla_hw_data *ha = vha->hw;
690 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700691 srb_t *sp;
692 int rval;
693
Andrew Vasquez85880802009-12-15 21:29:46 -0800694 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700695 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400696 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700697 "PCI Channel IO permanent failure, exiting "
698 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700699 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700700 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400701 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700702 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800703 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700704 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700705 goto qc24_fail_command;
706 }
707
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400708 rval = fc_remote_port_chkready(rport);
709 if (rval) {
710 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400711 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700712 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
713 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700714 goto qc24_fail_command;
715 }
716
Arun Easibad75002010-05-04 15:01:30 -0700717 if (!vha->flags.difdix_supported &&
718 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700719 ql_dbg(ql_dbg_io, vha, 0x3004,
720 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
721 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700722 cmd->result = DID_NO_CONNECT << 16;
723 goto qc24_fail_command;
724 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800725
726 if (!fcport) {
727 cmd->result = DID_NO_CONNECT << 16;
728 goto qc24_fail_command;
729 }
730
Andrew Vasquezfca29702005-07-06 10:31:47 -0700731 if (atomic_read(&fcport->state) != FCS_ONLINE) {
732 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700733 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700734 ql_dbg(ql_dbg_io, vha, 0x3005,
735 "Returning DNC, fcport_state=%d loop_state=%d.\n",
736 atomic_read(&fcport->state),
737 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700738 cmd->result = DID_NO_CONNECT << 16;
739 goto qc24_fail_command;
740 }
Mike Christie7b594132008-08-17 15:24:40 -0500741 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700742 }
743
Chad Dupuise05fe292014-09-25 05:16:59 -0400744 /*
745 * Return target busy if we've received a non-zero retry_delay_timer
746 * in a FCP_RSP.
747 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100748 if (fcport->retry_delay_timestamp == 0) {
749 /* retry delay not set */
750 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400751 fcport->retry_delay_timestamp = 0;
752 else
753 goto qc24_target_busy;
754
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500755 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400756 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800757 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700758
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800759 sp->u.scmd.cmd = cmd;
760 sp->type = SRB_SCSI_CMD;
761 atomic_set(&sp->ref_count, 1);
762 CMD_SP(cmd) = (void *)sp;
763 sp->free = qla2x00_sp_free_dma;
764 sp->done = qla2x00_sp_compl;
765
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800766 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700767 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500768 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700769 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700770 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700771 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700772
Andrew Vasquezfca29702005-07-06 10:31:47 -0700773 return 0;
774
775qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800776 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700777
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800778qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700779 return SCSI_MLQUEUE_HOST_BUSY;
780
Mike Christie7b594132008-08-17 15:24:40 -0500781qc24_target_busy:
782 return SCSI_MLQUEUE_TARGET_BUSY;
783
Andrew Vasquezfca29702005-07-06 10:31:47 -0700784qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800785 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700786
787 return 0;
788}
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790/*
791 * qla2x00_eh_wait_on_command
792 * Waits for the command to be returned by the Firmware for some
793 * max time.
794 *
795 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 *
798 * Return:
799 * Not Found : 0
800 * Found : 1
801 */
802static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800803qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700805#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -0400806#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500807 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800808 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
809 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500810 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Andrew Vasquez85880802009-12-15 21:29:46 -0800812 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700813 ql_dbg(ql_dbg_taskm, vha, 0x8005,
814 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800815 return ret;
816 }
817
Lalit Chandivaded9704322009-08-25 11:36:18 -0700818 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700819 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500820 }
821 if (CMD_SP(cmd))
822 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
f4f051e2005-04-17 15:02:26 -0500824 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
827/*
828 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700829 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 * <= MAX_RETRIES_OF_ISP_ABORT or
831 * finally HBA is disabled ie marked offline
832 *
833 * Input:
834 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700835 *
836 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 * Does context switching-Release SPIN_LOCK
838 * (if any) before calling this routine.
839 *
840 * Return:
841 * Success (Adapter is online) : 0
842 * Failed (Adapter is offline/disabled) : 1
843 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800844int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800845qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700847 int return_status;
848 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800849 struct qla_hw_data *ha = vha->hw;
850 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700852 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800853 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
854 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
855 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
856 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 msleep(1000);
859 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700861 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 else
863 return_status = QLA_FUNCTION_FAILED;
864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return (return_status);
866}
867
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700868/*
Sawan Chandak638a1a02014-04-11 16:54:38 -0400869 * qla2x00_wait_for_hba_ready
870 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700871 *
872 * Input:
873 * ha - pointer to host adapter structure
874 *
875 * Note:
876 * Does context switching-Release SPIN_LOCK
877 * (if any) before calling this routine.
878 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700879 */
Sawan Chandak638a1a02014-04-11 16:54:38 -0400880static void
881qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700882{
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700883 struct qla_hw_data *ha = vha->hw;
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700884
Sawan Chandak9d35894d2014-09-25 05:16:52 -0400885 while (((qla2x00_reset_active(vha)) || ha->dpc_active ||
886 ha->flags.mbox_busy) ||
887 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
888 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags))
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700889 msleep(1000);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700890}
891
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700892int
893qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
894{
895 int return_status;
896 unsigned long wait_reset;
897 struct qla_hw_data *ha = vha->hw;
898 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
899
900 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
901 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
902 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
903 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
904 ha->dpc_active) && time_before(jiffies, wait_reset)) {
905
906 msleep(1000);
907
908 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
909 ha->flags.chip_reset_done)
910 break;
911 }
912 if (ha->flags.chip_reset_done)
913 return_status = QLA_SUCCESS;
914 else
915 return_status = QLA_FUNCTION_FAILED;
916
917 return return_status;
918}
919
Giridhar Malavali083a4692010-05-28 15:08:18 -0700920static void
921sp_get(struct srb *sp)
922{
923 atomic_inc(&sp->ref_count);
924}
925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926/**************************************************************************
927* qla2xxx_eh_abort
928*
929* Description:
930* The abort function will abort the specified command.
931*
932* Input:
933* cmd = Linux SCSI command packet to be aborted.
934*
935* Returns:
936* Either SUCCESS or FAILED.
937*
938* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700939* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800941static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942qla2xxx_eh_abort(struct scsi_cmnd *cmd)
943{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800944 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500945 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800946 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200947 unsigned int id;
948 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700949 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400950 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800951 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
f4f051e2005-04-17 15:02:26 -0500953 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700954 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800956 ret = fc_block_scsi_eh(cmd);
957 if (ret != 0)
958 return ret;
959 ret = SUCCESS;
960
f4f051e2005-04-17 15:02:26 -0500961 id = cmd->device->id;
962 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800964 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700965 sp = (srb_t *) CMD_SP(cmd);
966 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800967 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700968 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500969 }
Mike Christie170babc2010-10-15 11:27:47 -0700970
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700971 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -0400972 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
973 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -0700974
975 /* Get a reference to the sp and drop the lock.*/
976 sp_get(sp);
977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400979 rval = ha->isp_ops->abort_command(sp);
980 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -0400981 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400982 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -0400983 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400984 ret = FAILED;
985
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700986 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400987 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -0700988 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700989 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800990 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700991 wait = 1;
992 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700993
994 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800995 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700996 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500997
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700998 /* Did the command return during mailbox execution? */
999 if (ret == FAILED && !CMD_SP(cmd))
1000 ret = SUCCESS;
1001
f4f051e2005-04-17 15:02:26 -05001002 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001003 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001004 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001005 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001006 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001007 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001011 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001012 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001013 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
f4f051e2005-04-17 15:02:26 -05001015 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016}
1017
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001018int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001019qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001020 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001022 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001023 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001024 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001025 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001026 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001027 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Andrew Vasquez523ec772008-04-03 13:13:24 -07001029 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001030
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001031 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001032 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001033 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001034 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001035 sp = req->outstanding_cmds[cnt];
1036 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001037 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001038 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001039 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001040 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1041 continue;
1042 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001043 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001044 switch (type) {
1045 case WAIT_HOST:
1046 match = 1;
1047 break;
1048 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001049 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001050 break;
1051 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001052 match = (cmd->device->id == t &&
1053 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001054 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001056 if (!match)
1057 continue;
1058
1059 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001060 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001061 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001064
1065 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066}
1067
Andrew Vasquez523ec772008-04-03 13:13:24 -07001068static char *reset_errors[] = {
1069 "HBA not online",
1070 "HBA not ready",
1071 "Task management failed",
1072 "Waiting for command completions",
1073};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Andrew Vasquez523ec772008-04-03 13:13:24 -07001075static int
1076__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001077 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001078{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001080 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1081 int err;
1082
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001083 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001084 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001085 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001086
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001087 err = fc_block_scsi_eh(cmd);
1088 if (err != 0)
1089 return err;
1090
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001091 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001092 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001093 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001094
1095 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001096 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1097 ql_log(ql_log_warn, vha, 0x800a,
1098 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001099 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001100 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001101 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001102 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001103 != QLA_SUCCESS) {
1104 ql_log(ql_log_warn, vha, 0x800c,
1105 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001106 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001107 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001108 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001110 cmd->device->lun, type) != QLA_SUCCESS) {
1111 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001112 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001113 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001114 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001115
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001116 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001117 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001118 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001119
1120 return SUCCESS;
1121
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001122eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001123 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001124 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001125 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1126 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001127 return FAILED;
1128}
1129
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001130static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1132{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1134 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Andrew Vasquez523ec772008-04-03 13:13:24 -07001136 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1137 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138}
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001141qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001143 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1144 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Andrew Vasquez523ec772008-04-03 13:13:24 -07001146 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1147 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150/**************************************************************************
1151* qla2xxx_eh_bus_reset
1152*
1153* Description:
1154* The bus reset function will reset the bus and abort any executing
1155* commands.
1156*
1157* Input:
1158* cmd = Linux SCSI command packet of the command that cause the
1159* bus reset.
1160*
1161* Returns:
1162* SUCCESS/FAILURE (defined as macro in scsi.h).
1163*
1164**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001165static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1167{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001169 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001170 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001171 unsigned int id;
1172 uint64_t lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
f4f051e2005-04-17 15:02:26 -05001174 id = cmd->device->id;
1175 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001176
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001178 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001181 ret = fc_block_scsi_eh(cmd);
1182 if (ret != 0)
1183 return ret;
1184 ret = FAILED;
1185
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001186 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001187 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001190 ql_log(ql_log_fatal, vha, 0x8013,
1191 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001192 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 }
1194
Saurav Kashyapad5376892011-11-18 09:02:09 -08001195 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1196 ret = SUCCESS;
1197
f4f051e2005-04-17 15:02:26 -05001198 if (ret == FAILED)
1199 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001201 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001202 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001203 QLA_SUCCESS) {
1204 ql_log(ql_log_warn, vha, 0x8014,
1205 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001206 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
f4f051e2005-04-17 15:02:26 -05001209eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001210 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001211 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001212 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
f4f051e2005-04-17 15:02:26 -05001214 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
1217/**************************************************************************
1218* qla2xxx_eh_host_reset
1219*
1220* Description:
1221* The reset function will reset the Adapter.
1222*
1223* Input:
1224* cmd = Linux SCSI command packet of the command that cause the
1225* adapter reset.
1226*
1227* Returns:
1228* Either SUCCESS or FAILED.
1229*
1230* Note:
1231**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001232static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1234{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001237 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001238 unsigned int id;
1239 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001240 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
f4f051e2005-04-17 15:02:26 -05001242 id = cmd->device->id;
1243 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001244
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001245 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001246 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Chad Dupuis63ee7072014-04-11 16:54:46 -04001248 /*
1249 * No point in issuing another reset if one is active. Also do not
1250 * attempt a reset if we are updating flash.
1251 */
1252 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001253 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001255 if (vha != base_vha) {
1256 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001257 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001258 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001259 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001260 if (!qla82xx_fcoe_ctx_reset(vha)) {
1261 /* Ctx reset success */
1262 ret = SUCCESS;
1263 goto eh_host_reset_lock;
1264 }
1265 /* fall thru if ctx reset failed */
1266 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001267 if (ha->wq)
1268 flush_workqueue(ha->wq);
1269
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001271 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1273 /* failed. schedule dpc to try */
1274 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1275
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001276 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1277 ql_log(ql_log_warn, vha, 0x802a,
1278 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001280 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 }
1282 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001285 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001286 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001287 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001288 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
f4f051e2005-04-17 15:02:26 -05001290eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001291 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001292 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001293 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
f4f051e2005-04-17 15:02:26 -05001295 return ret;
1296}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298/*
1299* qla2x00_loop_reset
1300* Issue loop reset.
1301*
1302* Input:
1303* ha = adapter block pointer.
1304*
1305* Returns:
1306* 0 = success
1307*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001308int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001309qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001311 int ret;
bdf79622005-04-17 15:06:53 -05001312 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Armen Baloyan58547712013-08-27 01:37:33 -04001315 if (IS_QLAFX00(ha)) {
1316 return qlafx00_loop_reset(vha);
1317 }
1318
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001319 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001320 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1321 if (fcport->port_type != FCT_TARGET)
1322 continue;
1323
1324 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1325 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001326 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001327 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001328 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001329 }
1330 }
1331 }
1332
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001333
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001334 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001335 atomic_set(&vha->loop_state, LOOP_DOWN);
1336 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1337 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001338 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001339 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001340 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1341 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
1344
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001345 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001346 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001347 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001348 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1349 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001350 }
1351
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001355 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001358void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001360{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001361 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001362 unsigned long flags;
1363 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001364 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001365 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001366
Arun Easic0cb4492014-09-25 06:14:51 -04001367 qlt_host_reset_handler(ha);
1368
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001369 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001370 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001371 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001372 if (!req)
1373 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001374 if (!req->outstanding_cmds)
1375 continue;
1376 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001377 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001378 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001379 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001380 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001381 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001382 }
1383 }
1384 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1385}
1386
f4f051e2005-04-17 15:02:26 -05001387static int
1388qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389{
bdf79622005-04-17 15:06:53 -05001390 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001392 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001393 return -ENXIO;
1394
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001395 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001396
1397 return 0;
1398}
1399
1400static int
1401qla2xxx_slave_configure(struct scsi_device *sdev)
1402{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001404 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001405
Arun Easi9e522cd2012-08-22 14:21:31 -04001406 if (IS_T10_PI_CAPABLE(vha->hw))
1407 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1408
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001409 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001410 return 0;
1411}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
f4f051e2005-04-17 15:02:26 -05001413static void
1414qla2xxx_slave_destroy(struct scsi_device *sdev)
1415{
1416 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417}
1418
1419/**
1420 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1421 * @ha: HA context
1422 *
1423 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1424 * supported addressing method.
1425 */
1426static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001427qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001429 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Yang Hongyang6a355282009-04-06 19:01:13 -07001432 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001433 /* Any upper-dword bits set? */
1434 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001435 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001436 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001438 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1439 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001440 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001443
Yang Hongyang284901a2009-04-06 19:01:15 -07001444 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1445 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446}
1447
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001448static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001450{
1451 unsigned long flags = 0;
1452 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1453
1454 spin_lock_irqsave(&ha->hardware_lock, flags);
1455 ha->interrupts_on = 1;
1456 /* enable risc and host interrupts */
1457 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1458 RD_REG_WORD(&reg->ictrl);
1459 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1460
1461}
1462
1463static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001464qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001465{
1466 unsigned long flags = 0;
1467 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1468
1469 spin_lock_irqsave(&ha->hardware_lock, flags);
1470 ha->interrupts_on = 0;
1471 /* disable risc and host interrupts */
1472 WRT_REG_WORD(&reg->ictrl, 0);
1473 RD_REG_WORD(&reg->ictrl);
1474 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1475}
1476
1477static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001479{
1480 unsigned long flags = 0;
1481 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1482
1483 spin_lock_irqsave(&ha->hardware_lock, flags);
1484 ha->interrupts_on = 1;
1485 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1486 RD_REG_DWORD(&reg->ictrl);
1487 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1488}
1489
1490static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001492{
1493 unsigned long flags = 0;
1494 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1495
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001496 if (IS_NOPOLLING_TYPE(ha))
1497 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001498 spin_lock_irqsave(&ha->hardware_lock, flags);
1499 ha->interrupts_on = 0;
1500 WRT_REG_DWORD(&reg->ictrl, 0);
1501 RD_REG_DWORD(&reg->ictrl);
1502 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1503}
1504
Giridhar Malavali706f4572011-11-18 09:03:16 -08001505static int
1506qla2x00_iospace_config(struct qla_hw_data *ha)
1507{
1508 resource_size_t pio;
1509 uint16_t msix;
1510 int cpus;
1511
Giridhar Malavali706f4572011-11-18 09:03:16 -08001512 if (pci_request_selected_regions(ha->pdev, ha->bars,
1513 QLA2XXX_DRIVER_NAME)) {
1514 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1515 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1516 pci_name(ha->pdev));
1517 goto iospace_error_exit;
1518 }
1519 if (!(ha->bars & 1))
1520 goto skip_pio;
1521
1522 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1523 pio = pci_resource_start(ha->pdev, 0);
1524 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1525 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1526 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1527 "Invalid pci I/O region size (%s).\n",
1528 pci_name(ha->pdev));
1529 pio = 0;
1530 }
1531 } else {
1532 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1533 "Region #0 no a PIO resource (%s).\n",
1534 pci_name(ha->pdev));
1535 pio = 0;
1536 }
1537 ha->pio_address = pio;
1538 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1539 "PIO address=%llu.\n",
1540 (unsigned long long)ha->pio_address);
1541
1542skip_pio:
1543 /* Use MMIO operations for all accesses. */
1544 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1545 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1546 "Region #1 not an MMIO resource (%s), aborting.\n",
1547 pci_name(ha->pdev));
1548 goto iospace_error_exit;
1549 }
1550 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1551 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1552 "Invalid PCI mem region size (%s), aborting.\n",
1553 pci_name(ha->pdev));
1554 goto iospace_error_exit;
1555 }
1556
1557 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1558 if (!ha->iobase) {
1559 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1560 "Cannot remap MMIO (%s), aborting.\n",
1561 pci_name(ha->pdev));
1562 goto iospace_error_exit;
1563 }
1564
1565 /* Determine queue resources */
1566 ha->max_req_queues = ha->max_rsp_queues = 1;
1567 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1568 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1569 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1570 goto mqiobase_exit;
1571
1572 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1573 pci_resource_len(ha->pdev, 3));
1574 if (ha->mqiobase) {
1575 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1576 "MQIO Base=%p.\n", ha->mqiobase);
1577 /* Read MSIX vector size of the board */
1578 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1579 ha->msix_count = msix;
1580 /* Max queues are bounded by available msix vectors */
1581 /* queue 0 uses two msix vectors */
1582 if (ql2xmultique_tag) {
1583 cpus = num_online_cpus();
1584 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1585 (cpus + 1) : (ha->msix_count - 1);
1586 ha->max_req_queues = 2;
1587 } else if (ql2xmaxqueues > 1) {
1588 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1589 QLA_MQ_SIZE : ql2xmaxqueues;
1590 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1591 "QoS mode set, max no of request queues:%d.\n",
1592 ha->max_req_queues);
1593 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1594 "QoS mode set, max no of request queues:%d.\n",
1595 ha->max_req_queues);
1596 }
1597 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1598 "MSI-X vector count: %d.\n", msix);
1599 } else
1600 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1601 "BAR 3 not enabled.\n");
1602
1603mqiobase_exit:
1604 ha->msix_count = ha->max_rsp_queues + 1;
1605 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1606 "MSIX Count:%d.\n", ha->msix_count);
1607 return (0);
1608
1609iospace_error_exit:
1610 return (-ENOMEM);
1611}
1612
1613
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001614static int
1615qla83xx_iospace_config(struct qla_hw_data *ha)
1616{
1617 uint16_t msix;
1618 int cpus;
1619
1620 if (pci_request_selected_regions(ha->pdev, ha->bars,
1621 QLA2XXX_DRIVER_NAME)) {
1622 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1623 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1624 pci_name(ha->pdev));
1625
1626 goto iospace_error_exit;
1627 }
1628
1629 /* Use MMIO operations for all accesses. */
1630 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1631 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1632 "Invalid pci I/O region size (%s).\n",
1633 pci_name(ha->pdev));
1634 goto iospace_error_exit;
1635 }
1636 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1637 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1638 "Invalid PCI mem region size (%s), aborting\n",
1639 pci_name(ha->pdev));
1640 goto iospace_error_exit;
1641 }
1642
1643 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1644 if (!ha->iobase) {
1645 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1646 "Cannot remap MMIO (%s), aborting.\n",
1647 pci_name(ha->pdev));
1648 goto iospace_error_exit;
1649 }
1650
1651 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1652 /* 83XX 26XX always use MQ type access for queues
1653 * - mbar 2, a.k.a region 4 */
1654 ha->max_req_queues = ha->max_rsp_queues = 1;
1655 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1656 pci_resource_len(ha->pdev, 4));
1657
1658 if (!ha->mqiobase) {
1659 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1660 "BAR2/region4 not enabled\n");
1661 goto mqiobase_exit;
1662 }
1663
1664 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1665 pci_resource_len(ha->pdev, 2));
1666 if (ha->msixbase) {
1667 /* Read MSIX vector size of the board */
1668 pci_read_config_word(ha->pdev,
1669 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1670 ha->msix_count = msix;
1671 /* Max queues are bounded by available msix vectors */
1672 /* queue 0 uses two msix vectors */
1673 if (ql2xmultique_tag) {
1674 cpus = num_online_cpus();
1675 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1676 (cpus + 1) : (ha->msix_count - 1);
1677 ha->max_req_queues = 2;
1678 } else if (ql2xmaxqueues > 1) {
1679 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1680 QLA_MQ_SIZE : ql2xmaxqueues;
1681 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1682 "QoS mode set, max no of request queues:%d.\n",
1683 ha->max_req_queues);
1684 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1685 "QoS mode set, max no of request queues:%d.\n",
1686 ha->max_req_queues);
1687 }
1688 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1689 "MSI-X vector count: %d.\n", msix);
1690 } else
1691 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1692 "BAR 1 not enabled.\n");
1693
1694mqiobase_exit:
1695 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001696
1697 qlt_83xx_iospace_config(ha);
1698
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001699 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1700 "MSIX Count:%d.\n", ha->msix_count);
1701 return 0;
1702
1703iospace_error_exit:
1704 return -ENOMEM;
1705}
1706
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001707static struct isp_operations qla2100_isp_ops = {
1708 .pci_config = qla2100_pci_config,
1709 .reset_chip = qla2x00_reset_chip,
1710 .chip_diag = qla2x00_chip_diag,
1711 .config_rings = qla2x00_config_rings,
1712 .reset_adapter = qla2x00_reset_adapter,
1713 .nvram_config = qla2x00_nvram_config,
1714 .update_fw_options = qla2x00_update_fw_options,
1715 .load_risc = qla2x00_load_risc,
1716 .pci_info_str = qla2x00_pci_info_str,
1717 .fw_version_str = qla2x00_fw_version_str,
1718 .intr_handler = qla2100_intr_handler,
1719 .enable_intrs = qla2x00_enable_intrs,
1720 .disable_intrs = qla2x00_disable_intrs,
1721 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001722 .target_reset = qla2x00_abort_target,
1723 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001724 .fabric_login = qla2x00_login_fabric,
1725 .fabric_logout = qla2x00_fabric_logout,
1726 .calc_req_entries = qla2x00_calc_iocbs_32,
1727 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1728 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1729 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1730 .read_nvram = qla2x00_read_nvram_data,
1731 .write_nvram = qla2x00_write_nvram_data,
1732 .fw_dump = qla2100_fw_dump,
1733 .beacon_on = NULL,
1734 .beacon_off = NULL,
1735 .beacon_blink = NULL,
1736 .read_optrom = qla2x00_read_optrom_data,
1737 .write_optrom = qla2x00_write_optrom_data,
1738 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001739 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001740 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001741 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001742 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001743};
1744
1745static struct isp_operations qla2300_isp_ops = {
1746 .pci_config = qla2300_pci_config,
1747 .reset_chip = qla2x00_reset_chip,
1748 .chip_diag = qla2x00_chip_diag,
1749 .config_rings = qla2x00_config_rings,
1750 .reset_adapter = qla2x00_reset_adapter,
1751 .nvram_config = qla2x00_nvram_config,
1752 .update_fw_options = qla2x00_update_fw_options,
1753 .load_risc = qla2x00_load_risc,
1754 .pci_info_str = qla2x00_pci_info_str,
1755 .fw_version_str = qla2x00_fw_version_str,
1756 .intr_handler = qla2300_intr_handler,
1757 .enable_intrs = qla2x00_enable_intrs,
1758 .disable_intrs = qla2x00_disable_intrs,
1759 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001760 .target_reset = qla2x00_abort_target,
1761 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001762 .fabric_login = qla2x00_login_fabric,
1763 .fabric_logout = qla2x00_fabric_logout,
1764 .calc_req_entries = qla2x00_calc_iocbs_32,
1765 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1766 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1767 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1768 .read_nvram = qla2x00_read_nvram_data,
1769 .write_nvram = qla2x00_write_nvram_data,
1770 .fw_dump = qla2300_fw_dump,
1771 .beacon_on = qla2x00_beacon_on,
1772 .beacon_off = qla2x00_beacon_off,
1773 .beacon_blink = qla2x00_beacon_blink,
1774 .read_optrom = qla2x00_read_optrom_data,
1775 .write_optrom = qla2x00_write_optrom_data,
1776 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001777 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001778 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001779 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001780 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001781};
1782
1783static struct isp_operations qla24xx_isp_ops = {
1784 .pci_config = qla24xx_pci_config,
1785 .reset_chip = qla24xx_reset_chip,
1786 .chip_diag = qla24xx_chip_diag,
1787 .config_rings = qla24xx_config_rings,
1788 .reset_adapter = qla24xx_reset_adapter,
1789 .nvram_config = qla24xx_nvram_config,
1790 .update_fw_options = qla24xx_update_fw_options,
1791 .load_risc = qla24xx_load_risc,
1792 .pci_info_str = qla24xx_pci_info_str,
1793 .fw_version_str = qla24xx_fw_version_str,
1794 .intr_handler = qla24xx_intr_handler,
1795 .enable_intrs = qla24xx_enable_intrs,
1796 .disable_intrs = qla24xx_disable_intrs,
1797 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001798 .target_reset = qla24xx_abort_target,
1799 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001800 .fabric_login = qla24xx_login_fabric,
1801 .fabric_logout = qla24xx_fabric_logout,
1802 .calc_req_entries = NULL,
1803 .build_iocbs = NULL,
1804 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1805 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1806 .read_nvram = qla24xx_read_nvram_data,
1807 .write_nvram = qla24xx_write_nvram_data,
1808 .fw_dump = qla24xx_fw_dump,
1809 .beacon_on = qla24xx_beacon_on,
1810 .beacon_off = qla24xx_beacon_off,
1811 .beacon_blink = qla24xx_beacon_blink,
1812 .read_optrom = qla24xx_read_optrom_data,
1813 .write_optrom = qla24xx_write_optrom_data,
1814 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001815 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001816 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001817 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001818 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001819};
1820
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001821static struct isp_operations qla25xx_isp_ops = {
1822 .pci_config = qla25xx_pci_config,
1823 .reset_chip = qla24xx_reset_chip,
1824 .chip_diag = qla24xx_chip_diag,
1825 .config_rings = qla24xx_config_rings,
1826 .reset_adapter = qla24xx_reset_adapter,
1827 .nvram_config = qla24xx_nvram_config,
1828 .update_fw_options = qla24xx_update_fw_options,
1829 .load_risc = qla24xx_load_risc,
1830 .pci_info_str = qla24xx_pci_info_str,
1831 .fw_version_str = qla24xx_fw_version_str,
1832 .intr_handler = qla24xx_intr_handler,
1833 .enable_intrs = qla24xx_enable_intrs,
1834 .disable_intrs = qla24xx_disable_intrs,
1835 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001836 .target_reset = qla24xx_abort_target,
1837 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001838 .fabric_login = qla24xx_login_fabric,
1839 .fabric_logout = qla24xx_fabric_logout,
1840 .calc_req_entries = NULL,
1841 .build_iocbs = NULL,
1842 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1843 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1844 .read_nvram = qla25xx_read_nvram_data,
1845 .write_nvram = qla25xx_write_nvram_data,
1846 .fw_dump = qla25xx_fw_dump,
1847 .beacon_on = qla24xx_beacon_on,
1848 .beacon_off = qla24xx_beacon_off,
1849 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001850 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001851 .write_optrom = qla24xx_write_optrom_data,
1852 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001853 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001854 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001855 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001856 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001857};
1858
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001859static struct isp_operations qla81xx_isp_ops = {
1860 .pci_config = qla25xx_pci_config,
1861 .reset_chip = qla24xx_reset_chip,
1862 .chip_diag = qla24xx_chip_diag,
1863 .config_rings = qla24xx_config_rings,
1864 .reset_adapter = qla24xx_reset_adapter,
1865 .nvram_config = qla81xx_nvram_config,
1866 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001867 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001868 .pci_info_str = qla24xx_pci_info_str,
1869 .fw_version_str = qla24xx_fw_version_str,
1870 .intr_handler = qla24xx_intr_handler,
1871 .enable_intrs = qla24xx_enable_intrs,
1872 .disable_intrs = qla24xx_disable_intrs,
1873 .abort_command = qla24xx_abort_command,
1874 .target_reset = qla24xx_abort_target,
1875 .lun_reset = qla24xx_lun_reset,
1876 .fabric_login = qla24xx_login_fabric,
1877 .fabric_logout = qla24xx_fabric_logout,
1878 .calc_req_entries = NULL,
1879 .build_iocbs = NULL,
1880 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1881 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001882 .read_nvram = NULL,
1883 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001884 .fw_dump = qla81xx_fw_dump,
1885 .beacon_on = qla24xx_beacon_on,
1886 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001887 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001888 .read_optrom = qla25xx_read_optrom_data,
1889 .write_optrom = qla24xx_write_optrom_data,
1890 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001891 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001892 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001893 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001894 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001895};
1896
1897static struct isp_operations qla82xx_isp_ops = {
1898 .pci_config = qla82xx_pci_config,
1899 .reset_chip = qla82xx_reset_chip,
1900 .chip_diag = qla24xx_chip_diag,
1901 .config_rings = qla82xx_config_rings,
1902 .reset_adapter = qla24xx_reset_adapter,
1903 .nvram_config = qla81xx_nvram_config,
1904 .update_fw_options = qla24xx_update_fw_options,
1905 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001906 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001907 .fw_version_str = qla24xx_fw_version_str,
1908 .intr_handler = qla82xx_intr_handler,
1909 .enable_intrs = qla82xx_enable_intrs,
1910 .disable_intrs = qla82xx_disable_intrs,
1911 .abort_command = qla24xx_abort_command,
1912 .target_reset = qla24xx_abort_target,
1913 .lun_reset = qla24xx_lun_reset,
1914 .fabric_login = qla24xx_login_fabric,
1915 .fabric_logout = qla24xx_fabric_logout,
1916 .calc_req_entries = NULL,
1917 .build_iocbs = NULL,
1918 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1919 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1920 .read_nvram = qla24xx_read_nvram_data,
1921 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001922 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001923 .beacon_on = qla82xx_beacon_on,
1924 .beacon_off = qla82xx_beacon_off,
1925 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001926 .read_optrom = qla82xx_read_optrom_data,
1927 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001928 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001929 .start_scsi = qla82xx_start_scsi,
1930 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001931 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001932 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001933};
1934
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001935static struct isp_operations qla8044_isp_ops = {
1936 .pci_config = qla82xx_pci_config,
1937 .reset_chip = qla82xx_reset_chip,
1938 .chip_diag = qla24xx_chip_diag,
1939 .config_rings = qla82xx_config_rings,
1940 .reset_adapter = qla24xx_reset_adapter,
1941 .nvram_config = qla81xx_nvram_config,
1942 .update_fw_options = qla24xx_update_fw_options,
1943 .load_risc = qla82xx_load_risc,
1944 .pci_info_str = qla24xx_pci_info_str,
1945 .fw_version_str = qla24xx_fw_version_str,
1946 .intr_handler = qla8044_intr_handler,
1947 .enable_intrs = qla82xx_enable_intrs,
1948 .disable_intrs = qla82xx_disable_intrs,
1949 .abort_command = qla24xx_abort_command,
1950 .target_reset = qla24xx_abort_target,
1951 .lun_reset = qla24xx_lun_reset,
1952 .fabric_login = qla24xx_login_fabric,
1953 .fabric_logout = qla24xx_fabric_logout,
1954 .calc_req_entries = NULL,
1955 .build_iocbs = NULL,
1956 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1957 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1958 .read_nvram = NULL,
1959 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001960 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001961 .beacon_on = qla82xx_beacon_on,
1962 .beacon_off = qla82xx_beacon_off,
1963 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05001964 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001965 .write_optrom = qla8044_write_optrom_data,
1966 .get_flash_version = qla82xx_get_flash_version,
1967 .start_scsi = qla82xx_start_scsi,
1968 .abort_isp = qla8044_abort_isp,
1969 .iospace_config = qla82xx_iospace_config,
1970 .initialize_adapter = qla2x00_initialize_adapter,
1971};
1972
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001973static struct isp_operations qla83xx_isp_ops = {
1974 .pci_config = qla25xx_pci_config,
1975 .reset_chip = qla24xx_reset_chip,
1976 .chip_diag = qla24xx_chip_diag,
1977 .config_rings = qla24xx_config_rings,
1978 .reset_adapter = qla24xx_reset_adapter,
1979 .nvram_config = qla81xx_nvram_config,
1980 .update_fw_options = qla81xx_update_fw_options,
1981 .load_risc = qla81xx_load_risc,
1982 .pci_info_str = qla24xx_pci_info_str,
1983 .fw_version_str = qla24xx_fw_version_str,
1984 .intr_handler = qla24xx_intr_handler,
1985 .enable_intrs = qla24xx_enable_intrs,
1986 .disable_intrs = qla24xx_disable_intrs,
1987 .abort_command = qla24xx_abort_command,
1988 .target_reset = qla24xx_abort_target,
1989 .lun_reset = qla24xx_lun_reset,
1990 .fabric_login = qla24xx_login_fabric,
1991 .fabric_logout = qla24xx_fabric_logout,
1992 .calc_req_entries = NULL,
1993 .build_iocbs = NULL,
1994 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1995 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1996 .read_nvram = NULL,
1997 .write_nvram = NULL,
1998 .fw_dump = qla83xx_fw_dump,
1999 .beacon_on = qla24xx_beacon_on,
2000 .beacon_off = qla24xx_beacon_off,
2001 .beacon_blink = qla83xx_beacon_blink,
2002 .read_optrom = qla25xx_read_optrom_data,
2003 .write_optrom = qla24xx_write_optrom_data,
2004 .get_flash_version = qla24xx_get_flash_version,
2005 .start_scsi = qla24xx_dif_start_scsi,
2006 .abort_isp = qla2x00_abort_isp,
2007 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002008 .initialize_adapter = qla2x00_initialize_adapter,
2009};
2010
2011static struct isp_operations qlafx00_isp_ops = {
2012 .pci_config = qlafx00_pci_config,
2013 .reset_chip = qlafx00_soft_reset,
2014 .chip_diag = qlafx00_chip_diag,
2015 .config_rings = qlafx00_config_rings,
2016 .reset_adapter = qlafx00_soft_reset,
2017 .nvram_config = NULL,
2018 .update_fw_options = NULL,
2019 .load_risc = NULL,
2020 .pci_info_str = qlafx00_pci_info_str,
2021 .fw_version_str = qlafx00_fw_version_str,
2022 .intr_handler = qlafx00_intr_handler,
2023 .enable_intrs = qlafx00_enable_intrs,
2024 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002025 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002026 .target_reset = qlafx00_abort_target,
2027 .lun_reset = qlafx00_lun_reset,
2028 .fabric_login = NULL,
2029 .fabric_logout = NULL,
2030 .calc_req_entries = NULL,
2031 .build_iocbs = NULL,
2032 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2033 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2034 .read_nvram = qla24xx_read_nvram_data,
2035 .write_nvram = qla24xx_write_nvram_data,
2036 .fw_dump = NULL,
2037 .beacon_on = qla24xx_beacon_on,
2038 .beacon_off = qla24xx_beacon_off,
2039 .beacon_blink = NULL,
2040 .read_optrom = qla24xx_read_optrom_data,
2041 .write_optrom = qla24xx_write_optrom_data,
2042 .get_flash_version = qla24xx_get_flash_version,
2043 .start_scsi = qlafx00_start_scsi,
2044 .abort_isp = qlafx00_abort_isp,
2045 .iospace_config = qlafx00_iospace_config,
2046 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002047};
2048
Chad Dupuisf73cb692014-02-26 04:15:06 -05002049static struct isp_operations qla27xx_isp_ops = {
2050 .pci_config = qla25xx_pci_config,
2051 .reset_chip = qla24xx_reset_chip,
2052 .chip_diag = qla24xx_chip_diag,
2053 .config_rings = qla24xx_config_rings,
2054 .reset_adapter = qla24xx_reset_adapter,
2055 .nvram_config = qla81xx_nvram_config,
2056 .update_fw_options = qla81xx_update_fw_options,
2057 .load_risc = qla81xx_load_risc,
2058 .pci_info_str = qla24xx_pci_info_str,
2059 .fw_version_str = qla24xx_fw_version_str,
2060 .intr_handler = qla24xx_intr_handler,
2061 .enable_intrs = qla24xx_enable_intrs,
2062 .disable_intrs = qla24xx_disable_intrs,
2063 .abort_command = qla24xx_abort_command,
2064 .target_reset = qla24xx_abort_target,
2065 .lun_reset = qla24xx_lun_reset,
2066 .fabric_login = qla24xx_login_fabric,
2067 .fabric_logout = qla24xx_fabric_logout,
2068 .calc_req_entries = NULL,
2069 .build_iocbs = NULL,
2070 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2071 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2072 .read_nvram = NULL,
2073 .write_nvram = NULL,
2074 .fw_dump = qla27xx_fwdump,
2075 .beacon_on = qla24xx_beacon_on,
2076 .beacon_off = qla24xx_beacon_off,
2077 .beacon_blink = qla83xx_beacon_blink,
2078 .read_optrom = qla25xx_read_optrom_data,
2079 .write_optrom = qla24xx_write_optrom_data,
2080 .get_flash_version = qla24xx_get_flash_version,
2081 .start_scsi = qla24xx_dif_start_scsi,
2082 .abort_isp = qla2x00_abort_isp,
2083 .iospace_config = qla83xx_iospace_config,
2084 .initialize_adapter = qla2x00_initialize_adapter,
2085};
2086
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002087static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002089{
2090 ha->device_type = DT_EXTENDED_IDS;
2091 switch (ha->pdev->device) {
2092 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2093 ha->device_type |= DT_ISP2100;
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_ISP2200:
2098 ha->device_type |= DT_ISP2200;
2099 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002100 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002101 break;
2102 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2103 ha->device_type |= DT_ISP2300;
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_ISP2312:
2108 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002109 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002110 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002111 break;
2112 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2113 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002114 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002115 if (ha->pdev->subsystem_vendor == 0x1028 &&
2116 ha->pdev->subsystem_device == 0x0170)
2117 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002118 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002119 break;
2120 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2121 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002122 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002123 break;
2124 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2125 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002126 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002127 break;
2128 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2129 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002130 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002131 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002132 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002133 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002134 break;
2135 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2136 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002137 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002138 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002139 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002140 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002141 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002142 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2143 ha->device_type |= DT_ISP8432;
2144 ha->device_type |= DT_ZIO_SUPPORTED;
2145 ha->device_type |= DT_FWI2;
2146 ha->device_type |= DT_IIDMA;
2147 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2148 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002149 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2150 ha->device_type |= DT_ISP5422;
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.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002154 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2155 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002156 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002157 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002158 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002159 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2160 ha->device_type |= DT_ISP2532;
2161 ha->device_type |= DT_ZIO_SUPPORTED;
2162 ha->device_type |= DT_FWI2;
2163 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002164 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2165 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002166 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2167 ha->device_type |= DT_ISP8001;
2168 ha->device_type |= DT_ZIO_SUPPORTED;
2169 ha->device_type |= DT_FWI2;
2170 ha->device_type |= DT_IIDMA;
2171 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2172 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002173 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2174 ha->device_type |= DT_ISP8021;
2175 ha->device_type |= DT_ZIO_SUPPORTED;
2176 ha->device_type |= DT_FWI2;
2177 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2178 /* Initialize 82XX ISP flags */
2179 qla82xx_init_flags(ha);
2180 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002181 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2182 ha->device_type |= DT_ISP8044;
2183 ha->device_type |= DT_ZIO_SUPPORTED;
2184 ha->device_type |= DT_FWI2;
2185 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2186 /* Initialize 82XX ISP flags */
2187 qla82xx_init_flags(ha);
2188 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002189 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2190 ha->device_type |= DT_ISP2031;
2191 ha->device_type |= DT_ZIO_SUPPORTED;
2192 ha->device_type |= DT_FWI2;
2193 ha->device_type |= DT_IIDMA;
2194 ha->device_type |= DT_T10_PI;
2195 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2196 break;
2197 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2198 ha->device_type |= DT_ISP8031;
2199 ha->device_type |= DT_ZIO_SUPPORTED;
2200 ha->device_type |= DT_FWI2;
2201 ha->device_type |= DT_IIDMA;
2202 ha->device_type |= DT_T10_PI;
2203 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2204 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002205 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2206 ha->device_type |= DT_ISPFX00;
2207 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002208 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2209 ha->device_type |= DT_ISP2071;
2210 ha->device_type |= DT_ZIO_SUPPORTED;
2211 ha->device_type |= DT_FWI2;
2212 ha->device_type |= DT_IIDMA;
2213 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2214 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002215 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2216 ha->device_type |= DT_ISP2271;
2217 ha->device_type |= DT_ZIO_SUPPORTED;
2218 ha->device_type |= DT_FWI2;
2219 ha->device_type |= DT_IIDMA;
2220 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2221 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002222 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2223 ha->device_type |= DT_ISP2261;
2224 ha->device_type |= DT_ZIO_SUPPORTED;
2225 ha->device_type |= DT_FWI2;
2226 ha->device_type |= DT_IIDMA;
2227 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2228 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002229 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002230
Giridhar Malavalia9083012010-04-12 17:59:55 -07002231 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002232 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002233 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002234 /* Get adapter physical port no from interrupt pin register. */
2235 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002236 if (IS_QLA27XX(ha))
2237 ha->port_no--;
2238 else
2239 ha->port_no = !(ha->port_no & 1);
2240 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002241
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002242 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002243 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002244 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002245}
2246
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002247static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002248qla2xxx_scan_start(struct Scsi_Host *shost)
2249{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002251
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002252 if (vha->hw->flags.running_gold_fw)
2253 return;
2254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002255 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2256 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2257 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2258 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002259}
2260
2261static int
2262qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2263{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002264 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002267 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002269 return 1;
2270
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002272}
2273
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274/*
2275 * PCI driver interface
2276 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002277static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002278qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002280 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 scsi_qla_host_t *base_vha = NULL;
2283 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002284 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002285 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002286 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002287 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002289 struct req_que *req = NULL;
2290 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002291 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002292 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002293 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2294 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002295 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002296 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2297 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002298 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002299 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002300 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2301 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002302 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002303 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002304 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002305 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002306 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2307 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002308 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002309 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002310 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2311 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002312 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002313 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2314 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002315
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002316 if (mem_only) {
2317 if (pci_enable_device_mem(pdev))
2318 goto probe_out;
2319 } else {
2320 if (pci_enable_device(pdev))
2321 goto probe_out;
2322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
Jesse Barnes09276782008-10-18 17:33:19 -07002324 /* This may fail but that's ok */
2325 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002326
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2328 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002329 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2330 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002333 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2334 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002336 ha->tgt.enable_class_2 = ql2xenableclass2;
Quinn Tran33e79972014-09-25 06:14:55 -04002337 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2338 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002339 spin_lock_init(&ha->tgt.sess_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
2341 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002342 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002343 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002344 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002345 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002346 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002347 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002349 /* Set ISP-type information. */
2350 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002351
2352 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002353 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002354 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002355 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002356
Chad Dupuiscba1e472011-11-18 09:03:21 -08002357 ha->prev_topology = 0;
2358 ha->init_cb_size = sizeof(init_cb_t);
2359 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2360 ha->optrom_size = OPTROM_SIZE_2300;
2361
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002362 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002364 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 req_length = REQUEST_ENTRY_CNT_2100;
2367 rsp_length = RESPONSE_ENTRY_CNT_2100;
2368 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002369 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002370 ha->flash_conf_off = ~0;
2371 ha->flash_data_off = ~0;
2372 ha->nvram_conf_off = ~0;
2373 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002374 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002376 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002377 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 req_length = REQUEST_ENTRY_CNT_2200;
2379 rsp_length = RESPONSE_ENTRY_CNT_2100;
2380 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002381 ha->gid_list_info_size = 4;
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 = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002387 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002388 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 req_length = REQUEST_ENTRY_CNT_2200;
2391 rsp_length = RESPONSE_ENTRY_CNT_2300;
2392 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002393 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002394 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2395 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002396 ha->flash_conf_off = ~0;
2397 ha->flash_data_off = ~0;
2398 ha->nvram_conf_off = ~0;
2399 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002400 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002401 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002402 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002403 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002404 req_length = REQUEST_ENTRY_CNT_24XX;
2405 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002406 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002408 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002409 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002410 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002411 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002412 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002413 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2414 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2415 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2416 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002417 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002418 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002419 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420 req_length = REQUEST_ENTRY_CNT_24XX;
2421 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002422 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002423 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002424 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002425 ha->gid_list_info_size = 8;
2426 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002427 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002428 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002429 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2430 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2431 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2432 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2433 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002434 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002435 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2436 req_length = REQUEST_ENTRY_CNT_24XX;
2437 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002438 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002439 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2440 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2441 ha->gid_list_info_size = 8;
2442 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002443 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002444 ha->isp_ops = &qla81xx_isp_ops;
2445 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2446 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2447 ha->nvram_conf_off = ~0;
2448 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002449 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002450 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002451 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2452 req_length = REQUEST_ENTRY_CNT_82XX;
2453 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2454 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2455 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2456 ha->gid_list_info_size = 8;
2457 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002458 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002459 ha->isp_ops = &qla82xx_isp_ops;
2460 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2461 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2462 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2463 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002464 } else if (IS_QLA8044(ha)) {
2465 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2466 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2467 req_length = REQUEST_ENTRY_CNT_82XX;
2468 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2469 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2470 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2471 ha->gid_list_info_size = 8;
2472 ha->optrom_size = OPTROM_SIZE_83XX;
2473 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2474 ha->isp_ops = &qla8044_isp_ops;
2475 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2476 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2477 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2478 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002479 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002480 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002481 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002482 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002483 req_length = REQUEST_ENTRY_CNT_83XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002484 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002485 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002486 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2487 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2488 ha->gid_list_info_size = 8;
2489 ha->optrom_size = OPTROM_SIZE_83XX;
2490 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2491 ha->isp_ops = &qla83xx_isp_ops;
2492 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2493 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2494 ha->nvram_conf_off = ~0;
2495 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002496 } else if (IS_QLAFX00(ha)) {
2497 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2498 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2499 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2500 req_length = REQUEST_ENTRY_CNT_FX00;
2501 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002502 ha->isp_ops = &qlafx00_isp_ops;
2503 ha->port_down_retry_count = 30; /* default value */
2504 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2505 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002506 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002507 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002508 ha->mr.host_info_resend = false;
2509 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002510 } else if (IS_QLA27XX(ha)) {
2511 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2512 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2513 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2514 req_length = REQUEST_ENTRY_CNT_24XX;
2515 rsp_length = RESPONSE_ENTRY_CNT_2300;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002516 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002517 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2518 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2519 ha->gid_list_info_size = 8;
2520 ha->optrom_size = OPTROM_SIZE_83XX;
2521 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2522 ha->isp_ops = &qla27xx_isp_ops;
2523 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2524 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2525 ha->nvram_conf_off = ~0;
2526 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002528
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002529 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2530 "mbx_count=%d, req_length=%d, "
2531 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002532 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2533 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002534 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2535 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002536 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002537 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2538 "isp_ops=%p, flash_conf_off=%d, "
2539 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2540 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2541 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002542
2543 /* Configure PCI I/O space */
2544 ret = ha->isp_ops->iospace_config(ha);
2545 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002546 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002547
2548 ql_log_pci(ql_log_info, pdev, 0x001d,
2549 "Found an ISP%04X irq %d iobase 0x%p.\n",
2550 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002551 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002552 init_completion(&ha->mbx_cmd_comp);
2553 complete(&ha->mbx_cmd_comp);
2554 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002555 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002556 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002558 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Andrew Vasquez53303c42009-01-22 09:45:37 -08002560 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002561 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2562 "64 Bit addressing is %s.\n",
2563 ha->flags.enable_64bit_addressing ? "enable" :
2564 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002565 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002566 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002567 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2568 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 goto probe_hw_failed;
2571 }
2572
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002573 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002575 req->max_q_depth = ql2xmaxqdepth;
2576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002577
2578 base_vha = qla2x00_create_host(sht, ha);
2579 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002580 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002581 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002582 qla2x00_free_req_que(ha, req);
2583 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 }
2586
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002588 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002591 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002592 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002594 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2596 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002597
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002598 /* Setup fcport template structure. */
2599 ha->mr.fcport.vha = base_vha;
2600 ha->mr.fcport.port_type = FCT_UNKNOWN;
2601 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2602 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2603 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2604 ha->mr.fcport.scan_state = 1;
2605
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002606 /* Set the SG table size based on ISP type */
2607 if (!IS_FWI2_CAPABLE(ha)) {
2608 if (IS_QLA2100(ha))
2609 host->sg_tablesize = 32;
2610 } else {
2611 if (!IS_QLA82XX(ha))
2612 host->sg_tablesize = QLA_SG_ALL;
2613 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002614 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002615 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002616 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002617 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002618 host->max_cmd_len = 32;
2619 else
2620 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002621 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002622 /* Older HBAs support only 16-bit LUNs */
2623 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2624 ql2xmaxlun > 0xffff)
2625 host->max_lun = 0xffff;
2626 else
2627 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002628 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002629 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002630
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002631 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2632 "max_id=%d this_id=%d "
2633 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002634 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002635 host->this_id, host->cmd_per_lun, host->unique_id,
2636 host->max_cmd_len, host->max_channel, host->max_lun,
2637 host->transportt, sht->vendor_id);
2638
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002639que_init:
2640 /* Alloc arrays of request and response ring ptrs */
2641 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2642 ql_log(ql_log_fatal, base_vha, 0x003d,
2643 "Failed to allocate memory for queue pointers..."
2644 "aborting.\n");
2645 goto probe_init_failed;
2646 }
2647
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002648 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002649
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002650 /* Set up the irqs */
2651 ret = qla2x00_request_irqs(ha, rsp);
2652 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002653 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002654
2655 pci_save_state(pdev);
2656
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002657 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002658 rsp->req = req;
2659 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002660
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002661 if (IS_QLAFX00(ha)) {
2662 ha->rsp_q_map[0] = rsp;
2663 ha->req_q_map[0] = req;
2664 set_bit(0, ha->req_qid_map);
2665 set_bit(0, ha->rsp_qid_map);
2666 }
2667
Andrew Vasquez08029992009-03-24 09:07:55 -07002668 /* FWI2-capable only. */
2669 req->req_q_in = &ha->iobase->isp24.req_q_in;
2670 req->req_q_out = &ha->iobase->isp24.req_q_out;
2671 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2672 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002673 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002674 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2675 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2676 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2677 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002678 }
2679
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002680 if (IS_QLAFX00(ha)) {
2681 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2682 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2683 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2684 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2685 }
2686
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002687 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002688 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2689 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2690 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2691 }
2692
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002693 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2694 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2695 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2696 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2697 "req->req_q_in=%p req->req_q_out=%p "
2698 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2699 req->req_q_in, req->req_q_out,
2700 rsp->rsp_q_in, rsp->rsp_q_out);
2701 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2702 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2703 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2704 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2705 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2706 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002707
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002708 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002709 ql_log(ql_log_fatal, base_vha, 0x00d6,
2710 "Failed to initialize adapter - Adapter flags %x.\n",
2711 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712
Giridhar Malavalia9083012010-04-12 17:59:55 -07002713 if (IS_QLA82XX(ha)) {
2714 qla82xx_idc_lock(ha);
2715 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002716 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002717 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002718 ql_log(ql_log_fatal, base_vha, 0x00d7,
2719 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002720 } else if (IS_QLA8044(ha)) {
2721 qla8044_idc_lock(ha);
2722 qla8044_wr_direct(base_vha,
2723 QLA8044_CRB_DEV_STATE_INDEX,
2724 QLA8XXX_DEV_FAILED);
2725 qla8044_idc_unlock(ha);
2726 ql_log(ql_log_fatal, base_vha, 0x0150,
2727 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002728 }
2729
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002730 ret = -ENODEV;
2731 goto probe_failed;
2732 }
2733
Chad Dupuis3b1bef62014-02-26 04:15:04 -05002734 if (IS_QLAFX00(ha))
2735 host->can_queue = QLAFX00_MAX_CANQUEUE;
2736 else
2737 host->can_queue = req->num_outstanding_cmds - 10;
2738
2739 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2740 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2741 host->can_queue, base_vha->req,
2742 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2743
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002744 if (ha->mqenable) {
2745 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002746 ql_log(ql_log_warn, base_vha, 0x00ec,
2747 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002748 goto que_init;
2749 }
2750 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002751
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002752 if (ha->flags.running_gold_fw)
2753 goto skip_dpc;
2754
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002755 /*
2756 * Startup the kernel thread for this host adapter
2757 */
2758 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002759 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002761 ql_log(ql_log_fatal, base_vha, 0x00ed,
2762 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 ret = PTR_ERR(ha->dpc_thread);
2764 goto probe_failed;
2765 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002766 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2767 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002769 /*
2770 * If we're not coming up in initiator mode, we might sit for
2771 * a while without waking up the dpc thread, which leads to a
2772 * stuck process warning. So just kick the dpc once here and
2773 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2774 */
2775 qla2xxx_wake_dpc(base_vha);
2776
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002777 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2778
Saurav Kashyap81178772012-08-22 14:21:04 -04002779 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2780 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2781 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2782 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2783
2784 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2785 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2786 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2787 INIT_WORK(&ha->idc_state_handler,
2788 qla83xx_idc_state_handler_work);
2789 INIT_WORK(&ha->nic_core_unrecoverable,
2790 qla83xx_nic_core_unrecoverable_work);
2791 }
2792
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002793skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794 list_add_tail(&base_vha->list, &ha->vp_list);
2795 base_vha->host->irq = ha->pdev->irq;
2796
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002799 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2800 "Started qla2x00_timer with "
2801 "interval=%d.\n", WATCH_INTERVAL);
2802 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2803 "Detected hba at address=%p.\n",
2804 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Arun Easie02587d2011-08-16 11:29:23 -07002806 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002807 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002808 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002809 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002810 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2811 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002812 if (ql2xenabledif == 1)
2813 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002814 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002815 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002816 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002817 | SHOST_DIF_TYPE3_PROTECTION
2818 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002819 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002820 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002821
2822 guard = SHOST_DIX_GUARD_CRC;
2823
2824 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2825 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2826 guard |= SHOST_DIX_GUARD_IP;
2827
2828 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002829 } else
2830 base_vha->flags.difdix_supported = 0;
2831 }
2832
Giridhar Malavalia9083012010-04-12 17:59:55 -07002833 ha->isp_ops->enable_intrs(ha);
2834
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002835 if (IS_QLAFX00(ha)) {
2836 ret = qlafx00_fx_disc(base_vha,
2837 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2838 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2839 QLA_SG_ALL : 128;
2840 }
2841
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002842 ret = scsi_add_host(host, &pdev->dev);
2843 if (ret)
2844 goto probe_failed;
2845
Michael Reed14864002009-12-02 09:11:16 -06002846 base_vha->flags.init_done = 1;
2847 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04002848 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06002849
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002850 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2851 "Init done and hba is online.\n");
2852
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002853 if (qla_ini_mode_enabled(base_vha))
2854 scsi_scan_host(host);
2855 else
2856 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2857 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002860
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002861 if (IS_QLAFX00(ha)) {
2862 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002863 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2864
2865 /* Register system information */
2866 ret = qlafx00_fx_disc(base_vha,
2867 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2868 }
2869
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002870 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002873
Armen Baloyan03eb9122013-10-30 03:38:22 -04002874 ql_log(ql_log_info, base_vha, 0x00fb,
2875 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002876 ql_log(ql_log_info, base_vha, 0x00fc,
2877 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2878 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2879 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2880 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002881 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002883 qlt_add_target(ha, base_vha);
2884
Joe Lawrence6b383972014-08-26 17:12:29 -04002885 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 return 0;
2887
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002888probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002889 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002890 ha->req_q_map[0] = NULL;
2891 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002892 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002893 ha->rsp_q_map[0] = NULL;
2894 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002895 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002896
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002898 if (base_vha->timer_active)
2899 qla2x00_stop_timer(base_vha);
2900 base_vha->flags.online = 0;
2901 if (ha->dpc_thread) {
2902 struct task_struct *t = ha->dpc_thread;
2903
2904 ha->dpc_thread = NULL;
2905 kthread_stop(t);
2906 }
2907
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04002913 qla2x00_clear_drv_active(ha);
2914
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002915iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002916 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002917 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002918 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002919 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002920 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002921 } else {
2922 if (ha->iobase)
2923 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002924 if (ha->cregbase)
2925 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002926 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 pci_release_selected_regions(ha->pdev, ha->bars);
2928 kfree(ha);
2929 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002931probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002933 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
Adrian Bunk4c993f72008-01-14 00:55:16 -08002936static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002937qla2x00_shutdown(struct pci_dev *pdev)
2938{
2939 scsi_qla_host_t *vha;
2940 struct qla_hw_data *ha;
2941
Masanari Iida552f3f92013-02-08 01:57:44 -05002942 if (!atomic_read(&pdev->enable_cnt))
2943 return;
2944
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002945 vha = pci_get_drvdata(pdev);
2946 ha = vha->hw;
2947
Armen Baloyan42479342013-08-27 01:37:37 -04002948 /* Notify ISPFX00 firmware */
2949 if (IS_QLAFX00(ha))
2950 qlafx00_driver_shutdown(vha, 20);
2951
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002952 /* Turn-off FCE trace */
2953 if (ha->flags.fce_enabled) {
2954 qla2x00_disable_fce_trace(vha, NULL, NULL);
2955 ha->flags.fce_enabled = 0;
2956 }
2957
2958 /* Turn-off EFT trace */
2959 if (ha->eft)
2960 qla2x00_disable_eft_trace(vha);
2961
2962 /* Stop currently executing firmware. */
2963 qla2x00_try_to_stop_firmware(vha);
2964
2965 /* Turn adapter off line */
2966 vha->flags.online = 0;
2967
2968 /* turn-off interrupts on the card */
2969 if (ha->interrupts_on) {
2970 vha->flags.init_done = 0;
2971 ha->isp_ops->disable_intrs(ha);
2972 }
2973
2974 qla2x00_free_irqs(vha);
2975
2976 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04002977
2978 pci_disable_pcie_error_reporting(pdev);
2979 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002980}
2981
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002982/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002983static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002984qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002986 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002987 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Arun Easi43ebf162011-05-10 11:18:16 -07002989 mutex_lock(&ha->vport_lock);
2990 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07002991 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002992
Arun Easi43ebf162011-05-10 11:18:16 -07002993 BUG_ON(base_vha->list.next == &ha->vp_list);
2994 /* This assumes first entry in ha->vp_list is always base vha */
2995 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07002996 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002997
Arun Easi43ebf162011-05-10 11:18:16 -07002998 spin_unlock_irqrestore(&ha->vport_slock, flags);
2999 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003000
Arun Easi43ebf162011-05-10 11:18:16 -07003001 fc_vport_terminate(vha->fc_vport);
3002 scsi_host_put(vha->host);
3003
3004 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 }
Arun Easi43ebf162011-05-10 11:18:16 -07003006 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003007}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003008
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003009/* Stops all deferred work threads */
3010static void
3011qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3012{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003013 /* Flush the work queue and remove it */
3014 if (ha->wq) {
3015 flush_workqueue(ha->wq);
3016 destroy_workqueue(ha->wq);
3017 ha->wq = NULL;
3018 }
3019
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003020 /* Cancel all work and destroy DPC workqueues */
3021 if (ha->dpc_lp_wq) {
3022 cancel_work_sync(&ha->idc_aen);
3023 destroy_workqueue(ha->dpc_lp_wq);
3024 ha->dpc_lp_wq = NULL;
3025 }
3026
3027 if (ha->dpc_hp_wq) {
3028 cancel_work_sync(&ha->nic_core_reset);
3029 cancel_work_sync(&ha->idc_state_handler);
3030 cancel_work_sync(&ha->nic_core_unrecoverable);
3031 destroy_workqueue(ha->dpc_hp_wq);
3032 ha->dpc_hp_wq = NULL;
3033 }
3034
Andrew Vasquezb9978762009-03-24 09:08:05 -07003035 /* Kill the kernel thread for this host */
3036 if (ha->dpc_thread) {
3037 struct task_struct *t = ha->dpc_thread;
3038
3039 /*
3040 * qla2xxx_wake_dpc checks for ->dpc_thread
3041 * so we need to zero it out.
3042 */
3043 ha->dpc_thread = NULL;
3044 kthread_stop(t);
3045 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003046}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003047
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003048static void
3049qla2x00_unmap_iobases(struct qla_hw_data *ha)
3050{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003051 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003052
Chad Dupuisf73cb692014-02-26 04:15:06 -05003053 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003054 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003055 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003056 } else {
3057 if (ha->iobase)
3058 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003060 if (ha->cregbase)
3061 iounmap(ha->cregbase);
3062
Giridhar Malavalia9083012010-04-12 17:59:55 -07003063 if (ha->mqiobase)
3064 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003065
Chad Dupuisf73cb692014-02-26 04:15:06 -05003066 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003067 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003068 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003069}
3070
3071static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003072qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003073{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003074 if (IS_QLA8044(ha)) {
3075 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003076 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003077 qla8044_idc_unlock(ha);
3078 } else if (IS_QLA82XX(ha)) {
3079 qla82xx_idc_lock(ha);
3080 qla82xx_clear_drv_active(ha);
3081 qla82xx_idc_unlock(ha);
3082 }
3083}
3084
3085static void
3086qla2x00_remove_one(struct pci_dev *pdev)
3087{
3088 scsi_qla_host_t *base_vha;
3089 struct qla_hw_data *ha;
3090
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003091 base_vha = pci_get_drvdata(pdev);
3092 ha = base_vha->hw;
3093
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003094 /* Indicate device removal to prevent future board_disable and wait
3095 * until any pending board_disable has completed. */
3096 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3097 cancel_work_sync(&ha->board_disable);
3098
3099 /*
3100 * If the PCI device is disabled then there was a PCI-disconnect and
3101 * qla2x00_disable_board_on_pci_error has taken care of most of the
3102 * resources.
3103 */
3104 if (!atomic_read(&pdev->enable_cnt)) {
3105 scsi_host_put(base_vha->host);
3106 kfree(ha);
3107 pci_set_drvdata(pdev, NULL);
3108 return;
3109 }
3110
Sawan Chandak638a1a02014-04-11 16:54:38 -04003111 qla2x00_wait_for_hba_ready(base_vha);
3112
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003113 set_bit(UNLOADING, &base_vha->dpc_flags);
3114
3115 if (IS_QLAFX00(ha))
3116 qlafx00_driver_shutdown(base_vha, 20);
3117
3118 qla2x00_delete_all_vps(ha, base_vha);
3119
3120 if (IS_QLA8031(ha)) {
3121 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3122 "Clearing fcoe driver presence.\n");
3123 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3124 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3125 "Error while clearing DRV-Presence.\n");
3126 }
3127
3128 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3129
3130 qla2x00_dfs_remove(base_vha);
3131
3132 qla84xx_put_chip(base_vha);
3133
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003134 /* Laser should be disabled only for ISP2031 */
3135 if (IS_QLA2031(ha))
3136 qla83xx_disable_laser(base_vha);
3137
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003138 /* Disable timer */
3139 if (base_vha->timer_active)
3140 qla2x00_stop_timer(base_vha);
3141
3142 base_vha->flags.online = 0;
3143
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003144 /* free DMA memory */
3145 if (ha->exlogin_buf)
3146 qla2x00_free_exlogin_buffer(ha);
3147
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003148 /* free DMA memory */
3149 if (ha->exchoffld_buf)
3150 qla2x00_free_exchoffld_buffer(ha);
3151
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003152 qla2x00_destroy_deferred_work(ha);
3153
3154 qlt_remove_target(ha, base_vha);
3155
3156 qla2x00_free_sysfs_attr(base_vha, true);
3157
3158 fc_remove_host(base_vha->host);
3159
3160 scsi_remove_host(base_vha->host);
3161
3162 qla2x00_free_device(base_vha);
3163
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003164 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003165
Arun Easid2749ff2014-09-25 05:16:51 -04003166 scsi_host_put(base_vha->host);
3167
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003168 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003169
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 pci_release_selected_regions(ha->pdev, ha->bars);
3171 kfree(ha);
3172 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003174 pci_disable_pcie_error_reporting(pdev);
3175
Bernhard Walle665db932007-03-28 00:49:49 +02003176 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
3179static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183
Andrew Vasquez85880802009-12-15 21:29:46 -08003184 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3185
3186 /* Disable timer */
3187 if (vha->timer_active)
3188 qla2x00_stop_timer(vha);
3189
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003190 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003191
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003192 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003194
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003195 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003196 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003197
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003198 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
Andrew Vasquez85880802009-12-15 21:29:46 -08003201 vha->flags.online = 0;
3202
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003203 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003204 if (ha->interrupts_on) {
3205 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003206 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003207 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209 qla2x00_free_irqs(vha);
3210
Chad Dupuis88670482010-07-23 15:28:30 +05003211 qla2x00_free_fcports(vha);
3212
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003213 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003214
Giridhar Malavali08de2842011-08-16 11:31:44 -07003215 qla82xx_md_free(vha);
3216
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003217 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
Chad Dupuis88670482010-07-23 15:28:30 +05003220void qla2x00_free_fcports(struct scsi_qla_host *vha)
3221{
3222 fc_port_t *fcport, *tfcport;
3223
3224 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3225 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003226 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003227 kfree(fcport);
3228 fcport = NULL;
3229 }
3230}
3231
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003232static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003234 int defer)
3235{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003236 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003237 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003238 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003239
3240 if (!fcport->rport)
3241 return;
3242
3243 rport = fcport->rport;
3244 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003245 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003246 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003247 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003248 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003249 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003250 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3251 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003252 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003253 int now;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003254 if (rport)
3255 fc_remote_port_delete(rport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003256 qlt_do_generation_tick(vha, &now);
3257 qlt_fc_port_deleted(vha, fcport, now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003258 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003259}
3260
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3263 *
3264 * Input: ha = adapter block pointer. fcport = port structure pointer.
3265 *
3266 * Return: None.
3267 *
3268 * Context:
3269 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003271 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003273 if (IS_QLAFX00(vha->hw)) {
3274 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3275 qla2x00_schedule_rport_del(vha, fcport, defer);
3276 return;
3277 }
3278
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003279 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003280 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003281 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282 qla2x00_schedule_rport_del(vha, fcport, defer);
3283 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003284 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 * We may need to retry the login, so don't change the state of the
3286 * port but do the retries.
3287 */
3288 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003289 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
3291 if (!do_login)
3292 return;
3293
Arun Easia1d02852015-08-04 13:38:02 -04003294 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3295
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003299 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003300 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3301 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 }
3303}
3304
3305/*
3306 * qla2x00_mark_all_devices_lost
3307 * Updates fcport state when device goes offline.
3308 *
3309 * Input:
3310 * ha = adapter block pointer.
3311 * fcport = port structure pointer.
3312 *
3313 * Return:
3314 * None.
3315 *
3316 * Context:
3317 */
3318void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320{
3321 fc_port_t *fcport;
3322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003324 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003326
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 /*
3328 * No point in marking the device as lost, if the device is
3329 * already DEAD.
3330 */
3331 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3332 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003334 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003335 if (defer)
3336 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003337 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003338 qla2x00_schedule_rport_del(vha, fcport, defer);
3339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 }
3341}
3342
3343/*
3344* qla2x00_mem_alloc
3345* Allocates adapter memory.
3346*
3347* Returns:
3348* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003349* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003351static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003352qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3353 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354{
3355 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356
Andrew Vasqueze8711082008-01-31 12:33:48 -08003357 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003358 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003359 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003360 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003362 if (qlt_mem_alloc(ha) < 0)
3363 goto fail_free_init_cb;
3364
Chad Dupuis642ef982012-02-09 11:15:57 -08003365 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3366 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003367 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003368 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369
Andrew Vasqueze8711082008-01-31 12:33:48 -08003370 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3371 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003374 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003375 /* Allocate cache for CT6 Ctx. */
3376 if (!ctx_cachep) {
3377 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3378 sizeof(struct ct6_dsd), 0,
3379 SLAB_HWCACHE_ALIGN, NULL);
3380 if (!ctx_cachep)
3381 goto fail_free_gid_list;
3382 }
3383 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3384 ctx_cachep);
3385 if (!ha->ctx_mempool)
3386 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003387 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3388 "ctx_cachep=%p ctx_mempool=%p.\n",
3389 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003390 }
3391
Andrew Vasqueze8711082008-01-31 12:33:48 -08003392 /* Get memory for cached NVRAM */
3393 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3394 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003395 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3398 ha->pdev->device);
3399 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3400 DMA_POOL_SIZE, 8, 0);
3401 if (!ha->s_dma_pool)
3402 goto fail_free_nvram;
3403
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003404 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3405 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3406 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3407
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003408 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003409 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3410 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3411 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003412 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3413 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003414 goto fail_s_dma_pool;
3415 }
3416
3417 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3418 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3419 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003420 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3421 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003422 goto fail_dl_dma_pool;
3423 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003424 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3425 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3426 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003427 }
3428
Andrew Vasqueze8711082008-01-31 12:33:48 -08003429 /* Allocate memory for SNS commands */
3430 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003432 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003434 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003435 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003436 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003437 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003438 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003440 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003441 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003442 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 goto fail_dma_pool;
3444 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003445 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003447 if (!ha->ct_sns)
3448 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003449 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3450 "ms_iocb=%p ct_sns=%p.\n",
3451 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 }
3453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003454 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003455 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3456 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003457 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3458 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 goto fail_req;
3460 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003461 (*req)->length = req_len;
3462 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3463 ((*req)->length + 1) * sizeof(request_t),
3464 &(*req)->dma, GFP_KERNEL);
3465 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003466 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3467 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 goto fail_req_ring;
3469 }
3470 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003471 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3472 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003473 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3474 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 goto fail_rsp;
3476 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003477 (*rsp)->hw = ha;
3478 (*rsp)->length = rsp_len;
3479 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3480 ((*rsp)->length + 1) * sizeof(response_t),
3481 &(*rsp)->dma, GFP_KERNEL);
3482 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003483 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3484 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 goto fail_rsp_ring;
3486 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003487 (*req)->rsp = *rsp;
3488 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003489 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3490 "req=%p req->length=%d req->ring=%p rsp=%p "
3491 "rsp->length=%d rsp->ring=%p.\n",
3492 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3493 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003494 /* Allocate memory for NVRAM data for vports */
3495 if (ha->nvram_npiv_size) {
3496 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003497 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003498 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003499 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3500 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003501 goto fail_npiv_info;
3502 }
3503 } else
3504 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003505
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003506 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003507 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003508 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3509 &ha->ex_init_cb_dma);
3510 if (!ha->ex_init_cb)
3511 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003512 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3513 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003514 }
3515
Giridhar Malavalia9083012010-04-12 17:59:55 -07003516 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3517
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003518 /* Get consistent memory allocated for Async Port-Database. */
3519 if (!IS_FWI2_CAPABLE(ha)) {
3520 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3521 &ha->async_pd_dma);
3522 if (!ha->async_pd)
3523 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003524 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3525 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003526 }
3527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003529
3530 /* Allocate memory for our loop_id bitmap */
3531 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3532 GFP_KERNEL);
3533 if (!ha->loop_id_map)
3534 goto fail_async_pd;
3535 else {
3536 qla2x00_set_reserved_loop_ids(ha);
3537 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003538 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003539 }
3540
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003541 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003543fail_async_pd:
3544 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003545fail_ex_init_cb:
3546 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003547fail_npiv_info:
3548 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3549 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3550 (*rsp)->ring = NULL;
3551 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003553 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003554fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003555 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3556 sizeof(request_t), (*req)->ring, (*req)->dma);
3557 (*req)->ring = NULL;
3558 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003560 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003561fail_req:
3562 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3563 ha->ct_sns, ha->ct_sns_dma);
3564 ha->ct_sns = NULL;
3565 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003566fail_free_ms_iocb:
3567 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3568 ha->ms_iocb = NULL;
3569 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003570fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003571 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003572 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3573 ha->fcp_cmnd_dma_pool = NULL;
3574 }
3575fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003576 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003577 dma_pool_destroy(ha->dl_dma_pool);
3578 ha->dl_dma_pool = NULL;
3579 }
3580fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003581 dma_pool_destroy(ha->s_dma_pool);
3582 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003583fail_free_nvram:
3584 kfree(ha->nvram);
3585 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003586fail_free_ctx_mempool:
3587 mempool_destroy(ha->ctx_mempool);
3588 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003589fail_free_srb_mempool:
3590 mempool_destroy(ha->srb_mempool);
3591 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003592fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003593 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3594 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003595 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003596 ha->gid_list = NULL;
3597 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003598fail_free_tgt_mem:
3599 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600fail_free_init_cb:
3601 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3602 ha->init_cb_dma);
3603 ha->init_cb = NULL;
3604 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003605fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003606 ql_log(ql_log_fatal, NULL, 0x0030,
3607 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003608 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609}
3610
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003611int
3612qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
3613{
3614 int rval;
3615 uint16_t size, max_cnt, temp;
3616 struct qla_hw_data *ha = vha->hw;
3617
3618 /* Return if we don't need to alloacate any extended logins */
3619 if (!ql2xexlogins)
3620 return QLA_SUCCESS;
3621
3622 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
3623 max_cnt = 0;
3624 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
3625 if (rval != QLA_SUCCESS) {
3626 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
3627 "Failed to get exlogin status.\n");
3628 return rval;
3629 }
3630
3631 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
3632 ha->exlogin_size = (size * temp);
3633 ql_log(ql_log_info, vha, 0xd024,
3634 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
3635 max_cnt, size, temp);
3636
3637 ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
3638 ha->exlogin_size);
3639
3640 /* Get consistent memory for extended logins */
3641 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
3642 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
3643 if (!ha->exlogin_buf) {
3644 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
3645 "Failed to allocate memory for exlogin_buf_dma.\n");
3646 return -ENOMEM;
3647 }
3648
3649 /* Now configure the dma buffer */
3650 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
3651 if (rval) {
3652 ql_log(ql_log_fatal, vha, 0x00cf,
3653 "Setup extended login buffer ****FAILED****.\n");
3654 qla2x00_free_exlogin_buffer(ha);
3655 }
3656
3657 return rval;
3658}
3659
3660/*
3661* qla2x00_free_exlogin_buffer
3662*
3663* Input:
3664* ha = adapter block pointer
3665*/
3666void
3667qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
3668{
3669 if (ha->exlogin_buf) {
3670 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
3671 ha->exlogin_buf, ha->exlogin_buf_dma);
3672 ha->exlogin_buf = NULL;
3673 ha->exlogin_size = 0;
3674 }
3675}
3676
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003677int
3678qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
3679{
3680 int rval;
3681 uint16_t size, max_cnt, temp;
3682 struct qla_hw_data *ha = vha->hw;
3683
3684 /* Return if we don't need to alloacate any extended logins */
3685 if (!ql2xexchoffld)
3686 return QLA_SUCCESS;
3687
3688 ql_log(ql_log_info, vha, 0xd014,
3689 "Exchange offload count: %d.\n", ql2xexlogins);
3690
3691 max_cnt = 0;
3692 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
3693 if (rval != QLA_SUCCESS) {
3694 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
3695 "Failed to get exlogin status.\n");
3696 return rval;
3697 }
3698
3699 temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
3700 ha->exchoffld_size = (size * temp);
3701 ql_log(ql_log_info, vha, 0xd016,
3702 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
3703 max_cnt, size, temp);
3704
3705 ql_log(ql_log_info, vha, 0xd017,
3706 "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
3707
3708 /* Get consistent memory for extended logins */
3709 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
3710 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
3711 if (!ha->exchoffld_buf) {
3712 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
3713 "Failed to allocate memory for exchoffld_buf_dma.\n");
3714 return -ENOMEM;
3715 }
3716
3717 /* Now configure the dma buffer */
3718 rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
3719 if (rval) {
3720 ql_log(ql_log_fatal, vha, 0xd02e,
3721 "Setup exchange offload buffer ****FAILED****.\n");
3722 qla2x00_free_exchoffld_buffer(ha);
3723 }
3724
3725 return rval;
3726}
3727
3728/*
3729* qla2x00_free_exchoffld_buffer
3730*
3731* Input:
3732* ha = adapter block pointer
3733*/
3734void
3735qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
3736{
3737 if (ha->exchoffld_buf) {
3738 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
3739 ha->exchoffld_buf, ha->exchoffld_buf_dma);
3740 ha->exchoffld_buf = NULL;
3741 ha->exchoffld_size = 0;
3742 }
3743}
3744
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003746* qla2x00_free_fw_dump
3747* Frees fw dump stuff.
3748*
3749* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003750* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003751*/
3752static void
3753qla2x00_free_fw_dump(struct qla_hw_data *ha)
3754{
3755 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003756 dma_free_coherent(&ha->pdev->dev,
3757 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003758
Chad Dupuisf73cb692014-02-26 04:15:06 -05003759 if (ha->eft)
3760 dma_free_coherent(&ha->pdev->dev,
3761 EFT_SIZE, ha->eft, ha->eft_dma);
3762
3763 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003764 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05003765 if (ha->fw_dump_template)
3766 vfree(ha->fw_dump_template);
3767
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003768 ha->fce = NULL;
3769 ha->fce_dma = 0;
3770 ha->eft = NULL;
3771 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003772 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04003773 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003774 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003775 ha->fw_dump = NULL;
3776 ha->fw_dump_len = 0;
3777 ha->fw_dump_template = NULL;
3778 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003779}
3780
3781/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782* qla2x00_mem_free
3783* Frees all adapter allocated memory.
3784*
3785* Input:
3786* ha = adapter block pointer.
3787*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003788static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003789qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003791 qla2x00_free_fw_dump(ha);
3792
Saurav Kashyap81178772012-08-22 14:21:04 -04003793 if (ha->mctp_dump)
3794 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3795 ha->mctp_dump_dma);
3796
Andrew Vasqueze8711082008-01-31 12:33:48 -08003797 if (ha->srb_mempool)
3798 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003800 if (ha->dcbx_tlv)
3801 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3802 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3803
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003804 if (ha->xgmac_data)
3805 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3806 ha->xgmac_data, ha->xgmac_data_dma);
3807
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 if (ha->sns_cmd)
3809 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003810 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811
3812 if (ha->ct_sns)
3813 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815
Andrew Vasquez88729e52006-06-23 16:10:50 -07003816 if (ha->sfp_data)
3817 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3818
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 if (ha->ms_iocb)
3820 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3821
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003822 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003823 dma_pool_free(ha->s_dma_pool,
3824 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003825
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003826 if (ha->async_pd)
3827 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3828
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 if (ha->s_dma_pool)
3830 dma_pool_destroy(ha->s_dma_pool);
3831
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003833 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3834 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835
Giridhar Malavalia9083012010-04-12 17:59:55 -07003836 if (IS_QLA82XX(ha)) {
3837 if (!list_empty(&ha->gbl_dsd_list)) {
3838 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3839
3840 /* clean up allocated prev pool */
3841 list_for_each_entry_safe(dsd_ptr,
3842 tdsd_ptr, &ha->gbl_dsd_list, list) {
3843 dma_pool_free(ha->dl_dma_pool,
3844 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3845 list_del(&dsd_ptr->list);
3846 kfree(dsd_ptr);
3847 }
3848 }
3849 }
3850
3851 if (ha->dl_dma_pool)
3852 dma_pool_destroy(ha->dl_dma_pool);
3853
3854 if (ha->fcp_cmnd_dma_pool)
3855 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3856
3857 if (ha->ctx_mempool)
3858 mempool_destroy(ha->ctx_mempool);
3859
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003860 qlt_mem_free(ha);
3861
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003862 if (ha->init_cb)
3863 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003864 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865 vfree(ha->optrom_buffer);
3866 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003867 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003868 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003869 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
Andrew Vasqueze8711082008-01-31 12:33:48 -08003871 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003872 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 ha->sns_cmd = NULL;
3874 ha->sns_cmd_dma = 0;
3875 ha->ct_sns = NULL;
3876 ha->ct_sns_dma = 0;
3877 ha->ms_iocb = NULL;
3878 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 ha->init_cb = NULL;
3880 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003881 ha->ex_init_cb = NULL;
3882 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003883 ha->async_pd = NULL;
3884 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885
3886 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003887 ha->dl_dma_pool = NULL;
3888 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 ha->gid_list = NULL;
3891 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003892
3893 ha->tgt.atio_ring = NULL;
3894 ha->tgt.atio_dma = 0;
3895 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003896}
3897
3898struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3899 struct qla_hw_data *ha)
3900{
3901 struct Scsi_Host *host;
3902 struct scsi_qla_host *vha = NULL;
3903
3904 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3905 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003906 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3907 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 goto fail;
3909 }
3910
3911 /* Clear our data area */
3912 vha = shost_priv(host);
3913 memset(vha, 0, sizeof(scsi_qla_host_t));
3914
3915 vha->host = host;
3916 vha->host_no = host->host_no;
3917 vha->hw = ha;
3918
3919 INIT_LIST_HEAD(&vha->vp_fcports);
3920 INIT_LIST_HEAD(&vha->work_list);
3921 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04003922 INIT_LIST_HEAD(&vha->qla_cmd_list);
3923 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05003924 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05003925 INIT_LIST_HEAD(&vha->plogi_ack_list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003926
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003927 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04003928 spin_lock_init(&vha->cmd_list_lock);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003930 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003931 ql_dbg(ql_dbg_init, vha, 0x0041,
3932 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3933 vha->host, vha->hw, vha,
3934 dev_name(&(ha->pdev->dev)));
3935
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003936 return vha;
3937
3938fail:
3939 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940}
3941
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003942static struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003943qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003944{
3945 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003946 uint8_t bail;
3947
3948 QLA_VHA_MARK_BUSY(vha, bail);
3949 if (bail)
3950 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003951
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003952 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003953 if (!e) {
3954 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003955 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003956 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003957
3958 INIT_LIST_HEAD(&e->list);
3959 e->type = type;
3960 e->flags = QLA_EVT_FLAG_FREE;
3961 return e;
3962}
3963
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003964static int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003965qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003966{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003967 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003968
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003969 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003970 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003971 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003972 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003973
Andrew Vasquez0971de72008-04-03 13:13:18 -07003974 return QLA_SUCCESS;
3975}
3976
3977int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003979 u32 data)
3980{
3981 struct qla_work_evt *e;
3982
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003983 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003984 if (!e)
3985 return QLA_FUNCTION_FAILED;
3986
3987 e->u.aen.code = code;
3988 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003989 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003990}
3991
Andrew Vasquez8a659572009-02-08 20:50:12 -08003992int
3993qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3994{
3995 struct qla_work_evt *e;
3996
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003997 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003998 if (!e)
3999 return QLA_FUNCTION_FAILED;
4000
4001 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004002 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004003}
4004
Andrew Vasquezac280b62009-08-20 11:06:05 -07004005#define qla2x00_post_async_work(name, type) \
4006int qla2x00_post_async_##name##_work( \
4007 struct scsi_qla_host *vha, \
4008 fc_port_t *fcport, uint16_t *data) \
4009{ \
4010 struct qla_work_evt *e; \
4011 \
4012 e = qla2x00_alloc_work(vha, type); \
4013 if (!e) \
4014 return QLA_FUNCTION_FAILED; \
4015 \
4016 e->u.logio.fcport = fcport; \
4017 if (data) { \
4018 e->u.logio.data[0] = data[0]; \
4019 e->u.logio.data[1] = data[1]; \
4020 } \
4021 return qla2x00_post_work(vha, e); \
4022}
4023
4024qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4025qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
4026qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4027qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004028qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4029qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004030
Andrew Vasquez3420d362009-10-13 15:16:45 -07004031int
4032qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4033{
4034 struct qla_work_evt *e;
4035
4036 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4037 if (!e)
4038 return QLA_FUNCTION_FAILED;
4039
4040 e->u.uevent.code = code;
4041 return qla2x00_post_work(vha, e);
4042}
4043
4044static void
4045qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4046{
4047 char event_string[40];
4048 char *envp[] = { event_string, NULL };
4049
4050 switch (code) {
4051 case QLA_UEVENT_CODE_FW_DUMP:
4052 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4053 vha->host_no);
4054 break;
4055 default:
4056 /* do nothing */
4057 break;
4058 }
4059 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4060}
4061
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004062int
4063qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4064 uint32_t *data, int cnt)
4065{
4066 struct qla_work_evt *e;
4067
4068 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4069 if (!e)
4070 return QLA_FUNCTION_FAILED;
4071
4072 e->u.aenfx.evtcode = evtcode;
4073 e->u.aenfx.count = cnt;
4074 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4075 return qla2x00_post_work(vha, e);
4076}
4077
Andrew Vasquezac280b62009-08-20 11:06:05 -07004078void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004080{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004081 struct qla_work_evt *e, *tmp;
4082 unsigned long flags;
4083 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004084
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004085 spin_lock_irqsave(&vha->work_lock, flags);
4086 list_splice_init(&vha->work_list, &work);
4087 spin_unlock_irqrestore(&vha->work_lock, flags);
4088
4089 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004090 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004091
4092 switch (e->type) {
4093 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004094 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004095 e->u.aen.code, e->u.aen.data);
4096 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004097 case QLA_EVT_IDC_ACK:
4098 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4099 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004100 case QLA_EVT_ASYNC_LOGIN:
4101 qla2x00_async_login(vha, e->u.logio.fcport,
4102 e->u.logio.data);
4103 break;
4104 case QLA_EVT_ASYNC_LOGIN_DONE:
4105 qla2x00_async_login_done(vha, e->u.logio.fcport,
4106 e->u.logio.data);
4107 break;
4108 case QLA_EVT_ASYNC_LOGOUT:
4109 qla2x00_async_logout(vha, e->u.logio.fcport);
4110 break;
4111 case QLA_EVT_ASYNC_LOGOUT_DONE:
4112 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4113 e->u.logio.data);
4114 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004115 case QLA_EVT_ASYNC_ADISC:
4116 qla2x00_async_adisc(vha, e->u.logio.fcport,
4117 e->u.logio.data);
4118 break;
4119 case QLA_EVT_ASYNC_ADISC_DONE:
4120 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4121 e->u.logio.data);
4122 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004123 case QLA_EVT_UEVENT:
4124 qla2x00_uevent_emit(vha, e->u.uevent.code);
4125 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004126 case QLA_EVT_AENFX:
4127 qlafx00_process_aen(vha, e);
4128 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004129 }
4130 if (e->flags & QLA_EVT_FLAG_FREE)
4131 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004132
4133 /* For each work completed decrement vha ref count */
4134 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004135 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004138/* Relogins all the fcports of a vport
4139 * Context: dpc thread
4140 */
4141void qla2x00_relogin(struct scsi_qla_host *vha)
4142{
4143 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004144 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004145 uint16_t next_loopid = 0;
4146 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004147 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148
4149 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4150 /*
4151 * If the port is not ONLINE then try to login
4152 * to it if we haven't run out of retries.
4153 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004154 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4155 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004156 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004158 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004159 ha->isp_ops->fabric_logout(vha,
4160 fcport->loop_id,
4161 fcport->d_id.b.domain,
4162 fcport->d_id.b.area,
4163 fcport->d_id.b.al_pa);
4164
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004165 if (fcport->loop_id == FC_NO_LOOP_ID) {
4166 fcport->loop_id = next_loopid =
4167 ha->min_external_loopid;
4168 status = qla2x00_find_new_loop_id(
4169 vha, fcport);
4170 if (status != QLA_SUCCESS) {
4171 /* Ran out of IDs to use */
4172 break;
4173 }
4174 }
4175
Andrew Vasquezac280b62009-08-20 11:06:05 -07004176 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004177 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004178 data[0] = 0;
4179 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4180 status = qla2x00_post_async_login_work(
4181 vha, fcport, data);
4182 if (status == QLA_SUCCESS)
4183 continue;
4184 /* Attempt a retry. */
4185 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004186 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004187 status = qla2x00_fabric_login(vha,
4188 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004189 if (status == QLA_SUCCESS) {
4190 int status2;
4191 uint8_t opts;
4192
4193 opts = 0;
4194 if (fcport->flags &
4195 FCF_FCP2_DEVICE)
4196 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004197 status2 =
4198 qla2x00_get_port_database(
4199 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004200 if (status2 != QLA_SUCCESS)
4201 status = 1;
4202 }
4203 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004204 } else
4205 status = qla2x00_local_device_login(vha,
4206 fcport);
4207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 if (status == QLA_SUCCESS) {
4209 fcport->old_loop_id = fcport->loop_id;
4210
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004211 ql_dbg(ql_dbg_disc, vha, 0x2003,
4212 "Port login OK: logged in ID 0x%x.\n",
4213 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004214
4215 qla2x00_update_fcport(vha, fcport);
4216
4217 } else if (status == 1) {
4218 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4219 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004220 ql_dbg(ql_dbg_disc, vha, 0x2007,
4221 "Retrying %d login again loop_id 0x%x.\n",
4222 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 } else {
4224 fcport->login_retry = 0;
4225 }
4226
4227 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004228 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004229 }
4230 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4231 break;
4232 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004233}
4234
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004235/* Schedule work on any of the dpc-workqueues */
4236void
4237qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4238{
4239 struct qla_hw_data *ha = base_vha->hw;
4240
4241 switch (work_code) {
4242 case MBA_IDC_AEN: /* 0x8200 */
4243 if (ha->dpc_lp_wq)
4244 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4245 break;
4246
4247 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4248 if (!ha->flags.nic_core_reset_hdlr_active) {
4249 if (ha->dpc_hp_wq)
4250 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4251 } else
4252 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4253 "NIC Core reset is already active. Skip "
4254 "scheduling it again.\n");
4255 break;
4256 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4257 if (ha->dpc_hp_wq)
4258 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4259 break;
4260 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4261 if (ha->dpc_hp_wq)
4262 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4263 break;
4264 default:
4265 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004266 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004267 }
4268
4269 return;
4270}
4271
4272/* Work: Perform NIC Core Unrecoverable state handling */
4273void
4274qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4275{
4276 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004277 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004278 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4279 uint32_t dev_state = 0;
4280
4281 qla83xx_idc_lock(base_vha, 0);
4282 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4283 qla83xx_reset_ownership(base_vha);
4284 if (ha->flags.nic_core_reset_owner) {
4285 ha->flags.nic_core_reset_owner = 0;
4286 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4287 QLA8XXX_DEV_FAILED);
4288 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4289 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4290 }
4291 qla83xx_idc_unlock(base_vha, 0);
4292}
4293
4294/* Work: Execute IDC state handler */
4295void
4296qla83xx_idc_state_handler_work(struct work_struct *work)
4297{
4298 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004299 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004300 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4301 uint32_t dev_state = 0;
4302
4303 qla83xx_idc_lock(base_vha, 0);
4304 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4305 if (dev_state == QLA8XXX_DEV_FAILED ||
4306 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4307 qla83xx_idc_state_handler(base_vha);
4308 qla83xx_idc_unlock(base_vha, 0);
4309}
4310
Saurav Kashyapfa492632012-11-21 02:40:29 -05004311static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004312qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4313{
4314 int rval = QLA_SUCCESS;
4315 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4316 uint32_t heart_beat_counter1, heart_beat_counter2;
4317
4318 do {
4319 if (time_after(jiffies, heart_beat_wait)) {
4320 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4321 "Nic Core f/w is not alive.\n");
4322 rval = QLA_FUNCTION_FAILED;
4323 break;
4324 }
4325
4326 qla83xx_idc_lock(base_vha, 0);
4327 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4328 &heart_beat_counter1);
4329 qla83xx_idc_unlock(base_vha, 0);
4330 msleep(100);
4331 qla83xx_idc_lock(base_vha, 0);
4332 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4333 &heart_beat_counter2);
4334 qla83xx_idc_unlock(base_vha, 0);
4335 } while (heart_beat_counter1 == heart_beat_counter2);
4336
4337 return rval;
4338}
4339
4340/* Work: Perform NIC Core Reset handling */
4341void
4342qla83xx_nic_core_reset_work(struct work_struct *work)
4343{
4344 struct qla_hw_data *ha =
4345 container_of(work, struct qla_hw_data, nic_core_reset);
4346 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4347 uint32_t dev_state = 0;
4348
Saurav Kashyap81178772012-08-22 14:21:04 -04004349 if (IS_QLA2031(ha)) {
4350 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4351 ql_log(ql_log_warn, base_vha, 0xb081,
4352 "Failed to dump mctp\n");
4353 return;
4354 }
4355
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004356 if (!ha->flags.nic_core_reset_hdlr_active) {
4357 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4358 qla83xx_idc_lock(base_vha, 0);
4359 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4360 &dev_state);
4361 qla83xx_idc_unlock(base_vha, 0);
4362 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4363 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4364 "Nic Core f/w is alive.\n");
4365 return;
4366 }
4367 }
4368
4369 ha->flags.nic_core_reset_hdlr_active = 1;
4370 if (qla83xx_nic_core_reset(base_vha)) {
4371 /* NIC Core reset failed. */
4372 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4373 "NIC Core reset failed.\n");
4374 }
4375 ha->flags.nic_core_reset_hdlr_active = 0;
4376 }
4377}
4378
4379/* Work: Handle 8200 IDC aens */
4380void
4381qla83xx_service_idc_aen(struct work_struct *work)
4382{
4383 struct qla_hw_data *ha =
4384 container_of(work, struct qla_hw_data, idc_aen);
4385 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4386 uint32_t dev_state, idc_control;
4387
4388 qla83xx_idc_lock(base_vha, 0);
4389 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4390 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4391 qla83xx_idc_unlock(base_vha, 0);
4392 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4393 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4394 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4395 "Application requested NIC Core Reset.\n");
4396 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4397 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4398 QLA_SUCCESS) {
4399 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4400 "Other protocol driver requested NIC Core Reset.\n");
4401 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4402 }
4403 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4404 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4405 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4406 }
4407}
4408
4409static void
4410qla83xx_wait_logic(void)
4411{
4412 int i;
4413
4414 /* Yield CPU */
4415 if (!in_interrupt()) {
4416 /*
4417 * Wait about 200ms before retrying again.
4418 * This controls the number of retries for single
4419 * lock operation.
4420 */
4421 msleep(100);
4422 schedule();
4423 } else {
4424 for (i = 0; i < 20; i++)
4425 cpu_relax(); /* This a nop instr on i386 */
4426 }
4427}
4428
Saurav Kashyapfa492632012-11-21 02:40:29 -05004429static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004430qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4431{
4432 int rval;
4433 uint32_t data;
4434 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4435 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4436 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004437 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4438 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004439
4440 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4441 if (rval)
4442 return rval;
4443
4444 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4445 return QLA_SUCCESS;
4446 } else {
4447 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4448 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4449 data);
4450 if (rval)
4451 return rval;
4452
4453 msleep(200);
4454
4455 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4456 &data);
4457 if (rval)
4458 return rval;
4459
4460 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4461 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4462 ~(idc_lck_rcvry_stage_mask));
4463 rval = qla83xx_wr_reg(base_vha,
4464 QLA83XX_IDC_LOCK_RECOVERY, data);
4465 if (rval)
4466 return rval;
4467
4468 /* Forcefully perform IDC UnLock */
4469 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4470 &data);
4471 if (rval)
4472 return rval;
4473 /* Clear lock-id by setting 0xff */
4474 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4475 0xff);
4476 if (rval)
4477 return rval;
4478 /* Clear lock-recovery by setting 0x0 */
4479 rval = qla83xx_wr_reg(base_vha,
4480 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4481 if (rval)
4482 return rval;
4483 } else
4484 return QLA_SUCCESS;
4485 }
4486
4487 return rval;
4488}
4489
Saurav Kashyapfa492632012-11-21 02:40:29 -05004490static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004491qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4492{
4493 int rval = QLA_SUCCESS;
4494 uint32_t o_drv_lockid, n_drv_lockid;
4495 unsigned long lock_recovery_timeout;
4496
4497 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4498retry_lockid:
4499 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4500 if (rval)
4501 goto exit;
4502
4503 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4504 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4505 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4506 return QLA_SUCCESS;
4507 else
4508 return QLA_FUNCTION_FAILED;
4509 }
4510
4511 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4512 if (rval)
4513 goto exit;
4514
4515 if (o_drv_lockid == n_drv_lockid) {
4516 qla83xx_wait_logic();
4517 goto retry_lockid;
4518 } else
4519 return QLA_SUCCESS;
4520
4521exit:
4522 return rval;
4523}
4524
4525void
4526qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4527{
4528 uint16_t options = (requester_id << 15) | BIT_6;
4529 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004530 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004531 struct qla_hw_data *ha = base_vha->hw;
4532
4533 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4534retry_lock:
4535 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4536 == QLA_SUCCESS) {
4537 if (data) {
4538 /* Setting lock-id to our function-number */
4539 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4540 ha->portnum);
4541 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004542 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4543 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004544 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004545 "Failed to acquire IDC lock, acquired by %d, "
4546 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004547
4548 /* Retry/Perform IDC-Lock recovery */
4549 if (qla83xx_idc_lock_recovery(base_vha)
4550 == QLA_SUCCESS) {
4551 qla83xx_wait_logic();
4552 goto retry_lock;
4553 } else
4554 ql_log(ql_log_warn, base_vha, 0xb075,
4555 "IDC Lock recovery FAILED.\n");
4556 }
4557
4558 }
4559
4560 return;
4561
4562 /* XXX: IDC-lock implementation using access-control mbx */
4563retry_lock2:
4564 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4565 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4566 "Failed to acquire IDC lock. retrying...\n");
4567 /* Retry/Perform IDC-Lock recovery */
4568 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4569 qla83xx_wait_logic();
4570 goto retry_lock2;
4571 } else
4572 ql_log(ql_log_warn, base_vha, 0xb076,
4573 "IDC Lock recovery FAILED.\n");
4574 }
4575
4576 return;
4577}
4578
4579void
4580qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4581{
Bart Van Assche5897cb22015-06-04 15:57:20 -07004582#if 0
4583 uint16_t options = (requester_id << 15) | BIT_7;
4584#endif
4585 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004586 uint32_t data;
4587 struct qla_hw_data *ha = base_vha->hw;
4588
4589 /* IDC-unlock implementation using driver-unlock/lock-id
4590 * remote registers
4591 */
4592 retry = 0;
4593retry_unlock:
4594 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4595 == QLA_SUCCESS) {
4596 if (data == ha->portnum) {
4597 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4598 /* Clearing lock-id by setting 0xff */
4599 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4600 } else if (retry < 10) {
4601 /* SV: XXX: IDC unlock retrying needed here? */
4602
4603 /* Retry for IDC-unlock */
4604 qla83xx_wait_logic();
4605 retry++;
4606 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4607 "Failed to release IDC lock, retyring=%d\n", retry);
4608 goto retry_unlock;
4609 }
4610 } else if (retry < 10) {
4611 /* Retry for IDC-unlock */
4612 qla83xx_wait_logic();
4613 retry++;
4614 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4615 "Failed to read drv-lockid, retyring=%d\n", retry);
4616 goto retry_unlock;
4617 }
4618
4619 return;
4620
Bart Van Assche5897cb22015-06-04 15:57:20 -07004621#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004622 /* XXX: IDC-unlock implementation using access-control mbx */
4623 retry = 0;
4624retry_unlock2:
4625 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4626 if (retry < 10) {
4627 /* Retry for IDC-unlock */
4628 qla83xx_wait_logic();
4629 retry++;
4630 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4631 "Failed to release IDC lock, retyring=%d\n", retry);
4632 goto retry_unlock2;
4633 }
4634 }
4635
4636 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07004637#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004638}
4639
4640int
4641__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4642{
4643 int rval = QLA_SUCCESS;
4644 struct qla_hw_data *ha = vha->hw;
4645 uint32_t drv_presence;
4646
4647 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4648 if (rval == QLA_SUCCESS) {
4649 drv_presence |= (1 << ha->portnum);
4650 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4651 drv_presence);
4652 }
4653
4654 return rval;
4655}
4656
4657int
4658qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4659{
4660 int rval = QLA_SUCCESS;
4661
4662 qla83xx_idc_lock(vha, 0);
4663 rval = __qla83xx_set_drv_presence(vha);
4664 qla83xx_idc_unlock(vha, 0);
4665
4666 return rval;
4667}
4668
4669int
4670__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4671{
4672 int rval = QLA_SUCCESS;
4673 struct qla_hw_data *ha = vha->hw;
4674 uint32_t drv_presence;
4675
4676 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4677 if (rval == QLA_SUCCESS) {
4678 drv_presence &= ~(1 << ha->portnum);
4679 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4680 drv_presence);
4681 }
4682
4683 return rval;
4684}
4685
4686int
4687qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4688{
4689 int rval = QLA_SUCCESS;
4690
4691 qla83xx_idc_lock(vha, 0);
4692 rval = __qla83xx_clear_drv_presence(vha);
4693 qla83xx_idc_unlock(vha, 0);
4694
4695 return rval;
4696}
4697
Saurav Kashyapfa492632012-11-21 02:40:29 -05004698static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004699qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4700{
4701 struct qla_hw_data *ha = vha->hw;
4702 uint32_t drv_ack, drv_presence;
4703 unsigned long ack_timeout;
4704
4705 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4706 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4707 while (1) {
4708 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4709 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004710 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004711 break;
4712
4713 if (time_after_eq(jiffies, ack_timeout)) {
4714 ql_log(ql_log_warn, vha, 0xb067,
4715 "RESET ACK TIMEOUT! drv_presence=0x%x "
4716 "drv_ack=0x%x\n", drv_presence, drv_ack);
4717 /*
4718 * The function(s) which did not ack in time are forced
4719 * to withdraw any further participation in the IDC
4720 * reset.
4721 */
4722 if (drv_ack != drv_presence)
4723 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4724 drv_ack);
4725 break;
4726 }
4727
4728 qla83xx_idc_unlock(vha, 0);
4729 msleep(1000);
4730 qla83xx_idc_lock(vha, 0);
4731 }
4732
4733 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4734 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4735}
4736
Saurav Kashyapfa492632012-11-21 02:40:29 -05004737static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004738qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4739{
4740 int rval = QLA_SUCCESS;
4741 uint32_t idc_control;
4742
4743 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4744 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4745
4746 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4747 __qla83xx_get_idc_control(vha, &idc_control);
4748 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4749 __qla83xx_set_idc_control(vha, 0);
4750
4751 qla83xx_idc_unlock(vha, 0);
4752 rval = qla83xx_restart_nic_firmware(vha);
4753 qla83xx_idc_lock(vha, 0);
4754
4755 if (rval != QLA_SUCCESS) {
4756 ql_log(ql_log_fatal, vha, 0xb06a,
4757 "Failed to restart NIC f/w.\n");
4758 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4759 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4760 } else {
4761 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4762 "Success in restarting nic f/w.\n");
4763 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4764 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4765 }
4766
4767 return rval;
4768}
4769
4770/* Assumes idc_lock always held on entry */
4771int
4772qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4773{
4774 struct qla_hw_data *ha = base_vha->hw;
4775 int rval = QLA_SUCCESS;
4776 unsigned long dev_init_timeout;
4777 uint32_t dev_state;
4778
4779 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4780 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4781
4782 while (1) {
4783
4784 if (time_after_eq(jiffies, dev_init_timeout)) {
4785 ql_log(ql_log_warn, base_vha, 0xb06e,
4786 "Initialization TIMEOUT!\n");
4787 /* Init timeout. Disable further NIC Core
4788 * communication.
4789 */
4790 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4791 QLA8XXX_DEV_FAILED);
4792 ql_log(ql_log_info, base_vha, 0xb06f,
4793 "HW State: FAILED.\n");
4794 }
4795
4796 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4797 switch (dev_state) {
4798 case QLA8XXX_DEV_READY:
4799 if (ha->flags.nic_core_reset_owner)
4800 qla83xx_idc_audit(base_vha,
4801 IDC_AUDIT_COMPLETION);
4802 ha->flags.nic_core_reset_owner = 0;
4803 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4804 "Reset_owner reset by 0x%x.\n",
4805 ha->portnum);
4806 goto exit;
4807 case QLA8XXX_DEV_COLD:
4808 if (ha->flags.nic_core_reset_owner)
4809 rval = qla83xx_device_bootstrap(base_vha);
4810 else {
4811 /* Wait for AEN to change device-state */
4812 qla83xx_idc_unlock(base_vha, 0);
4813 msleep(1000);
4814 qla83xx_idc_lock(base_vha, 0);
4815 }
4816 break;
4817 case QLA8XXX_DEV_INITIALIZING:
4818 /* Wait for AEN to change device-state */
4819 qla83xx_idc_unlock(base_vha, 0);
4820 msleep(1000);
4821 qla83xx_idc_lock(base_vha, 0);
4822 break;
4823 case QLA8XXX_DEV_NEED_RESET:
4824 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4825 qla83xx_need_reset_handler(base_vha);
4826 else {
4827 /* Wait for AEN to change device-state */
4828 qla83xx_idc_unlock(base_vha, 0);
4829 msleep(1000);
4830 qla83xx_idc_lock(base_vha, 0);
4831 }
4832 /* reset timeout value after need reset handler */
4833 dev_init_timeout = jiffies +
4834 (ha->fcoe_dev_init_timeout * HZ);
4835 break;
4836 case QLA8XXX_DEV_NEED_QUIESCENT:
4837 /* XXX: DEBUG for now */
4838 qla83xx_idc_unlock(base_vha, 0);
4839 msleep(1000);
4840 qla83xx_idc_lock(base_vha, 0);
4841 break;
4842 case QLA8XXX_DEV_QUIESCENT:
4843 /* XXX: DEBUG for now */
4844 if (ha->flags.quiesce_owner)
4845 goto exit;
4846
4847 qla83xx_idc_unlock(base_vha, 0);
4848 msleep(1000);
4849 qla83xx_idc_lock(base_vha, 0);
4850 dev_init_timeout = jiffies +
4851 (ha->fcoe_dev_init_timeout * HZ);
4852 break;
4853 case QLA8XXX_DEV_FAILED:
4854 if (ha->flags.nic_core_reset_owner)
4855 qla83xx_idc_audit(base_vha,
4856 IDC_AUDIT_COMPLETION);
4857 ha->flags.nic_core_reset_owner = 0;
4858 __qla83xx_clear_drv_presence(base_vha);
4859 qla83xx_idc_unlock(base_vha, 0);
4860 qla8xxx_dev_failed_handler(base_vha);
4861 rval = QLA_FUNCTION_FAILED;
4862 qla83xx_idc_lock(base_vha, 0);
4863 goto exit;
4864 case QLA8XXX_BAD_VALUE:
4865 qla83xx_idc_unlock(base_vha, 0);
4866 msleep(1000);
4867 qla83xx_idc_lock(base_vha, 0);
4868 break;
4869 default:
4870 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09004871 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004872 qla83xx_idc_unlock(base_vha, 0);
4873 qla8xxx_dev_failed_handler(base_vha);
4874 rval = QLA_FUNCTION_FAILED;
4875 qla83xx_idc_lock(base_vha, 0);
4876 goto exit;
4877 }
4878 }
4879
4880exit:
4881 return rval;
4882}
4883
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004884void
4885qla2x00_disable_board_on_pci_error(struct work_struct *work)
4886{
4887 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
4888 board_disable);
4889 struct pci_dev *pdev = ha->pdev;
4890 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4891
4892 ql_log(ql_log_warn, base_vha, 0x015b,
4893 "Disabling adapter.\n");
4894
4895 set_bit(UNLOADING, &base_vha->dpc_flags);
4896
4897 qla2x00_delete_all_vps(ha, base_vha);
4898
4899 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4900
4901 qla2x00_dfs_remove(base_vha);
4902
4903 qla84xx_put_chip(base_vha);
4904
4905 if (base_vha->timer_active)
4906 qla2x00_stop_timer(base_vha);
4907
4908 base_vha->flags.online = 0;
4909
4910 qla2x00_destroy_deferred_work(ha);
4911
4912 /*
4913 * Do not try to stop beacon blink as it will issue a mailbox
4914 * command.
4915 */
4916 qla2x00_free_sysfs_attr(base_vha, false);
4917
4918 fc_remove_host(base_vha->host);
4919
4920 scsi_remove_host(base_vha->host);
4921
4922 base_vha->flags.init_done = 0;
4923 qla25xx_delete_queues(base_vha);
4924 qla2x00_free_irqs(base_vha);
4925 qla2x00_free_fcports(base_vha);
4926 qla2x00_mem_free(ha);
4927 qla82xx_md_free(base_vha);
4928 qla2x00_free_queues(ha);
4929
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004930 qla2x00_unmap_iobases(ha);
4931
4932 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004933 pci_disable_pcie_error_reporting(pdev);
4934 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004935
Joe Lawrencebeb9e312014-08-26 17:12:14 -04004936 /*
4937 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
4938 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004939}
4940
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941/**************************************************************************
4942* qla2x00_do_dpc
4943* This kernel thread is a task that is schedule by the interrupt handler
4944* to perform the background processing for interrupts.
4945*
4946* Notes:
4947* This task always run in the context of a kernel thread. It
4948* is kick-off by the driver's detect code and starts up
4949* up one per adapter. It immediately goes to sleep and waits for
4950* some fibre event. When either the interrupt handler or
4951* the timer routine detects a event it will one of the task
4952* bits then wake us up.
4953**************************************************************************/
4954static int
4955qla2x00_do_dpc(void *data)
4956{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004957 scsi_qla_host_t *base_vha;
4958 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004960 ha = (struct qla_hw_data *)data;
4961 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962
Dongsheng Yang8698a742014-03-11 18:09:12 +08004963 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964
James Bottomley563585e2011-01-27 16:12:37 -05004965 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004966 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004967 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4968 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969
Christoph Hellwig39a11242006-02-14 18:46:22 +01004970 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004972 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4973 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974
Andrew Vasquez85880802009-12-15 21:29:46 -08004975 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004976 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4977 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004978 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004979 }
4980
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 ha->dpc_active = 1;
4982
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004983 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4984 "DPC handler waking up, dpc_flags=0x%lx.\n",
4985 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004987 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004988
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004989 if (IS_P3P_TYPE(ha)) {
4990 if (IS_QLA8044(ha)) {
4991 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4992 &base_vha->dpc_flags)) {
4993 qla8044_idc_lock(ha);
4994 qla8044_wr_direct(base_vha,
4995 QLA8044_CRB_DEV_STATE_INDEX,
4996 QLA8XXX_DEV_FAILED);
4997 qla8044_idc_unlock(ha);
4998 ql_log(ql_log_info, base_vha, 0x4004,
4999 "HW State: FAILED.\n");
5000 qla8044_device_state_handler(base_vha);
5001 continue;
5002 }
5003
5004 } else {
5005 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5006 &base_vha->dpc_flags)) {
5007 qla82xx_idc_lock(ha);
5008 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5009 QLA8XXX_DEV_FAILED);
5010 qla82xx_idc_unlock(ha);
5011 ql_log(ql_log_info, base_vha, 0x0151,
5012 "HW State: FAILED.\n");
5013 qla82xx_device_state_handler(base_vha);
5014 continue;
5015 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005016 }
5017
5018 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5019 &base_vha->dpc_flags)) {
5020
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005021 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5022 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005023 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5024 &base_vha->dpc_flags))) {
5025 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5026 /* FCoE-ctx reset failed.
5027 * Escalate to chip-reset
5028 */
5029 set_bit(ISP_ABORT_NEEDED,
5030 &base_vha->dpc_flags);
5031 }
5032 clear_bit(ABORT_ISP_ACTIVE,
5033 &base_vha->dpc_flags);
5034 }
5035
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005036 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5037 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005038 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005039 } else if (IS_QLAFX00(ha)) {
5040 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5041 &base_vha->dpc_flags)) {
5042 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5043 "Firmware Reset Recovery\n");
5044 if (qlafx00_reset_initialize(base_vha)) {
5045 /* Failed. Abort isp later. */
5046 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005047 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005048 set_bit(ISP_UNRECOVERABLE,
5049 &base_vha->dpc_flags);
5050 ql_dbg(ql_dbg_dpc, base_vha,
5051 0x4021,
5052 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005053 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005054 }
5055 }
5056
5057 if (test_and_clear_bit(FX00_TARGET_SCAN,
5058 &base_vha->dpc_flags)) {
5059 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5060 "ISPFx00 Target Scan scheduled\n");
5061 if (qlafx00_rescan_isp(base_vha)) {
5062 if (!test_bit(UNLOADING,
5063 &base_vha->dpc_flags))
5064 set_bit(ISP_UNRECOVERABLE,
5065 &base_vha->dpc_flags);
5066 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5067 "ISPFx00 Target Scan Failed\n");
5068 }
5069 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5070 "ISPFx00 Target Scan End\n");
5071 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005072 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5073 &base_vha->dpc_flags)) {
5074 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5075 "ISPFx00 Host Info resend scheduled\n");
5076 qlafx00_fx_disc(base_vha,
5077 &base_vha->hw->mr.fcport,
5078 FXDISC_REG_HOST_INFO);
5079 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005080 }
5081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005082 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5083 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005085 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5086 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005088 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089
Giridhar Malavalia9083012010-04-12 17:59:55 -07005090 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 /* failed. retry later */
5092 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005093 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005095 clear_bit(ABORT_ISP_ACTIVE,
5096 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005097 }
5098
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005099 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5100 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 }
5102
David Jefferya394aac2012-11-21 02:39:54 -05005103 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5104 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005105 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005106 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005107
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005108 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
5109 int ret;
5110 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
5111 if (ret != QLA_SUCCESS)
5112 ql_log(ql_log_warn, base_vha, 0x121,
5113 "Failed to enable receiving of RSCN "
5114 "requests: 0x%x.\n", ret);
5115 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
5116 }
5117
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005118 if (IS_QLAFX00(ha))
5119 goto loop_resync_check;
5120
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005121 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005122 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5123 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005124 if (IS_P3P_TYPE(ha)) {
5125 if (IS_QLA82XX(ha))
5126 qla82xx_device_state_handler(base_vha);
5127 if (IS_QLA8044(ha))
5128 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005129 clear_bit(ISP_QUIESCE_NEEDED,
5130 &base_vha->dpc_flags);
5131 if (!ha->flags.quiesce_owner) {
5132 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005133 if (IS_QLA82XX(ha)) {
5134 qla82xx_idc_lock(ha);
5135 qla82xx_clear_qsnt_ready(
5136 base_vha);
5137 qla82xx_idc_unlock(ha);
5138 } else if (IS_QLA8044(ha)) {
5139 qla8044_idc_lock(ha);
5140 qla8044_clear_qsnt_ready(
5141 base_vha);
5142 qla8044_idc_unlock(ha);
5143 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005144 }
5145 } else {
5146 clear_bit(ISP_QUIESCE_NEEDED,
5147 &base_vha->dpc_flags);
5148 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005149 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005150 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5151 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005152 }
5153
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005154 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005155 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005156 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005158 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5159 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005160 qla2x00_rst_aen(base_vha);
5161 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005162 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5163 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 }
5165
5166 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005167 if ((test_and_clear_bit(RELOGIN_NEEDED,
5168 &base_vha->dpc_flags)) &&
5169 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5170 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005172 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5173 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005174 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005175 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5176 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005178loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005179 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005180 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005182 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5183 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184
5185 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005186 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187
Bart Van Assche52c82822015-07-09 07:23:26 -07005188 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005190 clear_bit(LOOP_RESYNC_ACTIVE,
5191 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 }
5193
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005194 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5195 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196 }
5197
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005198 if (IS_QLAFX00(ha))
5199 goto intr_on_check;
5200
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005201 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5202 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5203 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5204 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005205 }
5206
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005207intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005209 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005211 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005212 &base_vha->dpc_flags)) {
5213 if (ha->beacon_blink_led == 1)
5214 ha->isp_ops->beacon_blink(base_vha);
5215 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005216
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005217 if (!IS_QLAFX00(ha))
5218 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005219
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005221end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005222 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005224 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005226 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5227 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228
5229 /*
5230 * Make sure that nobody tries to wake us up again.
5231 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232 ha->dpc_active = 0;
5233
Andrew Vasquezac280b62009-08-20 11:06:05 -07005234 /* Cleanup any residual CTX SRBs. */
5235 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5236
Christoph Hellwig39a11242006-02-14 18:46:22 +01005237 return 0;
5238}
5239
5240void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005241qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005242{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005243 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005244 struct task_struct *t = ha->dpc_thread;
5245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005246 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005247 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248}
5249
5250/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251* qla2x00_rst_aen
5252* Processes asynchronous reset.
5253*
5254* Input:
5255* ha = adapter block pointer.
5256*/
5257static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005258qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005260 if (vha->flags.online && !vha->flags.reset_active &&
5261 !atomic_read(&vha->loop_down_timer) &&
5262 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005264 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265
5266 /*
5267 * Issue marker command only when we are going to start
5268 * the I/O.
5269 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005270 vha->marker_needed = 1;
5271 } while (!atomic_read(&vha->loop_down_timer) &&
5272 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 }
5274}
5275
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276/**************************************************************************
5277* qla2x00_timer
5278*
5279* Description:
5280* One second timer
5281*
5282* Context: Interrupt
5283***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005284void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005285qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 int start_dpc = 0;
5289 int index;
5290 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005291 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005292 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005293 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005294
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005295 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005296 ql_dbg(ql_dbg_timer, vha, 0x6000,
5297 "EEH = %d, restarting timer.\n",
5298 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005299 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5300 return;
5301 }
5302
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005303 /*
5304 * Hardware read to raise pending EEH errors during mailbox waits. If
5305 * the read returns -1 then disable the board.
5306 */
5307 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005308 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005309 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005312 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005313 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005314 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5315 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005316 if (IS_QLA82XX(ha))
5317 qla82xx_watchdog(vha);
5318 else if (IS_QLA8044(ha))
5319 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005320 }
5321
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005322 if (!vha->vp_idx && IS_QLAFX00(ha))
5323 qlafx00_timer_routine(vha);
5324
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005326 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005327 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5328 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005329 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005331 if (atomic_read(&vha->loop_down_timer) ==
5332 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005334 ql_log(ql_log_info, vha, 0x6008,
5335 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005337 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5338 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005340 /*
5341 * Schedule an ISP abort to return any FCP2-device
5342 * commands.
5343 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005344 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005345 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005346 spin_lock_irqsave(&ha->hardware_lock,
5347 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005348 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005349 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005350 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005351 index++) {
5352 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005353
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005354 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005355 if (!sp)
5356 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005357 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005358 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005359 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005360 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005361 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005363 if (IS_QLA82XX(ha))
5364 set_bit(FCOE_CTX_RESET_NEEDED,
5365 &vha->dpc_flags);
5366 else
5367 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005368 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005369 break;
5370 }
5371 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005372 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374 start_dpc++;
5375 }
5376
5377 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005378 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005379 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005380 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 "Loop down - aborting ISP.\n");
5382
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005383 if (IS_QLA82XX(ha))
5384 set_bit(FCOE_CTX_RESET_NEEDED,
5385 &vha->dpc_flags);
5386 else
5387 set_bit(ISP_ABORT_NEEDED,
5388 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 }
5390 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005391 ql_dbg(ql_dbg_timer, vha, 0x600a,
5392 "Loop down - seconds remaining %d.\n",
5393 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005395 /* Check if beacon LED needs to be blinked for physical host only */
5396 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005397 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005398 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005399 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5400 start_dpc++;
5401 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005402 }
5403
Andrew Vasquez550bf572008-04-24 15:21:23 -07005404 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005405 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005406 start_dpc++;
5407
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005409 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5410 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5411 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005413 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5414 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005415 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5416 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005417 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005418 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005419 ql_dbg(ql_dbg_timer, vha, 0x600b,
5420 "isp_abort_needed=%d loop_resync_needed=%d "
5421 "fcport_update_needed=%d start_dpc=%d "
5422 "reset_marker_needed=%d",
5423 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5424 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5425 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5426 start_dpc,
5427 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5428 ql_dbg(ql_dbg_timer, vha, 0x600c,
5429 "beacon_blink_needed=%d isp_unrecoverable=%d "
5430 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005431 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005432 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5433 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5434 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5435 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005436 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005437 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005440 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441}
5442
Andrew Vasquez54333832005-11-09 15:49:04 -08005443/* Firmware interface routines. */
5444
Chad Dupuisf73cb692014-02-26 04:15:06 -05005445#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08005446#define FW_ISP21XX 0
5447#define FW_ISP22XX 1
5448#define FW_ISP2300 2
5449#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005450#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005451#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005452#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005453#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005454#define FW_ISP2031 8
5455#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005456#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005457
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005458#define FW_FILE_ISP21XX "ql2100_fw.bin"
5459#define FW_FILE_ISP22XX "ql2200_fw.bin"
5460#define FW_FILE_ISP2300 "ql2300_fw.bin"
5461#define FW_FILE_ISP2322 "ql2322_fw.bin"
5462#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005463#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005464#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005465#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005466#define FW_FILE_ISP2031 "ql2600_fw.bin"
5467#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005468#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05005469
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005470
Daniel Walkere1e82b62008-05-12 22:21:10 -07005471static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005472
5473static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005474 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5475 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5476 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5477 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5478 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005479 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005480 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005481 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005482 { .name = FW_FILE_ISP2031, },
5483 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005484 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005485};
5486
5487struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005488qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005489{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005490 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005491 struct fw_blob *blob;
5492
Andrew Vasquez54333832005-11-09 15:49:04 -08005493 if (IS_QLA2100(ha)) {
5494 blob = &qla_fw_blobs[FW_ISP21XX];
5495 } else if (IS_QLA2200(ha)) {
5496 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005497 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005498 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005499 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005500 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005501 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005502 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005503 } else if (IS_QLA25XX(ha)) {
5504 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005505 } else if (IS_QLA81XX(ha)) {
5506 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005507 } else if (IS_QLA82XX(ha)) {
5508 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005509 } else if (IS_QLA2031(ha)) {
5510 blob = &qla_fw_blobs[FW_ISP2031];
5511 } else if (IS_QLA8031(ha)) {
5512 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005513 } else if (IS_QLA27XX(ha)) {
5514 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03005515 } else {
5516 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005517 }
5518
Daniel Walkere1e82b62008-05-12 22:21:10 -07005519 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005520 if (blob->fw)
5521 goto out;
5522
5523 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005524 ql_log(ql_log_warn, vha, 0x0063,
5525 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005526 blob->fw = NULL;
5527 blob = NULL;
5528 goto out;
5529 }
5530
5531out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005532 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005533 return blob;
5534}
5535
5536static void
5537qla2x00_release_firmware(void)
5538{
5539 int idx;
5540
Daniel Walkere1e82b62008-05-12 22:21:10 -07005541 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005542 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005543 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005544 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005545}
5546
Seokmann Ju14e660e2007-09-20 14:07:36 -07005547static pci_ers_result_t
5548qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5549{
Andrew Vasquez85880802009-12-15 21:29:46 -08005550 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5551 struct qla_hw_data *ha = vha->hw;
5552
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005553 ql_dbg(ql_dbg_aer, vha, 0x9000,
5554 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005555
Seokmann Ju14e660e2007-09-20 14:07:36 -07005556 switch (state) {
5557 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005558 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005559 return PCI_ERS_RESULT_CAN_RECOVER;
5560 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005561 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005562 /* For ISP82XX complete any pending mailbox cmd */
5563 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005564 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005565 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5566 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005567 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005568 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005569 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005570 /* Return back all IOs */
5571 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005572 return PCI_ERS_RESULT_NEED_RESET;
5573 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005574 ha->flags.pci_channel_io_perm_failure = 1;
5575 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005576 return PCI_ERS_RESULT_DISCONNECT;
5577 }
5578 return PCI_ERS_RESULT_NEED_RESET;
5579}
5580
5581static pci_ers_result_t
5582qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5583{
5584 int risc_paused = 0;
5585 uint32_t stat;
5586 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005587 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5588 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005589 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5590 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5591
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005592 if (IS_QLA82XX(ha))
5593 return PCI_ERS_RESULT_RECOVERED;
5594
Seokmann Ju14e660e2007-09-20 14:07:36 -07005595 spin_lock_irqsave(&ha->hardware_lock, flags);
5596 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5597 stat = RD_REG_DWORD(&reg->hccr);
5598 if (stat & HCCR_RISC_PAUSE)
5599 risc_paused = 1;
5600 } else if (IS_QLA23XX(ha)) {
5601 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5602 if (stat & HSR_RISC_PAUSED)
5603 risc_paused = 1;
5604 } else if (IS_FWI2_CAPABLE(ha)) {
5605 stat = RD_REG_DWORD(&reg24->host_status);
5606 if (stat & HSRX_RISC_PAUSED)
5607 risc_paused = 1;
5608 }
5609 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5610
5611 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005612 ql_log(ql_log_info, base_vha, 0x9003,
5613 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005614 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005615
5616 return PCI_ERS_RESULT_NEED_RESET;
5617 } else
5618 return PCI_ERS_RESULT_RECOVERED;
5619}
5620
Saurav Kashyapfa492632012-11-21 02:40:29 -05005621static uint32_t
5622qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005623{
5624 uint32_t rval = QLA_FUNCTION_FAILED;
5625 uint32_t drv_active = 0;
5626 struct qla_hw_data *ha = base_vha->hw;
5627 int fn;
5628 struct pci_dev *other_pdev = NULL;
5629
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005630 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5631 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005632
5633 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5634
5635 if (base_vha->flags.online) {
5636 /* Abort all outstanding commands,
5637 * so as to be requeued later */
5638 qla2x00_abort_isp_cleanup(base_vha);
5639 }
5640
5641
5642 fn = PCI_FUNC(ha->pdev->devfn);
5643 while (fn > 0) {
5644 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005645 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5646 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005647 other_pdev =
5648 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5649 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5650 fn));
5651
5652 if (!other_pdev)
5653 continue;
5654 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005655 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5656 "Found PCI func available and enable at 0x%x.\n",
5657 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005658 pci_dev_put(other_pdev);
5659 break;
5660 }
5661 pci_dev_put(other_pdev);
5662 }
5663
5664 if (!fn) {
5665 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005666 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5667 "This devfn is reset owner = 0x%x.\n",
5668 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005669 qla82xx_idc_lock(ha);
5670
5671 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005672 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005673
5674 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5675 QLA82XX_IDC_VERSION);
5676
5677 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005678 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5679 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005680
5681 qla82xx_idc_unlock(ha);
5682 /* Reset if device is not already reset
5683 * drv_active would be 0 if a reset has already been done
5684 */
5685 if (drv_active)
5686 rval = qla82xx_start_firmware(base_vha);
5687 else
5688 rval = QLA_SUCCESS;
5689 qla82xx_idc_lock(ha);
5690
5691 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005692 ql_log(ql_log_info, base_vha, 0x900b,
5693 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005694 qla82xx_clear_drv_active(ha);
5695 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005696 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005697 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005698 ql_log(ql_log_info, base_vha, 0x900c,
5699 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005700 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005701 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005702 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005703 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005704 rval = qla82xx_restart_isp(base_vha);
5705 qla82xx_idc_lock(ha);
5706 /* Clear driver state register */
5707 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5708 qla82xx_set_drv_active(base_vha);
5709 }
5710 qla82xx_idc_unlock(ha);
5711 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005712 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5713 "This devfn is not reset owner = 0x%x.\n",
5714 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005715 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005716 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005717 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005718 rval = qla82xx_restart_isp(base_vha);
5719 qla82xx_idc_lock(ha);
5720 qla82xx_set_drv_active(base_vha);
5721 qla82xx_idc_unlock(ha);
5722 }
5723 }
5724 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5725
5726 return rval;
5727}
5728
Seokmann Ju14e660e2007-09-20 14:07:36 -07005729static pci_ers_result_t
5730qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5731{
5732 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005733 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5734 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005735 struct rsp_que *rsp;
5736 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005737
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005738 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5739 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005740
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005741 /* Workaround: qla2xxx driver which access hardware earlier
5742 * needs error state to be pci_channel_io_online.
5743 * Otherwise mailbox command timesout.
5744 */
5745 pdev->error_state = pci_channel_io_normal;
5746
5747 pci_restore_state(pdev);
5748
Richard Lary8c1496b2010-02-18 10:07:29 -08005749 /* pci_restore_state() clears the saved_state flag of the device
5750 * save restored state which resets saved_state flag
5751 */
5752 pci_save_state(pdev);
5753
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005754 if (ha->mem_only)
5755 rc = pci_enable_device_mem(pdev);
5756 else
5757 rc = pci_enable_device(pdev);
5758
5759 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005760 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005761 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005762 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005763 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005764
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005765 rsp = ha->rsp_q_map[0];
5766 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005767 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005768
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005769 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005770 goto exit_slot_reset;
5771
5772 if (IS_QLA82XX(ha)) {
5773 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5774 ret = PCI_ERS_RESULT_RECOVERED;
5775 goto exit_slot_reset;
5776 } else
5777 goto exit_slot_reset;
5778 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005779
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005780 while (ha->flags.mbox_busy && retries--)
5781 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005783 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005784 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005785 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005786 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005787
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005788
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005789exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005790 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5791 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005792
Seokmann Ju14e660e2007-09-20 14:07:36 -07005793 return ret;
5794}
5795
5796static void
5797qla2xxx_pci_resume(struct pci_dev *pdev)
5798{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005799 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5800 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005801 int ret;
5802
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005803 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5804 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005805
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005806 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005807 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005808 ql_log(ql_log_fatal, base_vha, 0x9002,
5809 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005810 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005811
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005812 pci_cleanup_aer_uncorrect_error_status(pdev);
5813
Andrew Vasquez85880802009-12-15 21:29:46 -08005814 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005815}
5816
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04005817static void
5818qla83xx_disable_laser(scsi_qla_host_t *vha)
5819{
5820 uint32_t reg, data, fn;
5821 struct qla_hw_data *ha = vha->hw;
5822 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5823
5824 /* pci func #/port # */
5825 ql_dbg(ql_dbg_init, vha, 0x004b,
5826 "Disabling Laser for hba: %p\n", vha);
5827
5828 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5829 (BIT_15|BIT_14|BIT_13|BIT_12));
5830
5831 fn = (fn >> 12);
5832
5833 if (fn & 1)
5834 reg = PORT_1_2031;
5835 else
5836 reg = PORT_0_2031;
5837
5838 data = LASER_OFF_2031;
5839
5840 qla83xx_wr_reg(vha, reg, data);
5841}
5842
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005843static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005844 .error_detected = qla2xxx_pci_error_detected,
5845 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5846 .slot_reset = qla2xxx_pci_slot_reset,
5847 .resume = qla2xxx_pci_resume,
5848};
5849
Andrew Vasquez54333832005-11-09 15:49:04 -08005850static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005851 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5852 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5853 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5854 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5855 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5856 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5857 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5858 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5859 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005860 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005861 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5862 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005863 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005864 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005865 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005866 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005867 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005868 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005869 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05005870 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005871 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04005872 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005873 { 0 },
5874};
5875MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5876
Andrew Vasquezfca29702005-07-06 10:31:47 -07005877static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005878 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005879 .driver = {
5880 .owner = THIS_MODULE,
5881 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005882 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005883 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005884 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005885 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005886 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005887};
5888
Al Viro75ef9de2013-04-04 19:09:41 -04005889static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005890 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005891 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005892};
5893
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894/**
5895 * qla2x00_module_init - Module initialization.
5896 **/
5897static int __init
5898qla2x00_module_init(void)
5899{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005900 int ret = 0;
5901
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005903 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005904 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005906 ql_log(ql_log_fatal, NULL, 0x0001,
5907 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908 return -ENOMEM;
5909 }
5910
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005911 /* Initialize target kmem_cache and mem_pools */
5912 ret = qlt_init();
5913 if (ret < 0) {
5914 kmem_cache_destroy(srb_cachep);
5915 return ret;
5916 } else if (ret > 0) {
5917 /*
5918 * If initiator mode is explictly disabled by qlt_init(),
5919 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5920 * performing scsi_scan_target() during LOOP UP event.
5921 */
5922 qla2xxx_transport_functions.disable_target_scan = 1;
5923 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5924 }
5925
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 /* Derive version string. */
5927 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005928 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005929 strcat(qla2x00_version_str, "-debug");
5930
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005931 qla2xxx_transport_template =
5932 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005933 if (!qla2xxx_transport_template) {
5934 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005935 ql_log(ql_log_fatal, NULL, 0x0002,
5936 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005937 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005939 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005940
5941 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5942 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005943 ql_log(ql_log_fatal, NULL, 0x0003,
5944 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005945 }
5946
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005947 qla2xxx_transport_vport_template =
5948 fc_attach_transport(&qla2xxx_transport_vport_functions);
5949 if (!qla2xxx_transport_vport_template) {
5950 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005951 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005952 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005953 ql_log(ql_log_fatal, NULL, 0x0004,
5954 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005955 return -ENODEV;
5956 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005957 ql_log(ql_log_info, NULL, 0x0005,
5958 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005959 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005960 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005961 if (ret) {
5962 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005963 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005964 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005965 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005966 ql_log(ql_log_fatal, NULL, 0x0006,
5967 "pci_register_driver failed...ret=%d Failing load!.\n",
5968 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005969 }
5970 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971}
5972
5973/**
5974 * qla2x00_module_exit - Module cleanup.
5975 **/
5976static void __exit
5977qla2x00_module_exit(void)
5978{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005979 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005980 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005981 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005982 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005983 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005984 if (ctx_cachep)
5985 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005987 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988}
5989
5990module_init(qla2x00_module_init);
5991module_exit(qla2x00_module_exit);
5992
5993MODULE_AUTHOR("QLogic Corporation");
5994MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5995MODULE_LICENSE("GPL");
5996MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005997MODULE_FIRMWARE(FW_FILE_ISP21XX);
5998MODULE_FIRMWARE(FW_FILE_ISP22XX);
5999MODULE_FIRMWARE(FW_FILE_ISP2300);
6000MODULE_FIRMWARE(FW_FILE_ISP2322);
6001MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006002MODULE_FIRMWARE(FW_FILE_ISP25XX);
Sawan Chandakf1458cd2015-04-09 14:59:59 -04006003MODULE_FIRMWARE(FW_FILE_ISP2031);
6004MODULE_FIRMWARE(FW_FILE_ISP8031);
6005MODULE_FIRMWARE(FW_FILE_ISP27XX);