blob: 2c3c6afe88a3e7aa72f7390acb99b86bb2c80280 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Andrew Vasquez3420d362009-10-13 15:16:45 -070014#include <linux/kobject.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <scsi/scsi_tcq.h>
17#include <scsi/scsicam.h>
18#include <scsi/scsi_transport.h>
19#include <scsi/scsi_transport_fc.h>
20
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040021#include "qla_target.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24 * Driver version
25 */
26char qla2x00_version_str[40];
27
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070028static int apidev_major;
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/*
31 * SRB allocation cache
32 */
Christoph Lametere18b8902006-12-06 20:33:20 -080033static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Giridhar Malavalia9083012010-04-12 17:59:55 -070035/*
36 * CT6 CTX allocation cache
37 */
38static struct kmem_cache *ctx_cachep;
Saurav Kashyap3ce88662011-07-14 12:00:12 -070039/*
40 * error level for logging
41 */
42int ql_errlev = ql_log_all;
Giridhar Malavalia9083012010-04-12 17:59:55 -070043
Saurav Kashyapfa492632012-11-21 02:40:29 -050044static int ql2xenableclass2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040045module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
46MODULE_PARM_DESC(ql2xenableclass2,
47 "Specify if Class 2 operations are supported from the very "
48 "beginning. Default is 0 - class 2 not supported.");
49
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080052module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053MODULE_PARM_DESC(ql2xlogintimeout,
54 "Login timeout value in seconds.");
55
Andrew Vasqueza7b61842007-05-07 07:42:59 -070056int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080057module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070059 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 "a PORT-DOWN status.");
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int ql2xplogiabsentdevice;
63module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
64MODULE_PARM_DESC(ql2xplogiabsentdevice,
65 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070066 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080070module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071MODULE_PARM_DESC(ql2xloginretrycount,
72 "Specify an alternate value for the NVRAM login retry count.");
73
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070074int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080075module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070076MODULE_PARM_DESC(ql2xallocfwdump,
77 "Option to enable allocation of memory for a firmware dump "
78 "during HBA initialization. Memory allocation requirements "
79 "vary by ISP type. Default is 1 - allocate memory.");
80
Andrew Vasquez11010fe2006-10-06 09:54:59 -070081int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070082module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070083MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070084 "Option to enable extended error logging,\n"
85 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
86 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
87 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
88 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
89 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
90 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
91 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
92 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050093 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
94 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070095 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080096 "\t\t0x1e400000 - Preferred value for capturing essential "
97 "debug information (equivalent to old "
98 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070099 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700100
Giridhar Malavalia9083012010-04-12 17:59:55 -0700101int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800102module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700103MODULE_PARM_DESC(ql2xshiftctondsd,
104 "Set to control shifting of command type processing "
105 "based on total number of SG elements.");
106
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700107int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400108module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700109MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100110 "Enables FDMI registrations. "
111 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700112
Chad Dupuis50280c02013-10-30 03:38:14 -0400113#define MAX_Q_DEPTH 32
114static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700115module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
116MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400117 "Maximum queue depth to set for each LUN. "
118 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700119
Arun Easi9e522cd2012-08-22 14:21:31 -0400120int ql2xenabledif = 2;
121module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700122MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600123 " Enable T10-CRC-DIF:\n"
124 " Default is 2.\n"
125 " 0 -- No DIF Support\n"
126 " 1 -- Enable DIF for all types\n"
127 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700128
Arun Easi8cb20492011-08-16 11:29:22 -0700129int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700130module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
131MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700132 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600133 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700134 " 0 -- Error isolation disabled\n"
135 " 1 -- Error isolation enabled only for DIX Type 0\n"
136 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700137
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700138int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800139module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700140MODULE_PARM_DESC(ql2xiidmaenable,
141 "Enables iIDMA settings "
142 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
143
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800144int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800145module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800146MODULE_PARM_DESC(ql2xmaxqueues,
147 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700148 "Default is 1 for single queue. Set it to number "
149 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700150
151int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800152module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700153MODULE_PARM_DESC(ql2xmultique_tag,
154 "Enables CPU affinity settings for the driver "
155 "Default is 0 for no affinity of request and response IO. "
156 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700157
158int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700159module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700160MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 "Option to specify location from which to load ISP firmware:.\n"
162 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700163 " interface.\n"
164 " 1 -- load firmware from flash.\n"
165 " 0 -- use default semantics.\n");
166
Andrew Vasquezae97c912010-02-18 10:07:28 -0800167int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800168module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800169MODULE_PARM_DESC(ql2xetsenable,
170 "Enables firmware ETS burst."
171 "Default is 0 - skip ETS enablement.");
172
Giridhar Malavali69078692010-05-28 15:08:28 -0700173int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700174module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700175MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700176 "Option to specify scheme for request queue posting.\n"
177 " 0 -- Regular doorbell.\n"
178 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700179
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700180int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800181module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700182MODULE_PARM_DESC(ql2xtargetreset,
183 "Enable target reset."
184 "Default is 1 - use hw defaults.");
185
Chad Dupuis4da26e12010-10-15 11:27:40 -0700186int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800187module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700188MODULE_PARM_DESC(ql2xgffidenable,
189 "Enables GFF_ID checks of port type. "
190 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700191
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700192int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800193module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700194MODULE_PARM_DESC(ql2xasynctmfenable,
195 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
196 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700197
198int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700199module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700200MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700201 "Option to specify reset behaviour.\n"
202 " 0 (Default) -- Reset on failure.\n"
203 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700204
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200205uint64_t ql2xmaxlun = MAX_LUNS;
206module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700207MODULE_PARM_DESC(ql2xmaxlun,
208 "Defines the maximum LU number to register with the SCSI "
209 "midlayer. Default is 65535.");
210
Giridhar Malavali08de2842011-08-16 11:31:44 -0700211int ql2xmdcapmask = 0x1F;
212module_param(ql2xmdcapmask, int, S_IRUGO);
213MODULE_PARM_DESC(ql2xmdcapmask,
214 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800215 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700216
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800217int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700218module_param(ql2xmdenable, int, S_IRUGO);
219MODULE_PARM_DESC(ql2xmdenable,
220 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800221 "0 - MiniDump disabled. "
222 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700225 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 */
227static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500228static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800229static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
230static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500231static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500232static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static int qla2xxx_eh_abort(struct scsi_cmnd *);
234static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700235static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
237static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Mike Christiee881a172009-10-15 17:46:39 -0700239static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700240static int qla2x00_change_queue_type(struct scsi_device *, int);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400241static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400242static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400243static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700244
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700245struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700247 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700248 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700249
250 .eh_abort_handler = qla2xxx_eh_abort,
251 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700252 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700253 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
254 .eh_host_reset_handler = qla2xxx_eh_host_reset,
255
256 .slave_configure = qla2xxx_slave_configure,
257
258 .slave_alloc = qla2xxx_slave_alloc,
259 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700260 .scan_finished = qla2xxx_scan_finished,
261 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700262 .change_queue_depth = qla2x00_change_queue_depth,
263 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700264 .this_id = -1,
265 .cmd_per_lun = 3,
266 .use_clustering = ENABLE_CLUSTERING,
267 .sg_tablesize = SG_ALL,
268
269 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700270 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400271
272 .supported_mode = MODE_INITIATOR,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700273};
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700276struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278/* TODO Convert to inlines
279 *
280 * Timer routines
281 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700283__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800284qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800286 init_timer(&vha->timer);
287 vha->timer.expires = jiffies + interval * HZ;
288 vha->timer.data = (unsigned long)vha;
289 vha->timer.function = (void (*)(unsigned long))func;
290 add_timer(&vha->timer);
291 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
294static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800295qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700297 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700298 if (vha->device_flags & DFLG_DEV_FAILED) {
299 ql_dbg(ql_dbg_timer, vha, 0x600d,
300 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700301 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700302 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700303
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800304 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
Adrian Bunka824ebb2008-01-17 09:02:15 -0800307static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800308qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800310 del_timer_sync(&vha->timer);
311 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314static int qla2x00_do_dpc(void *data);
315
316static void qla2x00_rst_aen(scsi_qla_host_t *);
317
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800318static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
319 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700320static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800321static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400324static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
325 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800326{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700327 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700328 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800329 GFP_KERNEL);
330 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700331 ql_log(ql_log_fatal, vha, 0x003b,
332 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800333 goto fail_req_map;
334 }
335
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700336 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800337 GFP_KERNEL);
338 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700339 ql_log(ql_log_fatal, vha, 0x003c,
340 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800341 goto fail_rsp_map;
342 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400343 /*
344 * Make sure we record at least the request and response queue zero in
345 * case we need to free them if part of the probe fails.
346 */
347 ha->rsp_q_map[0] = rsp;
348 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800349 set_bit(0, ha->rsp_qid_map);
350 set_bit(0, ha->req_qid_map);
351 return 1;
352
353fail_rsp_map:
354 kfree(ha->req_q_map);
355 ha->req_q_map = NULL;
356fail_req_map:
357 return -ENOMEM;
358}
359
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700360static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800361{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400362 if (IS_QLAFX00(ha)) {
363 if (req && req->ring_fx00)
364 dma_free_coherent(&ha->pdev->dev,
365 (req->length_fx00 + 1) * sizeof(request_t),
366 req->ring_fx00, req->dma_fx00);
367 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800368 dma_free_coherent(&ha->pdev->dev,
369 (req->length + 1) * sizeof(request_t),
370 req->ring, req->dma);
371
Chad Dupuis8d93f552013-01-30 03:34:37 -0500372 if (req)
373 kfree(req->outstanding_cmds);
374
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800375 kfree(req);
376 req = NULL;
377}
378
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700379static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
380{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400381 if (IS_QLAFX00(ha)) {
382 if (rsp && rsp->ring)
383 dma_free_coherent(&ha->pdev->dev,
384 (rsp->length_fx00 + 1) * sizeof(request_t),
385 rsp->ring_fx00, rsp->dma_fx00);
386 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700387 dma_free_coherent(&ha->pdev->dev,
388 (rsp->length + 1) * sizeof(response_t),
389 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400390 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700391 kfree(rsp);
392 rsp = NULL;
393}
394
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800395static void qla2x00_free_queues(struct qla_hw_data *ha)
396{
397 struct req_que *req;
398 struct rsp_que *rsp;
399 int cnt;
400
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700401 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800402 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700403 qla2x00_free_req_que(ha, req);
404 }
405 kfree(ha->req_q_map);
406 ha->req_q_map = NULL;
407
408 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
409 rsp = ha->rsp_q_map[cnt];
410 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800411 }
412 kfree(ha->rsp_q_map);
413 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800414}
415
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700416static int qla25xx_setup_mode(struct scsi_qla_host *vha)
417{
418 uint16_t options = 0;
419 int ques, req, ret;
420 struct qla_hw_data *ha = vha->hw;
421
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700422 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700423 ql_log(ql_log_warn, vha, 0x00d8,
424 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700425 goto fail;
426 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700427 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700428 /* create a request queue for IO */
429 options |= BIT_7;
430 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
431 QLA_DEFAULT_QUE_QOS);
432 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700433 ql_log(ql_log_warn, vha, 0x00e0,
434 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700435 goto fail;
436 }
Tejun Heo278274d2011-02-01 11:42:42 +0100437 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700438 vha->req = ha->req_q_map[req];
439 options |= BIT_1;
440 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
441 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
442 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700443 ql_log(ql_log_warn, vha, 0x00e8,
444 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700445 goto fail2;
446 }
447 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700448 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700449 ql_dbg(ql_dbg_multiq, vha, 0xc007,
450 "CPU affinity mode enalbed, "
451 "no. of response queues:%d no. of request queues:%d.\n",
452 ha->max_rsp_queues, ha->max_req_queues);
453 ql_dbg(ql_dbg_init, vha, 0x00e9,
454 "CPU affinity mode enalbed, "
455 "no. of response queues:%d no. of request queues:%d.\n",
456 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700457 }
458 return 0;
459fail2:
460 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700461 destroy_workqueue(ha->wq);
462 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800463 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700464fail:
465 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700466 kfree(ha->req_q_map);
467 kfree(ha->rsp_q_map);
468 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700469 return 1;
470}
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800473qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800475 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 static char *pci_bus_modes[] = {
477 "33", "66", "100", "133",
478 };
479 uint16_t pci_bus;
480
481 strcpy(str, "PCI");
482 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
483 if (pci_bus) {
484 strcat(str, "-X (");
485 strcat(str, pci_bus_modes[pci_bus]);
486 } else {
487 pci_bus = (ha->pci_attr & BIT_8) >> 8;
488 strcat(str, " (");
489 strcat(str, pci_bus_modes[pci_bus]);
490 }
491 strcat(str, " MHz)");
492
493 return (str);
494}
495
Andrew Vasquezfca29702005-07-06 10:31:47 -0700496static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800497qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700498{
499 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700501 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700502
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600503 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700504 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600505 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600507 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
508 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
509 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700510
511 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500512 switch (lspeed) {
513 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700514 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500515 break;
516 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700517 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500518 break;
519 case 3:
520 strcat(str, "8.0GT/s ");
521 break;
522 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700523 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500524 break;
525 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700526 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
527 strcat(str, lwstr);
528
529 return str;
530 }
531
532 strcpy(str, "PCI");
533 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
534 if (pci_bus == 0 || pci_bus == 8) {
535 strcat(str, " (");
536 strcat(str, pci_bus_modes[pci_bus >> 3]);
537 } else {
538 strcat(str, "-X ");
539 if (pci_bus & BIT_2)
540 strcat(str, "Mode 2");
541 else
542 strcat(str, "Mode 1");
543 strcat(str, " (");
544 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
545 }
546 strcat(str, " MHz)");
547
548 return str;
549}
550
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800551static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400552qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700556
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400557 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
558 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 if (ha->fw_attributes & BIT_9) {
561 strcat(str, "FLX");
562 return (str);
563 }
564
565 switch (ha->fw_attributes & 0xFF) {
566 case 0x7:
567 strcat(str, "EF");
568 break;
569 case 0x17:
570 strcat(str, "TP");
571 break;
572 case 0x37:
573 strcat(str, "IP");
574 break;
575 case 0x77:
576 strcat(str, "VI");
577 break;
578 default:
579 sprintf(un_str, "(%x)", ha->fw_attributes);
580 strcat(str, un_str);
581 break;
582 }
583 if (ha->fw_attributes & 0x100)
584 strcat(str, "X");
585
586 return (str);
587}
588
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800589static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400590qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700593
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400594 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800595 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700596 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700597}
598
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800599void
600qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700601{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800602 srb_t *sp = (srb_t *)ptr;
603 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
604 struct qla_hw_data *ha = sp->fcport->vha->hw;
605 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700606
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800607 if (sp->flags & SRB_DMA_VALID) {
608 scsi_dma_unmap(cmd);
609 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700610 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800612 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
613 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
614 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
615 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
616 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700617
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800618 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
619 /* List assured to be having elements */
Quinn Tranf83adb62014-04-11 16:54:43 -0400620 qla2x00_clean_dsd_pool(ha, sp, NULL);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800621 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
622 }
623
624 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
625 dma_pool_free(ha->dl_dma_pool, ctx,
626 ((struct crc_context *)ctx)->crc_ctx_dma);
627 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
628 }
629
630 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
631 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
632
633 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
634 ctx1->fcp_cmnd_dma);
635 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
636 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
637 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
638 mempool_free(ctx1, ha->ctx_mempool);
639 ctx1 = NULL;
640 }
641
642 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500643 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800644}
645
Fengguang Wu14b06802013-04-25 01:29:19 -0400646static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800647qla2x00_sp_compl(void *data, void *ptr, int res)
648{
649 struct qla_hw_data *ha = (struct qla_hw_data *)data;
650 srb_t *sp = (srb_t *)ptr;
651 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
652
653 cmd->result = res;
654
655 if (atomic_read(&sp->ref_count) == 0) {
656 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
657 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
658 sp, GET_CMD_SP(sp));
659 if (ql2xextended_error_logging & ql_dbg_io)
660 BUG();
661 return;
662 }
663 if (!atomic_dec_and_test(&sp->ref_count))
664 return;
665
666 qla2x00_sp_free_dma(ha, sp);
667 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700668}
669
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400670/* If we are SP1 here, we need to still take and release the host_lock as SP1
671 * does not have the changes necessary to avoid taking host->host_lock.
672 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800674qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700675{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700676 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700677 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400678 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800679 struct qla_hw_data *ha = vha->hw;
680 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700681 srb_t *sp;
682 int rval;
683
Andrew Vasquez85880802009-12-15 21:29:46 -0800684 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700685 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400686 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 "PCI Channel IO permanent failure, exiting "
688 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700689 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700690 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400691 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700692 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800693 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700695 goto qc24_fail_command;
696 }
697
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400698 rval = fc_remote_port_chkready(rport);
699 if (rval) {
700 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400701 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700702 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
703 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700704 goto qc24_fail_command;
705 }
706
Arun Easibad75002010-05-04 15:01:30 -0700707 if (!vha->flags.difdix_supported &&
708 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700709 ql_dbg(ql_dbg_io, vha, 0x3004,
710 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
711 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700712 cmd->result = DID_NO_CONNECT << 16;
713 goto qc24_fail_command;
714 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800715
716 if (!fcport) {
717 cmd->result = DID_NO_CONNECT << 16;
718 goto qc24_fail_command;
719 }
720
Andrew Vasquezfca29702005-07-06 10:31:47 -0700721 if (atomic_read(&fcport->state) != FCS_ONLINE) {
722 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700723 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700724 ql_dbg(ql_dbg_io, vha, 0x3005,
725 "Returning DNC, fcport_state=%d loop_state=%d.\n",
726 atomic_read(&fcport->state),
727 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700728 cmd->result = DID_NO_CONNECT << 16;
729 goto qc24_fail_command;
730 }
Mike Christie7b594132008-08-17 15:24:40 -0500731 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700732 }
733
Chad Dupuise05fe292014-09-25 05:16:59 -0400734 /*
735 * Return target busy if we've received a non-zero retry_delay_timer
736 * in a FCP_RSP.
737 */
738 if (time_after(jiffies, fcport->retry_delay_timestamp))
739 fcport->retry_delay_timestamp = 0;
740 else
741 goto qc24_target_busy;
742
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500743 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400744 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800745 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700746
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800747 sp->u.scmd.cmd = cmd;
748 sp->type = SRB_SCSI_CMD;
749 atomic_set(&sp->ref_count, 1);
750 CMD_SP(cmd) = (void *)sp;
751 sp->free = qla2x00_sp_free_dma;
752 sp->done = qla2x00_sp_compl;
753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800754 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700755 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500756 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700757 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700758 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700759 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700760
Andrew Vasquezfca29702005-07-06 10:31:47 -0700761 return 0;
762
763qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800764 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700765
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800766qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700767 return SCSI_MLQUEUE_HOST_BUSY;
768
Mike Christie7b594132008-08-17 15:24:40 -0500769qc24_target_busy:
770 return SCSI_MLQUEUE_TARGET_BUSY;
771
Andrew Vasquezfca29702005-07-06 10:31:47 -0700772qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800773 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700774
775 return 0;
776}
777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778/*
779 * qla2x00_eh_wait_on_command
780 * Waits for the command to be returned by the Firmware for some
781 * max time.
782 *
783 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 *
786 * Return:
787 * Not Found : 0
788 * Found : 1
789 */
790static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700793#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -0400794#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500795 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800796 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
797 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500798 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Andrew Vasquez85880802009-12-15 21:29:46 -0800800 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700801 ql_dbg(ql_dbg_taskm, vha, 0x8005,
802 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800803 return ret;
804 }
805
Lalit Chandivaded9704322009-08-25 11:36:18 -0700806 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700807 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500808 }
809 if (CMD_SP(cmd))
810 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
f4f051e2005-04-17 15:02:26 -0500812 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
814
815/*
816 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700817 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 * <= MAX_RETRIES_OF_ISP_ABORT or
819 * finally HBA is disabled ie marked offline
820 *
821 * Input:
822 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700823 *
824 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 * Does context switching-Release SPIN_LOCK
826 * (if any) before calling this routine.
827 *
828 * Return:
829 * Success (Adapter is online) : 0
830 * Failed (Adapter is offline/disabled) : 1
831 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800832int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800833qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700835 int return_status;
836 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 struct qla_hw_data *ha = vha->hw;
838 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700840 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800841 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
842 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
843 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
844 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846 msleep(1000);
847 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800848 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700849 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 else
851 return_status = QLA_FUNCTION_FAILED;
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 return (return_status);
854}
855
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700856/*
Sawan Chandak638a1a02014-04-11 16:54:38 -0400857 * qla2x00_wait_for_hba_ready
858 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700859 *
860 * Input:
861 * ha - pointer to host adapter structure
862 *
863 * Note:
864 * Does context switching-Release SPIN_LOCK
865 * (if any) before calling this routine.
866 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700867 */
Sawan Chandak638a1a02014-04-11 16:54:38 -0400868static void
869qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700870{
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700871 struct qla_hw_data *ha = vha->hw;
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700872
Sawan Chandak9d35894d2014-09-25 05:16:52 -0400873 while (((qla2x00_reset_active(vha)) || ha->dpc_active ||
874 ha->flags.mbox_busy) ||
875 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
876 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags))
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700877 msleep(1000);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700878}
879
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700880int
881qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
882{
883 int return_status;
884 unsigned long wait_reset;
885 struct qla_hw_data *ha = vha->hw;
886 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
887
888 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
889 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
890 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
891 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
892 ha->dpc_active) && time_before(jiffies, wait_reset)) {
893
894 msleep(1000);
895
896 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
897 ha->flags.chip_reset_done)
898 break;
899 }
900 if (ha->flags.chip_reset_done)
901 return_status = QLA_SUCCESS;
902 else
903 return_status = QLA_FUNCTION_FAILED;
904
905 return return_status;
906}
907
Giridhar Malavali083a4692010-05-28 15:08:18 -0700908static void
909sp_get(struct srb *sp)
910{
911 atomic_inc(&sp->ref_count);
912}
913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914/**************************************************************************
915* qla2xxx_eh_abort
916*
917* Description:
918* The abort function will abort the specified command.
919*
920* Input:
921* cmd = Linux SCSI command packet to be aborted.
922*
923* Returns:
924* Either SUCCESS or FAILED.
925*
926* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700927* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800929static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930qla2xxx_eh_abort(struct scsi_cmnd *cmd)
931{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800932 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500933 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800934 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200935 unsigned int id;
936 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700937 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400938 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
f4f051e2005-04-17 15:02:26 -0500941 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700942 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800944 ret = fc_block_scsi_eh(cmd);
945 if (ret != 0)
946 return ret;
947 ret = SUCCESS;
948
f4f051e2005-04-17 15:02:26 -0500949 id = cmd->device->id;
950 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800952 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700953 sp = (srb_t *) CMD_SP(cmd);
954 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800955 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700956 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500957 }
Mike Christie170babc2010-10-15 11:27:47 -0700958
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700959 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200960 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800961 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700962
963 /* Get a reference to the sp and drop the lock.*/
964 sp_get(sp);
965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800966 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400967 rval = ha->isp_ops->abort_command(sp);
968 if (rval) {
969 if (rval == QLA_FUNCTION_PARAMETER_ERROR) {
970 /*
971 * Decrement the ref_count since we can't find the
972 * command
973 */
974 atomic_dec(&sp->ref_count);
975 ret = SUCCESS;
976 } else
977 ret = FAILED;
978
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700979 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400980 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -0700981 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700982 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800983 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700984 wait = 1;
985 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700986
987 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -0400988 /*
989 * Clear the slot in the oustanding_cmds array if we can't find the
990 * command to reclaim the resources.
991 */
992 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
993 vha->req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800994 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700995 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500996
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700997 /* Did the command return during mailbox execution? */
998 if (ret == FAILED && !CMD_SP(cmd))
999 ret = SUCCESS;
1000
f4f051e2005-04-17 15:02:26 -05001001 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001002 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001004 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001005 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001006 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001010 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001011 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001012 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
f4f051e2005-04-17 15:02:26 -05001014 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001017int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001019 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001021 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001022 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001023 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001024 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001025 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001026 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Andrew Vasquez523ec772008-04-03 13:13:24 -07001028 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001029
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001030 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001031 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001032 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001033 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001034 sp = req->outstanding_cmds[cnt];
1035 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001036 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001037 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001038 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001039 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1040 continue;
1041 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001042 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001043 switch (type) {
1044 case WAIT_HOST:
1045 match = 1;
1046 break;
1047 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001048 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001049 break;
1050 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001051 match = (cmd->device->id == t &&
1052 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001053 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001055 if (!match)
1056 continue;
1057
1058 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001059 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001060 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001062 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001063
1064 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Andrew Vasquez523ec772008-04-03 13:13:24 -07001067static char *reset_errors[] = {
1068 "HBA not online",
1069 "HBA not ready",
1070 "Task management failed",
1071 "Waiting for command completions",
1072};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Andrew Vasquez523ec772008-04-03 13:13:24 -07001074static int
1075__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001076 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001077{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001079 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1080 int err;
1081
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001082 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001083 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001085
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001086 err = fc_block_scsi_eh(cmd);
1087 if (err != 0)
1088 return err;
1089
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001090 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001091 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001092 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001093
1094 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001095 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1096 ql_log(ql_log_warn, vha, 0x800a,
1097 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001098 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001099 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001100 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001101 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001102 != QLA_SUCCESS) {
1103 ql_log(ql_log_warn, vha, 0x800c,
1104 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001105 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001106 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001107 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001108 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001109 cmd->device->lun, type) != QLA_SUCCESS) {
1110 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001111 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001112 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001114
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001115 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001116 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001117 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001118
1119 return SUCCESS;
1120
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001121eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001122 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001123 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001124 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1125 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001126 return FAILED;
1127}
1128
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001129static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1131{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001132 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1133 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Andrew Vasquez523ec772008-04-03 13:13:24 -07001135 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1136 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001140qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001142 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1143 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Andrew Vasquez523ec772008-04-03 13:13:24 -07001145 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1146 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149/**************************************************************************
1150* qla2xxx_eh_bus_reset
1151*
1152* Description:
1153* The bus reset function will reset the bus and abort any executing
1154* commands.
1155*
1156* Input:
1157* cmd = Linux SCSI command packet of the command that cause the
1158* bus reset.
1159*
1160* Returns:
1161* SUCCESS/FAILURE (defined as macro in scsi.h).
1162*
1163**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001164static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1166{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001167 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001168 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001169 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001170 unsigned int id;
1171 uint64_t lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
f4f051e2005-04-17 15:02:26 -05001173 id = cmd->device->id;
1174 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001175
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001176 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001177 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001180 ret = fc_block_scsi_eh(cmd);
1181 if (ret != 0)
1182 return ret;
1183 ret = FAILED;
1184
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001185 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001186 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001188 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001189 ql_log(ql_log_fatal, vha, 0x8013,
1190 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001191 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193
Saurav Kashyapad537682011-11-18 09:02:09 -08001194 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1195 ret = SUCCESS;
1196
f4f051e2005-04-17 15:02:26 -05001197 if (ret == FAILED)
1198 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001200 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001201 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001202 QLA_SUCCESS) {
1203 ql_log(ql_log_warn, vha, 0x8014,
1204 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001205 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
f4f051e2005-04-17 15:02:26 -05001208eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001209 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001210 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001211 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
f4f051e2005-04-17 15:02:26 -05001213 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
1216/**************************************************************************
1217* qla2xxx_eh_host_reset
1218*
1219* Description:
1220* The reset function will reset the Adapter.
1221*
1222* Input:
1223* cmd = Linux SCSI command packet of the command that cause the
1224* adapter reset.
1225*
1226* Returns:
1227* Either SUCCESS or FAILED.
1228*
1229* Note:
1230**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001231static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1233{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001234 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001236 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001237 unsigned int id;
1238 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
f4f051e2005-04-17 15:02:26 -05001241 id = cmd->device->id;
1242 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001243
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001244 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001245 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
Chad Dupuis63ee7072014-04-11 16:54:46 -04001247 /*
1248 * No point in issuing another reset if one is active. Also do not
1249 * attempt a reset if we are updating flash.
1250 */
1251 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001252 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001254 if (vha != base_vha) {
1255 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001256 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001257 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001258 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001259 if (!qla82xx_fcoe_ctx_reset(vha)) {
1260 /* Ctx reset success */
1261 ret = SUCCESS;
1262 goto eh_host_reset_lock;
1263 }
1264 /* fall thru if ctx reset failed */
1265 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001266 if (ha->wq)
1267 flush_workqueue(ha->wq);
1268
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001269 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001270 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001271 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1272 /* failed. schedule dpc to try */
1273 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1274
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001275 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1276 ql_log(ql_log_warn, vha, 0x802a,
1277 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001278 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001279 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001280 }
1281 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001284 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001285 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001286 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001287 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
f4f051e2005-04-17 15:02:26 -05001289eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001290 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001291 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001292 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
f4f051e2005-04-17 15:02:26 -05001294 return ret;
1295}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297/*
1298* qla2x00_loop_reset
1299* Issue loop reset.
1300*
1301* Input:
1302* ha = adapter block pointer.
1303*
1304* Returns:
1305* 0 = success
1306*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001307int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001310 int ret;
bdf79622005-04-17 15:06:53 -05001311 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Armen Baloyan58547712013-08-27 01:37:33 -04001314 if (IS_QLAFX00(ha)) {
1315 return qlafx00_loop_reset(vha);
1316 }
1317
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001318 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001319 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1320 if (fcport->port_type != FCT_TARGET)
1321 continue;
1322
1323 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1324 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001326 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001327 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001328 }
1329 }
1330 }
1331
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001332
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001333 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001334 atomic_set(&vha->loop_state, LOOP_DOWN);
1335 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1336 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001337 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001338 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001339 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1340 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001344 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001345 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001346 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001347 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1348 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001349 }
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001354 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001357void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001358qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001359{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001360 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001361 unsigned long flags;
1362 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001363 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001364 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001365
1366 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001367 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001368 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001369 if (!req)
1370 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001371 if (!req->outstanding_cmds)
1372 continue;
1373 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001374 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001375 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001376 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001377 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001378 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001379 }
1380 }
1381 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1382}
1383
f4f051e2005-04-17 15:02:26 -05001384static int
1385qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
bdf79622005-04-17 15:06:53 -05001387 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001389 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001390 return -ENXIO;
1391
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001392 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001393
1394 return 0;
1395}
1396
1397static int
1398qla2xxx_slave_configure(struct scsi_device *sdev)
1399{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001400 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001401 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001402
Arun Easi9e522cd2012-08-22 14:21:31 -04001403 if (IS_T10_PI_CAPABLE(vha->hw))
1404 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1405
f4f051e2005-04-17 15:02:26 -05001406 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001407 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001409 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001410 return 0;
1411}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
f4f051e2005-04-17 15:02:26 -05001413static void
1414qla2xxx_slave_destroy(struct scsi_device *sdev)
1415{
1416 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417}
1418
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001419static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1420{
1421 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1422
1423 if (!scsi_track_queue_full(sdev, qdepth))
1424 return;
1425
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001426 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001427 "Queue depth adjusted-down to %d for nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001428 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001429}
1430
1431static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1432{
1433 fc_port_t *fcport = sdev->hostdata;
1434 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001435 struct req_que *req = NULL;
1436
1437 req = vha->req;
1438 if (!req)
1439 return;
1440
1441 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1442 return;
1443
1444 if (sdev->ordered_tags)
1445 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1446 else
1447 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1448
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001449 ql_dbg(ql_dbg_io, vha, 0x302a,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001450 "Queue depth adjusted-up to %d for nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001451 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001452}
1453
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001454static int
Mike Christiee881a172009-10-15 17:46:39 -07001455qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001456{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001457 switch (reason) {
1458 case SCSI_QDEPTH_DEFAULT:
1459 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1460 break;
1461 case SCSI_QDEPTH_QFULL:
1462 qla2x00_handle_queue_full(sdev, qdepth);
1463 break;
1464 case SCSI_QDEPTH_RAMP_UP:
1465 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1466 break;
1467 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001468 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001469 }
Mike Christiee881a172009-10-15 17:46:39 -07001470
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001471 return sdev->queue_depth;
1472}
1473
1474static int
1475qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1476{
1477 if (sdev->tagged_supported) {
1478 scsi_set_tag_type(sdev, tag_type);
1479 if (tag_type)
1480 scsi_activate_tcq(sdev, sdev->queue_depth);
1481 else
1482 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1483 } else
1484 tag_type = 0;
1485
1486 return tag_type;
1487}
1488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489/**
1490 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1491 * @ha: HA context
1492 *
1493 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1494 * supported addressing method.
1495 */
1496static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001497qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001499 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Yang Hongyang6a355282009-04-06 19:01:13 -07001502 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001503 /* Any upper-dword bits set? */
1504 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001505 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001506 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001508 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1509 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001510 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001513
Yang Hongyang284901a2009-04-06 19:01:15 -07001514 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1515 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001518static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001520{
1521 unsigned long flags = 0;
1522 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1523
1524 spin_lock_irqsave(&ha->hardware_lock, flags);
1525 ha->interrupts_on = 1;
1526 /* enable risc and host interrupts */
1527 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1528 RD_REG_WORD(&reg->ictrl);
1529 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1530
1531}
1532
1533static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001534qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001535{
1536 unsigned long flags = 0;
1537 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1538
1539 spin_lock_irqsave(&ha->hardware_lock, flags);
1540 ha->interrupts_on = 0;
1541 /* disable risc and host interrupts */
1542 WRT_REG_WORD(&reg->ictrl, 0);
1543 RD_REG_WORD(&reg->ictrl);
1544 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1545}
1546
1547static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001548qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001549{
1550 unsigned long flags = 0;
1551 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1552
1553 spin_lock_irqsave(&ha->hardware_lock, flags);
1554 ha->interrupts_on = 1;
1555 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1556 RD_REG_DWORD(&reg->ictrl);
1557 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1558}
1559
1560static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001562{
1563 unsigned long flags = 0;
1564 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1565
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001566 if (IS_NOPOLLING_TYPE(ha))
1567 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001568 spin_lock_irqsave(&ha->hardware_lock, flags);
1569 ha->interrupts_on = 0;
1570 WRT_REG_DWORD(&reg->ictrl, 0);
1571 RD_REG_DWORD(&reg->ictrl);
1572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1573}
1574
Giridhar Malavali706f4572011-11-18 09:03:16 -08001575static int
1576qla2x00_iospace_config(struct qla_hw_data *ha)
1577{
1578 resource_size_t pio;
1579 uint16_t msix;
1580 int cpus;
1581
Giridhar Malavali706f4572011-11-18 09:03:16 -08001582 if (pci_request_selected_regions(ha->pdev, ha->bars,
1583 QLA2XXX_DRIVER_NAME)) {
1584 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1585 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1586 pci_name(ha->pdev));
1587 goto iospace_error_exit;
1588 }
1589 if (!(ha->bars & 1))
1590 goto skip_pio;
1591
1592 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1593 pio = pci_resource_start(ha->pdev, 0);
1594 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1595 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1596 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1597 "Invalid pci I/O region size (%s).\n",
1598 pci_name(ha->pdev));
1599 pio = 0;
1600 }
1601 } else {
1602 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1603 "Region #0 no a PIO resource (%s).\n",
1604 pci_name(ha->pdev));
1605 pio = 0;
1606 }
1607 ha->pio_address = pio;
1608 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1609 "PIO address=%llu.\n",
1610 (unsigned long long)ha->pio_address);
1611
1612skip_pio:
1613 /* Use MMIO operations for all accesses. */
1614 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1615 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1616 "Region #1 not an MMIO resource (%s), aborting.\n",
1617 pci_name(ha->pdev));
1618 goto iospace_error_exit;
1619 }
1620 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1621 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1622 "Invalid PCI mem region size (%s), aborting.\n",
1623 pci_name(ha->pdev));
1624 goto iospace_error_exit;
1625 }
1626
1627 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1628 if (!ha->iobase) {
1629 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1630 "Cannot remap MMIO (%s), aborting.\n",
1631 pci_name(ha->pdev));
1632 goto iospace_error_exit;
1633 }
1634
1635 /* Determine queue resources */
1636 ha->max_req_queues = ha->max_rsp_queues = 1;
1637 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1638 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1639 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1640 goto mqiobase_exit;
1641
1642 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1643 pci_resource_len(ha->pdev, 3));
1644 if (ha->mqiobase) {
1645 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1646 "MQIO Base=%p.\n", ha->mqiobase);
1647 /* Read MSIX vector size of the board */
1648 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1649 ha->msix_count = msix;
1650 /* Max queues are bounded by available msix vectors */
1651 /* queue 0 uses two msix vectors */
1652 if (ql2xmultique_tag) {
1653 cpus = num_online_cpus();
1654 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1655 (cpus + 1) : (ha->msix_count - 1);
1656 ha->max_req_queues = 2;
1657 } else if (ql2xmaxqueues > 1) {
1658 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1659 QLA_MQ_SIZE : ql2xmaxqueues;
1660 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1661 "QoS mode set, max no of request queues:%d.\n",
1662 ha->max_req_queues);
1663 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1664 "QoS mode set, max no of request queues:%d.\n",
1665 ha->max_req_queues);
1666 }
1667 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1668 "MSI-X vector count: %d.\n", msix);
1669 } else
1670 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1671 "BAR 3 not enabled.\n");
1672
1673mqiobase_exit:
1674 ha->msix_count = ha->max_rsp_queues + 1;
1675 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1676 "MSIX Count:%d.\n", ha->msix_count);
1677 return (0);
1678
1679iospace_error_exit:
1680 return (-ENOMEM);
1681}
1682
1683
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001684static int
1685qla83xx_iospace_config(struct qla_hw_data *ha)
1686{
1687 uint16_t msix;
1688 int cpus;
1689
1690 if (pci_request_selected_regions(ha->pdev, ha->bars,
1691 QLA2XXX_DRIVER_NAME)) {
1692 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1693 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1694 pci_name(ha->pdev));
1695
1696 goto iospace_error_exit;
1697 }
1698
1699 /* Use MMIO operations for all accesses. */
1700 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1701 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1702 "Invalid pci I/O region size (%s).\n",
1703 pci_name(ha->pdev));
1704 goto iospace_error_exit;
1705 }
1706 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1707 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1708 "Invalid PCI mem region size (%s), aborting\n",
1709 pci_name(ha->pdev));
1710 goto iospace_error_exit;
1711 }
1712
1713 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1714 if (!ha->iobase) {
1715 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1716 "Cannot remap MMIO (%s), aborting.\n",
1717 pci_name(ha->pdev));
1718 goto iospace_error_exit;
1719 }
1720
1721 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1722 /* 83XX 26XX always use MQ type access for queues
1723 * - mbar 2, a.k.a region 4 */
1724 ha->max_req_queues = ha->max_rsp_queues = 1;
1725 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1726 pci_resource_len(ha->pdev, 4));
1727
1728 if (!ha->mqiobase) {
1729 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1730 "BAR2/region4 not enabled\n");
1731 goto mqiobase_exit;
1732 }
1733
1734 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1735 pci_resource_len(ha->pdev, 2));
1736 if (ha->msixbase) {
1737 /* Read MSIX vector size of the board */
1738 pci_read_config_word(ha->pdev,
1739 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1740 ha->msix_count = msix;
1741 /* Max queues are bounded by available msix vectors */
1742 /* queue 0 uses two msix vectors */
1743 if (ql2xmultique_tag) {
1744 cpus = num_online_cpus();
1745 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1746 (cpus + 1) : (ha->msix_count - 1);
1747 ha->max_req_queues = 2;
1748 } else if (ql2xmaxqueues > 1) {
1749 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1750 QLA_MQ_SIZE : ql2xmaxqueues;
1751 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1752 "QoS mode set, max no of request queues:%d.\n",
1753 ha->max_req_queues);
1754 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1755 "QoS mode set, max no of request queues:%d.\n",
1756 ha->max_req_queues);
1757 }
1758 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1759 "MSI-X vector count: %d.\n", msix);
1760 } else
1761 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1762 "BAR 1 not enabled.\n");
1763
1764mqiobase_exit:
1765 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001766
1767 qlt_83xx_iospace_config(ha);
1768
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001769 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1770 "MSIX Count:%d.\n", ha->msix_count);
1771 return 0;
1772
1773iospace_error_exit:
1774 return -ENOMEM;
1775}
1776
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001777static struct isp_operations qla2100_isp_ops = {
1778 .pci_config = qla2100_pci_config,
1779 .reset_chip = qla2x00_reset_chip,
1780 .chip_diag = qla2x00_chip_diag,
1781 .config_rings = qla2x00_config_rings,
1782 .reset_adapter = qla2x00_reset_adapter,
1783 .nvram_config = qla2x00_nvram_config,
1784 .update_fw_options = qla2x00_update_fw_options,
1785 .load_risc = qla2x00_load_risc,
1786 .pci_info_str = qla2x00_pci_info_str,
1787 .fw_version_str = qla2x00_fw_version_str,
1788 .intr_handler = qla2100_intr_handler,
1789 .enable_intrs = qla2x00_enable_intrs,
1790 .disable_intrs = qla2x00_disable_intrs,
1791 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001792 .target_reset = qla2x00_abort_target,
1793 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001794 .fabric_login = qla2x00_login_fabric,
1795 .fabric_logout = qla2x00_fabric_logout,
1796 .calc_req_entries = qla2x00_calc_iocbs_32,
1797 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1798 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1799 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1800 .read_nvram = qla2x00_read_nvram_data,
1801 .write_nvram = qla2x00_write_nvram_data,
1802 .fw_dump = qla2100_fw_dump,
1803 .beacon_on = NULL,
1804 .beacon_off = NULL,
1805 .beacon_blink = NULL,
1806 .read_optrom = qla2x00_read_optrom_data,
1807 .write_optrom = qla2x00_write_optrom_data,
1808 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001810 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001811 .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
1815static struct isp_operations qla2300_isp_ops = {
1816 .pci_config = qla2300_pci_config,
1817 .reset_chip = qla2x00_reset_chip,
1818 .chip_diag = qla2x00_chip_diag,
1819 .config_rings = qla2x00_config_rings,
1820 .reset_adapter = qla2x00_reset_adapter,
1821 .nvram_config = qla2x00_nvram_config,
1822 .update_fw_options = qla2x00_update_fw_options,
1823 .load_risc = qla2x00_load_risc,
1824 .pci_info_str = qla2x00_pci_info_str,
1825 .fw_version_str = qla2x00_fw_version_str,
1826 .intr_handler = qla2300_intr_handler,
1827 .enable_intrs = qla2x00_enable_intrs,
1828 .disable_intrs = qla2x00_disable_intrs,
1829 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001830 .target_reset = qla2x00_abort_target,
1831 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001832 .fabric_login = qla2x00_login_fabric,
1833 .fabric_logout = qla2x00_fabric_logout,
1834 .calc_req_entries = qla2x00_calc_iocbs_32,
1835 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1836 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1837 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1838 .read_nvram = qla2x00_read_nvram_data,
1839 .write_nvram = qla2x00_write_nvram_data,
1840 .fw_dump = qla2300_fw_dump,
1841 .beacon_on = qla2x00_beacon_on,
1842 .beacon_off = qla2x00_beacon_off,
1843 .beacon_blink = qla2x00_beacon_blink,
1844 .read_optrom = qla2x00_read_optrom_data,
1845 .write_optrom = qla2x00_write_optrom_data,
1846 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001847 .start_scsi = qla2x00_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 Vasquezfd34f552007-07-19 15:06:00 -07001851};
1852
1853static struct isp_operations qla24xx_isp_ops = {
1854 .pci_config = qla24xx_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 = qla24xx_nvram_config,
1860 .update_fw_options = qla24xx_update_fw_options,
1861 .load_risc = qla24xx_load_risc,
1862 .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,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001868 .target_reset = qla24xx_abort_target,
1869 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001870 .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,
1876 .read_nvram = qla24xx_read_nvram_data,
1877 .write_nvram = qla24xx_write_nvram_data,
1878 .fw_dump = qla24xx_fw_dump,
1879 .beacon_on = qla24xx_beacon_on,
1880 .beacon_off = qla24xx_beacon_off,
1881 .beacon_blink = qla24xx_beacon_blink,
1882 .read_optrom = qla24xx_read_optrom_data,
1883 .write_optrom = qla24xx_write_optrom_data,
1884 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885 .start_scsi = qla24xx_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,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001889};
1890
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001891static struct isp_operations qla25xx_isp_ops = {
1892 .pci_config = qla25xx_pci_config,
1893 .reset_chip = qla24xx_reset_chip,
1894 .chip_diag = qla24xx_chip_diag,
1895 .config_rings = qla24xx_config_rings,
1896 .reset_adapter = qla24xx_reset_adapter,
1897 .nvram_config = qla24xx_nvram_config,
1898 .update_fw_options = qla24xx_update_fw_options,
1899 .load_risc = qla24xx_load_risc,
1900 .pci_info_str = qla24xx_pci_info_str,
1901 .fw_version_str = qla24xx_fw_version_str,
1902 .intr_handler = qla24xx_intr_handler,
1903 .enable_intrs = qla24xx_enable_intrs,
1904 .disable_intrs = qla24xx_disable_intrs,
1905 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001906 .target_reset = qla24xx_abort_target,
1907 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001908 .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 = qla25xx_read_nvram_data,
1915 .write_nvram = qla25xx_write_nvram_data,
1916 .fw_dump = qla25xx_fw_dump,
1917 .beacon_on = qla24xx_beacon_on,
1918 .beacon_off = qla24xx_beacon_off,
1919 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001920 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001921 .write_optrom = qla24xx_write_optrom_data,
1922 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001923 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001924 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001925 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001926 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001927};
1928
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001929static struct isp_operations qla81xx_isp_ops = {
1930 .pci_config = qla25xx_pci_config,
1931 .reset_chip = qla24xx_reset_chip,
1932 .chip_diag = qla24xx_chip_diag,
1933 .config_rings = qla24xx_config_rings,
1934 .reset_adapter = qla24xx_reset_adapter,
1935 .nvram_config = qla81xx_nvram_config,
1936 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001937 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001938 .pci_info_str = qla24xx_pci_info_str,
1939 .fw_version_str = qla24xx_fw_version_str,
1940 .intr_handler = qla24xx_intr_handler,
1941 .enable_intrs = qla24xx_enable_intrs,
1942 .disable_intrs = qla24xx_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,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001952 .read_nvram = NULL,
1953 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001954 .fw_dump = qla81xx_fw_dump,
1955 .beacon_on = qla24xx_beacon_on,
1956 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001957 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001958 .read_optrom = qla25xx_read_optrom_data,
1959 .write_optrom = qla24xx_write_optrom_data,
1960 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001961 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001962 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001963 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001964 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001965};
1966
1967static struct isp_operations qla82xx_isp_ops = {
1968 .pci_config = qla82xx_pci_config,
1969 .reset_chip = qla82xx_reset_chip,
1970 .chip_diag = qla24xx_chip_diag,
1971 .config_rings = qla82xx_config_rings,
1972 .reset_adapter = qla24xx_reset_adapter,
1973 .nvram_config = qla81xx_nvram_config,
1974 .update_fw_options = qla24xx_update_fw_options,
1975 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001976 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001977 .fw_version_str = qla24xx_fw_version_str,
1978 .intr_handler = qla82xx_intr_handler,
1979 .enable_intrs = qla82xx_enable_intrs,
1980 .disable_intrs = qla82xx_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 = qla24xx_read_nvram_data,
1991 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05001992 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001993 .beacon_on = qla82xx_beacon_on,
1994 .beacon_off = qla82xx_beacon_off,
1995 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001996 .read_optrom = qla82xx_read_optrom_data,
1997 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001998 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001999 .start_scsi = qla82xx_start_scsi,
2000 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002001 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002002 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002003};
2004
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002005static struct isp_operations qla8044_isp_ops = {
2006 .pci_config = qla82xx_pci_config,
2007 .reset_chip = qla82xx_reset_chip,
2008 .chip_diag = qla24xx_chip_diag,
2009 .config_rings = qla82xx_config_rings,
2010 .reset_adapter = qla24xx_reset_adapter,
2011 .nvram_config = qla81xx_nvram_config,
2012 .update_fw_options = qla24xx_update_fw_options,
2013 .load_risc = qla82xx_load_risc,
2014 .pci_info_str = qla24xx_pci_info_str,
2015 .fw_version_str = qla24xx_fw_version_str,
2016 .intr_handler = qla8044_intr_handler,
2017 .enable_intrs = qla82xx_enable_intrs,
2018 .disable_intrs = qla82xx_disable_intrs,
2019 .abort_command = qla24xx_abort_command,
2020 .target_reset = qla24xx_abort_target,
2021 .lun_reset = qla24xx_lun_reset,
2022 .fabric_login = qla24xx_login_fabric,
2023 .fabric_logout = qla24xx_fabric_logout,
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 = NULL,
2029 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002030 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002031 .beacon_on = qla82xx_beacon_on,
2032 .beacon_off = qla82xx_beacon_off,
2033 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002034 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002035 .write_optrom = qla8044_write_optrom_data,
2036 .get_flash_version = qla82xx_get_flash_version,
2037 .start_scsi = qla82xx_start_scsi,
2038 .abort_isp = qla8044_abort_isp,
2039 .iospace_config = qla82xx_iospace_config,
2040 .initialize_adapter = qla2x00_initialize_adapter,
2041};
2042
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002043static struct isp_operations qla83xx_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 = qla83xx_fw_dump,
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,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002078 .initialize_adapter = qla2x00_initialize_adapter,
2079};
2080
2081static struct isp_operations qlafx00_isp_ops = {
2082 .pci_config = qlafx00_pci_config,
2083 .reset_chip = qlafx00_soft_reset,
2084 .chip_diag = qlafx00_chip_diag,
2085 .config_rings = qlafx00_config_rings,
2086 .reset_adapter = qlafx00_soft_reset,
2087 .nvram_config = NULL,
2088 .update_fw_options = NULL,
2089 .load_risc = NULL,
2090 .pci_info_str = qlafx00_pci_info_str,
2091 .fw_version_str = qlafx00_fw_version_str,
2092 .intr_handler = qlafx00_intr_handler,
2093 .enable_intrs = qlafx00_enable_intrs,
2094 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002095 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002096 .target_reset = qlafx00_abort_target,
2097 .lun_reset = qlafx00_lun_reset,
2098 .fabric_login = NULL,
2099 .fabric_logout = NULL,
2100 .calc_req_entries = NULL,
2101 .build_iocbs = NULL,
2102 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2103 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2104 .read_nvram = qla24xx_read_nvram_data,
2105 .write_nvram = qla24xx_write_nvram_data,
2106 .fw_dump = NULL,
2107 .beacon_on = qla24xx_beacon_on,
2108 .beacon_off = qla24xx_beacon_off,
2109 .beacon_blink = NULL,
2110 .read_optrom = qla24xx_read_optrom_data,
2111 .write_optrom = qla24xx_write_optrom_data,
2112 .get_flash_version = qla24xx_get_flash_version,
2113 .start_scsi = qlafx00_start_scsi,
2114 .abort_isp = qlafx00_abort_isp,
2115 .iospace_config = qlafx00_iospace_config,
2116 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002117};
2118
Chad Dupuisf73cb692014-02-26 04:15:06 -05002119static struct isp_operations qla27xx_isp_ops = {
2120 .pci_config = qla25xx_pci_config,
2121 .reset_chip = qla24xx_reset_chip,
2122 .chip_diag = qla24xx_chip_diag,
2123 .config_rings = qla24xx_config_rings,
2124 .reset_adapter = qla24xx_reset_adapter,
2125 .nvram_config = qla81xx_nvram_config,
2126 .update_fw_options = qla81xx_update_fw_options,
2127 .load_risc = qla81xx_load_risc,
2128 .pci_info_str = qla24xx_pci_info_str,
2129 .fw_version_str = qla24xx_fw_version_str,
2130 .intr_handler = qla24xx_intr_handler,
2131 .enable_intrs = qla24xx_enable_intrs,
2132 .disable_intrs = qla24xx_disable_intrs,
2133 .abort_command = qla24xx_abort_command,
2134 .target_reset = qla24xx_abort_target,
2135 .lun_reset = qla24xx_lun_reset,
2136 .fabric_login = qla24xx_login_fabric,
2137 .fabric_logout = qla24xx_fabric_logout,
2138 .calc_req_entries = NULL,
2139 .build_iocbs = NULL,
2140 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2141 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2142 .read_nvram = NULL,
2143 .write_nvram = NULL,
2144 .fw_dump = qla27xx_fwdump,
2145 .beacon_on = qla24xx_beacon_on,
2146 .beacon_off = qla24xx_beacon_off,
2147 .beacon_blink = qla83xx_beacon_blink,
2148 .read_optrom = qla25xx_read_optrom_data,
2149 .write_optrom = qla24xx_write_optrom_data,
2150 .get_flash_version = qla24xx_get_flash_version,
2151 .start_scsi = qla24xx_dif_start_scsi,
2152 .abort_isp = qla2x00_abort_isp,
2153 .iospace_config = qla83xx_iospace_config,
2154 .initialize_adapter = qla2x00_initialize_adapter,
2155};
2156
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002157static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002159{
2160 ha->device_type = DT_EXTENDED_IDS;
2161 switch (ha->pdev->device) {
2162 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2163 ha->device_type |= DT_ISP2100;
2164 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002165 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002166 break;
2167 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2168 ha->device_type |= DT_ISP2200;
2169 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002170 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002171 break;
2172 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2173 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002174 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002175 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002176 break;
2177 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2178 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002179 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002180 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002181 break;
2182 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2183 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002184 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002185 if (ha->pdev->subsystem_vendor == 0x1028 &&
2186 ha->pdev->subsystem_device == 0x0170)
2187 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002188 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002189 break;
2190 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2191 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002192 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002193 break;
2194 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2195 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002196 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002197 break;
2198 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2199 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002200 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002201 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002202 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002203 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002204 break;
2205 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2206 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002207 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002208 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002209 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002210 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002211 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002212 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2213 ha->device_type |= DT_ISP8432;
2214 ha->device_type |= DT_ZIO_SUPPORTED;
2215 ha->device_type |= DT_FWI2;
2216 ha->device_type |= DT_IIDMA;
2217 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2218 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002219 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2220 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002221 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002222 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002223 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002224 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2225 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002226 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002227 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002228 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002229 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2230 ha->device_type |= DT_ISP2532;
2231 ha->device_type |= DT_ZIO_SUPPORTED;
2232 ha->device_type |= DT_FWI2;
2233 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002234 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2235 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002236 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2237 ha->device_type |= DT_ISP8001;
2238 ha->device_type |= DT_ZIO_SUPPORTED;
2239 ha->device_type |= DT_FWI2;
2240 ha->device_type |= DT_IIDMA;
2241 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2242 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002243 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2244 ha->device_type |= DT_ISP8021;
2245 ha->device_type |= DT_ZIO_SUPPORTED;
2246 ha->device_type |= DT_FWI2;
2247 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2248 /* Initialize 82XX ISP flags */
2249 qla82xx_init_flags(ha);
2250 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002251 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2252 ha->device_type |= DT_ISP8044;
2253 ha->device_type |= DT_ZIO_SUPPORTED;
2254 ha->device_type |= DT_FWI2;
2255 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2256 /* Initialize 82XX ISP flags */
2257 qla82xx_init_flags(ha);
2258 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002259 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2260 ha->device_type |= DT_ISP2031;
2261 ha->device_type |= DT_ZIO_SUPPORTED;
2262 ha->device_type |= DT_FWI2;
2263 ha->device_type |= DT_IIDMA;
2264 ha->device_type |= DT_T10_PI;
2265 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2266 break;
2267 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2268 ha->device_type |= DT_ISP8031;
2269 ha->device_type |= DT_ZIO_SUPPORTED;
2270 ha->device_type |= DT_FWI2;
2271 ha->device_type |= DT_IIDMA;
2272 ha->device_type |= DT_T10_PI;
2273 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2274 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002275 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2276 ha->device_type |= DT_ISPFX00;
2277 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002278 case PCI_DEVICE_ID_QLOGIC_ISP2071:
2279 ha->device_type |= DT_ISP2071;
2280 ha->device_type |= DT_ZIO_SUPPORTED;
2281 ha->device_type |= DT_FWI2;
2282 ha->device_type |= DT_IIDMA;
2283 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2284 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002285 case PCI_DEVICE_ID_QLOGIC_ISP2271:
2286 ha->device_type |= DT_ISP2271;
2287 ha->device_type |= DT_ZIO_SUPPORTED;
2288 ha->device_type |= DT_FWI2;
2289 ha->device_type |= DT_IIDMA;
2290 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2291 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002292 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002293
Giridhar Malavalia9083012010-04-12 17:59:55 -07002294 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002295 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002296 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002297 /* Get adapter physical port no from interrupt pin register. */
2298 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002299 if (IS_QLA27XX(ha))
2300 ha->port_no--;
2301 else
2302 ha->port_no = !(ha->port_no & 1);
2303 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002304
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002305 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002306 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002307 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002308}
2309
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002310static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002311qla2xxx_scan_start(struct Scsi_Host *shost)
2312{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002314
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002315 if (vha->hw->flags.running_gold_fw)
2316 return;
2317
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002318 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2319 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2320 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2321 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002322}
2323
2324static int
2325qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2326{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002328
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002330 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002332 return 1;
2333
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002335}
2336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337/*
2338 * PCI driver interface
2339 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002340static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002341qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002343 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002345 scsi_qla_host_t *base_vha = NULL;
2346 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002347 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002348 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002349 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002350 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002351 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002352 struct req_que *req = NULL;
2353 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002354 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002355 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002356 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2357 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002358 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002359 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2360 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002361 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002362 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002363 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2364 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002365 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002366 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002367 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002368 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2369 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002370 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002371 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002372 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2373 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002374 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002375 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2376 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002377
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002378 if (mem_only) {
2379 if (pci_enable_device_mem(pdev))
2380 goto probe_out;
2381 } else {
2382 if (pci_enable_device(pdev))
2383 goto probe_out;
2384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Jesse Barnes09276782008-10-18 17:33:19 -07002386 /* This may fail but that's ok */
2387 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2390 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002391 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2392 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002395 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2396 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002398 ha->tgt.enable_class_2 = ql2xenableclass2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
2400 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002401 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002402 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002403 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002404 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002405 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002406 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002408 /* Set ISP-type information. */
2409 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002410
2411 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002412 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002413 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002414 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002415
Chad Dupuiscba1e472011-11-18 09:03:21 -08002416 ha->prev_topology = 0;
2417 ha->init_cb_size = sizeof(init_cb_t);
2418 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2419 ha->optrom_size = OPTROM_SIZE_2300;
2420
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002421 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002423 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002425 req_length = REQUEST_ENTRY_CNT_2100;
2426 rsp_length = RESPONSE_ENTRY_CNT_2100;
2427 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002428 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002429 ha->flash_conf_off = ~0;
2430 ha->flash_data_off = ~0;
2431 ha->nvram_conf_off = ~0;
2432 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002433 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002435 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002436 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 req_length = REQUEST_ENTRY_CNT_2200;
2438 rsp_length = RESPONSE_ENTRY_CNT_2100;
2439 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002440 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002441 ha->flash_conf_off = ~0;
2442 ha->flash_data_off = ~0;
2443 ha->nvram_conf_off = ~0;
2444 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002445 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002446 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002447 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 req_length = REQUEST_ENTRY_CNT_2200;
2450 rsp_length = RESPONSE_ENTRY_CNT_2300;
2451 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002452 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002453 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2454 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002455 ha->flash_conf_off = ~0;
2456 ha->flash_data_off = ~0;
2457 ha->nvram_conf_off = ~0;
2458 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002459 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002460 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002461 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002462 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002463 req_length = REQUEST_ENTRY_CNT_24XX;
2464 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002465 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002467 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002468 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002469 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002470 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002471 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002472 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2473 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2474 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2475 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002476 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002477 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002478 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002479 req_length = REQUEST_ENTRY_CNT_24XX;
2480 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002481 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002483 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002484 ha->gid_list_info_size = 8;
2485 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002486 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002487 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002488 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2489 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2490 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2491 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2492 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002493 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002494 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2495 req_length = REQUEST_ENTRY_CNT_24XX;
2496 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002497 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002498 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2499 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2500 ha->gid_list_info_size = 8;
2501 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002502 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002503 ha->isp_ops = &qla81xx_isp_ops;
2504 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2505 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2506 ha->nvram_conf_off = ~0;
2507 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002508 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002509 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002510 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2511 req_length = REQUEST_ENTRY_CNT_82XX;
2512 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2513 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2514 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2515 ha->gid_list_info_size = 8;
2516 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002517 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002518 ha->isp_ops = &qla82xx_isp_ops;
2519 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2520 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2521 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2522 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002523 } else if (IS_QLA8044(ha)) {
2524 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2525 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2526 req_length = REQUEST_ENTRY_CNT_82XX;
2527 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2528 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2529 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2530 ha->gid_list_info_size = 8;
2531 ha->optrom_size = OPTROM_SIZE_83XX;
2532 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2533 ha->isp_ops = &qla8044_isp_ops;
2534 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2535 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2536 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2537 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002538 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002539 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002540 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002541 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2542 req_length = REQUEST_ENTRY_CNT_24XX;
2543 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002544 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002545 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2546 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2547 ha->gid_list_info_size = 8;
2548 ha->optrom_size = OPTROM_SIZE_83XX;
2549 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2550 ha->isp_ops = &qla83xx_isp_ops;
2551 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2552 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2553 ha->nvram_conf_off = ~0;
2554 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002555 } else if (IS_QLAFX00(ha)) {
2556 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2557 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2558 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2559 req_length = REQUEST_ENTRY_CNT_FX00;
2560 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002561 ha->isp_ops = &qlafx00_isp_ops;
2562 ha->port_down_retry_count = 30; /* default value */
2563 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2564 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002565 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002566 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002567 ha->mr.host_info_resend = false;
2568 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002569 } else if (IS_QLA27XX(ha)) {
2570 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2571 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2572 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2573 req_length = REQUEST_ENTRY_CNT_24XX;
2574 rsp_length = RESPONSE_ENTRY_CNT_2300;
2575 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2576 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2577 ha->gid_list_info_size = 8;
2578 ha->optrom_size = OPTROM_SIZE_83XX;
2579 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2580 ha->isp_ops = &qla27xx_isp_ops;
2581 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2582 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2583 ha->nvram_conf_off = ~0;
2584 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002586
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002587 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2588 "mbx_count=%d, req_length=%d, "
2589 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002590 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2591 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002592 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2593 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002594 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002595 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2596 "isp_ops=%p, flash_conf_off=%d, "
2597 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2598 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2599 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002600
2601 /* Configure PCI I/O space */
2602 ret = ha->isp_ops->iospace_config(ha);
2603 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002604 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002605
2606 ql_log_pci(ql_log_info, pdev, 0x001d,
2607 "Found an ISP%04X irq %d iobase 0x%p.\n",
2608 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002609 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002610 init_completion(&ha->mbx_cmd_comp);
2611 complete(&ha->mbx_cmd_comp);
2612 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002613 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002614 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002616 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Andrew Vasquez53303c42009-01-22 09:45:37 -08002618 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002619 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2620 "64 Bit addressing is %s.\n",
2621 ha->flags.enable_64bit_addressing ? "enable" :
2622 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002623 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002624 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002625 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2626 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002628 goto probe_hw_failed;
2629 }
2630
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002631 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002632 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002633 req->max_q_depth = ql2xmaxqdepth;
2634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635
2636 base_vha = qla2x00_create_host(sht, ha);
2637 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002638 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002639 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002640 qla2x00_free_req_que(ha, req);
2641 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 }
2644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04002646 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002649 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002650 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002652 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2654 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002655
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002656 /* Setup fcport template structure. */
2657 ha->mr.fcport.vha = base_vha;
2658 ha->mr.fcport.port_type = FCT_UNKNOWN;
2659 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2660 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2661 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2662 ha->mr.fcport.scan_state = 1;
2663
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002664 /* Set the SG table size based on ISP type */
2665 if (!IS_FWI2_CAPABLE(ha)) {
2666 if (IS_QLA2100(ha))
2667 host->sg_tablesize = 32;
2668 } else {
2669 if (!IS_QLA82XX(ha))
2670 host->sg_tablesize = QLA_SG_ALL;
2671 }
Chad Dupuis642ef982012-02-09 11:15:57 -08002672 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002673 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002674 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002675 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002676 host->max_cmd_len = 32;
2677 else
2678 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002679 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02002680 /* Older HBAs support only 16-bit LUNs */
2681 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2682 ql2xmaxlun > 0xffff)
2683 host->max_lun = 0xffff;
2684 else
2685 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002686 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002687 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002688
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002689 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2690 "max_id=%d this_id=%d "
2691 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02002692 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002693 host->this_id, host->cmd_per_lun, host->unique_id,
2694 host->max_cmd_len, host->max_channel, host->max_lun,
2695 host->transportt, sht->vendor_id);
2696
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002697que_init:
2698 /* Alloc arrays of request and response ring ptrs */
2699 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2700 ql_log(ql_log_fatal, base_vha, 0x003d,
2701 "Failed to allocate memory for queue pointers..."
2702 "aborting.\n");
2703 goto probe_init_failed;
2704 }
2705
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002706 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002707
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002708 /* Set up the irqs */
2709 ret = qla2x00_request_irqs(ha, rsp);
2710 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002711 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002712
2713 pci_save_state(pdev);
2714
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002715 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002716 rsp->req = req;
2717 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002718
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002719 if (IS_QLAFX00(ha)) {
2720 ha->rsp_q_map[0] = rsp;
2721 ha->req_q_map[0] = req;
2722 set_bit(0, ha->req_qid_map);
2723 set_bit(0, ha->rsp_qid_map);
2724 }
2725
Andrew Vasquez08029992009-03-24 09:07:55 -07002726 /* FWI2-capable only. */
2727 req->req_q_in = &ha->iobase->isp24.req_q_in;
2728 req->req_q_out = &ha->iobase->isp24.req_q_out;
2729 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2730 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002731 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002732 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2733 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2734 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2735 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002736 }
2737
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002738 if (IS_QLAFX00(ha)) {
2739 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2740 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2741 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2742 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2743 }
2744
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002745 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002746 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2747 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2748 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2749 }
2750
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002751 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2752 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2753 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2754 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2755 "req->req_q_in=%p req->req_q_out=%p "
2756 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2757 req->req_q_in, req->req_q_out,
2758 rsp->rsp_q_in, rsp->rsp_q_out);
2759 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2760 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2761 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2762 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2763 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2764 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002766 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002767 ql_log(ql_log_fatal, base_vha, 0x00d6,
2768 "Failed to initialize adapter - Adapter flags %x.\n",
2769 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770
Giridhar Malavalia9083012010-04-12 17:59:55 -07002771 if (IS_QLA82XX(ha)) {
2772 qla82xx_idc_lock(ha);
2773 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002774 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002775 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002776 ql_log(ql_log_fatal, base_vha, 0x00d7,
2777 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002778 } else if (IS_QLA8044(ha)) {
2779 qla8044_idc_lock(ha);
2780 qla8044_wr_direct(base_vha,
2781 QLA8044_CRB_DEV_STATE_INDEX,
2782 QLA8XXX_DEV_FAILED);
2783 qla8044_idc_unlock(ha);
2784 ql_log(ql_log_fatal, base_vha, 0x0150,
2785 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002786 }
2787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002788 ret = -ENODEV;
2789 goto probe_failed;
2790 }
2791
Chad Dupuis3b1bef62014-02-26 04:15:04 -05002792 if (IS_QLAFX00(ha))
2793 host->can_queue = QLAFX00_MAX_CANQUEUE;
2794 else
2795 host->can_queue = req->num_outstanding_cmds - 10;
2796
2797 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2798 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2799 host->can_queue, base_vha->req,
2800 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2801
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002802 if (ha->mqenable) {
2803 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002804 ql_log(ql_log_warn, base_vha, 0x00ec,
2805 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002806 goto que_init;
2807 }
2808 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002809
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002810 if (ha->flags.running_gold_fw)
2811 goto skip_dpc;
2812
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 /*
2814 * Startup the kernel thread for this host adapter
2815 */
2816 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002817 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002819 ql_log(ql_log_fatal, base_vha, 0x00ed,
2820 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 ret = PTR_ERR(ha->dpc_thread);
2822 goto probe_failed;
2823 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002824 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2825 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002827 /*
2828 * If we're not coming up in initiator mode, we might sit for
2829 * a while without waking up the dpc thread, which leads to a
2830 * stuck process warning. So just kick the dpc once here and
2831 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2832 */
2833 qla2xxx_wake_dpc(base_vha);
2834
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002835 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2836
Saurav Kashyap81178772012-08-22 14:21:04 -04002837 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2838 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2839 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2840 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2841
2842 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2843 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2844 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2845 INIT_WORK(&ha->idc_state_handler,
2846 qla83xx_idc_state_handler_work);
2847 INIT_WORK(&ha->nic_core_unrecoverable,
2848 qla83xx_nic_core_unrecoverable_work);
2849 }
2850
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002851skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 list_add_tail(&base_vha->list, &ha->vp_list);
2853 base_vha->host->irq = ha->pdev->irq;
2854
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002857 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2858 "Started qla2x00_timer with "
2859 "interval=%d.\n", WATCH_INTERVAL);
2860 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2861 "Detected hba at address=%p.\n",
2862 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863
Arun Easie02587d2011-08-16 11:29:23 -07002864 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002865 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002866 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002867 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002868 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2869 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002870 if (ql2xenabledif == 1)
2871 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002872 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002873 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002874 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002875 | SHOST_DIF_TYPE3_PROTECTION
2876 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002877 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002878 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002879
2880 guard = SHOST_DIX_GUARD_CRC;
2881
2882 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2883 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2884 guard |= SHOST_DIX_GUARD_IP;
2885
2886 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002887 } else
2888 base_vha->flags.difdix_supported = 0;
2889 }
2890
Giridhar Malavalia9083012010-04-12 17:59:55 -07002891 ha->isp_ops->enable_intrs(ha);
2892
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002893 if (IS_QLAFX00(ha)) {
2894 ret = qlafx00_fx_disc(base_vha,
2895 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2896 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2897 QLA_SG_ALL : 128;
2898 }
2899
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002900 ret = scsi_add_host(host, &pdev->dev);
2901 if (ret)
2902 goto probe_failed;
2903
Michael Reed14864002009-12-02 09:11:16 -06002904 base_vha->flags.init_done = 1;
2905 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04002906 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06002907
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002908 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2909 "Init done and hba is online.\n");
2910
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002911 if (qla_ini_mode_enabled(base_vha))
2912 scsi_scan_host(host);
2913 else
2914 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2915 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002918
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002919 if (IS_QLAFX00(ha)) {
2920 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002921 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2922
2923 /* Register system information */
2924 ret = qlafx00_fx_disc(base_vha,
2925 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2926 }
2927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002928 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002931
Armen Baloyan03eb9122013-10-30 03:38:22 -04002932 ql_log(ql_log_info, base_vha, 0x00fb,
2933 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002934 ql_log(ql_log_info, base_vha, 0x00fc,
2935 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2936 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2937 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2938 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04002939 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002941 qlt_add_target(ha, base_vha);
2942
Joe Lawrence6b383972014-08-26 17:12:29 -04002943 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 return 0;
2945
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002946probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002947 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002948 ha->req_q_map[0] = NULL;
2949 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002950 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002951 ha->rsp_q_map[0] = NULL;
2952 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002953 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002954
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002956 if (base_vha->timer_active)
2957 qla2x00_stop_timer(base_vha);
2958 base_vha->flags.online = 0;
2959 if (ha->dpc_thread) {
2960 struct task_struct *t = ha->dpc_thread;
2961
2962 ha->dpc_thread = NULL;
2963 kthread_stop(t);
2964 }
2965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04002971 qla2x00_clear_drv_active(ha);
2972
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002973iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002974 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002975 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002976 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002977 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05002978 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002979 } else {
2980 if (ha->iobase)
2981 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002982 if (ha->cregbase)
2983 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002984 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 pci_release_selected_regions(ha->pdev, ha->bars);
2986 kfree(ha);
2987 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002989probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002991 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993
Adrian Bunk4c993f72008-01-14 00:55:16 -08002994static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002995qla2x00_shutdown(struct pci_dev *pdev)
2996{
2997 scsi_qla_host_t *vha;
2998 struct qla_hw_data *ha;
2999
Masanari Iida552f3f92013-02-08 01:57:44 -05003000 if (!atomic_read(&pdev->enable_cnt))
3001 return;
3002
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003003 vha = pci_get_drvdata(pdev);
3004 ha = vha->hw;
3005
Armen Baloyan42479342013-08-27 01:37:37 -04003006 /* Notify ISPFX00 firmware */
3007 if (IS_QLAFX00(ha))
3008 qlafx00_driver_shutdown(vha, 20);
3009
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003010 /* Turn-off FCE trace */
3011 if (ha->flags.fce_enabled) {
3012 qla2x00_disable_fce_trace(vha, NULL, NULL);
3013 ha->flags.fce_enabled = 0;
3014 }
3015
3016 /* Turn-off EFT trace */
3017 if (ha->eft)
3018 qla2x00_disable_eft_trace(vha);
3019
3020 /* Stop currently executing firmware. */
3021 qla2x00_try_to_stop_firmware(vha);
3022
3023 /* Turn adapter off line */
3024 vha->flags.online = 0;
3025
3026 /* turn-off interrupts on the card */
3027 if (ha->interrupts_on) {
3028 vha->flags.init_done = 0;
3029 ha->isp_ops->disable_intrs(ha);
3030 }
3031
3032 qla2x00_free_irqs(vha);
3033
3034 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003035
3036 pci_disable_pcie_error_reporting(pdev);
3037 pci_disable_device(pdev);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003038}
3039
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003040/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003041static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003042qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003044 struct Scsi_Host *scsi_host;
3045 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003046 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047
Arun Easi43ebf162011-05-10 11:18:16 -07003048 mutex_lock(&ha->vport_lock);
3049 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003050 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003051
Arun Easi43ebf162011-05-10 11:18:16 -07003052 BUG_ON(base_vha->list.next == &ha->vp_list);
3053 /* This assumes first entry in ha->vp_list is always base vha */
3054 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003055 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003056
Arun Easi43ebf162011-05-10 11:18:16 -07003057 spin_unlock_irqrestore(&ha->vport_slock, flags);
3058 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003059
Arun Easi43ebf162011-05-10 11:18:16 -07003060 fc_vport_terminate(vha->fc_vport);
3061 scsi_host_put(vha->host);
3062
3063 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003064 }
Arun Easi43ebf162011-05-10 11:18:16 -07003065 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003066}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003067
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003068/* Stops all deferred work threads */
3069static void
3070qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3071{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003072 /* Flush the work queue and remove it */
3073 if (ha->wq) {
3074 flush_workqueue(ha->wq);
3075 destroy_workqueue(ha->wq);
3076 ha->wq = NULL;
3077 }
3078
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003079 /* Cancel all work and destroy DPC workqueues */
3080 if (ha->dpc_lp_wq) {
3081 cancel_work_sync(&ha->idc_aen);
3082 destroy_workqueue(ha->dpc_lp_wq);
3083 ha->dpc_lp_wq = NULL;
3084 }
3085
3086 if (ha->dpc_hp_wq) {
3087 cancel_work_sync(&ha->nic_core_reset);
3088 cancel_work_sync(&ha->idc_state_handler);
3089 cancel_work_sync(&ha->nic_core_unrecoverable);
3090 destroy_workqueue(ha->dpc_hp_wq);
3091 ha->dpc_hp_wq = NULL;
3092 }
3093
Andrew Vasquezb9978762009-03-24 09:08:05 -07003094 /* Kill the kernel thread for this host */
3095 if (ha->dpc_thread) {
3096 struct task_struct *t = ha->dpc_thread;
3097
3098 /*
3099 * qla2xxx_wake_dpc checks for ->dpc_thread
3100 * so we need to zero it out.
3101 */
3102 ha->dpc_thread = NULL;
3103 kthread_stop(t);
3104 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003105}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003106
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003107static void
3108qla2x00_unmap_iobases(struct qla_hw_data *ha)
3109{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003110 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003111
Chad Dupuisf73cb692014-02-26 04:15:06 -05003112 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003113 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003114 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003115 } else {
3116 if (ha->iobase)
3117 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003119 if (ha->cregbase)
3120 iounmap(ha->cregbase);
3121
Giridhar Malavalia9083012010-04-12 17:59:55 -07003122 if (ha->mqiobase)
3123 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003124
Chad Dupuisf73cb692014-02-26 04:15:06 -05003125 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003126 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003127 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003128}
3129
3130static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003131qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003132{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003133 if (IS_QLA8044(ha)) {
3134 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003135 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003136 qla8044_idc_unlock(ha);
3137 } else if (IS_QLA82XX(ha)) {
3138 qla82xx_idc_lock(ha);
3139 qla82xx_clear_drv_active(ha);
3140 qla82xx_idc_unlock(ha);
3141 }
3142}
3143
3144static void
3145qla2x00_remove_one(struct pci_dev *pdev)
3146{
3147 scsi_qla_host_t *base_vha;
3148 struct qla_hw_data *ha;
3149
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003150 base_vha = pci_get_drvdata(pdev);
3151 ha = base_vha->hw;
3152
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003153 /* Indicate device removal to prevent future board_disable and wait
3154 * until any pending board_disable has completed. */
3155 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3156 cancel_work_sync(&ha->board_disable);
3157
3158 /*
3159 * If the PCI device is disabled then there was a PCI-disconnect and
3160 * qla2x00_disable_board_on_pci_error has taken care of most of the
3161 * resources.
3162 */
3163 if (!atomic_read(&pdev->enable_cnt)) {
3164 scsi_host_put(base_vha->host);
3165 kfree(ha);
3166 pci_set_drvdata(pdev, NULL);
3167 return;
3168 }
3169
Sawan Chandak638a1a02014-04-11 16:54:38 -04003170 qla2x00_wait_for_hba_ready(base_vha);
3171
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003172 set_bit(UNLOADING, &base_vha->dpc_flags);
3173
3174 if (IS_QLAFX00(ha))
3175 qlafx00_driver_shutdown(base_vha, 20);
3176
3177 qla2x00_delete_all_vps(ha, base_vha);
3178
3179 if (IS_QLA8031(ha)) {
3180 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3181 "Clearing fcoe driver presence.\n");
3182 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3183 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3184 "Error while clearing DRV-Presence.\n");
3185 }
3186
3187 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3188
3189 qla2x00_dfs_remove(base_vha);
3190
3191 qla84xx_put_chip(base_vha);
3192
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003193 /* Laser should be disabled only for ISP2031 */
3194 if (IS_QLA2031(ha))
3195 qla83xx_disable_laser(base_vha);
3196
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003197 /* Disable timer */
3198 if (base_vha->timer_active)
3199 qla2x00_stop_timer(base_vha);
3200
3201 base_vha->flags.online = 0;
3202
3203 qla2x00_destroy_deferred_work(ha);
3204
3205 qlt_remove_target(ha, base_vha);
3206
3207 qla2x00_free_sysfs_attr(base_vha, true);
3208
3209 fc_remove_host(base_vha->host);
3210
3211 scsi_remove_host(base_vha->host);
3212
3213 qla2x00_free_device(base_vha);
3214
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003215 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003216
Arun Easid2749ff2014-09-25 05:16:51 -04003217 scsi_host_put(base_vha->host);
3218
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003219 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003220
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 pci_release_selected_regions(ha->pdev, ha->bars);
3222 kfree(ha);
3223 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003225 pci_disable_pcie_error_reporting(pdev);
3226
Bernhard Walle665db932007-03-28 00:49:49 +02003227 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
Andrew Vasquez85880802009-12-15 21:29:46 -08003235 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3236
3237 /* Disable timer */
3238 if (vha->timer_active)
3239 qla2x00_stop_timer(vha);
3240
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003241 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003242
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003243 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003244 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003245
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003246 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003248
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003249 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Andrew Vasquez85880802009-12-15 21:29:46 -08003252 vha->flags.online = 0;
3253
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003254 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003255 if (ha->interrupts_on) {
3256 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003257 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003258 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 qla2x00_free_irqs(vha);
3261
Chad Dupuis88670482010-07-23 15:28:30 +05003262 qla2x00_free_fcports(vha);
3263
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003264 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003265
Giridhar Malavali08de2842011-08-16 11:31:44 -07003266 qla82xx_md_free(vha);
3267
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003268 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269}
3270
Chad Dupuis88670482010-07-23 15:28:30 +05003271void qla2x00_free_fcports(struct scsi_qla_host *vha)
3272{
3273 fc_port_t *fcport, *tfcport;
3274
3275 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3276 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003277 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003278 kfree(fcport);
3279 fcport = NULL;
3280 }
3281}
3282
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003283static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003285 int defer)
3286{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003287 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003288 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003289 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003290
3291 if (!fcport->rport)
3292 return;
3293
3294 rport = fcport->rport;
3295 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003296 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003297 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003298 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003299 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003300 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3301 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003302 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003303 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003304 qlt_fc_port_deleted(vha, fcport);
3305 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003306}
3307
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3310 *
3311 * Input: ha = adapter block pointer. fcport = port structure pointer.
3312 *
3313 * Return: None.
3314 *
3315 * Context:
3316 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003318 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003320 if (IS_QLAFX00(vha->hw)) {
3321 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3322 qla2x00_schedule_rport_del(vha, fcport, defer);
3323 return;
3324 }
3325
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003326 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003327 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003328 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 qla2x00_schedule_rport_del(vha, fcport, defer);
3330 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003331 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 * We may need to retry the login, so don't change the state of the
3333 * port but do the retries.
3334 */
3335 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003336 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
3338 if (!do_login)
3339 return;
3340
3341 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 fcport->login_retry = vha->hw->login_retry_count;
3343 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003345 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003346 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3347 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 }
3349}
3350
3351/*
3352 * qla2x00_mark_all_devices_lost
3353 * Updates fcport state when device goes offline.
3354 *
3355 * Input:
3356 * ha = adapter block pointer.
3357 * fcport = port structure pointer.
3358 *
3359 * Return:
3360 * None.
3361 *
3362 * Context:
3363 */
3364void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003365qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366{
3367 fc_port_t *fcport;
3368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003370 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003372
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 /*
3374 * No point in marking the device as lost, if the device is
3375 * already DEAD.
3376 */
3377 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3378 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003379 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003380 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003381 if (defer)
3382 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003383 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003384 qla2x00_schedule_rport_del(vha, fcport, defer);
3385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 }
3387}
3388
3389/*
3390* qla2x00_mem_alloc
3391* Allocates adapter memory.
3392*
3393* Returns:
3394* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003395* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003397static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003398qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3399 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400{
3401 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402
Andrew Vasqueze8711082008-01-31 12:33:48 -08003403 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003405 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003406 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003408 if (qlt_mem_alloc(ha) < 0)
3409 goto fail_free_init_cb;
3410
Chad Dupuis642ef982012-02-09 11:15:57 -08003411 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3412 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003414 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
Andrew Vasqueze8711082008-01-31 12:33:48 -08003416 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3417 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003420 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003421 /* Allocate cache for CT6 Ctx. */
3422 if (!ctx_cachep) {
3423 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3424 sizeof(struct ct6_dsd), 0,
3425 SLAB_HWCACHE_ALIGN, NULL);
3426 if (!ctx_cachep)
3427 goto fail_free_gid_list;
3428 }
3429 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3430 ctx_cachep);
3431 if (!ha->ctx_mempool)
3432 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003433 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3434 "ctx_cachep=%p ctx_mempool=%p.\n",
3435 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003436 }
3437
Andrew Vasqueze8711082008-01-31 12:33:48 -08003438 /* Get memory for cached NVRAM */
3439 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3440 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003441 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3444 ha->pdev->device);
3445 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3446 DMA_POOL_SIZE, 8, 0);
3447 if (!ha->s_dma_pool)
3448 goto fail_free_nvram;
3449
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003450 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3451 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3452 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3453
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003454 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003455 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3456 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3457 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003458 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3459 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003460 goto fail_s_dma_pool;
3461 }
3462
3463 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3464 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3465 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003466 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3467 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003468 goto fail_dl_dma_pool;
3469 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003470 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3471 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3472 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003473 }
3474
Andrew Vasqueze8711082008-01-31 12:33:48 -08003475 /* Allocate memory for SNS commands */
3476 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003478 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003480 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003482 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003483 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003484 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003486 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003488 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 goto fail_dma_pool;
3490 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003491 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003492 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003493 if (!ha->ct_sns)
3494 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003495 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3496 "ms_iocb=%p ct_sns=%p.\n",
3497 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 }
3499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003501 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3502 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003503 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3504 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003505 goto fail_req;
3506 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003507 (*req)->length = req_len;
3508 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3509 ((*req)->length + 1) * sizeof(request_t),
3510 &(*req)->dma, GFP_KERNEL);
3511 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003512 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3513 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514 goto fail_req_ring;
3515 }
3516 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003517 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3518 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003519 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3520 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003521 goto fail_rsp;
3522 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003523 (*rsp)->hw = ha;
3524 (*rsp)->length = rsp_len;
3525 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3526 ((*rsp)->length + 1) * sizeof(response_t),
3527 &(*rsp)->dma, GFP_KERNEL);
3528 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003529 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3530 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 goto fail_rsp_ring;
3532 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003533 (*req)->rsp = *rsp;
3534 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003535 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3536 "req=%p req->length=%d req->ring=%p rsp=%p "
3537 "rsp->length=%d rsp->ring=%p.\n",
3538 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3539 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003540 /* Allocate memory for NVRAM data for vports */
3541 if (ha->nvram_npiv_size) {
3542 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003543 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003544 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003545 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3546 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003547 goto fail_npiv_info;
3548 }
3549 } else
3550 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003552 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05003553 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003554 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3555 &ha->ex_init_cb_dma);
3556 if (!ha->ex_init_cb)
3557 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003558 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3559 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003560 }
3561
Giridhar Malavalia9083012010-04-12 17:59:55 -07003562 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3563
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003564 /* Get consistent memory allocated for Async Port-Database. */
3565 if (!IS_FWI2_CAPABLE(ha)) {
3566 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3567 &ha->async_pd_dma);
3568 if (!ha->async_pd)
3569 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003570 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3571 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003572 }
3573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003575
3576 /* Allocate memory for our loop_id bitmap */
3577 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3578 GFP_KERNEL);
3579 if (!ha->loop_id_map)
3580 goto fail_async_pd;
3581 else {
3582 qla2x00_set_reserved_loop_ids(ha);
3583 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003584 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003585 }
3586
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003587 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003588
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003589fail_async_pd:
3590 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003591fail_ex_init_cb:
3592 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003593fail_npiv_info:
3594 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3595 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3596 (*rsp)->ring = NULL;
3597 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003599 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003601 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3602 sizeof(request_t), (*req)->ring, (*req)->dma);
3603 (*req)->ring = NULL;
3604 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003606 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003607fail_req:
3608 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3609 ha->ct_sns, ha->ct_sns_dma);
3610 ha->ct_sns = NULL;
3611 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003612fail_free_ms_iocb:
3613 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3614 ha->ms_iocb = NULL;
3615 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003617 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003618 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3619 ha->fcp_cmnd_dma_pool = NULL;
3620 }
3621fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003622 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003623 dma_pool_destroy(ha->dl_dma_pool);
3624 ha->dl_dma_pool = NULL;
3625 }
3626fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003627 dma_pool_destroy(ha->s_dma_pool);
3628 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003629fail_free_nvram:
3630 kfree(ha->nvram);
3631 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003632fail_free_ctx_mempool:
3633 mempool_destroy(ha->ctx_mempool);
3634 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003635fail_free_srb_mempool:
3636 mempool_destroy(ha->srb_mempool);
3637 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003638fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003639 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3640 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003642 ha->gid_list = NULL;
3643 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003644fail_free_tgt_mem:
3645 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003646fail_free_init_cb:
3647 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3648 ha->init_cb_dma);
3649 ha->init_cb = NULL;
3650 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003651fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003652 ql_log(ql_log_fatal, NULL, 0x0030,
3653 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003654 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655}
3656
3657/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003658* qla2x00_free_fw_dump
3659* Frees fw dump stuff.
3660*
3661* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003662* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003663*/
3664static void
3665qla2x00_free_fw_dump(struct qla_hw_data *ha)
3666{
3667 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003668 dma_free_coherent(&ha->pdev->dev,
3669 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003670
Chad Dupuisf73cb692014-02-26 04:15:06 -05003671 if (ha->eft)
3672 dma_free_coherent(&ha->pdev->dev,
3673 EFT_SIZE, ha->eft, ha->eft_dma);
3674
3675 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003676 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05003677 if (ha->fw_dump_template)
3678 vfree(ha->fw_dump_template);
3679
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003680 ha->fce = NULL;
3681 ha->fce_dma = 0;
3682 ha->eft = NULL;
3683 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003684 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04003685 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003686 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003687 ha->fw_dump = NULL;
3688 ha->fw_dump_len = 0;
3689 ha->fw_dump_template = NULL;
3690 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003691}
3692
3693/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694* qla2x00_mem_free
3695* Frees all adapter allocated memory.
3696*
3697* Input:
3698* ha = adapter block pointer.
3699*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003700static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003701qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003703 qla2x00_free_fw_dump(ha);
3704
Saurav Kashyap81178772012-08-22 14:21:04 -04003705 if (ha->mctp_dump)
3706 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3707 ha->mctp_dump_dma);
3708
Andrew Vasqueze8711082008-01-31 12:33:48 -08003709 if (ha->srb_mempool)
3710 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003712 if (ha->dcbx_tlv)
3713 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3714 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3715
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003716 if (ha->xgmac_data)
3717 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3718 ha->xgmac_data, ha->xgmac_data_dma);
3719
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 if (ha->sns_cmd)
3721 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003722 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723
3724 if (ha->ct_sns)
3725 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003726 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
Andrew Vasquez88729e52006-06-23 16:10:50 -07003728 if (ha->sfp_data)
3729 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3730
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 if (ha->ms_iocb)
3732 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3733
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003734 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003735 dma_pool_free(ha->s_dma_pool,
3736 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003737
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003738 if (ha->async_pd)
3739 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3740
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 if (ha->s_dma_pool)
3742 dma_pool_destroy(ha->s_dma_pool);
3743
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003745 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3746 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
Giridhar Malavalia9083012010-04-12 17:59:55 -07003748 if (IS_QLA82XX(ha)) {
3749 if (!list_empty(&ha->gbl_dsd_list)) {
3750 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3751
3752 /* clean up allocated prev pool */
3753 list_for_each_entry_safe(dsd_ptr,
3754 tdsd_ptr, &ha->gbl_dsd_list, list) {
3755 dma_pool_free(ha->dl_dma_pool,
3756 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3757 list_del(&dsd_ptr->list);
3758 kfree(dsd_ptr);
3759 }
3760 }
3761 }
3762
3763 if (ha->dl_dma_pool)
3764 dma_pool_destroy(ha->dl_dma_pool);
3765
3766 if (ha->fcp_cmnd_dma_pool)
3767 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3768
3769 if (ha->ctx_mempool)
3770 mempool_destroy(ha->ctx_mempool);
3771
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003772 qlt_mem_free(ha);
3773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003774 if (ha->init_cb)
3775 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003776 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777 vfree(ha->optrom_buffer);
3778 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003779 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003780 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003781 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
Andrew Vasqueze8711082008-01-31 12:33:48 -08003783 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003784 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 ha->sns_cmd = NULL;
3786 ha->sns_cmd_dma = 0;
3787 ha->ct_sns = NULL;
3788 ha->ct_sns_dma = 0;
3789 ha->ms_iocb = NULL;
3790 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 ha->init_cb = NULL;
3792 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003793 ha->ex_init_cb = NULL;
3794 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003795 ha->async_pd = NULL;
3796 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
3798 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003799 ha->dl_dma_pool = NULL;
3800 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 ha->gid_list = NULL;
3803 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003804
3805 ha->tgt.atio_ring = NULL;
3806 ha->tgt.atio_dma = 0;
3807 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808}
3809
3810struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3811 struct qla_hw_data *ha)
3812{
3813 struct Scsi_Host *host;
3814 struct scsi_qla_host *vha = NULL;
3815
3816 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3817 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003818 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3819 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003820 goto fail;
3821 }
3822
3823 /* Clear our data area */
3824 vha = shost_priv(host);
3825 memset(vha, 0, sizeof(scsi_qla_host_t));
3826
3827 vha->host = host;
3828 vha->host_no = host->host_no;
3829 vha->hw = ha;
3830
3831 INIT_LIST_HEAD(&vha->vp_fcports);
3832 INIT_LIST_HEAD(&vha->work_list);
3833 INIT_LIST_HEAD(&vha->list);
3834
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003835 spin_lock_init(&vha->work_lock);
3836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003837 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003838 ql_dbg(ql_dbg_init, vha, 0x0041,
3839 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3840 vha->host, vha->hw, vha,
3841 dev_name(&(ha->pdev->dev)));
3842
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003843 return vha;
3844
3845fail:
3846 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847}
3848
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003849static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003850qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003851{
3852 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003853 uint8_t bail;
3854
3855 QLA_VHA_MARK_BUSY(vha, bail);
3856 if (bail)
3857 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003858
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003859 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003860 if (!e) {
3861 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003862 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003863 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003864
3865 INIT_LIST_HEAD(&e->list);
3866 e->type = type;
3867 e->flags = QLA_EVT_FLAG_FREE;
3868 return e;
3869}
3870
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003871static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003872qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003873{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003874 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003875
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003876 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003877 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003878 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003879 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003880
Andrew Vasquez0971de72008-04-03 13:13:18 -07003881 return QLA_SUCCESS;
3882}
3883
3884int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003885qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003886 u32 data)
3887{
3888 struct qla_work_evt *e;
3889
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003890 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003891 if (!e)
3892 return QLA_FUNCTION_FAILED;
3893
3894 e->u.aen.code = code;
3895 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003896 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003897}
3898
Andrew Vasquez8a659572009-02-08 20:50:12 -08003899int
3900qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3901{
3902 struct qla_work_evt *e;
3903
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003904 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003905 if (!e)
3906 return QLA_FUNCTION_FAILED;
3907
3908 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003909 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003910}
3911
Andrew Vasquezac280b62009-08-20 11:06:05 -07003912#define qla2x00_post_async_work(name, type) \
3913int qla2x00_post_async_##name##_work( \
3914 struct scsi_qla_host *vha, \
3915 fc_port_t *fcport, uint16_t *data) \
3916{ \
3917 struct qla_work_evt *e; \
3918 \
3919 e = qla2x00_alloc_work(vha, type); \
3920 if (!e) \
3921 return QLA_FUNCTION_FAILED; \
3922 \
3923 e->u.logio.fcport = fcport; \
3924 if (data) { \
3925 e->u.logio.data[0] = data[0]; \
3926 e->u.logio.data[1] = data[1]; \
3927 } \
3928 return qla2x00_post_work(vha, e); \
3929}
3930
3931qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3932qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3933qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3934qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003935qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3936qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003937
Andrew Vasquez3420d362009-10-13 15:16:45 -07003938int
3939qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3940{
3941 struct qla_work_evt *e;
3942
3943 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3944 if (!e)
3945 return QLA_FUNCTION_FAILED;
3946
3947 e->u.uevent.code = code;
3948 return qla2x00_post_work(vha, e);
3949}
3950
3951static void
3952qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3953{
3954 char event_string[40];
3955 char *envp[] = { event_string, NULL };
3956
3957 switch (code) {
3958 case QLA_UEVENT_CODE_FW_DUMP:
3959 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3960 vha->host_no);
3961 break;
3962 default:
3963 /* do nothing */
3964 break;
3965 }
3966 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3967}
3968
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003969int
3970qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
3971 uint32_t *data, int cnt)
3972{
3973 struct qla_work_evt *e;
3974
3975 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
3976 if (!e)
3977 return QLA_FUNCTION_FAILED;
3978
3979 e->u.aenfx.evtcode = evtcode;
3980 e->u.aenfx.count = cnt;
3981 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
3982 return qla2x00_post_work(vha, e);
3983}
3984
Andrew Vasquezac280b62009-08-20 11:06:05 -07003985void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003986qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003987{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003988 struct qla_work_evt *e, *tmp;
3989 unsigned long flags;
3990 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003991
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003992 spin_lock_irqsave(&vha->work_lock, flags);
3993 list_splice_init(&vha->work_list, &work);
3994 spin_unlock_irqrestore(&vha->work_lock, flags);
3995
3996 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003997 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003998
3999 switch (e->type) {
4000 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004002 e->u.aen.code, e->u.aen.data);
4003 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004004 case QLA_EVT_IDC_ACK:
4005 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4006 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004007 case QLA_EVT_ASYNC_LOGIN:
4008 qla2x00_async_login(vha, e->u.logio.fcport,
4009 e->u.logio.data);
4010 break;
4011 case QLA_EVT_ASYNC_LOGIN_DONE:
4012 qla2x00_async_login_done(vha, e->u.logio.fcport,
4013 e->u.logio.data);
4014 break;
4015 case QLA_EVT_ASYNC_LOGOUT:
4016 qla2x00_async_logout(vha, e->u.logio.fcport);
4017 break;
4018 case QLA_EVT_ASYNC_LOGOUT_DONE:
4019 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4020 e->u.logio.data);
4021 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004022 case QLA_EVT_ASYNC_ADISC:
4023 qla2x00_async_adisc(vha, e->u.logio.fcport,
4024 e->u.logio.data);
4025 break;
4026 case QLA_EVT_ASYNC_ADISC_DONE:
4027 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4028 e->u.logio.data);
4029 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004030 case QLA_EVT_UEVENT:
4031 qla2x00_uevent_emit(vha, e->u.uevent.code);
4032 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004033 case QLA_EVT_AENFX:
4034 qlafx00_process_aen(vha, e);
4035 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004036 }
4037 if (e->flags & QLA_EVT_FLAG_FREE)
4038 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004039
4040 /* For each work completed decrement vha ref count */
4041 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004042 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004043}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07004044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045/* Relogins all the fcports of a vport
4046 * Context: dpc thread
4047 */
4048void qla2x00_relogin(struct scsi_qla_host *vha)
4049{
4050 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004051 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 uint16_t next_loopid = 0;
4053 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004054 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055
4056 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4057 /*
4058 * If the port is not ONLINE then try to login
4059 * to it if we haven't run out of retries.
4060 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004061 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4062 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004063 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004065 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004066 ha->isp_ops->fabric_logout(vha,
4067 fcport->loop_id,
4068 fcport->d_id.b.domain,
4069 fcport->d_id.b.area,
4070 fcport->d_id.b.al_pa);
4071
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004072 if (fcport->loop_id == FC_NO_LOOP_ID) {
4073 fcport->loop_id = next_loopid =
4074 ha->min_external_loopid;
4075 status = qla2x00_find_new_loop_id(
4076 vha, fcport);
4077 if (status != QLA_SUCCESS) {
4078 /* Ran out of IDs to use */
4079 break;
4080 }
4081 }
4082
Andrew Vasquezac280b62009-08-20 11:06:05 -07004083 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004084 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004085 data[0] = 0;
4086 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4087 status = qla2x00_post_async_login_work(
4088 vha, fcport, data);
4089 if (status == QLA_SUCCESS)
4090 continue;
4091 /* Attempt a retry. */
4092 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004093 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004094 status = qla2x00_fabric_login(vha,
4095 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004096 if (status == QLA_SUCCESS) {
4097 int status2;
4098 uint8_t opts;
4099
4100 opts = 0;
4101 if (fcport->flags &
4102 FCF_FCP2_DEVICE)
4103 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004104 status2 =
4105 qla2x00_get_port_database(
4106 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004107 if (status2 != QLA_SUCCESS)
4108 status = 1;
4109 }
4110 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004111 } else
4112 status = qla2x00_local_device_login(vha,
4113 fcport);
4114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004115 if (status == QLA_SUCCESS) {
4116 fcport->old_loop_id = fcport->loop_id;
4117
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004118 ql_dbg(ql_dbg_disc, vha, 0x2003,
4119 "Port login OK: logged in ID 0x%x.\n",
4120 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004121
4122 qla2x00_update_fcport(vha, fcport);
4123
4124 } else if (status == 1) {
4125 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4126 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004127 ql_dbg(ql_dbg_disc, vha, 0x2007,
4128 "Retrying %d login again loop_id 0x%x.\n",
4129 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130 } else {
4131 fcport->login_retry = 0;
4132 }
4133
4134 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004135 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136 }
4137 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4138 break;
4139 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004140}
4141
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004142/* Schedule work on any of the dpc-workqueues */
4143void
4144qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4145{
4146 struct qla_hw_data *ha = base_vha->hw;
4147
4148 switch (work_code) {
4149 case MBA_IDC_AEN: /* 0x8200 */
4150 if (ha->dpc_lp_wq)
4151 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4152 break;
4153
4154 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4155 if (!ha->flags.nic_core_reset_hdlr_active) {
4156 if (ha->dpc_hp_wq)
4157 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4158 } else
4159 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4160 "NIC Core reset is already active. Skip "
4161 "scheduling it again.\n");
4162 break;
4163 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4164 if (ha->dpc_hp_wq)
4165 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4166 break;
4167 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4168 if (ha->dpc_hp_wq)
4169 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4170 break;
4171 default:
4172 ql_log(ql_log_warn, base_vha, 0xb05f,
4173 "Unknow work-code=0x%x.\n", work_code);
4174 }
4175
4176 return;
4177}
4178
4179/* Work: Perform NIC Core Unrecoverable state handling */
4180void
4181qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4182{
4183 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004184 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004185 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4186 uint32_t dev_state = 0;
4187
4188 qla83xx_idc_lock(base_vha, 0);
4189 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4190 qla83xx_reset_ownership(base_vha);
4191 if (ha->flags.nic_core_reset_owner) {
4192 ha->flags.nic_core_reset_owner = 0;
4193 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4194 QLA8XXX_DEV_FAILED);
4195 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4196 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4197 }
4198 qla83xx_idc_unlock(base_vha, 0);
4199}
4200
4201/* Work: Execute IDC state handler */
4202void
4203qla83xx_idc_state_handler_work(struct work_struct *work)
4204{
4205 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004206 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004207 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4208 uint32_t dev_state = 0;
4209
4210 qla83xx_idc_lock(base_vha, 0);
4211 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4212 if (dev_state == QLA8XXX_DEV_FAILED ||
4213 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4214 qla83xx_idc_state_handler(base_vha);
4215 qla83xx_idc_unlock(base_vha, 0);
4216}
4217
Saurav Kashyapfa492632012-11-21 02:40:29 -05004218static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004219qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4220{
4221 int rval = QLA_SUCCESS;
4222 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4223 uint32_t heart_beat_counter1, heart_beat_counter2;
4224
4225 do {
4226 if (time_after(jiffies, heart_beat_wait)) {
4227 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4228 "Nic Core f/w is not alive.\n");
4229 rval = QLA_FUNCTION_FAILED;
4230 break;
4231 }
4232
4233 qla83xx_idc_lock(base_vha, 0);
4234 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4235 &heart_beat_counter1);
4236 qla83xx_idc_unlock(base_vha, 0);
4237 msleep(100);
4238 qla83xx_idc_lock(base_vha, 0);
4239 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4240 &heart_beat_counter2);
4241 qla83xx_idc_unlock(base_vha, 0);
4242 } while (heart_beat_counter1 == heart_beat_counter2);
4243
4244 return rval;
4245}
4246
4247/* Work: Perform NIC Core Reset handling */
4248void
4249qla83xx_nic_core_reset_work(struct work_struct *work)
4250{
4251 struct qla_hw_data *ha =
4252 container_of(work, struct qla_hw_data, nic_core_reset);
4253 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4254 uint32_t dev_state = 0;
4255
Saurav Kashyap81178772012-08-22 14:21:04 -04004256 if (IS_QLA2031(ha)) {
4257 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4258 ql_log(ql_log_warn, base_vha, 0xb081,
4259 "Failed to dump mctp\n");
4260 return;
4261 }
4262
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004263 if (!ha->flags.nic_core_reset_hdlr_active) {
4264 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4265 qla83xx_idc_lock(base_vha, 0);
4266 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4267 &dev_state);
4268 qla83xx_idc_unlock(base_vha, 0);
4269 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4270 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4271 "Nic Core f/w is alive.\n");
4272 return;
4273 }
4274 }
4275
4276 ha->flags.nic_core_reset_hdlr_active = 1;
4277 if (qla83xx_nic_core_reset(base_vha)) {
4278 /* NIC Core reset failed. */
4279 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4280 "NIC Core reset failed.\n");
4281 }
4282 ha->flags.nic_core_reset_hdlr_active = 0;
4283 }
4284}
4285
4286/* Work: Handle 8200 IDC aens */
4287void
4288qla83xx_service_idc_aen(struct work_struct *work)
4289{
4290 struct qla_hw_data *ha =
4291 container_of(work, struct qla_hw_data, idc_aen);
4292 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4293 uint32_t dev_state, idc_control;
4294
4295 qla83xx_idc_lock(base_vha, 0);
4296 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4297 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4298 qla83xx_idc_unlock(base_vha, 0);
4299 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4300 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4301 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4302 "Application requested NIC Core Reset.\n");
4303 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4304 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4305 QLA_SUCCESS) {
4306 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4307 "Other protocol driver requested NIC Core Reset.\n");
4308 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4309 }
4310 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4311 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4312 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4313 }
4314}
4315
4316static void
4317qla83xx_wait_logic(void)
4318{
4319 int i;
4320
4321 /* Yield CPU */
4322 if (!in_interrupt()) {
4323 /*
4324 * Wait about 200ms before retrying again.
4325 * This controls the number of retries for single
4326 * lock operation.
4327 */
4328 msleep(100);
4329 schedule();
4330 } else {
4331 for (i = 0; i < 20; i++)
4332 cpu_relax(); /* This a nop instr on i386 */
4333 }
4334}
4335
Saurav Kashyapfa492632012-11-21 02:40:29 -05004336static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004337qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4338{
4339 int rval;
4340 uint32_t data;
4341 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4342 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4343 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004344 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4345 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004346
4347 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4348 if (rval)
4349 return rval;
4350
4351 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4352 return QLA_SUCCESS;
4353 } else {
4354 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4355 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4356 data);
4357 if (rval)
4358 return rval;
4359
4360 msleep(200);
4361
4362 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4363 &data);
4364 if (rval)
4365 return rval;
4366
4367 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4368 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4369 ~(idc_lck_rcvry_stage_mask));
4370 rval = qla83xx_wr_reg(base_vha,
4371 QLA83XX_IDC_LOCK_RECOVERY, data);
4372 if (rval)
4373 return rval;
4374
4375 /* Forcefully perform IDC UnLock */
4376 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4377 &data);
4378 if (rval)
4379 return rval;
4380 /* Clear lock-id by setting 0xff */
4381 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4382 0xff);
4383 if (rval)
4384 return rval;
4385 /* Clear lock-recovery by setting 0x0 */
4386 rval = qla83xx_wr_reg(base_vha,
4387 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4388 if (rval)
4389 return rval;
4390 } else
4391 return QLA_SUCCESS;
4392 }
4393
4394 return rval;
4395}
4396
Saurav Kashyapfa492632012-11-21 02:40:29 -05004397static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004398qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4399{
4400 int rval = QLA_SUCCESS;
4401 uint32_t o_drv_lockid, n_drv_lockid;
4402 unsigned long lock_recovery_timeout;
4403
4404 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4405retry_lockid:
4406 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4407 if (rval)
4408 goto exit;
4409
4410 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4411 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4412 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4413 return QLA_SUCCESS;
4414 else
4415 return QLA_FUNCTION_FAILED;
4416 }
4417
4418 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4419 if (rval)
4420 goto exit;
4421
4422 if (o_drv_lockid == n_drv_lockid) {
4423 qla83xx_wait_logic();
4424 goto retry_lockid;
4425 } else
4426 return QLA_SUCCESS;
4427
4428exit:
4429 return rval;
4430}
4431
4432void
4433qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4434{
4435 uint16_t options = (requester_id << 15) | BIT_6;
4436 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004437 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004438 struct qla_hw_data *ha = base_vha->hw;
4439
4440 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4441retry_lock:
4442 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4443 == QLA_SUCCESS) {
4444 if (data) {
4445 /* Setting lock-id to our function-number */
4446 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4447 ha->portnum);
4448 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004449 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4450 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004451 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004452 "Failed to acquire IDC lock, acquired by %d, "
4453 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004454
4455 /* Retry/Perform IDC-Lock recovery */
4456 if (qla83xx_idc_lock_recovery(base_vha)
4457 == QLA_SUCCESS) {
4458 qla83xx_wait_logic();
4459 goto retry_lock;
4460 } else
4461 ql_log(ql_log_warn, base_vha, 0xb075,
4462 "IDC Lock recovery FAILED.\n");
4463 }
4464
4465 }
4466
4467 return;
4468
4469 /* XXX: IDC-lock implementation using access-control mbx */
4470retry_lock2:
4471 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4472 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4473 "Failed to acquire IDC lock. retrying...\n");
4474 /* Retry/Perform IDC-Lock recovery */
4475 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4476 qla83xx_wait_logic();
4477 goto retry_lock2;
4478 } else
4479 ql_log(ql_log_warn, base_vha, 0xb076,
4480 "IDC Lock recovery FAILED.\n");
4481 }
4482
4483 return;
4484}
4485
4486void
4487qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4488{
4489 uint16_t options = (requester_id << 15) | BIT_7, retry;
4490 uint32_t data;
4491 struct qla_hw_data *ha = base_vha->hw;
4492
4493 /* IDC-unlock implementation using driver-unlock/lock-id
4494 * remote registers
4495 */
4496 retry = 0;
4497retry_unlock:
4498 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4499 == QLA_SUCCESS) {
4500 if (data == ha->portnum) {
4501 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4502 /* Clearing lock-id by setting 0xff */
4503 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4504 } else if (retry < 10) {
4505 /* SV: XXX: IDC unlock retrying needed here? */
4506
4507 /* Retry for IDC-unlock */
4508 qla83xx_wait_logic();
4509 retry++;
4510 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4511 "Failed to release IDC lock, retyring=%d\n", retry);
4512 goto retry_unlock;
4513 }
4514 } else if (retry < 10) {
4515 /* Retry for IDC-unlock */
4516 qla83xx_wait_logic();
4517 retry++;
4518 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4519 "Failed to read drv-lockid, retyring=%d\n", retry);
4520 goto retry_unlock;
4521 }
4522
4523 return;
4524
4525 /* XXX: IDC-unlock implementation using access-control mbx */
4526 retry = 0;
4527retry_unlock2:
4528 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4529 if (retry < 10) {
4530 /* Retry for IDC-unlock */
4531 qla83xx_wait_logic();
4532 retry++;
4533 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4534 "Failed to release IDC lock, retyring=%d\n", retry);
4535 goto retry_unlock2;
4536 }
4537 }
4538
4539 return;
4540}
4541
4542int
4543__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4544{
4545 int rval = QLA_SUCCESS;
4546 struct qla_hw_data *ha = vha->hw;
4547 uint32_t drv_presence;
4548
4549 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4550 if (rval == QLA_SUCCESS) {
4551 drv_presence |= (1 << ha->portnum);
4552 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4553 drv_presence);
4554 }
4555
4556 return rval;
4557}
4558
4559int
4560qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4561{
4562 int rval = QLA_SUCCESS;
4563
4564 qla83xx_idc_lock(vha, 0);
4565 rval = __qla83xx_set_drv_presence(vha);
4566 qla83xx_idc_unlock(vha, 0);
4567
4568 return rval;
4569}
4570
4571int
4572__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4573{
4574 int rval = QLA_SUCCESS;
4575 struct qla_hw_data *ha = vha->hw;
4576 uint32_t drv_presence;
4577
4578 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4579 if (rval == QLA_SUCCESS) {
4580 drv_presence &= ~(1 << ha->portnum);
4581 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4582 drv_presence);
4583 }
4584
4585 return rval;
4586}
4587
4588int
4589qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4590{
4591 int rval = QLA_SUCCESS;
4592
4593 qla83xx_idc_lock(vha, 0);
4594 rval = __qla83xx_clear_drv_presence(vha);
4595 qla83xx_idc_unlock(vha, 0);
4596
4597 return rval;
4598}
4599
Saurav Kashyapfa492632012-11-21 02:40:29 -05004600static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004601qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4602{
4603 struct qla_hw_data *ha = vha->hw;
4604 uint32_t drv_ack, drv_presence;
4605 unsigned long ack_timeout;
4606
4607 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4608 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4609 while (1) {
4610 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4611 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004612 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004613 break;
4614
4615 if (time_after_eq(jiffies, ack_timeout)) {
4616 ql_log(ql_log_warn, vha, 0xb067,
4617 "RESET ACK TIMEOUT! drv_presence=0x%x "
4618 "drv_ack=0x%x\n", drv_presence, drv_ack);
4619 /*
4620 * The function(s) which did not ack in time are forced
4621 * to withdraw any further participation in the IDC
4622 * reset.
4623 */
4624 if (drv_ack != drv_presence)
4625 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4626 drv_ack);
4627 break;
4628 }
4629
4630 qla83xx_idc_unlock(vha, 0);
4631 msleep(1000);
4632 qla83xx_idc_lock(vha, 0);
4633 }
4634
4635 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4636 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4637}
4638
Saurav Kashyapfa492632012-11-21 02:40:29 -05004639static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004640qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4641{
4642 int rval = QLA_SUCCESS;
4643 uint32_t idc_control;
4644
4645 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4646 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4647
4648 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4649 __qla83xx_get_idc_control(vha, &idc_control);
4650 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4651 __qla83xx_set_idc_control(vha, 0);
4652
4653 qla83xx_idc_unlock(vha, 0);
4654 rval = qla83xx_restart_nic_firmware(vha);
4655 qla83xx_idc_lock(vha, 0);
4656
4657 if (rval != QLA_SUCCESS) {
4658 ql_log(ql_log_fatal, vha, 0xb06a,
4659 "Failed to restart NIC f/w.\n");
4660 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4661 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4662 } else {
4663 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4664 "Success in restarting nic f/w.\n");
4665 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4666 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4667 }
4668
4669 return rval;
4670}
4671
4672/* Assumes idc_lock always held on entry */
4673int
4674qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4675{
4676 struct qla_hw_data *ha = base_vha->hw;
4677 int rval = QLA_SUCCESS;
4678 unsigned long dev_init_timeout;
4679 uint32_t dev_state;
4680
4681 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4682 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4683
4684 while (1) {
4685
4686 if (time_after_eq(jiffies, dev_init_timeout)) {
4687 ql_log(ql_log_warn, base_vha, 0xb06e,
4688 "Initialization TIMEOUT!\n");
4689 /* Init timeout. Disable further NIC Core
4690 * communication.
4691 */
4692 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4693 QLA8XXX_DEV_FAILED);
4694 ql_log(ql_log_info, base_vha, 0xb06f,
4695 "HW State: FAILED.\n");
4696 }
4697
4698 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4699 switch (dev_state) {
4700 case QLA8XXX_DEV_READY:
4701 if (ha->flags.nic_core_reset_owner)
4702 qla83xx_idc_audit(base_vha,
4703 IDC_AUDIT_COMPLETION);
4704 ha->flags.nic_core_reset_owner = 0;
4705 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4706 "Reset_owner reset by 0x%x.\n",
4707 ha->portnum);
4708 goto exit;
4709 case QLA8XXX_DEV_COLD:
4710 if (ha->flags.nic_core_reset_owner)
4711 rval = qla83xx_device_bootstrap(base_vha);
4712 else {
4713 /* Wait for AEN to change device-state */
4714 qla83xx_idc_unlock(base_vha, 0);
4715 msleep(1000);
4716 qla83xx_idc_lock(base_vha, 0);
4717 }
4718 break;
4719 case QLA8XXX_DEV_INITIALIZING:
4720 /* Wait for AEN to change device-state */
4721 qla83xx_idc_unlock(base_vha, 0);
4722 msleep(1000);
4723 qla83xx_idc_lock(base_vha, 0);
4724 break;
4725 case QLA8XXX_DEV_NEED_RESET:
4726 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4727 qla83xx_need_reset_handler(base_vha);
4728 else {
4729 /* Wait for AEN to change device-state */
4730 qla83xx_idc_unlock(base_vha, 0);
4731 msleep(1000);
4732 qla83xx_idc_lock(base_vha, 0);
4733 }
4734 /* reset timeout value after need reset handler */
4735 dev_init_timeout = jiffies +
4736 (ha->fcoe_dev_init_timeout * HZ);
4737 break;
4738 case QLA8XXX_DEV_NEED_QUIESCENT:
4739 /* XXX: DEBUG for now */
4740 qla83xx_idc_unlock(base_vha, 0);
4741 msleep(1000);
4742 qla83xx_idc_lock(base_vha, 0);
4743 break;
4744 case QLA8XXX_DEV_QUIESCENT:
4745 /* XXX: DEBUG for now */
4746 if (ha->flags.quiesce_owner)
4747 goto exit;
4748
4749 qla83xx_idc_unlock(base_vha, 0);
4750 msleep(1000);
4751 qla83xx_idc_lock(base_vha, 0);
4752 dev_init_timeout = jiffies +
4753 (ha->fcoe_dev_init_timeout * HZ);
4754 break;
4755 case QLA8XXX_DEV_FAILED:
4756 if (ha->flags.nic_core_reset_owner)
4757 qla83xx_idc_audit(base_vha,
4758 IDC_AUDIT_COMPLETION);
4759 ha->flags.nic_core_reset_owner = 0;
4760 __qla83xx_clear_drv_presence(base_vha);
4761 qla83xx_idc_unlock(base_vha, 0);
4762 qla8xxx_dev_failed_handler(base_vha);
4763 rval = QLA_FUNCTION_FAILED;
4764 qla83xx_idc_lock(base_vha, 0);
4765 goto exit;
4766 case QLA8XXX_BAD_VALUE:
4767 qla83xx_idc_unlock(base_vha, 0);
4768 msleep(1000);
4769 qla83xx_idc_lock(base_vha, 0);
4770 break;
4771 default:
4772 ql_log(ql_log_warn, base_vha, 0xb071,
4773 "Unknow Device State: %x.\n", dev_state);
4774 qla83xx_idc_unlock(base_vha, 0);
4775 qla8xxx_dev_failed_handler(base_vha);
4776 rval = QLA_FUNCTION_FAILED;
4777 qla83xx_idc_lock(base_vha, 0);
4778 goto exit;
4779 }
4780 }
4781
4782exit:
4783 return rval;
4784}
4785
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004786void
4787qla2x00_disable_board_on_pci_error(struct work_struct *work)
4788{
4789 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
4790 board_disable);
4791 struct pci_dev *pdev = ha->pdev;
4792 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4793
4794 ql_log(ql_log_warn, base_vha, 0x015b,
4795 "Disabling adapter.\n");
4796
4797 set_bit(UNLOADING, &base_vha->dpc_flags);
4798
4799 qla2x00_delete_all_vps(ha, base_vha);
4800
4801 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4802
4803 qla2x00_dfs_remove(base_vha);
4804
4805 qla84xx_put_chip(base_vha);
4806
4807 if (base_vha->timer_active)
4808 qla2x00_stop_timer(base_vha);
4809
4810 base_vha->flags.online = 0;
4811
4812 qla2x00_destroy_deferred_work(ha);
4813
4814 /*
4815 * Do not try to stop beacon blink as it will issue a mailbox
4816 * command.
4817 */
4818 qla2x00_free_sysfs_attr(base_vha, false);
4819
4820 fc_remove_host(base_vha->host);
4821
4822 scsi_remove_host(base_vha->host);
4823
4824 base_vha->flags.init_done = 0;
4825 qla25xx_delete_queues(base_vha);
4826 qla2x00_free_irqs(base_vha);
4827 qla2x00_free_fcports(base_vha);
4828 qla2x00_mem_free(ha);
4829 qla82xx_md_free(base_vha);
4830 qla2x00_free_queues(ha);
4831
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004832 qla2x00_unmap_iobases(ha);
4833
4834 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004835 pci_disable_pcie_error_reporting(pdev);
4836 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004837
Joe Lawrencebeb9e312014-08-26 17:12:14 -04004838 /*
4839 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
4840 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004841}
4842
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843/**************************************************************************
4844* qla2x00_do_dpc
4845* This kernel thread is a task that is schedule by the interrupt handler
4846* to perform the background processing for interrupts.
4847*
4848* Notes:
4849* This task always run in the context of a kernel thread. It
4850* is kick-off by the driver's detect code and starts up
4851* up one per adapter. It immediately goes to sleep and waits for
4852* some fibre event. When either the interrupt handler or
4853* the timer routine detects a event it will one of the task
4854* bits then wake us up.
4855**************************************************************************/
4856static int
4857qla2x00_do_dpc(void *data)
4858{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004859 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004860 scsi_qla_host_t *base_vha;
4861 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004862
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004863 ha = (struct qla_hw_data *)data;
4864 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865
Dongsheng Yang8698a742014-03-11 18:09:12 +08004866 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867
James Bottomley563585e2011-01-27 16:12:37 -05004868 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004869 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004870 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4871 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872
Christoph Hellwig39a11242006-02-14 18:46:22 +01004873 schedule();
4874 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004876 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4877 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878
Andrew Vasquez85880802009-12-15 21:29:46 -08004879 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004880 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4881 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004882 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004883 }
4884
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 ha->dpc_active = 1;
4886
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004887 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4888 "DPC handler waking up, dpc_flags=0x%lx.\n",
4889 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004891 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004892
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004893 if (IS_P3P_TYPE(ha)) {
4894 if (IS_QLA8044(ha)) {
4895 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4896 &base_vha->dpc_flags)) {
4897 qla8044_idc_lock(ha);
4898 qla8044_wr_direct(base_vha,
4899 QLA8044_CRB_DEV_STATE_INDEX,
4900 QLA8XXX_DEV_FAILED);
4901 qla8044_idc_unlock(ha);
4902 ql_log(ql_log_info, base_vha, 0x4004,
4903 "HW State: FAILED.\n");
4904 qla8044_device_state_handler(base_vha);
4905 continue;
4906 }
4907
4908 } else {
4909 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4910 &base_vha->dpc_flags)) {
4911 qla82xx_idc_lock(ha);
4912 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4913 QLA8XXX_DEV_FAILED);
4914 qla82xx_idc_unlock(ha);
4915 ql_log(ql_log_info, base_vha, 0x0151,
4916 "HW State: FAILED.\n");
4917 qla82xx_device_state_handler(base_vha);
4918 continue;
4919 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004920 }
4921
4922 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4923 &base_vha->dpc_flags)) {
4924
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004925 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4926 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004927 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4928 &base_vha->dpc_flags))) {
4929 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4930 /* FCoE-ctx reset failed.
4931 * Escalate to chip-reset
4932 */
4933 set_bit(ISP_ABORT_NEEDED,
4934 &base_vha->dpc_flags);
4935 }
4936 clear_bit(ABORT_ISP_ACTIVE,
4937 &base_vha->dpc_flags);
4938 }
4939
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004940 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4941 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004942 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004943 } else if (IS_QLAFX00(ha)) {
4944 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4945 &base_vha->dpc_flags)) {
4946 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
4947 "Firmware Reset Recovery\n");
4948 if (qlafx00_reset_initialize(base_vha)) {
4949 /* Failed. Abort isp later. */
4950 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03004951 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004952 set_bit(ISP_UNRECOVERABLE,
4953 &base_vha->dpc_flags);
4954 ql_dbg(ql_dbg_dpc, base_vha,
4955 0x4021,
4956 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03004957 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004958 }
4959 }
4960
4961 if (test_and_clear_bit(FX00_TARGET_SCAN,
4962 &base_vha->dpc_flags)) {
4963 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
4964 "ISPFx00 Target Scan scheduled\n");
4965 if (qlafx00_rescan_isp(base_vha)) {
4966 if (!test_bit(UNLOADING,
4967 &base_vha->dpc_flags))
4968 set_bit(ISP_UNRECOVERABLE,
4969 &base_vha->dpc_flags);
4970 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
4971 "ISPFx00 Target Scan Failed\n");
4972 }
4973 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
4974 "ISPFx00 Target Scan End\n");
4975 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04004976 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
4977 &base_vha->dpc_flags)) {
4978 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
4979 "ISPFx00 Host Info resend scheduled\n");
4980 qlafx00_fx_disc(base_vha,
4981 &base_vha->hw->mr.fcport,
4982 FXDISC_REG_HOST_INFO);
4983 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004984 }
4985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004986 if (test_and_clear_bit(ISP_ABORT_NEEDED,
4987 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004989 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
4990 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004992 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
Giridhar Malavalia9083012010-04-12 17:59:55 -07004994 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 /* failed. retry later */
4996 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004997 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004999 clear_bit(ABORT_ISP_ACTIVE,
5000 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005001 }
5002
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005003 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5004 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 }
5006
David Jefferya394aac2012-11-21 02:39:54 -05005007 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5008 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005009 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005010 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005011
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005012 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
5013 int ret;
5014 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
5015 if (ret != QLA_SUCCESS)
5016 ql_log(ql_log_warn, base_vha, 0x121,
5017 "Failed to enable receiving of RSCN "
5018 "requests: 0x%x.\n", ret);
5019 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
5020 }
5021
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005022 if (IS_QLAFX00(ha))
5023 goto loop_resync_check;
5024
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005025 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005026 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5027 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005028 if (IS_P3P_TYPE(ha)) {
5029 if (IS_QLA82XX(ha))
5030 qla82xx_device_state_handler(base_vha);
5031 if (IS_QLA8044(ha))
5032 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005033 clear_bit(ISP_QUIESCE_NEEDED,
5034 &base_vha->dpc_flags);
5035 if (!ha->flags.quiesce_owner) {
5036 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005037 if (IS_QLA82XX(ha)) {
5038 qla82xx_idc_lock(ha);
5039 qla82xx_clear_qsnt_ready(
5040 base_vha);
5041 qla82xx_idc_unlock(ha);
5042 } else if (IS_QLA8044(ha)) {
5043 qla8044_idc_lock(ha);
5044 qla8044_clear_qsnt_ready(
5045 base_vha);
5046 qla8044_idc_unlock(ha);
5047 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005048 }
5049 } else {
5050 clear_bit(ISP_QUIESCE_NEEDED,
5051 &base_vha->dpc_flags);
5052 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005053 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005054 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5055 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005056 }
5057
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005058 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005059 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005060 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005062 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5063 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005064 qla2x00_rst_aen(base_vha);
5065 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005066 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5067 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 }
5069
5070 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005071 if ((test_and_clear_bit(RELOGIN_NEEDED,
5072 &base_vha->dpc_flags)) &&
5073 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5074 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005076 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5077 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005078 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005079 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5080 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005082loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005083 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005084 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005086 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5087 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
5089 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005090 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005092 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005094 clear_bit(LOOP_RESYNC_ACTIVE,
5095 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 }
5097
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005098 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5099 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 }
5101
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005102 if (IS_QLAFX00(ha))
5103 goto intr_on_check;
5104
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005105 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5106 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5107 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5108 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005109 }
5110
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005111intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005113 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005115 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005116 &base_vha->dpc_flags)) {
5117 if (ha->beacon_blink_led == 1)
5118 ha->isp_ops->beacon_blink(base_vha);
5119 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005120
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005121 if (!IS_QLAFX00(ha))
5122 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005123
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005125end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005126 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005128 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005130 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5131 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
5133 /*
5134 * Make sure that nobody tries to wake us up again.
5135 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 ha->dpc_active = 0;
5137
Andrew Vasquezac280b62009-08-20 11:06:05 -07005138 /* Cleanup any residual CTX SRBs. */
5139 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5140
Christoph Hellwig39a11242006-02-14 18:46:22 +01005141 return 0;
5142}
5143
5144void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005145qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005146{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005147 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005148 struct task_struct *t = ha->dpc_thread;
5149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005150 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005151 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152}
5153
5154/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155* qla2x00_rst_aen
5156* Processes asynchronous reset.
5157*
5158* Input:
5159* ha = adapter block pointer.
5160*/
5161static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005162qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005164 if (vha->flags.online && !vha->flags.reset_active &&
5165 !atomic_read(&vha->loop_down_timer) &&
5166 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005168 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169
5170 /*
5171 * Issue marker command only when we are going to start
5172 * the I/O.
5173 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005174 vha->marker_needed = 1;
5175 } while (!atomic_read(&vha->loop_down_timer) &&
5176 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 }
5178}
5179
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180/**************************************************************************
5181* qla2x00_timer
5182*
5183* Description:
5184* One second timer
5185*
5186* Context: Interrupt
5187***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005188void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005189qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 int start_dpc = 0;
5193 int index;
5194 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005195 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005196 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005197 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005198
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005199 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005200 ql_dbg(ql_dbg_timer, vha, 0x6000,
5201 "EEH = %d, restarting timer.\n",
5202 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005203 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5204 return;
5205 }
5206
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005207 /*
5208 * Hardware read to raise pending EEH errors during mailbox waits. If
5209 * the read returns -1 then disable the board.
5210 */
5211 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005212 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04005213 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005216 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005217 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005218 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5219 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005220 if (IS_QLA82XX(ha))
5221 qla82xx_watchdog(vha);
5222 else if (IS_QLA8044(ha))
5223 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005224 }
5225
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005226 if (!vha->vp_idx && IS_QLAFX00(ha))
5227 qlafx00_timer_routine(vha);
5228
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005230 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005231 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5232 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005233 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005235 if (atomic_read(&vha->loop_down_timer) ==
5236 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005238 ql_log(ql_log_info, vha, 0x6008,
5239 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005241 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5242 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005244 /*
5245 * Schedule an ISP abort to return any FCP2-device
5246 * commands.
5247 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005248 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005249 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005250 spin_lock_irqsave(&ha->hardware_lock,
5251 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005252 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005253 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005254 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005255 index++) {
5256 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005258 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005259 if (!sp)
5260 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005261 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005262 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005263 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005264 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005265 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005267 if (IS_QLA82XX(ha))
5268 set_bit(FCOE_CTX_RESET_NEEDED,
5269 &vha->dpc_flags);
5270 else
5271 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005272 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005273 break;
5274 }
5275 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005276 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278 start_dpc++;
5279 }
5280
5281 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005282 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005283 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005284 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 "Loop down - aborting ISP.\n");
5286
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005287 if (IS_QLA82XX(ha))
5288 set_bit(FCOE_CTX_RESET_NEEDED,
5289 &vha->dpc_flags);
5290 else
5291 set_bit(ISP_ABORT_NEEDED,
5292 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 }
5294 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005295 ql_dbg(ql_dbg_timer, vha, 0x600a,
5296 "Loop down - seconds remaining %d.\n",
5297 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005299 /* Check if beacon LED needs to be blinked for physical host only */
5300 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005301 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005302 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005303 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5304 start_dpc++;
5305 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005306 }
5307
Andrew Vasquez550bf572008-04-24 15:21:23 -07005308 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005309 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005310 start_dpc++;
5311
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005313 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5314 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5315 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005317 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5318 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005319 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5320 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005321 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005322 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005323 ql_dbg(ql_dbg_timer, vha, 0x600b,
5324 "isp_abort_needed=%d loop_resync_needed=%d "
5325 "fcport_update_needed=%d start_dpc=%d "
5326 "reset_marker_needed=%d",
5327 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5328 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5329 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5330 start_dpc,
5331 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5332 ql_dbg(ql_dbg_timer, vha, 0x600c,
5333 "beacon_blink_needed=%d isp_unrecoverable=%d "
5334 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005335 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005336 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5337 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5338 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5339 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005340 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005341 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005344 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345}
5346
Andrew Vasquez54333832005-11-09 15:49:04 -08005347/* Firmware interface routines. */
5348
Chad Dupuisf73cb692014-02-26 04:15:06 -05005349#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08005350#define FW_ISP21XX 0
5351#define FW_ISP22XX 1
5352#define FW_ISP2300 2
5353#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005354#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005355#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005356#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005357#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005358#define FW_ISP2031 8
5359#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005360#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005361
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005362#define FW_FILE_ISP21XX "ql2100_fw.bin"
5363#define FW_FILE_ISP22XX "ql2200_fw.bin"
5364#define FW_FILE_ISP2300 "ql2300_fw.bin"
5365#define FW_FILE_ISP2322 "ql2322_fw.bin"
5366#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005367#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005368#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005369#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005370#define FW_FILE_ISP2031 "ql2600_fw.bin"
5371#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005372#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05005373
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005374
Daniel Walkere1e82b62008-05-12 22:21:10 -07005375static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005376
5377static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005378 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5379 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5380 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5381 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5382 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005383 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005384 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005385 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005386 { .name = FW_FILE_ISP2031, },
5387 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005388 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005389};
5390
5391struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005392qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005393{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005394 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005395 struct fw_blob *blob;
5396
Andrew Vasquez54333832005-11-09 15:49:04 -08005397 if (IS_QLA2100(ha)) {
5398 blob = &qla_fw_blobs[FW_ISP21XX];
5399 } else if (IS_QLA2200(ha)) {
5400 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005401 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005402 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005403 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005404 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005405 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005406 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005407 } else if (IS_QLA25XX(ha)) {
5408 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005409 } else if (IS_QLA81XX(ha)) {
5410 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005411 } else if (IS_QLA82XX(ha)) {
5412 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005413 } else if (IS_QLA2031(ha)) {
5414 blob = &qla_fw_blobs[FW_ISP2031];
5415 } else if (IS_QLA8031(ha)) {
5416 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005417 } else if (IS_QLA27XX(ha)) {
5418 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03005419 } else {
5420 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005421 }
5422
Daniel Walkere1e82b62008-05-12 22:21:10 -07005423 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005424 if (blob->fw)
5425 goto out;
5426
5427 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005428 ql_log(ql_log_warn, vha, 0x0063,
5429 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005430 blob->fw = NULL;
5431 blob = NULL;
5432 goto out;
5433 }
5434
5435out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005436 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005437 return blob;
5438}
5439
5440static void
5441qla2x00_release_firmware(void)
5442{
5443 int idx;
5444
Daniel Walkere1e82b62008-05-12 22:21:10 -07005445 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005446 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005447 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005448 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005449}
5450
Seokmann Ju14e660e2007-09-20 14:07:36 -07005451static pci_ers_result_t
5452qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5453{
Andrew Vasquez85880802009-12-15 21:29:46 -08005454 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5455 struct qla_hw_data *ha = vha->hw;
5456
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005457 ql_dbg(ql_dbg_aer, vha, 0x9000,
5458 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005459
Seokmann Ju14e660e2007-09-20 14:07:36 -07005460 switch (state) {
5461 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005462 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005463 return PCI_ERS_RESULT_CAN_RECOVER;
5464 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005465 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005466 /* For ISP82XX complete any pending mailbox cmd */
5467 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005468 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005469 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5470 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005471 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005472 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005473 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005474 /* Return back all IOs */
5475 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005476 return PCI_ERS_RESULT_NEED_RESET;
5477 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005478 ha->flags.pci_channel_io_perm_failure = 1;
5479 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005480 return PCI_ERS_RESULT_DISCONNECT;
5481 }
5482 return PCI_ERS_RESULT_NEED_RESET;
5483}
5484
5485static pci_ers_result_t
5486qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5487{
5488 int risc_paused = 0;
5489 uint32_t stat;
5490 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005491 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5492 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005493 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5494 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5495
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005496 if (IS_QLA82XX(ha))
5497 return PCI_ERS_RESULT_RECOVERED;
5498
Seokmann Ju14e660e2007-09-20 14:07:36 -07005499 spin_lock_irqsave(&ha->hardware_lock, flags);
5500 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5501 stat = RD_REG_DWORD(&reg->hccr);
5502 if (stat & HCCR_RISC_PAUSE)
5503 risc_paused = 1;
5504 } else if (IS_QLA23XX(ha)) {
5505 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5506 if (stat & HSR_RISC_PAUSED)
5507 risc_paused = 1;
5508 } else if (IS_FWI2_CAPABLE(ha)) {
5509 stat = RD_REG_DWORD(&reg24->host_status);
5510 if (stat & HSRX_RISC_PAUSED)
5511 risc_paused = 1;
5512 }
5513 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5514
5515 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005516 ql_log(ql_log_info, base_vha, 0x9003,
5517 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005518 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005519
5520 return PCI_ERS_RESULT_NEED_RESET;
5521 } else
5522 return PCI_ERS_RESULT_RECOVERED;
5523}
5524
Saurav Kashyapfa492632012-11-21 02:40:29 -05005525static uint32_t
5526qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005527{
5528 uint32_t rval = QLA_FUNCTION_FAILED;
5529 uint32_t drv_active = 0;
5530 struct qla_hw_data *ha = base_vha->hw;
5531 int fn;
5532 struct pci_dev *other_pdev = NULL;
5533
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005534 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5535 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005536
5537 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5538
5539 if (base_vha->flags.online) {
5540 /* Abort all outstanding commands,
5541 * so as to be requeued later */
5542 qla2x00_abort_isp_cleanup(base_vha);
5543 }
5544
5545
5546 fn = PCI_FUNC(ha->pdev->devfn);
5547 while (fn > 0) {
5548 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005549 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5550 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005551 other_pdev =
5552 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5553 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5554 fn));
5555
5556 if (!other_pdev)
5557 continue;
5558 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005559 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5560 "Found PCI func available and enable at 0x%x.\n",
5561 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005562 pci_dev_put(other_pdev);
5563 break;
5564 }
5565 pci_dev_put(other_pdev);
5566 }
5567
5568 if (!fn) {
5569 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005570 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5571 "This devfn is reset owner = 0x%x.\n",
5572 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005573 qla82xx_idc_lock(ha);
5574
5575 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005576 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005577
5578 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5579 QLA82XX_IDC_VERSION);
5580
5581 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005582 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5583 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005584
5585 qla82xx_idc_unlock(ha);
5586 /* Reset if device is not already reset
5587 * drv_active would be 0 if a reset has already been done
5588 */
5589 if (drv_active)
5590 rval = qla82xx_start_firmware(base_vha);
5591 else
5592 rval = QLA_SUCCESS;
5593 qla82xx_idc_lock(ha);
5594
5595 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005596 ql_log(ql_log_info, base_vha, 0x900b,
5597 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005598 qla82xx_clear_drv_active(ha);
5599 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005600 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005601 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005602 ql_log(ql_log_info, base_vha, 0x900c,
5603 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005604 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005605 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005606 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005607 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005608 rval = qla82xx_restart_isp(base_vha);
5609 qla82xx_idc_lock(ha);
5610 /* Clear driver state register */
5611 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5612 qla82xx_set_drv_active(base_vha);
5613 }
5614 qla82xx_idc_unlock(ha);
5615 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005616 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5617 "This devfn is not reset owner = 0x%x.\n",
5618 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005619 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005620 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005621 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005622 rval = qla82xx_restart_isp(base_vha);
5623 qla82xx_idc_lock(ha);
5624 qla82xx_set_drv_active(base_vha);
5625 qla82xx_idc_unlock(ha);
5626 }
5627 }
5628 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5629
5630 return rval;
5631}
5632
Seokmann Ju14e660e2007-09-20 14:07:36 -07005633static pci_ers_result_t
5634qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5635{
5636 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005637 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5638 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005639 struct rsp_que *rsp;
5640 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005641
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005642 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5643 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005644
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005645 /* Workaround: qla2xxx driver which access hardware earlier
5646 * needs error state to be pci_channel_io_online.
5647 * Otherwise mailbox command timesout.
5648 */
5649 pdev->error_state = pci_channel_io_normal;
5650
5651 pci_restore_state(pdev);
5652
Richard Lary8c1496b2010-02-18 10:07:29 -08005653 /* pci_restore_state() clears the saved_state flag of the device
5654 * save restored state which resets saved_state flag
5655 */
5656 pci_save_state(pdev);
5657
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005658 if (ha->mem_only)
5659 rc = pci_enable_device_mem(pdev);
5660 else
5661 rc = pci_enable_device(pdev);
5662
5663 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005664 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005665 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005666 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005667 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005668
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005669 rsp = ha->rsp_q_map[0];
5670 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005671 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005673 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005674 goto exit_slot_reset;
5675
5676 if (IS_QLA82XX(ha)) {
5677 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5678 ret = PCI_ERS_RESULT_RECOVERED;
5679 goto exit_slot_reset;
5680 } else
5681 goto exit_slot_reset;
5682 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005683
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005684 while (ha->flags.mbox_busy && retries--)
5685 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005686
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005687 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005688 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005689 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005690 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005691
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005692
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005693exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005694 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5695 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005696
Seokmann Ju14e660e2007-09-20 14:07:36 -07005697 return ret;
5698}
5699
5700static void
5701qla2xxx_pci_resume(struct pci_dev *pdev)
5702{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005703 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5704 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005705 int ret;
5706
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005707 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5708 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005709
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005710 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005711 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005712 ql_log(ql_log_fatal, base_vha, 0x9002,
5713 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005714 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005715
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005716 pci_cleanup_aer_uncorrect_error_status(pdev);
5717
Andrew Vasquez85880802009-12-15 21:29:46 -08005718 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005719}
5720
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04005721static void
5722qla83xx_disable_laser(scsi_qla_host_t *vha)
5723{
5724 uint32_t reg, data, fn;
5725 struct qla_hw_data *ha = vha->hw;
5726 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
5727
5728 /* pci func #/port # */
5729 ql_dbg(ql_dbg_init, vha, 0x004b,
5730 "Disabling Laser for hba: %p\n", vha);
5731
5732 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
5733 (BIT_15|BIT_14|BIT_13|BIT_12));
5734
5735 fn = (fn >> 12);
5736
5737 if (fn & 1)
5738 reg = PORT_1_2031;
5739 else
5740 reg = PORT_0_2031;
5741
5742 data = LASER_OFF_2031;
5743
5744 qla83xx_wr_reg(vha, reg, data);
5745}
5746
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005747static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005748 .error_detected = qla2xxx_pci_error_detected,
5749 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5750 .slot_reset = qla2xxx_pci_slot_reset,
5751 .resume = qla2xxx_pci_resume,
5752};
5753
Andrew Vasquez54333832005-11-09 15:49:04 -08005754static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005755 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5756 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5757 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5758 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5759 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5760 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5761 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5762 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5763 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005764 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005765 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5766 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005767 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005768 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005769 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005770 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005771 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005772 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005773 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05005774 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04005775 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005776 { 0 },
5777};
5778MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5779
Andrew Vasquezfca29702005-07-06 10:31:47 -07005780static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005781 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005782 .driver = {
5783 .owner = THIS_MODULE,
5784 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005785 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005786 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005787 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005788 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005789 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005790};
5791
Al Viro75ef9de2013-04-04 19:09:41 -04005792static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005793 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005794 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005795};
5796
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797/**
5798 * qla2x00_module_init - Module initialization.
5799 **/
5800static int __init
5801qla2x00_module_init(void)
5802{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005803 int ret = 0;
5804
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005806 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005807 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005809 ql_log(ql_log_fatal, NULL, 0x0001,
5810 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811 return -ENOMEM;
5812 }
5813
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005814 /* Initialize target kmem_cache and mem_pools */
5815 ret = qlt_init();
5816 if (ret < 0) {
5817 kmem_cache_destroy(srb_cachep);
5818 return ret;
5819 } else if (ret > 0) {
5820 /*
5821 * If initiator mode is explictly disabled by qlt_init(),
5822 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5823 * performing scsi_scan_target() during LOOP UP event.
5824 */
5825 qla2xxx_transport_functions.disable_target_scan = 1;
5826 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5827 }
5828
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 /* Derive version string. */
5830 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005831 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005832 strcat(qla2x00_version_str, "-debug");
5833
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005834 qla2xxx_transport_template =
5835 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005836 if (!qla2xxx_transport_template) {
5837 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005838 ql_log(ql_log_fatal, NULL, 0x0002,
5839 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005840 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005842 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005843
5844 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5845 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005846 ql_log(ql_log_fatal, NULL, 0x0003,
5847 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005848 }
5849
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005850 qla2xxx_transport_vport_template =
5851 fc_attach_transport(&qla2xxx_transport_vport_functions);
5852 if (!qla2xxx_transport_vport_template) {
5853 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005854 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005855 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005856 ql_log(ql_log_fatal, NULL, 0x0004,
5857 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005858 return -ENODEV;
5859 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005860 ql_log(ql_log_info, NULL, 0x0005,
5861 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005862 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005863 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005864 if (ret) {
5865 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005866 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005867 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005868 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005869 ql_log(ql_log_fatal, NULL, 0x0006,
5870 "pci_register_driver failed...ret=%d Failing load!.\n",
5871 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005872 }
5873 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874}
5875
5876/**
5877 * qla2x00_module_exit - Module cleanup.
5878 **/
5879static void __exit
5880qla2x00_module_exit(void)
5881{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005882 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005883 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005884 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005885 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005886 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005887 if (ctx_cachep)
5888 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005890 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891}
5892
5893module_init(qla2x00_module_init);
5894module_exit(qla2x00_module_exit);
5895
5896MODULE_AUTHOR("QLogic Corporation");
5897MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5898MODULE_LICENSE("GPL");
5899MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005900MODULE_FIRMWARE(FW_FILE_ISP21XX);
5901MODULE_FIRMWARE(FW_FILE_ISP22XX);
5902MODULE_FIRMWARE(FW_FILE_ISP2300);
5903MODULE_FIRMWARE(FW_FILE_ISP2322);
5904MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005905MODULE_FIRMWARE(FW_FILE_ISP25XX);