blob: f92b22bca7ea08744673ee4ef6f7d1fcd225ca36 [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 Dupuis3c290d02013-01-30 03:34:38 -0500113int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700114module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
115MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400116 "Maximum queue depth to set for each LUN. "
117 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700118
Arun Easi9e522cd2012-08-22 14:21:31 -0400119int ql2xenabledif = 2;
120module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700121MODULE_PARM_DESC(ql2xenabledif,
122 " Enable T10-CRC-DIF "
Arun Easi8cb20492011-08-16 11:29:22 -0700123 " Default is 0 - No DIF Support. 1 - Enable it"
124 ", 2 - Enable DIF for all types, except Type 0.");
Arun Easibad75002010-05-04 15:01:30 -0700125
Arun Easi8cb20492011-08-16 11:29:22 -0700126int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700127module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
128MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700129 " Enable T10-CRC-DIF Error isolation by HBA:\n"
130 " Default is 1.\n"
131 " 0 -- Error isolation disabled\n"
132 " 1 -- Error isolation enabled only for DIX Type 0\n"
133 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700134
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700135int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800136module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700137MODULE_PARM_DESC(ql2xiidmaenable,
138 "Enables iIDMA settings "
139 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
140
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800141int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800142module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800143MODULE_PARM_DESC(ql2xmaxqueues,
144 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700145 "Default is 1 for single queue. Set it to number "
146 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700147
148int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800149module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700150MODULE_PARM_DESC(ql2xmultique_tag,
151 "Enables CPU affinity settings for the driver "
152 "Default is 0 for no affinity of request and response IO. "
153 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700154
155int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700156module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700157MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700158 "Option to specify location from which to load ISP firmware:.\n"
159 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700160 " interface.\n"
161 " 1 -- load firmware from flash.\n"
162 " 0 -- use default semantics.\n");
163
Andrew Vasquezae97c912010-02-18 10:07:28 -0800164int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800165module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800166MODULE_PARM_DESC(ql2xetsenable,
167 "Enables firmware ETS burst."
168 "Default is 0 - skip ETS enablement.");
169
Giridhar Malavali69078692010-05-28 15:08:28 -0700170int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700171module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700172MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700173 "Option to specify scheme for request queue posting.\n"
174 " 0 -- Regular doorbell.\n"
175 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700176
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700177int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800178module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700179MODULE_PARM_DESC(ql2xtargetreset,
180 "Enable target reset."
181 "Default is 1 - use hw defaults.");
182
Chad Dupuis4da26e12010-10-15 11:27:40 -0700183int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800184module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700185MODULE_PARM_DESC(ql2xgffidenable,
186 "Enables GFF_ID checks of port type. "
187 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700189int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800190module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700191MODULE_PARM_DESC(ql2xasynctmfenable,
192 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
193 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700194
195int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700196module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700197MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700198 "Option to specify reset behaviour.\n"
199 " 0 (Default) -- Reset on failure.\n"
200 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700201
Andrew Vasquez82515922011-05-10 11:30:13 -0700202uint ql2xmaxlun = MAX_LUNS;
203module_param(ql2xmaxlun, uint, S_IRUGO);
204MODULE_PARM_DESC(ql2xmaxlun,
205 "Defines the maximum LU number to register with the SCSI "
206 "midlayer. Default is 65535.");
207
Giridhar Malavali08de2842011-08-16 11:31:44 -0700208int ql2xmdcapmask = 0x1F;
209module_param(ql2xmdcapmask, int, S_IRUGO);
210MODULE_PARM_DESC(ql2xmdcapmask,
211 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800212 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700213
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800214int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700215module_param(ql2xmdenable, int, S_IRUGO);
216MODULE_PARM_DESC(ql2xmdenable,
217 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800218 "0 - MiniDump disabled. "
219 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700222 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 */
224static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500225static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800226static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
227static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500228static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500229static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static int qla2xxx_eh_abort(struct scsi_cmnd *);
231static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700232static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
234static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Mike Christiee881a172009-10-15 17:46:39 -0700236static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700237static int qla2x00_change_queue_type(struct scsi_device *, int);
Saurav Kashyap34912552013-06-25 11:27:18 -0400238static void qla2x00_free_device(scsi_qla_host_t *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700239
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700240struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700242 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700243 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700244
245 .eh_abort_handler = qla2xxx_eh_abort,
246 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700247 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700248 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
249 .eh_host_reset_handler = qla2xxx_eh_host_reset,
250
251 .slave_configure = qla2xxx_slave_configure,
252
253 .slave_alloc = qla2xxx_slave_alloc,
254 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700255 .scan_finished = qla2xxx_scan_finished,
256 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700257 .change_queue_depth = qla2x00_change_queue_depth,
258 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700259 .this_id = -1,
260 .cmd_per_lun = 3,
261 .use_clustering = ENABLE_CLUSTERING,
262 .sg_tablesize = SG_ALL,
263
264 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700265 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400266
267 .supported_mode = MODE_INITIATOR,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700268};
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700271struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273/* TODO Convert to inlines
274 *
275 * Timer routines
276 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700278__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800279qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800281 init_timer(&vha->timer);
282 vha->timer.expires = jiffies + interval * HZ;
283 vha->timer.data = (unsigned long)vha;
284 vha->timer.function = (void (*)(unsigned long))func;
285 add_timer(&vha->timer);
286 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
289static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800290qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700292 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700293 if (vha->device_flags & DFLG_DEV_FAILED) {
294 ql_dbg(ql_dbg_timer, vha, 0x600d,
295 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700296 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700297 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700298
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800299 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301
Adrian Bunka824ebb2008-01-17 09:02:15 -0800302static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800303qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800305 del_timer_sync(&vha->timer);
306 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309static int qla2x00_do_dpc(void *data);
310
311static void qla2x00_rst_aen(scsi_qla_host_t *);
312
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800313static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
314 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700315static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800316static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400319static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
320 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800321{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700322 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700323 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800324 GFP_KERNEL);
325 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700326 ql_log(ql_log_fatal, vha, 0x003b,
327 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800328 goto fail_req_map;
329 }
330
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700331 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800332 GFP_KERNEL);
333 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700334 ql_log(ql_log_fatal, vha, 0x003c,
335 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800336 goto fail_rsp_map;
337 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400338 /*
339 * Make sure we record at least the request and response queue zero in
340 * case we need to free them if part of the probe fails.
341 */
342 ha->rsp_q_map[0] = rsp;
343 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800344 set_bit(0, ha->rsp_qid_map);
345 set_bit(0, ha->req_qid_map);
346 return 1;
347
348fail_rsp_map:
349 kfree(ha->req_q_map);
350 ha->req_q_map = NULL;
351fail_req_map:
352 return -ENOMEM;
353}
354
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700355static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800356{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400357 if (IS_QLAFX00(ha)) {
358 if (req && req->ring_fx00)
359 dma_free_coherent(&ha->pdev->dev,
360 (req->length_fx00 + 1) * sizeof(request_t),
361 req->ring_fx00, req->dma_fx00);
362 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800363 dma_free_coherent(&ha->pdev->dev,
364 (req->length + 1) * sizeof(request_t),
365 req->ring, req->dma);
366
Chad Dupuis8d93f552013-01-30 03:34:37 -0500367 if (req)
368 kfree(req->outstanding_cmds);
369
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800370 kfree(req);
371 req = NULL;
372}
373
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700374static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
375{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400376 if (IS_QLAFX00(ha)) {
377 if (rsp && rsp->ring)
378 dma_free_coherent(&ha->pdev->dev,
379 (rsp->length_fx00 + 1) * sizeof(request_t),
380 rsp->ring_fx00, rsp->dma_fx00);
381 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700382 dma_free_coherent(&ha->pdev->dev,
383 (rsp->length + 1) * sizeof(response_t),
384 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400385 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700386 kfree(rsp);
387 rsp = NULL;
388}
389
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800390static void qla2x00_free_queues(struct qla_hw_data *ha)
391{
392 struct req_que *req;
393 struct rsp_que *rsp;
394 int cnt;
395
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700396 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800397 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700398 qla2x00_free_req_que(ha, req);
399 }
400 kfree(ha->req_q_map);
401 ha->req_q_map = NULL;
402
403 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
404 rsp = ha->rsp_q_map[cnt];
405 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800406 }
407 kfree(ha->rsp_q_map);
408 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800409}
410
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700411static int qla25xx_setup_mode(struct scsi_qla_host *vha)
412{
413 uint16_t options = 0;
414 int ques, req, ret;
415 struct qla_hw_data *ha = vha->hw;
416
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700417 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700418 ql_log(ql_log_warn, vha, 0x00d8,
419 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700420 goto fail;
421 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700422 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700423 /* create a request queue for IO */
424 options |= BIT_7;
425 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
426 QLA_DEFAULT_QUE_QOS);
427 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700428 ql_log(ql_log_warn, vha, 0x00e0,
429 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700430 goto fail;
431 }
Tejun Heo278274d2011-02-01 11:42:42 +0100432 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700433 vha->req = ha->req_q_map[req];
434 options |= BIT_1;
435 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
436 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
437 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700438 ql_log(ql_log_warn, vha, 0x00e8,
439 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700440 goto fail2;
441 }
442 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700443 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700444 ql_dbg(ql_dbg_multiq, vha, 0xc007,
445 "CPU affinity mode enalbed, "
446 "no. of response queues:%d no. of request queues:%d.\n",
447 ha->max_rsp_queues, ha->max_req_queues);
448 ql_dbg(ql_dbg_init, vha, 0x00e9,
449 "CPU affinity mode enalbed, "
450 "no. of response queues:%d no. of request queues:%d.\n",
451 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700452 }
453 return 0;
454fail2:
455 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700456 destroy_workqueue(ha->wq);
457 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800458 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700459fail:
460 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700461 kfree(ha->req_q_map);
462 kfree(ha->rsp_q_map);
463 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700464 return 1;
465}
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800468qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800470 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 static char *pci_bus_modes[] = {
472 "33", "66", "100", "133",
473 };
474 uint16_t pci_bus;
475
476 strcpy(str, "PCI");
477 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
478 if (pci_bus) {
479 strcat(str, "-X (");
480 strcat(str, pci_bus_modes[pci_bus]);
481 } else {
482 pci_bus = (ha->pci_attr & BIT_8) >> 8;
483 strcat(str, " (");
484 strcat(str, pci_bus_modes[pci_bus]);
485 }
486 strcat(str, " MHz)");
487
488 return (str);
489}
490
Andrew Vasquezfca29702005-07-06 10:31:47 -0700491static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800492qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700493{
494 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800495 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700496 uint32_t pci_bus;
497 int pcie_reg;
498
Jon Masone67f1322012-07-10 14:57:56 -0700499 pcie_reg = pci_pcie_cap(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700500 if (pcie_reg) {
501 char lwstr[6];
502 uint16_t pcie_lstat, lspeed, lwidth;
503
Jon Masone67f1322012-07-10 14:57:56 -0700504 pcie_reg += PCI_EXP_LNKCAP;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700505 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
506 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
507 lwidth = (pcie_lstat &
508 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
509
510 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500511 switch (lspeed) {
512 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700513 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500514 break;
515 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700516 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500517 break;
518 case 3:
519 strcat(str, "8.0GT/s ");
520 break;
521 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500523 break;
524 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700525 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
526 strcat(str, lwstr);
527
528 return str;
529 }
530
531 strcpy(str, "PCI");
532 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
533 if (pci_bus == 0 || pci_bus == 8) {
534 strcat(str, " (");
535 strcat(str, pci_bus_modes[pci_bus >> 3]);
536 } else {
537 strcat(str, "-X ");
538 if (pci_bus & BIT_2)
539 strcat(str, "Mode 2");
540 else
541 strcat(str, "Mode 1");
542 strcat(str, " (");
543 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
544 }
545 strcat(str, " MHz)");
546
547 return str;
548}
549
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800550static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
557 ha->fw_minor_version,
558 ha->fw_subminor_version);
559
560 if (ha->fw_attributes & BIT_9) {
561 strcat(str, "FLX");
562 return (str);
563 }
564
565 switch (ha->fw_attributes & 0xFF) {
566 case 0x7:
567 strcat(str, "EF");
568 break;
569 case 0x17:
570 strcat(str, "TP");
571 break;
572 case 0x37:
573 strcat(str, "IP");
574 break;
575 case 0x77:
576 strcat(str, "VI");
577 break;
578 default:
579 sprintf(un_str, "(%x)", ha->fw_attributes);
580 strcat(str, un_str);
581 break;
582 }
583 if (ha->fw_attributes & 0x100)
584 strcat(str, "X");
585
586 return (str);
587}
588
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800589static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700593
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800594 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
595 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700596 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700597}
598
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800599void
600qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700601{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800602 srb_t *sp = (srb_t *)ptr;
603 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
604 struct qla_hw_data *ha = sp->fcport->vha->hw;
605 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700606
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800607 if (sp->flags & SRB_DMA_VALID) {
608 scsi_dma_unmap(cmd);
609 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700610 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800612 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
613 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
614 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
615 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
616 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700617
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800618 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
619 /* List assured to be having elements */
620 qla2x00_clean_dsd_pool(ha, sp);
621 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
622 }
623
624 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
625 dma_pool_free(ha->dl_dma_pool, ctx,
626 ((struct crc_context *)ctx)->crc_ctx_dma);
627 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
628 }
629
630 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
631 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
632
633 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
634 ctx1->fcp_cmnd_dma);
635 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
636 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
637 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
638 mempool_free(ctx1, ha->ctx_mempool);
639 ctx1 = NULL;
640 }
641
642 CMD_SP(cmd) = NULL;
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500643 qla2x00_rel_sp(sp->fcport->vha, sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800644}
645
Fengguang Wu14b06802013-04-25 01:29:19 -0400646static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800647qla2x00_sp_compl(void *data, void *ptr, int res)
648{
649 struct qla_hw_data *ha = (struct qla_hw_data *)data;
650 srb_t *sp = (srb_t *)ptr;
651 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
652
653 cmd->result = res;
654
655 if (atomic_read(&sp->ref_count) == 0) {
656 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
657 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
658 sp, GET_CMD_SP(sp));
659 if (ql2xextended_error_logging & ql_dbg_io)
660 BUG();
661 return;
662 }
663 if (!atomic_dec_and_test(&sp->ref_count))
664 return;
665
666 qla2x00_sp_free_dma(ha, sp);
667 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700668}
669
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400670/* If we are SP1 here, we need to still take and release the host_lock as SP1
671 * does not have the changes necessary to avoid taking host->host_lock.
672 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800674qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700675{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700676 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700677 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400678 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800679 struct qla_hw_data *ha = vha->hw;
680 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700681 srb_t *sp;
682 int rval;
683
Andrew Vasquez85880802009-12-15 21:29:46 -0800684 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700685 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400686 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 "PCI Channel IO permanent failure, exiting "
688 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700689 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700690 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400691 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700692 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800693 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700695 goto qc24_fail_command;
696 }
697
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400698 rval = fc_remote_port_chkready(rport);
699 if (rval) {
700 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400701 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700702 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
703 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700704 goto qc24_fail_command;
705 }
706
Arun Easibad75002010-05-04 15:01:30 -0700707 if (!vha->flags.difdix_supported &&
708 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700709 ql_dbg(ql_dbg_io, vha, 0x3004,
710 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
711 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700712 cmd->result = DID_NO_CONNECT << 16;
713 goto qc24_fail_command;
714 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800715
716 if (!fcport) {
717 cmd->result = DID_NO_CONNECT << 16;
718 goto qc24_fail_command;
719 }
720
Andrew Vasquezfca29702005-07-06 10:31:47 -0700721 if (atomic_read(&fcport->state) != FCS_ONLINE) {
722 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700723 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700724 ql_dbg(ql_dbg_io, vha, 0x3005,
725 "Returning DNC, fcport_state=%d loop_state=%d.\n",
726 atomic_read(&fcport->state),
727 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700728 cmd->result = DID_NO_CONNECT << 16;
729 goto qc24_fail_command;
730 }
Mike Christie7b594132008-08-17 15:24:40 -0500731 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700732 }
733
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500734 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis3c290d02013-01-30 03:34:38 -0500735 if (!sp) {
736 set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800737 goto qc24_host_busy;
Chad Dupuis3c290d02013-01-30 03:34:38 -0500738 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700739
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800740 sp->u.scmd.cmd = cmd;
741 sp->type = SRB_SCSI_CMD;
742 atomic_set(&sp->ref_count, 1);
743 CMD_SP(cmd) = (void *)sp;
744 sp->free = qla2x00_sp_free_dma;
745 sp->done = qla2x00_sp_compl;
746
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800747 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700748 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500749 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700750 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Chad Dupuis3c290d02013-01-30 03:34:38 -0500751 set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700752 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700753 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700754
Andrew Vasquezfca29702005-07-06 10:31:47 -0700755 return 0;
756
757qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800758 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700759
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800760qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700761 return SCSI_MLQUEUE_HOST_BUSY;
762
Mike Christie7b594132008-08-17 15:24:40 -0500763qc24_target_busy:
764 return SCSI_MLQUEUE_TARGET_BUSY;
765
Andrew Vasquezfca29702005-07-06 10:31:47 -0700766qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800767 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700768
769 return 0;
770}
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772/*
773 * qla2x00_eh_wait_on_command
774 * Waits for the command to be returned by the Firmware for some
775 * max time.
776 *
777 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 *
780 * Return:
781 * Not Found : 0
782 * Found : 1
783 */
784static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700787#define ABORT_POLLING_PERIOD 1000
788#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500789 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800790 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
791 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500792 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Andrew Vasquez85880802009-12-15 21:29:46 -0800794 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700795 ql_dbg(ql_dbg_taskm, vha, 0x8005,
796 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800797 return ret;
798 }
799
Lalit Chandivaded9704322009-08-25 11:36:18 -0700800 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700801 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500802 }
803 if (CMD_SP(cmd))
804 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
f4f051e2005-04-17 15:02:26 -0500806 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
809/*
810 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700811 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 * <= MAX_RETRIES_OF_ISP_ABORT or
813 * finally HBA is disabled ie marked offline
814 *
815 * Input:
816 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700817 *
818 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 * Does context switching-Release SPIN_LOCK
820 * (if any) before calling this routine.
821 *
822 * Return:
823 * Success (Adapter is online) : 0
824 * Failed (Adapter is offline/disabled) : 1
825 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800826int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800827qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700829 int return_status;
830 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 struct qla_hw_data *ha = vha->hw;
832 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700834 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
836 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
837 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
838 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 msleep(1000);
841 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700843 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 else
845 return_status = QLA_FUNCTION_FAILED;
846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 return (return_status);
848}
849
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700850/*
851 * qla2x00_wait_for_reset_ready
852 * Wait till the HBA is online after going through
853 * <= MAX_RETRIES_OF_ISP_ABORT or
854 * finally HBA is disabled ie marked offline or flash
855 * operations are in progress.
856 *
857 * Input:
858 * ha - pointer to host adapter structure
859 *
860 * Note:
861 * Does context switching-Release SPIN_LOCK
862 * (if any) before calling this routine.
863 *
864 * Return:
865 * Success (Adapter is online/no flash ops) : 0
866 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
867 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500868static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700869qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
870{
871 int return_status;
872 unsigned long wait_online;
873 struct qla_hw_data *ha = vha->hw;
874 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
875
876 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
877 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
878 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
879 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
880 ha->optrom_state != QLA_SWAITING ||
881 ha->dpc_active) && time_before(jiffies, wait_online))
882 msleep(1000);
883
884 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
885 return_status = QLA_SUCCESS;
886 else
887 return_status = QLA_FUNCTION_FAILED;
888
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700889 ql_dbg(ql_dbg_taskm, vha, 0x8019,
890 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700891
892 return return_status;
893}
894
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700895int
896qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
897{
898 int return_status;
899 unsigned long wait_reset;
900 struct qla_hw_data *ha = vha->hw;
901 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
902
903 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
904 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
905 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
906 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
907 ha->dpc_active) && time_before(jiffies, wait_reset)) {
908
909 msleep(1000);
910
911 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
912 ha->flags.chip_reset_done)
913 break;
914 }
915 if (ha->flags.chip_reset_done)
916 return_status = QLA_SUCCESS;
917 else
918 return_status = QLA_FUNCTION_FAILED;
919
920 return return_status;
921}
922
Giridhar Malavali083a4692010-05-28 15:08:18 -0700923static void
924sp_get(struct srb *sp)
925{
926 atomic_inc(&sp->ref_count);
927}
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929/**************************************************************************
930* qla2xxx_eh_abort
931*
932* Description:
933* The abort function will abort the specified command.
934*
935* Input:
936* cmd = Linux SCSI command packet to be aborted.
937*
938* Returns:
939* Either SUCCESS or FAILED.
940*
941* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700942* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800944static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945qla2xxx_eh_abort(struct scsi_cmnd *cmd)
946{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800947 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500948 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800949 int ret;
f4f051e2005-04-17 15:02:26 -0500950 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700951 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700952 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800953 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
f4f051e2005-04-17 15:02:26 -0500955 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700956 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800958 ret = fc_block_scsi_eh(cmd);
959 if (ret != 0)
960 return ret;
961 ret = SUCCESS;
962
f4f051e2005-04-17 15:02:26 -0500963 id = cmd->device->id;
964 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800966 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700967 sp = (srb_t *) CMD_SP(cmd);
968 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800969 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700970 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500971 }
Mike Christie170babc2010-10-15 11:27:47 -0700972
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800974 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
975 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700976
977 /* Get a reference to the sp and drop the lock.*/
978 sp_get(sp);
979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700981 if (ha->isp_ops->abort_command(sp)) {
Arun Easia55aac72012-02-09 11:14:03 -0800982 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700983 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800984 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700985 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700986 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800987 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700988 wait = 1;
989 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700990
991 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800992 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700993 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500994
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700995 /* Did the command return during mailbox execution? */
996 if (ret == FAILED && !CMD_SP(cmd))
997 ret = SUCCESS;
998
f4f051e2005-04-17 15:02:26 -0500999 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001000 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001001 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001003 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001004 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001005 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001008 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001009 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
1010 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
f4f051e2005-04-17 15:02:26 -05001012 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001015int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001016qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001017 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001019 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001020 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001021 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001022 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001023 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001024 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Andrew Vasquez523ec772008-04-03 13:13:24 -07001026 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001027
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001028 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001029 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001030 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001031 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001032 sp = req->outstanding_cmds[cnt];
1033 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001034 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001035 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001036 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001037 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1038 continue;
1039 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001040 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001041 switch (type) {
1042 case WAIT_HOST:
1043 match = 1;
1044 break;
1045 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001046 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001047 break;
1048 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001049 match = (cmd->device->id == t &&
1050 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001051 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001053 if (!match)
1054 continue;
1055
1056 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001057 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001058 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001061
1062 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
Andrew Vasquez523ec772008-04-03 13:13:24 -07001065static char *reset_errors[] = {
1066 "HBA not online",
1067 "HBA not ready",
1068 "Task management failed",
1069 "Waiting for command completions",
1070};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Andrew Vasquez523ec772008-04-03 13:13:24 -07001072static int
1073__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001074 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001075{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001076 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001077 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1078 int err;
1079
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001081 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001082 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001083
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001084 err = fc_block_scsi_eh(cmd);
1085 if (err != 0)
1086 return err;
1087
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001088 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001089 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001090 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001091
1092 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001093 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1094 ql_log(ql_log_warn, vha, 0x800a,
1095 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001096 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001097 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001098 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001099 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001100 != QLA_SUCCESS) {
1101 ql_log(ql_log_warn, vha, 0x800c,
1102 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001103 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001104 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001105 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001106 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001107 cmd->device->lun, type) != QLA_SUCCESS) {
1108 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001109 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001110 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001111 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001112
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001114 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1115 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001116
1117 return SUCCESS;
1118
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001119eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001120 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001121 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1122 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1123 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001124 return FAILED;
1125}
1126
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001127static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1129{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001130 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1131 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Andrew Vasquez523ec772008-04-03 13:13:24 -07001133 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1134 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001138qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001140 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1141 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Andrew Vasquez523ec772008-04-03 13:13:24 -07001143 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1144 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147/**************************************************************************
1148* qla2xxx_eh_bus_reset
1149*
1150* Description:
1151* The bus reset function will reset the bus and abort any executing
1152* commands.
1153*
1154* Input:
1155* cmd = Linux SCSI command packet of the command that cause the
1156* bus reset.
1157*
1158* Returns:
1159* SUCCESS/FAILURE (defined as macro in scsi.h).
1160*
1161**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001162static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1164{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001165 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001166 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001167 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001168 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
f4f051e2005-04-17 15:02:26 -05001170 id = cmd->device->id;
1171 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001172
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001173 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001174 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001177 ret = fc_block_scsi_eh(cmd);
1178 if (ret != 0)
1179 return ret;
1180 ret = FAILED;
1181
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001182 ql_log(ql_log_info, vha, 0x8012,
Andrew Vasquez46270af2012-05-15 14:34:17 -04001183 "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001185 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001186 ql_log(ql_log_fatal, vha, 0x8013,
1187 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001188 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190
Saurav Kashyapad537682011-11-18 09:02:09 -08001191 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1192 ret = SUCCESS;
1193
f4f051e2005-04-17 15:02:26 -05001194 if (ret == FAILED)
1195 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001197 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001198 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001199 QLA_SUCCESS) {
1200 ql_log(ql_log_warn, vha, 0x8014,
1201 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001202 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
f4f051e2005-04-17 15:02:26 -05001205eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001206 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001207 "BUS RESET %s nexus=%ld:%d:%d.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001208 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
f4f051e2005-04-17 15:02:26 -05001210 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
1213/**************************************************************************
1214* qla2xxx_eh_host_reset
1215*
1216* Description:
1217* The reset function will reset the Adapter.
1218*
1219* Input:
1220* cmd = Linux SCSI command packet of the command that cause the
1221* adapter reset.
1222*
1223* Returns:
1224* Either SUCCESS or FAILED.
1225*
1226* Note:
1227**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001228static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1230{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001231 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001232 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001233 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001234 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
f4f051e2005-04-17 15:02:26 -05001237 id = cmd->device->id;
1238 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001239
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001240 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001241 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001243 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001244 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001246 if (vha != base_vha) {
1247 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001248 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001249 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001250 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001251 if (!qla82xx_fcoe_ctx_reset(vha)) {
1252 /* Ctx reset success */
1253 ret = SUCCESS;
1254 goto eh_host_reset_lock;
1255 }
1256 /* fall thru if ctx reset failed */
1257 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001258 if (ha->wq)
1259 flush_workqueue(ha->wq);
1260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001261 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001262 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1264 /* failed. schedule dpc to try */
1265 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1266
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001267 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1268 ql_log(ql_log_warn, vha, 0x802a,
1269 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001271 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 }
1273 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001276 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001277 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001278 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001279 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
f4f051e2005-04-17 15:02:26 -05001281eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001282 ql_log(ql_log_info, vha, 0x8017,
1283 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1284 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
f4f051e2005-04-17 15:02:26 -05001286 return ret;
1287}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289/*
1290* qla2x00_loop_reset
1291* Issue loop reset.
1292*
1293* Input:
1294* ha = adapter block pointer.
1295*
1296* Returns:
1297* 0 = success
1298*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001299int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001300qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001302 int ret;
bdf79622005-04-17 15:06:53 -05001303 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001306 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001307 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1308 if (fcport->port_type != FCT_TARGET)
1309 continue;
1310
1311 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1312 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1314 "Bus Reset failed: Target Reset=%d "
1315 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001316 }
1317 }
1318 }
1319
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001320 if (IS_QLAFX00(ha))
1321 return QLA_SUCCESS;
1322
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001323 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001324 atomic_set(&vha->loop_state, LOOP_DOWN);
1325 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1326 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001328 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001329 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1330 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001334 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001336 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001337 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1338 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001339 }
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001344 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001347void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001349{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001350 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001351 unsigned long flags;
1352 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001354 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001355
1356 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001357 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001358 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001359 if (!req)
1360 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001361 if (!req->outstanding_cmds)
1362 continue;
1363 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001364 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001365 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001366 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001367 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001368 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001369 }
1370 }
1371 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1372}
1373
f4f051e2005-04-17 15:02:26 -05001374static int
1375qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
bdf79622005-04-17 15:06:53 -05001377 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001379 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001380 return -ENXIO;
1381
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001382 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001383
1384 return 0;
1385}
1386
1387static int
1388qla2xxx_slave_configure(struct scsi_device *sdev)
1389{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001390 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001391 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001392
Arun Easi9e522cd2012-08-22 14:21:31 -04001393 if (IS_T10_PI_CAPABLE(vha->hw))
1394 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1395
f4f051e2005-04-17 15:02:26 -05001396 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001397 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001399 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001400 return 0;
1401}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
f4f051e2005-04-17 15:02:26 -05001403static void
1404qla2xxx_slave_destroy(struct scsi_device *sdev)
1405{
1406 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407}
1408
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001409static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1410{
1411 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1412
1413 if (!scsi_track_queue_full(sdev, qdepth))
1414 return;
1415
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001416 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001417 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1418 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001419}
1420
1421static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1422{
1423 fc_port_t *fcport = sdev->hostdata;
1424 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001425 struct req_que *req = NULL;
1426
1427 req = vha->req;
1428 if (!req)
1429 return;
1430
1431 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1432 return;
1433
1434 if (sdev->ordered_tags)
1435 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1436 else
1437 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1438
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001439 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001440 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1441 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001442}
1443
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001444static int
Mike Christiee881a172009-10-15 17:46:39 -07001445qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001446{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001447 switch (reason) {
1448 case SCSI_QDEPTH_DEFAULT:
1449 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1450 break;
1451 case SCSI_QDEPTH_QFULL:
1452 qla2x00_handle_queue_full(sdev, qdepth);
1453 break;
1454 case SCSI_QDEPTH_RAMP_UP:
1455 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1456 break;
1457 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001458 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001459 }
Mike Christiee881a172009-10-15 17:46:39 -07001460
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001461 return sdev->queue_depth;
1462}
1463
1464static int
1465qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1466{
1467 if (sdev->tagged_supported) {
1468 scsi_set_tag_type(sdev, tag_type);
1469 if (tag_type)
1470 scsi_activate_tcq(sdev, sdev->queue_depth);
1471 else
1472 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1473 } else
1474 tag_type = 0;
1475
1476 return tag_type;
1477}
1478
Chad Dupuis3c290d02013-01-30 03:34:38 -05001479static void
1480qla2x00_host_ramp_down_queuedepth(scsi_qla_host_t *vha)
1481{
1482 scsi_qla_host_t *vp;
1483 struct Scsi_Host *shost;
1484 struct scsi_device *sdev;
1485 struct qla_hw_data *ha = vha->hw;
1486 unsigned long flags;
1487
1488 ha->host_last_rampdown_time = jiffies;
1489
1490 if (ha->cfg_lun_q_depth <= vha->host->cmd_per_lun)
1491 return;
1492
1493 if ((ha->cfg_lun_q_depth / 2) < vha->host->cmd_per_lun)
1494 ha->cfg_lun_q_depth = vha->host->cmd_per_lun;
1495 else
1496 ha->cfg_lun_q_depth = ha->cfg_lun_q_depth / 2;
1497
1498 /*
1499 * Geometrically ramp down the queue depth for all devices on this
1500 * adapter
1501 */
1502 spin_lock_irqsave(&ha->vport_slock, flags);
1503 list_for_each_entry(vp, &ha->vp_list, list) {
1504 shost = vp->host;
1505 shost_for_each_device(sdev, shost) {
1506 if (sdev->queue_depth > shost->cmd_per_lun) {
1507 if (sdev->queue_depth < ha->cfg_lun_q_depth)
1508 continue;
1509 ql_log(ql_log_warn, vp, 0x3031,
1510 "%ld:%d:%d: Ramping down queue depth to %d",
1511 vp->host_no, sdev->id, sdev->lun,
1512 ha->cfg_lun_q_depth);
1513 qla2x00_change_queue_depth(sdev,
1514 ha->cfg_lun_q_depth, SCSI_QDEPTH_DEFAULT);
1515 }
1516 }
1517 }
1518 spin_unlock_irqrestore(&ha->vport_slock, flags);
1519
1520 return;
1521}
1522
1523static void
1524qla2x00_host_ramp_up_queuedepth(scsi_qla_host_t *vha)
1525{
1526 scsi_qla_host_t *vp;
1527 struct Scsi_Host *shost;
1528 struct scsi_device *sdev;
1529 struct qla_hw_data *ha = vha->hw;
1530 unsigned long flags;
1531
1532 ha->host_last_rampup_time = jiffies;
1533 ha->cfg_lun_q_depth++;
1534
1535 /*
1536 * Linearly ramp up the queue depth for all devices on this
1537 * adapter
1538 */
1539 spin_lock_irqsave(&ha->vport_slock, flags);
1540 list_for_each_entry(vp, &ha->vp_list, list) {
1541 shost = vp->host;
1542 shost_for_each_device(sdev, shost) {
1543 if (sdev->queue_depth > ha->cfg_lun_q_depth)
1544 continue;
1545 qla2x00_change_queue_depth(sdev, ha->cfg_lun_q_depth,
1546 SCSI_QDEPTH_RAMP_UP);
1547 }
1548 }
1549 spin_unlock_irqrestore(&ha->vport_slock, flags);
1550
1551 return;
1552}
1553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554/**
1555 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1556 * @ha: HA context
1557 *
1558 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1559 * supported addressing method.
1560 */
1561static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001562qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001564 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Yang Hongyang6a355282009-04-06 19:01:13 -07001567 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001568 /* Any upper-dword bits set? */
1569 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001570 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001571 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001573 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1574 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001575 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001578
Yang Hongyang284901a2009-04-06 19:01:15 -07001579 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1580 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001583static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001584qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001585{
1586 unsigned long flags = 0;
1587 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1588
1589 spin_lock_irqsave(&ha->hardware_lock, flags);
1590 ha->interrupts_on = 1;
1591 /* enable risc and host interrupts */
1592 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1593 RD_REG_WORD(&reg->ictrl);
1594 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1595
1596}
1597
1598static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001599qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001600{
1601 unsigned long flags = 0;
1602 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1603
1604 spin_lock_irqsave(&ha->hardware_lock, flags);
1605 ha->interrupts_on = 0;
1606 /* disable risc and host interrupts */
1607 WRT_REG_WORD(&reg->ictrl, 0);
1608 RD_REG_WORD(&reg->ictrl);
1609 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1610}
1611
1612static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001614{
1615 unsigned long flags = 0;
1616 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1617
1618 spin_lock_irqsave(&ha->hardware_lock, flags);
1619 ha->interrupts_on = 1;
1620 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1621 RD_REG_DWORD(&reg->ictrl);
1622 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1623}
1624
1625static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001626qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001627{
1628 unsigned long flags = 0;
1629 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1630
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001631 if (IS_NOPOLLING_TYPE(ha))
1632 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001633 spin_lock_irqsave(&ha->hardware_lock, flags);
1634 ha->interrupts_on = 0;
1635 WRT_REG_DWORD(&reg->ictrl, 0);
1636 RD_REG_DWORD(&reg->ictrl);
1637 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1638}
1639
Giridhar Malavali706f4572011-11-18 09:03:16 -08001640static int
1641qla2x00_iospace_config(struct qla_hw_data *ha)
1642{
1643 resource_size_t pio;
1644 uint16_t msix;
1645 int cpus;
1646
Giridhar Malavali706f4572011-11-18 09:03:16 -08001647 if (pci_request_selected_regions(ha->pdev, ha->bars,
1648 QLA2XXX_DRIVER_NAME)) {
1649 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1650 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1651 pci_name(ha->pdev));
1652 goto iospace_error_exit;
1653 }
1654 if (!(ha->bars & 1))
1655 goto skip_pio;
1656
1657 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1658 pio = pci_resource_start(ha->pdev, 0);
1659 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1660 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1661 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1662 "Invalid pci I/O region size (%s).\n",
1663 pci_name(ha->pdev));
1664 pio = 0;
1665 }
1666 } else {
1667 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1668 "Region #0 no a PIO resource (%s).\n",
1669 pci_name(ha->pdev));
1670 pio = 0;
1671 }
1672 ha->pio_address = pio;
1673 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1674 "PIO address=%llu.\n",
1675 (unsigned long long)ha->pio_address);
1676
1677skip_pio:
1678 /* Use MMIO operations for all accesses. */
1679 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1680 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1681 "Region #1 not an MMIO resource (%s), aborting.\n",
1682 pci_name(ha->pdev));
1683 goto iospace_error_exit;
1684 }
1685 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1686 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1687 "Invalid PCI mem region size (%s), aborting.\n",
1688 pci_name(ha->pdev));
1689 goto iospace_error_exit;
1690 }
1691
1692 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1693 if (!ha->iobase) {
1694 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1695 "Cannot remap MMIO (%s), aborting.\n",
1696 pci_name(ha->pdev));
1697 goto iospace_error_exit;
1698 }
1699
1700 /* Determine queue resources */
1701 ha->max_req_queues = ha->max_rsp_queues = 1;
1702 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1703 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1704 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1705 goto mqiobase_exit;
1706
1707 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1708 pci_resource_len(ha->pdev, 3));
1709 if (ha->mqiobase) {
1710 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1711 "MQIO Base=%p.\n", ha->mqiobase);
1712 /* Read MSIX vector size of the board */
1713 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1714 ha->msix_count = msix;
1715 /* Max queues are bounded by available msix vectors */
1716 /* queue 0 uses two msix vectors */
1717 if (ql2xmultique_tag) {
1718 cpus = num_online_cpus();
1719 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1720 (cpus + 1) : (ha->msix_count - 1);
1721 ha->max_req_queues = 2;
1722 } else if (ql2xmaxqueues > 1) {
1723 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1724 QLA_MQ_SIZE : ql2xmaxqueues;
1725 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1726 "QoS mode set, max no of request queues:%d.\n",
1727 ha->max_req_queues);
1728 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1729 "QoS mode set, max no of request queues:%d.\n",
1730 ha->max_req_queues);
1731 }
1732 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1733 "MSI-X vector count: %d.\n", msix);
1734 } else
1735 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1736 "BAR 3 not enabled.\n");
1737
1738mqiobase_exit:
1739 ha->msix_count = ha->max_rsp_queues + 1;
1740 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1741 "MSIX Count:%d.\n", ha->msix_count);
1742 return (0);
1743
1744iospace_error_exit:
1745 return (-ENOMEM);
1746}
1747
1748
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001749static int
1750qla83xx_iospace_config(struct qla_hw_data *ha)
1751{
1752 uint16_t msix;
1753 int cpus;
1754
1755 if (pci_request_selected_regions(ha->pdev, ha->bars,
1756 QLA2XXX_DRIVER_NAME)) {
1757 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1758 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1759 pci_name(ha->pdev));
1760
1761 goto iospace_error_exit;
1762 }
1763
1764 /* Use MMIO operations for all accesses. */
1765 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1766 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1767 "Invalid pci I/O region size (%s).\n",
1768 pci_name(ha->pdev));
1769 goto iospace_error_exit;
1770 }
1771 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1772 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1773 "Invalid PCI mem region size (%s), aborting\n",
1774 pci_name(ha->pdev));
1775 goto iospace_error_exit;
1776 }
1777
1778 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1779 if (!ha->iobase) {
1780 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1781 "Cannot remap MMIO (%s), aborting.\n",
1782 pci_name(ha->pdev));
1783 goto iospace_error_exit;
1784 }
1785
1786 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1787 /* 83XX 26XX always use MQ type access for queues
1788 * - mbar 2, a.k.a region 4 */
1789 ha->max_req_queues = ha->max_rsp_queues = 1;
1790 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1791 pci_resource_len(ha->pdev, 4));
1792
1793 if (!ha->mqiobase) {
1794 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1795 "BAR2/region4 not enabled\n");
1796 goto mqiobase_exit;
1797 }
1798
1799 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1800 pci_resource_len(ha->pdev, 2));
1801 if (ha->msixbase) {
1802 /* Read MSIX vector size of the board */
1803 pci_read_config_word(ha->pdev,
1804 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1805 ha->msix_count = msix;
1806 /* Max queues are bounded by available msix vectors */
1807 /* queue 0 uses two msix vectors */
1808 if (ql2xmultique_tag) {
1809 cpus = num_online_cpus();
1810 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1811 (cpus + 1) : (ha->msix_count - 1);
1812 ha->max_req_queues = 2;
1813 } else if (ql2xmaxqueues > 1) {
1814 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1815 QLA_MQ_SIZE : ql2xmaxqueues;
1816 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1817 "QoS mode set, max no of request queues:%d.\n",
1818 ha->max_req_queues);
1819 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1820 "QoS mode set, max no of request queues:%d.\n",
1821 ha->max_req_queues);
1822 }
1823 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1824 "MSI-X vector count: %d.\n", msix);
1825 } else
1826 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1827 "BAR 1 not enabled.\n");
1828
1829mqiobase_exit:
1830 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001831
1832 qlt_83xx_iospace_config(ha);
1833
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001834 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1835 "MSIX Count:%d.\n", ha->msix_count);
1836 return 0;
1837
1838iospace_error_exit:
1839 return -ENOMEM;
1840}
1841
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001842static struct isp_operations qla2100_isp_ops = {
1843 .pci_config = qla2100_pci_config,
1844 .reset_chip = qla2x00_reset_chip,
1845 .chip_diag = qla2x00_chip_diag,
1846 .config_rings = qla2x00_config_rings,
1847 .reset_adapter = qla2x00_reset_adapter,
1848 .nvram_config = qla2x00_nvram_config,
1849 .update_fw_options = qla2x00_update_fw_options,
1850 .load_risc = qla2x00_load_risc,
1851 .pci_info_str = qla2x00_pci_info_str,
1852 .fw_version_str = qla2x00_fw_version_str,
1853 .intr_handler = qla2100_intr_handler,
1854 .enable_intrs = qla2x00_enable_intrs,
1855 .disable_intrs = qla2x00_disable_intrs,
1856 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001857 .target_reset = qla2x00_abort_target,
1858 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001859 .fabric_login = qla2x00_login_fabric,
1860 .fabric_logout = qla2x00_fabric_logout,
1861 .calc_req_entries = qla2x00_calc_iocbs_32,
1862 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1863 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1864 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1865 .read_nvram = qla2x00_read_nvram_data,
1866 .write_nvram = qla2x00_write_nvram_data,
1867 .fw_dump = qla2100_fw_dump,
1868 .beacon_on = NULL,
1869 .beacon_off = NULL,
1870 .beacon_blink = NULL,
1871 .read_optrom = qla2x00_read_optrom_data,
1872 .write_optrom = qla2x00_write_optrom_data,
1873 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001875 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001876 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001877 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001878};
1879
1880static struct isp_operations qla2300_isp_ops = {
1881 .pci_config = qla2300_pci_config,
1882 .reset_chip = qla2x00_reset_chip,
1883 .chip_diag = qla2x00_chip_diag,
1884 .config_rings = qla2x00_config_rings,
1885 .reset_adapter = qla2x00_reset_adapter,
1886 .nvram_config = qla2x00_nvram_config,
1887 .update_fw_options = qla2x00_update_fw_options,
1888 .load_risc = qla2x00_load_risc,
1889 .pci_info_str = qla2x00_pci_info_str,
1890 .fw_version_str = qla2x00_fw_version_str,
1891 .intr_handler = qla2300_intr_handler,
1892 .enable_intrs = qla2x00_enable_intrs,
1893 .disable_intrs = qla2x00_disable_intrs,
1894 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001895 .target_reset = qla2x00_abort_target,
1896 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001897 .fabric_login = qla2x00_login_fabric,
1898 .fabric_logout = qla2x00_fabric_logout,
1899 .calc_req_entries = qla2x00_calc_iocbs_32,
1900 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1901 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1902 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1903 .read_nvram = qla2x00_read_nvram_data,
1904 .write_nvram = qla2x00_write_nvram_data,
1905 .fw_dump = qla2300_fw_dump,
1906 .beacon_on = qla2x00_beacon_on,
1907 .beacon_off = qla2x00_beacon_off,
1908 .beacon_blink = qla2x00_beacon_blink,
1909 .read_optrom = qla2x00_read_optrom_data,
1910 .write_optrom = qla2x00_write_optrom_data,
1911 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001913 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001914 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001915 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001916};
1917
1918static struct isp_operations qla24xx_isp_ops = {
1919 .pci_config = qla24xx_pci_config,
1920 .reset_chip = qla24xx_reset_chip,
1921 .chip_diag = qla24xx_chip_diag,
1922 .config_rings = qla24xx_config_rings,
1923 .reset_adapter = qla24xx_reset_adapter,
1924 .nvram_config = qla24xx_nvram_config,
1925 .update_fw_options = qla24xx_update_fw_options,
1926 .load_risc = qla24xx_load_risc,
1927 .pci_info_str = qla24xx_pci_info_str,
1928 .fw_version_str = qla24xx_fw_version_str,
1929 .intr_handler = qla24xx_intr_handler,
1930 .enable_intrs = qla24xx_enable_intrs,
1931 .disable_intrs = qla24xx_disable_intrs,
1932 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001933 .target_reset = qla24xx_abort_target,
1934 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001935 .fabric_login = qla24xx_login_fabric,
1936 .fabric_logout = qla24xx_fabric_logout,
1937 .calc_req_entries = NULL,
1938 .build_iocbs = NULL,
1939 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1940 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1941 .read_nvram = qla24xx_read_nvram_data,
1942 .write_nvram = qla24xx_write_nvram_data,
1943 .fw_dump = qla24xx_fw_dump,
1944 .beacon_on = qla24xx_beacon_on,
1945 .beacon_off = qla24xx_beacon_off,
1946 .beacon_blink = qla24xx_beacon_blink,
1947 .read_optrom = qla24xx_read_optrom_data,
1948 .write_optrom = qla24xx_write_optrom_data,
1949 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001951 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001952 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001953 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001954};
1955
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001956static struct isp_operations qla25xx_isp_ops = {
1957 .pci_config = qla25xx_pci_config,
1958 .reset_chip = qla24xx_reset_chip,
1959 .chip_diag = qla24xx_chip_diag,
1960 .config_rings = qla24xx_config_rings,
1961 .reset_adapter = qla24xx_reset_adapter,
1962 .nvram_config = qla24xx_nvram_config,
1963 .update_fw_options = qla24xx_update_fw_options,
1964 .load_risc = qla24xx_load_risc,
1965 .pci_info_str = qla24xx_pci_info_str,
1966 .fw_version_str = qla24xx_fw_version_str,
1967 .intr_handler = qla24xx_intr_handler,
1968 .enable_intrs = qla24xx_enable_intrs,
1969 .disable_intrs = qla24xx_disable_intrs,
1970 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001971 .target_reset = qla24xx_abort_target,
1972 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001973 .fabric_login = qla24xx_login_fabric,
1974 .fabric_logout = qla24xx_fabric_logout,
1975 .calc_req_entries = NULL,
1976 .build_iocbs = NULL,
1977 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1978 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1979 .read_nvram = qla25xx_read_nvram_data,
1980 .write_nvram = qla25xx_write_nvram_data,
1981 .fw_dump = qla25xx_fw_dump,
1982 .beacon_on = qla24xx_beacon_on,
1983 .beacon_off = qla24xx_beacon_off,
1984 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001985 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001986 .write_optrom = qla24xx_write_optrom_data,
1987 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001988 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001989 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001990 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001991 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001992};
1993
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001994static struct isp_operations qla81xx_isp_ops = {
1995 .pci_config = qla25xx_pci_config,
1996 .reset_chip = qla24xx_reset_chip,
1997 .chip_diag = qla24xx_chip_diag,
1998 .config_rings = qla24xx_config_rings,
1999 .reset_adapter = qla24xx_reset_adapter,
2000 .nvram_config = qla81xx_nvram_config,
2001 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002002 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002003 .pci_info_str = qla24xx_pci_info_str,
2004 .fw_version_str = qla24xx_fw_version_str,
2005 .intr_handler = qla24xx_intr_handler,
2006 .enable_intrs = qla24xx_enable_intrs,
2007 .disable_intrs = qla24xx_disable_intrs,
2008 .abort_command = qla24xx_abort_command,
2009 .target_reset = qla24xx_abort_target,
2010 .lun_reset = qla24xx_lun_reset,
2011 .fabric_login = qla24xx_login_fabric,
2012 .fabric_logout = qla24xx_fabric_logout,
2013 .calc_req_entries = NULL,
2014 .build_iocbs = NULL,
2015 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2016 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002017 .read_nvram = NULL,
2018 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002019 .fw_dump = qla81xx_fw_dump,
2020 .beacon_on = qla24xx_beacon_on,
2021 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002022 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002023 .read_optrom = qla25xx_read_optrom_data,
2024 .write_optrom = qla24xx_write_optrom_data,
2025 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002026 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002027 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002028 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002029 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002030};
2031
2032static struct isp_operations qla82xx_isp_ops = {
2033 .pci_config = qla82xx_pci_config,
2034 .reset_chip = qla82xx_reset_chip,
2035 .chip_diag = qla24xx_chip_diag,
2036 .config_rings = qla82xx_config_rings,
2037 .reset_adapter = qla24xx_reset_adapter,
2038 .nvram_config = qla81xx_nvram_config,
2039 .update_fw_options = qla24xx_update_fw_options,
2040 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002041 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002042 .fw_version_str = qla24xx_fw_version_str,
2043 .intr_handler = qla82xx_intr_handler,
2044 .enable_intrs = qla82xx_enable_intrs,
2045 .disable_intrs = qla82xx_disable_intrs,
2046 .abort_command = qla24xx_abort_command,
2047 .target_reset = qla24xx_abort_target,
2048 .lun_reset = qla24xx_lun_reset,
2049 .fabric_login = qla24xx_login_fabric,
2050 .fabric_logout = qla24xx_fabric_logout,
2051 .calc_req_entries = NULL,
2052 .build_iocbs = NULL,
2053 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2054 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2055 .read_nvram = qla24xx_read_nvram_data,
2056 .write_nvram = qla24xx_write_nvram_data,
2057 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002058 .beacon_on = qla82xx_beacon_on,
2059 .beacon_off = qla82xx_beacon_off,
2060 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002061 .read_optrom = qla82xx_read_optrom_data,
2062 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002063 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002064 .start_scsi = qla82xx_start_scsi,
2065 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002066 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002067 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002068};
2069
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002070static struct isp_operations qla8044_isp_ops = {
2071 .pci_config = qla82xx_pci_config,
2072 .reset_chip = qla82xx_reset_chip,
2073 .chip_diag = qla24xx_chip_diag,
2074 .config_rings = qla82xx_config_rings,
2075 .reset_adapter = qla24xx_reset_adapter,
2076 .nvram_config = qla81xx_nvram_config,
2077 .update_fw_options = qla24xx_update_fw_options,
2078 .load_risc = qla82xx_load_risc,
2079 .pci_info_str = qla24xx_pci_info_str,
2080 .fw_version_str = qla24xx_fw_version_str,
2081 .intr_handler = qla8044_intr_handler,
2082 .enable_intrs = qla82xx_enable_intrs,
2083 .disable_intrs = qla82xx_disable_intrs,
2084 .abort_command = qla24xx_abort_command,
2085 .target_reset = qla24xx_abort_target,
2086 .lun_reset = qla24xx_lun_reset,
2087 .fabric_login = qla24xx_login_fabric,
2088 .fabric_logout = qla24xx_fabric_logout,
2089 .calc_req_entries = NULL,
2090 .build_iocbs = NULL,
2091 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2092 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2093 .read_nvram = NULL,
2094 .write_nvram = NULL,
2095 .fw_dump = qla24xx_fw_dump,
2096 .beacon_on = qla82xx_beacon_on,
2097 .beacon_off = qla82xx_beacon_off,
2098 .beacon_blink = NULL,
2099 .read_optrom = qla82xx_read_optrom_data,
2100 .write_optrom = qla8044_write_optrom_data,
2101 .get_flash_version = qla82xx_get_flash_version,
2102 .start_scsi = qla82xx_start_scsi,
2103 .abort_isp = qla8044_abort_isp,
2104 .iospace_config = qla82xx_iospace_config,
2105 .initialize_adapter = qla2x00_initialize_adapter,
2106};
2107
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002108static struct isp_operations qla83xx_isp_ops = {
2109 .pci_config = qla25xx_pci_config,
2110 .reset_chip = qla24xx_reset_chip,
2111 .chip_diag = qla24xx_chip_diag,
2112 .config_rings = qla24xx_config_rings,
2113 .reset_adapter = qla24xx_reset_adapter,
2114 .nvram_config = qla81xx_nvram_config,
2115 .update_fw_options = qla81xx_update_fw_options,
2116 .load_risc = qla81xx_load_risc,
2117 .pci_info_str = qla24xx_pci_info_str,
2118 .fw_version_str = qla24xx_fw_version_str,
2119 .intr_handler = qla24xx_intr_handler,
2120 .enable_intrs = qla24xx_enable_intrs,
2121 .disable_intrs = qla24xx_disable_intrs,
2122 .abort_command = qla24xx_abort_command,
2123 .target_reset = qla24xx_abort_target,
2124 .lun_reset = qla24xx_lun_reset,
2125 .fabric_login = qla24xx_login_fabric,
2126 .fabric_logout = qla24xx_fabric_logout,
2127 .calc_req_entries = NULL,
2128 .build_iocbs = NULL,
2129 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2130 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2131 .read_nvram = NULL,
2132 .write_nvram = NULL,
2133 .fw_dump = qla83xx_fw_dump,
2134 .beacon_on = qla24xx_beacon_on,
2135 .beacon_off = qla24xx_beacon_off,
2136 .beacon_blink = qla83xx_beacon_blink,
2137 .read_optrom = qla25xx_read_optrom_data,
2138 .write_optrom = qla24xx_write_optrom_data,
2139 .get_flash_version = qla24xx_get_flash_version,
2140 .start_scsi = qla24xx_dif_start_scsi,
2141 .abort_isp = qla2x00_abort_isp,
2142 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002143 .initialize_adapter = qla2x00_initialize_adapter,
2144};
2145
2146static struct isp_operations qlafx00_isp_ops = {
2147 .pci_config = qlafx00_pci_config,
2148 .reset_chip = qlafx00_soft_reset,
2149 .chip_diag = qlafx00_chip_diag,
2150 .config_rings = qlafx00_config_rings,
2151 .reset_adapter = qlafx00_soft_reset,
2152 .nvram_config = NULL,
2153 .update_fw_options = NULL,
2154 .load_risc = NULL,
2155 .pci_info_str = qlafx00_pci_info_str,
2156 .fw_version_str = qlafx00_fw_version_str,
2157 .intr_handler = qlafx00_intr_handler,
2158 .enable_intrs = qlafx00_enable_intrs,
2159 .disable_intrs = qlafx00_disable_intrs,
2160 .abort_command = qlafx00_abort_command,
2161 .target_reset = qlafx00_abort_target,
2162 .lun_reset = qlafx00_lun_reset,
2163 .fabric_login = NULL,
2164 .fabric_logout = NULL,
2165 .calc_req_entries = NULL,
2166 .build_iocbs = NULL,
2167 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2168 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2169 .read_nvram = qla24xx_read_nvram_data,
2170 .write_nvram = qla24xx_write_nvram_data,
2171 .fw_dump = NULL,
2172 .beacon_on = qla24xx_beacon_on,
2173 .beacon_off = qla24xx_beacon_off,
2174 .beacon_blink = NULL,
2175 .read_optrom = qla24xx_read_optrom_data,
2176 .write_optrom = qla24xx_write_optrom_data,
2177 .get_flash_version = qla24xx_get_flash_version,
2178 .start_scsi = qlafx00_start_scsi,
2179 .abort_isp = qlafx00_abort_isp,
2180 .iospace_config = qlafx00_iospace_config,
2181 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002182};
2183
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002184static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002185qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002186{
2187 ha->device_type = DT_EXTENDED_IDS;
2188 switch (ha->pdev->device) {
2189 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2190 ha->device_type |= DT_ISP2100;
2191 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002192 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002193 break;
2194 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2195 ha->device_type |= DT_ISP2200;
2196 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002197 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002198 break;
2199 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2200 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002201 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002202 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002203 break;
2204 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2205 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002206 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002207 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002208 break;
2209 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2210 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002211 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002212 if (ha->pdev->subsystem_vendor == 0x1028 &&
2213 ha->pdev->subsystem_device == 0x0170)
2214 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002215 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002216 break;
2217 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2218 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002219 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002220 break;
2221 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2222 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002223 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002224 break;
2225 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2226 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002227 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002228 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002229 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002230 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002231 break;
2232 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2233 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002234 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002235 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002236 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002237 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002238 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002239 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2240 ha->device_type |= DT_ISP8432;
2241 ha->device_type |= DT_ZIO_SUPPORTED;
2242 ha->device_type |= DT_FWI2;
2243 ha->device_type |= DT_IIDMA;
2244 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2245 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002246 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2247 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002248 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002249 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002250 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002251 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2252 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002253 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002254 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002255 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002256 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2257 ha->device_type |= DT_ISP2532;
2258 ha->device_type |= DT_ZIO_SUPPORTED;
2259 ha->device_type |= DT_FWI2;
2260 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002261 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2262 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002263 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2264 ha->device_type |= DT_ISP8001;
2265 ha->device_type |= DT_ZIO_SUPPORTED;
2266 ha->device_type |= DT_FWI2;
2267 ha->device_type |= DT_IIDMA;
2268 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2269 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002270 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2271 ha->device_type |= DT_ISP8021;
2272 ha->device_type |= DT_ZIO_SUPPORTED;
2273 ha->device_type |= DT_FWI2;
2274 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2275 /* Initialize 82XX ISP flags */
2276 qla82xx_init_flags(ha);
2277 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002278 case PCI_DEVICE_ID_QLOGIC_ISP8044:
2279 ha->device_type |= DT_ISP8044;
2280 ha->device_type |= DT_ZIO_SUPPORTED;
2281 ha->device_type |= DT_FWI2;
2282 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2283 /* Initialize 82XX ISP flags */
2284 qla82xx_init_flags(ha);
2285 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002286 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2287 ha->device_type |= DT_ISP2031;
2288 ha->device_type |= DT_ZIO_SUPPORTED;
2289 ha->device_type |= DT_FWI2;
2290 ha->device_type |= DT_IIDMA;
2291 ha->device_type |= DT_T10_PI;
2292 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2293 break;
2294 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2295 ha->device_type |= DT_ISP8031;
2296 ha->device_type |= DT_ZIO_SUPPORTED;
2297 ha->device_type |= DT_FWI2;
2298 ha->device_type |= DT_IIDMA;
2299 ha->device_type |= DT_T10_PI;
2300 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2301 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002302 case PCI_DEVICE_ID_QLOGIC_ISPF001:
2303 ha->device_type |= DT_ISPFX00;
2304 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002305 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002306
Giridhar Malavalia9083012010-04-12 17:59:55 -07002307 if (IS_QLA82XX(ha))
2308 ha->port_no = !(ha->portnum & 1);
2309 else
2310 /* Get adapter physical port no from interrupt pin register. */
2311 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2312
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002313 if (ha->port_no & 1)
2314 ha->flags.port0 = 1;
2315 else
2316 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002317 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002318 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002319 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002320}
2321
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002322static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002323qla2xxx_scan_start(struct Scsi_Host *shost)
2324{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002326
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002327 if (vha->hw->flags.running_gold_fw)
2328 return;
2329
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2331 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2332 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2333 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002334}
2335
2336static int
2337qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2338{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002339 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002340
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002342 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002343 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002344 return 1;
2345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002346 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002347}
2348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349/*
2350 * PCI driver interface
2351 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002352static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002353qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002355 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002357 scsi_qla_host_t *base_vha = NULL;
2358 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002359 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002360 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002361 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002362 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002364 struct req_que *req = NULL;
2365 struct rsp_que *rsp = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002366 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002367 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002368 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2369 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002370 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002371 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2372 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002373 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002374 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002375 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2376 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002377 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002378 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2379 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002380 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002381 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002382 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2383 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002384 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002385 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2386 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002387
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002388 if (mem_only) {
2389 if (pci_enable_device_mem(pdev))
2390 goto probe_out;
2391 } else {
2392 if (pci_enable_device(pdev))
2393 goto probe_out;
2394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
Jesse Barnes09276782008-10-18 17:33:19 -07002396 /* This may fail but that's ok */
2397 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002398
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002399 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2400 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002401 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2402 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002405 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2406 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002408 ha->tgt.enable_class_2 = ql2xenableclass2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
2410 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002411 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002412 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002413 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002414 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -04002415 mutex_init(&ha->selflogin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002417 /* Set ISP-type information. */
2418 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002419
2420 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002421 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2422 IS_QLA83XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002423 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002424
Chad Dupuiscba1e472011-11-18 09:03:21 -08002425 ha->prev_topology = 0;
2426 ha->init_cb_size = sizeof(init_cb_t);
2427 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2428 ha->optrom_size = OPTROM_SIZE_2300;
Chad Dupuis3c290d02013-01-30 03:34:38 -05002429 ha->cfg_lun_q_depth = ql2xmaxqdepth;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002430
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002431 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002433 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002435 req_length = REQUEST_ENTRY_CNT_2100;
2436 rsp_length = RESPONSE_ENTRY_CNT_2100;
2437 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002438 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002439 ha->flash_conf_off = ~0;
2440 ha->flash_data_off = ~0;
2441 ha->nvram_conf_off = ~0;
2442 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002443 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002445 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002446 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 req_length = REQUEST_ENTRY_CNT_2200;
2448 rsp_length = RESPONSE_ENTRY_CNT_2100;
2449 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002450 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002451 ha->flash_conf_off = ~0;
2452 ha->flash_data_off = ~0;
2453 ha->nvram_conf_off = ~0;
2454 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002455 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002456 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002457 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 req_length = REQUEST_ENTRY_CNT_2200;
2460 rsp_length = RESPONSE_ENTRY_CNT_2300;
2461 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002462 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002463 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2464 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002465 ha->flash_conf_off = ~0;
2466 ha->flash_data_off = ~0;
2467 ha->nvram_conf_off = ~0;
2468 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002469 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002470 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002471 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002472 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 req_length = REQUEST_ENTRY_CNT_24XX;
2474 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002475 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002477 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002478 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002479 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002480 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002481 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002482 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2483 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2484 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2485 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002486 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002487 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002488 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 req_length = REQUEST_ENTRY_CNT_24XX;
2490 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002491 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002493 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002494 ha->gid_list_info_size = 8;
2495 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002496 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002497 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002498 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2499 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2500 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2501 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2502 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002503 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002504 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2505 req_length = REQUEST_ENTRY_CNT_24XX;
2506 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002507 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002508 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2509 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2510 ha->gid_list_info_size = 8;
2511 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002512 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002513 ha->isp_ops = &qla81xx_isp_ops;
2514 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2515 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2516 ha->nvram_conf_off = ~0;
2517 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002518 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002519 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002520 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2521 req_length = REQUEST_ENTRY_CNT_82XX;
2522 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2523 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2524 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2525 ha->gid_list_info_size = 8;
2526 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002527 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002528 ha->isp_ops = &qla82xx_isp_ops;
2529 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2530 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2531 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2532 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002533 } else if (IS_QLA8044(ha)) {
2534 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2535 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2536 req_length = REQUEST_ENTRY_CNT_82XX;
2537 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2538 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2539 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2540 ha->gid_list_info_size = 8;
2541 ha->optrom_size = OPTROM_SIZE_83XX;
2542 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2543 ha->isp_ops = &qla8044_isp_ops;
2544 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2545 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2546 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2547 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002548 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002549 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002550 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002551 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2552 req_length = REQUEST_ENTRY_CNT_24XX;
2553 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002554 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002555 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2556 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2557 ha->gid_list_info_size = 8;
2558 ha->optrom_size = OPTROM_SIZE_83XX;
2559 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2560 ha->isp_ops = &qla83xx_isp_ops;
2561 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2562 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2563 ha->nvram_conf_off = ~0;
2564 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002565 } else if (IS_QLAFX00(ha)) {
2566 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2567 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2568 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2569 req_length = REQUEST_ENTRY_CNT_FX00;
2570 rsp_length = RESPONSE_ENTRY_CNT_FX00;
2571 ha->init_cb_size = sizeof(struct init_cb_fx);
2572 ha->isp_ops = &qlafx00_isp_ops;
2573 ha->port_down_retry_count = 30; /* default value */
2574 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2575 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
2576 ha->mr.fw_hbt_en = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002578
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002579 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2580 "mbx_count=%d, req_length=%d, "
2581 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002582 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2583 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002584 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2585 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002586 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002587 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2588 "isp_ops=%p, flash_conf_off=%d, "
2589 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2590 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2591 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002592
2593 /* Configure PCI I/O space */
2594 ret = ha->isp_ops->iospace_config(ha);
2595 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002596 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002597
2598 ql_log_pci(ql_log_info, pdev, 0x001d,
2599 "Found an ISP%04X irq %d iobase 0x%p.\n",
2600 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002601 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002602 init_completion(&ha->mbx_cmd_comp);
2603 complete(&ha->mbx_cmd_comp);
2604 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002605 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002606 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002608 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609
Andrew Vasquez53303c42009-01-22 09:45:37 -08002610 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002611 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2612 "64 Bit addressing is %s.\n",
2613 ha->flags.enable_64bit_addressing ? "enable" :
2614 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002615 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002617 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2618 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 goto probe_hw_failed;
2621 }
2622
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002623 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002625 req->max_q_depth = ql2xmaxqdepth;
2626
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627
2628 base_vha = qla2x00_create_host(sht, ha);
2629 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002630 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002631 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002632 qla2x00_free_req_que(ha, req);
2633 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 }
2636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002640 base_vha->req = req;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002641 if (IS_QLAFX00(ha))
2642 host->can_queue = 1024;
2643 else
2644 host->can_queue = req->length + 128;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002645 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002647 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2649 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002650
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002651 /* Setup fcport template structure. */
2652 ha->mr.fcport.vha = base_vha;
2653 ha->mr.fcport.port_type = FCT_UNKNOWN;
2654 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2655 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2656 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2657 ha->mr.fcport.scan_state = 1;
2658
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002659 /* Set the SG table size based on ISP type */
2660 if (!IS_FWI2_CAPABLE(ha)) {
2661 if (IS_QLA2100(ha))
2662 host->sg_tablesize = 32;
2663 } else {
2664 if (!IS_QLA82XX(ha))
2665 host->sg_tablesize = QLA_SG_ALL;
2666 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002667 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2668 "can_queue=%d, req=%p, "
2669 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2670 host->can_queue, base_vha->req,
2671 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Chad Dupuis642ef982012-02-09 11:15:57 -08002672 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002673 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002674 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002675 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002676 host->max_cmd_len = 32;
2677 else
2678 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002679 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002680 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002681 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002682 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002683
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002684 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2685 "max_id=%d this_id=%d "
2686 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002687 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002688 host->this_id, host->cmd_per_lun, host->unique_id,
2689 host->max_cmd_len, host->max_channel, host->max_lun,
2690 host->transportt, sht->vendor_id);
2691
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002692que_init:
2693 /* Alloc arrays of request and response ring ptrs */
2694 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2695 ql_log(ql_log_fatal, base_vha, 0x003d,
2696 "Failed to allocate memory for queue pointers..."
2697 "aborting.\n");
2698 goto probe_init_failed;
2699 }
2700
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002701 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002702
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002703 /* Set up the irqs */
2704 ret = qla2x00_request_irqs(ha, rsp);
2705 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002706 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002707
2708 pci_save_state(pdev);
2709
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002710 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002711 rsp->req = req;
2712 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002713
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002714 if (IS_QLAFX00(ha)) {
2715 ha->rsp_q_map[0] = rsp;
2716 ha->req_q_map[0] = req;
2717 set_bit(0, ha->req_qid_map);
2718 set_bit(0, ha->rsp_qid_map);
2719 }
2720
Andrew Vasquez08029992009-03-24 09:07:55 -07002721 /* FWI2-capable only. */
2722 req->req_q_in = &ha->iobase->isp24.req_q_in;
2723 req->req_q_out = &ha->iobase->isp24.req_q_out;
2724 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2725 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002726 if (ha->mqenable || IS_QLA83XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002727 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2728 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2729 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2730 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002731 }
2732
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002733 if (IS_QLAFX00(ha)) {
2734 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2735 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2736 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2737 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2738 }
2739
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002740 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002741 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2742 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2743 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2744 }
2745
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002746 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2747 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2748 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2749 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2750 "req->req_q_in=%p req->req_q_out=%p "
2751 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2752 req->req_q_in, req->req_q_out,
2753 rsp->rsp_q_in, rsp->rsp_q_out);
2754 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2755 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2756 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2757 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2758 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2759 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002761 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002762 ql_log(ql_log_fatal, base_vha, 0x00d6,
2763 "Failed to initialize adapter - Adapter flags %x.\n",
2764 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765
Giridhar Malavalia9083012010-04-12 17:59:55 -07002766 if (IS_QLA82XX(ha)) {
2767 qla82xx_idc_lock(ha);
2768 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002769 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002770 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002771 ql_log(ql_log_fatal, base_vha, 0x00d7,
2772 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002773 } else if (IS_QLA8044(ha)) {
2774 qla8044_idc_lock(ha);
2775 qla8044_wr_direct(base_vha,
2776 QLA8044_CRB_DEV_STATE_INDEX,
2777 QLA8XXX_DEV_FAILED);
2778 qla8044_idc_unlock(ha);
2779 ql_log(ql_log_fatal, base_vha, 0x0150,
2780 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002781 }
2782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783 ret = -ENODEV;
2784 goto probe_failed;
2785 }
2786
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002787 if (ha->mqenable) {
2788 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002789 ql_log(ql_log_warn, base_vha, 0x00ec,
2790 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002791 goto que_init;
2792 }
2793 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002794
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002795 if (ha->flags.running_gold_fw)
2796 goto skip_dpc;
2797
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 /*
2799 * Startup the kernel thread for this host adapter
2800 */
2801 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002802 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002803 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002804 ql_log(ql_log_fatal, base_vha, 0x00ed,
2805 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002806 ret = PTR_ERR(ha->dpc_thread);
2807 goto probe_failed;
2808 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002809 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2810 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002812 /*
2813 * If we're not coming up in initiator mode, we might sit for
2814 * a while without waking up the dpc thread, which leads to a
2815 * stuck process warning. So just kick the dpc once here and
2816 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2817 */
2818 qla2xxx_wake_dpc(base_vha);
2819
Saurav Kashyap81178772012-08-22 14:21:04 -04002820 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2821 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2822 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2823 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2824
2825 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2826 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2827 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2828 INIT_WORK(&ha->idc_state_handler,
2829 qla83xx_idc_state_handler_work);
2830 INIT_WORK(&ha->nic_core_unrecoverable,
2831 qla83xx_nic_core_unrecoverable_work);
2832 }
2833
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002834skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 list_add_tail(&base_vha->list, &ha->vp_list);
2836 base_vha->host->irq = ha->pdev->irq;
2837
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002840 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2841 "Started qla2x00_timer with "
2842 "interval=%d.\n", WATCH_INTERVAL);
2843 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2844 "Detected hba at address=%p.\n",
2845 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
Arun Easie02587d2011-08-16 11:29:23 -07002847 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002848 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002849 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002850 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002851 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2852 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002853 if (ql2xenabledif == 1)
2854 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002855 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002856 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002857 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002858 | SHOST_DIF_TYPE3_PROTECTION
2859 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002860 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002861 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002862
2863 guard = SHOST_DIX_GUARD_CRC;
2864
2865 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2866 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2867 guard |= SHOST_DIX_GUARD_IP;
2868
2869 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002870 } else
2871 base_vha->flags.difdix_supported = 0;
2872 }
2873
Giridhar Malavalia9083012010-04-12 17:59:55 -07002874 ha->isp_ops->enable_intrs(ha);
2875
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002876 ret = scsi_add_host(host, &pdev->dev);
2877 if (ret)
2878 goto probe_failed;
2879
Michael Reed14864002009-12-02 09:11:16 -06002880 base_vha->flags.init_done = 1;
2881 base_vha->flags.online = 1;
2882
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002883 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2884 "Init done and hba is online.\n");
2885
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002886 if (qla_ini_mode_enabled(base_vha))
2887 scsi_scan_host(host);
2888 else
2889 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2890 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002893
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002894 if (IS_QLAFX00(ha)) {
2895 ret = qlafx00_fx_disc(base_vha,
2896 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
2897
2898 ret = qlafx00_fx_disc(base_vha,
2899 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
2900
2901 /* Register system information */
2902 ret = qlafx00_fx_disc(base_vha,
2903 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
2904 }
2905
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002906 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002907
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002909
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002910 ql_log(ql_log_info, base_vha, 0x00fb,
Bart Van Asschec5dcfaa2013-06-25 11:27:25 -04002911 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002912 ql_log(ql_log_info, base_vha, 0x00fc,
2913 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2914 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2915 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2916 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002919 qlt_add_target(ha, base_vha);
2920
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 return 0;
2922
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002923probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002924 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002925 ha->req_q_map[0] = NULL;
2926 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002927 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002928 ha->rsp_q_map[0] = NULL;
2929 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002930 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002931
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002933 if (base_vha->timer_active)
2934 qla2x00_stop_timer(base_vha);
2935 base_vha->flags.online = 0;
2936 if (ha->dpc_thread) {
2937 struct task_struct *t = ha->dpc_thread;
2938
2939 ha->dpc_thread = NULL;
2940 kthread_stop(t);
2941 }
2942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002948 if (IS_QLA82XX(ha)) {
2949 qla82xx_idc_lock(ha);
2950 qla82xx_clear_drv_active(ha);
2951 qla82xx_idc_unlock(ha);
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002952 }
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002953 if (IS_QLA8044(ha)) {
2954 qla8044_idc_lock(ha);
2955 qla8044_clear_drv_active(base_vha);
2956 qla8044_idc_unlock(ha);
2957 }
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002958iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002959 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002960 if (!ha->nx_pcibase)
2961 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002962 if (!ql2xdbwr)
2963 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2964 } else {
2965 if (ha->iobase)
2966 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002967 if (ha->cregbase)
2968 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002969 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 pci_release_selected_regions(ha->pdev, ha->bars);
2971 kfree(ha);
2972 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002974probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002976 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
Adrian Bunk4c993f72008-01-14 00:55:16 -08002979static void
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002980qla2x00_stop_dpc_thread(scsi_qla_host_t *vha)
2981{
2982 struct qla_hw_data *ha = vha->hw;
2983 struct task_struct *t = ha->dpc_thread;
2984
2985 if (ha->dpc_thread == NULL)
2986 return;
2987 /*
2988 * qla2xxx_wake_dpc checks for ->dpc_thread
2989 * so we need to zero it out.
2990 */
2991 ha->dpc_thread = NULL;
2992 kthread_stop(t);
2993}
2994
2995static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002996qla2x00_shutdown(struct pci_dev *pdev)
2997{
2998 scsi_qla_host_t *vha;
2999 struct qla_hw_data *ha;
3000
Masanari Iida552f3f92013-02-08 01:57:44 -05003001 if (!atomic_read(&pdev->enable_cnt))
3002 return;
3003
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003004 vha = pci_get_drvdata(pdev);
3005 ha = vha->hw;
3006
3007 /* Turn-off FCE trace */
3008 if (ha->flags.fce_enabled) {
3009 qla2x00_disable_fce_trace(vha, NULL, NULL);
3010 ha->flags.fce_enabled = 0;
3011 }
3012
3013 /* Turn-off EFT trace */
3014 if (ha->eft)
3015 qla2x00_disable_eft_trace(vha);
3016
3017 /* Stop currently executing firmware. */
3018 qla2x00_try_to_stop_firmware(vha);
3019
3020 /* Turn adapter off line */
3021 vha->flags.online = 0;
3022
3023 /* turn-off interrupts on the card */
3024 if (ha->interrupts_on) {
3025 vha->flags.init_done = 0;
3026 ha->isp_ops->disable_intrs(ha);
3027 }
3028
3029 qla2x00_free_irqs(vha);
3030
3031 qla2x00_free_fw_dump(ha);
3032}
3033
3034static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003035qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036{
Arun Easifeafb7b2010-09-03 14:57:00 -07003037 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003039 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003041 /*
3042 * If the PCI device is disabled that means that probe failed and any
3043 * resources should be have cleaned up on probe exit.
3044 */
3045 if (!atomic_read(&pdev->enable_cnt))
3046 return;
3047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 base_vha = pci_get_drvdata(pdev);
3049 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003051 ha->flags.host_shutting_down = 1;
3052
Giridhar Malavali220d36b2012-11-21 02:39:55 -05003053 set_bit(UNLOADING, &base_vha->dpc_flags);
Arun Easi43ebf162011-05-10 11:18:16 -07003054 mutex_lock(&ha->vport_lock);
3055 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003056 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003057
Arun Easi43ebf162011-05-10 11:18:16 -07003058 BUG_ON(base_vha->list.next == &ha->vp_list);
3059 /* This assumes first entry in ha->vp_list is always base vha */
3060 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche6e97c9d2013-06-25 11:27:30 -04003061 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003062
Arun Easi43ebf162011-05-10 11:18:16 -07003063 spin_unlock_irqrestore(&ha->vport_slock, flags);
3064 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003065
Arun Easi43ebf162011-05-10 11:18:16 -07003066 fc_vport_terminate(vha->fc_vport);
3067 scsi_host_put(vha->host);
3068
3069 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003070 }
Arun Easi43ebf162011-05-10 11:18:16 -07003071 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003072
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003073 if (IS_QLA8031(ha)) {
3074 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3075 "Clearing fcoe driver presence.\n");
3076 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3077 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3078 "Error while clearing DRV-Presence.\n");
3079 }
3080
Andrew Vasquezb9978762009-03-24 09:08:05 -07003081 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3082
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003083 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003084
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003085 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003086
Andrew Vasquezb9978762009-03-24 09:08:05 -07003087 /* Disable timer */
3088 if (base_vha->timer_active)
3089 qla2x00_stop_timer(base_vha);
3090
3091 base_vha->flags.online = 0;
3092
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003093 /* Flush the work queue and remove it */
3094 if (ha->wq) {
3095 flush_workqueue(ha->wq);
3096 destroy_workqueue(ha->wq);
3097 ha->wq = NULL;
3098 }
3099
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003100 /* Cancel all work and destroy DPC workqueues */
3101 if (ha->dpc_lp_wq) {
3102 cancel_work_sync(&ha->idc_aen);
3103 destroy_workqueue(ha->dpc_lp_wq);
3104 ha->dpc_lp_wq = NULL;
3105 }
3106
3107 if (ha->dpc_hp_wq) {
3108 cancel_work_sync(&ha->nic_core_reset);
3109 cancel_work_sync(&ha->idc_state_handler);
3110 cancel_work_sync(&ha->nic_core_unrecoverable);
3111 destroy_workqueue(ha->dpc_hp_wq);
3112 ha->dpc_hp_wq = NULL;
3113 }
3114
Andrew Vasquezb9978762009-03-24 09:08:05 -07003115 /* Kill the kernel thread for this host */
3116 if (ha->dpc_thread) {
3117 struct task_struct *t = ha->dpc_thread;
3118
3119 /*
3120 * qla2xxx_wake_dpc checks for ->dpc_thread
3121 * so we need to zero it out.
3122 */
3123 ha->dpc_thread = NULL;
3124 kthread_stop(t);
3125 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003126 qlt_remove_target(ha, base_vha);
Andrew Vasquezb9978762009-03-24 09:08:05 -07003127
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05003131
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003132 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 scsi_host_put(base_vha->host);
3137
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003138 if (IS_QLA8044(ha)) {
3139 qla8044_idc_lock(ha);
3140 qla8044_clear_drv_active(base_vha);
3141 qla8044_idc_unlock(ha);
3142 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003143 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003144 qla82xx_idc_lock(ha);
3145 qla82xx_clear_drv_active(ha);
3146 qla82xx_idc_unlock(ha);
3147
Giridhar Malavalia9083012010-04-12 17:59:55 -07003148 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
3149 if (!ql2xdbwr)
3150 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
3151 } else {
3152 if (ha->iobase)
3153 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003154
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003155 if (ha->cregbase)
3156 iounmap(ha->cregbase);
3157
Giridhar Malavalia9083012010-04-12 17:59:55 -07003158 if (ha->mqiobase)
3159 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003160
3161 if (IS_QLA83XX(ha) && ha->msixbase)
3162 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003163 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003164
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 pci_release_selected_regions(ha->pdev, ha->bars);
3166 kfree(ha);
3167 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003169 pci_disable_pcie_error_reporting(pdev);
3170
Bernhard Walle665db932007-03-28 00:49:49 +02003171 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 pci_set_drvdata(pdev, NULL);
3173}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
3175static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003178 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
Andrew Vasquez85880802009-12-15 21:29:46 -08003180 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3181
3182 /* Disable timer */
3183 if (vha->timer_active)
3184 qla2x00_stop_timer(vha);
3185
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003186 qla2x00_stop_dpc_thread(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003187
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003188 qla25xx_delete_queues(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003189 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003191
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003192 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003194
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003195 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003196 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197
Andrew Vasquez85880802009-12-15 21:29:46 -08003198 vha->flags.online = 0;
3199
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003200 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003201 if (ha->interrupts_on) {
3202 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003203 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003204 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003206 qla2x00_free_irqs(vha);
3207
Chad Dupuis88670482010-07-23 15:28:30 +05003208 qla2x00_free_fcports(vha);
3209
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003210 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003211
Giridhar Malavali08de2842011-08-16 11:31:44 -07003212 qla82xx_md_free(vha);
3213
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003214 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215}
3216
Chad Dupuis88670482010-07-23 15:28:30 +05003217void qla2x00_free_fcports(struct scsi_qla_host *vha)
3218{
3219 fc_port_t *fcport, *tfcport;
3220
3221 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3222 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003223 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003224 kfree(fcport);
3225 fcport = NULL;
3226 }
3227}
3228
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003229static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003231 int defer)
3232{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003233 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003234 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003235 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003236
3237 if (!fcport->rport)
3238 return;
3239
3240 rport = fcport->rport;
3241 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003242 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003243 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003244 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003245 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003246 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3247 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003248 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003249 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003250 qlt_fc_port_deleted(vha, fcport);
3251 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003252}
3253
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3256 *
3257 * Input: ha = adapter block pointer. fcport = port structure pointer.
3258 *
3259 * Return: None.
3260 *
3261 * Context:
3262 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003264 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003266 if (IS_QLAFX00(vha->hw)) {
3267 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3268 qla2x00_schedule_rport_del(vha, fcport, defer);
3269 return;
3270 }
3271
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003272 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003273 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003274 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 qla2x00_schedule_rport_del(vha, fcport, defer);
3276 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003277 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 * We may need to retry the login, so don't change the state of the
3279 * port but do the retries.
3280 */
3281 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003282 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
3284 if (!do_login)
3285 return;
3286
3287 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003288 fcport->login_retry = vha->hw->login_retry_count;
3289 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003291 ql_dbg(ql_dbg_disc, vha, 0x2067,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003292 "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
3293 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 }
3295}
3296
3297/*
3298 * qla2x00_mark_all_devices_lost
3299 * Updates fcport state when device goes offline.
3300 *
3301 * Input:
3302 * ha = adapter block pointer.
3303 * fcport = port structure pointer.
3304 *
3305 * Return:
3306 * None.
3307 *
3308 * Context:
3309 */
3310void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003311qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312{
3313 fc_port_t *fcport;
3314
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003316 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003318
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 /*
3320 * No point in marking the device as lost, if the device is
3321 * already DEAD.
3322 */
3323 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3324 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003326 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003327 if (defer)
3328 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003329 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003330 qla2x00_schedule_rport_del(vha, fcport, defer);
3331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 }
3333}
3334
3335/*
3336* qla2x00_mem_alloc
3337* Allocates adapter memory.
3338*
3339* Returns:
3340* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003341* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003343static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003344qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3345 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346{
3347 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
Andrew Vasqueze8711082008-01-31 12:33:48 -08003349 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003351 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003354 if (qlt_mem_alloc(ha) < 0)
3355 goto fail_free_init_cb;
3356
Chad Dupuis642ef982012-02-09 11:15:57 -08003357 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3358 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003359 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003360 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
Andrew Vasqueze8711082008-01-31 12:33:48 -08003362 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3363 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003364 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003366 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003367 /* Allocate cache for CT6 Ctx. */
3368 if (!ctx_cachep) {
3369 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3370 sizeof(struct ct6_dsd), 0,
3371 SLAB_HWCACHE_ALIGN, NULL);
3372 if (!ctx_cachep)
3373 goto fail_free_gid_list;
3374 }
3375 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3376 ctx_cachep);
3377 if (!ha->ctx_mempool)
3378 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003379 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3380 "ctx_cachep=%p ctx_mempool=%p.\n",
3381 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003382 }
3383
Andrew Vasqueze8711082008-01-31 12:33:48 -08003384 /* Get memory for cached NVRAM */
3385 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3386 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003387 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3390 ha->pdev->device);
3391 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3392 DMA_POOL_SIZE, 8, 0);
3393 if (!ha->s_dma_pool)
3394 goto fail_free_nvram;
3395
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003396 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3397 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3398 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3399
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003400 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003401 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3402 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3403 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003404 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3405 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003406 goto fail_s_dma_pool;
3407 }
3408
3409 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3410 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3411 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003412 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3413 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003414 goto fail_dl_dma_pool;
3415 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003416 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3417 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3418 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003419 }
3420
Andrew Vasqueze8711082008-01-31 12:33:48 -08003421 /* Allocate memory for SNS commands */
3422 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003423 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003424 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003425 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003426 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003427 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003428 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003429 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003430 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003432 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003434 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003435 goto fail_dma_pool;
3436 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003437 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003438 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003439 if (!ha->ct_sns)
3440 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003441 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3442 "ms_iocb=%p ct_sns=%p.\n",
3443 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 }
3445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003447 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3448 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003449 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3450 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003451 goto fail_req;
3452 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003453 (*req)->length = req_len;
3454 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3455 ((*req)->length + 1) * sizeof(request_t),
3456 &(*req)->dma, GFP_KERNEL);
3457 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003458 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3459 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460 goto fail_req_ring;
3461 }
3462 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003463 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3464 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003465 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3466 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003467 goto fail_rsp;
3468 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003469 (*rsp)->hw = ha;
3470 (*rsp)->length = rsp_len;
3471 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3472 ((*rsp)->length + 1) * sizeof(response_t),
3473 &(*rsp)->dma, GFP_KERNEL);
3474 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003475 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3476 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 goto fail_rsp_ring;
3478 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003479 (*req)->rsp = *rsp;
3480 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003481 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3482 "req=%p req->length=%d req->ring=%p rsp=%p "
3483 "rsp->length=%d rsp->ring=%p.\n",
3484 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3485 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003486 /* Allocate memory for NVRAM data for vports */
3487 if (ha->nvram_npiv_size) {
3488 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003489 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003490 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003491 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3492 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003493 goto fail_npiv_info;
3494 }
3495 } else
3496 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003498 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003499 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003500 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3501 &ha->ex_init_cb_dma);
3502 if (!ha->ex_init_cb)
3503 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003504 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3505 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003506 }
3507
Giridhar Malavalia9083012010-04-12 17:59:55 -07003508 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3509
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003510 /* Get consistent memory allocated for Async Port-Database. */
3511 if (!IS_FWI2_CAPABLE(ha)) {
3512 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3513 &ha->async_pd_dma);
3514 if (!ha->async_pd)
3515 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003516 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3517 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003518 }
3519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003521
3522 /* Allocate memory for our loop_id bitmap */
3523 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3524 GFP_KERNEL);
3525 if (!ha->loop_id_map)
3526 goto fail_async_pd;
3527 else {
3528 qla2x00_set_reserved_loop_ids(ha);
3529 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
3530 "loop_id_map=%p. \n", ha->loop_id_map);
3531 }
3532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533 return 1;
3534
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003535fail_async_pd:
3536 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003537fail_ex_init_cb:
3538 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003539fail_npiv_info:
3540 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3541 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3542 (*rsp)->ring = NULL;
3543 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003544fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003545 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003546fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003547 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3548 sizeof(request_t), (*req)->ring, (*req)->dma);
3549 (*req)->ring = NULL;
3550 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003552 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003553fail_req:
3554 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3555 ha->ct_sns, ha->ct_sns_dma);
3556 ha->ct_sns = NULL;
3557 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003558fail_free_ms_iocb:
3559 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3560 ha->ms_iocb = NULL;
3561 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003563 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003564 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3565 ha->fcp_cmnd_dma_pool = NULL;
3566 }
3567fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003568 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003569 dma_pool_destroy(ha->dl_dma_pool);
3570 ha->dl_dma_pool = NULL;
3571 }
3572fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003573 dma_pool_destroy(ha->s_dma_pool);
3574 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003575fail_free_nvram:
3576 kfree(ha->nvram);
3577 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003578fail_free_ctx_mempool:
3579 mempool_destroy(ha->ctx_mempool);
3580 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003581fail_free_srb_mempool:
3582 mempool_destroy(ha->srb_mempool);
3583 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003584fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003585 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3586 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003588 ha->gid_list = NULL;
3589 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003590fail_free_tgt_mem:
3591 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592fail_free_init_cb:
3593 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3594 ha->init_cb_dma);
3595 ha->init_cb = NULL;
3596 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003597fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003598 ql_log(ql_log_fatal, NULL, 0x0030,
3599 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003600 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601}
3602
3603/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003604* qla2x00_free_fw_dump
3605* Frees fw dump stuff.
3606*
3607* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003608* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003609*/
3610static void
3611qla2x00_free_fw_dump(struct qla_hw_data *ha)
3612{
3613 if (ha->fce)
3614 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3615 ha->fce_dma);
3616
3617 if (ha->fw_dump) {
3618 if (ha->eft)
3619 dma_free_coherent(&ha->pdev->dev,
3620 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3621 vfree(ha->fw_dump);
3622 }
3623 ha->fce = NULL;
3624 ha->fce_dma = 0;
3625 ha->eft = NULL;
3626 ha->eft_dma = 0;
3627 ha->fw_dump = NULL;
3628 ha->fw_dumped = 0;
3629 ha->fw_dump_reading = 0;
3630}
3631
3632/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633* qla2x00_mem_free
3634* Frees all adapter allocated memory.
3635*
3636* Input:
3637* ha = adapter block pointer.
3638*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003639static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003640qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003642 qla2x00_free_fw_dump(ha);
3643
Saurav Kashyap81178772012-08-22 14:21:04 -04003644 if (ha->mctp_dump)
3645 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3646 ha->mctp_dump_dma);
3647
Andrew Vasqueze8711082008-01-31 12:33:48 -08003648 if (ha->srb_mempool)
3649 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003651 if (ha->dcbx_tlv)
3652 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3653 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3654
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003655 if (ha->xgmac_data)
3656 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3657 ha->xgmac_data, ha->xgmac_data_dma);
3658
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 if (ha->sns_cmd)
3660 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003661 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
3663 if (ha->ct_sns)
3664 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003665 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
Andrew Vasquez88729e52006-06-23 16:10:50 -07003667 if (ha->sfp_data)
3668 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3669
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 if (ha->ms_iocb)
3671 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3672
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003673 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003674 dma_pool_free(ha->s_dma_pool,
3675 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003676
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003677 if (ha->async_pd)
3678 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3679
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 if (ha->s_dma_pool)
3681 dma_pool_destroy(ha->s_dma_pool);
3682
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003684 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3685 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686
Giridhar Malavalia9083012010-04-12 17:59:55 -07003687 if (IS_QLA82XX(ha)) {
3688 if (!list_empty(&ha->gbl_dsd_list)) {
3689 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3690
3691 /* clean up allocated prev pool */
3692 list_for_each_entry_safe(dsd_ptr,
3693 tdsd_ptr, &ha->gbl_dsd_list, list) {
3694 dma_pool_free(ha->dl_dma_pool,
3695 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3696 list_del(&dsd_ptr->list);
3697 kfree(dsd_ptr);
3698 }
3699 }
3700 }
3701
3702 if (ha->dl_dma_pool)
3703 dma_pool_destroy(ha->dl_dma_pool);
3704
3705 if (ha->fcp_cmnd_dma_pool)
3706 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3707
3708 if (ha->ctx_mempool)
3709 mempool_destroy(ha->ctx_mempool);
3710
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003711 qlt_mem_free(ha);
3712
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 if (ha->init_cb)
3714 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003715 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 vfree(ha->optrom_buffer);
3717 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003718 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003719 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003720 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721
Andrew Vasqueze8711082008-01-31 12:33:48 -08003722 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003723 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 ha->sns_cmd = NULL;
3725 ha->sns_cmd_dma = 0;
3726 ha->ct_sns = NULL;
3727 ha->ct_sns_dma = 0;
3728 ha->ms_iocb = NULL;
3729 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 ha->init_cb = NULL;
3731 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003732 ha->ex_init_cb = NULL;
3733 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003734 ha->async_pd = NULL;
3735 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736
3737 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003738 ha->dl_dma_pool = NULL;
3739 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 ha->gid_list = NULL;
3742 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003743
3744 ha->tgt.atio_ring = NULL;
3745 ha->tgt.atio_dma = 0;
3746 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003747}
3748
3749struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3750 struct qla_hw_data *ha)
3751{
3752 struct Scsi_Host *host;
3753 struct scsi_qla_host *vha = NULL;
3754
3755 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3756 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003757 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3758 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759 goto fail;
3760 }
3761
3762 /* Clear our data area */
3763 vha = shost_priv(host);
3764 memset(vha, 0, sizeof(scsi_qla_host_t));
3765
3766 vha->host = host;
3767 vha->host_no = host->host_no;
3768 vha->hw = ha;
3769
3770 INIT_LIST_HEAD(&vha->vp_fcports);
3771 INIT_LIST_HEAD(&vha->work_list);
3772 INIT_LIST_HEAD(&vha->list);
3773
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003774 spin_lock_init(&vha->work_lock);
3775
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003776 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003777 ql_dbg(ql_dbg_init, vha, 0x0041,
3778 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3779 vha->host, vha->hw, vha,
3780 dev_name(&(ha->pdev->dev)));
3781
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003782 return vha;
3783
3784fail:
3785 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786}
3787
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003788static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003789qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003790{
3791 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003792 uint8_t bail;
3793
3794 QLA_VHA_MARK_BUSY(vha, bail);
3795 if (bail)
3796 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003797
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003798 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003799 if (!e) {
3800 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003801 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003802 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003803
3804 INIT_LIST_HEAD(&e->list);
3805 e->type = type;
3806 e->flags = QLA_EVT_FLAG_FREE;
3807 return e;
3808}
3809
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003810static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003811qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003812{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003813 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003814
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003815 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003817 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003819
Andrew Vasquez0971de72008-04-03 13:13:18 -07003820 return QLA_SUCCESS;
3821}
3822
3823int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003825 u32 data)
3826{
3827 struct qla_work_evt *e;
3828
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003829 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003830 if (!e)
3831 return QLA_FUNCTION_FAILED;
3832
3833 e->u.aen.code = code;
3834 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003835 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003836}
3837
Andrew Vasquez8a659572009-02-08 20:50:12 -08003838int
3839qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3840{
3841 struct qla_work_evt *e;
3842
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003843 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003844 if (!e)
3845 return QLA_FUNCTION_FAILED;
3846
3847 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003848 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003849}
3850
Andrew Vasquezac280b62009-08-20 11:06:05 -07003851#define qla2x00_post_async_work(name, type) \
3852int qla2x00_post_async_##name##_work( \
3853 struct scsi_qla_host *vha, \
3854 fc_port_t *fcport, uint16_t *data) \
3855{ \
3856 struct qla_work_evt *e; \
3857 \
3858 e = qla2x00_alloc_work(vha, type); \
3859 if (!e) \
3860 return QLA_FUNCTION_FAILED; \
3861 \
3862 e->u.logio.fcport = fcport; \
3863 if (data) { \
3864 e->u.logio.data[0] = data[0]; \
3865 e->u.logio.data[1] = data[1]; \
3866 } \
3867 return qla2x00_post_work(vha, e); \
3868}
3869
3870qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3871qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3872qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3873qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003874qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3875qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003876
Andrew Vasquez3420d362009-10-13 15:16:45 -07003877int
3878qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3879{
3880 struct qla_work_evt *e;
3881
3882 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3883 if (!e)
3884 return QLA_FUNCTION_FAILED;
3885
3886 e->u.uevent.code = code;
3887 return qla2x00_post_work(vha, e);
3888}
3889
3890static void
3891qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3892{
3893 char event_string[40];
3894 char *envp[] = { event_string, NULL };
3895
3896 switch (code) {
3897 case QLA_UEVENT_CODE_FW_DUMP:
3898 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3899 vha->host_no);
3900 break;
3901 default:
3902 /* do nothing */
3903 break;
3904 }
3905 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3906}
3907
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003908int
3909qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
3910 uint32_t *data, int cnt)
3911{
3912 struct qla_work_evt *e;
3913
3914 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
3915 if (!e)
3916 return QLA_FUNCTION_FAILED;
3917
3918 e->u.aenfx.evtcode = evtcode;
3919 e->u.aenfx.count = cnt;
3920 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
3921 return qla2x00_post_work(vha, e);
3922}
3923
Andrew Vasquezac280b62009-08-20 11:06:05 -07003924void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003925qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003926{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003927 struct qla_work_evt *e, *tmp;
3928 unsigned long flags;
3929 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003930
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003931 spin_lock_irqsave(&vha->work_lock, flags);
3932 list_splice_init(&vha->work_list, &work);
3933 spin_unlock_irqrestore(&vha->work_lock, flags);
3934
3935 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003936 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003937
3938 switch (e->type) {
3939 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003940 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003941 e->u.aen.code, e->u.aen.data);
3942 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003943 case QLA_EVT_IDC_ACK:
3944 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3945 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003946 case QLA_EVT_ASYNC_LOGIN:
3947 qla2x00_async_login(vha, e->u.logio.fcport,
3948 e->u.logio.data);
3949 break;
3950 case QLA_EVT_ASYNC_LOGIN_DONE:
3951 qla2x00_async_login_done(vha, e->u.logio.fcport,
3952 e->u.logio.data);
3953 break;
3954 case QLA_EVT_ASYNC_LOGOUT:
3955 qla2x00_async_logout(vha, e->u.logio.fcport);
3956 break;
3957 case QLA_EVT_ASYNC_LOGOUT_DONE:
3958 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3959 e->u.logio.data);
3960 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003961 case QLA_EVT_ASYNC_ADISC:
3962 qla2x00_async_adisc(vha, e->u.logio.fcport,
3963 e->u.logio.data);
3964 break;
3965 case QLA_EVT_ASYNC_ADISC_DONE:
3966 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3967 e->u.logio.data);
3968 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003969 case QLA_EVT_UEVENT:
3970 qla2x00_uevent_emit(vha, e->u.uevent.code);
3971 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003972 case QLA_EVT_AENFX:
3973 qlafx00_process_aen(vha, e);
3974 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003975 }
3976 if (e->flags & QLA_EVT_FLAG_FREE)
3977 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003978
3979 /* For each work completed decrement vha ref count */
3980 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003981 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003982}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003984/* Relogins all the fcports of a vport
3985 * Context: dpc thread
3986 */
3987void qla2x00_relogin(struct scsi_qla_host *vha)
3988{
3989 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003990 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003991 uint16_t next_loopid = 0;
3992 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003993 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003994
3995 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3996 /*
3997 * If the port is not ONLINE then try to login
3998 * to it if we haven't run out of retries.
3999 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004000 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4001 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004002 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004003 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004004 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 ha->isp_ops->fabric_logout(vha,
4006 fcport->loop_id,
4007 fcport->d_id.b.domain,
4008 fcport->d_id.b.area,
4009 fcport->d_id.b.al_pa);
4010
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004011 if (fcport->loop_id == FC_NO_LOOP_ID) {
4012 fcport->loop_id = next_loopid =
4013 ha->min_external_loopid;
4014 status = qla2x00_find_new_loop_id(
4015 vha, fcport);
4016 if (status != QLA_SUCCESS) {
4017 /* Ran out of IDs to use */
4018 break;
4019 }
4020 }
4021
Andrew Vasquezac280b62009-08-20 11:06:05 -07004022 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004023 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004024 data[0] = 0;
4025 data[1] = QLA_LOGIO_LOGIN_RETRIED;
4026 status = qla2x00_post_async_login_work(
4027 vha, fcport, data);
4028 if (status == QLA_SUCCESS)
4029 continue;
4030 /* Attempt a retry. */
4031 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004032 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07004033 status = qla2x00_fabric_login(vha,
4034 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004035 if (status == QLA_SUCCESS) {
4036 int status2;
4037 uint8_t opts;
4038
4039 opts = 0;
4040 if (fcport->flags &
4041 FCF_FCP2_DEVICE)
4042 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05004043 status2 =
4044 qla2x00_get_port_database(
4045 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07004046 if (status2 != QLA_SUCCESS)
4047 status = 1;
4048 }
4049 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004050 } else
4051 status = qla2x00_local_device_login(vha,
4052 fcport);
4053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 if (status == QLA_SUCCESS) {
4055 fcport->old_loop_id = fcport->loop_id;
4056
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004057 ql_dbg(ql_dbg_disc, vha, 0x2003,
4058 "Port login OK: logged in ID 0x%x.\n",
4059 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060
4061 qla2x00_update_fcport(vha, fcport);
4062
4063 } else if (status == 1) {
4064 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4065 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004066 ql_dbg(ql_dbg_disc, vha, 0x2007,
4067 "Retrying %d login again loop_id 0x%x.\n",
4068 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 } else {
4070 fcport->login_retry = 0;
4071 }
4072
4073 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04004074 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004075 }
4076 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4077 break;
4078 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004079}
4080
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004081/* Schedule work on any of the dpc-workqueues */
4082void
4083qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4084{
4085 struct qla_hw_data *ha = base_vha->hw;
4086
4087 switch (work_code) {
4088 case MBA_IDC_AEN: /* 0x8200 */
4089 if (ha->dpc_lp_wq)
4090 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4091 break;
4092
4093 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4094 if (!ha->flags.nic_core_reset_hdlr_active) {
4095 if (ha->dpc_hp_wq)
4096 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4097 } else
4098 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4099 "NIC Core reset is already active. Skip "
4100 "scheduling it again.\n");
4101 break;
4102 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4103 if (ha->dpc_hp_wq)
4104 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4105 break;
4106 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4107 if (ha->dpc_hp_wq)
4108 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4109 break;
4110 default:
4111 ql_log(ql_log_warn, base_vha, 0xb05f,
4112 "Unknow work-code=0x%x.\n", work_code);
4113 }
4114
4115 return;
4116}
4117
4118/* Work: Perform NIC Core Unrecoverable state handling */
4119void
4120qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4121{
4122 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004123 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004124 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4125 uint32_t dev_state = 0;
4126
4127 qla83xx_idc_lock(base_vha, 0);
4128 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4129 qla83xx_reset_ownership(base_vha);
4130 if (ha->flags.nic_core_reset_owner) {
4131 ha->flags.nic_core_reset_owner = 0;
4132 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4133 QLA8XXX_DEV_FAILED);
4134 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4135 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4136 }
4137 qla83xx_idc_unlock(base_vha, 0);
4138}
4139
4140/* Work: Execute IDC state handler */
4141void
4142qla83xx_idc_state_handler_work(struct work_struct *work)
4143{
4144 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004145 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004146 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4147 uint32_t dev_state = 0;
4148
4149 qla83xx_idc_lock(base_vha, 0);
4150 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4151 if (dev_state == QLA8XXX_DEV_FAILED ||
4152 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4153 qla83xx_idc_state_handler(base_vha);
4154 qla83xx_idc_unlock(base_vha, 0);
4155}
4156
Saurav Kashyapfa492632012-11-21 02:40:29 -05004157static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004158qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4159{
4160 int rval = QLA_SUCCESS;
4161 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4162 uint32_t heart_beat_counter1, heart_beat_counter2;
4163
4164 do {
4165 if (time_after(jiffies, heart_beat_wait)) {
4166 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4167 "Nic Core f/w is not alive.\n");
4168 rval = QLA_FUNCTION_FAILED;
4169 break;
4170 }
4171
4172 qla83xx_idc_lock(base_vha, 0);
4173 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4174 &heart_beat_counter1);
4175 qla83xx_idc_unlock(base_vha, 0);
4176 msleep(100);
4177 qla83xx_idc_lock(base_vha, 0);
4178 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4179 &heart_beat_counter2);
4180 qla83xx_idc_unlock(base_vha, 0);
4181 } while (heart_beat_counter1 == heart_beat_counter2);
4182
4183 return rval;
4184}
4185
4186/* Work: Perform NIC Core Reset handling */
4187void
4188qla83xx_nic_core_reset_work(struct work_struct *work)
4189{
4190 struct qla_hw_data *ha =
4191 container_of(work, struct qla_hw_data, nic_core_reset);
4192 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4193 uint32_t dev_state = 0;
4194
Saurav Kashyap81178772012-08-22 14:21:04 -04004195 if (IS_QLA2031(ha)) {
4196 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4197 ql_log(ql_log_warn, base_vha, 0xb081,
4198 "Failed to dump mctp\n");
4199 return;
4200 }
4201
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004202 if (!ha->flags.nic_core_reset_hdlr_active) {
4203 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4204 qla83xx_idc_lock(base_vha, 0);
4205 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4206 &dev_state);
4207 qla83xx_idc_unlock(base_vha, 0);
4208 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4209 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4210 "Nic Core f/w is alive.\n");
4211 return;
4212 }
4213 }
4214
4215 ha->flags.nic_core_reset_hdlr_active = 1;
4216 if (qla83xx_nic_core_reset(base_vha)) {
4217 /* NIC Core reset failed. */
4218 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4219 "NIC Core reset failed.\n");
4220 }
4221 ha->flags.nic_core_reset_hdlr_active = 0;
4222 }
4223}
4224
4225/* Work: Handle 8200 IDC aens */
4226void
4227qla83xx_service_idc_aen(struct work_struct *work)
4228{
4229 struct qla_hw_data *ha =
4230 container_of(work, struct qla_hw_data, idc_aen);
4231 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4232 uint32_t dev_state, idc_control;
4233
4234 qla83xx_idc_lock(base_vha, 0);
4235 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4236 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4237 qla83xx_idc_unlock(base_vha, 0);
4238 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4239 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4240 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4241 "Application requested NIC Core Reset.\n");
4242 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4243 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4244 QLA_SUCCESS) {
4245 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4246 "Other protocol driver requested NIC Core Reset.\n");
4247 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4248 }
4249 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4250 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4251 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4252 }
4253}
4254
4255static void
4256qla83xx_wait_logic(void)
4257{
4258 int i;
4259
4260 /* Yield CPU */
4261 if (!in_interrupt()) {
4262 /*
4263 * Wait about 200ms before retrying again.
4264 * This controls the number of retries for single
4265 * lock operation.
4266 */
4267 msleep(100);
4268 schedule();
4269 } else {
4270 for (i = 0; i < 20; i++)
4271 cpu_relax(); /* This a nop instr on i386 */
4272 }
4273}
4274
Saurav Kashyapfa492632012-11-21 02:40:29 -05004275static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004276qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4277{
4278 int rval;
4279 uint32_t data;
4280 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4281 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4282 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004283 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4284 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004285
4286 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4287 if (rval)
4288 return rval;
4289
4290 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4291 return QLA_SUCCESS;
4292 } else {
4293 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4294 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4295 data);
4296 if (rval)
4297 return rval;
4298
4299 msleep(200);
4300
4301 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4302 &data);
4303 if (rval)
4304 return rval;
4305
4306 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4307 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4308 ~(idc_lck_rcvry_stage_mask));
4309 rval = qla83xx_wr_reg(base_vha,
4310 QLA83XX_IDC_LOCK_RECOVERY, data);
4311 if (rval)
4312 return rval;
4313
4314 /* Forcefully perform IDC UnLock */
4315 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4316 &data);
4317 if (rval)
4318 return rval;
4319 /* Clear lock-id by setting 0xff */
4320 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4321 0xff);
4322 if (rval)
4323 return rval;
4324 /* Clear lock-recovery by setting 0x0 */
4325 rval = qla83xx_wr_reg(base_vha,
4326 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4327 if (rval)
4328 return rval;
4329 } else
4330 return QLA_SUCCESS;
4331 }
4332
4333 return rval;
4334}
4335
Saurav Kashyapfa492632012-11-21 02:40:29 -05004336static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004337qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4338{
4339 int rval = QLA_SUCCESS;
4340 uint32_t o_drv_lockid, n_drv_lockid;
4341 unsigned long lock_recovery_timeout;
4342
4343 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4344retry_lockid:
4345 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4346 if (rval)
4347 goto exit;
4348
4349 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4350 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4351 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4352 return QLA_SUCCESS;
4353 else
4354 return QLA_FUNCTION_FAILED;
4355 }
4356
4357 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4358 if (rval)
4359 goto exit;
4360
4361 if (o_drv_lockid == n_drv_lockid) {
4362 qla83xx_wait_logic();
4363 goto retry_lockid;
4364 } else
4365 return QLA_SUCCESS;
4366
4367exit:
4368 return rval;
4369}
4370
4371void
4372qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4373{
4374 uint16_t options = (requester_id << 15) | BIT_6;
4375 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05004376 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004377 struct qla_hw_data *ha = base_vha->hw;
4378
4379 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4380retry_lock:
4381 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4382 == QLA_SUCCESS) {
4383 if (data) {
4384 /* Setting lock-id to our function-number */
4385 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4386 ha->portnum);
4387 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05004388 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4389 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004390 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05004391 "Failed to acquire IDC lock, acquired by %d, "
4392 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004393
4394 /* Retry/Perform IDC-Lock recovery */
4395 if (qla83xx_idc_lock_recovery(base_vha)
4396 == QLA_SUCCESS) {
4397 qla83xx_wait_logic();
4398 goto retry_lock;
4399 } else
4400 ql_log(ql_log_warn, base_vha, 0xb075,
4401 "IDC Lock recovery FAILED.\n");
4402 }
4403
4404 }
4405
4406 return;
4407
4408 /* XXX: IDC-lock implementation using access-control mbx */
4409retry_lock2:
4410 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4411 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4412 "Failed to acquire IDC lock. retrying...\n");
4413 /* Retry/Perform IDC-Lock recovery */
4414 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4415 qla83xx_wait_logic();
4416 goto retry_lock2;
4417 } else
4418 ql_log(ql_log_warn, base_vha, 0xb076,
4419 "IDC Lock recovery FAILED.\n");
4420 }
4421
4422 return;
4423}
4424
4425void
4426qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4427{
4428 uint16_t options = (requester_id << 15) | BIT_7, retry;
4429 uint32_t data;
4430 struct qla_hw_data *ha = base_vha->hw;
4431
4432 /* IDC-unlock implementation using driver-unlock/lock-id
4433 * remote registers
4434 */
4435 retry = 0;
4436retry_unlock:
4437 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4438 == QLA_SUCCESS) {
4439 if (data == ha->portnum) {
4440 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4441 /* Clearing lock-id by setting 0xff */
4442 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4443 } else if (retry < 10) {
4444 /* SV: XXX: IDC unlock retrying needed here? */
4445
4446 /* Retry for IDC-unlock */
4447 qla83xx_wait_logic();
4448 retry++;
4449 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4450 "Failed to release IDC lock, retyring=%d\n", retry);
4451 goto retry_unlock;
4452 }
4453 } else if (retry < 10) {
4454 /* Retry for IDC-unlock */
4455 qla83xx_wait_logic();
4456 retry++;
4457 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4458 "Failed to read drv-lockid, retyring=%d\n", retry);
4459 goto retry_unlock;
4460 }
4461
4462 return;
4463
4464 /* XXX: IDC-unlock implementation using access-control mbx */
4465 retry = 0;
4466retry_unlock2:
4467 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4468 if (retry < 10) {
4469 /* Retry for IDC-unlock */
4470 qla83xx_wait_logic();
4471 retry++;
4472 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4473 "Failed to release IDC lock, retyring=%d\n", retry);
4474 goto retry_unlock2;
4475 }
4476 }
4477
4478 return;
4479}
4480
4481int
4482__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4483{
4484 int rval = QLA_SUCCESS;
4485 struct qla_hw_data *ha = vha->hw;
4486 uint32_t drv_presence;
4487
4488 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4489 if (rval == QLA_SUCCESS) {
4490 drv_presence |= (1 << ha->portnum);
4491 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4492 drv_presence);
4493 }
4494
4495 return rval;
4496}
4497
4498int
4499qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4500{
4501 int rval = QLA_SUCCESS;
4502
4503 qla83xx_idc_lock(vha, 0);
4504 rval = __qla83xx_set_drv_presence(vha);
4505 qla83xx_idc_unlock(vha, 0);
4506
4507 return rval;
4508}
4509
4510int
4511__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4512{
4513 int rval = QLA_SUCCESS;
4514 struct qla_hw_data *ha = vha->hw;
4515 uint32_t drv_presence;
4516
4517 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4518 if (rval == QLA_SUCCESS) {
4519 drv_presence &= ~(1 << ha->portnum);
4520 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4521 drv_presence);
4522 }
4523
4524 return rval;
4525}
4526
4527int
4528qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4529{
4530 int rval = QLA_SUCCESS;
4531
4532 qla83xx_idc_lock(vha, 0);
4533 rval = __qla83xx_clear_drv_presence(vha);
4534 qla83xx_idc_unlock(vha, 0);
4535
4536 return rval;
4537}
4538
Saurav Kashyapfa492632012-11-21 02:40:29 -05004539static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004540qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4541{
4542 struct qla_hw_data *ha = vha->hw;
4543 uint32_t drv_ack, drv_presence;
4544 unsigned long ack_timeout;
4545
4546 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4547 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4548 while (1) {
4549 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4550 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004551 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004552 break;
4553
4554 if (time_after_eq(jiffies, ack_timeout)) {
4555 ql_log(ql_log_warn, vha, 0xb067,
4556 "RESET ACK TIMEOUT! drv_presence=0x%x "
4557 "drv_ack=0x%x\n", drv_presence, drv_ack);
4558 /*
4559 * The function(s) which did not ack in time are forced
4560 * to withdraw any further participation in the IDC
4561 * reset.
4562 */
4563 if (drv_ack != drv_presence)
4564 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4565 drv_ack);
4566 break;
4567 }
4568
4569 qla83xx_idc_unlock(vha, 0);
4570 msleep(1000);
4571 qla83xx_idc_lock(vha, 0);
4572 }
4573
4574 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4575 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4576}
4577
Saurav Kashyapfa492632012-11-21 02:40:29 -05004578static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004579qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4580{
4581 int rval = QLA_SUCCESS;
4582 uint32_t idc_control;
4583
4584 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4585 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4586
4587 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4588 __qla83xx_get_idc_control(vha, &idc_control);
4589 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4590 __qla83xx_set_idc_control(vha, 0);
4591
4592 qla83xx_idc_unlock(vha, 0);
4593 rval = qla83xx_restart_nic_firmware(vha);
4594 qla83xx_idc_lock(vha, 0);
4595
4596 if (rval != QLA_SUCCESS) {
4597 ql_log(ql_log_fatal, vha, 0xb06a,
4598 "Failed to restart NIC f/w.\n");
4599 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4600 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4601 } else {
4602 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4603 "Success in restarting nic f/w.\n");
4604 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4605 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4606 }
4607
4608 return rval;
4609}
4610
4611/* Assumes idc_lock always held on entry */
4612int
4613qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4614{
4615 struct qla_hw_data *ha = base_vha->hw;
4616 int rval = QLA_SUCCESS;
4617 unsigned long dev_init_timeout;
4618 uint32_t dev_state;
4619
4620 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4621 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4622
4623 while (1) {
4624
4625 if (time_after_eq(jiffies, dev_init_timeout)) {
4626 ql_log(ql_log_warn, base_vha, 0xb06e,
4627 "Initialization TIMEOUT!\n");
4628 /* Init timeout. Disable further NIC Core
4629 * communication.
4630 */
4631 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4632 QLA8XXX_DEV_FAILED);
4633 ql_log(ql_log_info, base_vha, 0xb06f,
4634 "HW State: FAILED.\n");
4635 }
4636
4637 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4638 switch (dev_state) {
4639 case QLA8XXX_DEV_READY:
4640 if (ha->flags.nic_core_reset_owner)
4641 qla83xx_idc_audit(base_vha,
4642 IDC_AUDIT_COMPLETION);
4643 ha->flags.nic_core_reset_owner = 0;
4644 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4645 "Reset_owner reset by 0x%x.\n",
4646 ha->portnum);
4647 goto exit;
4648 case QLA8XXX_DEV_COLD:
4649 if (ha->flags.nic_core_reset_owner)
4650 rval = qla83xx_device_bootstrap(base_vha);
4651 else {
4652 /* Wait for AEN to change device-state */
4653 qla83xx_idc_unlock(base_vha, 0);
4654 msleep(1000);
4655 qla83xx_idc_lock(base_vha, 0);
4656 }
4657 break;
4658 case QLA8XXX_DEV_INITIALIZING:
4659 /* Wait for AEN to change device-state */
4660 qla83xx_idc_unlock(base_vha, 0);
4661 msleep(1000);
4662 qla83xx_idc_lock(base_vha, 0);
4663 break;
4664 case QLA8XXX_DEV_NEED_RESET:
4665 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4666 qla83xx_need_reset_handler(base_vha);
4667 else {
4668 /* Wait for AEN to change device-state */
4669 qla83xx_idc_unlock(base_vha, 0);
4670 msleep(1000);
4671 qla83xx_idc_lock(base_vha, 0);
4672 }
4673 /* reset timeout value after need reset handler */
4674 dev_init_timeout = jiffies +
4675 (ha->fcoe_dev_init_timeout * HZ);
4676 break;
4677 case QLA8XXX_DEV_NEED_QUIESCENT:
4678 /* XXX: DEBUG for now */
4679 qla83xx_idc_unlock(base_vha, 0);
4680 msleep(1000);
4681 qla83xx_idc_lock(base_vha, 0);
4682 break;
4683 case QLA8XXX_DEV_QUIESCENT:
4684 /* XXX: DEBUG for now */
4685 if (ha->flags.quiesce_owner)
4686 goto exit;
4687
4688 qla83xx_idc_unlock(base_vha, 0);
4689 msleep(1000);
4690 qla83xx_idc_lock(base_vha, 0);
4691 dev_init_timeout = jiffies +
4692 (ha->fcoe_dev_init_timeout * HZ);
4693 break;
4694 case QLA8XXX_DEV_FAILED:
4695 if (ha->flags.nic_core_reset_owner)
4696 qla83xx_idc_audit(base_vha,
4697 IDC_AUDIT_COMPLETION);
4698 ha->flags.nic_core_reset_owner = 0;
4699 __qla83xx_clear_drv_presence(base_vha);
4700 qla83xx_idc_unlock(base_vha, 0);
4701 qla8xxx_dev_failed_handler(base_vha);
4702 rval = QLA_FUNCTION_FAILED;
4703 qla83xx_idc_lock(base_vha, 0);
4704 goto exit;
4705 case QLA8XXX_BAD_VALUE:
4706 qla83xx_idc_unlock(base_vha, 0);
4707 msleep(1000);
4708 qla83xx_idc_lock(base_vha, 0);
4709 break;
4710 default:
4711 ql_log(ql_log_warn, base_vha, 0xb071,
4712 "Unknow Device State: %x.\n", dev_state);
4713 qla83xx_idc_unlock(base_vha, 0);
4714 qla8xxx_dev_failed_handler(base_vha);
4715 rval = QLA_FUNCTION_FAILED;
4716 qla83xx_idc_lock(base_vha, 0);
4717 goto exit;
4718 }
4719 }
4720
4721exit:
4722 return rval;
4723}
4724
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725/**************************************************************************
4726* qla2x00_do_dpc
4727* This kernel thread is a task that is schedule by the interrupt handler
4728* to perform the background processing for interrupts.
4729*
4730* Notes:
4731* This task always run in the context of a kernel thread. It
4732* is kick-off by the driver's detect code and starts up
4733* up one per adapter. It immediately goes to sleep and waits for
4734* some fibre event. When either the interrupt handler or
4735* the timer routine detects a event it will one of the task
4736* bits then wake us up.
4737**************************************************************************/
4738static int
4739qla2x00_do_dpc(void *data)
4740{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004741 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004742 scsi_qla_host_t *base_vha;
4743 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004744
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004745 ha = (struct qla_hw_data *)data;
4746 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 set_user_nice(current, -20);
4749
James Bottomley563585e2011-01-27 16:12:37 -05004750 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004751 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004752 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4753 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754
Christoph Hellwig39a11242006-02-14 18:46:22 +01004755 schedule();
4756 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004758 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4759 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760
Andrew Vasquez85880802009-12-15 21:29:46 -08004761 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004762 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4763 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004764 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004765 }
4766
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 ha->dpc_active = 1;
4768
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004769 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4770 "DPC handler waking up, dpc_flags=0x%lx.\n",
4771 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004773 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004774
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004775 if (IS_P3P_TYPE(ha)) {
4776 if (IS_QLA8044(ha)) {
4777 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4778 &base_vha->dpc_flags)) {
4779 qla8044_idc_lock(ha);
4780 qla8044_wr_direct(base_vha,
4781 QLA8044_CRB_DEV_STATE_INDEX,
4782 QLA8XXX_DEV_FAILED);
4783 qla8044_idc_unlock(ha);
4784 ql_log(ql_log_info, base_vha, 0x4004,
4785 "HW State: FAILED.\n");
4786 qla8044_device_state_handler(base_vha);
4787 continue;
4788 }
4789
4790 } else {
4791 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4792 &base_vha->dpc_flags)) {
4793 qla82xx_idc_lock(ha);
4794 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4795 QLA8XXX_DEV_FAILED);
4796 qla82xx_idc_unlock(ha);
4797 ql_log(ql_log_info, base_vha, 0x0151,
4798 "HW State: FAILED.\n");
4799 qla82xx_device_state_handler(base_vha);
4800 continue;
4801 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004802 }
4803
4804 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4805 &base_vha->dpc_flags)) {
4806
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004807 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4808 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004809 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4810 &base_vha->dpc_flags))) {
4811 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4812 /* FCoE-ctx reset failed.
4813 * Escalate to chip-reset
4814 */
4815 set_bit(ISP_ABORT_NEEDED,
4816 &base_vha->dpc_flags);
4817 }
4818 clear_bit(ABORT_ISP_ACTIVE,
4819 &base_vha->dpc_flags);
4820 }
4821
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004822 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4823 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004824 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004825 } else if (IS_QLAFX00(ha)) {
4826 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4827 &base_vha->dpc_flags)) {
4828 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
4829 "Firmware Reset Recovery\n");
4830 if (qlafx00_reset_initialize(base_vha)) {
4831 /* Failed. Abort isp later. */
4832 if (!test_bit(UNLOADING,
4833 &base_vha->dpc_flags))
4834 set_bit(ISP_UNRECOVERABLE,
4835 &base_vha->dpc_flags);
4836 ql_dbg(ql_dbg_dpc, base_vha,
4837 0x4021,
4838 "Reset Recovery Failed\n");
4839 }
4840 }
4841
4842 if (test_and_clear_bit(FX00_TARGET_SCAN,
4843 &base_vha->dpc_flags)) {
4844 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
4845 "ISPFx00 Target Scan scheduled\n");
4846 if (qlafx00_rescan_isp(base_vha)) {
4847 if (!test_bit(UNLOADING,
4848 &base_vha->dpc_flags))
4849 set_bit(ISP_UNRECOVERABLE,
4850 &base_vha->dpc_flags);
4851 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
4852 "ISPFx00 Target Scan Failed\n");
4853 }
4854 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
4855 "ISPFx00 Target Scan End\n");
4856 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07004857 }
4858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004859 if (test_and_clear_bit(ISP_ABORT_NEEDED,
4860 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004862 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
4863 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004865 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866
Giridhar Malavalia9083012010-04-12 17:59:55 -07004867 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 /* failed. retry later */
4869 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004870 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004872 clear_bit(ABORT_ISP_ACTIVE,
4873 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08004874 }
4875
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004876 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
4877 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 }
4879
David Jefferya394aac2012-11-21 02:39:54 -05004880 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
4881 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004882 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07004883 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004884
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004885 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
4886 int ret;
4887 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
4888 if (ret != QLA_SUCCESS)
4889 ql_log(ql_log_warn, base_vha, 0x121,
4890 "Failed to enable receiving of RSCN "
4891 "requests: 0x%x.\n", ret);
4892 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
4893 }
4894
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004895 if (IS_QLAFX00(ha))
4896 goto loop_resync_check;
4897
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004898 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004899 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
4900 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004901 if (IS_P3P_TYPE(ha)) {
4902 if (IS_QLA82XX(ha))
4903 qla82xx_device_state_handler(base_vha);
4904 if (IS_QLA8044(ha))
4905 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004906 clear_bit(ISP_QUIESCE_NEEDED,
4907 &base_vha->dpc_flags);
4908 if (!ha->flags.quiesce_owner) {
4909 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004910 if (IS_QLA82XX(ha)) {
4911 qla82xx_idc_lock(ha);
4912 qla82xx_clear_qsnt_ready(
4913 base_vha);
4914 qla82xx_idc_unlock(ha);
4915 } else if (IS_QLA8044(ha)) {
4916 qla8044_idc_lock(ha);
4917 qla8044_clear_qsnt_ready(
4918 base_vha);
4919 qla8044_idc_unlock(ha);
4920 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004921 }
4922 } else {
4923 clear_bit(ISP_QUIESCE_NEEDED,
4924 &base_vha->dpc_flags);
4925 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004926 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004927 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
4928 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004929 }
4930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004931 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004932 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004933 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004935 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
4936 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004937 qla2x00_rst_aen(base_vha);
4938 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004939 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
4940 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 }
4942
4943 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004944 if ((test_and_clear_bit(RELOGIN_NEEDED,
4945 &base_vha->dpc_flags)) &&
4946 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
4947 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004949 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
4950 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004951 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004952 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
4953 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004955loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004956 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004957 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004959 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
4960 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961
4962 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004963 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004965 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004967 clear_bit(LOOP_RESYNC_ACTIVE,
4968 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 }
4970
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004971 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
4972 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 }
4974
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004975 if (IS_QLAFX00(ha))
4976 goto intr_on_check;
4977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004978 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
4979 atomic_read(&base_vha->loop_state) == LOOP_READY) {
4980 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
4981 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07004982 }
4983
Chad Dupuis3c290d02013-01-30 03:34:38 -05004984 if (test_and_clear_bit(HOST_RAMP_DOWN_QUEUE_DEPTH,
4985 &base_vha->dpc_flags)) {
4986 /* Prevents simultaneous ramp up and down */
4987 clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
4988 &base_vha->dpc_flags);
4989 qla2x00_host_ramp_down_queuedepth(base_vha);
4990 }
4991
4992 if (test_and_clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
4993 &base_vha->dpc_flags))
4994 qla2x00_host_ramp_up_queuedepth(base_vha);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004995intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004997 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004999 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
5000 &base_vha->dpc_flags))
5001 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005002
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005003 if (!IS_QLAFX00(ha))
5004 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005007end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005008 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005010 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005012 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5013 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014
5015 /*
5016 * Make sure that nobody tries to wake us up again.
5017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 ha->dpc_active = 0;
5019
Andrew Vasquezac280b62009-08-20 11:06:05 -07005020 /* Cleanup any residual CTX SRBs. */
5021 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5022
Christoph Hellwig39a11242006-02-14 18:46:22 +01005023 return 0;
5024}
5025
5026void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005027qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01005028{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005029 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005030 struct task_struct *t = ha->dpc_thread;
5031
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005032 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07005033 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034}
5035
5036/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037* qla2x00_rst_aen
5038* Processes asynchronous reset.
5039*
5040* Input:
5041* ha = adapter block pointer.
5042*/
5043static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005044qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005046 if (vha->flags.online && !vha->flags.reset_active &&
5047 !atomic_read(&vha->loop_down_timer) &&
5048 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005050 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051
5052 /*
5053 * Issue marker command only when we are going to start
5054 * the I/O.
5055 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005056 vha->marker_needed = 1;
5057 } while (!atomic_read(&vha->loop_down_timer) &&
5058 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059 }
5060}
5061
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062/**************************************************************************
5063* qla2x00_timer
5064*
5065* Description:
5066* One second timer
5067*
5068* Context: Interrupt
5069***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005070void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005071qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 int start_dpc = 0;
5075 int index;
5076 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08005077 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005078 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005079 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08005080
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005081 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005082 ql_dbg(ql_dbg_timer, vha, 0x6000,
5083 "EEH = %d, restarting timer.\n",
5084 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005085 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5086 return;
5087 }
5088
Andrew Vasquez85880802009-12-15 21:29:46 -08005089 /* Hardware read to raise pending EEH errors during mailbox waits. */
5090 if (!pci_channel_offline(ha->pdev))
5091 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005093 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005094 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005095 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5096 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005097 if (IS_QLA82XX(ha))
5098 qla82xx_watchdog(vha);
5099 else if (IS_QLA8044(ha))
5100 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005101 }
5102
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005103 if (!vha->vp_idx && IS_QLAFX00(ha))
5104 qlafx00_timer_routine(vha);
5105
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005107 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005108 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5109 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005110 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005112 if (atomic_read(&vha->loop_down_timer) ==
5113 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005115 ql_log(ql_log_info, vha, 0x6008,
5116 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005118 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5119 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005121 /*
5122 * Schedule an ISP abort to return any FCP2-device
5123 * commands.
5124 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005125 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005126 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005127 spin_lock_irqsave(&ha->hardware_lock,
5128 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005129 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005130 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05005131 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005132 index++) {
5133 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05005134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005135 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005136 if (!sp)
5137 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08005138 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07005139 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005140 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08005141 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005142 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005144 if (IS_QLA82XX(ha))
5145 set_bit(FCOE_CTX_RESET_NEEDED,
5146 &vha->dpc_flags);
5147 else
5148 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005149 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005150 break;
5151 }
5152 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005153 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 start_dpc++;
5156 }
5157
5158 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005159 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07005160 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005161 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 "Loop down - aborting ISP.\n");
5163
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07005164 if (IS_QLA82XX(ha))
5165 set_bit(FCOE_CTX_RESET_NEEDED,
5166 &vha->dpc_flags);
5167 else
5168 set_bit(ISP_ABORT_NEEDED,
5169 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 }
5171 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005172 ql_dbg(ql_dbg_timer, vha, 0x600a,
5173 "Loop down - seconds remaining %d.\n",
5174 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 }
5176
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07005177 /* Check if beacon LED needs to be blinked for physical host only */
5178 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005179 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005180 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07005181 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5182 start_dpc++;
5183 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005184 }
5185
Andrew Vasquez550bf572008-04-24 15:21:23 -07005186 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005187 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07005188 start_dpc++;
5189
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005191 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5192 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5193 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005195 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5196 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07005197 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5198 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005199 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis3c290d02013-01-30 03:34:38 -05005200 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
5201 test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags) ||
5202 test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005203 ql_dbg(ql_dbg_timer, vha, 0x600b,
5204 "isp_abort_needed=%d loop_resync_needed=%d "
5205 "fcport_update_needed=%d start_dpc=%d "
5206 "reset_marker_needed=%d",
5207 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5208 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5209 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5210 start_dpc,
5211 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5212 ql_dbg(ql_dbg_timer, vha, 0x600c,
5213 "beacon_blink_needed=%d isp_unrecoverable=%d "
5214 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis3c290d02013-01-30 03:34:38 -05005215 "relogin_needed=%d, host_ramp_down_needed=%d "
5216 "host_ramp_up_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005217 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5218 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5219 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5220 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis3c290d02013-01-30 03:34:38 -05005221 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
5222 test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags),
5223 test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005224 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005227 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228}
5229
Andrew Vasquez54333832005-11-09 15:49:04 -08005230/* Firmware interface routines. */
5231
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005232#define FW_BLOBS 10
Andrew Vasquez54333832005-11-09 15:49:04 -08005233#define FW_ISP21XX 0
5234#define FW_ISP22XX 1
5235#define FW_ISP2300 2
5236#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005237#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005238#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005239#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07005240#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005241#define FW_ISP2031 8
5242#define FW_ISP8031 9
Andrew Vasquez54333832005-11-09 15:49:04 -08005243
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005244#define FW_FILE_ISP21XX "ql2100_fw.bin"
5245#define FW_FILE_ISP22XX "ql2200_fw.bin"
5246#define FW_FILE_ISP2300 "ql2300_fw.bin"
5247#define FW_FILE_ISP2322 "ql2322_fw.bin"
5248#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005249#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005250#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07005251#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005252#define FW_FILE_ISP2031 "ql2600_fw.bin"
5253#define FW_FILE_ISP8031 "ql8300_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005254
Daniel Walkere1e82b62008-05-12 22:21:10 -07005255static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005256
5257static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005258 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5259 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5260 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5261 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5262 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005263 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005264 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005265 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005266 { .name = FW_FILE_ISP2031, },
5267 { .name = FW_FILE_ISP8031, },
Andrew Vasquez54333832005-11-09 15:49:04 -08005268};
5269
5270struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005271qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08005272{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005273 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08005274 struct fw_blob *blob;
5275
Andrew Vasquez54333832005-11-09 15:49:04 -08005276 if (IS_QLA2100(ha)) {
5277 blob = &qla_fw_blobs[FW_ISP21XX];
5278 } else if (IS_QLA2200(ha)) {
5279 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005280 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005281 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08005282 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005283 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005284 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08005285 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005286 } else if (IS_QLA25XX(ha)) {
5287 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005288 } else if (IS_QLA81XX(ha)) {
5289 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07005290 } else if (IS_QLA82XX(ha)) {
5291 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005292 } else if (IS_QLA2031(ha)) {
5293 blob = &qla_fw_blobs[FW_ISP2031];
5294 } else if (IS_QLA8031(ha)) {
5295 blob = &qla_fw_blobs[FW_ISP8031];
Dan Carpenter8a655222012-02-21 10:29:40 +03005296 } else {
5297 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005298 }
5299
Daniel Walkere1e82b62008-05-12 22:21:10 -07005300 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005301 if (blob->fw)
5302 goto out;
5303
5304 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005305 ql_log(ql_log_warn, vha, 0x0063,
5306 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005307 blob->fw = NULL;
5308 blob = NULL;
5309 goto out;
5310 }
5311
5312out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005313 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005314 return blob;
5315}
5316
5317static void
5318qla2x00_release_firmware(void)
5319{
5320 int idx;
5321
Daniel Walkere1e82b62008-05-12 22:21:10 -07005322 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005323 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005324 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005325 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005326}
5327
Seokmann Ju14e660e2007-09-20 14:07:36 -07005328static pci_ers_result_t
5329qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5330{
Andrew Vasquez85880802009-12-15 21:29:46 -08005331 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5332 struct qla_hw_data *ha = vha->hw;
5333
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005334 ql_dbg(ql_dbg_aer, vha, 0x9000,
5335 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005336
Seokmann Ju14e660e2007-09-20 14:07:36 -07005337 switch (state) {
5338 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005339 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005340 return PCI_ERS_RESULT_CAN_RECOVER;
5341 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005342 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005343 /* For ISP82XX complete any pending mailbox cmd */
5344 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005345 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005346 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5347 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005348 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005349 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005350 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005351 /* Return back all IOs */
5352 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005353 return PCI_ERS_RESULT_NEED_RESET;
5354 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005355 ha->flags.pci_channel_io_perm_failure = 1;
5356 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005357 return PCI_ERS_RESULT_DISCONNECT;
5358 }
5359 return PCI_ERS_RESULT_NEED_RESET;
5360}
5361
5362static pci_ers_result_t
5363qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5364{
5365 int risc_paused = 0;
5366 uint32_t stat;
5367 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005368 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5369 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005370 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5371 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5372
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005373 if (IS_QLA82XX(ha))
5374 return PCI_ERS_RESULT_RECOVERED;
5375
Seokmann Ju14e660e2007-09-20 14:07:36 -07005376 spin_lock_irqsave(&ha->hardware_lock, flags);
5377 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5378 stat = RD_REG_DWORD(&reg->hccr);
5379 if (stat & HCCR_RISC_PAUSE)
5380 risc_paused = 1;
5381 } else if (IS_QLA23XX(ha)) {
5382 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5383 if (stat & HSR_RISC_PAUSED)
5384 risc_paused = 1;
5385 } else if (IS_FWI2_CAPABLE(ha)) {
5386 stat = RD_REG_DWORD(&reg24->host_status);
5387 if (stat & HSRX_RISC_PAUSED)
5388 risc_paused = 1;
5389 }
5390 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5391
5392 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005393 ql_log(ql_log_info, base_vha, 0x9003,
5394 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005395 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005396
5397 return PCI_ERS_RESULT_NEED_RESET;
5398 } else
5399 return PCI_ERS_RESULT_RECOVERED;
5400}
5401
Saurav Kashyapfa492632012-11-21 02:40:29 -05005402static uint32_t
5403qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005404{
5405 uint32_t rval = QLA_FUNCTION_FAILED;
5406 uint32_t drv_active = 0;
5407 struct qla_hw_data *ha = base_vha->hw;
5408 int fn;
5409 struct pci_dev *other_pdev = NULL;
5410
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005411 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5412 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005413
5414 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5415
5416 if (base_vha->flags.online) {
5417 /* Abort all outstanding commands,
5418 * so as to be requeued later */
5419 qla2x00_abort_isp_cleanup(base_vha);
5420 }
5421
5422
5423 fn = PCI_FUNC(ha->pdev->devfn);
5424 while (fn > 0) {
5425 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005426 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5427 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005428 other_pdev =
5429 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5430 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5431 fn));
5432
5433 if (!other_pdev)
5434 continue;
5435 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005436 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5437 "Found PCI func available and enable at 0x%x.\n",
5438 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005439 pci_dev_put(other_pdev);
5440 break;
5441 }
5442 pci_dev_put(other_pdev);
5443 }
5444
5445 if (!fn) {
5446 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005447 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5448 "This devfn is reset owner = 0x%x.\n",
5449 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005450 qla82xx_idc_lock(ha);
5451
5452 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005453 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005454
5455 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5456 QLA82XX_IDC_VERSION);
5457
5458 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005459 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5460 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005461
5462 qla82xx_idc_unlock(ha);
5463 /* Reset if device is not already reset
5464 * drv_active would be 0 if a reset has already been done
5465 */
5466 if (drv_active)
5467 rval = qla82xx_start_firmware(base_vha);
5468 else
5469 rval = QLA_SUCCESS;
5470 qla82xx_idc_lock(ha);
5471
5472 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005473 ql_log(ql_log_info, base_vha, 0x900b,
5474 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005475 qla82xx_clear_drv_active(ha);
5476 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005477 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005478 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005479 ql_log(ql_log_info, base_vha, 0x900c,
5480 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005481 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005482 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005483 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005484 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005485 rval = qla82xx_restart_isp(base_vha);
5486 qla82xx_idc_lock(ha);
5487 /* Clear driver state register */
5488 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5489 qla82xx_set_drv_active(base_vha);
5490 }
5491 qla82xx_idc_unlock(ha);
5492 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005493 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5494 "This devfn is not reset owner = 0x%x.\n",
5495 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005496 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005497 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005498 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005499 rval = qla82xx_restart_isp(base_vha);
5500 qla82xx_idc_lock(ha);
5501 qla82xx_set_drv_active(base_vha);
5502 qla82xx_idc_unlock(ha);
5503 }
5504 }
5505 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5506
5507 return rval;
5508}
5509
Seokmann Ju14e660e2007-09-20 14:07:36 -07005510static pci_ers_result_t
5511qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5512{
5513 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005514 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5515 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005516 struct rsp_que *rsp;
5517 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005518
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005519 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5520 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005521
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005522 /* Workaround: qla2xxx driver which access hardware earlier
5523 * needs error state to be pci_channel_io_online.
5524 * Otherwise mailbox command timesout.
5525 */
5526 pdev->error_state = pci_channel_io_normal;
5527
5528 pci_restore_state(pdev);
5529
Richard Lary8c1496b2010-02-18 10:07:29 -08005530 /* pci_restore_state() clears the saved_state flag of the device
5531 * save restored state which resets saved_state flag
5532 */
5533 pci_save_state(pdev);
5534
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005535 if (ha->mem_only)
5536 rc = pci_enable_device_mem(pdev);
5537 else
5538 rc = pci_enable_device(pdev);
5539
5540 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005541 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005542 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005543 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005544 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005545
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005546 rsp = ha->rsp_q_map[0];
5547 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005548 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005550 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005551 goto exit_slot_reset;
5552
5553 if (IS_QLA82XX(ha)) {
5554 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5555 ret = PCI_ERS_RESULT_RECOVERED;
5556 goto exit_slot_reset;
5557 } else
5558 goto exit_slot_reset;
5559 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005560
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005561 while (ha->flags.mbox_busy && retries--)
5562 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005563
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005564 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005565 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005566 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005567 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005568
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005569
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005570exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005571 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5572 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005573
Seokmann Ju14e660e2007-09-20 14:07:36 -07005574 return ret;
5575}
5576
5577static void
5578qla2xxx_pci_resume(struct pci_dev *pdev)
5579{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005580 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5581 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005582 int ret;
5583
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005584 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5585 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005586
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005587 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005588 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005589 ql_log(ql_log_fatal, base_vha, 0x9002,
5590 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005591 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005592
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005593 pci_cleanup_aer_uncorrect_error_status(pdev);
5594
Andrew Vasquez85880802009-12-15 21:29:46 -08005595 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005596}
5597
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005598static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005599 .error_detected = qla2xxx_pci_error_detected,
5600 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5601 .slot_reset = qla2xxx_pci_slot_reset,
5602 .resume = qla2xxx_pci_resume,
5603};
5604
Andrew Vasquez54333832005-11-09 15:49:04 -08005605static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005606 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5607 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5608 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5609 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5610 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5611 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5612 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5613 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5614 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005615 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005616 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5617 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005618 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005619 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005620 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005621 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005622 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005623 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005624 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005625 { 0 },
5626};
5627MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5628
Andrew Vasquezfca29702005-07-06 10:31:47 -07005629static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005630 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005631 .driver = {
5632 .owner = THIS_MODULE,
5633 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005634 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005635 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005636 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005637 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005638 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005639};
5640
Al Viro75ef9de2013-04-04 19:09:41 -04005641static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005642 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005643 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005644};
5645
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646/**
5647 * qla2x00_module_init - Module initialization.
5648 **/
5649static int __init
5650qla2x00_module_init(void)
5651{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005652 int ret = 0;
5653
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005655 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005656 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005657 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005658 ql_log(ql_log_fatal, NULL, 0x0001,
5659 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660 return -ENOMEM;
5661 }
5662
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005663 /* Initialize target kmem_cache and mem_pools */
5664 ret = qlt_init();
5665 if (ret < 0) {
5666 kmem_cache_destroy(srb_cachep);
5667 return ret;
5668 } else if (ret > 0) {
5669 /*
5670 * If initiator mode is explictly disabled by qlt_init(),
5671 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5672 * performing scsi_scan_target() during LOOP UP event.
5673 */
5674 qla2xxx_transport_functions.disable_target_scan = 1;
5675 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5676 }
5677
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678 /* Derive version string. */
5679 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005680 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005681 strcat(qla2x00_version_str, "-debug");
5682
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005683 qla2xxx_transport_template =
5684 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005685 if (!qla2xxx_transport_template) {
5686 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005687 ql_log(ql_log_fatal, NULL, 0x0002,
5688 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005689 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005690 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005691 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005692
5693 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5694 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005695 ql_log(ql_log_fatal, NULL, 0x0003,
5696 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005697 }
5698
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005699 qla2xxx_transport_vport_template =
5700 fc_attach_transport(&qla2xxx_transport_vport_functions);
5701 if (!qla2xxx_transport_vport_template) {
5702 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005703 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005704 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005705 ql_log(ql_log_fatal, NULL, 0x0004,
5706 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005707 return -ENODEV;
5708 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005709 ql_log(ql_log_info, NULL, 0x0005,
5710 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005711 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005712 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005713 if (ret) {
5714 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005715 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005716 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005717 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005718 ql_log(ql_log_fatal, NULL, 0x0006,
5719 "pci_register_driver failed...ret=%d Failing load!.\n",
5720 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005721 }
5722 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723}
5724
5725/**
5726 * qla2x00_module_exit - Module cleanup.
5727 **/
5728static void __exit
5729qla2x00_module_exit(void)
5730{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005731 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005732 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005733 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005734 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005735 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005736 if (ctx_cachep)
5737 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005738 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005739 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740}
5741
5742module_init(qla2x00_module_init);
5743module_exit(qla2x00_module_exit);
5744
5745MODULE_AUTHOR("QLogic Corporation");
5746MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5747MODULE_LICENSE("GPL");
5748MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005749MODULE_FIRMWARE(FW_FILE_ISP21XX);
5750MODULE_FIRMWARE(FW_FILE_ISP22XX);
5751MODULE_FIRMWARE(FW_FILE_ISP2300);
5752MODULE_FIRMWARE(FW_FILE_ISP2322);
5753MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005754MODULE_FIRMWARE(FW_FILE_ISP25XX);