blob: 89a53002b58577e003cb5a3a499138a1111e9f53 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 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;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800108module_param(ql2xfdmienable, int, S_IRUGO);
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,
123 " Enable T10-CRC-DIF "
Arun Easi8cb20492011-08-16 11:29:22 -0700124 " Default is 0 - No DIF Support. 1 - Enable it"
125 ", 2 - Enable DIF for all types, except Type 0.");
Arun Easibad75002010-05-04 15:01:30 -0700126
Arun Easi8cb20492011-08-16 11:29:22 -0700127int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700128module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
129MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700130 " Enable T10-CRC-DIF Error isolation by HBA:\n"
131 " Default is 1.\n"
132 " 0 -- Error isolation disabled\n"
133 " 1 -- Error isolation enabled only for DIX Type 0\n"
134 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700135
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700136int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800137module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700138MODULE_PARM_DESC(ql2xiidmaenable,
139 "Enables iIDMA settings "
140 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
141
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800142int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800143module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800144MODULE_PARM_DESC(ql2xmaxqueues,
145 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700146 "Default is 1 for single queue. Set it to number "
147 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700148
149int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800150module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700151MODULE_PARM_DESC(ql2xmultique_tag,
152 "Enables CPU affinity settings for the driver "
153 "Default is 0 for no affinity of request and response IO. "
154 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700155
156int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700157module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700158MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700159 "Option to specify location from which to load ISP firmware:.\n"
160 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700161 " interface.\n"
162 " 1 -- load firmware from flash.\n"
163 " 0 -- use default semantics.\n");
164
Andrew Vasquezae97c912010-02-18 10:07:28 -0800165int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800166module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800167MODULE_PARM_DESC(ql2xetsenable,
168 "Enables firmware ETS burst."
169 "Default is 0 - skip ETS enablement.");
170
Giridhar Malavali69078692010-05-28 15:08:28 -0700171int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700172module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700173MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700174 "Option to specify scheme for request queue posting.\n"
175 " 0 -- Regular doorbell.\n"
176 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700177
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700178int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800179module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700180MODULE_PARM_DESC(ql2xtargetreset,
181 "Enable target reset."
182 "Default is 1 - use hw defaults.");
183
Chad Dupuis4da26e12010-10-15 11:27:40 -0700184int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800185module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700186MODULE_PARM_DESC(ql2xgffidenable,
187 "Enables GFF_ID checks of port type. "
188 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700189
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700190int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800191module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700192MODULE_PARM_DESC(ql2xasynctmfenable,
193 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
194 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700195
196int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700197module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700198MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700199 "Option to specify reset behaviour.\n"
200 " 0 (Default) -- Reset on failure.\n"
201 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700202
Andrew Vasquez82515922011-05-10 11:30:13 -0700203uint ql2xmaxlun = MAX_LUNS;
204module_param(ql2xmaxlun, uint, S_IRUGO);
205MODULE_PARM_DESC(ql2xmaxlun,
206 "Defines the maximum LU number to register with the SCSI "
207 "midlayer. Default is 65535.");
208
Giridhar Malavali08de2842011-08-16 11:31:44 -0700209int ql2xmdcapmask = 0x1F;
210module_param(ql2xmdcapmask, int, S_IRUGO);
211MODULE_PARM_DESC(ql2xmdcapmask,
212 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800213 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700214
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800215int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700216module_param(ql2xmdenable, int, S_IRUGO);
217MODULE_PARM_DESC(ql2xmdenable,
218 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800219 "0 - MiniDump disabled. "
220 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700223 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 */
225static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500226static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800227static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
228static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500229static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500230static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231static int qla2xxx_eh_abort(struct scsi_cmnd *);
232static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700233static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
235static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Mike Christiee881a172009-10-15 17:46:39 -0700237static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700238static int qla2x00_change_queue_type(struct scsi_device *, int);
Saurav Kashyap34912552013-06-25 11:27:18 -0400239static void qla2x00_free_device(scsi_qla_host_t *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700240
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700241struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700243 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700244 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700245
246 .eh_abort_handler = qla2xxx_eh_abort,
247 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700248 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700249 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
250 .eh_host_reset_handler = qla2xxx_eh_host_reset,
251
252 .slave_configure = qla2xxx_slave_configure,
253
254 .slave_alloc = qla2xxx_slave_alloc,
255 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700256 .scan_finished = qla2xxx_scan_finished,
257 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700258 .change_queue_depth = qla2x00_change_queue_depth,
259 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700260 .this_id = -1,
261 .cmd_per_lun = 3,
262 .use_clustering = ENABLE_CLUSTERING,
263 .sg_tablesize = SG_ALL,
264
265 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700266 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400267
268 .supported_mode = MODE_INITIATOR,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700269};
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700272struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274/* TODO Convert to inlines
275 *
276 * Timer routines
277 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700279__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800280qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800282 init_timer(&vha->timer);
283 vha->timer.expires = jiffies + interval * HZ;
284 vha->timer.data = (unsigned long)vha;
285 vha->timer.function = (void (*)(unsigned long))func;
286 add_timer(&vha->timer);
287 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
290static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800291qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700293 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 if (vha->device_flags & DFLG_DEV_FAILED) {
295 ql_dbg(ql_dbg_timer, vha, 0x600d,
296 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700297 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700298 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700299
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800300 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Adrian Bunka824ebb2008-01-17 09:02:15 -0800303static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800304qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306 del_timer_sync(&vha->timer);
307 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310static int qla2x00_do_dpc(void *data);
311
312static void qla2x00_rst_aen(scsi_qla_host_t *);
313
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800314static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
315 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700316static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800317static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400320static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
321 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800322{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700323 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700324 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800325 GFP_KERNEL);
326 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700327 ql_log(ql_log_fatal, vha, 0x003b,
328 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800329 goto fail_req_map;
330 }
331
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700332 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800333 GFP_KERNEL);
334 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700335 ql_log(ql_log_fatal, vha, 0x003c,
336 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800337 goto fail_rsp_map;
338 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400339 /*
340 * Make sure we record at least the request and response queue zero in
341 * case we need to free them if part of the probe fails.
342 */
343 ha->rsp_q_map[0] = rsp;
344 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800345 set_bit(0, ha->rsp_qid_map);
346 set_bit(0, ha->req_qid_map);
347 return 1;
348
349fail_rsp_map:
350 kfree(ha->req_q_map);
351 ha->req_q_map = NULL;
352fail_req_map:
353 return -ENOMEM;
354}
355
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700356static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800357{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400358 if (IS_QLAFX00(ha)) {
359 if (req && req->ring_fx00)
360 dma_free_coherent(&ha->pdev->dev,
361 (req->length_fx00 + 1) * sizeof(request_t),
362 req->ring_fx00, req->dma_fx00);
363 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800364 dma_free_coherent(&ha->pdev->dev,
365 (req->length + 1) * sizeof(request_t),
366 req->ring, req->dma);
367
Chad Dupuis8d93f552013-01-30 03:34:37 -0500368 if (req)
369 kfree(req->outstanding_cmds);
370
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800371 kfree(req);
372 req = NULL;
373}
374
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700375static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
376{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400377 if (IS_QLAFX00(ha)) {
378 if (rsp && rsp->ring)
379 dma_free_coherent(&ha->pdev->dev,
380 (rsp->length_fx00 + 1) * sizeof(request_t),
381 rsp->ring_fx00, rsp->dma_fx00);
382 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700383 dma_free_coherent(&ha->pdev->dev,
384 (rsp->length + 1) * sizeof(response_t),
385 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400386 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700387 kfree(rsp);
388 rsp = NULL;
389}
390
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800391static void qla2x00_free_queues(struct qla_hw_data *ha)
392{
393 struct req_que *req;
394 struct rsp_que *rsp;
395 int cnt;
396
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700397 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800398 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700399 qla2x00_free_req_que(ha, req);
400 }
401 kfree(ha->req_q_map);
402 ha->req_q_map = NULL;
403
404 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
405 rsp = ha->rsp_q_map[cnt];
406 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800407 }
408 kfree(ha->rsp_q_map);
409 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800410}
411
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700412static int qla25xx_setup_mode(struct scsi_qla_host *vha)
413{
414 uint16_t options = 0;
415 int ques, req, ret;
416 struct qla_hw_data *ha = vha->hw;
417
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700418 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700419 ql_log(ql_log_warn, vha, 0x00d8,
420 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700421 goto fail;
422 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700423 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700424 /* create a request queue for IO */
425 options |= BIT_7;
426 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
427 QLA_DEFAULT_QUE_QOS);
428 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700429 ql_log(ql_log_warn, vha, 0x00e0,
430 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700431 goto fail;
432 }
Tejun Heo278274d2011-02-01 11:42:42 +0100433 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700434 vha->req = ha->req_q_map[req];
435 options |= BIT_1;
436 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
437 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
438 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700439 ql_log(ql_log_warn, vha, 0x00e8,
440 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700441 goto fail2;
442 }
443 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700444 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700445 ql_dbg(ql_dbg_multiq, vha, 0xc007,
446 "CPU affinity mode enalbed, "
447 "no. of response queues:%d no. of request queues:%d.\n",
448 ha->max_rsp_queues, ha->max_req_queues);
449 ql_dbg(ql_dbg_init, vha, 0x00e9,
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);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700453 }
454 return 0;
455fail2:
456 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700457 destroy_workqueue(ha->wq);
458 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800459 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700460fail:
461 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700462 kfree(ha->req_q_map);
463 kfree(ha->rsp_q_map);
464 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700465 return 1;
466}
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800469qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800471 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 static char *pci_bus_modes[] = {
473 "33", "66", "100", "133",
474 };
475 uint16_t pci_bus;
476
477 strcpy(str, "PCI");
478 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
479 if (pci_bus) {
480 strcat(str, "-X (");
481 strcat(str, pci_bus_modes[pci_bus]);
482 } else {
483 pci_bus = (ha->pci_attr & BIT_8) >> 8;
484 strcat(str, " (");
485 strcat(str, pci_bus_modes[pci_bus]);
486 }
487 strcat(str, " MHz)");
488
489 return (str);
490}
491
Andrew Vasquezfca29702005-07-06 10:31:47 -0700492static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800493qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700494{
495 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800496 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700497 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700498
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600499 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700500 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600501 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700502
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600503 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
504 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
505 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506
507 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500508 switch (lspeed) {
509 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700510 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500511 break;
512 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700513 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500514 break;
515 case 3:
516 strcat(str, "8.0GT/s ");
517 break;
518 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700519 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500520 break;
521 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
523 strcat(str, lwstr);
524
525 return str;
526 }
527
528 strcpy(str, "PCI");
529 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
530 if (pci_bus == 0 || pci_bus == 8) {
531 strcat(str, " (");
532 strcat(str, pci_bus_modes[pci_bus >> 3]);
533 } else {
534 strcat(str, "-X ");
535 if (pci_bus & BIT_2)
536 strcat(str, "Mode 2");
537 else
538 strcat(str, "Mode 1");
539 strcat(str, " (");
540 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
541 }
542 strcat(str, " MHz)");
543
544 return str;
545}
546
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800547static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800548qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
554 ha->fw_minor_version,
555 ha->fw_subminor_version);
556
557 if (ha->fw_attributes & BIT_9) {
558 strcat(str, "FLX");
559 return (str);
560 }
561
562 switch (ha->fw_attributes & 0xFF) {
563 case 0x7:
564 strcat(str, "EF");
565 break;
566 case 0x17:
567 strcat(str, "TP");
568 break;
569 case 0x37:
570 strcat(str, "IP");
571 break;
572 case 0x77:
573 strcat(str, "VI");
574 break;
575 default:
576 sprintf(un_str, "(%x)", ha->fw_attributes);
577 strcat(str, un_str);
578 break;
579 }
580 if (ha->fw_attributes & 0x100)
581 strcat(str, "X");
582
583 return (str);
584}
585
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800586static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700588{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700590
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800591 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
592 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700593 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700594}
595
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800596void
597qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700598{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800599 srb_t *sp = (srb_t *)ptr;
600 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
601 struct qla_hw_data *ha = sp->fcport->vha->hw;
602 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700603
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800604 if (sp->flags & SRB_DMA_VALID) {
605 scsi_dma_unmap(cmd);
606 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700607 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700608
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800609 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
610 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
611 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
612 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
613 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700614
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800615 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
616 /* List assured to be having elements */
617 qla2x00_clean_dsd_pool(ha, sp);
618 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
619 }
620
621 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
622 dma_pool_free(ha->dl_dma_pool, ctx,
623 ((struct crc_context *)ctx)->crc_ctx_dma);
624 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
625 }
626
627 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
628 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
629
630 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
631 ctx1->fcp_cmnd_dma);
632 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
633 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
634 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
635 mempool_free(ctx1, ha->ctx_mempool);
636 ctx1 = NULL;
637 }
638
639 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500640 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800641}
642
Fengguang Wu14b06802013-04-25 01:29:19 -0400643static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800644qla2x00_sp_compl(void *data, void *ptr, int res)
645{
646 struct qla_hw_data *ha = (struct qla_hw_data *)data;
647 srb_t *sp = (srb_t *)ptr;
648 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
649
650 cmd->result = res;
651
652 if (atomic_read(&sp->ref_count) == 0) {
653 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
654 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
655 sp, GET_CMD_SP(sp));
656 if (ql2xextended_error_logging & ql_dbg_io)
657 BUG();
658 return;
659 }
660 if (!atomic_dec_and_test(&sp->ref_count))
661 return;
662
663 qla2x00_sp_free_dma(ha, sp);
664 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700665}
666
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400667/* If we are SP1 here, we need to still take and release the host_lock as SP1
668 * does not have the changes necessary to avoid taking host->host_lock.
669 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800671qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700672{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700673 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700674 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400675 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800676 struct qla_hw_data *ha = vha->hw;
677 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700678 srb_t *sp;
679 int rval;
680
Andrew Vasquez85880802009-12-15 21:29:46 -0800681 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700682 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400683 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700684 "PCI Channel IO permanent failure, exiting "
685 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700686 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400688 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700689 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800690 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700692 goto qc24_fail_command;
693 }
694
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400695 rval = fc_remote_port_chkready(rport);
696 if (rval) {
697 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400698 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700699 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
700 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700701 goto qc24_fail_command;
702 }
703
Arun Easibad75002010-05-04 15:01:30 -0700704 if (!vha->flags.difdix_supported &&
705 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700706 ql_dbg(ql_dbg_io, vha, 0x3004,
707 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
708 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700709 cmd->result = DID_NO_CONNECT << 16;
710 goto qc24_fail_command;
711 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800712
713 if (!fcport) {
714 cmd->result = DID_NO_CONNECT << 16;
715 goto qc24_fail_command;
716 }
717
Andrew Vasquezfca29702005-07-06 10:31:47 -0700718 if (atomic_read(&fcport->state) != FCS_ONLINE) {
719 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700720 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700721 ql_dbg(ql_dbg_io, vha, 0x3005,
722 "Returning DNC, fcport_state=%d loop_state=%d.\n",
723 atomic_read(&fcport->state),
724 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700725 cmd->result = DID_NO_CONNECT << 16;
726 goto qc24_fail_command;
727 }
Mike Christie7b594132008-08-17 15:24:40 -0500728 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700729 }
730
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500731 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400732 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800733 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700734
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800735 sp->u.scmd.cmd = cmd;
736 sp->type = SRB_SCSI_CMD;
737 atomic_set(&sp->ref_count, 1);
738 CMD_SP(cmd) = (void *)sp;
739 sp->free = qla2x00_sp_free_dma;
740 sp->done = qla2x00_sp_compl;
741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800742 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700743 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500744 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700745 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700746 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700747 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700748
Andrew Vasquezfca29702005-07-06 10:31:47 -0700749 return 0;
750
751qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800752 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700753
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800754qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700755 return SCSI_MLQUEUE_HOST_BUSY;
756
Mike Christie7b594132008-08-17 15:24:40 -0500757qc24_target_busy:
758 return SCSI_MLQUEUE_TARGET_BUSY;
759
Andrew Vasquezfca29702005-07-06 10:31:47 -0700760qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800761 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700762
763 return 0;
764}
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766/*
767 * qla2x00_eh_wait_on_command
768 * Waits for the command to be returned by the Firmware for some
769 * max time.
770 *
771 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 *
774 * Return:
775 * Not Found : 0
776 * Found : 1
777 */
778static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800779qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700781#define ABORT_POLLING_PERIOD 1000
782#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500783 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800784 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
785 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500786 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Andrew Vasquez85880802009-12-15 21:29:46 -0800788 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700789 ql_dbg(ql_dbg_taskm, vha, 0x8005,
790 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800791 return ret;
792 }
793
Lalit Chandivaded9704322009-08-25 11:36:18 -0700794 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700795 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500796 }
797 if (CMD_SP(cmd))
798 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
f4f051e2005-04-17 15:02:26 -0500800 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
803/*
804 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700805 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 * <= MAX_RETRIES_OF_ISP_ABORT or
807 * finally HBA is disabled ie marked offline
808 *
809 * Input:
810 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700811 *
812 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 * Does context switching-Release SPIN_LOCK
814 * (if any) before calling this routine.
815 *
816 * Return:
817 * Success (Adapter is online) : 0
818 * Failed (Adapter is offline/disabled) : 1
819 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800820int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800821qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700823 int return_status;
824 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800825 struct qla_hw_data *ha = vha->hw;
826 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700828 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800829 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
830 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
831 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
832 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 msleep(1000);
835 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800836 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700837 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 else
839 return_status = QLA_FUNCTION_FAILED;
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 return (return_status);
842}
843
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700844/*
845 * qla2x00_wait_for_reset_ready
846 * Wait till the HBA is online after going through
847 * <= MAX_RETRIES_OF_ISP_ABORT or
848 * finally HBA is disabled ie marked offline or flash
849 * operations are in progress.
850 *
851 * Input:
852 * ha - pointer to host adapter structure
853 *
854 * Note:
855 * Does context switching-Release SPIN_LOCK
856 * (if any) before calling this routine.
857 *
858 * Return:
859 * Success (Adapter is online/no flash ops) : 0
860 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
861 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500862static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700863qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
864{
865 int return_status;
866 unsigned long wait_online;
867 struct qla_hw_data *ha = vha->hw;
868 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
869
870 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
871 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
872 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
873 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
874 ha->optrom_state != QLA_SWAITING ||
875 ha->dpc_active) && time_before(jiffies, wait_online))
876 msleep(1000);
877
878 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
879 return_status = QLA_SUCCESS;
880 else
881 return_status = QLA_FUNCTION_FAILED;
882
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700883 ql_dbg(ql_dbg_taskm, vha, 0x8019,
884 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700885
886 return return_status;
887}
888
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700889int
890qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
891{
892 int return_status;
893 unsigned long wait_reset;
894 struct qla_hw_data *ha = vha->hw;
895 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
896
897 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
898 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
899 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
900 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
901 ha->dpc_active) && time_before(jiffies, wait_reset)) {
902
903 msleep(1000);
904
905 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
906 ha->flags.chip_reset_done)
907 break;
908 }
909 if (ha->flags.chip_reset_done)
910 return_status = QLA_SUCCESS;
911 else
912 return_status = QLA_FUNCTION_FAILED;
913
914 return return_status;
915}
916
Giridhar Malavali083a4692010-05-28 15:08:18 -0700917static void
918sp_get(struct srb *sp)
919{
920 atomic_inc(&sp->ref_count);
921}
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923/**************************************************************************
924* qla2xxx_eh_abort
925*
926* Description:
927* The abort function will abort the specified command.
928*
929* Input:
930* cmd = Linux SCSI command packet to be aborted.
931*
932* Returns:
933* Either SUCCESS or FAILED.
934*
935* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700936* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800938static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939qla2xxx_eh_abort(struct scsi_cmnd *cmd)
940{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800941 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500942 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800943 int ret;
f4f051e2005-04-17 15:02:26 -0500944 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700945 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700946 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800947 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
f4f051e2005-04-17 15:02:26 -0500949 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700950 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800952 ret = fc_block_scsi_eh(cmd);
953 if (ret != 0)
954 return ret;
955 ret = SUCCESS;
956
f4f051e2005-04-17 15:02:26 -0500957 id = cmd->device->id;
958 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800960 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700961 sp = (srb_t *) CMD_SP(cmd);
962 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800963 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700964 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500965 }
Mike Christie170babc2010-10-15 11:27:47 -0700966
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700967 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800968 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
969 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700970
971 /* Get a reference to the sp and drop the lock.*/
972 sp_get(sp);
973
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800974 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700975 if (ha->isp_ops->abort_command(sp)) {
Arun Easia55aac72012-02-09 11:14:03 -0800976 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700977 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800978 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700979 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700980 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800981 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700982 wait = 1;
983 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700984
985 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800986 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700987 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500988
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700989 /* Did the command return during mailbox execution? */
990 if (ret == FAILED && !CMD_SP(cmd))
991 ret = SUCCESS;
992
f4f051e2005-04-17 15:02:26 -0500993 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700994 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800995 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700996 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800997 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -0700998 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001003 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
1004 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
f4f051e2005-04-17 15:02:26 -05001006 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001009int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001010qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001011 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001013 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001014 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001015 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001016 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001017 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001018 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Andrew Vasquez523ec772008-04-03 13:13:24 -07001020 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001021
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001022 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001023 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001024 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001025 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001026 sp = req->outstanding_cmds[cnt];
1027 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001028 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001029 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001030 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001031 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1032 continue;
1033 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001034 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001035 switch (type) {
1036 case WAIT_HOST:
1037 match = 1;
1038 break;
1039 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001040 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001041 break;
1042 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001043 match = (cmd->device->id == t &&
1044 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001045 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001047 if (!match)
1048 continue;
1049
1050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001051 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001052 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001054 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001055
1056 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
Andrew Vasquez523ec772008-04-03 13:13:24 -07001059static char *reset_errors[] = {
1060 "HBA not online",
1061 "HBA not ready",
1062 "Task management failed",
1063 "Waiting for command completions",
1064};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Andrew Vasquez523ec772008-04-03 13:13:24 -07001066static int
1067__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001068 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001069{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001070 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001071 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1072 int err;
1073
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001074 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001075 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001076 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001077
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001078 err = fc_block_scsi_eh(cmd);
1079 if (err != 0)
1080 return err;
1081
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001082 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001083 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001085
1086 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001087 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1088 ql_log(ql_log_warn, vha, 0x800a,
1089 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001090 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001091 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001092 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001093 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001094 != QLA_SUCCESS) {
1095 ql_log(ql_log_warn, vha, 0x800c,
1096 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001097 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001098 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001099 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001100 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 cmd->device->lun, type) != QLA_SUCCESS) {
1102 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001103 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001104 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001105 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001106
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001107 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001108 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1109 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001110
1111 return SUCCESS;
1112
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001113eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001114 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001115 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1116 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1117 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001118 return FAILED;
1119}
1120
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001121static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1123{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001124 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1125 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Andrew Vasquez523ec772008-04-03 13:13:24 -07001127 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1128 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001132qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001134 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1135 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Andrew Vasquez523ec772008-04-03 13:13:24 -07001137 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1138 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141/**************************************************************************
1142* qla2xxx_eh_bus_reset
1143*
1144* Description:
1145* The bus reset function will reset the bus and abort any executing
1146* commands.
1147*
1148* Input:
1149* cmd = Linux SCSI command packet of the command that cause the
1150* bus reset.
1151*
1152* Returns:
1153* SUCCESS/FAILURE (defined as macro in scsi.h).
1154*
1155**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001156static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1158{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001159 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001160 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001161 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001162 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
f4f051e2005-04-17 15:02:26 -05001164 id = cmd->device->id;
1165 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001166
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001167 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001168 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001171 ret = fc_block_scsi_eh(cmd);
1172 if (ret != 0)
1173 return ret;
1174 ret = FAILED;
1175
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001176 ql_log(ql_log_info, vha, 0x8012,
Andrew Vasquez46270af2012-05-15 14:34:17 -04001177 "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001179 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001180 ql_log(ql_log_fatal, vha, 0x8013,
1181 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001182 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 }
1184
Saurav Kashyapad537682011-11-18 09:02:09 -08001185 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1186 ret = SUCCESS;
1187
f4f051e2005-04-17 15:02:26 -05001188 if (ret == FAILED)
1189 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001191 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001192 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001193 QLA_SUCCESS) {
1194 ql_log(ql_log_warn, vha, 0x8014,
1195 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001196 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
f4f051e2005-04-17 15:02:26 -05001199eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001200 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001201 "BUS RESET %s nexus=%ld:%d:%d.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001202 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
f4f051e2005-04-17 15:02:26 -05001204 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205}
1206
1207/**************************************************************************
1208* qla2xxx_eh_host_reset
1209*
1210* Description:
1211* The reset function will reset the Adapter.
1212*
1213* Input:
1214* cmd = Linux SCSI command packet of the command that cause the
1215* adapter reset.
1216*
1217* Returns:
1218* Either SUCCESS or FAILED.
1219*
1220* Note:
1221**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001222static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1224{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001226 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001227 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001228 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001229 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
f4f051e2005-04-17 15:02:26 -05001231 id = cmd->device->id;
1232 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001233
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001234 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001235 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001237 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001238 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001240 if (vha != base_vha) {
1241 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001242 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001243 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001244 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001245 if (!qla82xx_fcoe_ctx_reset(vha)) {
1246 /* Ctx reset success */
1247 ret = SUCCESS;
1248 goto eh_host_reset_lock;
1249 }
1250 /* fall thru if ctx reset failed */
1251 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001252 if (ha->wq)
1253 flush_workqueue(ha->wq);
1254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001255 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001256 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001257 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1258 /* failed. schedule dpc to try */
1259 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1260
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001261 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1262 ql_log(ql_log_warn, vha, 0x802a,
1263 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001265 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001266 }
1267 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001271 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001273 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
f4f051e2005-04-17 15:02:26 -05001275eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001276 ql_log(ql_log_info, vha, 0x8017,
1277 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1278 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
f4f051e2005-04-17 15:02:26 -05001280 return ret;
1281}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
1283/*
1284* qla2x00_loop_reset
1285* Issue loop reset.
1286*
1287* Input:
1288* ha = adapter block pointer.
1289*
1290* Returns:
1291* 0 = success
1292*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001293int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001294qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001296 int ret;
bdf79622005-04-17 15:06:53 -05001297 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001298 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Armen Baloyan58547712013-08-27 01:37:33 -04001300 if (IS_QLAFX00(ha)) {
1301 return qlafx00_loop_reset(vha);
1302 }
1303
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001304 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001305 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1306 if (fcport->port_type != FCT_TARGET)
1307 continue;
1308
1309 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1310 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001311 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001312 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001314 }
1315 }
1316 }
1317
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001318
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001319 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001320 atomic_set(&vha->loop_state, LOOP_DOWN);
1321 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1322 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001323 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001324 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1326 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 }
1329
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001330 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001331 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001332 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001333 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1334 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001335 }
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001338 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001340 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001343void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001344qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001345{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001346 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001347 unsigned long flags;
1348 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001349 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001350 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001351
1352 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001353 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001354 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001355 if (!req)
1356 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001357 if (!req->outstanding_cmds)
1358 continue;
1359 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001360 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001361 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001362 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001363 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001364 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001365 }
1366 }
1367 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1368}
1369
f4f051e2005-04-17 15:02:26 -05001370static int
1371qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
bdf79622005-04-17 15:06:53 -05001373 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001375 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001376 return -ENXIO;
1377
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001378 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001379
1380 return 0;
1381}
1382
1383static int
1384qla2xxx_slave_configure(struct scsi_device *sdev)
1385{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001387 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001388
Arun Easi9e522cd2012-08-22 14:21:31 -04001389 if (IS_T10_PI_CAPABLE(vha->hw))
1390 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1391
f4f051e2005-04-17 15:02:26 -05001392 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001393 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001395 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001396 return 0;
1397}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
f4f051e2005-04-17 15:02:26 -05001399static void
1400qla2xxx_slave_destroy(struct scsi_device *sdev)
1401{
1402 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001405static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1406{
1407 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1408
1409 if (!scsi_track_queue_full(sdev, qdepth))
1410 return;
1411
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001412 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001413 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1414 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001415}
1416
1417static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1418{
1419 fc_port_t *fcport = sdev->hostdata;
1420 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001421 struct req_que *req = NULL;
1422
1423 req = vha->req;
1424 if (!req)
1425 return;
1426
1427 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1428 return;
1429
1430 if (sdev->ordered_tags)
1431 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1432 else
1433 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1434
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001435 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001436 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1437 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001438}
1439
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001440static int
Mike Christiee881a172009-10-15 17:46:39 -07001441qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001442{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001443 switch (reason) {
1444 case SCSI_QDEPTH_DEFAULT:
1445 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1446 break;
1447 case SCSI_QDEPTH_QFULL:
1448 qla2x00_handle_queue_full(sdev, qdepth);
1449 break;
1450 case SCSI_QDEPTH_RAMP_UP:
1451 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1452 break;
1453 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001454 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001455 }
Mike Christiee881a172009-10-15 17:46:39 -07001456
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001457 return sdev->queue_depth;
1458}
1459
1460static int
1461qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1462{
1463 if (sdev->tagged_supported) {
1464 scsi_set_tag_type(sdev, tag_type);
1465 if (tag_type)
1466 scsi_activate_tcq(sdev, sdev->queue_depth);
1467 else
1468 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1469 } else
1470 tag_type = 0;
1471
1472 return tag_type;
1473}
1474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475/**
1476 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1477 * @ha: HA context
1478 *
1479 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1480 * supported addressing method.
1481 */
1482static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001483qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001485 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Yang Hongyang6a355282009-04-06 19:01:13 -07001488 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001489 /* Any upper-dword bits set? */
1490 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001491 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001492 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001494 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1495 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001496 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001499
Yang Hongyang284901a2009-04-06 19:01:15 -07001500 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1501 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001504static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001505qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001506{
1507 unsigned long flags = 0;
1508 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1509
1510 spin_lock_irqsave(&ha->hardware_lock, flags);
1511 ha->interrupts_on = 1;
1512 /* enable risc and host interrupts */
1513 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1514 RD_REG_WORD(&reg->ictrl);
1515 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1516
1517}
1518
1519static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001520qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001521{
1522 unsigned long flags = 0;
1523 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1524
1525 spin_lock_irqsave(&ha->hardware_lock, flags);
1526 ha->interrupts_on = 0;
1527 /* disable risc and host interrupts */
1528 WRT_REG_WORD(&reg->ictrl, 0);
1529 RD_REG_WORD(&reg->ictrl);
1530 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1531}
1532
1533static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001534qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001535{
1536 unsigned long flags = 0;
1537 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1538
1539 spin_lock_irqsave(&ha->hardware_lock, flags);
1540 ha->interrupts_on = 1;
1541 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1542 RD_REG_DWORD(&reg->ictrl);
1543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1544}
1545
1546static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001547qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001548{
1549 unsigned long flags = 0;
1550 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1551
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001552 if (IS_NOPOLLING_TYPE(ha))
1553 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001554 spin_lock_irqsave(&ha->hardware_lock, flags);
1555 ha->interrupts_on = 0;
1556 WRT_REG_DWORD(&reg->ictrl, 0);
1557 RD_REG_DWORD(&reg->ictrl);
1558 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1559}
1560
Giridhar Malavali706f4572011-11-18 09:03:16 -08001561static int
1562qla2x00_iospace_config(struct qla_hw_data *ha)
1563{
1564 resource_size_t pio;
1565 uint16_t msix;
1566 int cpus;
1567
Giridhar Malavali706f4572011-11-18 09:03:16 -08001568 if (pci_request_selected_regions(ha->pdev, ha->bars,
1569 QLA2XXX_DRIVER_NAME)) {
1570 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1571 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1572 pci_name(ha->pdev));
1573 goto iospace_error_exit;
1574 }
1575 if (!(ha->bars & 1))
1576 goto skip_pio;
1577
1578 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1579 pio = pci_resource_start(ha->pdev, 0);
1580 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1581 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1582 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1583 "Invalid pci I/O region size (%s).\n",
1584 pci_name(ha->pdev));
1585 pio = 0;
1586 }
1587 } else {
1588 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1589 "Region #0 no a PIO resource (%s).\n",
1590 pci_name(ha->pdev));
1591 pio = 0;
1592 }
1593 ha->pio_address = pio;
1594 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1595 "PIO address=%llu.\n",
1596 (unsigned long long)ha->pio_address);
1597
1598skip_pio:
1599 /* Use MMIO operations for all accesses. */
1600 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1601 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1602 "Region #1 not an MMIO resource (%s), aborting.\n",
1603 pci_name(ha->pdev));
1604 goto iospace_error_exit;
1605 }
1606 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1607 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1608 "Invalid PCI mem region size (%s), aborting.\n",
1609 pci_name(ha->pdev));
1610 goto iospace_error_exit;
1611 }
1612
1613 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1614 if (!ha->iobase) {
1615 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1616 "Cannot remap MMIO (%s), aborting.\n",
1617 pci_name(ha->pdev));
1618 goto iospace_error_exit;
1619 }
1620
1621 /* Determine queue resources */
1622 ha->max_req_queues = ha->max_rsp_queues = 1;
1623 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1624 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1625 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1626 goto mqiobase_exit;
1627
1628 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1629 pci_resource_len(ha->pdev, 3));
1630 if (ha->mqiobase) {
1631 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1632 "MQIO Base=%p.\n", ha->mqiobase);
1633 /* Read MSIX vector size of the board */
1634 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1635 ha->msix_count = msix;
1636 /* Max queues are bounded by available msix vectors */
1637 /* queue 0 uses two msix vectors */
1638 if (ql2xmultique_tag) {
1639 cpus = num_online_cpus();
1640 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1641 (cpus + 1) : (ha->msix_count - 1);
1642 ha->max_req_queues = 2;
1643 } else if (ql2xmaxqueues > 1) {
1644 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1645 QLA_MQ_SIZE : ql2xmaxqueues;
1646 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1647 "QoS mode set, max no of request queues:%d.\n",
1648 ha->max_req_queues);
1649 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1650 "QoS mode set, max no of request queues:%d.\n",
1651 ha->max_req_queues);
1652 }
1653 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1654 "MSI-X vector count: %d.\n", msix);
1655 } else
1656 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1657 "BAR 3 not enabled.\n");
1658
1659mqiobase_exit:
1660 ha->msix_count = ha->max_rsp_queues + 1;
1661 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1662 "MSIX Count:%d.\n", ha->msix_count);
1663 return (0);
1664
1665iospace_error_exit:
1666 return (-ENOMEM);
1667}
1668
1669
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001670static int
1671qla83xx_iospace_config(struct qla_hw_data *ha)
1672{
1673 uint16_t msix;
1674 int cpus;
1675
1676 if (pci_request_selected_regions(ha->pdev, ha->bars,
1677 QLA2XXX_DRIVER_NAME)) {
1678 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1679 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1680 pci_name(ha->pdev));
1681
1682 goto iospace_error_exit;
1683 }
1684
1685 /* Use MMIO operations for all accesses. */
1686 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1687 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1688 "Invalid pci I/O region size (%s).\n",
1689 pci_name(ha->pdev));
1690 goto iospace_error_exit;
1691 }
1692 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1693 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1694 "Invalid PCI mem region size (%s), aborting\n",
1695 pci_name(ha->pdev));
1696 goto iospace_error_exit;
1697 }
1698
1699 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1700 if (!ha->iobase) {
1701 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1702 "Cannot remap MMIO (%s), aborting.\n",
1703 pci_name(ha->pdev));
1704 goto iospace_error_exit;
1705 }
1706
1707 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1708 /* 83XX 26XX always use MQ type access for queues
1709 * - mbar 2, a.k.a region 4 */
1710 ha->max_req_queues = ha->max_rsp_queues = 1;
1711 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1712 pci_resource_len(ha->pdev, 4));
1713
1714 if (!ha->mqiobase) {
1715 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1716 "BAR2/region4 not enabled\n");
1717 goto mqiobase_exit;
1718 }
1719
1720 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1721 pci_resource_len(ha->pdev, 2));
1722 if (ha->msixbase) {
1723 /* Read MSIX vector size of the board */
1724 pci_read_config_word(ha->pdev,
1725 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1726 ha->msix_count = msix;
1727 /* Max queues are bounded by available msix vectors */
1728 /* queue 0 uses two msix vectors */
1729 if (ql2xmultique_tag) {
1730 cpus = num_online_cpus();
1731 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1732 (cpus + 1) : (ha->msix_count - 1);
1733 ha->max_req_queues = 2;
1734 } else if (ql2xmaxqueues > 1) {
1735 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1736 QLA_MQ_SIZE : ql2xmaxqueues;
1737 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1738 "QoS mode set, max no of request queues:%d.\n",
1739 ha->max_req_queues);
1740 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1741 "QoS mode set, max no of request queues:%d.\n",
1742 ha->max_req_queues);
1743 }
1744 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1745 "MSI-X vector count: %d.\n", msix);
1746 } else
1747 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1748 "BAR 1 not enabled.\n");
1749
1750mqiobase_exit:
1751 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001752
1753 qlt_83xx_iospace_config(ha);
1754
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001755 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1756 "MSIX Count:%d.\n", ha->msix_count);
1757 return 0;
1758
1759iospace_error_exit:
1760 return -ENOMEM;
1761}
1762
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001763static struct isp_operations qla2100_isp_ops = {
1764 .pci_config = qla2100_pci_config,
1765 .reset_chip = qla2x00_reset_chip,
1766 .chip_diag = qla2x00_chip_diag,
1767 .config_rings = qla2x00_config_rings,
1768 .reset_adapter = qla2x00_reset_adapter,
1769 .nvram_config = qla2x00_nvram_config,
1770 .update_fw_options = qla2x00_update_fw_options,
1771 .load_risc = qla2x00_load_risc,
1772 .pci_info_str = qla2x00_pci_info_str,
1773 .fw_version_str = qla2x00_fw_version_str,
1774 .intr_handler = qla2100_intr_handler,
1775 .enable_intrs = qla2x00_enable_intrs,
1776 .disable_intrs = qla2x00_disable_intrs,
1777 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001778 .target_reset = qla2x00_abort_target,
1779 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001780 .fabric_login = qla2x00_login_fabric,
1781 .fabric_logout = qla2x00_fabric_logout,
1782 .calc_req_entries = qla2x00_calc_iocbs_32,
1783 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1784 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1785 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1786 .read_nvram = qla2x00_read_nvram_data,
1787 .write_nvram = qla2x00_write_nvram_data,
1788 .fw_dump = qla2100_fw_dump,
1789 .beacon_on = NULL,
1790 .beacon_off = NULL,
1791 .beacon_blink = NULL,
1792 .read_optrom = qla2x00_read_optrom_data,
1793 .write_optrom = qla2x00_write_optrom_data,
1794 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001795 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001796 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001797 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001798 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001799};
1800
1801static struct isp_operations qla2300_isp_ops = {
1802 .pci_config = qla2300_pci_config,
1803 .reset_chip = qla2x00_reset_chip,
1804 .chip_diag = qla2x00_chip_diag,
1805 .config_rings = qla2x00_config_rings,
1806 .reset_adapter = qla2x00_reset_adapter,
1807 .nvram_config = qla2x00_nvram_config,
1808 .update_fw_options = qla2x00_update_fw_options,
1809 .load_risc = qla2x00_load_risc,
1810 .pci_info_str = qla2x00_pci_info_str,
1811 .fw_version_str = qla2x00_fw_version_str,
1812 .intr_handler = qla2300_intr_handler,
1813 .enable_intrs = qla2x00_enable_intrs,
1814 .disable_intrs = qla2x00_disable_intrs,
1815 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001816 .target_reset = qla2x00_abort_target,
1817 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001818 .fabric_login = qla2x00_login_fabric,
1819 .fabric_logout = qla2x00_fabric_logout,
1820 .calc_req_entries = qla2x00_calc_iocbs_32,
1821 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1822 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1823 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1824 .read_nvram = qla2x00_read_nvram_data,
1825 .write_nvram = qla2x00_write_nvram_data,
1826 .fw_dump = qla2300_fw_dump,
1827 .beacon_on = qla2x00_beacon_on,
1828 .beacon_off = qla2x00_beacon_off,
1829 .beacon_blink = qla2x00_beacon_blink,
1830 .read_optrom = qla2x00_read_optrom_data,
1831 .write_optrom = qla2x00_write_optrom_data,
1832 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001833 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001834 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001835 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001836 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001837};
1838
1839static struct isp_operations qla24xx_isp_ops = {
1840 .pci_config = qla24xx_pci_config,
1841 .reset_chip = qla24xx_reset_chip,
1842 .chip_diag = qla24xx_chip_diag,
1843 .config_rings = qla24xx_config_rings,
1844 .reset_adapter = qla24xx_reset_adapter,
1845 .nvram_config = qla24xx_nvram_config,
1846 .update_fw_options = qla24xx_update_fw_options,
1847 .load_risc = qla24xx_load_risc,
1848 .pci_info_str = qla24xx_pci_info_str,
1849 .fw_version_str = qla24xx_fw_version_str,
1850 .intr_handler = qla24xx_intr_handler,
1851 .enable_intrs = qla24xx_enable_intrs,
1852 .disable_intrs = qla24xx_disable_intrs,
1853 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001854 .target_reset = qla24xx_abort_target,
1855 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001856 .fabric_login = qla24xx_login_fabric,
1857 .fabric_logout = qla24xx_fabric_logout,
1858 .calc_req_entries = NULL,
1859 .build_iocbs = NULL,
1860 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1861 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1862 .read_nvram = qla24xx_read_nvram_data,
1863 .write_nvram = qla24xx_write_nvram_data,
1864 .fw_dump = qla24xx_fw_dump,
1865 .beacon_on = qla24xx_beacon_on,
1866 .beacon_off = qla24xx_beacon_off,
1867 .beacon_blink = qla24xx_beacon_blink,
1868 .read_optrom = qla24xx_read_optrom_data,
1869 .write_optrom = qla24xx_write_optrom_data,
1870 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001872 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001873 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001874 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001875};
1876
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001877static struct isp_operations qla25xx_isp_ops = {
1878 .pci_config = qla25xx_pci_config,
1879 .reset_chip = qla24xx_reset_chip,
1880 .chip_diag = qla24xx_chip_diag,
1881 .config_rings = qla24xx_config_rings,
1882 .reset_adapter = qla24xx_reset_adapter,
1883 .nvram_config = qla24xx_nvram_config,
1884 .update_fw_options = qla24xx_update_fw_options,
1885 .load_risc = qla24xx_load_risc,
1886 .pci_info_str = qla24xx_pci_info_str,
1887 .fw_version_str = qla24xx_fw_version_str,
1888 .intr_handler = qla24xx_intr_handler,
1889 .enable_intrs = qla24xx_enable_intrs,
1890 .disable_intrs = qla24xx_disable_intrs,
1891 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001892 .target_reset = qla24xx_abort_target,
1893 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001894 .fabric_login = qla24xx_login_fabric,
1895 .fabric_logout = qla24xx_fabric_logout,
1896 .calc_req_entries = NULL,
1897 .build_iocbs = NULL,
1898 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1899 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1900 .read_nvram = qla25xx_read_nvram_data,
1901 .write_nvram = qla25xx_write_nvram_data,
1902 .fw_dump = qla25xx_fw_dump,
1903 .beacon_on = qla24xx_beacon_on,
1904 .beacon_off = qla24xx_beacon_off,
1905 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001906 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001907 .write_optrom = qla24xx_write_optrom_data,
1908 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001909 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001910 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001911 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001912 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001913};
1914
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001915static struct isp_operations qla81xx_isp_ops = {
1916 .pci_config = qla25xx_pci_config,
1917 .reset_chip = qla24xx_reset_chip,
1918 .chip_diag = qla24xx_chip_diag,
1919 .config_rings = qla24xx_config_rings,
1920 .reset_adapter = qla24xx_reset_adapter,
1921 .nvram_config = qla81xx_nvram_config,
1922 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001923 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001924 .pci_info_str = qla24xx_pci_info_str,
1925 .fw_version_str = qla24xx_fw_version_str,
1926 .intr_handler = qla24xx_intr_handler,
1927 .enable_intrs = qla24xx_enable_intrs,
1928 .disable_intrs = qla24xx_disable_intrs,
1929 .abort_command = qla24xx_abort_command,
1930 .target_reset = qla24xx_abort_target,
1931 .lun_reset = qla24xx_lun_reset,
1932 .fabric_login = qla24xx_login_fabric,
1933 .fabric_logout = qla24xx_fabric_logout,
1934 .calc_req_entries = NULL,
1935 .build_iocbs = NULL,
1936 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1937 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001938 .read_nvram = NULL,
1939 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001940 .fw_dump = qla81xx_fw_dump,
1941 .beacon_on = qla24xx_beacon_on,
1942 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001943 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001944 .read_optrom = qla25xx_read_optrom_data,
1945 .write_optrom = qla24xx_write_optrom_data,
1946 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001947 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001948 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001949 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001950 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001951};
1952
1953static struct isp_operations qla82xx_isp_ops = {
1954 .pci_config = qla82xx_pci_config,
1955 .reset_chip = qla82xx_reset_chip,
1956 .chip_diag = qla24xx_chip_diag,
1957 .config_rings = qla82xx_config_rings,
1958 .reset_adapter = qla24xx_reset_adapter,
1959 .nvram_config = qla81xx_nvram_config,
1960 .update_fw_options = qla24xx_update_fw_options,
1961 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001962 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001963 .fw_version_str = qla24xx_fw_version_str,
1964 .intr_handler = qla82xx_intr_handler,
1965 .enable_intrs = qla82xx_enable_intrs,
1966 .disable_intrs = qla82xx_disable_intrs,
1967 .abort_command = qla24xx_abort_command,
1968 .target_reset = qla24xx_abort_target,
1969 .lun_reset = qla24xx_lun_reset,
1970 .fabric_login = qla24xx_login_fabric,
1971 .fabric_logout = qla24xx_fabric_logout,
1972 .calc_req_entries = NULL,
1973 .build_iocbs = NULL,
1974 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1975 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1976 .read_nvram = qla24xx_read_nvram_data,
1977 .write_nvram = qla24xx_write_nvram_data,
1978 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001979 .beacon_on = qla82xx_beacon_on,
1980 .beacon_off = qla82xx_beacon_off,
1981 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001982 .read_optrom = qla82xx_read_optrom_data,
1983 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001984 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001985 .start_scsi = qla82xx_start_scsi,
1986 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001987 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001988 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001989};
1990
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001991static struct isp_operations qla8044_isp_ops = {
1992 .pci_config = qla82xx_pci_config,
1993 .reset_chip = qla82xx_reset_chip,
1994 .chip_diag = qla24xx_chip_diag,
1995 .config_rings = qla82xx_config_rings,
1996 .reset_adapter = qla24xx_reset_adapter,
1997 .nvram_config = qla81xx_nvram_config,
1998 .update_fw_options = qla24xx_update_fw_options,
1999 .load_risc = qla82xx_load_risc,
2000 .pci_info_str = qla24xx_pci_info_str,
2001 .fw_version_str = qla24xx_fw_version_str,
2002 .intr_handler = qla8044_intr_handler,
2003 .enable_intrs = qla82xx_enable_intrs,
2004 .disable_intrs = qla82xx_disable_intrs,
2005 .abort_command = qla24xx_abort_command,
2006 .target_reset = qla24xx_abort_target,
2007 .lun_reset = qla24xx_lun_reset,
2008 .fabric_login = qla24xx_login_fabric,
2009 .fabric_logout = qla24xx_fabric_logout,
2010 .calc_req_entries = NULL,
2011 .build_iocbs = NULL,
2012 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2013 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2014 .read_nvram = NULL,
2015 .write_nvram = NULL,
2016 .fw_dump = qla24xx_fw_dump,
2017 .beacon_on = qla82xx_beacon_on,
2018 .beacon_off = qla82xx_beacon_off,
2019 .beacon_blink = NULL,
2020 .read_optrom = qla82xx_read_optrom_data,
2021 .write_optrom = qla8044_write_optrom_data,
2022 .get_flash_version = qla82xx_get_flash_version,
2023 .start_scsi = qla82xx_start_scsi,
2024 .abort_isp = qla8044_abort_isp,
2025 .iospace_config = qla82xx_iospace_config,
2026 .initialize_adapter = qla2x00_initialize_adapter,
2027};
2028
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002029static struct isp_operations qla83xx_isp_ops = {
2030 .pci_config = qla25xx_pci_config,
2031 .reset_chip = qla24xx_reset_chip,
2032 .chip_diag = qla24xx_chip_diag,
2033 .config_rings = qla24xx_config_rings,
2034 .reset_adapter = qla24xx_reset_adapter,
2035 .nvram_config = qla81xx_nvram_config,
2036 .update_fw_options = qla81xx_update_fw_options,
2037 .load_risc = qla81xx_load_risc,
2038 .pci_info_str = qla24xx_pci_info_str,
2039 .fw_version_str = qla24xx_fw_version_str,
2040 .intr_handler = qla24xx_intr_handler,
2041 .enable_intrs = qla24xx_enable_intrs,
2042 .disable_intrs = qla24xx_disable_intrs,
2043 .abort_command = qla24xx_abort_command,
2044 .target_reset = qla24xx_abort_target,
2045 .lun_reset = qla24xx_lun_reset,
2046 .fabric_login = qla24xx_login_fabric,
2047 .fabric_logout = qla24xx_fabric_logout,
2048 .calc_req_entries = NULL,
2049 .build_iocbs = NULL,
2050 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2051 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2052 .read_nvram = NULL,
2053 .write_nvram = NULL,
2054 .fw_dump = qla83xx_fw_dump,
2055 .beacon_on = qla24xx_beacon_on,
2056 .beacon_off = qla24xx_beacon_off,
2057 .beacon_blink = qla83xx_beacon_blink,
2058 .read_optrom = qla25xx_read_optrom_data,
2059 .write_optrom = qla24xx_write_optrom_data,
2060 .get_flash_version = qla24xx_get_flash_version,
2061 .start_scsi = qla24xx_dif_start_scsi,
2062 .abort_isp = qla2x00_abort_isp,
2063 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002064 .initialize_adapter = qla2x00_initialize_adapter,
2065};
2066
2067static struct isp_operations qlafx00_isp_ops = {
2068 .pci_config = qlafx00_pci_config,
2069 .reset_chip = qlafx00_soft_reset,
2070 .chip_diag = qlafx00_chip_diag,
2071 .config_rings = qlafx00_config_rings,
2072 .reset_adapter = qlafx00_soft_reset,
2073 .nvram_config = NULL,
2074 .update_fw_options = NULL,
2075 .load_risc = NULL,
2076 .pci_info_str = qlafx00_pci_info_str,
2077 .fw_version_str = qlafx00_fw_version_str,
2078 .intr_handler = qlafx00_intr_handler,
2079 .enable_intrs = qlafx00_enable_intrs,
2080 .disable_intrs = qlafx00_disable_intrs,
2081 .abort_command = qlafx00_abort_command,
2082 .target_reset = qlafx00_abort_target,
2083 .lun_reset = qlafx00_lun_reset,
2084 .fabric_login = NULL,
2085 .fabric_logout = NULL,
2086 .calc_req_entries = NULL,
2087 .build_iocbs = NULL,
2088 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2089 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2090 .read_nvram = qla24xx_read_nvram_data,
2091 .write_nvram = qla24xx_write_nvram_data,
2092 .fw_dump = NULL,
2093 .beacon_on = qla24xx_beacon_on,
2094 .beacon_off = qla24xx_beacon_off,
2095 .beacon_blink = NULL,
2096 .read_optrom = qla24xx_read_optrom_data,
2097 .write_optrom = qla24xx_write_optrom_data,
2098 .get_flash_version = qla24xx_get_flash_version,
2099 .start_scsi = qlafx00_start_scsi,
2100 .abort_isp = qlafx00_abort_isp,
2101 .iospace_config = qlafx00_iospace_config,
2102 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002103};
2104
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002105static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002106qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002107{
2108 ha->device_type = DT_EXTENDED_IDS;
2109 switch (ha->pdev->device) {
2110 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2111 ha->device_type |= DT_ISP2100;
2112 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002113 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002114 break;
2115 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2116 ha->device_type |= DT_ISP2200;
2117 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002118 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002119 break;
2120 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2121 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002122 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002123 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002124 break;
2125 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2126 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002127 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002128 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002129 break;
2130 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2131 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002132 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002133 if (ha->pdev->subsystem_vendor == 0x1028 &&
2134 ha->pdev->subsystem_device == 0x0170)
2135 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002136 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002137 break;
2138 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2139 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002140 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002141 break;
2142 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2143 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002144 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002145 break;
2146 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2147 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002148 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002149 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002150 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002151 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002152 break;
2153 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2154 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002155 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002156 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002157 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002158 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002159 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002160 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2161 ha->device_type |= DT_ISP8432;
2162 ha->device_type |= DT_ZIO_SUPPORTED;
2163 ha->device_type |= DT_FWI2;
2164 ha->device_type |= DT_IIDMA;
2165 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2166 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002167 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2168 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002169 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002170 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002171 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002172 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2173 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002174 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002175 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002176 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002177 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2178 ha->device_type |= DT_ISP2532;
2179 ha->device_type |= DT_ZIO_SUPPORTED;
2180 ha->device_type |= DT_FWI2;
2181 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002182 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2183 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002184 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2185 ha->device_type |= DT_ISP8001;
2186 ha->device_type |= DT_ZIO_SUPPORTED;
2187 ha->device_type |= DT_FWI2;
2188 ha->device_type |= DT_IIDMA;
2189 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2190 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002191 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2192 ha->device_type |= DT_ISP8021;
2193 ha->device_type |= DT_ZIO_SUPPORTED;
2194 ha->device_type |= DT_FWI2;
2195 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2196 /* Initialize 82XX ISP flags */
2197 qla82xx_init_flags(ha);
2198 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002199 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2200 ha->device_type |= DT_ISP8044;
2201 ha->device_type |= DT_ZIO_SUPPORTED;
2202 ha->device_type |= DT_FWI2;
2203 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2204 /* Initialize 82XX ISP flags */
2205 qla82xx_init_flags(ha);
2206 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002207 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2208 ha->device_type |= DT_ISP2031;
2209 ha->device_type |= DT_ZIO_SUPPORTED;
2210 ha->device_type |= DT_FWI2;
2211 ha->device_type |= DT_IIDMA;
2212 ha->device_type |= DT_T10_PI;
2213 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2214 break;
2215 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2216 ha->device_type |= DT_ISP8031;
2217 ha->device_type |= DT_ZIO_SUPPORTED;
2218 ha->device_type |= DT_FWI2;
2219 ha->device_type |= DT_IIDMA;
2220 ha->device_type |= DT_T10_PI;
2221 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2222 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002223 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2224 ha->device_type |= DT_ISPFX00;
2225 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002226 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002227
Giridhar Malavalia9083012010-04-12 17:59:55 -07002228 if (IS_QLA82XX(ha))
2229 ha->port_no = !(ha->portnum & 1);
2230 else
2231 /* Get adapter physical port no from interrupt pin register. */
2232 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2233
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002234 if (ha->port_no & 1)
2235 ha->flags.port0 = 1;
2236 else
2237 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002238 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002239 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002240 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002241}
2242
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002243static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002244qla2xxx_scan_start(struct Scsi_Host *shost)
2245{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002247
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002248 if (vha->hw->flags.running_gold_fw)
2249 return;
2250
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2252 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2253 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2254 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002255}
2256
2257static int
2258qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2259{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002263 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002264 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002265 return 1;
2266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002268}
2269
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270/*
2271 * PCI driver interface
2272 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002273static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002274qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002276 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002278 scsi_qla_host_t *base_vha = NULL;
2279 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002280 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002281 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002282 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002283 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002284 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002285 struct req_que *req = NULL;
2286 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002287 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002288 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002289 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2290 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002291 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002292 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2293 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002294 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002295 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002296 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2297 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002298 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002299 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2300 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002301 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002302 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002303 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2304 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002305 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002306 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2307 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002308
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002309 if (mem_only) {
2310 if (pci_enable_device_mem(pdev))
2311 goto probe_out;
2312 } else {
2313 if (pci_enable_device(pdev))
2314 goto probe_out;
2315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
Jesse Barnes09276782008-10-18 17:33:19 -07002317 /* This may fail but that's ok */
2318 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2321 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002322 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2323 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002324 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002326 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2327 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002328 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002329 ha->tgt.enable_class_2 = ql2xenableclass2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002332 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002333 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002334 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002335 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002336 mutex_init(&ha->selflogin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002338 /* Set ISP-type information. */
2339 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002340
2341 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002342 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2343 IS_QLA83XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002344 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002345
Chad Dupuiscba1e472011-11-18 09:03:21 -08002346 ha->prev_topology = 0;
2347 ha->init_cb_size = sizeof(init_cb_t);
2348 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2349 ha->optrom_size = OPTROM_SIZE_2300;
2350
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002351 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002353 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 req_length = REQUEST_ENTRY_CNT_2100;
2356 rsp_length = RESPONSE_ENTRY_CNT_2100;
2357 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002358 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002359 ha->flash_conf_off = ~0;
2360 ha->flash_data_off = ~0;
2361 ha->nvram_conf_off = ~0;
2362 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002363 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002365 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002366 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 req_length = REQUEST_ENTRY_CNT_2200;
2368 rsp_length = RESPONSE_ENTRY_CNT_2100;
2369 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002370 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002371 ha->flash_conf_off = ~0;
2372 ha->flash_data_off = ~0;
2373 ha->nvram_conf_off = ~0;
2374 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002375 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002376 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002377 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002379 req_length = REQUEST_ENTRY_CNT_2200;
2380 rsp_length = RESPONSE_ENTRY_CNT_2300;
2381 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002382 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002383 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2384 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002385 ha->flash_conf_off = ~0;
2386 ha->flash_data_off = ~0;
2387 ha->nvram_conf_off = ~0;
2388 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002389 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002390 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002391 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002392 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 req_length = REQUEST_ENTRY_CNT_24XX;
2394 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002395 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002397 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002398 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002399 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002400 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002401 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002402 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2403 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2404 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2405 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002406 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002407 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002408 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 req_length = REQUEST_ENTRY_CNT_24XX;
2410 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002411 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002413 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002414 ha->gid_list_info_size = 8;
2415 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002416 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002417 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002418 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2419 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2420 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2421 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2422 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002423 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002424 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2425 req_length = REQUEST_ENTRY_CNT_24XX;
2426 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002427 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002428 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2429 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2430 ha->gid_list_info_size = 8;
2431 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002432 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002433 ha->isp_ops = &qla81xx_isp_ops;
2434 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2435 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2436 ha->nvram_conf_off = ~0;
2437 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002438 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002439 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002440 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2441 req_length = REQUEST_ENTRY_CNT_82XX;
2442 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2443 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2444 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2445 ha->gid_list_info_size = 8;
2446 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002447 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002448 ha->isp_ops = &qla82xx_isp_ops;
2449 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2450 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2451 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2452 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002453 } else if (IS_QLA8044(ha)) {
2454 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2455 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2456 req_length = REQUEST_ENTRY_CNT_82XX;
2457 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2458 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2459 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2460 ha->gid_list_info_size = 8;
2461 ha->optrom_size = OPTROM_SIZE_83XX;
2462 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2463 ha->isp_ops = &qla8044_isp_ops;
2464 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2465 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2466 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2467 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002468 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002469 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002470 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002471 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2472 req_length = REQUEST_ENTRY_CNT_24XX;
2473 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002474 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002475 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2476 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2477 ha->gid_list_info_size = 8;
2478 ha->optrom_size = OPTROM_SIZE_83XX;
2479 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2480 ha->isp_ops = &qla83xx_isp_ops;
2481 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2482 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2483 ha->nvram_conf_off = ~0;
2484 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002485 } else if (IS_QLAFX00(ha)) {
2486 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2487 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2488 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2489 req_length = REQUEST_ENTRY_CNT_FX00;
2490 rsp_length = RESPONSE_ENTRY_CNT_FX00;
2491 ha->init_cb_size = sizeof(struct init_cb_fx);
2492 ha->isp_ops = &qlafx00_isp_ops;
2493 ha->port_down_retry_count = 30; /* default value */
2494 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2495 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002496 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002497 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002498 ha->mr.host_info_resend = false;
2499 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002501
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002502 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2503 "mbx_count=%d, req_length=%d, "
2504 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002505 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2506 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002507 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2508 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002509 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002510 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2511 "isp_ops=%p, flash_conf_off=%d, "
2512 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2513 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2514 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002515
2516 /* Configure PCI I/O space */
2517 ret = ha->isp_ops->iospace_config(ha);
2518 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002519 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002520
2521 ql_log_pci(ql_log_info, pdev, 0x001d,
2522 "Found an ISP%04X irq %d iobase 0x%p.\n",
2523 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002524 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002525 init_completion(&ha->mbx_cmd_comp);
2526 complete(&ha->mbx_cmd_comp);
2527 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002528 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002529 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002531 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Andrew Vasquez53303c42009-01-22 09:45:37 -08002533 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002534 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2535 "64 Bit addressing is %s.\n",
2536 ha->flags.enable_64bit_addressing ? "enable" :
2537 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002538 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002540 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2541 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 goto probe_hw_failed;
2544 }
2545
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002546 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002548 req->max_q_depth = ql2xmaxqdepth;
2549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002550
2551 base_vha = qla2x00_create_host(sht, ha);
2552 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002553 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002554 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002555 qla2x00_free_req_que(ha, req);
2556 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 }
2559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002563 base_vha->req = req;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002564 if (IS_QLAFX00(ha))
Armen Baloyana4e04d92013-10-30 03:38:27 -04002565 host->can_queue = QLAFX00_MAX_CANQUEUE;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002566 else
2567 host->can_queue = req->length + 128;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002568 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002570 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002571 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2572 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002573
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002574 /* Setup fcport template structure. */
2575 ha->mr.fcport.vha = base_vha;
2576 ha->mr.fcport.port_type = FCT_UNKNOWN;
2577 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2578 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2579 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2580 ha->mr.fcport.scan_state = 1;
2581
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002582 /* Set the SG table size based on ISP type */
2583 if (!IS_FWI2_CAPABLE(ha)) {
2584 if (IS_QLA2100(ha))
2585 host->sg_tablesize = 32;
2586 } else {
2587 if (!IS_QLA82XX(ha))
2588 host->sg_tablesize = QLA_SG_ALL;
2589 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002590 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2591 "can_queue=%d, req=%p, "
2592 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2593 host->can_queue, base_vha->req,
2594 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Chad Dupuis642ef982012-02-09 11:15:57 -08002595 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002596 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002597 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002598 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002599 host->max_cmd_len = 32;
2600 else
2601 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002602 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002603 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002604 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002605 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002606
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002607 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2608 "max_id=%d this_id=%d "
2609 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002610 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002611 host->this_id, host->cmd_per_lun, host->unique_id,
2612 host->max_cmd_len, host->max_channel, host->max_lun,
2613 host->transportt, sht->vendor_id);
2614
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002615que_init:
2616 /* Alloc arrays of request and response ring ptrs */
2617 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2618 ql_log(ql_log_fatal, base_vha, 0x003d,
2619 "Failed to allocate memory for queue pointers..."
2620 "aborting.\n");
2621 goto probe_init_failed;
2622 }
2623
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002624 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002625
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002626 /* Set up the irqs */
2627 ret = qla2x00_request_irqs(ha, rsp);
2628 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002629 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002630
2631 pci_save_state(pdev);
2632
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002633 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002634 rsp->req = req;
2635 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002636
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002637 if (IS_QLAFX00(ha)) {
2638 ha->rsp_q_map[0] = rsp;
2639 ha->req_q_map[0] = req;
2640 set_bit(0, ha->req_qid_map);
2641 set_bit(0, ha->rsp_qid_map);
2642 }
2643
Andrew Vasquez08029992009-03-24 09:07:55 -07002644 /* FWI2-capable only. */
2645 req->req_q_in = &ha->iobase->isp24.req_q_in;
2646 req->req_q_out = &ha->iobase->isp24.req_q_out;
2647 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2648 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002649 if (ha->mqenable || IS_QLA83XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002650 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2651 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2652 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2653 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002654 }
2655
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002656 if (IS_QLAFX00(ha)) {
2657 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2658 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2659 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2660 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2661 }
2662
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002663 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002664 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2665 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2666 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2667 }
2668
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002669 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2670 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2671 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2672 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2673 "req->req_q_in=%p req->req_q_out=%p "
2674 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2675 req->req_q_in, req->req_q_out,
2676 rsp->rsp_q_in, rsp->rsp_q_out);
2677 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2678 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2679 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2680 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2681 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2682 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002684 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002685 ql_log(ql_log_fatal, base_vha, 0x00d6,
2686 "Failed to initialize adapter - Adapter flags %x.\n",
2687 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688
Giridhar Malavalia9083012010-04-12 17:59:55 -07002689 if (IS_QLA82XX(ha)) {
2690 qla82xx_idc_lock(ha);
2691 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002692 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002693 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002694 ql_log(ql_log_fatal, base_vha, 0x00d7,
2695 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002696 } else if (IS_QLA8044(ha)) {
2697 qla8044_idc_lock(ha);
2698 qla8044_wr_direct(base_vha,
2699 QLA8044_CRB_DEV_STATE_INDEX,
2700 QLA8XXX_DEV_FAILED);
2701 qla8044_idc_unlock(ha);
2702 ql_log(ql_log_fatal, base_vha, 0x0150,
2703 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002704 }
2705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 ret = -ENODEV;
2707 goto probe_failed;
2708 }
2709
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002710 if (ha->mqenable) {
2711 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002712 ql_log(ql_log_warn, base_vha, 0x00ec,
2713 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002714 goto que_init;
2715 }
2716 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002717
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002718 if (ha->flags.running_gold_fw)
2719 goto skip_dpc;
2720
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 /*
2722 * Startup the kernel thread for this host adapter
2723 */
2724 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002725 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002726 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002727 ql_log(ql_log_fatal, base_vha, 0x00ed,
2728 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002729 ret = PTR_ERR(ha->dpc_thread);
2730 goto probe_failed;
2731 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002732 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2733 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002735 /*
2736 * If we're not coming up in initiator mode, we might sit for
2737 * a while without waking up the dpc thread, which leads to a
2738 * stuck process warning. So just kick the dpc once here and
2739 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2740 */
2741 qla2xxx_wake_dpc(base_vha);
2742
Chad Dupuisf3ddac12013-10-30 03:38:16 -04002743 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
2744
Saurav Kashyap81178772012-08-22 14:21:04 -04002745 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2746 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2747 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2748 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2749
2750 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2751 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2752 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2753 INIT_WORK(&ha->idc_state_handler,
2754 qla83xx_idc_state_handler_work);
2755 INIT_WORK(&ha->nic_core_unrecoverable,
2756 qla83xx_nic_core_unrecoverable_work);
2757 }
2758
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002759skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 list_add_tail(&base_vha->list, &ha->vp_list);
2761 base_vha->host->irq = ha->pdev->irq;
2762
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002765 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2766 "Started qla2x00_timer with "
2767 "interval=%d.\n", WATCH_INTERVAL);
2768 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2769 "Detected hba at address=%p.\n",
2770 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
Arun Easie02587d2011-08-16 11:29:23 -07002772 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002773 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002774 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002775 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002776 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2777 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002778 if (ql2xenabledif == 1)
2779 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002780 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002781 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002782 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002783 | SHOST_DIF_TYPE3_PROTECTION
2784 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002785 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002786 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002787
2788 guard = SHOST_DIX_GUARD_CRC;
2789
2790 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2791 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2792 guard |= SHOST_DIX_GUARD_IP;
2793
2794 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002795 } else
2796 base_vha->flags.difdix_supported = 0;
2797 }
2798
Giridhar Malavalia9083012010-04-12 17:59:55 -07002799 ha->isp_ops->enable_intrs(ha);
2800
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04002801 if (IS_QLAFX00(ha)) {
2802 ret = qlafx00_fx_disc(base_vha,
2803 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2804 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
2805 QLA_SG_ALL : 128;
2806 }
2807
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002808 ret = scsi_add_host(host, &pdev->dev);
2809 if (ret)
2810 goto probe_failed;
2811
Michael Reed14864002009-12-02 09:11:16 -06002812 base_vha->flags.init_done = 1;
2813 base_vha->flags.online = 1;
2814
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002815 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2816 "Init done and hba is online.\n");
2817
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002818 if (qla_ini_mode_enabled(base_vha))
2819 scsi_scan_host(host);
2820 else
2821 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2822 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002823
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002825
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002826 if (IS_QLAFX00(ha)) {
2827 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002828 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2829
2830 /* Register system information */
2831 ret = qlafx00_fx_disc(base_vha,
2832 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2833 }
2834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002838
Armen Baloyan03eb9122013-10-30 03:38:22 -04002839 ql_log(ql_log_info, base_vha, 0x00fb,
2840 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002841 ql_log(ql_log_info, base_vha, 0x00fc,
2842 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2843 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2844 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2845 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002848 qlt_add_target(ha, base_vha);
2849
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 return 0;
2851
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002852probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002853 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002854 ha->req_q_map[0] = NULL;
2855 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002856 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002857 ha->rsp_q_map[0] = NULL;
2858 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002859 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002860
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002862 if (base_vha->timer_active)
2863 qla2x00_stop_timer(base_vha);
2864 base_vha->flags.online = 0;
2865 if (ha->dpc_thread) {
2866 struct task_struct *t = ha->dpc_thread;
2867
2868 ha->dpc_thread = NULL;
2869 kthread_stop(t);
2870 }
2871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002874 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002877 if (IS_QLA82XX(ha)) {
2878 qla82xx_idc_lock(ha);
2879 qla82xx_clear_drv_active(ha);
2880 qla82xx_idc_unlock(ha);
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002881 }
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002882 if (IS_QLA8044(ha)) {
2883 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05002884 qla8044_clear_drv_active(ha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002885 qla8044_idc_unlock(ha);
2886 }
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002887iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002888 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002889 if (!ha->nx_pcibase)
2890 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002891 if (!ql2xdbwr)
2892 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2893 } else {
2894 if (ha->iobase)
2895 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002896 if (ha->cregbase)
2897 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002898 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002899 pci_release_selected_regions(ha->pdev, ha->bars);
2900 kfree(ha);
2901 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002903probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002905 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
Adrian Bunk4c993f72008-01-14 00:55:16 -08002908static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002909qla2x00_shutdown(struct pci_dev *pdev)
2910{
2911 scsi_qla_host_t *vha;
2912 struct qla_hw_data *ha;
2913
Masanari Iida552f3f92013-02-08 01:57:44 -05002914 if (!atomic_read(&pdev->enable_cnt))
2915 return;
2916
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002917 vha = pci_get_drvdata(pdev);
2918 ha = vha->hw;
2919
Armen Baloyan42479342013-08-27 01:37:37 -04002920 /* Notify ISPFX00 firmware */
2921 if (IS_QLAFX00(ha))
2922 qlafx00_driver_shutdown(vha, 20);
2923
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002924 /* Turn-off FCE trace */
2925 if (ha->flags.fce_enabled) {
2926 qla2x00_disable_fce_trace(vha, NULL, NULL);
2927 ha->flags.fce_enabled = 0;
2928 }
2929
2930 /* Turn-off EFT trace */
2931 if (ha->eft)
2932 qla2x00_disable_eft_trace(vha);
2933
2934 /* Stop currently executing firmware. */
2935 qla2x00_try_to_stop_firmware(vha);
2936
2937 /* Turn adapter off line */
2938 vha->flags.online = 0;
2939
2940 /* turn-off interrupts on the card */
2941 if (ha->interrupts_on) {
2942 vha->flags.init_done = 0;
2943 ha->isp_ops->disable_intrs(ha);
2944 }
2945
2946 qla2x00_free_irqs(vha);
2947
2948 qla2x00_free_fw_dump(ha);
2949}
2950
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002951/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002952static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002953qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002955 struct Scsi_Host *scsi_host;
2956 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002957 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
Arun Easi43ebf162011-05-10 11:18:16 -07002959 mutex_lock(&ha->vport_lock);
2960 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07002961 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002962
Arun Easi43ebf162011-05-10 11:18:16 -07002963 BUG_ON(base_vha->list.next == &ha->vp_list);
2964 /* This assumes first entry in ha->vp_list is always base vha */
2965 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002966 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002967
Arun Easi43ebf162011-05-10 11:18:16 -07002968 spin_unlock_irqrestore(&ha->vport_slock, flags);
2969 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002970
Arun Easi43ebf162011-05-10 11:18:16 -07002971 fc_vport_terminate(vha->fc_vport);
2972 scsi_host_put(vha->host);
2973
2974 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 }
Arun Easi43ebf162011-05-10 11:18:16 -07002976 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002977}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002978
Chad Dupuisfe1b8062013-10-30 03:38:15 -04002979/* Stops all deferred work threads */
2980static void
2981qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
2982{
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002983 /* Flush the work queue and remove it */
2984 if (ha->wq) {
2985 flush_workqueue(ha->wq);
2986 destroy_workqueue(ha->wq);
2987 ha->wq = NULL;
2988 }
2989
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002990 /* Cancel all work and destroy DPC workqueues */
2991 if (ha->dpc_lp_wq) {
2992 cancel_work_sync(&ha->idc_aen);
2993 destroy_workqueue(ha->dpc_lp_wq);
2994 ha->dpc_lp_wq = NULL;
2995 }
2996
2997 if (ha->dpc_hp_wq) {
2998 cancel_work_sync(&ha->nic_core_reset);
2999 cancel_work_sync(&ha->idc_state_handler);
3000 cancel_work_sync(&ha->nic_core_unrecoverable);
3001 destroy_workqueue(ha->dpc_hp_wq);
3002 ha->dpc_hp_wq = NULL;
3003 }
3004
Andrew Vasquezb9978762009-03-24 09:08:05 -07003005 /* Kill the kernel thread for this host */
3006 if (ha->dpc_thread) {
3007 struct task_struct *t = ha->dpc_thread;
3008
3009 /*
3010 * qla2xxx_wake_dpc checks for ->dpc_thread
3011 * so we need to zero it out.
3012 */
3013 ha->dpc_thread = NULL;
3014 kthread_stop(t);
3015 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003016}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003017
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003018static void
3019qla2x00_unmap_iobases(struct qla_hw_data *ha)
3020{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003021 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003022
Giridhar Malavalia9083012010-04-12 17:59:55 -07003023 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
3024 if (!ql2xdbwr)
3025 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
3026 } else {
3027 if (ha->iobase)
3028 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003030 if (ha->cregbase)
3031 iounmap(ha->cregbase);
3032
Giridhar Malavalia9083012010-04-12 17:59:55 -07003033 if (ha->mqiobase)
3034 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003035
3036 if (IS_QLA83XX(ha) && ha->msixbase)
3037 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003038 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003039}
3040
3041static void
3042qla2x00_clear_drv_active(scsi_qla_host_t *vha)
3043{
3044 struct qla_hw_data *ha = vha->hw;
3045
3046 if (IS_QLA8044(ha)) {
3047 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003048 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003049 qla8044_idc_unlock(ha);
3050 } else if (IS_QLA82XX(ha)) {
3051 qla82xx_idc_lock(ha);
3052 qla82xx_clear_drv_active(ha);
3053 qla82xx_idc_unlock(ha);
3054 }
3055}
3056
3057static void
3058qla2x00_remove_one(struct pci_dev *pdev)
3059{
3060 scsi_qla_host_t *base_vha;
3061 struct qla_hw_data *ha;
3062
3063 /*
3064 * If the PCI device is disabled that means that probe failed and any
3065 * resources should be have cleaned up on probe exit.
3066 */
3067 if (!atomic_read(&pdev->enable_cnt))
3068 return;
3069
3070 base_vha = pci_get_drvdata(pdev);
3071 ha = base_vha->hw;
3072
3073 set_bit(UNLOADING, &base_vha->dpc_flags);
3074
3075 if (IS_QLAFX00(ha))
3076 qlafx00_driver_shutdown(base_vha, 20);
3077
3078 qla2x00_delete_all_vps(ha, base_vha);
3079
3080 if (IS_QLA8031(ha)) {
3081 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3082 "Clearing fcoe driver presence.\n");
3083 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3084 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3085 "Error while clearing DRV-Presence.\n");
3086 }
3087
3088 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3089
3090 qla2x00_dfs_remove(base_vha);
3091
3092 qla84xx_put_chip(base_vha);
3093
3094 /* Disable timer */
3095 if (base_vha->timer_active)
3096 qla2x00_stop_timer(base_vha);
3097
3098 base_vha->flags.online = 0;
3099
3100 qla2x00_destroy_deferred_work(ha);
3101
3102 qlt_remove_target(ha, base_vha);
3103
3104 qla2x00_free_sysfs_attr(base_vha, true);
3105
3106 fc_remove_host(base_vha->host);
3107
3108 scsi_remove_host(base_vha->host);
3109
3110 qla2x00_free_device(base_vha);
3111
3112 scsi_host_put(base_vha->host);
3113
3114 qla2x00_clear_drv_active(base_vha);
3115
3116 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003117
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 pci_release_selected_regions(ha->pdev, ha->bars);
3119 kfree(ha);
3120 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003122 pci_disable_pcie_error_reporting(pdev);
3123
Bernhard Walle665db932007-03-28 00:49:49 +02003124 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
3127static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
Andrew Vasquez85880802009-12-15 21:29:46 -08003132 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3133
3134 /* Disable timer */
3135 if (vha->timer_active)
3136 qla2x00_stop_timer(vha);
3137
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003138 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003139
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003140 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003142
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003143 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003144 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003145
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003146 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Andrew Vasquez85880802009-12-15 21:29:46 -08003149 vha->flags.online = 0;
3150
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003151 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003152 if (ha->interrupts_on) {
3153 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003154 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003155 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 qla2x00_free_irqs(vha);
3158
Chad Dupuis88670482010-07-23 15:28:30 +05003159 qla2x00_free_fcports(vha);
3160
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003161 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003162
Giridhar Malavali08de2842011-08-16 11:31:44 -07003163 qla82xx_md_free(vha);
3164
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003165 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166}
3167
Chad Dupuis88670482010-07-23 15:28:30 +05003168void qla2x00_free_fcports(struct scsi_qla_host *vha)
3169{
3170 fc_port_t *fcport, *tfcport;
3171
3172 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3173 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003174 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003175 kfree(fcport);
3176 fcport = NULL;
3177 }
3178}
3179
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003180static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003181qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003182 int defer)
3183{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003184 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003185 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003186 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003187
3188 if (!fcport->rport)
3189 return;
3190
3191 rport = fcport->rport;
3192 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003193 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003194 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003195 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003196 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003197 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3198 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003199 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003200 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003201 qlt_fc_port_deleted(vha, fcport);
3202 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003203}
3204
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3207 *
3208 * Input: ha = adapter block pointer. fcport = port structure pointer.
3209 *
3210 * Return: None.
3211 *
3212 * Context:
3213 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003214void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003215 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003217 if (IS_QLAFX00(vha->hw)) {
3218 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3219 qla2x00_schedule_rport_del(vha, fcport, defer);
3220 return;
3221 }
3222
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003223 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003224 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003225 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003226 qla2x00_schedule_rport_del(vha, fcport, defer);
3227 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003228 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 * We may need to retry the login, so don't change the state of the
3230 * port but do the retries.
3231 */
3232 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003233 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
3235 if (!do_login)
3236 return;
3237
3238 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003239 fcport->login_retry = vha->hw->login_retry_count;
3240 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003242 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003243 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3244 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 }
3246}
3247
3248/*
3249 * qla2x00_mark_all_devices_lost
3250 * Updates fcport state when device goes offline.
3251 *
3252 * Input:
3253 * ha = adapter block pointer.
3254 * fcport = port structure pointer.
3255 *
3256 * Return:
3257 * None.
3258 *
3259 * Context:
3260 */
3261void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263{
3264 fc_port_t *fcport;
3265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003267 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003269
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 /*
3271 * No point in marking the device as lost, if the device is
3272 * already DEAD.
3273 */
3274 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3275 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003277 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003278 if (defer)
3279 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003280 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003281 qla2x00_schedule_rport_del(vha, fcport, defer);
3282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 }
3284}
3285
3286/*
3287* qla2x00_mem_alloc
3288* Allocates adapter memory.
3289*
3290* Returns:
3291* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003292* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003294static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003295qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3296 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297{
3298 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
Andrew Vasqueze8711082008-01-31 12:33:48 -08003300 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003302 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003305 if (qlt_mem_alloc(ha) < 0)
3306 goto fail_free_init_cb;
3307
Chad Dupuis642ef982012-02-09 11:15:57 -08003308 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3309 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003311 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312
Andrew Vasqueze8711082008-01-31 12:33:48 -08003313 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3314 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003317 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003318 /* Allocate cache for CT6 Ctx. */
3319 if (!ctx_cachep) {
3320 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3321 sizeof(struct ct6_dsd), 0,
3322 SLAB_HWCACHE_ALIGN, NULL);
3323 if (!ctx_cachep)
3324 goto fail_free_gid_list;
3325 }
3326 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3327 ctx_cachep);
3328 if (!ha->ctx_mempool)
3329 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003330 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3331 "ctx_cachep=%p ctx_mempool=%p.\n",
3332 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003333 }
3334
Andrew Vasqueze8711082008-01-31 12:33:48 -08003335 /* Get memory for cached NVRAM */
3336 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3337 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003338 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3341 ha->pdev->device);
3342 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3343 DMA_POOL_SIZE, 8, 0);
3344 if (!ha->s_dma_pool)
3345 goto fail_free_nvram;
3346
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003347 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3348 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3349 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3350
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003351 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003352 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3353 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3354 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003355 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3356 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003357 goto fail_s_dma_pool;
3358 }
3359
3360 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3361 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3362 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003363 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3364 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003365 goto fail_dl_dma_pool;
3366 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003367 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3368 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3369 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003370 }
3371
Andrew Vasqueze8711082008-01-31 12:33:48 -08003372 /* Allocate memory for SNS commands */
3373 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003375 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003377 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003379 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003380 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003381 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003382 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003383 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003385 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 goto fail_dma_pool;
3387 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003388 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003390 if (!ha->ct_sns)
3391 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003392 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3393 "ms_iocb=%p ct_sns=%p.\n",
3394 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 }
3396
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003398 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3399 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003400 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3401 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 goto fail_req;
3403 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003404 (*req)->length = req_len;
3405 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3406 ((*req)->length + 1) * sizeof(request_t),
3407 &(*req)->dma, GFP_KERNEL);
3408 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003409 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3410 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 goto fail_req_ring;
3412 }
3413 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003414 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3415 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003416 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3417 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 goto fail_rsp;
3419 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003420 (*rsp)->hw = ha;
3421 (*rsp)->length = rsp_len;
3422 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3423 ((*rsp)->length + 1) * sizeof(response_t),
3424 &(*rsp)->dma, GFP_KERNEL);
3425 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003426 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3427 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 goto fail_rsp_ring;
3429 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003430 (*req)->rsp = *rsp;
3431 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003432 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3433 "req=%p req->length=%d req->ring=%p rsp=%p "
3434 "rsp->length=%d rsp->ring=%p.\n",
3435 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3436 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003437 /* Allocate memory for NVRAM data for vports */
3438 if (ha->nvram_npiv_size) {
3439 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003441 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003442 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3443 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003444 goto fail_npiv_info;
3445 }
3446 } else
3447 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003449 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003450 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003451 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3452 &ha->ex_init_cb_dma);
3453 if (!ha->ex_init_cb)
3454 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003455 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3456 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003457 }
3458
Giridhar Malavalia9083012010-04-12 17:59:55 -07003459 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3460
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003461 /* Get consistent memory allocated for Async Port-Database. */
3462 if (!IS_FWI2_CAPABLE(ha)) {
3463 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3464 &ha->async_pd_dma);
3465 if (!ha->async_pd)
3466 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003467 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3468 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003469 }
3470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003471 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003472
3473 /* Allocate memory for our loop_id bitmap */
3474 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3475 GFP_KERNEL);
3476 if (!ha->loop_id_map)
3477 goto fail_async_pd;
3478 else {
3479 qla2x00_set_reserved_loop_ids(ha);
3480 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
3481 "loop_id_map=%p. \n", ha->loop_id_map);
3482 }
3483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 return 1;
3485
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003486fail_async_pd:
3487 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003488fail_ex_init_cb:
3489 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003490fail_npiv_info:
3491 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3492 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3493 (*rsp)->ring = NULL;
3494 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003496 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003498 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3499 sizeof(request_t), (*req)->ring, (*req)->dma);
3500 (*req)->ring = NULL;
3501 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003503 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504fail_req:
3505 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3506 ha->ct_sns, ha->ct_sns_dma);
3507 ha->ct_sns = NULL;
3508 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003509fail_free_ms_iocb:
3510 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3511 ha->ms_iocb = NULL;
3512 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003514 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003515 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3516 ha->fcp_cmnd_dma_pool = NULL;
3517 }
3518fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003519 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003520 dma_pool_destroy(ha->dl_dma_pool);
3521 ha->dl_dma_pool = NULL;
3522 }
3523fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003524 dma_pool_destroy(ha->s_dma_pool);
3525 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003526fail_free_nvram:
3527 kfree(ha->nvram);
3528 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003529fail_free_ctx_mempool:
3530 mempool_destroy(ha->ctx_mempool);
3531 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003532fail_free_srb_mempool:
3533 mempool_destroy(ha->srb_mempool);
3534 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003535fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003536 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3537 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003539 ha->gid_list = NULL;
3540 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003541fail_free_tgt_mem:
3542 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543fail_free_init_cb:
3544 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3545 ha->init_cb_dma);
3546 ha->init_cb = NULL;
3547 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003548fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003549 ql_log(ql_log_fatal, NULL, 0x0030,
3550 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003551 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552}
3553
3554/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003555* qla2x00_free_fw_dump
3556* Frees fw dump stuff.
3557*
3558* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003559* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003560*/
3561static void
3562qla2x00_free_fw_dump(struct qla_hw_data *ha)
3563{
3564 if (ha->fce)
3565 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3566 ha->fce_dma);
3567
3568 if (ha->fw_dump) {
3569 if (ha->eft)
3570 dma_free_coherent(&ha->pdev->dev,
3571 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3572 vfree(ha->fw_dump);
3573 }
3574 ha->fce = NULL;
3575 ha->fce_dma = 0;
3576 ha->eft = NULL;
3577 ha->eft_dma = 0;
3578 ha->fw_dump = NULL;
3579 ha->fw_dumped = 0;
3580 ha->fw_dump_reading = 0;
3581}
3582
3583/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584* qla2x00_mem_free
3585* Frees all adapter allocated memory.
3586*
3587* Input:
3588* ha = adapter block pointer.
3589*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003590static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003593 qla2x00_free_fw_dump(ha);
3594
Saurav Kashyap81178772012-08-22 14:21:04 -04003595 if (ha->mctp_dump)
3596 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3597 ha->mctp_dump_dma);
3598
Andrew Vasqueze8711082008-01-31 12:33:48 -08003599 if (ha->srb_mempool)
3600 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003602 if (ha->dcbx_tlv)
3603 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3604 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3605
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003606 if (ha->xgmac_data)
3607 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3608 ha->xgmac_data, ha->xgmac_data_dma);
3609
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 if (ha->sns_cmd)
3611 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003612 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613
3614 if (ha->ct_sns)
3615 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
Andrew Vasquez88729e52006-06-23 16:10:50 -07003618 if (ha->sfp_data)
3619 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3620
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 if (ha->ms_iocb)
3622 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3623
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003624 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003625 dma_pool_free(ha->s_dma_pool,
3626 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003627
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003628 if (ha->async_pd)
3629 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3630
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 if (ha->s_dma_pool)
3632 dma_pool_destroy(ha->s_dma_pool);
3633
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003635 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3636 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
Giridhar Malavalia9083012010-04-12 17:59:55 -07003638 if (IS_QLA82XX(ha)) {
3639 if (!list_empty(&ha->gbl_dsd_list)) {
3640 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3641
3642 /* clean up allocated prev pool */
3643 list_for_each_entry_safe(dsd_ptr,
3644 tdsd_ptr, &ha->gbl_dsd_list, list) {
3645 dma_pool_free(ha->dl_dma_pool,
3646 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3647 list_del(&dsd_ptr->list);
3648 kfree(dsd_ptr);
3649 }
3650 }
3651 }
3652
3653 if (ha->dl_dma_pool)
3654 dma_pool_destroy(ha->dl_dma_pool);
3655
3656 if (ha->fcp_cmnd_dma_pool)
3657 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3658
3659 if (ha->ctx_mempool)
3660 mempool_destroy(ha->ctx_mempool);
3661
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003662 qlt_mem_free(ha);
3663
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003664 if (ha->init_cb)
3665 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003666 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003667 vfree(ha->optrom_buffer);
3668 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003669 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003670 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003671 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672
Andrew Vasqueze8711082008-01-31 12:33:48 -08003673 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003674 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 ha->sns_cmd = NULL;
3676 ha->sns_cmd_dma = 0;
3677 ha->ct_sns = NULL;
3678 ha->ct_sns_dma = 0;
3679 ha->ms_iocb = NULL;
3680 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 ha->init_cb = NULL;
3682 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003683 ha->ex_init_cb = NULL;
3684 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003685 ha->async_pd = NULL;
3686 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687
3688 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003689 ha->dl_dma_pool = NULL;
3690 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 ha->gid_list = NULL;
3693 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003694
3695 ha->tgt.atio_ring = NULL;
3696 ha->tgt.atio_dma = 0;
3697 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003698}
3699
3700struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3701 struct qla_hw_data *ha)
3702{
3703 struct Scsi_Host *host;
3704 struct scsi_qla_host *vha = NULL;
3705
3706 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3707 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003708 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3709 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003710 goto fail;
3711 }
3712
3713 /* Clear our data area */
3714 vha = shost_priv(host);
3715 memset(vha, 0, sizeof(scsi_qla_host_t));
3716
3717 vha->host = host;
3718 vha->host_no = host->host_no;
3719 vha->hw = ha;
3720
3721 INIT_LIST_HEAD(&vha->vp_fcports);
3722 INIT_LIST_HEAD(&vha->work_list);
3723 INIT_LIST_HEAD(&vha->list);
3724
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003725 spin_lock_init(&vha->work_lock);
3726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003727 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003728 ql_dbg(ql_dbg_init, vha, 0x0041,
3729 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3730 vha->host, vha->hw, vha,
3731 dev_name(&(ha->pdev->dev)));
3732
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003733 return vha;
3734
3735fail:
3736 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737}
3738
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003739static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003740qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003741{
3742 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003743 uint8_t bail;
3744
3745 QLA_VHA_MARK_BUSY(vha, bail);
3746 if (bail)
3747 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003748
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003749 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003750 if (!e) {
3751 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003752 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003753 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003754
3755 INIT_LIST_HEAD(&e->list);
3756 e->type = type;
3757 e->flags = QLA_EVT_FLAG_FREE;
3758 return e;
3759}
3760
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003761static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003762qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003763{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003764 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003765
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003766 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003768 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003769 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003770
Andrew Vasquez0971de72008-04-03 13:13:18 -07003771 return QLA_SUCCESS;
3772}
3773
3774int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003775qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003776 u32 data)
3777{
3778 struct qla_work_evt *e;
3779
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003780 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003781 if (!e)
3782 return QLA_FUNCTION_FAILED;
3783
3784 e->u.aen.code = code;
3785 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003786 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003787}
3788
Andrew Vasquez8a659572009-02-08 20:50:12 -08003789int
3790qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3791{
3792 struct qla_work_evt *e;
3793
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003794 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003795 if (!e)
3796 return QLA_FUNCTION_FAILED;
3797
3798 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003799 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003800}
3801
Andrew Vasquezac280b62009-08-20 11:06:05 -07003802#define qla2x00_post_async_work(name, type) \
3803int qla2x00_post_async_##name##_work( \
3804 struct scsi_qla_host *vha, \
3805 fc_port_t *fcport, uint16_t *data) \
3806{ \
3807 struct qla_work_evt *e; \
3808 \
3809 e = qla2x00_alloc_work(vha, type); \
3810 if (!e) \
3811 return QLA_FUNCTION_FAILED; \
3812 \
3813 e->u.logio.fcport = fcport; \
3814 if (data) { \
3815 e->u.logio.data[0] = data[0]; \
3816 e->u.logio.data[1] = data[1]; \
3817 } \
3818 return qla2x00_post_work(vha, e); \
3819}
3820
3821qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3822qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3823qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3824qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003825qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3826qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003827
Andrew Vasquez3420d362009-10-13 15:16:45 -07003828int
3829qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3830{
3831 struct qla_work_evt *e;
3832
3833 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3834 if (!e)
3835 return QLA_FUNCTION_FAILED;
3836
3837 e->u.uevent.code = code;
3838 return qla2x00_post_work(vha, e);
3839}
3840
3841static void
3842qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3843{
3844 char event_string[40];
3845 char *envp[] = { event_string, NULL };
3846
3847 switch (code) {
3848 case QLA_UEVENT_CODE_FW_DUMP:
3849 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3850 vha->host_no);
3851 break;
3852 default:
3853 /* do nothing */
3854 break;
3855 }
3856 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3857}
3858
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003859int
3860qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
3861 uint32_t *data, int cnt)
3862{
3863 struct qla_work_evt *e;
3864
3865 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
3866 if (!e)
3867 return QLA_FUNCTION_FAILED;
3868
3869 e->u.aenfx.evtcode = evtcode;
3870 e->u.aenfx.count = cnt;
3871 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
3872 return qla2x00_post_work(vha, e);
3873}
3874
Andrew Vasquezac280b62009-08-20 11:06:05 -07003875void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003876qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003877{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003878 struct qla_work_evt *e, *tmp;
3879 unsigned long flags;
3880 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003881
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003882 spin_lock_irqsave(&vha->work_lock, flags);
3883 list_splice_init(&vha->work_list, &work);
3884 spin_unlock_irqrestore(&vha->work_lock, flags);
3885
3886 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003887 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003888
3889 switch (e->type) {
3890 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003891 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003892 e->u.aen.code, e->u.aen.data);
3893 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003894 case QLA_EVT_IDC_ACK:
3895 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3896 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003897 case QLA_EVT_ASYNC_LOGIN:
3898 qla2x00_async_login(vha, e->u.logio.fcport,
3899 e->u.logio.data);
3900 break;
3901 case QLA_EVT_ASYNC_LOGIN_DONE:
3902 qla2x00_async_login_done(vha, e->u.logio.fcport,
3903 e->u.logio.data);
3904 break;
3905 case QLA_EVT_ASYNC_LOGOUT:
3906 qla2x00_async_logout(vha, e->u.logio.fcport);
3907 break;
3908 case QLA_EVT_ASYNC_LOGOUT_DONE:
3909 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3910 e->u.logio.data);
3911 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003912 case QLA_EVT_ASYNC_ADISC:
3913 qla2x00_async_adisc(vha, e->u.logio.fcport,
3914 e->u.logio.data);
3915 break;
3916 case QLA_EVT_ASYNC_ADISC_DONE:
3917 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3918 e->u.logio.data);
3919 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003920 case QLA_EVT_UEVENT:
3921 qla2x00_uevent_emit(vha, e->u.uevent.code);
3922 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003923 case QLA_EVT_AENFX:
3924 qlafx00_process_aen(vha, e);
3925 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003926 }
3927 if (e->flags & QLA_EVT_FLAG_FREE)
3928 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003929
3930 /* For each work completed decrement vha ref count */
3931 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003932 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003933}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935/* Relogins all the fcports of a vport
3936 * Context: dpc thread
3937 */
3938void qla2x00_relogin(struct scsi_qla_host *vha)
3939{
3940 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003941 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003942 uint16_t next_loopid = 0;
3943 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003944 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003945
3946 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3947 /*
3948 * If the port is not ONLINE then try to login
3949 * to it if we haven't run out of retries.
3950 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003951 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3952 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003953 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003954 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003955 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956 ha->isp_ops->fabric_logout(vha,
3957 fcport->loop_id,
3958 fcport->d_id.b.domain,
3959 fcport->d_id.b.area,
3960 fcport->d_id.b.al_pa);
3961
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003962 if (fcport->loop_id == FC_NO_LOOP_ID) {
3963 fcport->loop_id = next_loopid =
3964 ha->min_external_loopid;
3965 status = qla2x00_find_new_loop_id(
3966 vha, fcport);
3967 if (status != QLA_SUCCESS) {
3968 /* Ran out of IDs to use */
3969 break;
3970 }
3971 }
3972
Andrew Vasquezac280b62009-08-20 11:06:05 -07003973 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003974 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003975 data[0] = 0;
3976 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3977 status = qla2x00_post_async_login_work(
3978 vha, fcport, data);
3979 if (status == QLA_SUCCESS)
3980 continue;
3981 /* Attempt a retry. */
3982 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003983 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003984 status = qla2x00_fabric_login(vha,
3985 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003986 if (status == QLA_SUCCESS) {
3987 int status2;
3988 uint8_t opts;
3989
3990 opts = 0;
3991 if (fcport->flags &
3992 FCF_FCP2_DEVICE)
3993 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05003994 status2 =
3995 qla2x00_get_port_database(
3996 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003997 if (status2 != QLA_SUCCESS)
3998 status = 1;
3999 }
4000 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001 } else
4002 status = qla2x00_local_device_login(vha,
4003 fcport);
4004
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 if (status == QLA_SUCCESS) {
4006 fcport->old_loop_id = fcport->loop_id;
4007
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004008 ql_dbg(ql_dbg_disc, vha, 0x2003,
4009 "Port login OK: logged in ID 0x%x.\n",
4010 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004011
4012 qla2x00_update_fcport(vha, fcport);
4013
4014 } else if (status == 1) {
4015 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4016 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004017 ql_dbg(ql_dbg_disc, vha, 0x2007,
4018 "Retrying %d login again loop_id 0x%x.\n",
4019 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 } else {
4021 fcport->login_retry = 0;
4022 }
4023
4024 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004025 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 }
4027 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4028 break;
4029 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004030}
4031
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004032/* Schedule work on any of the dpc-workqueues */
4033void
4034qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4035{
4036 struct qla_hw_data *ha = base_vha->hw;
4037
4038 switch (work_code) {
4039 case MBA_IDC_AEN: /* 0x8200 */
4040 if (ha->dpc_lp_wq)
4041 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4042 break;
4043
4044 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4045 if (!ha->flags.nic_core_reset_hdlr_active) {
4046 if (ha->dpc_hp_wq)
4047 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4048 } else
4049 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4050 "NIC Core reset is already active. Skip "
4051 "scheduling it again.\n");
4052 break;
4053 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4054 if (ha->dpc_hp_wq)
4055 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4056 break;
4057 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4058 if (ha->dpc_hp_wq)
4059 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4060 break;
4061 default:
4062 ql_log(ql_log_warn, base_vha, 0xb05f,
4063 "Unknow work-code=0x%x.\n", work_code);
4064 }
4065
4066 return;
4067}
4068
4069/* Work: Perform NIC Core Unrecoverable state handling */
4070void
4071qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4072{
4073 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004074 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004075 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4076 uint32_t dev_state = 0;
4077
4078 qla83xx_idc_lock(base_vha, 0);
4079 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4080 qla83xx_reset_ownership(base_vha);
4081 if (ha->flags.nic_core_reset_owner) {
4082 ha->flags.nic_core_reset_owner = 0;
4083 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4084 QLA8XXX_DEV_FAILED);
4085 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4086 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4087 }
4088 qla83xx_idc_unlock(base_vha, 0);
4089}
4090
4091/* Work: Execute IDC state handler */
4092void
4093qla83xx_idc_state_handler_work(struct work_struct *work)
4094{
4095 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004096 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004097 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4098 uint32_t dev_state = 0;
4099
4100 qla83xx_idc_lock(base_vha, 0);
4101 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4102 if (dev_state == QLA8XXX_DEV_FAILED ||
4103 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4104 qla83xx_idc_state_handler(base_vha);
4105 qla83xx_idc_unlock(base_vha, 0);
4106}
4107
Saurav Kashyapfa492632012-11-21 02:40:29 -05004108static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004109qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4110{
4111 int rval = QLA_SUCCESS;
4112 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4113 uint32_t heart_beat_counter1, heart_beat_counter2;
4114
4115 do {
4116 if (time_after(jiffies, heart_beat_wait)) {
4117 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4118 "Nic Core f/w is not alive.\n");
4119 rval = QLA_FUNCTION_FAILED;
4120 break;
4121 }
4122
4123 qla83xx_idc_lock(base_vha, 0);
4124 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4125 &heart_beat_counter1);
4126 qla83xx_idc_unlock(base_vha, 0);
4127 msleep(100);
4128 qla83xx_idc_lock(base_vha, 0);
4129 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4130 &heart_beat_counter2);
4131 qla83xx_idc_unlock(base_vha, 0);
4132 } while (heart_beat_counter1 == heart_beat_counter2);
4133
4134 return rval;
4135}
4136
4137/* Work: Perform NIC Core Reset handling */
4138void
4139qla83xx_nic_core_reset_work(struct work_struct *work)
4140{
4141 struct qla_hw_data *ha =
4142 container_of(work, struct qla_hw_data, nic_core_reset);
4143 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4144 uint32_t dev_state = 0;
4145
Saurav Kashyap81178772012-08-22 14:21:04 -04004146 if (IS_QLA2031(ha)) {
4147 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4148 ql_log(ql_log_warn, base_vha, 0xb081,
4149 "Failed to dump mctp\n");
4150 return;
4151 }
4152
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004153 if (!ha->flags.nic_core_reset_hdlr_active) {
4154 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4155 qla83xx_idc_lock(base_vha, 0);
4156 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4157 &dev_state);
4158 qla83xx_idc_unlock(base_vha, 0);
4159 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4160 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4161 "Nic Core f/w is alive.\n");
4162 return;
4163 }
4164 }
4165
4166 ha->flags.nic_core_reset_hdlr_active = 1;
4167 if (qla83xx_nic_core_reset(base_vha)) {
4168 /* NIC Core reset failed. */
4169 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4170 "NIC Core reset failed.\n");
4171 }
4172 ha->flags.nic_core_reset_hdlr_active = 0;
4173 }
4174}
4175
4176/* Work: Handle 8200 IDC aens */
4177void
4178qla83xx_service_idc_aen(struct work_struct *work)
4179{
4180 struct qla_hw_data *ha =
4181 container_of(work, struct qla_hw_data, idc_aen);
4182 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4183 uint32_t dev_state, idc_control;
4184
4185 qla83xx_idc_lock(base_vha, 0);
4186 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4187 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4188 qla83xx_idc_unlock(base_vha, 0);
4189 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4190 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4191 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4192 "Application requested NIC Core Reset.\n");
4193 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4194 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4195 QLA_SUCCESS) {
4196 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4197 "Other protocol driver requested NIC Core Reset.\n");
4198 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4199 }
4200 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4201 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4202 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4203 }
4204}
4205
4206static void
4207qla83xx_wait_logic(void)
4208{
4209 int i;
4210
4211 /* Yield CPU */
4212 if (!in_interrupt()) {
4213 /*
4214 * Wait about 200ms before retrying again.
4215 * This controls the number of retries for single
4216 * lock operation.
4217 */
4218 msleep(100);
4219 schedule();
4220 } else {
4221 for (i = 0; i < 20; i++)
4222 cpu_relax(); /* This a nop instr on i386 */
4223 }
4224}
4225
Saurav Kashyapfa492632012-11-21 02:40:29 -05004226static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004227qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4228{
4229 int rval;
4230 uint32_t data;
4231 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4232 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4233 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004234 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4235 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004236
4237 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4238 if (rval)
4239 return rval;
4240
4241 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4242 return QLA_SUCCESS;
4243 } else {
4244 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4245 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4246 data);
4247 if (rval)
4248 return rval;
4249
4250 msleep(200);
4251
4252 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4253 &data);
4254 if (rval)
4255 return rval;
4256
4257 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4258 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4259 ~(idc_lck_rcvry_stage_mask));
4260 rval = qla83xx_wr_reg(base_vha,
4261 QLA83XX_IDC_LOCK_RECOVERY, data);
4262 if (rval)
4263 return rval;
4264
4265 /* Forcefully perform IDC UnLock */
4266 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4267 &data);
4268 if (rval)
4269 return rval;
4270 /* Clear lock-id by setting 0xff */
4271 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4272 0xff);
4273 if (rval)
4274 return rval;
4275 /* Clear lock-recovery by setting 0x0 */
4276 rval = qla83xx_wr_reg(base_vha,
4277 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4278 if (rval)
4279 return rval;
4280 } else
4281 return QLA_SUCCESS;
4282 }
4283
4284 return rval;
4285}
4286
Saurav Kashyapfa492632012-11-21 02:40:29 -05004287static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004288qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4289{
4290 int rval = QLA_SUCCESS;
4291 uint32_t o_drv_lockid, n_drv_lockid;
4292 unsigned long lock_recovery_timeout;
4293
4294 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4295retry_lockid:
4296 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4297 if (rval)
4298 goto exit;
4299
4300 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4301 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4302 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4303 return QLA_SUCCESS;
4304 else
4305 return QLA_FUNCTION_FAILED;
4306 }
4307
4308 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4309 if (rval)
4310 goto exit;
4311
4312 if (o_drv_lockid == n_drv_lockid) {
4313 qla83xx_wait_logic();
4314 goto retry_lockid;
4315 } else
4316 return QLA_SUCCESS;
4317
4318exit:
4319 return rval;
4320}
4321
4322void
4323qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4324{
4325 uint16_t options = (requester_id << 15) | BIT_6;
4326 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004327 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004328 struct qla_hw_data *ha = base_vha->hw;
4329
4330 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4331retry_lock:
4332 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4333 == QLA_SUCCESS) {
4334 if (data) {
4335 /* Setting lock-id to our function-number */
4336 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4337 ha->portnum);
4338 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004339 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4340 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004341 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004342 "Failed to acquire IDC lock, acquired by %d, "
4343 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004344
4345 /* Retry/Perform IDC-Lock recovery */
4346 if (qla83xx_idc_lock_recovery(base_vha)
4347 == QLA_SUCCESS) {
4348 qla83xx_wait_logic();
4349 goto retry_lock;
4350 } else
4351 ql_log(ql_log_warn, base_vha, 0xb075,
4352 "IDC Lock recovery FAILED.\n");
4353 }
4354
4355 }
4356
4357 return;
4358
4359 /* XXX: IDC-lock implementation using access-control mbx */
4360retry_lock2:
4361 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4362 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4363 "Failed to acquire IDC lock. retrying...\n");
4364 /* Retry/Perform IDC-Lock recovery */
4365 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4366 qla83xx_wait_logic();
4367 goto retry_lock2;
4368 } else
4369 ql_log(ql_log_warn, base_vha, 0xb076,
4370 "IDC Lock recovery FAILED.\n");
4371 }
4372
4373 return;
4374}
4375
4376void
4377qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4378{
4379 uint16_t options = (requester_id << 15) | BIT_7, retry;
4380 uint32_t data;
4381 struct qla_hw_data *ha = base_vha->hw;
4382
4383 /* IDC-unlock implementation using driver-unlock/lock-id
4384 * remote registers
4385 */
4386 retry = 0;
4387retry_unlock:
4388 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4389 == QLA_SUCCESS) {
4390 if (data == ha->portnum) {
4391 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4392 /* Clearing lock-id by setting 0xff */
4393 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4394 } else if (retry < 10) {
4395 /* SV: XXX: IDC unlock retrying needed here? */
4396
4397 /* Retry for IDC-unlock */
4398 qla83xx_wait_logic();
4399 retry++;
4400 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4401 "Failed to release IDC lock, retyring=%d\n", retry);
4402 goto retry_unlock;
4403 }
4404 } else if (retry < 10) {
4405 /* Retry for IDC-unlock */
4406 qla83xx_wait_logic();
4407 retry++;
4408 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4409 "Failed to read drv-lockid, retyring=%d\n", retry);
4410 goto retry_unlock;
4411 }
4412
4413 return;
4414
4415 /* XXX: IDC-unlock implementation using access-control mbx */
4416 retry = 0;
4417retry_unlock2:
4418 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4419 if (retry < 10) {
4420 /* Retry for IDC-unlock */
4421 qla83xx_wait_logic();
4422 retry++;
4423 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4424 "Failed to release IDC lock, retyring=%d\n", retry);
4425 goto retry_unlock2;
4426 }
4427 }
4428
4429 return;
4430}
4431
4432int
4433__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4434{
4435 int rval = QLA_SUCCESS;
4436 struct qla_hw_data *ha = vha->hw;
4437 uint32_t drv_presence;
4438
4439 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4440 if (rval == QLA_SUCCESS) {
4441 drv_presence |= (1 << ha->portnum);
4442 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4443 drv_presence);
4444 }
4445
4446 return rval;
4447}
4448
4449int
4450qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4451{
4452 int rval = QLA_SUCCESS;
4453
4454 qla83xx_idc_lock(vha, 0);
4455 rval = __qla83xx_set_drv_presence(vha);
4456 qla83xx_idc_unlock(vha, 0);
4457
4458 return rval;
4459}
4460
4461int
4462__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4463{
4464 int rval = QLA_SUCCESS;
4465 struct qla_hw_data *ha = vha->hw;
4466 uint32_t drv_presence;
4467
4468 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4469 if (rval == QLA_SUCCESS) {
4470 drv_presence &= ~(1 << ha->portnum);
4471 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4472 drv_presence);
4473 }
4474
4475 return rval;
4476}
4477
4478int
4479qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4480{
4481 int rval = QLA_SUCCESS;
4482
4483 qla83xx_idc_lock(vha, 0);
4484 rval = __qla83xx_clear_drv_presence(vha);
4485 qla83xx_idc_unlock(vha, 0);
4486
4487 return rval;
4488}
4489
Saurav Kashyapfa492632012-11-21 02:40:29 -05004490static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004491qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4492{
4493 struct qla_hw_data *ha = vha->hw;
4494 uint32_t drv_ack, drv_presence;
4495 unsigned long ack_timeout;
4496
4497 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4498 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4499 while (1) {
4500 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4501 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004502 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004503 break;
4504
4505 if (time_after_eq(jiffies, ack_timeout)) {
4506 ql_log(ql_log_warn, vha, 0xb067,
4507 "RESET ACK TIMEOUT! drv_presence=0x%x "
4508 "drv_ack=0x%x\n", drv_presence, drv_ack);
4509 /*
4510 * The function(s) which did not ack in time are forced
4511 * to withdraw any further participation in the IDC
4512 * reset.
4513 */
4514 if (drv_ack != drv_presence)
4515 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4516 drv_ack);
4517 break;
4518 }
4519
4520 qla83xx_idc_unlock(vha, 0);
4521 msleep(1000);
4522 qla83xx_idc_lock(vha, 0);
4523 }
4524
4525 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4526 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4527}
4528
Saurav Kashyapfa492632012-11-21 02:40:29 -05004529static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004530qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4531{
4532 int rval = QLA_SUCCESS;
4533 uint32_t idc_control;
4534
4535 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4536 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4537
4538 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4539 __qla83xx_get_idc_control(vha, &idc_control);
4540 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4541 __qla83xx_set_idc_control(vha, 0);
4542
4543 qla83xx_idc_unlock(vha, 0);
4544 rval = qla83xx_restart_nic_firmware(vha);
4545 qla83xx_idc_lock(vha, 0);
4546
4547 if (rval != QLA_SUCCESS) {
4548 ql_log(ql_log_fatal, vha, 0xb06a,
4549 "Failed to restart NIC f/w.\n");
4550 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4551 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4552 } else {
4553 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4554 "Success in restarting nic f/w.\n");
4555 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4556 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4557 }
4558
4559 return rval;
4560}
4561
4562/* Assumes idc_lock always held on entry */
4563int
4564qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4565{
4566 struct qla_hw_data *ha = base_vha->hw;
4567 int rval = QLA_SUCCESS;
4568 unsigned long dev_init_timeout;
4569 uint32_t dev_state;
4570
4571 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4572 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4573
4574 while (1) {
4575
4576 if (time_after_eq(jiffies, dev_init_timeout)) {
4577 ql_log(ql_log_warn, base_vha, 0xb06e,
4578 "Initialization TIMEOUT!\n");
4579 /* Init timeout. Disable further NIC Core
4580 * communication.
4581 */
4582 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4583 QLA8XXX_DEV_FAILED);
4584 ql_log(ql_log_info, base_vha, 0xb06f,
4585 "HW State: FAILED.\n");
4586 }
4587
4588 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4589 switch (dev_state) {
4590 case QLA8XXX_DEV_READY:
4591 if (ha->flags.nic_core_reset_owner)
4592 qla83xx_idc_audit(base_vha,
4593 IDC_AUDIT_COMPLETION);
4594 ha->flags.nic_core_reset_owner = 0;
4595 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4596 "Reset_owner reset by 0x%x.\n",
4597 ha->portnum);
4598 goto exit;
4599 case QLA8XXX_DEV_COLD:
4600 if (ha->flags.nic_core_reset_owner)
4601 rval = qla83xx_device_bootstrap(base_vha);
4602 else {
4603 /* Wait for AEN to change device-state */
4604 qla83xx_idc_unlock(base_vha, 0);
4605 msleep(1000);
4606 qla83xx_idc_lock(base_vha, 0);
4607 }
4608 break;
4609 case QLA8XXX_DEV_INITIALIZING:
4610 /* Wait for AEN to change device-state */
4611 qla83xx_idc_unlock(base_vha, 0);
4612 msleep(1000);
4613 qla83xx_idc_lock(base_vha, 0);
4614 break;
4615 case QLA8XXX_DEV_NEED_RESET:
4616 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4617 qla83xx_need_reset_handler(base_vha);
4618 else {
4619 /* Wait for AEN to change device-state */
4620 qla83xx_idc_unlock(base_vha, 0);
4621 msleep(1000);
4622 qla83xx_idc_lock(base_vha, 0);
4623 }
4624 /* reset timeout value after need reset handler */
4625 dev_init_timeout = jiffies +
4626 (ha->fcoe_dev_init_timeout * HZ);
4627 break;
4628 case QLA8XXX_DEV_NEED_QUIESCENT:
4629 /* XXX: DEBUG for now */
4630 qla83xx_idc_unlock(base_vha, 0);
4631 msleep(1000);
4632 qla83xx_idc_lock(base_vha, 0);
4633 break;
4634 case QLA8XXX_DEV_QUIESCENT:
4635 /* XXX: DEBUG for now */
4636 if (ha->flags.quiesce_owner)
4637 goto exit;
4638
4639 qla83xx_idc_unlock(base_vha, 0);
4640 msleep(1000);
4641 qla83xx_idc_lock(base_vha, 0);
4642 dev_init_timeout = jiffies +
4643 (ha->fcoe_dev_init_timeout * HZ);
4644 break;
4645 case QLA8XXX_DEV_FAILED:
4646 if (ha->flags.nic_core_reset_owner)
4647 qla83xx_idc_audit(base_vha,
4648 IDC_AUDIT_COMPLETION);
4649 ha->flags.nic_core_reset_owner = 0;
4650 __qla83xx_clear_drv_presence(base_vha);
4651 qla83xx_idc_unlock(base_vha, 0);
4652 qla8xxx_dev_failed_handler(base_vha);
4653 rval = QLA_FUNCTION_FAILED;
4654 qla83xx_idc_lock(base_vha, 0);
4655 goto exit;
4656 case QLA8XXX_BAD_VALUE:
4657 qla83xx_idc_unlock(base_vha, 0);
4658 msleep(1000);
4659 qla83xx_idc_lock(base_vha, 0);
4660 break;
4661 default:
4662 ql_log(ql_log_warn, base_vha, 0xb071,
4663 "Unknow Device State: %x.\n", dev_state);
4664 qla83xx_idc_unlock(base_vha, 0);
4665 qla8xxx_dev_failed_handler(base_vha);
4666 rval = QLA_FUNCTION_FAILED;
4667 qla83xx_idc_lock(base_vha, 0);
4668 goto exit;
4669 }
4670 }
4671
4672exit:
4673 return rval;
4674}
4675
Chad Dupuisf3ddac12013-10-30 03:38:16 -04004676void
4677qla2x00_disable_board_on_pci_error(struct work_struct *work)
4678{
4679 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
4680 board_disable);
4681 struct pci_dev *pdev = ha->pdev;
4682 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4683
4684 ql_log(ql_log_warn, base_vha, 0x015b,
4685 "Disabling adapter.\n");
4686
4687 set_bit(UNLOADING, &base_vha->dpc_flags);
4688
4689 qla2x00_delete_all_vps(ha, base_vha);
4690
4691 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4692
4693 qla2x00_dfs_remove(base_vha);
4694
4695 qla84xx_put_chip(base_vha);
4696
4697 if (base_vha->timer_active)
4698 qla2x00_stop_timer(base_vha);
4699
4700 base_vha->flags.online = 0;
4701
4702 qla2x00_destroy_deferred_work(ha);
4703
4704 /*
4705 * Do not try to stop beacon blink as it will issue a mailbox
4706 * command.
4707 */
4708 qla2x00_free_sysfs_attr(base_vha, false);
4709
4710 fc_remove_host(base_vha->host);
4711
4712 scsi_remove_host(base_vha->host);
4713
4714 base_vha->flags.init_done = 0;
4715 qla25xx_delete_queues(base_vha);
4716 qla2x00_free_irqs(base_vha);
4717 qla2x00_free_fcports(base_vha);
4718 qla2x00_mem_free(ha);
4719 qla82xx_md_free(base_vha);
4720 qla2x00_free_queues(ha);
4721
4722 scsi_host_put(base_vha->host);
4723
4724 qla2x00_unmap_iobases(ha);
4725
4726 pci_release_selected_regions(ha->pdev, ha->bars);
4727 kfree(ha);
4728 ha = NULL;
4729
4730 pci_disable_pcie_error_reporting(pdev);
4731 pci_disable_device(pdev);
4732 pci_set_drvdata(pdev, NULL);
4733
4734}
4735
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736/**************************************************************************
4737* qla2x00_do_dpc
4738* This kernel thread is a task that is schedule by the interrupt handler
4739* to perform the background processing for interrupts.
4740*
4741* Notes:
4742* This task always run in the context of a kernel thread. It
4743* is kick-off by the driver's detect code and starts up
4744* up one per adapter. It immediately goes to sleep and waits for
4745* some fibre event. When either the interrupt handler or
4746* the timer routine detects a event it will one of the task
4747* bits then wake us up.
4748**************************************************************************/
4749static int
4750qla2x00_do_dpc(void *data)
4751{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004752 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004753 scsi_qla_host_t *base_vha;
4754 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004755
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004756 ha = (struct qla_hw_data *)data;
4757 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 set_user_nice(current, -20);
4760
James Bottomley563585e2011-01-27 16:12:37 -05004761 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004762 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004763 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4764 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765
Christoph Hellwig39a11242006-02-14 18:46:22 +01004766 schedule();
4767 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004769 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4770 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771
Andrew Vasquez85880802009-12-15 21:29:46 -08004772 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004773 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4774 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004775 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004776 }
4777
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 ha->dpc_active = 1;
4779
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004780 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4781 "DPC handler waking up, dpc_flags=0x%lx.\n",
4782 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004784 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004785
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004786 if (IS_P3P_TYPE(ha)) {
4787 if (IS_QLA8044(ha)) {
4788 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4789 &base_vha->dpc_flags)) {
4790 qla8044_idc_lock(ha);
4791 qla8044_wr_direct(base_vha,
4792 QLA8044_CRB_DEV_STATE_INDEX,
4793 QLA8XXX_DEV_FAILED);
4794 qla8044_idc_unlock(ha);
4795 ql_log(ql_log_info, base_vha, 0x4004,
4796 "HW State: FAILED.\n");
4797 qla8044_device_state_handler(base_vha);
4798 continue;
4799 }
4800
4801 } else {
4802 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4803 &base_vha->dpc_flags)) {
4804 qla82xx_idc_lock(ha);
4805 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4806 QLA8XXX_DEV_FAILED);
4807 qla82xx_idc_unlock(ha);
4808 ql_log(ql_log_info, base_vha, 0x0151,
4809 "HW State: FAILED.\n");
4810 qla82xx_device_state_handler(base_vha);
4811 continue;
4812 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004813 }
4814
4815 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4816 &base_vha->dpc_flags)) {
4817
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004818 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4819 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004820 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4821 &base_vha->dpc_flags))) {
4822 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4823 /* FCoE-ctx reset failed.
4824 * Escalate to chip-reset
4825 */
4826 set_bit(ISP_ABORT_NEEDED,
4827 &base_vha->dpc_flags);
4828 }
4829 clear_bit(ABORT_ISP_ACTIVE,
4830 &base_vha->dpc_flags);
4831 }
4832
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004833 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4834 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004835 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004836 } else if (IS_QLAFX00(ha)) {
4837 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4838 &base_vha->dpc_flags)) {
4839 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
4840 "Firmware Reset Recovery\n");
4841 if (qlafx00_reset_initialize(base_vha)) {
4842 /* Failed. Abort isp later. */
4843 if (!test_bit(UNLOADING,
4844 &base_vha->dpc_flags))
4845 set_bit(ISP_UNRECOVERABLE,
4846 &base_vha->dpc_flags);
4847 ql_dbg(ql_dbg_dpc, base_vha,
4848 0x4021,
4849 "Reset Recovery Failed\n");
4850 }
4851 }
4852
4853 if (test_and_clear_bit(FX00_TARGET_SCAN,
4854 &base_vha->dpc_flags)) {
4855 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
4856 "ISPFx00 Target Scan scheduled\n");
4857 if (qlafx00_rescan_isp(base_vha)) {
4858 if (!test_bit(UNLOADING,
4859 &base_vha->dpc_flags))
4860 set_bit(ISP_UNRECOVERABLE,
4861 &base_vha->dpc_flags);
4862 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
4863 "ISPFx00 Target Scan Failed\n");
4864 }
4865 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
4866 "ISPFx00 Target Scan End\n");
4867 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04004868 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
4869 &base_vha->dpc_flags)) {
4870 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
4871 "ISPFx00 Host Info resend scheduled\n");
4872 qlafx00_fx_disc(base_vha,
4873 &base_vha->hw->mr.fcport,
4874 FXDISC_REG_HOST_INFO);
4875 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004876 }
4877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004878 if (test_and_clear_bit(ISP_ABORT_NEEDED,
4879 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004881 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
4882 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885
Giridhar Malavalia9083012010-04-12 17:59:55 -07004886 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 /* failed. retry later */
4888 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004889 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004891 clear_bit(ABORT_ISP_ACTIVE,
4892 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08004893 }
4894
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004895 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
4896 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 }
4898
David Jefferya394aac2012-11-21 02:39:54 -05004899 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
4900 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07004902 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004903
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004904 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
4905 int ret;
4906 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
4907 if (ret != QLA_SUCCESS)
4908 ql_log(ql_log_warn, base_vha, 0x121,
4909 "Failed to enable receiving of RSCN "
4910 "requests: 0x%x.\n", ret);
4911 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
4912 }
4913
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004914 if (IS_QLAFX00(ha))
4915 goto loop_resync_check;
4916
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004917 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004918 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
4919 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004920 if (IS_P3P_TYPE(ha)) {
4921 if (IS_QLA82XX(ha))
4922 qla82xx_device_state_handler(base_vha);
4923 if (IS_QLA8044(ha))
4924 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004925 clear_bit(ISP_QUIESCE_NEEDED,
4926 &base_vha->dpc_flags);
4927 if (!ha->flags.quiesce_owner) {
4928 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004929 if (IS_QLA82XX(ha)) {
4930 qla82xx_idc_lock(ha);
4931 qla82xx_clear_qsnt_ready(
4932 base_vha);
4933 qla82xx_idc_unlock(ha);
4934 } else if (IS_QLA8044(ha)) {
4935 qla8044_idc_lock(ha);
4936 qla8044_clear_qsnt_ready(
4937 base_vha);
4938 qla8044_idc_unlock(ha);
4939 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004940 }
4941 } else {
4942 clear_bit(ISP_QUIESCE_NEEDED,
4943 &base_vha->dpc_flags);
4944 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004945 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004946 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
4947 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004948 }
4949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004950 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004951 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004952 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004954 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
4955 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004956 qla2x00_rst_aen(base_vha);
4957 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004958 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
4959 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 }
4961
4962 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004963 if ((test_and_clear_bit(RELOGIN_NEEDED,
4964 &base_vha->dpc_flags)) &&
4965 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
4966 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004968 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
4969 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004970 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004971 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
4972 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004974loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004975 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004976 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004978 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
4979 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
4981 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004982 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004984 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004986 clear_bit(LOOP_RESYNC_ACTIVE,
4987 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 }
4989
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004990 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
4991 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 }
4993
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004994 if (IS_QLAFX00(ha))
4995 goto intr_on_check;
4996
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004997 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
4998 atomic_read(&base_vha->loop_state) == LOOP_READY) {
4999 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5000 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005001 }
5002
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005003intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005005 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005007 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
5008 &base_vha->dpc_flags))
5009 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005010
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005011 if (!IS_QLAFX00(ha))
5012 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005013
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005015end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005016 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005018 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005020 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5021 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022
5023 /*
5024 * Make sure that nobody tries to wake us up again.
5025 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 ha->dpc_active = 0;
5027
Andrew Vasquezac280b62009-08-20 11:06:05 -07005028 /* Cleanup any residual CTX SRBs. */
5029 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5030
Christoph Hellwig39a11242006-02-14 18:46:22 +01005031 return 0;
5032}
5033
5034void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005035qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005036{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005037 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005038 struct task_struct *t = ha->dpc_thread;
5039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005040 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005041 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042}
5043
5044/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045* qla2x00_rst_aen
5046* Processes asynchronous reset.
5047*
5048* Input:
5049* ha = adapter block pointer.
5050*/
5051static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005052qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005054 if (vha->flags.online && !vha->flags.reset_active &&
5055 !atomic_read(&vha->loop_down_timer) &&
5056 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005058 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059
5060 /*
5061 * Issue marker command only when we are going to start
5062 * the I/O.
5063 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005064 vha->marker_needed = 1;
5065 } while (!atomic_read(&vha->loop_down_timer) &&
5066 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 }
5068}
5069
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070/**************************************************************************
5071* qla2x00_timer
5072*
5073* Description:
5074* One second timer
5075*
5076* Context: Interrupt
5077***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005078void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005079qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 int start_dpc = 0;
5083 int index;
5084 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005085 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005086 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005087 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005088
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005089 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005090 ql_dbg(ql_dbg_timer, vha, 0x6000,
5091 "EEH = %d, restarting timer.\n",
5092 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005093 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5094 return;
5095 }
5096
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005097 /*
5098 * Hardware read to raise pending EEH errors during mailbox waits. If
5099 * the read returns -1 then disable the board.
5100 */
5101 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08005102 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005103 if (w == 0xffff)
5104 /*
5105 * Schedule this on the default system workqueue so that
5106 * all the adapter workqueues and the DPC thread can be
5107 * shutdown cleanly.
5108 */
5109 schedule_work(&ha->board_disable);
5110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005112 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005113 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005114 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5115 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005116 if (IS_QLA82XX(ha))
5117 qla82xx_watchdog(vha);
5118 else if (IS_QLA8044(ha))
5119 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005120 }
5121
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005122 if (!vha->vp_idx && IS_QLAFX00(ha))
5123 qlafx00_timer_routine(vha);
5124
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005126 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005127 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5128 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005129 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005131 if (atomic_read(&vha->loop_down_timer) ==
5132 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005134 ql_log(ql_log_info, vha, 0x6008,
5135 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005137 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5138 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005140 /*
5141 * Schedule an ISP abort to return any FCP2-device
5142 * commands.
5143 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005144 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005145 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005146 spin_lock_irqsave(&ha->hardware_lock,
5147 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005148 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005149 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005150 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005151 index++) {
5152 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005153
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005154 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005155 if (!sp)
5156 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005157 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005158 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005159 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005160 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005161 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005163 if (IS_QLA82XX(ha))
5164 set_bit(FCOE_CTX_RESET_NEEDED,
5165 &vha->dpc_flags);
5166 else
5167 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005168 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005169 break;
5170 }
5171 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005172 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 start_dpc++;
5175 }
5176
5177 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005178 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005179 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005180 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 "Loop down - aborting ISP.\n");
5182
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005183 if (IS_QLA82XX(ha))
5184 set_bit(FCOE_CTX_RESET_NEEDED,
5185 &vha->dpc_flags);
5186 else
5187 set_bit(ISP_ABORT_NEEDED,
5188 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189 }
5190 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005191 ql_dbg(ql_dbg_timer, vha, 0x600a,
5192 "Loop down - seconds remaining %d.\n",
5193 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005195 /* Check if beacon LED needs to be blinked for physical host only */
5196 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005197 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005198 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005199 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5200 start_dpc++;
5201 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005202 }
5203
Andrew Vasquez550bf572008-04-24 15:21:23 -07005204 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005205 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005206 start_dpc++;
5207
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005209 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5210 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5211 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005213 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5214 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005215 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5216 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005217 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04005218 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005219 ql_dbg(ql_dbg_timer, vha, 0x600b,
5220 "isp_abort_needed=%d loop_resync_needed=%d "
5221 "fcport_update_needed=%d start_dpc=%d "
5222 "reset_marker_needed=%d",
5223 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5224 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5225 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5226 start_dpc,
5227 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5228 ql_dbg(ql_dbg_timer, vha, 0x600c,
5229 "beacon_blink_needed=%d isp_unrecoverable=%d "
5230 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04005231 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005232 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5233 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5234 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5235 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04005236 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005237 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005240 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241}
5242
Andrew Vasquez54333832005-11-09 15:49:04 -08005243/* Firmware interface routines. */
5244
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005245#define FW_BLOBS 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005246#define FW_ISP21XX 0
5247#define FW_ISP22XX 1
5248#define FW_ISP2300 2
5249#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005250#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005251#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005252#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005253#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005254#define FW_ISP2031 8
5255#define FW_ISP8031 9
Andrew Vasquez54333832005-11-09 15:49:04 -08005256
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005257#define FW_FILE_ISP21XX "ql2100_fw.bin"
5258#define FW_FILE_ISP22XX "ql2200_fw.bin"
5259#define FW_FILE_ISP2300 "ql2300_fw.bin"
5260#define FW_FILE_ISP2322 "ql2322_fw.bin"
5261#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005262#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005263#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005264#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005265#define FW_FILE_ISP2031 "ql2600_fw.bin"
5266#define FW_FILE_ISP8031 "ql8300_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005267
Daniel Walkere1e82b62008-05-12 22:21:10 -07005268static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005269
5270static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005271 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5272 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5273 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5274 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5275 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005276 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005277 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005278 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005279 { .name = FW_FILE_ISP2031, },
5280 { .name = FW_FILE_ISP8031, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005281};
5282
5283struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005284qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005285{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005286 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005287 struct fw_blob *blob;
5288
Andrew Vasquez54333832005-11-09 15:49:04 -08005289 if (IS_QLA2100(ha)) {
5290 blob = &qla_fw_blobs[FW_ISP21XX];
5291 } else if (IS_QLA2200(ha)) {
5292 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005293 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005294 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005295 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005296 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005297 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005298 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005299 } else if (IS_QLA25XX(ha)) {
5300 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005301 } else if (IS_QLA81XX(ha)) {
5302 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005303 } else if (IS_QLA82XX(ha)) {
5304 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005305 } else if (IS_QLA2031(ha)) {
5306 blob = &qla_fw_blobs[FW_ISP2031];
5307 } else if (IS_QLA8031(ha)) {
5308 blob = &qla_fw_blobs[FW_ISP8031];
Dan Carpenter8a655222012-02-21 10:29:40 +03005309 } else {
5310 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005311 }
5312
Daniel Walkere1e82b62008-05-12 22:21:10 -07005313 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005314 if (blob->fw)
5315 goto out;
5316
5317 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005318 ql_log(ql_log_warn, vha, 0x0063,
5319 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005320 blob->fw = NULL;
5321 blob = NULL;
5322 goto out;
5323 }
5324
5325out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005326 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005327 return blob;
5328}
5329
5330static void
5331qla2x00_release_firmware(void)
5332{
5333 int idx;
5334
Daniel Walkere1e82b62008-05-12 22:21:10 -07005335 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005336 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005337 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005338 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005339}
5340
Seokmann Ju14e660e2007-09-20 14:07:36 -07005341static pci_ers_result_t
5342qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5343{
Andrew Vasquez85880802009-12-15 21:29:46 -08005344 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5345 struct qla_hw_data *ha = vha->hw;
5346
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005347 ql_dbg(ql_dbg_aer, vha, 0x9000,
5348 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005349
Seokmann Ju14e660e2007-09-20 14:07:36 -07005350 switch (state) {
5351 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005352 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005353 return PCI_ERS_RESULT_CAN_RECOVER;
5354 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005355 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005356 /* For ISP82XX complete any pending mailbox cmd */
5357 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005358 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005359 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5360 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005361 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005362 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005363 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005364 /* Return back all IOs */
5365 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005366 return PCI_ERS_RESULT_NEED_RESET;
5367 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005368 ha->flags.pci_channel_io_perm_failure = 1;
5369 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005370 return PCI_ERS_RESULT_DISCONNECT;
5371 }
5372 return PCI_ERS_RESULT_NEED_RESET;
5373}
5374
5375static pci_ers_result_t
5376qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5377{
5378 int risc_paused = 0;
5379 uint32_t stat;
5380 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005381 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5382 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005383 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5384 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5385
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005386 if (IS_QLA82XX(ha))
5387 return PCI_ERS_RESULT_RECOVERED;
5388
Seokmann Ju14e660e2007-09-20 14:07:36 -07005389 spin_lock_irqsave(&ha->hardware_lock, flags);
5390 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5391 stat = RD_REG_DWORD(&reg->hccr);
5392 if (stat & HCCR_RISC_PAUSE)
5393 risc_paused = 1;
5394 } else if (IS_QLA23XX(ha)) {
5395 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5396 if (stat & HSR_RISC_PAUSED)
5397 risc_paused = 1;
5398 } else if (IS_FWI2_CAPABLE(ha)) {
5399 stat = RD_REG_DWORD(&reg24->host_status);
5400 if (stat & HSRX_RISC_PAUSED)
5401 risc_paused = 1;
5402 }
5403 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5404
5405 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005406 ql_log(ql_log_info, base_vha, 0x9003,
5407 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005408 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005409
5410 return PCI_ERS_RESULT_NEED_RESET;
5411 } else
5412 return PCI_ERS_RESULT_RECOVERED;
5413}
5414
Saurav Kashyapfa492632012-11-21 02:40:29 -05005415static uint32_t
5416qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005417{
5418 uint32_t rval = QLA_FUNCTION_FAILED;
5419 uint32_t drv_active = 0;
5420 struct qla_hw_data *ha = base_vha->hw;
5421 int fn;
5422 struct pci_dev *other_pdev = NULL;
5423
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005424 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5425 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005426
5427 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5428
5429 if (base_vha->flags.online) {
5430 /* Abort all outstanding commands,
5431 * so as to be requeued later */
5432 qla2x00_abort_isp_cleanup(base_vha);
5433 }
5434
5435
5436 fn = PCI_FUNC(ha->pdev->devfn);
5437 while (fn > 0) {
5438 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005439 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5440 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005441 other_pdev =
5442 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5443 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5444 fn));
5445
5446 if (!other_pdev)
5447 continue;
5448 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005449 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5450 "Found PCI func available and enable at 0x%x.\n",
5451 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005452 pci_dev_put(other_pdev);
5453 break;
5454 }
5455 pci_dev_put(other_pdev);
5456 }
5457
5458 if (!fn) {
5459 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005460 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5461 "This devfn is reset owner = 0x%x.\n",
5462 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005463 qla82xx_idc_lock(ha);
5464
5465 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005466 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005467
5468 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5469 QLA82XX_IDC_VERSION);
5470
5471 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005472 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5473 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005474
5475 qla82xx_idc_unlock(ha);
5476 /* Reset if device is not already reset
5477 * drv_active would be 0 if a reset has already been done
5478 */
5479 if (drv_active)
5480 rval = qla82xx_start_firmware(base_vha);
5481 else
5482 rval = QLA_SUCCESS;
5483 qla82xx_idc_lock(ha);
5484
5485 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005486 ql_log(ql_log_info, base_vha, 0x900b,
5487 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005488 qla82xx_clear_drv_active(ha);
5489 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005490 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005491 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005492 ql_log(ql_log_info, base_vha, 0x900c,
5493 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005494 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005495 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005496 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005497 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005498 rval = qla82xx_restart_isp(base_vha);
5499 qla82xx_idc_lock(ha);
5500 /* Clear driver state register */
5501 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5502 qla82xx_set_drv_active(base_vha);
5503 }
5504 qla82xx_idc_unlock(ha);
5505 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005506 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5507 "This devfn is not reset owner = 0x%x.\n",
5508 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005509 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005510 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005511 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005512 rval = qla82xx_restart_isp(base_vha);
5513 qla82xx_idc_lock(ha);
5514 qla82xx_set_drv_active(base_vha);
5515 qla82xx_idc_unlock(ha);
5516 }
5517 }
5518 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5519
5520 return rval;
5521}
5522
Seokmann Ju14e660e2007-09-20 14:07:36 -07005523static pci_ers_result_t
5524qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5525{
5526 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005527 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5528 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005529 struct rsp_que *rsp;
5530 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005531
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005532 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5533 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005534
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005535 /* Workaround: qla2xxx driver which access hardware earlier
5536 * needs error state to be pci_channel_io_online.
5537 * Otherwise mailbox command timesout.
5538 */
5539 pdev->error_state = pci_channel_io_normal;
5540
5541 pci_restore_state(pdev);
5542
Richard Lary8c1496b2010-02-18 10:07:29 -08005543 /* pci_restore_state() clears the saved_state flag of the device
5544 * save restored state which resets saved_state flag
5545 */
5546 pci_save_state(pdev);
5547
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005548 if (ha->mem_only)
5549 rc = pci_enable_device_mem(pdev);
5550 else
5551 rc = pci_enable_device(pdev);
5552
5553 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005554 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005555 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005556 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005557 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005558
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005559 rsp = ha->rsp_q_map[0];
5560 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005561 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005563 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005564 goto exit_slot_reset;
5565
5566 if (IS_QLA82XX(ha)) {
5567 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5568 ret = PCI_ERS_RESULT_RECOVERED;
5569 goto exit_slot_reset;
5570 } else
5571 goto exit_slot_reset;
5572 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005573
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005574 while (ha->flags.mbox_busy && retries--)
5575 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005577 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005578 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005579 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005580 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005581
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005582
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005583exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005584 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5585 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005586
Seokmann Ju14e660e2007-09-20 14:07:36 -07005587 return ret;
5588}
5589
5590static void
5591qla2xxx_pci_resume(struct pci_dev *pdev)
5592{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005593 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5594 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005595 int ret;
5596
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005597 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5598 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005599
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005600 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005601 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005602 ql_log(ql_log_fatal, base_vha, 0x9002,
5603 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005604 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005605
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005606 pci_cleanup_aer_uncorrect_error_status(pdev);
5607
Andrew Vasquez85880802009-12-15 21:29:46 -08005608 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005609}
5610
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005611static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005612 .error_detected = qla2xxx_pci_error_detected,
5613 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5614 .slot_reset = qla2xxx_pci_slot_reset,
5615 .resume = qla2xxx_pci_resume,
5616};
5617
Andrew Vasquez54333832005-11-09 15:49:04 -08005618static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005619 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5620 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5621 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5622 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5623 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5624 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5625 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5626 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5627 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005628 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005629 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5630 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005631 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005632 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005633 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005634 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005635 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005636 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005637 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005638 { 0 },
5639};
5640MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5641
Andrew Vasquezfca29702005-07-06 10:31:47 -07005642static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005643 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005644 .driver = {
5645 .owner = THIS_MODULE,
5646 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005647 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005648 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005649 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005650 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005651 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005652};
5653
Al Viro75ef9de2013-04-04 19:09:41 -04005654static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005655 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005656 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005657};
5658
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659/**
5660 * qla2x00_module_init - Module initialization.
5661 **/
5662static int __init
5663qla2x00_module_init(void)
5664{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005665 int ret = 0;
5666
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005668 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005669 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005671 ql_log(ql_log_fatal, NULL, 0x0001,
5672 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005673 return -ENOMEM;
5674 }
5675
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005676 /* Initialize target kmem_cache and mem_pools */
5677 ret = qlt_init();
5678 if (ret < 0) {
5679 kmem_cache_destroy(srb_cachep);
5680 return ret;
5681 } else if (ret > 0) {
5682 /*
5683 * If initiator mode is explictly disabled by qlt_init(),
5684 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5685 * performing scsi_scan_target() during LOOP UP event.
5686 */
5687 qla2xxx_transport_functions.disable_target_scan = 1;
5688 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5689 }
5690
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691 /* Derive version string. */
5692 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005693 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005694 strcat(qla2x00_version_str, "-debug");
5695
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005696 qla2xxx_transport_template =
5697 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005698 if (!qla2xxx_transport_template) {
5699 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005700 ql_log(ql_log_fatal, NULL, 0x0002,
5701 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005702 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005704 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005705
5706 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5707 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005708 ql_log(ql_log_fatal, NULL, 0x0003,
5709 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005710 }
5711
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005712 qla2xxx_transport_vport_template =
5713 fc_attach_transport(&qla2xxx_transport_vport_functions);
5714 if (!qla2xxx_transport_vport_template) {
5715 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005716 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005717 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005718 ql_log(ql_log_fatal, NULL, 0x0004,
5719 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005720 return -ENODEV;
5721 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005722 ql_log(ql_log_info, NULL, 0x0005,
5723 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005724 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005725 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005726 if (ret) {
5727 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005728 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005729 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005730 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005731 ql_log(ql_log_fatal, NULL, 0x0006,
5732 "pci_register_driver failed...ret=%d Failing load!.\n",
5733 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005734 }
5735 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736}
5737
5738/**
5739 * qla2x00_module_exit - Module cleanup.
5740 **/
5741static void __exit
5742qla2x00_module_exit(void)
5743{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005744 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005745 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005746 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005747 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005748 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005749 if (ctx_cachep)
5750 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005752 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753}
5754
5755module_init(qla2x00_module_init);
5756module_exit(qla2x00_module_exit);
5757
5758MODULE_AUTHOR("QLogic Corporation");
5759MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5760MODULE_LICENSE("GPL");
5761MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005762MODULE_FIRMWARE(FW_FILE_ISP21XX);
5763MODULE_FIRMWARE(FW_FILE_ISP22XX);
5764MODULE_FIRMWARE(FW_FILE_ISP2300);
5765MODULE_FIRMWARE(FW_FILE_ISP2322);
5766MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005767MODULE_FIRMWARE(FW_FILE_ISP25XX);