blob: 3c4af7e1055083c1a48e27f2206c7b00d166a5eb [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700231 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 */
233static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500234static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800235static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
236static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500237static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500238static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static int qla2xxx_eh_abort(struct scsi_cmnd *);
240static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700241static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
243static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400245static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400246static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400247static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700248
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700249struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700251 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700252 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700253
254 .eh_abort_handler = qla2xxx_eh_abort,
255 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700256 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700257 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
258 .eh_host_reset_handler = qla2xxx_eh_host_reset,
259
260 .slave_configure = qla2xxx_slave_configure,
261
262 .slave_alloc = qla2xxx_slave_alloc,
263 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700264 .scan_finished = qla2xxx_scan_finished,
265 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100266 .change_queue_depth = scsi_change_queue_depth,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700267 .this_id = -1,
268 .cmd_per_lun = 3,
269 .use_clustering = ENABLE_CLUSTERING,
270 .sg_tablesize = SG_ALL,
271
272 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700273 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400274
275 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100276 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700277};
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700280struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282/* TODO Convert to inlines
283 *
284 * Timer routines
285 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700287__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800288qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800290 init_timer(&vha->timer);
291 vha->timer.expires = jiffies + interval * HZ;
292 vha->timer.data = (unsigned long)vha;
293 vha->timer.function = (void (*)(unsigned long))func;
294 add_timer(&vha->timer);
295 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
298static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800299qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700301 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700302 if (vha->device_flags & DFLG_DEV_FAILED) {
303 ql_dbg(ql_dbg_timer, vha, 0x600d,
304 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700305 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700306 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800308 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Adrian Bunka824ebb2008-01-17 09:02:15 -0800311static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800312qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800314 del_timer_sync(&vha->timer);
315 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318static int qla2x00_do_dpc(void *data);
319
320static void qla2x00_rst_aen(scsi_qla_host_t *);
321
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800322static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
323 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700324static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800325static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400328static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
329 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800330{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700331 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700332 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800333 GFP_KERNEL);
334 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700335 ql_log(ql_log_fatal, vha, 0x003b,
336 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800337 goto fail_req_map;
338 }
339
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700340 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800341 GFP_KERNEL);
342 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700343 ql_log(ql_log_fatal, vha, 0x003c,
344 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800345 goto fail_rsp_map;
346 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400347 /*
348 * Make sure we record at least the request and response queue zero in
349 * case we need to free them if part of the probe fails.
350 */
351 ha->rsp_q_map[0] = rsp;
352 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800353 set_bit(0, ha->rsp_qid_map);
354 set_bit(0, ha->req_qid_map);
355 return 1;
356
357fail_rsp_map:
358 kfree(ha->req_q_map);
359 ha->req_q_map = NULL;
360fail_req_map:
361 return -ENOMEM;
362}
363
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700364static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800365{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400366 if (IS_QLAFX00(ha)) {
367 if (req && req->ring_fx00)
368 dma_free_coherent(&ha->pdev->dev,
369 (req->length_fx00 + 1) * sizeof(request_t),
370 req->ring_fx00, req->dma_fx00);
371 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800372 dma_free_coherent(&ha->pdev->dev,
373 (req->length + 1) * sizeof(request_t),
374 req->ring, req->dma);
375
Chad Dupuis8d93f552013-01-30 03:34:37 -0500376 if (req)
377 kfree(req->outstanding_cmds);
378
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800379 kfree(req);
380 req = NULL;
381}
382
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700383static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
384{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400385 if (IS_QLAFX00(ha)) {
386 if (rsp && rsp->ring)
387 dma_free_coherent(&ha->pdev->dev,
388 (rsp->length_fx00 + 1) * sizeof(request_t),
389 rsp->ring_fx00, rsp->dma_fx00);
390 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700391 dma_free_coherent(&ha->pdev->dev,
392 (rsp->length + 1) * sizeof(response_t),
393 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400394 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700395 kfree(rsp);
396 rsp = NULL;
397}
398
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800399static void qla2x00_free_queues(struct qla_hw_data *ha)
400{
401 struct req_que *req;
402 struct rsp_que *rsp;
403 int cnt;
404
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700405 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800406 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700407 qla2x00_free_req_que(ha, req);
408 }
409 kfree(ha->req_q_map);
410 ha->req_q_map = NULL;
411
412 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
413 rsp = ha->rsp_q_map[cnt];
414 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415 }
416 kfree(ha->rsp_q_map);
417 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800418}
419
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700420static int qla25xx_setup_mode(struct scsi_qla_host *vha)
421{
422 uint16_t options = 0;
423 int ques, req, ret;
424 struct qla_hw_data *ha = vha->hw;
425
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700426 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700427 ql_log(ql_log_warn, vha, 0x00d8,
428 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700429 goto fail;
430 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700431 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700432 /* create a request queue for IO */
433 options |= BIT_7;
434 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
435 QLA_DEFAULT_QUE_QOS);
436 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700437 ql_log(ql_log_warn, vha, 0x00e0,
438 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700439 goto fail;
440 }
Tejun Heo278274d2011-02-01 11:42:42 +0100441 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700442 vha->req = ha->req_q_map[req];
443 options |= BIT_1;
444 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
445 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
446 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700447 ql_log(ql_log_warn, vha, 0x00e8,
448 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700449 goto fail2;
450 }
451 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700452 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700453 ql_dbg(ql_dbg_multiq, vha, 0xc007,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100454 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700455 "no. of response queues:%d no. of request queues:%d.\n",
456 ha->max_rsp_queues, ha->max_req_queues);
457 ql_dbg(ql_dbg_init, vha, 0x00e9,
Yannick Guerrini6ef68da2015-02-23 23:26:50 +0100458 "CPU affinity mode enabled, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700459 "no. of response queues:%d no. of request queues:%d.\n",
460 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700461 }
462 return 0;
463fail2:
464 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700465 destroy_workqueue(ha->wq);
466 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800467 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700468fail:
469 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700470 kfree(ha->req_q_map);
471 kfree(ha->rsp_q_map);
472 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700473 return 1;
474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800477qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 static char *pci_bus_modes[] = {
481 "33", "66", "100", "133",
482 };
483 uint16_t pci_bus;
484
485 strcpy(str, "PCI");
486 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
487 if (pci_bus) {
488 strcat(str, "-X (");
489 strcat(str, pci_bus_modes[pci_bus]);
490 } else {
491 pci_bus = (ha->pci_attr & BIT_8) >> 8;
492 strcat(str, " (");
493 strcat(str, pci_bus_modes[pci_bus]);
494 }
495 strcat(str, " MHz)");
496
497 return (str);
498}
499
Andrew Vasquezfca29702005-07-06 10:31:47 -0700500static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700502{
503 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700505 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600507 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700508 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600509 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700510
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600511 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
512 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
513 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700514
515 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500516 switch (lspeed) {
517 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700518 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500519 break;
520 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700521 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500522 break;
523 case 3:
524 strcat(str, "8.0GT/s ");
525 break;
526 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700527 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500528 break;
529 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700530 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
531 strcat(str, lwstr);
532
533 return str;
534 }
535
536 strcpy(str, "PCI");
537 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
538 if (pci_bus == 0 || pci_bus == 8) {
539 strcat(str, " (");
540 strcat(str, pci_bus_modes[pci_bus >> 3]);
541 } else {
542 strcat(str, "-X ");
543 if (pci_bus & BIT_2)
544 strcat(str, "Mode 2");
545 else
546 strcat(str, "Mode 1");
547 strcat(str, " (");
548 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
549 }
550 strcat(str, " MHz)");
551
552 return str;
553}
554
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800555static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400556qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800559 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700560
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400561 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
562 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 if (ha->fw_attributes & BIT_9) {
565 strcat(str, "FLX");
566 return (str);
567 }
568
569 switch (ha->fw_attributes & 0xFF) {
570 case 0x7:
571 strcat(str, "EF");
572 break;
573 case 0x17:
574 strcat(str, "TP");
575 break;
576 case 0x37:
577 strcat(str, "IP");
578 break;
579 case 0x77:
580 strcat(str, "VI");
581 break;
582 default:
583 sprintf(un_str, "(%x)", ha->fw_attributes);
584 strcat(str, un_str);
585 break;
586 }
587 if (ha->fw_attributes & 0x100)
588 strcat(str, "X");
589
590 return (str);
591}
592
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800593static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400594qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700595{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700597
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400598 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800599 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700600 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700601}
602
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800603void
604qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700605{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800606 srb_t *sp = (srb_t *)ptr;
607 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
608 struct qla_hw_data *ha = sp->fcport->vha->hw;
609 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700610
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800611 if (sp->flags & SRB_DMA_VALID) {
612 scsi_dma_unmap(cmd);
613 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700614 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700615
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800616 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
617 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
618 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
619 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
620 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700621
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800622 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
623 /* List assured to be having elements */
Quinn Tranf83adb62014-04-11 16:54:43 -0400624 qla2x00_clean_dsd_pool(ha, sp, NULL);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800625 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
626 }
627
628 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
629 dma_pool_free(ha->dl_dma_pool, ctx,
630 ((struct crc_context *)ctx)->crc_ctx_dma);
631 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
632 }
633
634 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
635 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
636
637 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
638 ctx1->fcp_cmnd_dma);
639 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
640 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
641 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
642 mempool_free(ctx1, ha->ctx_mempool);
643 ctx1 = NULL;
644 }
645
646 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500647 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800648}
649
Fengguang Wu14b06802013-04-25 01:29:19 -0400650static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800651qla2x00_sp_compl(void *data, void *ptr, int res)
652{
653 struct qla_hw_data *ha = (struct qla_hw_data *)data;
654 srb_t *sp = (srb_t *)ptr;
655 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
656
657 cmd->result = res;
658
659 if (atomic_read(&sp->ref_count) == 0) {
660 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
661 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
662 sp, GET_CMD_SP(sp));
663 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400664 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800665 return;
666 }
667 if (!atomic_dec_and_test(&sp->ref_count))
668 return;
669
670 qla2x00_sp_free_dma(ha, sp);
671 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700672}
673
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400674/* If we are SP1 here, we need to still take and release the host_lock as SP1
675 * does not have the changes necessary to avoid taking host->host_lock.
676 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800678qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700679{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700680 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700681 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400682 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800683 struct qla_hw_data *ha = vha->hw;
684 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700685 srb_t *sp;
686 int rval;
687
Andrew Vasquez85880802009-12-15 21:29:46 -0800688 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700689 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400690 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 "PCI Channel IO permanent failure, exiting "
692 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700693 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400695 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700696 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800697 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700698 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700699 goto qc24_fail_command;
700 }
701
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400702 rval = fc_remote_port_chkready(rport);
703 if (rval) {
704 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400705 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700706 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
707 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700708 goto qc24_fail_command;
709 }
710
Arun Easibad75002010-05-04 15:01:30 -0700711 if (!vha->flags.difdix_supported &&
712 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700713 ql_dbg(ql_dbg_io, vha, 0x3004,
714 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
715 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700716 cmd->result = DID_NO_CONNECT << 16;
717 goto qc24_fail_command;
718 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800719
720 if (!fcport) {
721 cmd->result = DID_NO_CONNECT << 16;
722 goto qc24_fail_command;
723 }
724
Andrew Vasquezfca29702005-07-06 10:31:47 -0700725 if (atomic_read(&fcport->state) != FCS_ONLINE) {
726 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700727 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700728 ql_dbg(ql_dbg_io, vha, 0x3005,
729 "Returning DNC, fcport_state=%d loop_state=%d.\n",
730 atomic_read(&fcport->state),
731 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700732 cmd->result = DID_NO_CONNECT << 16;
733 goto qc24_fail_command;
734 }
Mike Christie7b594132008-08-17 15:24:40 -0500735 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700736 }
737
Chad Dupuise05fe292014-09-25 05:16:59 -0400738 /*
739 * Return target busy if we've received a non-zero retry_delay_timer
740 * in a FCP_RSP.
741 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100742 if (fcport->retry_delay_timestamp == 0) {
743 /* retry delay not set */
744 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400745 fcport->retry_delay_timestamp = 0;
746 else
747 goto qc24_target_busy;
748
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500749 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400750 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800751 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700752
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800753 sp->u.scmd.cmd = cmd;
754 sp->type = SRB_SCSI_CMD;
755 atomic_set(&sp->ref_count, 1);
756 CMD_SP(cmd) = (void *)sp;
757 sp->free = qla2x00_sp_free_dma;
758 sp->done = qla2x00_sp_compl;
759
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800760 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700761 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500762 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700763 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700764 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700765 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700766
Andrew Vasquezfca29702005-07-06 10:31:47 -0700767 return 0;
768
769qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800770 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700771
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800772qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700773 return SCSI_MLQUEUE_HOST_BUSY;
774
Mike Christie7b594132008-08-17 15:24:40 -0500775qc24_target_busy:
776 return SCSI_MLQUEUE_TARGET_BUSY;
777
Andrew Vasquezfca29702005-07-06 10:31:47 -0700778qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800779 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700780
781 return 0;
782}
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784/*
785 * qla2x00_eh_wait_on_command
786 * Waits for the command to be returned by the Firmware for some
787 * max time.
788 *
789 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 *
792 * Return:
793 * Not Found : 0
794 * Found : 1
795 */
796static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800797qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700799#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -0400800#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500801 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800802 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
803 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500804 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Andrew Vasquez85880802009-12-15 21:29:46 -0800806 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700807 ql_dbg(ql_dbg_taskm, vha, 0x8005,
808 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800809 return ret;
810 }
811
Lalit Chandivaded9704322009-08-25 11:36:18 -0700812 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700813 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500814 }
815 if (CMD_SP(cmd))
816 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
f4f051e2005-04-17 15:02:26 -0500818 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
821/*
822 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700823 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 * <= MAX_RETRIES_OF_ISP_ABORT or
825 * finally HBA is disabled ie marked offline
826 *
827 * Input:
828 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700829 *
830 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 * Does context switching-Release SPIN_LOCK
832 * (if any) before calling this routine.
833 *
834 * Return:
835 * Success (Adapter is online) : 0
836 * Failed (Adapter is offline/disabled) : 1
837 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800838int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800839qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700841 int return_status;
842 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800843 struct qla_hw_data *ha = vha->hw;
844 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700846 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800847 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
848 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
849 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
850 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 msleep(1000);
853 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700855 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 else
857 return_status = QLA_FUNCTION_FAILED;
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 return (return_status);
860}
861
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700862/*
Sawan Chandak638a1a02014-04-11 16:54:38 -0400863 * qla2x00_wait_for_hba_ready
864 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700865 *
866 * Input:
867 * ha - pointer to host adapter structure
868 *
869 * Note:
870 * Does context switching-Release SPIN_LOCK
871 * (if any) before calling this routine.
872 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700873 */
Sawan Chandak638a1a02014-04-11 16:54:38 -0400874static void
875qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700876{
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700877 struct qla_hw_data *ha = vha->hw;
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700878
Sawan Chandak9d35894d2014-09-25 05:16:52 -0400879 while (((qla2x00_reset_active(vha)) || ha->dpc_active ||
880 ha->flags.mbox_busy) ||
881 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
882 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags))
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700883 msleep(1000);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700884}
885
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700886int
887qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
888{
889 int return_status;
890 unsigned long wait_reset;
891 struct qla_hw_data *ha = vha->hw;
892 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
893
894 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
895 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
896 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
897 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
898 ha->dpc_active) && time_before(jiffies, wait_reset)) {
899
900 msleep(1000);
901
902 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
903 ha->flags.chip_reset_done)
904 break;
905 }
906 if (ha->flags.chip_reset_done)
907 return_status = QLA_SUCCESS;
908 else
909 return_status = QLA_FUNCTION_FAILED;
910
911 return return_status;
912}
913
Giridhar Malavali083a4692010-05-28 15:08:18 -0700914static void
915sp_get(struct srb *sp)
916{
917 atomic_inc(&sp->ref_count);
918}
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920/**************************************************************************
921* qla2xxx_eh_abort
922*
923* Description:
924* The abort function will abort the specified command.
925*
926* Input:
927* cmd = Linux SCSI command packet to be aborted.
928*
929* Returns:
930* Either SUCCESS or FAILED.
931*
932* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700933* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800935static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936qla2xxx_eh_abort(struct scsi_cmnd *cmd)
937{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800938 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500939 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800940 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200941 unsigned int id;
942 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700943 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400944 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800945 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
f4f051e2005-04-17 15:02:26 -0500947 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700948 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800950 ret = fc_block_scsi_eh(cmd);
951 if (ret != 0)
952 return ret;
953 ret = SUCCESS;
954
f4f051e2005-04-17 15:02:26 -0500955 id = cmd->device->id;
956 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500957
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800958 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700959 sp = (srb_t *) CMD_SP(cmd);
960 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800961 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700962 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500963 }
Mike Christie170babc2010-10-15 11:27:47 -0700964
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700965 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -0400966 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
967 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -0700968
969 /* Get a reference to the sp and drop the lock.*/
970 sp_get(sp);
971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800972 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400973 rval = ha->isp_ops->abort_command(sp);
974 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -0400975 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400976 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -0400977 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400978 ret = FAILED;
979
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700980 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400981 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -0700982 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700983 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800984 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700985 wait = 1;
986 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700987
988 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800989 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700990 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500991
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700992 /* Did the command return during mailbox execution? */
993 if (ret == FAILED && !CMD_SP(cmd))
994 ret = SUCCESS;
995
f4f051e2005-04-17 15:02:26 -0500996 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700997 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800998 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700999 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001000 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001001 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001002 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001005 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001006 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001007 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
f4f051e2005-04-17 15:02:26 -05001009 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001012int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001014 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001016 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001017 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001019 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001020 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001021 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Andrew Vasquez523ec772008-04-03 13:13:24 -07001023 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001025 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001026 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001027 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001028 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001029 sp = req->outstanding_cmds[cnt];
1030 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001031 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001032 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001033 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001034 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1035 continue;
1036 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001037 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001038 switch (type) {
1039 case WAIT_HOST:
1040 match = 1;
1041 break;
1042 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001043 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001044 break;
1045 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001046 match = (cmd->device->id == t &&
1047 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001048 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001050 if (!match)
1051 continue;
1052
1053 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001054 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001055 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001058
1059 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Andrew Vasquez523ec772008-04-03 13:13:24 -07001062static char *reset_errors[] = {
1063 "HBA not online",
1064 "HBA not ready",
1065 "Task management failed",
1066 "Waiting for command completions",
1067};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Andrew Vasquez523ec772008-04-03 13:13:24 -07001069static int
1070__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001071 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001072{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001074 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1075 int err;
1076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001077 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001078 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001079 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001080
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001081 err = fc_block_scsi_eh(cmd);
1082 if (err != 0)
1083 return err;
1084
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001085 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001086 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001087 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001088
1089 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001090 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1091 ql_log(ql_log_warn, vha, 0x800a,
1092 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001093 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001094 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001095 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001096 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001097 != QLA_SUCCESS) {
1098 ql_log(ql_log_warn, vha, 0x800c,
1099 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001100 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001102 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001103 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001104 cmd->device->lun, type) != QLA_SUCCESS) {
1105 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001106 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001107 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001108 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001109
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001110 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001111 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001112 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001113
1114 return SUCCESS;
1115
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001116eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001117 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001118 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001119 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1120 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001121 return FAILED;
1122}
1123
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001124static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1126{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1128 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Andrew Vasquez523ec772008-04-03 13:13:24 -07001130 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1131 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001135qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001137 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1138 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Andrew Vasquez523ec772008-04-03 13:13:24 -07001140 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1141 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144/**************************************************************************
1145* qla2xxx_eh_bus_reset
1146*
1147* Description:
1148* The bus reset function will reset the bus and abort any executing
1149* commands.
1150*
1151* Input:
1152* cmd = Linux SCSI command packet of the command that cause the
1153* bus reset.
1154*
1155* Returns:
1156* SUCCESS/FAILURE (defined as macro in scsi.h).
1157*
1158**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001159static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1161{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001162 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001163 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001164 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001165 unsigned int id;
1166 uint64_t lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
f4f051e2005-04-17 15:02:26 -05001168 id = cmd->device->id;
1169 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001170
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001171 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001172 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001175 ret = fc_block_scsi_eh(cmd);
1176 if (ret != 0)
1177 return ret;
1178 ret = FAILED;
1179
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001180 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001181 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001184 ql_log(ql_log_fatal, vha, 0x8013,
1185 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001186 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
1188
Saurav Kashyapad537682011-11-18 09:02:09 -08001189 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1190 ret = SUCCESS;
1191
f4f051e2005-04-17 15:02:26 -05001192 if (ret == FAILED)
1193 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001195 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001196 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001197 QLA_SUCCESS) {
1198 ql_log(ql_log_warn, vha, 0x8014,
1199 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001200 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
f4f051e2005-04-17 15:02:26 -05001203eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001204 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001205 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001206 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
f4f051e2005-04-17 15:02:26 -05001208 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
1211/**************************************************************************
1212* qla2xxx_eh_host_reset
1213*
1214* Description:
1215* The reset function will reset the Adapter.
1216*
1217* Input:
1218* cmd = Linux SCSI command packet of the command that cause the
1219* adapter reset.
1220*
1221* Returns:
1222* Either SUCCESS or FAILED.
1223*
1224* Note:
1225**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001226static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1228{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001229 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001230 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001231 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001232 unsigned int id;
1233 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001234 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
f4f051e2005-04-17 15:02:26 -05001236 id = cmd->device->id;
1237 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001238
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001239 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001240 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Chad Dupuis63ee7072014-04-11 16:54:46 -04001242 /*
1243 * No point in issuing another reset if one is active. Also do not
1244 * attempt a reset if we are updating flash.
1245 */
1246 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001247 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001249 if (vha != base_vha) {
1250 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001251 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001252 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001253 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001254 if (!qla82xx_fcoe_ctx_reset(vha)) {
1255 /* Ctx reset success */
1256 ret = SUCCESS;
1257 goto eh_host_reset_lock;
1258 }
1259 /* fall thru if ctx reset failed */
1260 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001261 if (ha->wq)
1262 flush_workqueue(ha->wq);
1263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001265 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001266 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1267 /* failed. schedule dpc to try */
1268 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1269
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001270 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1271 ql_log(ql_log_warn, vha, 0x802a,
1272 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001273 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001274 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001275 }
1276 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001280 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001282 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
f4f051e2005-04-17 15:02:26 -05001284eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001285 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001286 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001287 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
f4f051e2005-04-17 15:02:26 -05001289 return ret;
1290}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292/*
1293* qla2x00_loop_reset
1294* Issue loop reset.
1295*
1296* Input:
1297* ha = adapter block pointer.
1298*
1299* Returns:
1300* 0 = success
1301*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001302int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001303qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001305 int ret;
bdf79622005-04-17 15:06:53 -05001306 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Armen Baloyan58547712013-08-27 01:37:33 -04001309 if (IS_QLAFX00(ha)) {
1310 return qlafx00_loop_reset(vha);
1311 }
1312
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001313 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001314 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1315 if (fcport->port_type != FCT_TARGET)
1316 continue;
1317
1318 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1319 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001320 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001321 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001322 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001323 }
1324 }
1325 }
1326
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001327
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001328 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001329 atomic_set(&vha->loop_state, LOOP_DOWN);
1330 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1331 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001332 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001333 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001334 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1335 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001339 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001341 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1343 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001344 }
1345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001347 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001349 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001352void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001354{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001355 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001356 unsigned long flags;
1357 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001358 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001359 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001360
Arun Easic0cb4492014-09-25 06:14:51 -04001361 qlt_host_reset_handler(ha);
1362
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001363 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001364 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001365 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001366 if (!req)
1367 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001368 if (!req->outstanding_cmds)
1369 continue;
1370 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001371 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001372 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001373 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001374 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001375 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001376 }
1377 }
1378 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1379}
1380
f4f051e2005-04-17 15:02:26 -05001381static int
1382qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
bdf79622005-04-17 15:06:53 -05001384 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001386 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001387 return -ENXIO;
1388
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001389 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001390
1391 return 0;
1392}
1393
1394static int
1395qla2xxx_slave_configure(struct scsi_device *sdev)
1396{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001397 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001398 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001399
Arun Easi9e522cd2012-08-22 14:21:31 -04001400 if (IS_T10_PI_CAPABLE(vha->hw))
1401 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1402
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001403 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001404 return 0;
1405}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
f4f051e2005-04-17 15:02:26 -05001407static void
1408qla2xxx_slave_destroy(struct scsi_device *sdev)
1409{
1410 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
1413/**
1414 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1415 * @ha: HA context
1416 *
1417 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1418 * supported addressing method.
1419 */
1420static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001421qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001423 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Yang Hongyang6a355282009-04-06 19:01:13 -07001426 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001427 /* Any upper-dword bits set? */
1428 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001429 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001430 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001432 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1433 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001434 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001437
Yang Hongyang284901a2009-04-06 19:01:15 -07001438 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1439 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440}
1441
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001442static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001443qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001444{
1445 unsigned long flags = 0;
1446 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1447
1448 spin_lock_irqsave(&ha->hardware_lock, flags);
1449 ha->interrupts_on = 1;
1450 /* enable risc and host interrupts */
1451 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1452 RD_REG_WORD(&reg->ictrl);
1453 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1454
1455}
1456
1457static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001458qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001459{
1460 unsigned long flags = 0;
1461 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1462
1463 spin_lock_irqsave(&ha->hardware_lock, flags);
1464 ha->interrupts_on = 0;
1465 /* disable risc and host interrupts */
1466 WRT_REG_WORD(&reg->ictrl, 0);
1467 RD_REG_WORD(&reg->ictrl);
1468 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1469}
1470
1471static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001473{
1474 unsigned long flags = 0;
1475 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1476
1477 spin_lock_irqsave(&ha->hardware_lock, flags);
1478 ha->interrupts_on = 1;
1479 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1480 RD_REG_DWORD(&reg->ictrl);
1481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1482}
1483
1484static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001486{
1487 unsigned long flags = 0;
1488 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1489
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001490 if (IS_NOPOLLING_TYPE(ha))
1491 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001492 spin_lock_irqsave(&ha->hardware_lock, flags);
1493 ha->interrupts_on = 0;
1494 WRT_REG_DWORD(&reg->ictrl, 0);
1495 RD_REG_DWORD(&reg->ictrl);
1496 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1497}
1498
Giridhar Malavali706f4572011-11-18 09:03:16 -08001499static int
1500qla2x00_iospace_config(struct qla_hw_data *ha)
1501{
1502 resource_size_t pio;
1503 uint16_t msix;
1504 int cpus;
1505
Giridhar Malavali706f4572011-11-18 09:03:16 -08001506 if (pci_request_selected_regions(ha->pdev, ha->bars,
1507 QLA2XXX_DRIVER_NAME)) {
1508 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1509 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1510 pci_name(ha->pdev));
1511 goto iospace_error_exit;
1512 }
1513 if (!(ha->bars & 1))
1514 goto skip_pio;
1515
1516 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1517 pio = pci_resource_start(ha->pdev, 0);
1518 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1519 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1520 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1521 "Invalid pci I/O region size (%s).\n",
1522 pci_name(ha->pdev));
1523 pio = 0;
1524 }
1525 } else {
1526 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1527 "Region #0 no a PIO resource (%s).\n",
1528 pci_name(ha->pdev));
1529 pio = 0;
1530 }
1531 ha->pio_address = pio;
1532 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1533 "PIO address=%llu.\n",
1534 (unsigned long long)ha->pio_address);
1535
1536skip_pio:
1537 /* Use MMIO operations for all accesses. */
1538 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1539 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1540 "Region #1 not an MMIO resource (%s), aborting.\n",
1541 pci_name(ha->pdev));
1542 goto iospace_error_exit;
1543 }
1544 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1545 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1546 "Invalid PCI mem region size (%s), aborting.\n",
1547 pci_name(ha->pdev));
1548 goto iospace_error_exit;
1549 }
1550
1551 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1552 if (!ha->iobase) {
1553 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1554 "Cannot remap MMIO (%s), aborting.\n",
1555 pci_name(ha->pdev));
1556 goto iospace_error_exit;
1557 }
1558
1559 /* Determine queue resources */
1560 ha->max_req_queues = ha->max_rsp_queues = 1;
1561 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1562 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1563 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1564 goto mqiobase_exit;
1565
1566 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1567 pci_resource_len(ha->pdev, 3));
1568 if (ha->mqiobase) {
1569 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1570 "MQIO Base=%p.\n", ha->mqiobase);
1571 /* Read MSIX vector size of the board */
1572 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1573 ha->msix_count = msix;
1574 /* Max queues are bounded by available msix vectors */
1575 /* queue 0 uses two msix vectors */
1576 if (ql2xmultique_tag) {
1577 cpus = num_online_cpus();
1578 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1579 (cpus + 1) : (ha->msix_count - 1);
1580 ha->max_req_queues = 2;
1581 } else if (ql2xmaxqueues > 1) {
1582 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1583 QLA_MQ_SIZE : ql2xmaxqueues;
1584 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1585 "QoS mode set, max no of request queues:%d.\n",
1586 ha->max_req_queues);
1587 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1588 "QoS mode set, max no of request queues:%d.\n",
1589 ha->max_req_queues);
1590 }
1591 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1592 "MSI-X vector count: %d.\n", msix);
1593 } else
1594 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1595 "BAR 3 not enabled.\n");
1596
1597mqiobase_exit:
1598 ha->msix_count = ha->max_rsp_queues + 1;
1599 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1600 "MSIX Count:%d.\n", ha->msix_count);
1601 return (0);
1602
1603iospace_error_exit:
1604 return (-ENOMEM);
1605}
1606
1607
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001608static int
1609qla83xx_iospace_config(struct qla_hw_data *ha)
1610{
1611 uint16_t msix;
1612 int cpus;
1613
1614 if (pci_request_selected_regions(ha->pdev, ha->bars,
1615 QLA2XXX_DRIVER_NAME)) {
1616 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1617 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1618 pci_name(ha->pdev));
1619
1620 goto iospace_error_exit;
1621 }
1622
1623 /* Use MMIO operations for all accesses. */
1624 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1625 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1626 "Invalid pci I/O region size (%s).\n",
1627 pci_name(ha->pdev));
1628 goto iospace_error_exit;
1629 }
1630 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1631 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1632 "Invalid PCI mem region size (%s), aborting\n",
1633 pci_name(ha->pdev));
1634 goto iospace_error_exit;
1635 }
1636
1637 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1638 if (!ha->iobase) {
1639 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1640 "Cannot remap MMIO (%s), aborting.\n",
1641 pci_name(ha->pdev));
1642 goto iospace_error_exit;
1643 }
1644
1645 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1646 /* 83XX 26XX always use MQ type access for queues
1647 * - mbar 2, a.k.a region 4 */
1648 ha->max_req_queues = ha->max_rsp_queues = 1;
1649 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1650 pci_resource_len(ha->pdev, 4));
1651
1652 if (!ha->mqiobase) {
1653 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1654 "BAR2/region4 not enabled\n");
1655 goto mqiobase_exit;
1656 }
1657
1658 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1659 pci_resource_len(ha->pdev, 2));
1660 if (ha->msixbase) {
1661 /* Read MSIX vector size of the board */
1662 pci_read_config_word(ha->pdev,
1663 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1664 ha->msix_count = msix;
1665 /* Max queues are bounded by available msix vectors */
1666 /* queue 0 uses two msix vectors */
1667 if (ql2xmultique_tag) {
1668 cpus = num_online_cpus();
1669 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1670 (cpus + 1) : (ha->msix_count - 1);
1671 ha->max_req_queues = 2;
1672 } else if (ql2xmaxqueues > 1) {
1673 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1674 QLA_MQ_SIZE : ql2xmaxqueues;
1675 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1676 "QoS mode set, max no of request queues:%d.\n",
1677 ha->max_req_queues);
1678 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1679 "QoS mode set, max no of request queues:%d.\n",
1680 ha->max_req_queues);
1681 }
1682 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1683 "MSI-X vector count: %d.\n", msix);
1684 } else
1685 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1686 "BAR 1 not enabled.\n");
1687
1688mqiobase_exit:
1689 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001690
1691 qlt_83xx_iospace_config(ha);
1692
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001693 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1694 "MSIX Count:%d.\n", ha->msix_count);
1695 return 0;
1696
1697iospace_error_exit:
1698 return -ENOMEM;
1699}
1700
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001701static struct isp_operations qla2100_isp_ops = {
1702 .pci_config = qla2100_pci_config,
1703 .reset_chip = qla2x00_reset_chip,
1704 .chip_diag = qla2x00_chip_diag,
1705 .config_rings = qla2x00_config_rings,
1706 .reset_adapter = qla2x00_reset_adapter,
1707 .nvram_config = qla2x00_nvram_config,
1708 .update_fw_options = qla2x00_update_fw_options,
1709 .load_risc = qla2x00_load_risc,
1710 .pci_info_str = qla2x00_pci_info_str,
1711 .fw_version_str = qla2x00_fw_version_str,
1712 .intr_handler = qla2100_intr_handler,
1713 .enable_intrs = qla2x00_enable_intrs,
1714 .disable_intrs = qla2x00_disable_intrs,
1715 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001716 .target_reset = qla2x00_abort_target,
1717 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001718 .fabric_login = qla2x00_login_fabric,
1719 .fabric_logout = qla2x00_fabric_logout,
1720 .calc_req_entries = qla2x00_calc_iocbs_32,
1721 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1722 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1723 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1724 .read_nvram = qla2x00_read_nvram_data,
1725 .write_nvram = qla2x00_write_nvram_data,
1726 .fw_dump = qla2100_fw_dump,
1727 .beacon_on = NULL,
1728 .beacon_off = NULL,
1729 .beacon_blink = NULL,
1730 .read_optrom = qla2x00_read_optrom_data,
1731 .write_optrom = qla2x00_write_optrom_data,
1732 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001733 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001734 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001735 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001736 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001737};
1738
1739static struct isp_operations qla2300_isp_ops = {
1740 .pci_config = qla2300_pci_config,
1741 .reset_chip = qla2x00_reset_chip,
1742 .chip_diag = qla2x00_chip_diag,
1743 .config_rings = qla2x00_config_rings,
1744 .reset_adapter = qla2x00_reset_adapter,
1745 .nvram_config = qla2x00_nvram_config,
1746 .update_fw_options = qla2x00_update_fw_options,
1747 .load_risc = qla2x00_load_risc,
1748 .pci_info_str = qla2x00_pci_info_str,
1749 .fw_version_str = qla2x00_fw_version_str,
1750 .intr_handler = qla2300_intr_handler,
1751 .enable_intrs = qla2x00_enable_intrs,
1752 .disable_intrs = qla2x00_disable_intrs,
1753 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001754 .target_reset = qla2x00_abort_target,
1755 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001756 .fabric_login = qla2x00_login_fabric,
1757 .fabric_logout = qla2x00_fabric_logout,
1758 .calc_req_entries = qla2x00_calc_iocbs_32,
1759 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1760 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1761 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1762 .read_nvram = qla2x00_read_nvram_data,
1763 .write_nvram = qla2x00_write_nvram_data,
1764 .fw_dump = qla2300_fw_dump,
1765 .beacon_on = qla2x00_beacon_on,
1766 .beacon_off = qla2x00_beacon_off,
1767 .beacon_blink = qla2x00_beacon_blink,
1768 .read_optrom = qla2x00_read_optrom_data,
1769 .write_optrom = qla2x00_write_optrom_data,
1770 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001771 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001772 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001773 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001774 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001775};
1776
1777static struct isp_operations qla24xx_isp_ops = {
1778 .pci_config = qla24xx_pci_config,
1779 .reset_chip = qla24xx_reset_chip,
1780 .chip_diag = qla24xx_chip_diag,
1781 .config_rings = qla24xx_config_rings,
1782 .reset_adapter = qla24xx_reset_adapter,
1783 .nvram_config = qla24xx_nvram_config,
1784 .update_fw_options = qla24xx_update_fw_options,
1785 .load_risc = qla24xx_load_risc,
1786 .pci_info_str = qla24xx_pci_info_str,
1787 .fw_version_str = qla24xx_fw_version_str,
1788 .intr_handler = qla24xx_intr_handler,
1789 .enable_intrs = qla24xx_enable_intrs,
1790 .disable_intrs = qla24xx_disable_intrs,
1791 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001792 .target_reset = qla24xx_abort_target,
1793 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001794 .fabric_login = qla24xx_login_fabric,
1795 .fabric_logout = qla24xx_fabric_logout,
1796 .calc_req_entries = NULL,
1797 .build_iocbs = NULL,
1798 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1799 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1800 .read_nvram = qla24xx_read_nvram_data,
1801 .write_nvram = qla24xx_write_nvram_data,
1802 .fw_dump = qla24xx_fw_dump,
1803 .beacon_on = qla24xx_beacon_on,
1804 .beacon_off = qla24xx_beacon_off,
1805 .beacon_blink = qla24xx_beacon_blink,
1806 .read_optrom = qla24xx_read_optrom_data,
1807 .write_optrom = qla24xx_write_optrom_data,
1808 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001810 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001811 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001812 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001813};
1814
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001815static struct isp_operations qla25xx_isp_ops = {
1816 .pci_config = qla25xx_pci_config,
1817 .reset_chip = qla24xx_reset_chip,
1818 .chip_diag = qla24xx_chip_diag,
1819 .config_rings = qla24xx_config_rings,
1820 .reset_adapter = qla24xx_reset_adapter,
1821 .nvram_config = qla24xx_nvram_config,
1822 .update_fw_options = qla24xx_update_fw_options,
1823 .load_risc = qla24xx_load_risc,
1824 .pci_info_str = qla24xx_pci_info_str,
1825 .fw_version_str = qla24xx_fw_version_str,
1826 .intr_handler = qla24xx_intr_handler,
1827 .enable_intrs = qla24xx_enable_intrs,
1828 .disable_intrs = qla24xx_disable_intrs,
1829 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001830 .target_reset = qla24xx_abort_target,
1831 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001832 .fabric_login = qla24xx_login_fabric,
1833 .fabric_logout = qla24xx_fabric_logout,
1834 .calc_req_entries = NULL,
1835 .build_iocbs = NULL,
1836 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1837 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1838 .read_nvram = qla25xx_read_nvram_data,
1839 .write_nvram = qla25xx_write_nvram_data,
1840 .fw_dump = qla25xx_fw_dump,
1841 .beacon_on = qla24xx_beacon_on,
1842 .beacon_off = qla24xx_beacon_off,
1843 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001844 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001845 .write_optrom = qla24xx_write_optrom_data,
1846 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001847 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001848 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001849 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001850 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001851};
1852
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001853static struct isp_operations qla81xx_isp_ops = {
1854 .pci_config = qla25xx_pci_config,
1855 .reset_chip = qla24xx_reset_chip,
1856 .chip_diag = qla24xx_chip_diag,
1857 .config_rings = qla24xx_config_rings,
1858 .reset_adapter = qla24xx_reset_adapter,
1859 .nvram_config = qla81xx_nvram_config,
1860 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001861 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001862 .pci_info_str = qla24xx_pci_info_str,
1863 .fw_version_str = qla24xx_fw_version_str,
1864 .intr_handler = qla24xx_intr_handler,
1865 .enable_intrs = qla24xx_enable_intrs,
1866 .disable_intrs = qla24xx_disable_intrs,
1867 .abort_command = qla24xx_abort_command,
1868 .target_reset = qla24xx_abort_target,
1869 .lun_reset = qla24xx_lun_reset,
1870 .fabric_login = qla24xx_login_fabric,
1871 .fabric_logout = qla24xx_fabric_logout,
1872 .calc_req_entries = NULL,
1873 .build_iocbs = NULL,
1874 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1875 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001876 .read_nvram = NULL,
1877 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001878 .fw_dump = qla81xx_fw_dump,
1879 .beacon_on = qla24xx_beacon_on,
1880 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001881 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001882 .read_optrom = qla25xx_read_optrom_data,
1883 .write_optrom = qla24xx_write_optrom_data,
1884 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001885 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001886 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001887 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001888 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001889};
1890
1891static struct isp_operations qla82xx_isp_ops = {
1892 .pci_config = qla82xx_pci_config,
1893 .reset_chip = qla82xx_reset_chip,
1894 .chip_diag = qla24xx_chip_diag,
1895 .config_rings = qla82xx_config_rings,
1896 .reset_adapter = qla24xx_reset_adapter,
1897 .nvram_config = qla81xx_nvram_config,
1898 .update_fw_options = qla24xx_update_fw_options,
1899 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001900 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001901 .fw_version_str = qla24xx_fw_version_str,
1902 .intr_handler = qla82xx_intr_handler,
1903 .enable_intrs = qla82xx_enable_intrs,
1904 .disable_intrs = qla82xx_disable_intrs,
1905 .abort_command = qla24xx_abort_command,
1906 .target_reset = qla24xx_abort_target,
1907 .lun_reset = qla24xx_lun_reset,
1908 .fabric_login = qla24xx_login_fabric,
1909 .fabric_logout = qla24xx_fabric_logout,
1910 .calc_req_entries = NULL,
1911 .build_iocbs = NULL,
1912 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1913 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1914 .read_nvram = qla24xx_read_nvram_data,
1915 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001916 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001917 .beacon_on = qla82xx_beacon_on,
1918 .beacon_off = qla82xx_beacon_off,
1919 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001920 .read_optrom = qla82xx_read_optrom_data,
1921 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001922 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001923 .start_scsi = qla82xx_start_scsi,
1924 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001925 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001926 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001927};
1928
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001929static struct isp_operations qla8044_isp_ops = {
1930 .pci_config = qla82xx_pci_config,
1931 .reset_chip = qla82xx_reset_chip,
1932 .chip_diag = qla24xx_chip_diag,
1933 .config_rings = qla82xx_config_rings,
1934 .reset_adapter = qla24xx_reset_adapter,
1935 .nvram_config = qla81xx_nvram_config,
1936 .update_fw_options = qla24xx_update_fw_options,
1937 .load_risc = qla82xx_load_risc,
1938 .pci_info_str = qla24xx_pci_info_str,
1939 .fw_version_str = qla24xx_fw_version_str,
1940 .intr_handler = qla8044_intr_handler,
1941 .enable_intrs = qla82xx_enable_intrs,
1942 .disable_intrs = qla82xx_disable_intrs,
1943 .abort_command = qla24xx_abort_command,
1944 .target_reset = qla24xx_abort_target,
1945 .lun_reset = qla24xx_lun_reset,
1946 .fabric_login = qla24xx_login_fabric,
1947 .fabric_logout = qla24xx_fabric_logout,
1948 .calc_req_entries = NULL,
1949 .build_iocbs = NULL,
1950 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1951 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1952 .read_nvram = NULL,
1953 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001954 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001955 .beacon_on = qla82xx_beacon_on,
1956 .beacon_off = qla82xx_beacon_off,
1957 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05001958 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001959 .write_optrom = qla8044_write_optrom_data,
1960 .get_flash_version = qla82xx_get_flash_version,
1961 .start_scsi = qla82xx_start_scsi,
1962 .abort_isp = qla8044_abort_isp,
1963 .iospace_config = qla82xx_iospace_config,
1964 .initialize_adapter = qla2x00_initialize_adapter,
1965};
1966
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001967static struct isp_operations qla83xx_isp_ops = {
1968 .pci_config = qla25xx_pci_config,
1969 .reset_chip = qla24xx_reset_chip,
1970 .chip_diag = qla24xx_chip_diag,
1971 .config_rings = qla24xx_config_rings,
1972 .reset_adapter = qla24xx_reset_adapter,
1973 .nvram_config = qla81xx_nvram_config,
1974 .update_fw_options = qla81xx_update_fw_options,
1975 .load_risc = qla81xx_load_risc,
1976 .pci_info_str = qla24xx_pci_info_str,
1977 .fw_version_str = qla24xx_fw_version_str,
1978 .intr_handler = qla24xx_intr_handler,
1979 .enable_intrs = qla24xx_enable_intrs,
1980 .disable_intrs = qla24xx_disable_intrs,
1981 .abort_command = qla24xx_abort_command,
1982 .target_reset = qla24xx_abort_target,
1983 .lun_reset = qla24xx_lun_reset,
1984 .fabric_login = qla24xx_login_fabric,
1985 .fabric_logout = qla24xx_fabric_logout,
1986 .calc_req_entries = NULL,
1987 .build_iocbs = NULL,
1988 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1989 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1990 .read_nvram = NULL,
1991 .write_nvram = NULL,
1992 .fw_dump = qla83xx_fw_dump,
1993 .beacon_on = qla24xx_beacon_on,
1994 .beacon_off = qla24xx_beacon_off,
1995 .beacon_blink = qla83xx_beacon_blink,
1996 .read_optrom = qla25xx_read_optrom_data,
1997 .write_optrom = qla24xx_write_optrom_data,
1998 .get_flash_version = qla24xx_get_flash_version,
1999 .start_scsi = qla24xx_dif_start_scsi,
2000 .abort_isp = qla2x00_abort_isp,
2001 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002002 .initialize_adapter = qla2x00_initialize_adapter,
2003};
2004
2005static struct isp_operations qlafx00_isp_ops = {
2006 .pci_config = qlafx00_pci_config,
2007 .reset_chip = qlafx00_soft_reset,
2008 .chip_diag = qlafx00_chip_diag,
2009 .config_rings = qlafx00_config_rings,
2010 .reset_adapter = qlafx00_soft_reset,
2011 .nvram_config = NULL,
2012 .update_fw_options = NULL,
2013 .load_risc = NULL,
2014 .pci_info_str = qlafx00_pci_info_str,
2015 .fw_version_str = qlafx00_fw_version_str,
2016 .intr_handler = qlafx00_intr_handler,
2017 .enable_intrs = qlafx00_enable_intrs,
2018 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002019 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002020 .target_reset = qlafx00_abort_target,
2021 .lun_reset = qlafx00_lun_reset,
2022 .fabric_login = NULL,
2023 .fabric_logout = NULL,
2024 .calc_req_entries = NULL,
2025 .build_iocbs = NULL,
2026 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2027 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2028 .read_nvram = qla24xx_read_nvram_data,
2029 .write_nvram = qla24xx_write_nvram_data,
2030 .fw_dump = NULL,
2031 .beacon_on = qla24xx_beacon_on,
2032 .beacon_off = qla24xx_beacon_off,
2033 .beacon_blink = NULL,
2034 .read_optrom = qla24xx_read_optrom_data,
2035 .write_optrom = qla24xx_write_optrom_data,
2036 .get_flash_version = qla24xx_get_flash_version,
2037 .start_scsi = qlafx00_start_scsi,
2038 .abort_isp = qlafx00_abort_isp,
2039 .iospace_config = qlafx00_iospace_config,
2040 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002041};
2042
Chad Dupuisf73cb692014-02-26 04:15:06 -05002043static struct isp_operations qla27xx_isp_ops = {
2044 .pci_config = qla25xx_pci_config,
2045 .reset_chip = qla24xx_reset_chip,
2046 .chip_diag = qla24xx_chip_diag,
2047 .config_rings = qla24xx_config_rings,
2048 .reset_adapter = qla24xx_reset_adapter,
2049 .nvram_config = qla81xx_nvram_config,
2050 .update_fw_options = qla81xx_update_fw_options,
2051 .load_risc = qla81xx_load_risc,
2052 .pci_info_str = qla24xx_pci_info_str,
2053 .fw_version_str = qla24xx_fw_version_str,
2054 .intr_handler = qla24xx_intr_handler,
2055 .enable_intrs = qla24xx_enable_intrs,
2056 .disable_intrs = qla24xx_disable_intrs,
2057 .abort_command = qla24xx_abort_command,
2058 .target_reset = qla24xx_abort_target,
2059 .lun_reset = qla24xx_lun_reset,
2060 .fabric_login = qla24xx_login_fabric,
2061 .fabric_logout = qla24xx_fabric_logout,
2062 .calc_req_entries = NULL,
2063 .build_iocbs = NULL,
2064 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2065 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2066 .read_nvram = NULL,
2067 .write_nvram = NULL,
2068 .fw_dump = qla27xx_fwdump,
2069 .beacon_on = qla24xx_beacon_on,
2070 .beacon_off = qla24xx_beacon_off,
2071 .beacon_blink = qla83xx_beacon_blink,
2072 .read_optrom = qla25xx_read_optrom_data,
2073 .write_optrom = qla24xx_write_optrom_data,
2074 .get_flash_version = qla24xx_get_flash_version,
2075 .start_scsi = qla24xx_dif_start_scsi,
2076 .abort_isp = qla2x00_abort_isp,
2077 .iospace_config = qla83xx_iospace_config,
2078 .initialize_adapter = qla2x00_initialize_adapter,
2079};
2080
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002081static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002083{
2084 ha->device_type = DT_EXTENDED_IDS;
2085 switch (ha->pdev->device) {
2086 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2087 ha->device_type |= DT_ISP2100;
2088 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002089 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002090 break;
2091 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2092 ha->device_type |= DT_ISP2200;
2093 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002094 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002095 break;
2096 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2097 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002098 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002099 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002100 break;
2101 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2102 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002103 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002104 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002105 break;
2106 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2107 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002108 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002109 if (ha->pdev->subsystem_vendor == 0x1028 &&
2110 ha->pdev->subsystem_device == 0x0170)
2111 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002112 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002113 break;
2114 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2115 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002116 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002117 break;
2118 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2119 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002120 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002121 break;
2122 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2123 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002124 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002125 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002126 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002127 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002128 break;
2129 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2130 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002131 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002132 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002133 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002134 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002135 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002136 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2137 ha->device_type |= DT_ISP8432;
2138 ha->device_type |= DT_ZIO_SUPPORTED;
2139 ha->device_type |= DT_FWI2;
2140 ha->device_type |= DT_IIDMA;
2141 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2142 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002143 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2144 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002145 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002146 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002147 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002148 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2149 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002150 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002151 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002152 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002153 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2154 ha->device_type |= DT_ISP2532;
2155 ha->device_type |= DT_ZIO_SUPPORTED;
2156 ha->device_type |= DT_FWI2;
2157 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002158 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2159 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002160 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2161 ha->device_type |= DT_ISP8001;
2162 ha->device_type |= DT_ZIO_SUPPORTED;
2163 ha->device_type |= DT_FWI2;
2164 ha->device_type |= DT_IIDMA;
2165 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2166 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002167 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2168 ha->device_type |= DT_ISP8021;
2169 ha->device_type |= DT_ZIO_SUPPORTED;
2170 ha->device_type |= DT_FWI2;
2171 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2172 /* Initialize 82XX ISP flags */
2173 qla82xx_init_flags(ha);
2174 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002175 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2176 ha->device_type |= DT_ISP8044;
2177 ha->device_type |= DT_ZIO_SUPPORTED;
2178 ha->device_type |= DT_FWI2;
2179 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2180 /* Initialize 82XX ISP flags */
2181 qla82xx_init_flags(ha);
2182 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002183 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2184 ha->device_type |= DT_ISP2031;
2185 ha->device_type |= DT_ZIO_SUPPORTED;
2186 ha->device_type |= DT_FWI2;
2187 ha->device_type |= DT_IIDMA;
2188 ha->device_type |= DT_T10_PI;
2189 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2190 break;
2191 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2192 ha->device_type |= DT_ISP8031;
2193 ha->device_type |= DT_ZIO_SUPPORTED;
2194 ha->device_type |= DT_FWI2;
2195 ha->device_type |= DT_IIDMA;
2196 ha->device_type |= DT_T10_PI;
2197 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2198 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002199 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2200 ha->device_type |= DT_ISPFX00;
2201 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002202 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2203 ha->device_type |= DT_ISP2071;
2204 ha->device_type |= DT_ZIO_SUPPORTED;
2205 ha->device_type |= DT_FWI2;
2206 ha->device_type |= DT_IIDMA;
2207 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2208 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002209 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2210 ha->device_type |= DT_ISP2271;
2211 ha->device_type |= DT_ZIO_SUPPORTED;
2212 ha->device_type |= DT_FWI2;
2213 ha->device_type |= DT_IIDMA;
2214 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2215 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002216 case PCI_DEVICE_ID_QLOGIC_ISP2261:
2217 ha->device_type |= DT_ISP2261;
2218 ha->device_type |= DT_ZIO_SUPPORTED;
2219 ha->device_type |= DT_FWI2;
2220 ha->device_type |= DT_IIDMA;
2221 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2222 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002223 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002224
Giridhar Malavalia9083012010-04-12 17:59:55 -07002225 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002226 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002227 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002228 /* Get adapter physical port no from interrupt pin register. */
2229 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002230 if (IS_QLA27XX(ha))
2231 ha->port_no--;
2232 else
2233 ha->port_no = !(ha->port_no & 1);
2234 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002235
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002236 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002237 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002238 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002239}
2240
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002241static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002242qla2xxx_scan_start(struct Scsi_Host *shost)
2243{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002244 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002245
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002246 if (vha->hw->flags.running_gold_fw)
2247 return;
2248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2250 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2251 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2252 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002253}
2254
2255static int
2256qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2257{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002258 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002261 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002263 return 1;
2264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002266}
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268/*
2269 * PCI driver interface
2270 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002271static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002272qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002274 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276 scsi_qla_host_t *base_vha = NULL;
2277 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002278 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002279 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002280 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002281 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002283 struct req_que *req = NULL;
2284 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002285 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002286 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002287 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2288 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002289 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002290 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2291 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002292 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002293 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002294 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2295 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002296 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002297 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002298 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002299 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002300 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2301 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002302 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002303 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002304 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2305 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002306 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002307 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2308 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002309
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002310 if (mem_only) {
2311 if (pci_enable_device_mem(pdev))
2312 goto probe_out;
2313 } else {
2314 if (pci_enable_device(pdev))
2315 goto probe_out;
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Jesse Barnes09276782008-10-18 17:33:19 -07002318 /* This may fail but that's ok */
2319 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2322 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002323 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2324 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002327 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2328 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002330 ha->tgt.enable_class_2 = ql2xenableclass2;
Quinn Tran33e79972014-09-25 06:14:55 -04002331 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2332 spin_lock_init(&ha->tgt.q_full_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002335 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002336 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002337 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002338 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002339 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002340 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002342 /* Set ISP-type information. */
2343 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002344
2345 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002346 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002347 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002348 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002349
Chad Dupuiscba1e472011-11-18 09:03:21 -08002350 ha->prev_topology = 0;
2351 ha->init_cb_size = sizeof(init_cb_t);
2352 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2353 ha->optrom_size = OPTROM_SIZE_2300;
2354
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002355 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002357 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359 req_length = REQUEST_ENTRY_CNT_2100;
2360 rsp_length = RESPONSE_ENTRY_CNT_2100;
2361 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002362 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002363 ha->flash_conf_off = ~0;
2364 ha->flash_data_off = ~0;
2365 ha->nvram_conf_off = ~0;
2366 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002367 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002369 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002370 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 req_length = REQUEST_ENTRY_CNT_2200;
2372 rsp_length = RESPONSE_ENTRY_CNT_2100;
2373 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002374 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002375 ha->flash_conf_off = ~0;
2376 ha->flash_data_off = ~0;
2377 ha->nvram_conf_off = ~0;
2378 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002379 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002380 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002381 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 req_length = REQUEST_ENTRY_CNT_2200;
2384 rsp_length = RESPONSE_ENTRY_CNT_2300;
2385 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002386 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002387 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2388 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002389 ha->flash_conf_off = ~0;
2390 ha->flash_data_off = ~0;
2391 ha->nvram_conf_off = ~0;
2392 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002393 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002394 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002395 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002396 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 req_length = REQUEST_ENTRY_CNT_24XX;
2398 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002399 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002401 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002402 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002403 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002404 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002405 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002406 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2407 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2408 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2409 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002410 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002411 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002412 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002413 req_length = REQUEST_ENTRY_CNT_24XX;
2414 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002415 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002417 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002418 ha->gid_list_info_size = 8;
2419 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002420 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002421 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002422 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2423 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2424 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2425 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2426 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002427 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002428 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2429 req_length = REQUEST_ENTRY_CNT_24XX;
2430 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002431 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002432 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2433 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2434 ha->gid_list_info_size = 8;
2435 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002436 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002437 ha->isp_ops = &qla81xx_isp_ops;
2438 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2439 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2440 ha->nvram_conf_off = ~0;
2441 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002442 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002443 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002444 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2445 req_length = REQUEST_ENTRY_CNT_82XX;
2446 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2447 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2448 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2449 ha->gid_list_info_size = 8;
2450 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002451 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002452 ha->isp_ops = &qla82xx_isp_ops;
2453 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2454 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2455 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2456 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002457 } else if (IS_QLA8044(ha)) {
2458 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2459 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2460 req_length = REQUEST_ENTRY_CNT_82XX;
2461 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2462 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2463 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2464 ha->gid_list_info_size = 8;
2465 ha->optrom_size = OPTROM_SIZE_83XX;
2466 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2467 ha->isp_ops = &qla8044_isp_ops;
2468 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2469 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2470 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2471 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002472 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002473 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002474 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002475 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002476 req_length = REQUEST_ENTRY_CNT_83XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002477 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002478 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002479 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2480 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2481 ha->gid_list_info_size = 8;
2482 ha->optrom_size = OPTROM_SIZE_83XX;
2483 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2484 ha->isp_ops = &qla83xx_isp_ops;
2485 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2486 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2487 ha->nvram_conf_off = ~0;
2488 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002489 } else if (IS_QLAFX00(ha)) {
2490 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2491 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2492 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2493 req_length = REQUEST_ENTRY_CNT_FX00;
2494 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002495 ha->isp_ops = &qlafx00_isp_ops;
2496 ha->port_down_retry_count = 30; /* default value */
2497 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2498 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002499 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002500 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002501 ha->mr.host_info_resend = false;
2502 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002503 } else if (IS_QLA27XX(ha)) {
2504 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2505 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2506 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2507 req_length = REQUEST_ENTRY_CNT_24XX;
2508 rsp_length = RESPONSE_ENTRY_CNT_2300;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002509 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002510 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2511 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2512 ha->gid_list_info_size = 8;
2513 ha->optrom_size = OPTROM_SIZE_83XX;
2514 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2515 ha->isp_ops = &qla27xx_isp_ops;
2516 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2517 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2518 ha->nvram_conf_off = ~0;
2519 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002521
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002522 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2523 "mbx_count=%d, req_length=%d, "
2524 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002525 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2526 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002527 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2528 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002529 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002530 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2531 "isp_ops=%p, flash_conf_off=%d, "
2532 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2533 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2534 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002535
2536 /* Configure PCI I/O space */
2537 ret = ha->isp_ops->iospace_config(ha);
2538 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002539 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002540
2541 ql_log_pci(ql_log_info, pdev, 0x001d,
2542 "Found an ISP%04X irq %d iobase 0x%p.\n",
2543 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002544 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002545 init_completion(&ha->mbx_cmd_comp);
2546 complete(&ha->mbx_cmd_comp);
2547 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002548 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002549 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002551 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
Andrew Vasquez53303c42009-01-22 09:45:37 -08002553 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002554 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2555 "64 Bit addressing is %s.\n",
2556 ha->flags.enable_64bit_addressing ? "enable" :
2557 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002558 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002559 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002560 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2561 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 goto probe_hw_failed;
2564 }
2565
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002566 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002568 req->max_q_depth = ql2xmaxqdepth;
2569
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570
2571 base_vha = qla2x00_create_host(sht, ha);
2572 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002573 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002574 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002575 qla2x00_free_req_que(ha, req);
2576 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002577 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 }
2579
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002581 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002584 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002585 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002586 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002587 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2589 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002590
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002591 /* Setup fcport template structure. */
2592 ha->mr.fcport.vha = base_vha;
2593 ha->mr.fcport.port_type = FCT_UNKNOWN;
2594 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2595 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2596 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2597 ha->mr.fcport.scan_state = 1;
2598
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002599 /* Set the SG table size based on ISP type */
2600 if (!IS_FWI2_CAPABLE(ha)) {
2601 if (IS_QLA2100(ha))
2602 host->sg_tablesize = 32;
2603 } else {
2604 if (!IS_QLA82XX(ha))
2605 host->sg_tablesize = QLA_SG_ALL;
2606 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002607 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002608 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002609 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002610 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002611 host->max_cmd_len = 32;
2612 else
2613 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002614 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002615 /* Older HBAs support only 16-bit LUNs */
2616 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2617 ql2xmaxlun > 0xffff)
2618 host->max_lun = 0xffff;
2619 else
2620 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002621 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002622 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002623
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002624 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2625 "max_id=%d this_id=%d "
2626 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002627 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002628 host->this_id, host->cmd_per_lun, host->unique_id,
2629 host->max_cmd_len, host->max_channel, host->max_lun,
2630 host->transportt, sht->vendor_id);
2631
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002632que_init:
2633 /* Alloc arrays of request and response ring ptrs */
2634 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2635 ql_log(ql_log_fatal, base_vha, 0x003d,
2636 "Failed to allocate memory for queue pointers..."
2637 "aborting.\n");
2638 goto probe_init_failed;
2639 }
2640
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002641 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002642
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002643 /* Set up the irqs */
2644 ret = qla2x00_request_irqs(ha, rsp);
2645 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002646 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002647
2648 pci_save_state(pdev);
2649
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002650 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002651 rsp->req = req;
2652 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002653
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002654 if (IS_QLAFX00(ha)) {
2655 ha->rsp_q_map[0] = rsp;
2656 ha->req_q_map[0] = req;
2657 set_bit(0, ha->req_qid_map);
2658 set_bit(0, ha->rsp_qid_map);
2659 }
2660
Andrew Vasquez08029992009-03-24 09:07:55 -07002661 /* FWI2-capable only. */
2662 req->req_q_in = &ha->iobase->isp24.req_q_in;
2663 req->req_q_out = &ha->iobase->isp24.req_q_out;
2664 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2665 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002666 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002667 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2668 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2669 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2670 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002671 }
2672
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002673 if (IS_QLAFX00(ha)) {
2674 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2675 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2676 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2677 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2678 }
2679
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002680 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002681 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2682 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2683 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2684 }
2685
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002686 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2687 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2688 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2689 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2690 "req->req_q_in=%p req->req_q_out=%p "
2691 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2692 req->req_q_in, req->req_q_out,
2693 rsp->rsp_q_in, rsp->rsp_q_out);
2694 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2695 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2696 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2697 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2698 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2699 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002701 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002702 ql_log(ql_log_fatal, base_vha, 0x00d6,
2703 "Failed to initialize adapter - Adapter flags %x.\n",
2704 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002705
Giridhar Malavalia9083012010-04-12 17:59:55 -07002706 if (IS_QLA82XX(ha)) {
2707 qla82xx_idc_lock(ha);
2708 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002709 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002710 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002711 ql_log(ql_log_fatal, base_vha, 0x00d7,
2712 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002713 } else if (IS_QLA8044(ha)) {
2714 qla8044_idc_lock(ha);
2715 qla8044_wr_direct(base_vha,
2716 QLA8044_CRB_DEV_STATE_INDEX,
2717 QLA8XXX_DEV_FAILED);
2718 qla8044_idc_unlock(ha);
2719 ql_log(ql_log_fatal, base_vha, 0x0150,
2720 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002721 }
2722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 ret = -ENODEV;
2724 goto probe_failed;
2725 }
2726
Chad Dupuis3b1bef62014-02-26 04:15:04 -05002727 if (IS_QLAFX00(ha))
2728 host->can_queue = QLAFX00_MAX_CANQUEUE;
2729 else
2730 host->can_queue = req->num_outstanding_cmds - 10;
2731
2732 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2733 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2734 host->can_queue, base_vha->req,
2735 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2736
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002737 if (ha->mqenable) {
2738 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002739 ql_log(ql_log_warn, base_vha, 0x00ec,
2740 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002741 goto que_init;
2742 }
2743 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002744
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002745 if (ha->flags.running_gold_fw)
2746 goto skip_dpc;
2747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 /*
2749 * Startup the kernel thread for this host adapter
2750 */
2751 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002752 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002754 ql_log(ql_log_fatal, base_vha, 0x00ed,
2755 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002756 ret = PTR_ERR(ha->dpc_thread);
2757 goto probe_failed;
2758 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002759 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2760 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002762 /*
2763 * If we're not coming up in initiator mode, we might sit for
2764 * a while without waking up the dpc thread, which leads to a
2765 * stuck process warning. So just kick the dpc once here and
2766 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2767 */
2768 qla2xxx_wake_dpc(base_vha);
2769
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002770 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2771
Saurav Kashyap81178772012-08-22 14:21:04 -04002772 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2773 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2774 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2775 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2776
2777 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2778 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2779 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2780 INIT_WORK(&ha->idc_state_handler,
2781 qla83xx_idc_state_handler_work);
2782 INIT_WORK(&ha->nic_core_unrecoverable,
2783 qla83xx_nic_core_unrecoverable_work);
2784 }
2785
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002786skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 list_add_tail(&base_vha->list, &ha->vp_list);
2788 base_vha->host->irq = ha->pdev->irq;
2789
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002792 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2793 "Started qla2x00_timer with "
2794 "interval=%d.\n", WATCH_INTERVAL);
2795 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2796 "Detected hba at address=%p.\n",
2797 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798
Arun Easie02587d2011-08-16 11:29:23 -07002799 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002800 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002801 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002802 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002803 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2804 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002805 if (ql2xenabledif == 1)
2806 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002807 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002808 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002809 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002810 | SHOST_DIF_TYPE3_PROTECTION
2811 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002812 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002813 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002814
2815 guard = SHOST_DIX_GUARD_CRC;
2816
2817 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2818 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2819 guard |= SHOST_DIX_GUARD_IP;
2820
2821 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002822 } else
2823 base_vha->flags.difdix_supported = 0;
2824 }
2825
Giridhar Malavalia9083012010-04-12 17:59:55 -07002826 ha->isp_ops->enable_intrs(ha);
2827
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002828 if (IS_QLAFX00(ha)) {
2829 ret = qlafx00_fx_disc(base_vha,
2830 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2831 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2832 QLA_SG_ALL : 128;
2833 }
2834
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002835 ret = scsi_add_host(host, &pdev->dev);
2836 if (ret)
2837 goto probe_failed;
2838
Michael Reed14864002009-12-02 09:11:16 -06002839 base_vha->flags.init_done = 1;
2840 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04002841 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06002842
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002843 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2844 "Init done and hba is online.\n");
2845
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002846 if (qla_ini_mode_enabled(base_vha))
2847 scsi_scan_host(host);
2848 else
2849 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2850 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002851
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002853
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002854 if (IS_QLAFX00(ha)) {
2855 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002856 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2857
2858 /* Register system information */
2859 ret = qlafx00_fx_disc(base_vha,
2860 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2861 }
2862
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002865 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002866
Armen Baloyan03eb9122013-10-30 03:38:22 -04002867 ql_log(ql_log_info, base_vha, 0x00fb,
2868 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002869 ql_log(ql_log_info, base_vha, 0x00fc,
2870 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2871 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2872 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2873 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002874 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002876 qlt_add_target(ha, base_vha);
2877
Joe Lawrence6b383972014-08-26 17:12:29 -04002878 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 return 0;
2880
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002881probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002882 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002883 ha->req_q_map[0] = NULL;
2884 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002885 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002886 ha->rsp_q_map[0] = NULL;
2887 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002888 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002889
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002891 if (base_vha->timer_active)
2892 qla2x00_stop_timer(base_vha);
2893 base_vha->flags.online = 0;
2894 if (ha->dpc_thread) {
2895 struct task_struct *t = ha->dpc_thread;
2896
2897 ha->dpc_thread = NULL;
2898 kthread_stop(t);
2899 }
2900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04002906 qla2x00_clear_drv_active(ha);
2907
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002908iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002909 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002910 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002911 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002912 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002913 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002914 } else {
2915 if (ha->iobase)
2916 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002917 if (ha->cregbase)
2918 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002919 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 pci_release_selected_regions(ha->pdev, ha->bars);
2921 kfree(ha);
2922 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002924probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002926 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
Adrian Bunk4c993f72008-01-14 00:55:16 -08002929static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002930qla2x00_shutdown(struct pci_dev *pdev)
2931{
2932 scsi_qla_host_t *vha;
2933 struct qla_hw_data *ha;
2934
Masanari Iida552f3f92013-02-08 01:57:44 -05002935 if (!atomic_read(&pdev->enable_cnt))
2936 return;
2937
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002938 vha = pci_get_drvdata(pdev);
2939 ha = vha->hw;
2940
Armen Baloyan42479342013-08-27 01:37:37 -04002941 /* Notify ISPFX00 firmware */
2942 if (IS_QLAFX00(ha))
2943 qlafx00_driver_shutdown(vha, 20);
2944
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002945 /* Turn-off FCE trace */
2946 if (ha->flags.fce_enabled) {
2947 qla2x00_disable_fce_trace(vha, NULL, NULL);
2948 ha->flags.fce_enabled = 0;
2949 }
2950
2951 /* Turn-off EFT trace */
2952 if (ha->eft)
2953 qla2x00_disable_eft_trace(vha);
2954
2955 /* Stop currently executing firmware. */
2956 qla2x00_try_to_stop_firmware(vha);
2957
2958 /* Turn adapter off line */
2959 vha->flags.online = 0;
2960
2961 /* turn-off interrupts on the card */
2962 if (ha->interrupts_on) {
2963 vha->flags.init_done = 0;
2964 ha->isp_ops->disable_intrs(ha);
2965 }
2966
2967 qla2x00_free_irqs(vha);
2968
2969 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04002970
2971 pci_disable_pcie_error_reporting(pdev);
2972 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002973}
2974
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002975/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002976static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002977qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002979 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002980 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981
Arun Easi43ebf162011-05-10 11:18:16 -07002982 mutex_lock(&ha->vport_lock);
2983 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07002984 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002985
Arun Easi43ebf162011-05-10 11:18:16 -07002986 BUG_ON(base_vha->list.next == &ha->vp_list);
2987 /* This assumes first entry in ha->vp_list is always base vha */
2988 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07002989 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002990
Arun Easi43ebf162011-05-10 11:18:16 -07002991 spin_unlock_irqrestore(&ha->vport_slock, flags);
2992 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002993
Arun Easi43ebf162011-05-10 11:18:16 -07002994 fc_vport_terminate(vha->fc_vport);
2995 scsi_host_put(vha->host);
2996
2997 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 }
Arun Easi43ebf162011-05-10 11:18:16 -07002999 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003000}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003001
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003002/* Stops all deferred work threads */
3003static void
3004qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3005{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003006 /* Flush the work queue and remove it */
3007 if (ha->wq) {
3008 flush_workqueue(ha->wq);
3009 destroy_workqueue(ha->wq);
3010 ha->wq = NULL;
3011 }
3012
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003013 /* Cancel all work and destroy DPC workqueues */
3014 if (ha->dpc_lp_wq) {
3015 cancel_work_sync(&ha->idc_aen);
3016 destroy_workqueue(ha->dpc_lp_wq);
3017 ha->dpc_lp_wq = NULL;
3018 }
3019
3020 if (ha->dpc_hp_wq) {
3021 cancel_work_sync(&ha->nic_core_reset);
3022 cancel_work_sync(&ha->idc_state_handler);
3023 cancel_work_sync(&ha->nic_core_unrecoverable);
3024 destroy_workqueue(ha->dpc_hp_wq);
3025 ha->dpc_hp_wq = NULL;
3026 }
3027
Andrew Vasquezb9978762009-03-24 09:08:05 -07003028 /* Kill the kernel thread for this host */
3029 if (ha->dpc_thread) {
3030 struct task_struct *t = ha->dpc_thread;
3031
3032 /*
3033 * qla2xxx_wake_dpc checks for ->dpc_thread
3034 * so we need to zero it out.
3035 */
3036 ha->dpc_thread = NULL;
3037 kthread_stop(t);
3038 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003039}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003040
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003041static void
3042qla2x00_unmap_iobases(struct qla_hw_data *ha)
3043{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003044 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003045
Chad Dupuisf73cb692014-02-26 04:15:06 -05003046 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003047 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003048 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003049 } else {
3050 if (ha->iobase)
3051 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003052
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003053 if (ha->cregbase)
3054 iounmap(ha->cregbase);
3055
Giridhar Malavalia9083012010-04-12 17:59:55 -07003056 if (ha->mqiobase)
3057 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003058
Chad Dupuisf73cb692014-02-26 04:15:06 -05003059 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003060 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003061 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003062}
3063
3064static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003065qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003066{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003067 if (IS_QLA8044(ha)) {
3068 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003069 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003070 qla8044_idc_unlock(ha);
3071 } else if (IS_QLA82XX(ha)) {
3072 qla82xx_idc_lock(ha);
3073 qla82xx_clear_drv_active(ha);
3074 qla82xx_idc_unlock(ha);
3075 }
3076}
3077
3078static void
3079qla2x00_remove_one(struct pci_dev *pdev)
3080{
3081 scsi_qla_host_t *base_vha;
3082 struct qla_hw_data *ha;
3083
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003084 base_vha = pci_get_drvdata(pdev);
3085 ha = base_vha->hw;
3086
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003087 /* Indicate device removal to prevent future board_disable and wait
3088 * until any pending board_disable has completed. */
3089 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3090 cancel_work_sync(&ha->board_disable);
3091
3092 /*
3093 * If the PCI device is disabled then there was a PCI-disconnect and
3094 * qla2x00_disable_board_on_pci_error has taken care of most of the
3095 * resources.
3096 */
3097 if (!atomic_read(&pdev->enable_cnt)) {
3098 scsi_host_put(base_vha->host);
3099 kfree(ha);
3100 pci_set_drvdata(pdev, NULL);
3101 return;
3102 }
3103
Sawan Chandak638a1a02014-04-11 16:54:38 -04003104 qla2x00_wait_for_hba_ready(base_vha);
3105
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003106 set_bit(UNLOADING, &base_vha->dpc_flags);
3107
3108 if (IS_QLAFX00(ha))
3109 qlafx00_driver_shutdown(base_vha, 20);
3110
3111 qla2x00_delete_all_vps(ha, base_vha);
3112
3113 if (IS_QLA8031(ha)) {
3114 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3115 "Clearing fcoe driver presence.\n");
3116 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3117 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3118 "Error while clearing DRV-Presence.\n");
3119 }
3120
3121 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3122
3123 qla2x00_dfs_remove(base_vha);
3124
3125 qla84xx_put_chip(base_vha);
3126
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003127 /* Laser should be disabled only for ISP2031 */
3128 if (IS_QLA2031(ha))
3129 qla83xx_disable_laser(base_vha);
3130
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003131 /* Disable timer */
3132 if (base_vha->timer_active)
3133 qla2x00_stop_timer(base_vha);
3134
3135 base_vha->flags.online = 0;
3136
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003137 /* free DMA memory */
3138 if (ha->exlogin_buf)
3139 qla2x00_free_exlogin_buffer(ha);
3140
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003141 qla2x00_destroy_deferred_work(ha);
3142
3143 qlt_remove_target(ha, base_vha);
3144
3145 qla2x00_free_sysfs_attr(base_vha, true);
3146
3147 fc_remove_host(base_vha->host);
3148
3149 scsi_remove_host(base_vha->host);
3150
3151 qla2x00_free_device(base_vha);
3152
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003153 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003154
Arun Easid2749ff2014-09-25 05:16:51 -04003155 scsi_host_put(base_vha->host);
3156
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003157 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003158
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 pci_release_selected_regions(ha->pdev, ha->bars);
3160 kfree(ha);
3161 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003163 pci_disable_pcie_error_reporting(pdev);
3164
Bernhard Walle665db932007-03-28 00:49:49 +02003165 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Andrew Vasquez85880802009-12-15 21:29:46 -08003173 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3174
3175 /* Disable timer */
3176 if (vha->timer_active)
3177 qla2x00_stop_timer(vha);
3178
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003179 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003180
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003181 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003183
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003184 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003185 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003186
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003187 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
Andrew Vasquez85880802009-12-15 21:29:46 -08003190 vha->flags.online = 0;
3191
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003192 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003193 if (ha->interrupts_on) {
3194 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003195 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003196 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003197
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 qla2x00_free_irqs(vha);
3199
Chad Dupuis88670482010-07-23 15:28:30 +05003200 qla2x00_free_fcports(vha);
3201
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003202 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003203
Giridhar Malavali08de2842011-08-16 11:31:44 -07003204 qla82xx_md_free(vha);
3205
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003206 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207}
3208
Chad Dupuis88670482010-07-23 15:28:30 +05003209void qla2x00_free_fcports(struct scsi_qla_host *vha)
3210{
3211 fc_port_t *fcport, *tfcport;
3212
3213 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3214 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003215 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003216 kfree(fcport);
3217 fcport = NULL;
3218 }
3219}
3220
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003221static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003223 int defer)
3224{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003225 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003226 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003227 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003228
3229 if (!fcport->rport)
3230 return;
3231
3232 rport = fcport->rport;
3233 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003234 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003235 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003236 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003237 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003238 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003239 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3240 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003241 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003242 int now;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003243 if (rport)
3244 fc_remote_port_delete(rport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003245 qlt_do_generation_tick(vha, &now);
3246 qlt_fc_port_deleted(vha, fcport, now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003247 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003248}
3249
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3252 *
3253 * Input: ha = adapter block pointer. fcport = port structure pointer.
3254 *
3255 * Return: None.
3256 *
3257 * Context:
3258 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003260 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003262 if (IS_QLAFX00(vha->hw)) {
3263 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3264 qla2x00_schedule_rport_del(vha, fcport, defer);
3265 return;
3266 }
3267
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003268 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003269 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003270 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 qla2x00_schedule_rport_del(vha, fcport, defer);
3272 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003273 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 * We may need to retry the login, so don't change the state of the
3275 * port but do the retries.
3276 */
3277 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003278 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 if (!do_login)
3281 return;
3282
Arun Easia1d02852015-08-04 13:38:02 -04003283 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3284
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003288 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003289 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3290 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 }
3292}
3293
3294/*
3295 * qla2x00_mark_all_devices_lost
3296 * Updates fcport state when device goes offline.
3297 *
3298 * Input:
3299 * ha = adapter block pointer.
3300 * fcport = port structure pointer.
3301 *
3302 * Return:
3303 * None.
3304 *
3305 * Context:
3306 */
3307void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003308qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309{
3310 fc_port_t *fcport;
3311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003313 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003315
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 /*
3317 * No point in marking the device as lost, if the device is
3318 * already DEAD.
3319 */
3320 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3321 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003323 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003324 if (defer)
3325 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003326 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003327 qla2x00_schedule_rport_del(vha, fcport, defer);
3328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 }
3330}
3331
3332/*
3333* qla2x00_mem_alloc
3334* Allocates adapter memory.
3335*
3336* Returns:
3337* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003338* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003340static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003341qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3342 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343{
3344 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Andrew Vasqueze8711082008-01-31 12:33:48 -08003346 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003348 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003349 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003351 if (qlt_mem_alloc(ha) < 0)
3352 goto fail_free_init_cb;
3353
Chad Dupuis642ef982012-02-09 11:15:57 -08003354 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3355 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003357 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358
Andrew Vasqueze8711082008-01-31 12:33:48 -08003359 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3360 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003363 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003364 /* Allocate cache for CT6 Ctx. */
3365 if (!ctx_cachep) {
3366 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3367 sizeof(struct ct6_dsd), 0,
3368 SLAB_HWCACHE_ALIGN, NULL);
3369 if (!ctx_cachep)
3370 goto fail_free_gid_list;
3371 }
3372 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3373 ctx_cachep);
3374 if (!ha->ctx_mempool)
3375 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003376 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3377 "ctx_cachep=%p ctx_mempool=%p.\n",
3378 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003379 }
3380
Andrew Vasqueze8711082008-01-31 12:33:48 -08003381 /* Get memory for cached NVRAM */
3382 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3383 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003384 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3387 ha->pdev->device);
3388 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3389 DMA_POOL_SIZE, 8, 0);
3390 if (!ha->s_dma_pool)
3391 goto fail_free_nvram;
3392
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003393 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3394 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3395 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3396
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003397 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003398 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3399 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3400 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003401 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3402 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003403 goto fail_s_dma_pool;
3404 }
3405
3406 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3407 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3408 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003409 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3410 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003411 goto fail_dl_dma_pool;
3412 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003413 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3414 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3415 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003416 }
3417
Andrew Vasqueze8711082008-01-31 12:33:48 -08003418 /* Allocate memory for SNS commands */
3419 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003421 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003423 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003425 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003426 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003427 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003429 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003431 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 goto fail_dma_pool;
3433 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003434 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003435 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003436 if (!ha->ct_sns)
3437 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003438 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3439 "ms_iocb=%p ct_sns=%p.\n",
3440 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 }
3442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003444 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3445 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003446 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3447 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448 goto fail_req;
3449 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003450 (*req)->length = req_len;
3451 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3452 ((*req)->length + 1) * sizeof(request_t),
3453 &(*req)->dma, GFP_KERNEL);
3454 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003455 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3456 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003457 goto fail_req_ring;
3458 }
3459 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003460 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3461 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003462 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3463 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003464 goto fail_rsp;
3465 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003466 (*rsp)->hw = ha;
3467 (*rsp)->length = rsp_len;
3468 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3469 ((*rsp)->length + 1) * sizeof(response_t),
3470 &(*rsp)->dma, GFP_KERNEL);
3471 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003472 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3473 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003474 goto fail_rsp_ring;
3475 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003476 (*req)->rsp = *rsp;
3477 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003478 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3479 "req=%p req->length=%d req->ring=%p rsp=%p "
3480 "rsp->length=%d rsp->ring=%p.\n",
3481 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3482 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003483 /* Allocate memory for NVRAM data for vports */
3484 if (ha->nvram_npiv_size) {
3485 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003486 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003487 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003488 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3489 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003490 goto fail_npiv_info;
3491 }
3492 } else
3493 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003495 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003496 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003497 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3498 &ha->ex_init_cb_dma);
3499 if (!ha->ex_init_cb)
3500 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003501 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3502 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003503 }
3504
Giridhar Malavalia9083012010-04-12 17:59:55 -07003505 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3506
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003507 /* Get consistent memory allocated for Async Port-Database. */
3508 if (!IS_FWI2_CAPABLE(ha)) {
3509 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3510 &ha->async_pd_dma);
3511 if (!ha->async_pd)
3512 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003513 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3514 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003515 }
3516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003518
3519 /* Allocate memory for our loop_id bitmap */
3520 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3521 GFP_KERNEL);
3522 if (!ha->loop_id_map)
3523 goto fail_async_pd;
3524 else {
3525 qla2x00_set_reserved_loop_ids(ha);
3526 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003527 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003528 }
3529
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003530 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003532fail_async_pd:
3533 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003534fail_ex_init_cb:
3535 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003536fail_npiv_info:
3537 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3538 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3539 (*rsp)->ring = NULL;
3540 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003542 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003544 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3545 sizeof(request_t), (*req)->ring, (*req)->dma);
3546 (*req)->ring = NULL;
3547 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003549 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550fail_req:
3551 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3552 ha->ct_sns, ha->ct_sns_dma);
3553 ha->ct_sns = NULL;
3554 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003555fail_free_ms_iocb:
3556 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3557 ha->ms_iocb = NULL;
3558 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003560 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003561 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3562 ha->fcp_cmnd_dma_pool = NULL;
3563 }
3564fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003565 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003566 dma_pool_destroy(ha->dl_dma_pool);
3567 ha->dl_dma_pool = NULL;
3568 }
3569fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003570 dma_pool_destroy(ha->s_dma_pool);
3571 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003572fail_free_nvram:
3573 kfree(ha->nvram);
3574 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003575fail_free_ctx_mempool:
3576 mempool_destroy(ha->ctx_mempool);
3577 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003578fail_free_srb_mempool:
3579 mempool_destroy(ha->srb_mempool);
3580 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003581fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003582 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3583 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003584 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003585 ha->gid_list = NULL;
3586 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003587fail_free_tgt_mem:
3588 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003589fail_free_init_cb:
3590 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3591 ha->init_cb_dma);
3592 ha->init_cb = NULL;
3593 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003594fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003595 ql_log(ql_log_fatal, NULL, 0x0030,
3596 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003597 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598}
3599
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003600int
3601qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
3602{
3603 int rval;
3604 uint16_t size, max_cnt, temp;
3605 struct qla_hw_data *ha = vha->hw;
3606
3607 /* Return if we don't need to alloacate any extended logins */
3608 if (!ql2xexlogins)
3609 return QLA_SUCCESS;
3610
3611 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
3612 max_cnt = 0;
3613 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
3614 if (rval != QLA_SUCCESS) {
3615 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
3616 "Failed to get exlogin status.\n");
3617 return rval;
3618 }
3619
3620 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
3621 ha->exlogin_size = (size * temp);
3622 ql_log(ql_log_info, vha, 0xd024,
3623 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
3624 max_cnt, size, temp);
3625
3626 ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
3627 ha->exlogin_size);
3628
3629 /* Get consistent memory for extended logins */
3630 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
3631 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
3632 if (!ha->exlogin_buf) {
3633 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
3634 "Failed to allocate memory for exlogin_buf_dma.\n");
3635 return -ENOMEM;
3636 }
3637
3638 /* Now configure the dma buffer */
3639 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
3640 if (rval) {
3641 ql_log(ql_log_fatal, vha, 0x00cf,
3642 "Setup extended login buffer ****FAILED****.\n");
3643 qla2x00_free_exlogin_buffer(ha);
3644 }
3645
3646 return rval;
3647}
3648
3649/*
3650* qla2x00_free_exlogin_buffer
3651*
3652* Input:
3653* ha = adapter block pointer
3654*/
3655void
3656qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
3657{
3658 if (ha->exlogin_buf) {
3659 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
3660 ha->exlogin_buf, ha->exlogin_buf_dma);
3661 ha->exlogin_buf = NULL;
3662 ha->exlogin_size = 0;
3663 }
3664}
3665
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003667* qla2x00_free_fw_dump
3668* Frees fw dump stuff.
3669*
3670* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003671* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003672*/
3673static void
3674qla2x00_free_fw_dump(struct qla_hw_data *ha)
3675{
3676 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003677 dma_free_coherent(&ha->pdev->dev,
3678 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003679
Chad Dupuisf73cb692014-02-26 04:15:06 -05003680 if (ha->eft)
3681 dma_free_coherent(&ha->pdev->dev,
3682 EFT_SIZE, ha->eft, ha->eft_dma);
3683
3684 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003685 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05003686 if (ha->fw_dump_template)
3687 vfree(ha->fw_dump_template);
3688
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003689 ha->fce = NULL;
3690 ha->fce_dma = 0;
3691 ha->eft = NULL;
3692 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003693 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04003694 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003695 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003696 ha->fw_dump = NULL;
3697 ha->fw_dump_len = 0;
3698 ha->fw_dump_template = NULL;
3699 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003700}
3701
3702/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703* qla2x00_mem_free
3704* Frees all adapter allocated memory.
3705*
3706* Input:
3707* ha = adapter block pointer.
3708*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003709static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003710qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003712 qla2x00_free_fw_dump(ha);
3713
Saurav Kashyap81178772012-08-22 14:21:04 -04003714 if (ha->mctp_dump)
3715 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3716 ha->mctp_dump_dma);
3717
Andrew Vasqueze8711082008-01-31 12:33:48 -08003718 if (ha->srb_mempool)
3719 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003721 if (ha->dcbx_tlv)
3722 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3723 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3724
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003725 if (ha->xgmac_data)
3726 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3727 ha->xgmac_data, ha->xgmac_data_dma);
3728
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 if (ha->sns_cmd)
3730 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003731 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732
3733 if (ha->ct_sns)
3734 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003735 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736
Andrew Vasquez88729e52006-06-23 16:10:50 -07003737 if (ha->sfp_data)
3738 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3739
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 if (ha->ms_iocb)
3741 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3742
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003743 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003744 dma_pool_free(ha->s_dma_pool,
3745 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003746
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003747 if (ha->async_pd)
3748 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3749
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 if (ha->s_dma_pool)
3751 dma_pool_destroy(ha->s_dma_pool);
3752
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003754 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3755 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756
Giridhar Malavalia9083012010-04-12 17:59:55 -07003757 if (IS_QLA82XX(ha)) {
3758 if (!list_empty(&ha->gbl_dsd_list)) {
3759 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3760
3761 /* clean up allocated prev pool */
3762 list_for_each_entry_safe(dsd_ptr,
3763 tdsd_ptr, &ha->gbl_dsd_list, list) {
3764 dma_pool_free(ha->dl_dma_pool,
3765 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3766 list_del(&dsd_ptr->list);
3767 kfree(dsd_ptr);
3768 }
3769 }
3770 }
3771
3772 if (ha->dl_dma_pool)
3773 dma_pool_destroy(ha->dl_dma_pool);
3774
3775 if (ha->fcp_cmnd_dma_pool)
3776 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3777
3778 if (ha->ctx_mempool)
3779 mempool_destroy(ha->ctx_mempool);
3780
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003781 qlt_mem_free(ha);
3782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 if (ha->init_cb)
3784 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003785 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003786 vfree(ha->optrom_buffer);
3787 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003788 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003789 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003790 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
Andrew Vasqueze8711082008-01-31 12:33:48 -08003792 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003793 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 ha->sns_cmd = NULL;
3795 ha->sns_cmd_dma = 0;
3796 ha->ct_sns = NULL;
3797 ha->ct_sns_dma = 0;
3798 ha->ms_iocb = NULL;
3799 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 ha->init_cb = NULL;
3801 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003802 ha->ex_init_cb = NULL;
3803 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003804 ha->async_pd = NULL;
3805 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
3807 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003808 ha->dl_dma_pool = NULL;
3809 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 ha->gid_list = NULL;
3812 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003813
3814 ha->tgt.atio_ring = NULL;
3815 ha->tgt.atio_dma = 0;
3816 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817}
3818
3819struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3820 struct qla_hw_data *ha)
3821{
3822 struct Scsi_Host *host;
3823 struct scsi_qla_host *vha = NULL;
3824
3825 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3826 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003827 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3828 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829 goto fail;
3830 }
3831
3832 /* Clear our data area */
3833 vha = shost_priv(host);
3834 memset(vha, 0, sizeof(scsi_qla_host_t));
3835
3836 vha->host = host;
3837 vha->host_no = host->host_no;
3838 vha->hw = ha;
3839
3840 INIT_LIST_HEAD(&vha->vp_fcports);
3841 INIT_LIST_HEAD(&vha->work_list);
3842 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04003843 INIT_LIST_HEAD(&vha->qla_cmd_list);
3844 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003846 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04003847 spin_lock_init(&vha->cmd_list_lock);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003849 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003850 ql_dbg(ql_dbg_init, vha, 0x0041,
3851 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3852 vha->host, vha->hw, vha,
3853 dev_name(&(ha->pdev->dev)));
3854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003855 return vha;
3856
3857fail:
3858 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859}
3860
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003861static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003862qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003863{
3864 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003865 uint8_t bail;
3866
3867 QLA_VHA_MARK_BUSY(vha, bail);
3868 if (bail)
3869 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003870
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003871 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003872 if (!e) {
3873 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003874 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003875 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003876
3877 INIT_LIST_HEAD(&e->list);
3878 e->type = type;
3879 e->flags = QLA_EVT_FLAG_FREE;
3880 return e;
3881}
3882
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003883static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003884qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003885{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003886 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003887
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003888 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003889 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003890 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003891 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003892
Andrew Vasquez0971de72008-04-03 13:13:18 -07003893 return QLA_SUCCESS;
3894}
3895
3896int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003897qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003898 u32 data)
3899{
3900 struct qla_work_evt *e;
3901
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003902 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003903 if (!e)
3904 return QLA_FUNCTION_FAILED;
3905
3906 e->u.aen.code = code;
3907 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003908 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003909}
3910
Andrew Vasquez8a659572009-02-08 20:50:12 -08003911int
3912qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3913{
3914 struct qla_work_evt *e;
3915
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003916 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003917 if (!e)
3918 return QLA_FUNCTION_FAILED;
3919
3920 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003921 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003922}
3923
Andrew Vasquezac280b62009-08-20 11:06:05 -07003924#define qla2x00_post_async_work(name, type) \
3925int qla2x00_post_async_##name##_work( \
3926 struct scsi_qla_host *vha, \
3927 fc_port_t *fcport, uint16_t *data) \
3928{ \
3929 struct qla_work_evt *e; \
3930 \
3931 e = qla2x00_alloc_work(vha, type); \
3932 if (!e) \
3933 return QLA_FUNCTION_FAILED; \
3934 \
3935 e->u.logio.fcport = fcport; \
3936 if (data) { \
3937 e->u.logio.data[0] = data[0]; \
3938 e->u.logio.data[1] = data[1]; \
3939 } \
3940 return qla2x00_post_work(vha, e); \
3941}
3942
3943qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3944qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3945qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3946qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003947qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3948qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003949
Andrew Vasquez3420d362009-10-13 15:16:45 -07003950int
3951qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3952{
3953 struct qla_work_evt *e;
3954
3955 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3956 if (!e)
3957 return QLA_FUNCTION_FAILED;
3958
3959 e->u.uevent.code = code;
3960 return qla2x00_post_work(vha, e);
3961}
3962
3963static void
3964qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3965{
3966 char event_string[40];
3967 char *envp[] = { event_string, NULL };
3968
3969 switch (code) {
3970 case QLA_UEVENT_CODE_FW_DUMP:
3971 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3972 vha->host_no);
3973 break;
3974 default:
3975 /* do nothing */
3976 break;
3977 }
3978 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3979}
3980
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003981int
3982qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
3983 uint32_t *data, int cnt)
3984{
3985 struct qla_work_evt *e;
3986
3987 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
3988 if (!e)
3989 return QLA_FUNCTION_FAILED;
3990
3991 e->u.aenfx.evtcode = evtcode;
3992 e->u.aenfx.count = cnt;
3993 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
3994 return qla2x00_post_work(vha, e);
3995}
3996
Andrew Vasquezac280b62009-08-20 11:06:05 -07003997void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003998qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003999{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004000 struct qla_work_evt *e, *tmp;
4001 unsigned long flags;
4002 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004003
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004004 spin_lock_irqsave(&vha->work_lock, flags);
4005 list_splice_init(&vha->work_list, &work);
4006 spin_unlock_irqrestore(&vha->work_lock, flags);
4007
4008 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004009 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004010
4011 switch (e->type) {
4012 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004013 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004014 e->u.aen.code, e->u.aen.data);
4015 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004016 case QLA_EVT_IDC_ACK:
4017 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4018 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004019 case QLA_EVT_ASYNC_LOGIN:
4020 qla2x00_async_login(vha, e->u.logio.fcport,
4021 e->u.logio.data);
4022 break;
4023 case QLA_EVT_ASYNC_LOGIN_DONE:
4024 qla2x00_async_login_done(vha, e->u.logio.fcport,
4025 e->u.logio.data);
4026 break;
4027 case QLA_EVT_ASYNC_LOGOUT:
4028 qla2x00_async_logout(vha, e->u.logio.fcport);
4029 break;
4030 case QLA_EVT_ASYNC_LOGOUT_DONE:
4031 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4032 e->u.logio.data);
4033 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004034 case QLA_EVT_ASYNC_ADISC:
4035 qla2x00_async_adisc(vha, e->u.logio.fcport,
4036 e->u.logio.data);
4037 break;
4038 case QLA_EVT_ASYNC_ADISC_DONE:
4039 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4040 e->u.logio.data);
4041 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004042 case QLA_EVT_UEVENT:
4043 qla2x00_uevent_emit(vha, e->u.uevent.code);
4044 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004045 case QLA_EVT_AENFX:
4046 qlafx00_process_aen(vha, e);
4047 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004048 }
4049 if (e->flags & QLA_EVT_FLAG_FREE)
4050 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004051
4052 /* For each work completed decrement vha ref count */
4053 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004054 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057/* Relogins all the fcports of a vport
4058 * Context: dpc thread
4059 */
4060void qla2x00_relogin(struct scsi_qla_host *vha)
4061{
4062 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004063 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064 uint16_t next_loopid = 0;
4065 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004066 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067
4068 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4069 /*
4070 * If the port is not ONLINE then try to login
4071 * to it if we haven't run out of retries.
4072 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004073 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4074 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004075 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004076 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004077 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004078 ha->isp_ops->fabric_logout(vha,
4079 fcport->loop_id,
4080 fcport->d_id.b.domain,
4081 fcport->d_id.b.area,
4082 fcport->d_id.b.al_pa);
4083
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004084 if (fcport->loop_id == FC_NO_LOOP_ID) {
4085 fcport->loop_id = next_loopid =
4086 ha->min_external_loopid;
4087 status = qla2x00_find_new_loop_id(
4088 vha, fcport);
4089 if (status != QLA_SUCCESS) {
4090 /* Ran out of IDs to use */
4091 break;
4092 }
4093 }
4094
Andrew Vasquezac280b62009-08-20 11:06:05 -07004095 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004096 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004097 data[0] = 0;
4098 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4099 status = qla2x00_post_async_login_work(
4100 vha, fcport, data);
4101 if (status == QLA_SUCCESS)
4102 continue;
4103 /* Attempt a retry. */
4104 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004105 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004106 status = qla2x00_fabric_login(vha,
4107 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004108 if (status == QLA_SUCCESS) {
4109 int status2;
4110 uint8_t opts;
4111
4112 opts = 0;
4113 if (fcport->flags &
4114 FCF_FCP2_DEVICE)
4115 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004116 status2 =
4117 qla2x00_get_port_database(
4118 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004119 if (status2 != QLA_SUCCESS)
4120 status = 1;
4121 }
4122 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004123 } else
4124 status = qla2x00_local_device_login(vha,
4125 fcport);
4126
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 if (status == QLA_SUCCESS) {
4128 fcport->old_loop_id = fcport->loop_id;
4129
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004130 ql_dbg(ql_dbg_disc, vha, 0x2003,
4131 "Port login OK: logged in ID 0x%x.\n",
4132 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133
4134 qla2x00_update_fcport(vha, fcport);
4135
4136 } else if (status == 1) {
4137 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4138 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004139 ql_dbg(ql_dbg_disc, vha, 0x2007,
4140 "Retrying %d login again loop_id 0x%x.\n",
4141 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 } else {
4143 fcport->login_retry = 0;
4144 }
4145
4146 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004147 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148 }
4149 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4150 break;
4151 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004152}
4153
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004154/* Schedule work on any of the dpc-workqueues */
4155void
4156qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4157{
4158 struct qla_hw_data *ha = base_vha->hw;
4159
4160 switch (work_code) {
4161 case MBA_IDC_AEN: /* 0x8200 */
4162 if (ha->dpc_lp_wq)
4163 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4164 break;
4165
4166 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4167 if (!ha->flags.nic_core_reset_hdlr_active) {
4168 if (ha->dpc_hp_wq)
4169 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4170 } else
4171 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4172 "NIC Core reset is already active. Skip "
4173 "scheduling it again.\n");
4174 break;
4175 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4176 if (ha->dpc_hp_wq)
4177 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4178 break;
4179 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4180 if (ha->dpc_hp_wq)
4181 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4182 break;
4183 default:
4184 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004185 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004186 }
4187
4188 return;
4189}
4190
4191/* Work: Perform NIC Core Unrecoverable state handling */
4192void
4193qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4194{
4195 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004196 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004197 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4198 uint32_t dev_state = 0;
4199
4200 qla83xx_idc_lock(base_vha, 0);
4201 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4202 qla83xx_reset_ownership(base_vha);
4203 if (ha->flags.nic_core_reset_owner) {
4204 ha->flags.nic_core_reset_owner = 0;
4205 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4206 QLA8XXX_DEV_FAILED);
4207 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4208 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4209 }
4210 qla83xx_idc_unlock(base_vha, 0);
4211}
4212
4213/* Work: Execute IDC state handler */
4214void
4215qla83xx_idc_state_handler_work(struct work_struct *work)
4216{
4217 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004218 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004219 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4220 uint32_t dev_state = 0;
4221
4222 qla83xx_idc_lock(base_vha, 0);
4223 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4224 if (dev_state == QLA8XXX_DEV_FAILED ||
4225 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4226 qla83xx_idc_state_handler(base_vha);
4227 qla83xx_idc_unlock(base_vha, 0);
4228}
4229
Saurav Kashyapfa492632012-11-21 02:40:29 -05004230static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004231qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4232{
4233 int rval = QLA_SUCCESS;
4234 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4235 uint32_t heart_beat_counter1, heart_beat_counter2;
4236
4237 do {
4238 if (time_after(jiffies, heart_beat_wait)) {
4239 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4240 "Nic Core f/w is not alive.\n");
4241 rval = QLA_FUNCTION_FAILED;
4242 break;
4243 }
4244
4245 qla83xx_idc_lock(base_vha, 0);
4246 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4247 &heart_beat_counter1);
4248 qla83xx_idc_unlock(base_vha, 0);
4249 msleep(100);
4250 qla83xx_idc_lock(base_vha, 0);
4251 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4252 &heart_beat_counter2);
4253 qla83xx_idc_unlock(base_vha, 0);
4254 } while (heart_beat_counter1 == heart_beat_counter2);
4255
4256 return rval;
4257}
4258
4259/* Work: Perform NIC Core Reset handling */
4260void
4261qla83xx_nic_core_reset_work(struct work_struct *work)
4262{
4263 struct qla_hw_data *ha =
4264 container_of(work, struct qla_hw_data, nic_core_reset);
4265 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4266 uint32_t dev_state = 0;
4267
Saurav Kashyap81178772012-08-22 14:21:04 -04004268 if (IS_QLA2031(ha)) {
4269 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4270 ql_log(ql_log_warn, base_vha, 0xb081,
4271 "Failed to dump mctp\n");
4272 return;
4273 }
4274
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004275 if (!ha->flags.nic_core_reset_hdlr_active) {
4276 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4277 qla83xx_idc_lock(base_vha, 0);
4278 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4279 &dev_state);
4280 qla83xx_idc_unlock(base_vha, 0);
4281 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4282 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4283 "Nic Core f/w is alive.\n");
4284 return;
4285 }
4286 }
4287
4288 ha->flags.nic_core_reset_hdlr_active = 1;
4289 if (qla83xx_nic_core_reset(base_vha)) {
4290 /* NIC Core reset failed. */
4291 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4292 "NIC Core reset failed.\n");
4293 }
4294 ha->flags.nic_core_reset_hdlr_active = 0;
4295 }
4296}
4297
4298/* Work: Handle 8200 IDC aens */
4299void
4300qla83xx_service_idc_aen(struct work_struct *work)
4301{
4302 struct qla_hw_data *ha =
4303 container_of(work, struct qla_hw_data, idc_aen);
4304 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4305 uint32_t dev_state, idc_control;
4306
4307 qla83xx_idc_lock(base_vha, 0);
4308 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4309 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4310 qla83xx_idc_unlock(base_vha, 0);
4311 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4312 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4313 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4314 "Application requested NIC Core Reset.\n");
4315 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4316 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4317 QLA_SUCCESS) {
4318 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4319 "Other protocol driver requested NIC Core Reset.\n");
4320 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4321 }
4322 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4323 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4324 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4325 }
4326}
4327
4328static void
4329qla83xx_wait_logic(void)
4330{
4331 int i;
4332
4333 /* Yield CPU */
4334 if (!in_interrupt()) {
4335 /*
4336 * Wait about 200ms before retrying again.
4337 * This controls the number of retries for single
4338 * lock operation.
4339 */
4340 msleep(100);
4341 schedule();
4342 } else {
4343 for (i = 0; i < 20; i++)
4344 cpu_relax(); /* This a nop instr on i386 */
4345 }
4346}
4347
Saurav Kashyapfa492632012-11-21 02:40:29 -05004348static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004349qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4350{
4351 int rval;
4352 uint32_t data;
4353 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4354 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4355 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004356 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4357 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004358
4359 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4360 if (rval)
4361 return rval;
4362
4363 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4364 return QLA_SUCCESS;
4365 } else {
4366 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4367 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4368 data);
4369 if (rval)
4370 return rval;
4371
4372 msleep(200);
4373
4374 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4375 &data);
4376 if (rval)
4377 return rval;
4378
4379 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4380 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4381 ~(idc_lck_rcvry_stage_mask));
4382 rval = qla83xx_wr_reg(base_vha,
4383 QLA83XX_IDC_LOCK_RECOVERY, data);
4384 if (rval)
4385 return rval;
4386
4387 /* Forcefully perform IDC UnLock */
4388 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4389 &data);
4390 if (rval)
4391 return rval;
4392 /* Clear lock-id by setting 0xff */
4393 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4394 0xff);
4395 if (rval)
4396 return rval;
4397 /* Clear lock-recovery by setting 0x0 */
4398 rval = qla83xx_wr_reg(base_vha,
4399 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4400 if (rval)
4401 return rval;
4402 } else
4403 return QLA_SUCCESS;
4404 }
4405
4406 return rval;
4407}
4408
Saurav Kashyapfa492632012-11-21 02:40:29 -05004409static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004410qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4411{
4412 int rval = QLA_SUCCESS;
4413 uint32_t o_drv_lockid, n_drv_lockid;
4414 unsigned long lock_recovery_timeout;
4415
4416 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4417retry_lockid:
4418 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4419 if (rval)
4420 goto exit;
4421
4422 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4423 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4424 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4425 return QLA_SUCCESS;
4426 else
4427 return QLA_FUNCTION_FAILED;
4428 }
4429
4430 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4431 if (rval)
4432 goto exit;
4433
4434 if (o_drv_lockid == n_drv_lockid) {
4435 qla83xx_wait_logic();
4436 goto retry_lockid;
4437 } else
4438 return QLA_SUCCESS;
4439
4440exit:
4441 return rval;
4442}
4443
4444void
4445qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4446{
4447 uint16_t options = (requester_id << 15) | BIT_6;
4448 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004449 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004450 struct qla_hw_data *ha = base_vha->hw;
4451
4452 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4453retry_lock:
4454 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4455 == QLA_SUCCESS) {
4456 if (data) {
4457 /* Setting lock-id to our function-number */
4458 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4459 ha->portnum);
4460 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004461 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4462 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004463 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004464 "Failed to acquire IDC lock, acquired by %d, "
4465 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004466
4467 /* Retry/Perform IDC-Lock recovery */
4468 if (qla83xx_idc_lock_recovery(base_vha)
4469 == QLA_SUCCESS) {
4470 qla83xx_wait_logic();
4471 goto retry_lock;
4472 } else
4473 ql_log(ql_log_warn, base_vha, 0xb075,
4474 "IDC Lock recovery FAILED.\n");
4475 }
4476
4477 }
4478
4479 return;
4480
4481 /* XXX: IDC-lock implementation using access-control mbx */
4482retry_lock2:
4483 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4484 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4485 "Failed to acquire IDC lock. retrying...\n");
4486 /* Retry/Perform IDC-Lock recovery */
4487 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4488 qla83xx_wait_logic();
4489 goto retry_lock2;
4490 } else
4491 ql_log(ql_log_warn, base_vha, 0xb076,
4492 "IDC Lock recovery FAILED.\n");
4493 }
4494
4495 return;
4496}
4497
4498void
4499qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4500{
Bart Van Assche5897cb22015-06-04 15:57:20 -07004501#if 0
4502 uint16_t options = (requester_id << 15) | BIT_7;
4503#endif
4504 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004505 uint32_t data;
4506 struct qla_hw_data *ha = base_vha->hw;
4507
4508 /* IDC-unlock implementation using driver-unlock/lock-id
4509 * remote registers
4510 */
4511 retry = 0;
4512retry_unlock:
4513 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4514 == QLA_SUCCESS) {
4515 if (data == ha->portnum) {
4516 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4517 /* Clearing lock-id by setting 0xff */
4518 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4519 } else if (retry < 10) {
4520 /* SV: XXX: IDC unlock retrying needed here? */
4521
4522 /* Retry for IDC-unlock */
4523 qla83xx_wait_logic();
4524 retry++;
4525 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4526 "Failed to release IDC lock, retyring=%d\n", retry);
4527 goto retry_unlock;
4528 }
4529 } else if (retry < 10) {
4530 /* Retry for IDC-unlock */
4531 qla83xx_wait_logic();
4532 retry++;
4533 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4534 "Failed to read drv-lockid, retyring=%d\n", retry);
4535 goto retry_unlock;
4536 }
4537
4538 return;
4539
Bart Van Assche5897cb22015-06-04 15:57:20 -07004540#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004541 /* XXX: IDC-unlock implementation using access-control mbx */
4542 retry = 0;
4543retry_unlock2:
4544 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4545 if (retry < 10) {
4546 /* Retry for IDC-unlock */
4547 qla83xx_wait_logic();
4548 retry++;
4549 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4550 "Failed to release IDC lock, retyring=%d\n", retry);
4551 goto retry_unlock2;
4552 }
4553 }
4554
4555 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07004556#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004557}
4558
4559int
4560__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4561{
4562 int rval = QLA_SUCCESS;
4563 struct qla_hw_data *ha = vha->hw;
4564 uint32_t drv_presence;
4565
4566 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4567 if (rval == QLA_SUCCESS) {
4568 drv_presence |= (1 << ha->portnum);
4569 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4570 drv_presence);
4571 }
4572
4573 return rval;
4574}
4575
4576int
4577qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4578{
4579 int rval = QLA_SUCCESS;
4580
4581 qla83xx_idc_lock(vha, 0);
4582 rval = __qla83xx_set_drv_presence(vha);
4583 qla83xx_idc_unlock(vha, 0);
4584
4585 return rval;
4586}
4587
4588int
4589__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4590{
4591 int rval = QLA_SUCCESS;
4592 struct qla_hw_data *ha = vha->hw;
4593 uint32_t drv_presence;
4594
4595 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4596 if (rval == QLA_SUCCESS) {
4597 drv_presence &= ~(1 << ha->portnum);
4598 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4599 drv_presence);
4600 }
4601
4602 return rval;
4603}
4604
4605int
4606qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4607{
4608 int rval = QLA_SUCCESS;
4609
4610 qla83xx_idc_lock(vha, 0);
4611 rval = __qla83xx_clear_drv_presence(vha);
4612 qla83xx_idc_unlock(vha, 0);
4613
4614 return rval;
4615}
4616
Saurav Kashyapfa492632012-11-21 02:40:29 -05004617static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004618qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4619{
4620 struct qla_hw_data *ha = vha->hw;
4621 uint32_t drv_ack, drv_presence;
4622 unsigned long ack_timeout;
4623
4624 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4625 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4626 while (1) {
4627 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4628 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004629 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004630 break;
4631
4632 if (time_after_eq(jiffies, ack_timeout)) {
4633 ql_log(ql_log_warn, vha, 0xb067,
4634 "RESET ACK TIMEOUT! drv_presence=0x%x "
4635 "drv_ack=0x%x\n", drv_presence, drv_ack);
4636 /*
4637 * The function(s) which did not ack in time are forced
4638 * to withdraw any further participation in the IDC
4639 * reset.
4640 */
4641 if (drv_ack != drv_presence)
4642 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4643 drv_ack);
4644 break;
4645 }
4646
4647 qla83xx_idc_unlock(vha, 0);
4648 msleep(1000);
4649 qla83xx_idc_lock(vha, 0);
4650 }
4651
4652 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4653 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4654}
4655
Saurav Kashyapfa492632012-11-21 02:40:29 -05004656static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004657qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4658{
4659 int rval = QLA_SUCCESS;
4660 uint32_t idc_control;
4661
4662 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4663 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4664
4665 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4666 __qla83xx_get_idc_control(vha, &idc_control);
4667 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4668 __qla83xx_set_idc_control(vha, 0);
4669
4670 qla83xx_idc_unlock(vha, 0);
4671 rval = qla83xx_restart_nic_firmware(vha);
4672 qla83xx_idc_lock(vha, 0);
4673
4674 if (rval != QLA_SUCCESS) {
4675 ql_log(ql_log_fatal, vha, 0xb06a,
4676 "Failed to restart NIC f/w.\n");
4677 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4678 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4679 } else {
4680 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4681 "Success in restarting nic f/w.\n");
4682 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4683 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4684 }
4685
4686 return rval;
4687}
4688
4689/* Assumes idc_lock always held on entry */
4690int
4691qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4692{
4693 struct qla_hw_data *ha = base_vha->hw;
4694 int rval = QLA_SUCCESS;
4695 unsigned long dev_init_timeout;
4696 uint32_t dev_state;
4697
4698 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4699 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4700
4701 while (1) {
4702
4703 if (time_after_eq(jiffies, dev_init_timeout)) {
4704 ql_log(ql_log_warn, base_vha, 0xb06e,
4705 "Initialization TIMEOUT!\n");
4706 /* Init timeout. Disable further NIC Core
4707 * communication.
4708 */
4709 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4710 QLA8XXX_DEV_FAILED);
4711 ql_log(ql_log_info, base_vha, 0xb06f,
4712 "HW State: FAILED.\n");
4713 }
4714
4715 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4716 switch (dev_state) {
4717 case QLA8XXX_DEV_READY:
4718 if (ha->flags.nic_core_reset_owner)
4719 qla83xx_idc_audit(base_vha,
4720 IDC_AUDIT_COMPLETION);
4721 ha->flags.nic_core_reset_owner = 0;
4722 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4723 "Reset_owner reset by 0x%x.\n",
4724 ha->portnum);
4725 goto exit;
4726 case QLA8XXX_DEV_COLD:
4727 if (ha->flags.nic_core_reset_owner)
4728 rval = qla83xx_device_bootstrap(base_vha);
4729 else {
4730 /* Wait for AEN to change device-state */
4731 qla83xx_idc_unlock(base_vha, 0);
4732 msleep(1000);
4733 qla83xx_idc_lock(base_vha, 0);
4734 }
4735 break;
4736 case QLA8XXX_DEV_INITIALIZING:
4737 /* Wait for AEN to change device-state */
4738 qla83xx_idc_unlock(base_vha, 0);
4739 msleep(1000);
4740 qla83xx_idc_lock(base_vha, 0);
4741 break;
4742 case QLA8XXX_DEV_NEED_RESET:
4743 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4744 qla83xx_need_reset_handler(base_vha);
4745 else {
4746 /* Wait for AEN to change device-state */
4747 qla83xx_idc_unlock(base_vha, 0);
4748 msleep(1000);
4749 qla83xx_idc_lock(base_vha, 0);
4750 }
4751 /* reset timeout value after need reset handler */
4752 dev_init_timeout = jiffies +
4753 (ha->fcoe_dev_init_timeout * HZ);
4754 break;
4755 case QLA8XXX_DEV_NEED_QUIESCENT:
4756 /* XXX: DEBUG for now */
4757 qla83xx_idc_unlock(base_vha, 0);
4758 msleep(1000);
4759 qla83xx_idc_lock(base_vha, 0);
4760 break;
4761 case QLA8XXX_DEV_QUIESCENT:
4762 /* XXX: DEBUG for now */
4763 if (ha->flags.quiesce_owner)
4764 goto exit;
4765
4766 qla83xx_idc_unlock(base_vha, 0);
4767 msleep(1000);
4768 qla83xx_idc_lock(base_vha, 0);
4769 dev_init_timeout = jiffies +
4770 (ha->fcoe_dev_init_timeout * HZ);
4771 break;
4772 case QLA8XXX_DEV_FAILED:
4773 if (ha->flags.nic_core_reset_owner)
4774 qla83xx_idc_audit(base_vha,
4775 IDC_AUDIT_COMPLETION);
4776 ha->flags.nic_core_reset_owner = 0;
4777 __qla83xx_clear_drv_presence(base_vha);
4778 qla83xx_idc_unlock(base_vha, 0);
4779 qla8xxx_dev_failed_handler(base_vha);
4780 rval = QLA_FUNCTION_FAILED;
4781 qla83xx_idc_lock(base_vha, 0);
4782 goto exit;
4783 case QLA8XXX_BAD_VALUE:
4784 qla83xx_idc_unlock(base_vha, 0);
4785 msleep(1000);
4786 qla83xx_idc_lock(base_vha, 0);
4787 break;
4788 default:
4789 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09004790 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004791 qla83xx_idc_unlock(base_vha, 0);
4792 qla8xxx_dev_failed_handler(base_vha);
4793 rval = QLA_FUNCTION_FAILED;
4794 qla83xx_idc_lock(base_vha, 0);
4795 goto exit;
4796 }
4797 }
4798
4799exit:
4800 return rval;
4801}
4802
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004803void
4804qla2x00_disable_board_on_pci_error(struct work_struct *work)
4805{
4806 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
4807 board_disable);
4808 struct pci_dev *pdev = ha->pdev;
4809 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4810
4811 ql_log(ql_log_warn, base_vha, 0x015b,
4812 "Disabling adapter.\n");
4813
4814 set_bit(UNLOADING, &base_vha->dpc_flags);
4815
4816 qla2x00_delete_all_vps(ha, base_vha);
4817
4818 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4819
4820 qla2x00_dfs_remove(base_vha);
4821
4822 qla84xx_put_chip(base_vha);
4823
4824 if (base_vha->timer_active)
4825 qla2x00_stop_timer(base_vha);
4826
4827 base_vha->flags.online = 0;
4828
4829 qla2x00_destroy_deferred_work(ha);
4830
4831 /*
4832 * Do not try to stop beacon blink as it will issue a mailbox
4833 * command.
4834 */
4835 qla2x00_free_sysfs_attr(base_vha, false);
4836
4837 fc_remove_host(base_vha->host);
4838
4839 scsi_remove_host(base_vha->host);
4840
4841 base_vha->flags.init_done = 0;
4842 qla25xx_delete_queues(base_vha);
4843 qla2x00_free_irqs(base_vha);
4844 qla2x00_free_fcports(base_vha);
4845 qla2x00_mem_free(ha);
4846 qla82xx_md_free(base_vha);
4847 qla2x00_free_queues(ha);
4848
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004849 qla2x00_unmap_iobases(ha);
4850
4851 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004852 pci_disable_pcie_error_reporting(pdev);
4853 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004854
Joe Lawrencebeb9e312014-08-26 17:12:14 -04004855 /*
4856 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
4857 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004858}
4859
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860/**************************************************************************
4861* qla2x00_do_dpc
4862* This kernel thread is a task that is schedule by the interrupt handler
4863* to perform the background processing for interrupts.
4864*
4865* Notes:
4866* This task always run in the context of a kernel thread. It
4867* is kick-off by the driver's detect code and starts up
4868* up one per adapter. It immediately goes to sleep and waits for
4869* some fibre event. When either the interrupt handler or
4870* the timer routine detects a event it will one of the task
4871* bits then wake us up.
4872**************************************************************************/
4873static int
4874qla2x00_do_dpc(void *data)
4875{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004876 scsi_qla_host_t *base_vha;
4877 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004878
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004879 ha = (struct qla_hw_data *)data;
4880 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881
Dongsheng Yang8698a742014-03-11 18:09:12 +08004882 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883
James Bottomley563585e2011-01-27 16:12:37 -05004884 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004885 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004886 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4887 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888
Christoph Hellwig39a11242006-02-14 18:46:22 +01004889 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004891 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4892 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893
Andrew Vasquez85880802009-12-15 21:29:46 -08004894 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004895 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4896 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004897 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004898 }
4899
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 ha->dpc_active = 1;
4901
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004902 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4903 "DPC handler waking up, dpc_flags=0x%lx.\n",
4904 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004906 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004907
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004908 if (IS_P3P_TYPE(ha)) {
4909 if (IS_QLA8044(ha)) {
4910 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4911 &base_vha->dpc_flags)) {
4912 qla8044_idc_lock(ha);
4913 qla8044_wr_direct(base_vha,
4914 QLA8044_CRB_DEV_STATE_INDEX,
4915 QLA8XXX_DEV_FAILED);
4916 qla8044_idc_unlock(ha);
4917 ql_log(ql_log_info, base_vha, 0x4004,
4918 "HW State: FAILED.\n");
4919 qla8044_device_state_handler(base_vha);
4920 continue;
4921 }
4922
4923 } else {
4924 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4925 &base_vha->dpc_flags)) {
4926 qla82xx_idc_lock(ha);
4927 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4928 QLA8XXX_DEV_FAILED);
4929 qla82xx_idc_unlock(ha);
4930 ql_log(ql_log_info, base_vha, 0x0151,
4931 "HW State: FAILED.\n");
4932 qla82xx_device_state_handler(base_vha);
4933 continue;
4934 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004935 }
4936
4937 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4938 &base_vha->dpc_flags)) {
4939
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004940 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4941 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004942 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4943 &base_vha->dpc_flags))) {
4944 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4945 /* FCoE-ctx reset failed.
4946 * Escalate to chip-reset
4947 */
4948 set_bit(ISP_ABORT_NEEDED,
4949 &base_vha->dpc_flags);
4950 }
4951 clear_bit(ABORT_ISP_ACTIVE,
4952 &base_vha->dpc_flags);
4953 }
4954
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004955 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4956 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004957 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004958 } else if (IS_QLAFX00(ha)) {
4959 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4960 &base_vha->dpc_flags)) {
4961 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
4962 "Firmware Reset Recovery\n");
4963 if (qlafx00_reset_initialize(base_vha)) {
4964 /* Failed. Abort isp later. */
4965 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03004966 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004967 set_bit(ISP_UNRECOVERABLE,
4968 &base_vha->dpc_flags);
4969 ql_dbg(ql_dbg_dpc, base_vha,
4970 0x4021,
4971 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03004972 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004973 }
4974 }
4975
4976 if (test_and_clear_bit(FX00_TARGET_SCAN,
4977 &base_vha->dpc_flags)) {
4978 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
4979 "ISPFx00 Target Scan scheduled\n");
4980 if (qlafx00_rescan_isp(base_vha)) {
4981 if (!test_bit(UNLOADING,
4982 &base_vha->dpc_flags))
4983 set_bit(ISP_UNRECOVERABLE,
4984 &base_vha->dpc_flags);
4985 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
4986 "ISPFx00 Target Scan Failed\n");
4987 }
4988 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
4989 "ISPFx00 Target Scan End\n");
4990 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04004991 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
4992 &base_vha->dpc_flags)) {
4993 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
4994 "ISPFx00 Host Info resend scheduled\n");
4995 qlafx00_fx_disc(base_vha,
4996 &base_vha->hw->mr.fcport,
4997 FXDISC_REG_HOST_INFO);
4998 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004999 }
5000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005001 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5002 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005004 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5005 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005007 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008
Giridhar Malavalia9083012010-04-12 17:59:55 -07005009 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 /* failed. retry later */
5011 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005012 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005014 clear_bit(ABORT_ISP_ACTIVE,
5015 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005016 }
5017
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005018 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5019 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020 }
5021
David Jefferya394aac2012-11-21 02:39:54 -05005022 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5023 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005024 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005025 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005026
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005027 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
5028 int ret;
5029 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
5030 if (ret != QLA_SUCCESS)
5031 ql_log(ql_log_warn, base_vha, 0x121,
5032 "Failed to enable receiving of RSCN "
5033 "requests: 0x%x.\n", ret);
5034 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
5035 }
5036
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005037 if (IS_QLAFX00(ha))
5038 goto loop_resync_check;
5039
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005040 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005041 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5042 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005043 if (IS_P3P_TYPE(ha)) {
5044 if (IS_QLA82XX(ha))
5045 qla82xx_device_state_handler(base_vha);
5046 if (IS_QLA8044(ha))
5047 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005048 clear_bit(ISP_QUIESCE_NEEDED,
5049 &base_vha->dpc_flags);
5050 if (!ha->flags.quiesce_owner) {
5051 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005052 if (IS_QLA82XX(ha)) {
5053 qla82xx_idc_lock(ha);
5054 qla82xx_clear_qsnt_ready(
5055 base_vha);
5056 qla82xx_idc_unlock(ha);
5057 } else if (IS_QLA8044(ha)) {
5058 qla8044_idc_lock(ha);
5059 qla8044_clear_qsnt_ready(
5060 base_vha);
5061 qla8044_idc_unlock(ha);
5062 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005063 }
5064 } else {
5065 clear_bit(ISP_QUIESCE_NEEDED,
5066 &base_vha->dpc_flags);
5067 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005068 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005069 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5070 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005071 }
5072
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005073 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005074 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005075 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005077 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5078 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005079 qla2x00_rst_aen(base_vha);
5080 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005081 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5082 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 }
5084
5085 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005086 if ((test_and_clear_bit(RELOGIN_NEEDED,
5087 &base_vha->dpc_flags)) &&
5088 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5089 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005091 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5092 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005093 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005094 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5095 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005097loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005098 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005099 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005101 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5102 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103
5104 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005105 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
Bart Van Assche52c82822015-07-09 07:23:26 -07005107 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005109 clear_bit(LOOP_RESYNC_ACTIVE,
5110 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 }
5112
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005113 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5114 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 }
5116
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005117 if (IS_QLAFX00(ha))
5118 goto intr_on_check;
5119
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005120 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5121 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5122 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5123 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005124 }
5125
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005126intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005128 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005130 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005131 &base_vha->dpc_flags)) {
5132 if (ha->beacon_blink_led == 1)
5133 ha->isp_ops->beacon_blink(base_vha);
5134 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005135
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005136 if (!IS_QLAFX00(ha))
5137 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005138
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005140end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005141 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005143 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005145 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5146 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
5148 /*
5149 * Make sure that nobody tries to wake us up again.
5150 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 ha->dpc_active = 0;
5152
Andrew Vasquezac280b62009-08-20 11:06:05 -07005153 /* Cleanup any residual CTX SRBs. */
5154 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5155
Christoph Hellwig39a11242006-02-14 18:46:22 +01005156 return 0;
5157}
5158
5159void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005160qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005161{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005162 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005163 struct task_struct *t = ha->dpc_thread;
5164
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005165 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005166 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167}
5168
5169/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170* qla2x00_rst_aen
5171* Processes asynchronous reset.
5172*
5173* Input:
5174* ha = adapter block pointer.
5175*/
5176static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005177qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005179 if (vha->flags.online && !vha->flags.reset_active &&
5180 !atomic_read(&vha->loop_down_timer) &&
5181 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005183 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184
5185 /*
5186 * Issue marker command only when we are going to start
5187 * the I/O.
5188 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005189 vha->marker_needed = 1;
5190 } while (!atomic_read(&vha->loop_down_timer) &&
5191 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 }
5193}
5194
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195/**************************************************************************
5196* qla2x00_timer
5197*
5198* Description:
5199* One second timer
5200*
5201* Context: Interrupt
5202***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005203void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005204qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 int start_dpc = 0;
5208 int index;
5209 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005210 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005211 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005212 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005213
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005214 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005215 ql_dbg(ql_dbg_timer, vha, 0x6000,
5216 "EEH = %d, restarting timer.\n",
5217 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005218 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5219 return;
5220 }
5221
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005222 /*
5223 * Hardware read to raise pending EEH errors during mailbox waits. If
5224 * the read returns -1 then disable the board.
5225 */
5226 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005227 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005228 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005231 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005232 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005233 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5234 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005235 if (IS_QLA82XX(ha))
5236 qla82xx_watchdog(vha);
5237 else if (IS_QLA8044(ha))
5238 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005239 }
5240
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005241 if (!vha->vp_idx && IS_QLAFX00(ha))
5242 qlafx00_timer_routine(vha);
5243
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005245 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005246 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5247 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005248 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005250 if (atomic_read(&vha->loop_down_timer) ==
5251 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005253 ql_log(ql_log_info, vha, 0x6008,
5254 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005256 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5257 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005259 /*
5260 * Schedule an ISP abort to return any FCP2-device
5261 * commands.
5262 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005263 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005264 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005265 spin_lock_irqsave(&ha->hardware_lock,
5266 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005267 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005268 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005269 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005270 index++) {
5271 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005272
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005273 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005274 if (!sp)
5275 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005276 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005277 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005278 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005279 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005280 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005282 if (IS_QLA82XX(ha))
5283 set_bit(FCOE_CTX_RESET_NEEDED,
5284 &vha->dpc_flags);
5285 else
5286 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005287 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005288 break;
5289 }
5290 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005291 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 start_dpc++;
5294 }
5295
5296 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005297 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005298 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005299 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 "Loop down - aborting ISP.\n");
5301
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005302 if (IS_QLA82XX(ha))
5303 set_bit(FCOE_CTX_RESET_NEEDED,
5304 &vha->dpc_flags);
5305 else
5306 set_bit(ISP_ABORT_NEEDED,
5307 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 }
5309 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005310 ql_dbg(ql_dbg_timer, vha, 0x600a,
5311 "Loop down - seconds remaining %d.\n",
5312 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005314 /* Check if beacon LED needs to be blinked for physical host only */
5315 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005316 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005317 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005318 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5319 start_dpc++;
5320 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005321 }
5322
Andrew Vasquez550bf572008-04-24 15:21:23 -07005323 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005324 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005325 start_dpc++;
5326
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005328 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5329 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5330 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005332 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5333 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005334 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5335 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005336 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005337 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005338 ql_dbg(ql_dbg_timer, vha, 0x600b,
5339 "isp_abort_needed=%d loop_resync_needed=%d "
5340 "fcport_update_needed=%d start_dpc=%d "
5341 "reset_marker_needed=%d",
5342 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5343 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5344 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5345 start_dpc,
5346 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5347 ql_dbg(ql_dbg_timer, vha, 0x600c,
5348 "beacon_blink_needed=%d isp_unrecoverable=%d "
5349 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005350 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005351 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5352 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5353 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5354 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005355 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005356 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005359 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360}
5361
Andrew Vasquez54333832005-11-09 15:49:04 -08005362/* Firmware interface routines. */
5363
Chad Dupuisf73cb692014-02-26 04:15:06 -05005364#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08005365#define FW_ISP21XX 0
5366#define FW_ISP22XX 1
5367#define FW_ISP2300 2
5368#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005369#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005370#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005371#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005372#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005373#define FW_ISP2031 8
5374#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005375#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005376
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005377#define FW_FILE_ISP21XX "ql2100_fw.bin"
5378#define FW_FILE_ISP22XX "ql2200_fw.bin"
5379#define FW_FILE_ISP2300 "ql2300_fw.bin"
5380#define FW_FILE_ISP2322 "ql2322_fw.bin"
5381#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005382#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005383#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005384#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005385#define FW_FILE_ISP2031 "ql2600_fw.bin"
5386#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005387#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05005388
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005389
Daniel Walkere1e82b62008-05-12 22:21:10 -07005390static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005391
5392static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005393 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5394 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5395 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5396 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5397 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005398 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005399 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005400 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005401 { .name = FW_FILE_ISP2031, },
5402 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005403 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005404};
5405
5406struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005407qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005408{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005409 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005410 struct fw_blob *blob;
5411
Andrew Vasquez54333832005-11-09 15:49:04 -08005412 if (IS_QLA2100(ha)) {
5413 blob = &qla_fw_blobs[FW_ISP21XX];
5414 } else if (IS_QLA2200(ha)) {
5415 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005416 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005417 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005418 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005419 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005420 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005421 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005422 } else if (IS_QLA25XX(ha)) {
5423 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005424 } else if (IS_QLA81XX(ha)) {
5425 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005426 } else if (IS_QLA82XX(ha)) {
5427 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005428 } else if (IS_QLA2031(ha)) {
5429 blob = &qla_fw_blobs[FW_ISP2031];
5430 } else if (IS_QLA8031(ha)) {
5431 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005432 } else if (IS_QLA27XX(ha)) {
5433 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03005434 } else {
5435 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005436 }
5437
Daniel Walkere1e82b62008-05-12 22:21:10 -07005438 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005439 if (blob->fw)
5440 goto out;
5441
5442 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005443 ql_log(ql_log_warn, vha, 0x0063,
5444 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005445 blob->fw = NULL;
5446 blob = NULL;
5447 goto out;
5448 }
5449
5450out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005451 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005452 return blob;
5453}
5454
5455static void
5456qla2x00_release_firmware(void)
5457{
5458 int idx;
5459
Daniel Walkere1e82b62008-05-12 22:21:10 -07005460 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005461 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005462 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005463 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005464}
5465
Seokmann Ju14e660e2007-09-20 14:07:36 -07005466static pci_ers_result_t
5467qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5468{
Andrew Vasquez85880802009-12-15 21:29:46 -08005469 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5470 struct qla_hw_data *ha = vha->hw;
5471
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005472 ql_dbg(ql_dbg_aer, vha, 0x9000,
5473 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005474
Seokmann Ju14e660e2007-09-20 14:07:36 -07005475 switch (state) {
5476 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005477 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005478 return PCI_ERS_RESULT_CAN_RECOVER;
5479 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005480 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005481 /* For ISP82XX complete any pending mailbox cmd */
5482 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005483 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005484 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5485 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005486 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005487 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005488 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005489 /* Return back all IOs */
5490 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005491 return PCI_ERS_RESULT_NEED_RESET;
5492 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005493 ha->flags.pci_channel_io_perm_failure = 1;
5494 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005495 return PCI_ERS_RESULT_DISCONNECT;
5496 }
5497 return PCI_ERS_RESULT_NEED_RESET;
5498}
5499
5500static pci_ers_result_t
5501qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5502{
5503 int risc_paused = 0;
5504 uint32_t stat;
5505 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005506 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5507 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005508 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5509 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5510
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005511 if (IS_QLA82XX(ha))
5512 return PCI_ERS_RESULT_RECOVERED;
5513
Seokmann Ju14e660e2007-09-20 14:07:36 -07005514 spin_lock_irqsave(&ha->hardware_lock, flags);
5515 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5516 stat = RD_REG_DWORD(&reg->hccr);
5517 if (stat & HCCR_RISC_PAUSE)
5518 risc_paused = 1;
5519 } else if (IS_QLA23XX(ha)) {
5520 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5521 if (stat & HSR_RISC_PAUSED)
5522 risc_paused = 1;
5523 } else if (IS_FWI2_CAPABLE(ha)) {
5524 stat = RD_REG_DWORD(&reg24->host_status);
5525 if (stat & HSRX_RISC_PAUSED)
5526 risc_paused = 1;
5527 }
5528 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5529
5530 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005531 ql_log(ql_log_info, base_vha, 0x9003,
5532 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005533 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005534
5535 return PCI_ERS_RESULT_NEED_RESET;
5536 } else
5537 return PCI_ERS_RESULT_RECOVERED;
5538}
5539
Saurav Kashyapfa492632012-11-21 02:40:29 -05005540static uint32_t
5541qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005542{
5543 uint32_t rval = QLA_FUNCTION_FAILED;
5544 uint32_t drv_active = 0;
5545 struct qla_hw_data *ha = base_vha->hw;
5546 int fn;
5547 struct pci_dev *other_pdev = NULL;
5548
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005549 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5550 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005551
5552 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5553
5554 if (base_vha->flags.online) {
5555 /* Abort all outstanding commands,
5556 * so as to be requeued later */
5557 qla2x00_abort_isp_cleanup(base_vha);
5558 }
5559
5560
5561 fn = PCI_FUNC(ha->pdev->devfn);
5562 while (fn > 0) {
5563 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005564 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5565 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005566 other_pdev =
5567 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5568 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5569 fn));
5570
5571 if (!other_pdev)
5572 continue;
5573 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005574 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5575 "Found PCI func available and enable at 0x%x.\n",
5576 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005577 pci_dev_put(other_pdev);
5578 break;
5579 }
5580 pci_dev_put(other_pdev);
5581 }
5582
5583 if (!fn) {
5584 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005585 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5586 "This devfn is reset owner = 0x%x.\n",
5587 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005588 qla82xx_idc_lock(ha);
5589
5590 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005591 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005592
5593 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5594 QLA82XX_IDC_VERSION);
5595
5596 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005597 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5598 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005599
5600 qla82xx_idc_unlock(ha);
5601 /* Reset if device is not already reset
5602 * drv_active would be 0 if a reset has already been done
5603 */
5604 if (drv_active)
5605 rval = qla82xx_start_firmware(base_vha);
5606 else
5607 rval = QLA_SUCCESS;
5608 qla82xx_idc_lock(ha);
5609
5610 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005611 ql_log(ql_log_info, base_vha, 0x900b,
5612 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005613 qla82xx_clear_drv_active(ha);
5614 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005615 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005616 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005617 ql_log(ql_log_info, base_vha, 0x900c,
5618 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005619 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005620 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005621 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005622 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005623 rval = qla82xx_restart_isp(base_vha);
5624 qla82xx_idc_lock(ha);
5625 /* Clear driver state register */
5626 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5627 qla82xx_set_drv_active(base_vha);
5628 }
5629 qla82xx_idc_unlock(ha);
5630 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005631 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5632 "This devfn is not reset owner = 0x%x.\n",
5633 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005634 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005635 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005636 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005637 rval = qla82xx_restart_isp(base_vha);
5638 qla82xx_idc_lock(ha);
5639 qla82xx_set_drv_active(base_vha);
5640 qla82xx_idc_unlock(ha);
5641 }
5642 }
5643 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5644
5645 return rval;
5646}
5647
Seokmann Ju14e660e2007-09-20 14:07:36 -07005648static pci_ers_result_t
5649qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5650{
5651 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005652 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5653 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005654 struct rsp_que *rsp;
5655 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005656
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005657 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5658 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005659
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005660 /* Workaround: qla2xxx driver which access hardware earlier
5661 * needs error state to be pci_channel_io_online.
5662 * Otherwise mailbox command timesout.
5663 */
5664 pdev->error_state = pci_channel_io_normal;
5665
5666 pci_restore_state(pdev);
5667
Richard Lary8c1496b2010-02-18 10:07:29 -08005668 /* pci_restore_state() clears the saved_state flag of the device
5669 * save restored state which resets saved_state flag
5670 */
5671 pci_save_state(pdev);
5672
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005673 if (ha->mem_only)
5674 rc = pci_enable_device_mem(pdev);
5675 else
5676 rc = pci_enable_device(pdev);
5677
5678 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005679 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005680 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005681 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005682 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005683
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005684 rsp = ha->rsp_q_map[0];
5685 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005686 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005688 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005689 goto exit_slot_reset;
5690
5691 if (IS_QLA82XX(ha)) {
5692 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5693 ret = PCI_ERS_RESULT_RECOVERED;
5694 goto exit_slot_reset;
5695 } else
5696 goto exit_slot_reset;
5697 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005698
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005699 while (ha->flags.mbox_busy && retries--)
5700 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005701
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005702 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005703 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005704 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005705 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005706
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005707
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005708exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005709 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5710 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005711
Seokmann Ju14e660e2007-09-20 14:07:36 -07005712 return ret;
5713}
5714
5715static void
5716qla2xxx_pci_resume(struct pci_dev *pdev)
5717{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005718 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5719 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005720 int ret;
5721
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005722 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5723 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005725 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005726 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005727 ql_log(ql_log_fatal, base_vha, 0x9002,
5728 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005729 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005730
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005731 pci_cleanup_aer_uncorrect_error_status(pdev);
5732
Andrew Vasquez85880802009-12-15 21:29:46 -08005733 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005734}
5735
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04005736static void
5737qla83xx_disable_laser(scsi_qla_host_t *vha)
5738{
5739 uint32_t reg, data, fn;
5740 struct qla_hw_data *ha = vha->hw;
5741 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5742
5743 /* pci func #/port # */
5744 ql_dbg(ql_dbg_init, vha, 0x004b,
5745 "Disabling Laser for hba: %p\n", vha);
5746
5747 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5748 (BIT_15|BIT_14|BIT_13|BIT_12));
5749
5750 fn = (fn >> 12);
5751
5752 if (fn & 1)
5753 reg = PORT_1_2031;
5754 else
5755 reg = PORT_0_2031;
5756
5757 data = LASER_OFF_2031;
5758
5759 qla83xx_wr_reg(vha, reg, data);
5760}
5761
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005762static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005763 .error_detected = qla2xxx_pci_error_detected,
5764 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5765 .slot_reset = qla2xxx_pci_slot_reset,
5766 .resume = qla2xxx_pci_resume,
5767};
5768
Andrew Vasquez54333832005-11-09 15:49:04 -08005769static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005770 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5771 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5772 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5773 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5774 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5775 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5776 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5777 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5778 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005779 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005780 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5781 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005782 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005783 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005784 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005785 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005786 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005787 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005788 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05005789 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005790 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04005791 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005792 { 0 },
5793};
5794MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5795
Andrew Vasquezfca29702005-07-06 10:31:47 -07005796static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005797 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005798 .driver = {
5799 .owner = THIS_MODULE,
5800 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005801 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005802 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005803 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005804 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005805 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005806};
5807
Al Viro75ef9de2013-04-04 19:09:41 -04005808static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005809 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005810 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005811};
5812
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813/**
5814 * qla2x00_module_init - Module initialization.
5815 **/
5816static int __init
5817qla2x00_module_init(void)
5818{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005819 int ret = 0;
5820
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005822 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005823 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005825 ql_log(ql_log_fatal, NULL, 0x0001,
5826 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827 return -ENOMEM;
5828 }
5829
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005830 /* Initialize target kmem_cache and mem_pools */
5831 ret = qlt_init();
5832 if (ret < 0) {
5833 kmem_cache_destroy(srb_cachep);
5834 return ret;
5835 } else if (ret > 0) {
5836 /*
5837 * If initiator mode is explictly disabled by qlt_init(),
5838 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5839 * performing scsi_scan_target() during LOOP UP event.
5840 */
5841 qla2xxx_transport_functions.disable_target_scan = 1;
5842 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5843 }
5844
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 /* Derive version string. */
5846 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005847 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005848 strcat(qla2x00_version_str, "-debug");
5849
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005850 qla2xxx_transport_template =
5851 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005852 if (!qla2xxx_transport_template) {
5853 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005854 ql_log(ql_log_fatal, NULL, 0x0002,
5855 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005856 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005858 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005859
5860 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5861 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005862 ql_log(ql_log_fatal, NULL, 0x0003,
5863 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005864 }
5865
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005866 qla2xxx_transport_vport_template =
5867 fc_attach_transport(&qla2xxx_transport_vport_functions);
5868 if (!qla2xxx_transport_vport_template) {
5869 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005870 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005871 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005872 ql_log(ql_log_fatal, NULL, 0x0004,
5873 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005874 return -ENODEV;
5875 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005876 ql_log(ql_log_info, NULL, 0x0005,
5877 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005878 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005879 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005880 if (ret) {
5881 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005882 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005883 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005884 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005885 ql_log(ql_log_fatal, NULL, 0x0006,
5886 "pci_register_driver failed...ret=%d Failing load!.\n",
5887 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005888 }
5889 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890}
5891
5892/**
5893 * qla2x00_module_exit - Module cleanup.
5894 **/
5895static void __exit
5896qla2x00_module_exit(void)
5897{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005898 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005899 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005900 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005901 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005902 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005903 if (ctx_cachep)
5904 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005906 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907}
5908
5909module_init(qla2x00_module_init);
5910module_exit(qla2x00_module_exit);
5911
5912MODULE_AUTHOR("QLogic Corporation");
5913MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5914MODULE_LICENSE("GPL");
5915MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005916MODULE_FIRMWARE(FW_FILE_ISP21XX);
5917MODULE_FIRMWARE(FW_FILE_ISP22XX);
5918MODULE_FIRMWARE(FW_FILE_ISP2300);
5919MODULE_FIRMWARE(FW_FILE_ISP2322);
5920MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005921MODULE_FIRMWARE(FW_FILE_ISP25XX);
Sawan Chandakf1458cd2015-04-09 14:59:59 -04005922MODULE_FIRMWARE(FW_FILE_ISP2031);
5923MODULE_FIRMWARE(FW_FILE_ISP8031);
5924MODULE_FIRMWARE(FW_FILE_ISP27XX);