blob: e93408f8e7e1c9212c513d8f929d5154b2e0007c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Chad Dupuis46152ce2012-08-22 14:21:08 -04003 * Copyright (c) 2003-2012 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070050int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080051module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052MODULE_PARM_DESC(ql2xlogintimeout,
53 "Login timeout value in seconds.");
54
Andrew Vasqueza7b61842007-05-07 07:42:59 -070055int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080056module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070058 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 "a PORT-DOWN status.");
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061int ql2xplogiabsentdevice;
62module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
63MODULE_PARM_DESC(ql2xplogiabsentdevice,
64 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070065 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080069module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070MODULE_PARM_DESC(ql2xloginretrycount,
71 "Specify an alternate value for the NVRAM login retry count.");
72
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070073int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080074module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070075MODULE_PARM_DESC(ql2xallocfwdump,
76 "Option to enable allocation of memory for a firmware dump "
77 "during HBA initialization. Memory allocation requirements "
78 "vary by ISP type. Default is 1 - allocate memory.");
79
Andrew Vasquez11010fe2006-10-06 09:54:59 -070080int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070081module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070082MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070083 "Option to enable extended error logging,\n"
84 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
85 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
86 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
87 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
88 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
89 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
90 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
91 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050092 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
93 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070094 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080095 "\t\t0x1e400000 - Preferred value for capturing essential "
96 "debug information (equivalent to old "
97 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070098 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -070099
Giridhar Malavalia9083012010-04-12 17:59:55 -0700100int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800101module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700102MODULE_PARM_DESC(ql2xshiftctondsd,
103 "Set to control shifting of command type processing "
104 "based on total number of SG elements.");
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static void qla2x00_free_device(scsi_qla_host_t *);
107
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700108int ql2xfdmienable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800109module_param(ql2xfdmienable, int, S_IRUGO);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700110MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100111 "Enables FDMI registrations. "
112 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700113
Chad Dupuis3c290d02013-01-30 03:34:38 -0500114int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700115module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
116MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400117 "Maximum queue depth to set for each LUN. "
118 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700119
Arun Easi9e522cd2012-08-22 14:21:31 -0400120int ql2xenabledif = 2;
121module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700122MODULE_PARM_DESC(ql2xenabledif,
123 " Enable T10-CRC-DIF "
Arun Easi8cb20492011-08-16 11:29:22 -0700124 " Default is 0 - No DIF Support. 1 - Enable it"
125 ", 2 - Enable DIF for all types, except Type 0.");
Arun Easibad75002010-05-04 15:01:30 -0700126
Arun Easi8cb20492011-08-16 11:29:22 -0700127int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700128module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
129MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700130 " Enable T10-CRC-DIF Error isolation by HBA:\n"
131 " Default is 1.\n"
132 " 0 -- Error isolation disabled\n"
133 " 1 -- Error isolation enabled only for DIX Type 0\n"
134 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700135
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700136int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800137module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700138MODULE_PARM_DESC(ql2xiidmaenable,
139 "Enables iIDMA settings "
140 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
141
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800142int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800143module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800144MODULE_PARM_DESC(ql2xmaxqueues,
145 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700146 "Default is 1 for single queue. Set it to number "
147 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700148
149int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800150module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700151MODULE_PARM_DESC(ql2xmultique_tag,
152 "Enables CPU affinity settings for the driver "
153 "Default is 0 for no affinity of request and response IO. "
154 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700155
156int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700157module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700158MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700159 "Option to specify location from which to load ISP firmware:.\n"
160 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700161 " interface.\n"
162 " 1 -- load firmware from flash.\n"
163 " 0 -- use default semantics.\n");
164
Andrew Vasquezae97c912010-02-18 10:07:28 -0800165int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800166module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800167MODULE_PARM_DESC(ql2xetsenable,
168 "Enables firmware ETS burst."
169 "Default is 0 - skip ETS enablement.");
170
Giridhar Malavali69078692010-05-28 15:08:28 -0700171int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700172module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700173MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700174 "Option to specify scheme for request queue posting.\n"
175 " 0 -- Regular doorbell.\n"
176 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700177
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700178int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800179module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700180MODULE_PARM_DESC(ql2xtargetreset,
181 "Enable target reset."
182 "Default is 1 - use hw defaults.");
183
Chad Dupuis4da26e12010-10-15 11:27:40 -0700184int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800185module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700186MODULE_PARM_DESC(ql2xgffidenable,
187 "Enables GFF_ID checks of port type. "
188 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700189
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700190int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800191module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700192MODULE_PARM_DESC(ql2xasynctmfenable,
193 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
194 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700195
196int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700197module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700198MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700199 "Option to specify reset behaviour.\n"
200 " 0 (Default) -- Reset on failure.\n"
201 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700202
Andrew Vasquez82515922011-05-10 11:30:13 -0700203uint ql2xmaxlun = MAX_LUNS;
204module_param(ql2xmaxlun, uint, S_IRUGO);
205MODULE_PARM_DESC(ql2xmaxlun,
206 "Defines the maximum LU number to register with the SCSI "
207 "midlayer. Default is 65535.");
208
Giridhar Malavali08de2842011-08-16 11:31:44 -0700209int ql2xmdcapmask = 0x1F;
210module_param(ql2xmdcapmask, int, S_IRUGO);
211MODULE_PARM_DESC(ql2xmdcapmask,
212 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800213 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700214
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800215int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700216module_param(ql2xmdenable, int, S_IRUGO);
217MODULE_PARM_DESC(ql2xmdenable,
218 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800219 "0 - MiniDump disabled. "
220 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700223 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 */
225static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500226static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800227static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
228static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500229static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500230static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231static int qla2xxx_eh_abort(struct scsi_cmnd *);
232static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700233static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
235static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Mike Christiee881a172009-10-15 17:46:39 -0700237static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700238static int qla2x00_change_queue_type(struct scsi_device *, int);
239
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{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800357 if (req && req->ring)
358 dma_free_coherent(&ha->pdev->dev,
359 (req->length + 1) * sizeof(request_t),
360 req->ring, req->dma);
361
Chad Dupuis8d93f552013-01-30 03:34:37 -0500362 if (req)
363 kfree(req->outstanding_cmds);
364
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800365 kfree(req);
366 req = NULL;
367}
368
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700369static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
370{
371 if (rsp && rsp->ring)
372 dma_free_coherent(&ha->pdev->dev,
373 (rsp->length + 1) * sizeof(response_t),
374 rsp->ring, rsp->dma);
375
376 kfree(rsp);
377 rsp = NULL;
378}
379
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800380static void qla2x00_free_queues(struct qla_hw_data *ha)
381{
382 struct req_que *req;
383 struct rsp_que *rsp;
384 int cnt;
385
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700386 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800387 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700388 qla2x00_free_req_que(ha, req);
389 }
390 kfree(ha->req_q_map);
391 ha->req_q_map = NULL;
392
393 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
394 rsp = ha->rsp_q_map[cnt];
395 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800396 }
397 kfree(ha->rsp_q_map);
398 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800399}
400
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700401static int qla25xx_setup_mode(struct scsi_qla_host *vha)
402{
403 uint16_t options = 0;
404 int ques, req, ret;
405 struct qla_hw_data *ha = vha->hw;
406
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700407 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700408 ql_log(ql_log_warn, vha, 0x00d8,
409 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700410 goto fail;
411 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700412 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700413 /* create a request queue for IO */
414 options |= BIT_7;
415 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
416 QLA_DEFAULT_QUE_QOS);
417 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700418 ql_log(ql_log_warn, vha, 0x00e0,
419 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700420 goto fail;
421 }
Tejun Heo278274d2011-02-01 11:42:42 +0100422 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700423 vha->req = ha->req_q_map[req];
424 options |= BIT_1;
425 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
426 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
427 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700428 ql_log(ql_log_warn, vha, 0x00e8,
429 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700430 goto fail2;
431 }
432 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700433 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700434 ql_dbg(ql_dbg_multiq, vha, 0xc007,
435 "CPU affinity mode enalbed, "
436 "no. of response queues:%d no. of request queues:%d.\n",
437 ha->max_rsp_queues, ha->max_req_queues);
438 ql_dbg(ql_dbg_init, vha, 0x00e9,
439 "CPU affinity mode enalbed, "
440 "no. of response queues:%d no. of request queues:%d.\n",
441 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700442 }
443 return 0;
444fail2:
445 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700446 destroy_workqueue(ha->wq);
447 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800448 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700449fail:
450 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700451 kfree(ha->req_q_map);
452 kfree(ha->rsp_q_map);
453 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700454 return 1;
455}
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800458qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800460 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 static char *pci_bus_modes[] = {
462 "33", "66", "100", "133",
463 };
464 uint16_t pci_bus;
465
466 strcpy(str, "PCI");
467 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
468 if (pci_bus) {
469 strcat(str, "-X (");
470 strcat(str, pci_bus_modes[pci_bus]);
471 } else {
472 pci_bus = (ha->pci_attr & BIT_8) >> 8;
473 strcat(str, " (");
474 strcat(str, pci_bus_modes[pci_bus]);
475 }
476 strcat(str, " MHz)");
477
478 return (str);
479}
480
Andrew Vasquezfca29702005-07-06 10:31:47 -0700481static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800482qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700483{
484 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800485 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700486 uint32_t pci_bus;
487 int pcie_reg;
488
Jon Masone67f1322012-07-10 14:57:56 -0700489 pcie_reg = pci_pcie_cap(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700490 if (pcie_reg) {
491 char lwstr[6];
492 uint16_t pcie_lstat, lspeed, lwidth;
493
Jon Masone67f1322012-07-10 14:57:56 -0700494 pcie_reg += PCI_EXP_LNKCAP;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700495 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
496 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
497 lwidth = (pcie_lstat &
498 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
499
500 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500501 switch (lspeed) {
502 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700503 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500504 break;
505 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700506 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500507 break;
508 case 3:
509 strcat(str, "8.0GT/s ");
510 break;
511 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700512 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500513 break;
514 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700515 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
516 strcat(str, lwstr);
517
518 return str;
519 }
520
521 strcpy(str, "PCI");
522 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
523 if (pci_bus == 0 || pci_bus == 8) {
524 strcat(str, " (");
525 strcat(str, pci_bus_modes[pci_bus >> 3]);
526 } else {
527 strcat(str, "-X ");
528 if (pci_bus & BIT_2)
529 strcat(str, "Mode 2");
530 else
531 strcat(str, "Mode 1");
532 strcat(str, " (");
533 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
534 }
535 strcat(str, " MHz)");
536
537 return str;
538}
539
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800540static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800541qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
543 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800544 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
547 ha->fw_minor_version,
548 ha->fw_subminor_version);
549
550 if (ha->fw_attributes & BIT_9) {
551 strcat(str, "FLX");
552 return (str);
553 }
554
555 switch (ha->fw_attributes & 0xFF) {
556 case 0x7:
557 strcat(str, "EF");
558 break;
559 case 0x17:
560 strcat(str, "TP");
561 break;
562 case 0x37:
563 strcat(str, "IP");
564 break;
565 case 0x77:
566 strcat(str, "VI");
567 break;
568 default:
569 sprintf(un_str, "(%x)", ha->fw_attributes);
570 strcat(str, un_str);
571 break;
572 }
573 if (ha->fw_attributes & 0x100)
574 strcat(str, "X");
575
576 return (str);
577}
578
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800579static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700581{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700583
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800584 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
585 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700586 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700587}
588
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800589void
590qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800592 srb_t *sp = (srb_t *)ptr;
593 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
594 struct qla_hw_data *ha = sp->fcport->vha->hw;
595 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700596
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800597 if (sp->flags & SRB_DMA_VALID) {
598 scsi_dma_unmap(cmd);
599 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700600 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700601
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800602 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
603 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
604 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
605 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
606 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700607
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800608 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
609 /* List assured to be having elements */
610 qla2x00_clean_dsd_pool(ha, sp);
611 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
612 }
613
614 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
615 dma_pool_free(ha->dl_dma_pool, ctx,
616 ((struct crc_context *)ctx)->crc_ctx_dma);
617 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
618 }
619
620 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
621 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
622
623 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
624 ctx1->fcp_cmnd_dma);
625 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
626 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
627 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
628 mempool_free(ctx1, ha->ctx_mempool);
629 ctx1 = NULL;
630 }
631
632 CMD_SP(cmd) = NULL;
633 mempool_free(sp, ha->srb_mempool);
634}
635
636static void
637qla2x00_sp_compl(void *data, void *ptr, int res)
638{
639 struct qla_hw_data *ha = (struct qla_hw_data *)data;
640 srb_t *sp = (srb_t *)ptr;
641 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
642
643 cmd->result = res;
644
645 if (atomic_read(&sp->ref_count) == 0) {
646 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
647 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
648 sp, GET_CMD_SP(sp));
649 if (ql2xextended_error_logging & ql_dbg_io)
650 BUG();
651 return;
652 }
653 if (!atomic_dec_and_test(&sp->ref_count))
654 return;
655
656 qla2x00_sp_free_dma(ha, sp);
657 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700658}
659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800661qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700662{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700663 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700664 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400665 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800666 struct qla_hw_data *ha = vha->hw;
667 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700668 srb_t *sp;
669 int rval;
670
Andrew Vasquez85880802009-12-15 21:29:46 -0800671 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700672 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400673 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700674 "PCI Channel IO permanent failure, exiting "
675 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700676 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700677 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400678 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700679 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800680 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700681 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700682 goto qc24_fail_command;
683 }
684
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400685 rval = fc_remote_port_chkready(rport);
686 if (rval) {
687 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400688 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700689 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
690 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700691 goto qc24_fail_command;
692 }
693
Arun Easibad75002010-05-04 15:01:30 -0700694 if (!vha->flags.difdix_supported &&
695 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700696 ql_dbg(ql_dbg_io, vha, 0x3004,
697 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
698 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700699 cmd->result = DID_NO_CONNECT << 16;
700 goto qc24_fail_command;
701 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800702
703 if (!fcport) {
704 cmd->result = DID_NO_CONNECT << 16;
705 goto qc24_fail_command;
706 }
707
Andrew Vasquezfca29702005-07-06 10:31:47 -0700708 if (atomic_read(&fcport->state) != FCS_ONLINE) {
709 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700710 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700711 ql_dbg(ql_dbg_io, vha, 0x3005,
712 "Returning DNC, fcport_state=%d loop_state=%d.\n",
713 atomic_read(&fcport->state),
714 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700715 cmd->result = DID_NO_CONNECT << 16;
716 goto qc24_fail_command;
717 }
Mike Christie7b594132008-08-17 15:24:40 -0500718 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700719 }
720
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800721 sp = qla2x00_get_sp(base_vha, fcport, GFP_ATOMIC);
Chad Dupuis3c290d02013-01-30 03:34:38 -0500722 if (!sp) {
723 set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800724 goto qc24_host_busy;
Chad Dupuis3c290d02013-01-30 03:34:38 -0500725 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700726
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800727 sp->u.scmd.cmd = cmd;
728 sp->type = SRB_SCSI_CMD;
729 atomic_set(&sp->ref_count, 1);
730 CMD_SP(cmd) = (void *)sp;
731 sp->free = qla2x00_sp_free_dma;
732 sp->done = qla2x00_sp_compl;
733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700735 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500736 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700737 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Chad Dupuis3c290d02013-01-30 03:34:38 -0500738 set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700739 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700740 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700741
Andrew Vasquezfca29702005-07-06 10:31:47 -0700742 return 0;
743
744qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800745 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700746
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800747qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700748 return SCSI_MLQUEUE_HOST_BUSY;
749
Mike Christie7b594132008-08-17 15:24:40 -0500750qc24_target_busy:
751 return SCSI_MLQUEUE_TARGET_BUSY;
752
Andrew Vasquezfca29702005-07-06 10:31:47 -0700753qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800754 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700755
756 return 0;
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759/*
760 * qla2x00_eh_wait_on_command
761 * Waits for the command to be returned by the Firmware for some
762 * max time.
763 *
764 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 *
767 * Return:
768 * Not Found : 0
769 * Found : 1
770 */
771static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700774#define ABORT_POLLING_PERIOD 1000
775#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500776 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800777 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
778 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500779 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Andrew Vasquez85880802009-12-15 21:29:46 -0800781 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700782 ql_dbg(ql_dbg_taskm, vha, 0x8005,
783 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800784 return ret;
785 }
786
Lalit Chandivaded9704322009-08-25 11:36:18 -0700787 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700788 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500789 }
790 if (CMD_SP(cmd))
791 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
f4f051e2005-04-17 15:02:26 -0500793 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
796/*
797 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700798 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 * <= MAX_RETRIES_OF_ISP_ABORT or
800 * finally HBA is disabled ie marked offline
801 *
802 * Input:
803 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700804 *
805 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 * Does context switching-Release SPIN_LOCK
807 * (if any) before calling this routine.
808 *
809 * Return:
810 * Success (Adapter is online) : 0
811 * Failed (Adapter is offline/disabled) : 1
812 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800813int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800814qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700816 int return_status;
817 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800818 struct qla_hw_data *ha = vha->hw;
819 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700821 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800822 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
823 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
824 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
825 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 msleep(1000);
828 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800829 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700830 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 else
832 return_status = QLA_FUNCTION_FAILED;
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return (return_status);
835}
836
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700837/*
838 * qla2x00_wait_for_reset_ready
839 * Wait till the HBA is online after going through
840 * <= MAX_RETRIES_OF_ISP_ABORT or
841 * finally HBA is disabled ie marked offline or flash
842 * operations are in progress.
843 *
844 * Input:
845 * ha - pointer to host adapter structure
846 *
847 * Note:
848 * Does context switching-Release SPIN_LOCK
849 * (if any) before calling this routine.
850 *
851 * Return:
852 * Success (Adapter is online/no flash ops) : 0
853 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
854 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500855static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700856qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
857{
858 int return_status;
859 unsigned long wait_online;
860 struct qla_hw_data *ha = vha->hw;
861 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
862
863 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
864 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
865 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
866 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
867 ha->optrom_state != QLA_SWAITING ||
868 ha->dpc_active) && time_before(jiffies, wait_online))
869 msleep(1000);
870
871 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
872 return_status = QLA_SUCCESS;
873 else
874 return_status = QLA_FUNCTION_FAILED;
875
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700876 ql_dbg(ql_dbg_taskm, vha, 0x8019,
877 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700878
879 return return_status;
880}
881
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700882int
883qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
884{
885 int return_status;
886 unsigned long wait_reset;
887 struct qla_hw_data *ha = vha->hw;
888 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
889
890 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
891 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
892 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
893 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
894 ha->dpc_active) && time_before(jiffies, wait_reset)) {
895
896 msleep(1000);
897
898 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
899 ha->flags.chip_reset_done)
900 break;
901 }
902 if (ha->flags.chip_reset_done)
903 return_status = QLA_SUCCESS;
904 else
905 return_status = QLA_FUNCTION_FAILED;
906
907 return return_status;
908}
909
Giridhar Malavali083a4692010-05-28 15:08:18 -0700910static void
911sp_get(struct srb *sp)
912{
913 atomic_inc(&sp->ref_count);
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916/**************************************************************************
917* qla2xxx_eh_abort
918*
919* Description:
920* The abort function will abort the specified command.
921*
922* Input:
923* cmd = Linux SCSI command packet to be aborted.
924*
925* Returns:
926* Either SUCCESS or FAILED.
927*
928* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700929* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800931static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932qla2xxx_eh_abort(struct scsi_cmnd *cmd)
933{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500935 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800936 int ret;
f4f051e2005-04-17 15:02:26 -0500937 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700938 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700939 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
f4f051e2005-04-17 15:02:26 -0500942 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700943 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800945 ret = fc_block_scsi_eh(cmd);
946 if (ret != 0)
947 return ret;
948 ret = SUCCESS;
949
f4f051e2005-04-17 15:02:26 -0500950 id = cmd->device->id;
951 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800953 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700954 sp = (srb_t *) CMD_SP(cmd);
955 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800956 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700957 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500958 }
Mike Christie170babc2010-10-15 11:27:47 -0700959
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700960 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800961 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
962 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700963
964 /* Get a reference to the sp and drop the lock.*/
965 sp_get(sp);
966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700968 if (ha->isp_ops->abort_command(sp)) {
Arun Easia55aac72012-02-09 11:14:03 -0800969 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700970 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800971 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700972 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800974 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700975 wait = 1;
976 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700977
978 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800979 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700980 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500981
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700982 /* Did the command return during mailbox execution? */
983 if (ret == FAILED && !CMD_SP(cmd))
984 ret = SUCCESS;
985
f4f051e2005-04-17 15:02:26 -0500986 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700987 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700989 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800990 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -0700991 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700995 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800996 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
997 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
f4f051e2005-04-17 15:02:26 -0500999 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000}
1001
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001002int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001004 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001006 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001007 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001008 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001009 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001010 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001011 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Andrew Vasquez523ec772008-04-03 13:13:24 -07001013 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001014
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001015 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001016 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001017 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001018 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001019 sp = req->outstanding_cmds[cnt];
1020 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001021 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001022 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001023 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001024 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1025 continue;
1026 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001027 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001028 switch (type) {
1029 case WAIT_HOST:
1030 match = 1;
1031 break;
1032 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001033 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001034 break;
1035 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001036 match = (cmd->device->id == t &&
1037 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001038 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001040 if (!match)
1041 continue;
1042
1043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001044 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001045 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001047 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001048
1049 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050}
1051
Andrew Vasquez523ec772008-04-03 13:13:24 -07001052static char *reset_errors[] = {
1053 "HBA not online",
1054 "HBA not ready",
1055 "Task management failed",
1056 "Waiting for command completions",
1057};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Andrew Vasquez523ec772008-04-03 13:13:24 -07001059static int
1060__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001061 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001062{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001064 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1065 int err;
1066
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001067 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001068 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001069 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001070
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001071 err = fc_block_scsi_eh(cmd);
1072 if (err != 0)
1073 return err;
1074
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001075 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001076 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001077 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001078
1079 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1081 ql_log(ql_log_warn, vha, 0x800a,
1082 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001083 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001085 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001086 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001087 != QLA_SUCCESS) {
1088 ql_log(ql_log_warn, vha, 0x800c,
1089 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001090 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001091 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001092 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001093 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001094 cmd->device->lun, type) != QLA_SUCCESS) {
1095 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001096 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001097 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001098 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001099
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001100 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001101 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1102 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001103
1104 return SUCCESS;
1105
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001106eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001107 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001108 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1109 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1110 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001111 return FAILED;
1112}
1113
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001114static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1116{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001117 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1118 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Andrew Vasquez523ec772008-04-03 13:13:24 -07001120 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1121 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001125qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1128 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Andrew Vasquez523ec772008-04-03 13:13:24 -07001130 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1131 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134/**************************************************************************
1135* qla2xxx_eh_bus_reset
1136*
1137* Description:
1138* The bus reset function will reset the bus and abort any executing
1139* commands.
1140*
1141* Input:
1142* cmd = Linux SCSI command packet of the command that cause the
1143* bus reset.
1144*
1145* Returns:
1146* SUCCESS/FAILURE (defined as macro in scsi.h).
1147*
1148**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001149static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1151{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001152 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001153 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001154 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001155 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
f4f051e2005-04-17 15:02:26 -05001157 id = cmd->device->id;
1158 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001159
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001160 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001161 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001164 ret = fc_block_scsi_eh(cmd);
1165 if (ret != 0)
1166 return ret;
1167 ret = FAILED;
1168
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001169 ql_log(ql_log_info, vha, 0x8012,
Andrew Vasquez46270af2012-05-15 14:34:17 -04001170 "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001173 ql_log(ql_log_fatal, vha, 0x8013,
1174 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001175 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
1177
Saurav Kashyapad537682011-11-18 09:02:09 -08001178 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1179 ret = SUCCESS;
1180
f4f051e2005-04-17 15:02:26 -05001181 if (ret == FAILED)
1182 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001184 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001185 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001186 QLA_SUCCESS) {
1187 ql_log(ql_log_warn, vha, 0x8014,
1188 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001189 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
f4f051e2005-04-17 15:02:26 -05001192eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001193 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001194 "BUS RESET %s nexus=%ld:%d:%d.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001195 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
f4f051e2005-04-17 15:02:26 -05001197 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
1200/**************************************************************************
1201* qla2xxx_eh_host_reset
1202*
1203* Description:
1204* The reset function will reset the Adapter.
1205*
1206* Input:
1207* cmd = Linux SCSI command packet of the command that cause the
1208* adapter reset.
1209*
1210* Returns:
1211* Either SUCCESS or FAILED.
1212*
1213* Note:
1214**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001215static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1217{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001219 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001220 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001221 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001222 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
f4f051e2005-04-17 15:02:26 -05001224 id = cmd->device->id;
1225 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001226
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001227 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001228 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001230 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001231 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 if (vha != base_vha) {
1234 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001235 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001237 if (IS_QLA82XX(vha->hw)) {
1238 if (!qla82xx_fcoe_ctx_reset(vha)) {
1239 /* Ctx reset success */
1240 ret = SUCCESS;
1241 goto eh_host_reset_lock;
1242 }
1243 /* fall thru if ctx reset failed */
1244 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001245 if (ha->wq)
1246 flush_workqueue(ha->wq);
1247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001249 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001250 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1251 /* failed. schedule dpc to try */
1252 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1253
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001254 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1255 ql_log(ql_log_warn, vha, 0x802a,
1256 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001257 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001258 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001259 }
1260 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001264 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001265 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001266 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
f4f051e2005-04-17 15:02:26 -05001268eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001269 ql_log(ql_log_info, vha, 0x8017,
1270 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1271 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
f4f051e2005-04-17 15:02:26 -05001273 return ret;
1274}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276/*
1277* qla2x00_loop_reset
1278* Issue loop reset.
1279*
1280* Input:
1281* ha = adapter block pointer.
1282*
1283* Returns:
1284* 0 = success
1285*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001286int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001287qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001289 int ret;
bdf79622005-04-17 15:06:53 -05001290 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001293 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001294 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1295 if (fcport->port_type != FCT_TARGET)
1296 continue;
1297
1298 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1299 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001300 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1301 "Bus Reset failed: Target Reset=%d "
1302 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001303 }
1304 }
1305 }
1306
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001307 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001309 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001310 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1311 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001312 }
1313 atomic_set(&vha->loop_state, LOOP_DOWN);
1314 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1315 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 }
1317
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001318 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001319 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001320 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001321 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1322 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001323 }
1324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001328 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001331void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001332qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001333{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001334 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001335 unsigned long flags;
1336 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001337 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001338 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001339
1340 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001341 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001342 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001343 if (!req)
1344 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001345 if (!req->outstanding_cmds)
1346 continue;
1347 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001348 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001349 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001350 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001351 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001352 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001353 }
1354 }
1355 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1356}
1357
f4f051e2005-04-17 15:02:26 -05001358static int
1359qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
bdf79622005-04-17 15:06:53 -05001361 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001363 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001364 return -ENXIO;
1365
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001366 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001367
1368 return 0;
1369}
1370
1371static int
1372qla2xxx_slave_configure(struct scsi_device *sdev)
1373{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001374 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001375 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001376
Arun Easi9e522cd2012-08-22 14:21:31 -04001377 if (IS_T10_PI_CAPABLE(vha->hw))
1378 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1379
f4f051e2005-04-17 15:02:26 -05001380 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001381 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001383 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001384 return 0;
1385}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
f4f051e2005-04-17 15:02:26 -05001387static void
1388qla2xxx_slave_destroy(struct scsi_device *sdev)
1389{
1390 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391}
1392
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001393static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1394{
1395 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1396
1397 if (!scsi_track_queue_full(sdev, qdepth))
1398 return;
1399
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001400 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001401 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1402 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001403}
1404
1405static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1406{
1407 fc_port_t *fcport = sdev->hostdata;
1408 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001409 struct req_que *req = NULL;
1410
1411 req = vha->req;
1412 if (!req)
1413 return;
1414
1415 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1416 return;
1417
1418 if (sdev->ordered_tags)
1419 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1420 else
1421 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1422
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001423 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001424 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1425 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001426}
1427
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001428static int
Mike Christiee881a172009-10-15 17:46:39 -07001429qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001430{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001431 switch (reason) {
1432 case SCSI_QDEPTH_DEFAULT:
1433 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1434 break;
1435 case SCSI_QDEPTH_QFULL:
1436 qla2x00_handle_queue_full(sdev, qdepth);
1437 break;
1438 case SCSI_QDEPTH_RAMP_UP:
1439 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1440 break;
1441 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001442 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001443 }
Mike Christiee881a172009-10-15 17:46:39 -07001444
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001445 return sdev->queue_depth;
1446}
1447
1448static int
1449qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1450{
1451 if (sdev->tagged_supported) {
1452 scsi_set_tag_type(sdev, tag_type);
1453 if (tag_type)
1454 scsi_activate_tcq(sdev, sdev->queue_depth);
1455 else
1456 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1457 } else
1458 tag_type = 0;
1459
1460 return tag_type;
1461}
1462
Chad Dupuis3c290d02013-01-30 03:34:38 -05001463static void
1464qla2x00_host_ramp_down_queuedepth(scsi_qla_host_t *vha)
1465{
1466 scsi_qla_host_t *vp;
1467 struct Scsi_Host *shost;
1468 struct scsi_device *sdev;
1469 struct qla_hw_data *ha = vha->hw;
1470 unsigned long flags;
1471
1472 ha->host_last_rampdown_time = jiffies;
1473
1474 if (ha->cfg_lun_q_depth <= vha->host->cmd_per_lun)
1475 return;
1476
1477 if ((ha->cfg_lun_q_depth / 2) < vha->host->cmd_per_lun)
1478 ha->cfg_lun_q_depth = vha->host->cmd_per_lun;
1479 else
1480 ha->cfg_lun_q_depth = ha->cfg_lun_q_depth / 2;
1481
1482 /*
1483 * Geometrically ramp down the queue depth for all devices on this
1484 * adapter
1485 */
1486 spin_lock_irqsave(&ha->vport_slock, flags);
1487 list_for_each_entry(vp, &ha->vp_list, list) {
1488 shost = vp->host;
1489 shost_for_each_device(sdev, shost) {
1490 if (sdev->queue_depth > shost->cmd_per_lun) {
1491 if (sdev->queue_depth < ha->cfg_lun_q_depth)
1492 continue;
1493 ql_log(ql_log_warn, vp, 0x3031,
1494 "%ld:%d:%d: Ramping down queue depth to %d",
1495 vp->host_no, sdev->id, sdev->lun,
1496 ha->cfg_lun_q_depth);
1497 qla2x00_change_queue_depth(sdev,
1498 ha->cfg_lun_q_depth, SCSI_QDEPTH_DEFAULT);
1499 }
1500 }
1501 }
1502 spin_unlock_irqrestore(&ha->vport_slock, flags);
1503
1504 return;
1505}
1506
1507static void
1508qla2x00_host_ramp_up_queuedepth(scsi_qla_host_t *vha)
1509{
1510 scsi_qla_host_t *vp;
1511 struct Scsi_Host *shost;
1512 struct scsi_device *sdev;
1513 struct qla_hw_data *ha = vha->hw;
1514 unsigned long flags;
1515
1516 ha->host_last_rampup_time = jiffies;
1517 ha->cfg_lun_q_depth++;
1518
1519 /*
1520 * Linearly ramp up the queue depth for all devices on this
1521 * adapter
1522 */
1523 spin_lock_irqsave(&ha->vport_slock, flags);
1524 list_for_each_entry(vp, &ha->vp_list, list) {
1525 shost = vp->host;
1526 shost_for_each_device(sdev, shost) {
1527 if (sdev->queue_depth > ha->cfg_lun_q_depth)
1528 continue;
1529 qla2x00_change_queue_depth(sdev, ha->cfg_lun_q_depth,
1530 SCSI_QDEPTH_RAMP_UP);
1531 }
1532 }
1533 spin_unlock_irqrestore(&ha->vport_slock, flags);
1534
1535 return;
1536}
1537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538/**
1539 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1540 * @ha: HA context
1541 *
1542 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1543 * supported addressing method.
1544 */
1545static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001546qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001548 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Yang Hongyang6a355282009-04-06 19:01:13 -07001551 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001552 /* Any upper-dword bits set? */
1553 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001554 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001555 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001557 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1558 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001559 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001562
Yang Hongyang284901a2009-04-06 19:01:15 -07001563 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1564 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001567static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001568qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001569{
1570 unsigned long flags = 0;
1571 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1572
1573 spin_lock_irqsave(&ha->hardware_lock, flags);
1574 ha->interrupts_on = 1;
1575 /* enable risc and host interrupts */
1576 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1577 RD_REG_WORD(&reg->ictrl);
1578 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1579
1580}
1581
1582static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001584{
1585 unsigned long flags = 0;
1586 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1587
1588 spin_lock_irqsave(&ha->hardware_lock, flags);
1589 ha->interrupts_on = 0;
1590 /* disable risc and host interrupts */
1591 WRT_REG_WORD(&reg->ictrl, 0);
1592 RD_REG_WORD(&reg->ictrl);
1593 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1594}
1595
1596static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001598{
1599 unsigned long flags = 0;
1600 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1601
1602 spin_lock_irqsave(&ha->hardware_lock, flags);
1603 ha->interrupts_on = 1;
1604 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1605 RD_REG_DWORD(&reg->ictrl);
1606 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1607}
1608
1609static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001610qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001611{
1612 unsigned long flags = 0;
1613 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1614
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001615 if (IS_NOPOLLING_TYPE(ha))
1616 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001617 spin_lock_irqsave(&ha->hardware_lock, flags);
1618 ha->interrupts_on = 0;
1619 WRT_REG_DWORD(&reg->ictrl, 0);
1620 RD_REG_DWORD(&reg->ictrl);
1621 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1622}
1623
Giridhar Malavali706f4572011-11-18 09:03:16 -08001624static int
1625qla2x00_iospace_config(struct qla_hw_data *ha)
1626{
1627 resource_size_t pio;
1628 uint16_t msix;
1629 int cpus;
1630
Giridhar Malavali706f4572011-11-18 09:03:16 -08001631 if (pci_request_selected_regions(ha->pdev, ha->bars,
1632 QLA2XXX_DRIVER_NAME)) {
1633 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1634 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1635 pci_name(ha->pdev));
1636 goto iospace_error_exit;
1637 }
1638 if (!(ha->bars & 1))
1639 goto skip_pio;
1640
1641 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1642 pio = pci_resource_start(ha->pdev, 0);
1643 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1644 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1645 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1646 "Invalid pci I/O region size (%s).\n",
1647 pci_name(ha->pdev));
1648 pio = 0;
1649 }
1650 } else {
1651 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1652 "Region #0 no a PIO resource (%s).\n",
1653 pci_name(ha->pdev));
1654 pio = 0;
1655 }
1656 ha->pio_address = pio;
1657 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1658 "PIO address=%llu.\n",
1659 (unsigned long long)ha->pio_address);
1660
1661skip_pio:
1662 /* Use MMIO operations for all accesses. */
1663 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1664 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1665 "Region #1 not an MMIO resource (%s), aborting.\n",
1666 pci_name(ha->pdev));
1667 goto iospace_error_exit;
1668 }
1669 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1670 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1671 "Invalid PCI mem region size (%s), aborting.\n",
1672 pci_name(ha->pdev));
1673 goto iospace_error_exit;
1674 }
1675
1676 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1677 if (!ha->iobase) {
1678 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1679 "Cannot remap MMIO (%s), aborting.\n",
1680 pci_name(ha->pdev));
1681 goto iospace_error_exit;
1682 }
1683
1684 /* Determine queue resources */
1685 ha->max_req_queues = ha->max_rsp_queues = 1;
1686 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1687 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1688 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1689 goto mqiobase_exit;
1690
1691 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1692 pci_resource_len(ha->pdev, 3));
1693 if (ha->mqiobase) {
1694 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1695 "MQIO Base=%p.\n", ha->mqiobase);
1696 /* Read MSIX vector size of the board */
1697 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1698 ha->msix_count = msix;
1699 /* Max queues are bounded by available msix vectors */
1700 /* queue 0 uses two msix vectors */
1701 if (ql2xmultique_tag) {
1702 cpus = num_online_cpus();
1703 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1704 (cpus + 1) : (ha->msix_count - 1);
1705 ha->max_req_queues = 2;
1706 } else if (ql2xmaxqueues > 1) {
1707 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1708 QLA_MQ_SIZE : ql2xmaxqueues;
1709 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1710 "QoS mode set, max no of request queues:%d.\n",
1711 ha->max_req_queues);
1712 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1713 "QoS mode set, max no of request queues:%d.\n",
1714 ha->max_req_queues);
1715 }
1716 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1717 "MSI-X vector count: %d.\n", msix);
1718 } else
1719 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1720 "BAR 3 not enabled.\n");
1721
1722mqiobase_exit:
1723 ha->msix_count = ha->max_rsp_queues + 1;
1724 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1725 "MSIX Count:%d.\n", ha->msix_count);
1726 return (0);
1727
1728iospace_error_exit:
1729 return (-ENOMEM);
1730}
1731
1732
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001733static int
1734qla83xx_iospace_config(struct qla_hw_data *ha)
1735{
1736 uint16_t msix;
1737 int cpus;
1738
1739 if (pci_request_selected_regions(ha->pdev, ha->bars,
1740 QLA2XXX_DRIVER_NAME)) {
1741 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1742 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1743 pci_name(ha->pdev));
1744
1745 goto iospace_error_exit;
1746 }
1747
1748 /* Use MMIO operations for all accesses. */
1749 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1750 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1751 "Invalid pci I/O region size (%s).\n",
1752 pci_name(ha->pdev));
1753 goto iospace_error_exit;
1754 }
1755 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1756 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1757 "Invalid PCI mem region size (%s), aborting\n",
1758 pci_name(ha->pdev));
1759 goto iospace_error_exit;
1760 }
1761
1762 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1763 if (!ha->iobase) {
1764 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1765 "Cannot remap MMIO (%s), aborting.\n",
1766 pci_name(ha->pdev));
1767 goto iospace_error_exit;
1768 }
1769
1770 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1771 /* 83XX 26XX always use MQ type access for queues
1772 * - mbar 2, a.k.a region 4 */
1773 ha->max_req_queues = ha->max_rsp_queues = 1;
1774 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1775 pci_resource_len(ha->pdev, 4));
1776
1777 if (!ha->mqiobase) {
1778 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1779 "BAR2/region4 not enabled\n");
1780 goto mqiobase_exit;
1781 }
1782
1783 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1784 pci_resource_len(ha->pdev, 2));
1785 if (ha->msixbase) {
1786 /* Read MSIX vector size of the board */
1787 pci_read_config_word(ha->pdev,
1788 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1789 ha->msix_count = msix;
1790 /* Max queues are bounded by available msix vectors */
1791 /* queue 0 uses two msix vectors */
1792 if (ql2xmultique_tag) {
1793 cpus = num_online_cpus();
1794 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1795 (cpus + 1) : (ha->msix_count - 1);
1796 ha->max_req_queues = 2;
1797 } else if (ql2xmaxqueues > 1) {
1798 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1799 QLA_MQ_SIZE : ql2xmaxqueues;
1800 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1801 "QoS mode set, max no of request queues:%d.\n",
1802 ha->max_req_queues);
1803 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1804 "QoS mode set, max no of request queues:%d.\n",
1805 ha->max_req_queues);
1806 }
1807 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1808 "MSI-X vector count: %d.\n", msix);
1809 } else
1810 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1811 "BAR 1 not enabled.\n");
1812
1813mqiobase_exit:
1814 ha->msix_count = ha->max_rsp_queues + 1;
Arun Easiaa230bc2013-01-30 03:34:39 -05001815
1816 qlt_83xx_iospace_config(ha);
1817
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001818 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1819 "MSIX Count:%d.\n", ha->msix_count);
1820 return 0;
1821
1822iospace_error_exit:
1823 return -ENOMEM;
1824}
1825
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001826static struct isp_operations qla2100_isp_ops = {
1827 .pci_config = qla2100_pci_config,
1828 .reset_chip = qla2x00_reset_chip,
1829 .chip_diag = qla2x00_chip_diag,
1830 .config_rings = qla2x00_config_rings,
1831 .reset_adapter = qla2x00_reset_adapter,
1832 .nvram_config = qla2x00_nvram_config,
1833 .update_fw_options = qla2x00_update_fw_options,
1834 .load_risc = qla2x00_load_risc,
1835 .pci_info_str = qla2x00_pci_info_str,
1836 .fw_version_str = qla2x00_fw_version_str,
1837 .intr_handler = qla2100_intr_handler,
1838 .enable_intrs = qla2x00_enable_intrs,
1839 .disable_intrs = qla2x00_disable_intrs,
1840 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001841 .target_reset = qla2x00_abort_target,
1842 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001843 .fabric_login = qla2x00_login_fabric,
1844 .fabric_logout = qla2x00_fabric_logout,
1845 .calc_req_entries = qla2x00_calc_iocbs_32,
1846 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1847 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1848 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1849 .read_nvram = qla2x00_read_nvram_data,
1850 .write_nvram = qla2x00_write_nvram_data,
1851 .fw_dump = qla2100_fw_dump,
1852 .beacon_on = NULL,
1853 .beacon_off = NULL,
1854 .beacon_blink = NULL,
1855 .read_optrom = qla2x00_read_optrom_data,
1856 .write_optrom = qla2x00_write_optrom_data,
1857 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001858 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001859 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001860 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001861};
1862
1863static struct isp_operations qla2300_isp_ops = {
1864 .pci_config = qla2300_pci_config,
1865 .reset_chip = qla2x00_reset_chip,
1866 .chip_diag = qla2x00_chip_diag,
1867 .config_rings = qla2x00_config_rings,
1868 .reset_adapter = qla2x00_reset_adapter,
1869 .nvram_config = qla2x00_nvram_config,
1870 .update_fw_options = qla2x00_update_fw_options,
1871 .load_risc = qla2x00_load_risc,
1872 .pci_info_str = qla2x00_pci_info_str,
1873 .fw_version_str = qla2x00_fw_version_str,
1874 .intr_handler = qla2300_intr_handler,
1875 .enable_intrs = qla2x00_enable_intrs,
1876 .disable_intrs = qla2x00_disable_intrs,
1877 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001878 .target_reset = qla2x00_abort_target,
1879 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001880 .fabric_login = qla2x00_login_fabric,
1881 .fabric_logout = qla2x00_fabric_logout,
1882 .calc_req_entries = qla2x00_calc_iocbs_32,
1883 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1884 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1885 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1886 .read_nvram = qla2x00_read_nvram_data,
1887 .write_nvram = qla2x00_write_nvram_data,
1888 .fw_dump = qla2300_fw_dump,
1889 .beacon_on = qla2x00_beacon_on,
1890 .beacon_off = qla2x00_beacon_off,
1891 .beacon_blink = qla2x00_beacon_blink,
1892 .read_optrom = qla2x00_read_optrom_data,
1893 .write_optrom = qla2x00_write_optrom_data,
1894 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001896 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001897 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001898};
1899
1900static struct isp_operations qla24xx_isp_ops = {
1901 .pci_config = qla24xx_pci_config,
1902 .reset_chip = qla24xx_reset_chip,
1903 .chip_diag = qla24xx_chip_diag,
1904 .config_rings = qla24xx_config_rings,
1905 .reset_adapter = qla24xx_reset_adapter,
1906 .nvram_config = qla24xx_nvram_config,
1907 .update_fw_options = qla24xx_update_fw_options,
1908 .load_risc = qla24xx_load_risc,
1909 .pci_info_str = qla24xx_pci_info_str,
1910 .fw_version_str = qla24xx_fw_version_str,
1911 .intr_handler = qla24xx_intr_handler,
1912 .enable_intrs = qla24xx_enable_intrs,
1913 .disable_intrs = qla24xx_disable_intrs,
1914 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001915 .target_reset = qla24xx_abort_target,
1916 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001917 .fabric_login = qla24xx_login_fabric,
1918 .fabric_logout = qla24xx_fabric_logout,
1919 .calc_req_entries = NULL,
1920 .build_iocbs = NULL,
1921 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1922 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1923 .read_nvram = qla24xx_read_nvram_data,
1924 .write_nvram = qla24xx_write_nvram_data,
1925 .fw_dump = qla24xx_fw_dump,
1926 .beacon_on = qla24xx_beacon_on,
1927 .beacon_off = qla24xx_beacon_off,
1928 .beacon_blink = qla24xx_beacon_blink,
1929 .read_optrom = qla24xx_read_optrom_data,
1930 .write_optrom = qla24xx_write_optrom_data,
1931 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001933 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001934 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001935};
1936
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001937static struct isp_operations qla25xx_isp_ops = {
1938 .pci_config = qla25xx_pci_config,
1939 .reset_chip = qla24xx_reset_chip,
1940 .chip_diag = qla24xx_chip_diag,
1941 .config_rings = qla24xx_config_rings,
1942 .reset_adapter = qla24xx_reset_adapter,
1943 .nvram_config = qla24xx_nvram_config,
1944 .update_fw_options = qla24xx_update_fw_options,
1945 .load_risc = qla24xx_load_risc,
1946 .pci_info_str = qla24xx_pci_info_str,
1947 .fw_version_str = qla24xx_fw_version_str,
1948 .intr_handler = qla24xx_intr_handler,
1949 .enable_intrs = qla24xx_enable_intrs,
1950 .disable_intrs = qla24xx_disable_intrs,
1951 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001952 .target_reset = qla24xx_abort_target,
1953 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001954 .fabric_login = qla24xx_login_fabric,
1955 .fabric_logout = qla24xx_fabric_logout,
1956 .calc_req_entries = NULL,
1957 .build_iocbs = NULL,
1958 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1959 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1960 .read_nvram = qla25xx_read_nvram_data,
1961 .write_nvram = qla25xx_write_nvram_data,
1962 .fw_dump = qla25xx_fw_dump,
1963 .beacon_on = qla24xx_beacon_on,
1964 .beacon_off = qla24xx_beacon_off,
1965 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001966 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001967 .write_optrom = qla24xx_write_optrom_data,
1968 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001969 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001970 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001971 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001972};
1973
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001974static struct isp_operations qla81xx_isp_ops = {
1975 .pci_config = qla25xx_pci_config,
1976 .reset_chip = qla24xx_reset_chip,
1977 .chip_diag = qla24xx_chip_diag,
1978 .config_rings = qla24xx_config_rings,
1979 .reset_adapter = qla24xx_reset_adapter,
1980 .nvram_config = qla81xx_nvram_config,
1981 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001982 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001983 .pci_info_str = qla24xx_pci_info_str,
1984 .fw_version_str = qla24xx_fw_version_str,
1985 .intr_handler = qla24xx_intr_handler,
1986 .enable_intrs = qla24xx_enable_intrs,
1987 .disable_intrs = qla24xx_disable_intrs,
1988 .abort_command = qla24xx_abort_command,
1989 .target_reset = qla24xx_abort_target,
1990 .lun_reset = qla24xx_lun_reset,
1991 .fabric_login = qla24xx_login_fabric,
1992 .fabric_logout = qla24xx_fabric_logout,
1993 .calc_req_entries = NULL,
1994 .build_iocbs = NULL,
1995 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1996 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001997 .read_nvram = NULL,
1998 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001999 .fw_dump = qla81xx_fw_dump,
2000 .beacon_on = qla24xx_beacon_on,
2001 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002002 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002003 .read_optrom = qla25xx_read_optrom_data,
2004 .write_optrom = qla24xx_write_optrom_data,
2005 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002006 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002007 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002008 .iospace_config = qla2x00_iospace_config,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002009};
2010
2011static struct isp_operations qla82xx_isp_ops = {
2012 .pci_config = qla82xx_pci_config,
2013 .reset_chip = qla82xx_reset_chip,
2014 .chip_diag = qla24xx_chip_diag,
2015 .config_rings = qla82xx_config_rings,
2016 .reset_adapter = qla24xx_reset_adapter,
2017 .nvram_config = qla81xx_nvram_config,
2018 .update_fw_options = qla24xx_update_fw_options,
2019 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002020 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002021 .fw_version_str = qla24xx_fw_version_str,
2022 .intr_handler = qla82xx_intr_handler,
2023 .enable_intrs = qla82xx_enable_intrs,
2024 .disable_intrs = qla82xx_disable_intrs,
2025 .abort_command = qla24xx_abort_command,
2026 .target_reset = qla24xx_abort_target,
2027 .lun_reset = qla24xx_lun_reset,
2028 .fabric_login = qla24xx_login_fabric,
2029 .fabric_logout = qla24xx_fabric_logout,
2030 .calc_req_entries = NULL,
2031 .build_iocbs = NULL,
2032 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2033 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2034 .read_nvram = qla24xx_read_nvram_data,
2035 .write_nvram = qla24xx_write_nvram_data,
2036 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002037 .beacon_on = qla82xx_beacon_on,
2038 .beacon_off = qla82xx_beacon_off,
2039 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002040 .read_optrom = qla82xx_read_optrom_data,
2041 .write_optrom = qla82xx_write_optrom_data,
2042 .get_flash_version = qla24xx_get_flash_version,
2043 .start_scsi = qla82xx_start_scsi,
2044 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002045 .iospace_config = qla82xx_iospace_config,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002046};
2047
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002048static struct isp_operations qla83xx_isp_ops = {
2049 .pci_config = qla25xx_pci_config,
2050 .reset_chip = qla24xx_reset_chip,
2051 .chip_diag = qla24xx_chip_diag,
2052 .config_rings = qla24xx_config_rings,
2053 .reset_adapter = qla24xx_reset_adapter,
2054 .nvram_config = qla81xx_nvram_config,
2055 .update_fw_options = qla81xx_update_fw_options,
2056 .load_risc = qla81xx_load_risc,
2057 .pci_info_str = qla24xx_pci_info_str,
2058 .fw_version_str = qla24xx_fw_version_str,
2059 .intr_handler = qla24xx_intr_handler,
2060 .enable_intrs = qla24xx_enable_intrs,
2061 .disable_intrs = qla24xx_disable_intrs,
2062 .abort_command = qla24xx_abort_command,
2063 .target_reset = qla24xx_abort_target,
2064 .lun_reset = qla24xx_lun_reset,
2065 .fabric_login = qla24xx_login_fabric,
2066 .fabric_logout = qla24xx_fabric_logout,
2067 .calc_req_entries = NULL,
2068 .build_iocbs = NULL,
2069 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2070 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2071 .read_nvram = NULL,
2072 .write_nvram = NULL,
2073 .fw_dump = qla83xx_fw_dump,
2074 .beacon_on = qla24xx_beacon_on,
2075 .beacon_off = qla24xx_beacon_off,
2076 .beacon_blink = qla83xx_beacon_blink,
2077 .read_optrom = qla25xx_read_optrom_data,
2078 .write_optrom = qla24xx_write_optrom_data,
2079 .get_flash_version = qla24xx_get_flash_version,
2080 .start_scsi = qla24xx_dif_start_scsi,
2081 .abort_isp = qla2x00_abort_isp,
2082 .iospace_config = qla83xx_iospace_config,
2083};
2084
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002085static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002087{
2088 ha->device_type = DT_EXTENDED_IDS;
2089 switch (ha->pdev->device) {
2090 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2091 ha->device_type |= DT_ISP2100;
2092 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002093 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002094 break;
2095 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2096 ha->device_type |= DT_ISP2200;
2097 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002098 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002099 break;
2100 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2101 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002102 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002103 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002104 break;
2105 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2106 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002107 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002108 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002109 break;
2110 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2111 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002112 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002113 if (ha->pdev->subsystem_vendor == 0x1028 &&
2114 ha->pdev->subsystem_device == 0x0170)
2115 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002116 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002117 break;
2118 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2119 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002120 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002121 break;
2122 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2123 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002124 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002125 break;
2126 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2127 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002128 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002129 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002130 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002131 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002132 break;
2133 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2134 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002135 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002136 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002137 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002138 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002139 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002140 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2141 ha->device_type |= DT_ISP8432;
2142 ha->device_type |= DT_ZIO_SUPPORTED;
2143 ha->device_type |= DT_FWI2;
2144 ha->device_type |= DT_IIDMA;
2145 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2146 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002147 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2148 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002149 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002150 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002151 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002152 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2153 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002154 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002155 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002156 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002157 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2158 ha->device_type |= DT_ISP2532;
2159 ha->device_type |= DT_ZIO_SUPPORTED;
2160 ha->device_type |= DT_FWI2;
2161 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002162 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2163 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002164 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2165 ha->device_type |= DT_ISP8001;
2166 ha->device_type |= DT_ZIO_SUPPORTED;
2167 ha->device_type |= DT_FWI2;
2168 ha->device_type |= DT_IIDMA;
2169 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2170 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002171 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2172 ha->device_type |= DT_ISP8021;
2173 ha->device_type |= DT_ZIO_SUPPORTED;
2174 ha->device_type |= DT_FWI2;
2175 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2176 /* Initialize 82XX ISP flags */
2177 qla82xx_init_flags(ha);
2178 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002179 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2180 ha->device_type |= DT_ISP2031;
2181 ha->device_type |= DT_ZIO_SUPPORTED;
2182 ha->device_type |= DT_FWI2;
2183 ha->device_type |= DT_IIDMA;
2184 ha->device_type |= DT_T10_PI;
2185 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2186 break;
2187 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2188 ha->device_type |= DT_ISP8031;
2189 ha->device_type |= DT_ZIO_SUPPORTED;
2190 ha->device_type |= DT_FWI2;
2191 ha->device_type |= DT_IIDMA;
2192 ha->device_type |= DT_T10_PI;
2193 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2194 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002195 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002196
Giridhar Malavalia9083012010-04-12 17:59:55 -07002197 if (IS_QLA82XX(ha))
2198 ha->port_no = !(ha->portnum & 1);
2199 else
2200 /* Get adapter physical port no from interrupt pin register. */
2201 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2202
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002203 if (ha->port_no & 1)
2204 ha->flags.port0 = 1;
2205 else
2206 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002207 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002208 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002209 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002210}
2211
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002212static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002213qla2xxx_scan_start(struct Scsi_Host *shost)
2214{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002215 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002216
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002217 if (vha->hw->flags.running_gold_fw)
2218 return;
2219
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002220 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2221 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2222 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2223 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002224}
2225
2226static int
2227qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2228{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002230
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002232 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002233 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002234 return 1;
2235
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002237}
2238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239/*
2240 * PCI driver interface
2241 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002242static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002243qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002245 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002247 scsi_qla_host_t *base_vha = NULL;
2248 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002249 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002250 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002251 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002252 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002254 struct req_que *req = NULL;
2255 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
Andrew Vasquez285d0322007-10-19 15:59:17 -07002257 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002258 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002259 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2260 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002261 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002262 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2263 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002264 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002265 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002266 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2267 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2268 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002269 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002270 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002271 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2272 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002273 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002274 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2275 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002276
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002277 if (mem_only) {
2278 if (pci_enable_device_mem(pdev))
2279 goto probe_out;
2280 } else {
2281 if (pci_enable_device(pdev))
2282 goto probe_out;
2283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Jesse Barnes09276782008-10-18 17:33:19 -07002285 /* This may fail but that's ok */
2286 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002287
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2289 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002290 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2291 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002294 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2295 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002296 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002297 ha->tgt.enable_class_2 = ql2xenableclass2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
2299 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002300 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002301 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002302 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002303 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002304 mutex_init(&ha->selflogin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002306 /* Set ISP-type information. */
2307 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002308
2309 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002310 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2311 IS_QLA83XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002312 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002313
Chad Dupuiscba1e472011-11-18 09:03:21 -08002314 ha->prev_topology = 0;
2315 ha->init_cb_size = sizeof(init_cb_t);
2316 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2317 ha->optrom_size = OPTROM_SIZE_2300;
Chad Dupuis3c290d02013-01-30 03:34:38 -05002318 ha->cfg_lun_q_depth = ql2xmaxqdepth;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002319
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002320 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002322 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002324 req_length = REQUEST_ENTRY_CNT_2100;
2325 rsp_length = RESPONSE_ENTRY_CNT_2100;
2326 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002327 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002328 ha->flash_conf_off = ~0;
2329 ha->flash_data_off = ~0;
2330 ha->nvram_conf_off = ~0;
2331 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002332 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002334 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002335 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 req_length = REQUEST_ENTRY_CNT_2200;
2337 rsp_length = RESPONSE_ENTRY_CNT_2100;
2338 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002339 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002340 ha->flash_conf_off = ~0;
2341 ha->flash_data_off = ~0;
2342 ha->nvram_conf_off = ~0;
2343 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002344 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002345 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002346 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348 req_length = REQUEST_ENTRY_CNT_2200;
2349 rsp_length = RESPONSE_ENTRY_CNT_2300;
2350 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002351 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002352 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2353 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002354 ha->flash_conf_off = ~0;
2355 ha->flash_data_off = ~0;
2356 ha->nvram_conf_off = ~0;
2357 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002358 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002359 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002360 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002361 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002362 req_length = REQUEST_ENTRY_CNT_24XX;
2363 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002364 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002366 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002367 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002368 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002369 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002370 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002371 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2372 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2373 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2374 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002375 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002376 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002377 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 req_length = REQUEST_ENTRY_CNT_24XX;
2379 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002380 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002382 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002383 ha->gid_list_info_size = 8;
2384 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002385 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002386 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002387 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2388 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2389 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2390 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2391 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002392 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002393 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2394 req_length = REQUEST_ENTRY_CNT_24XX;
2395 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002396 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002397 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2398 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2399 ha->gid_list_info_size = 8;
2400 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002401 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002402 ha->isp_ops = &qla81xx_isp_ops;
2403 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2404 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2405 ha->nvram_conf_off = ~0;
2406 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002407 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002408 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002409 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2410 req_length = REQUEST_ENTRY_CNT_82XX;
2411 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2412 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2413 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2414 ha->gid_list_info_size = 8;
2415 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002416 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002417 ha->isp_ops = &qla82xx_isp_ops;
2418 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2419 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2420 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2421 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002422 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002423 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002424 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002425 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2426 req_length = REQUEST_ENTRY_CNT_24XX;
2427 rsp_length = RESPONSE_ENTRY_CNT_2300;
2428 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2429 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2430 ha->gid_list_info_size = 8;
2431 ha->optrom_size = OPTROM_SIZE_83XX;
2432 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2433 ha->isp_ops = &qla83xx_isp_ops;
2434 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2435 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2436 ha->nvram_conf_off = ~0;
2437 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002439
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002440 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2441 "mbx_count=%d, req_length=%d, "
2442 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002443 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2444 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002445 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2446 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002447 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002448 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2449 "isp_ops=%p, flash_conf_off=%d, "
2450 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2451 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2452 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002453
2454 /* Configure PCI I/O space */
2455 ret = ha->isp_ops->iospace_config(ha);
2456 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002457 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002458
2459 ql_log_pci(ql_log_info, pdev, 0x001d,
2460 "Found an ISP%04X irq %d iobase 0x%p.\n",
2461 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002462 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002463 init_completion(&ha->mbx_cmd_comp);
2464 complete(&ha->mbx_cmd_comp);
2465 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002466 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002468 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
Andrew Vasquez53303c42009-01-22 09:45:37 -08002470 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002471 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2472 "64 Bit addressing is %s.\n",
2473 ha->flags.enable_64bit_addressing ? "enable" :
2474 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002475 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002477 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2478 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480 goto probe_hw_failed;
2481 }
2482
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002483 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002485 req->max_q_depth = ql2xmaxqdepth;
2486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002487
2488 base_vha = qla2x00_create_host(sht, ha);
2489 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002490 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002491 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002492 qla2x00_free_req_que(ha, req);
2493 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 }
2496
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002499 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002500 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002501 host->can_queue = req->length + 128;
2502 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002503 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002504 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2506 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002507
2508 /* Set the SG table size based on ISP type */
2509 if (!IS_FWI2_CAPABLE(ha)) {
2510 if (IS_QLA2100(ha))
2511 host->sg_tablesize = 32;
2512 } else {
2513 if (!IS_QLA82XX(ha))
2514 host->sg_tablesize = QLA_SG_ALL;
2515 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002516 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2517 "can_queue=%d, req=%p, "
2518 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2519 host->can_queue, base_vha->req,
2520 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Chad Dupuis642ef982012-02-09 11:15:57 -08002521 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002522 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002523 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002524 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002525 host->max_cmd_len = 32;
2526 else
2527 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002528 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002529 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002530 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002531 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002532
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002533 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2534 "max_id=%d this_id=%d "
2535 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002536 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002537 host->this_id, host->cmd_per_lun, host->unique_id,
2538 host->max_cmd_len, host->max_channel, host->max_lun,
2539 host->transportt, sht->vendor_id);
2540
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002541que_init:
2542 /* Alloc arrays of request and response ring ptrs */
2543 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2544 ql_log(ql_log_fatal, base_vha, 0x003d,
2545 "Failed to allocate memory for queue pointers..."
2546 "aborting.\n");
2547 goto probe_init_failed;
2548 }
2549
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002550 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002551
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002552 /* Set up the irqs */
2553 ret = qla2x00_request_irqs(ha, rsp);
2554 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002555 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002556
2557 pci_save_state(pdev);
2558
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002559 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002560 rsp->req = req;
2561 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002562
Andrew Vasquez08029992009-03-24 09:07:55 -07002563 /* FWI2-capable only. */
2564 req->req_q_in = &ha->iobase->isp24.req_q_in;
2565 req->req_q_out = &ha->iobase->isp24.req_q_out;
2566 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2567 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002568 if (ha->mqenable || IS_QLA83XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002569 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2570 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2571 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2572 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002573 }
2574
Giridhar Malavalia9083012010-04-12 17:59:55 -07002575 if (IS_QLA82XX(ha)) {
2576 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2577 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2578 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2579 }
2580
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002581 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2582 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2583 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2584 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2585 "req->req_q_in=%p req->req_q_out=%p "
2586 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2587 req->req_q_in, req->req_q_out,
2588 rsp->rsp_q_in, rsp->rsp_q_out);
2589 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2590 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2591 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2592 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2593 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2594 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002596 if (qla2x00_initialize_adapter(base_vha)) {
2597 ql_log(ql_log_fatal, base_vha, 0x00d6,
2598 "Failed to initialize adapter - Adapter flags %x.\n",
2599 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600
Giridhar Malavalia9083012010-04-12 17:59:55 -07002601 if (IS_QLA82XX(ha)) {
2602 qla82xx_idc_lock(ha);
2603 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002604 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002605 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002606 ql_log(ql_log_fatal, base_vha, 0x00d7,
2607 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002608 }
2609
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 ret = -ENODEV;
2611 goto probe_failed;
2612 }
2613
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002614 if (ha->mqenable) {
2615 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002616 ql_log(ql_log_warn, base_vha, 0x00ec,
2617 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002618 goto que_init;
2619 }
2620 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002621
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002622 if (ha->flags.running_gold_fw)
2623 goto skip_dpc;
2624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625 /*
2626 * Startup the kernel thread for this host adapter
2627 */
2628 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002629 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002631 ql_log(ql_log_fatal, base_vha, 0x00ed,
2632 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 ret = PTR_ERR(ha->dpc_thread);
2634 goto probe_failed;
2635 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002636 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2637 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002639 /*
2640 * If we're not coming up in initiator mode, we might sit for
2641 * a while without waking up the dpc thread, which leads to a
2642 * stuck process warning. So just kick the dpc once here and
2643 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2644 */
2645 qla2xxx_wake_dpc(base_vha);
2646
Saurav Kashyap81178772012-08-22 14:21:04 -04002647 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2648 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2649 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2650 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2651
2652 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2653 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2654 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2655 INIT_WORK(&ha->idc_state_handler,
2656 qla83xx_idc_state_handler_work);
2657 INIT_WORK(&ha->nic_core_unrecoverable,
2658 qla83xx_nic_core_unrecoverable_work);
2659 }
2660
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002661skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 list_add_tail(&base_vha->list, &ha->vp_list);
2663 base_vha->host->irq = ha->pdev->irq;
2664
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002667 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2668 "Started qla2x00_timer with "
2669 "interval=%d.\n", WATCH_INTERVAL);
2670 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2671 "Detected hba at address=%p.\n",
2672 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
Arun Easie02587d2011-08-16 11:29:23 -07002674 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002675 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002676 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002677 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002678 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2679 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002680 if (ql2xenabledif == 1)
2681 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002682 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002683 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002684 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002685 | SHOST_DIF_TYPE3_PROTECTION
2686 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002687 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002688 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002689
2690 guard = SHOST_DIX_GUARD_CRC;
2691
2692 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2693 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2694 guard |= SHOST_DIX_GUARD_IP;
2695
2696 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002697 } else
2698 base_vha->flags.difdix_supported = 0;
2699 }
2700
Giridhar Malavalia9083012010-04-12 17:59:55 -07002701 ha->isp_ops->enable_intrs(ha);
2702
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002703 ret = scsi_add_host(host, &pdev->dev);
2704 if (ret)
2705 goto probe_failed;
2706
Michael Reed14864002009-12-02 09:11:16 -06002707 base_vha->flags.init_done = 1;
2708 base_vha->flags.online = 1;
2709
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002710 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2711 "Init done and hba is online.\n");
2712
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002713 if (qla_ini_mode_enabled(base_vha))
2714 scsi_scan_host(host);
2715 else
2716 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2717 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002718
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002720
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002724
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002725 ql_log(ql_log_info, base_vha, 0x00fb,
2726 "QLogic %s - %s.\n",
2727 ha->model_number, ha->model_desc ? ha->model_desc : "");
2728 ql_log(ql_log_info, base_vha, 0x00fc,
2729 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2730 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2731 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2732 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002733 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002735 qlt_add_target(ha, base_vha);
2736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 return 0;
2738
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002739probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002740 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002741 ha->req_q_map[0] = NULL;
2742 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002743 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002744 ha->rsp_q_map[0] = NULL;
2745 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002746 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002747
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002749 if (base_vha->timer_active)
2750 qla2x00_stop_timer(base_vha);
2751 base_vha->flags.online = 0;
2752 if (ha->dpc_thread) {
2753 struct task_struct *t = ha->dpc_thread;
2754
2755 ha->dpc_thread = NULL;
2756 kthread_stop(t);
2757 }
2758
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002764 if (IS_QLA82XX(ha)) {
2765 qla82xx_idc_lock(ha);
2766 qla82xx_clear_drv_active(ha);
2767 qla82xx_idc_unlock(ha);
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002768 }
2769iospace_config_failed:
2770 if (IS_QLA82XX(ha)) {
2771 if (!ha->nx_pcibase)
2772 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002773 if (!ql2xdbwr)
2774 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2775 } else {
2776 if (ha->iobase)
2777 iounmap(ha->iobase);
2778 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 pci_release_selected_regions(ha->pdev, ha->bars);
2780 kfree(ha);
2781 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002783probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002784 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002785 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
Adrian Bunk4c993f72008-01-14 00:55:16 -08002788static void
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002789qla2x00_stop_dpc_thread(scsi_qla_host_t *vha)
2790{
2791 struct qla_hw_data *ha = vha->hw;
2792 struct task_struct *t = ha->dpc_thread;
2793
2794 if (ha->dpc_thread == NULL)
2795 return;
2796 /*
2797 * qla2xxx_wake_dpc checks for ->dpc_thread
2798 * so we need to zero it out.
2799 */
2800 ha->dpc_thread = NULL;
2801 kthread_stop(t);
2802}
2803
2804static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002805qla2x00_shutdown(struct pci_dev *pdev)
2806{
2807 scsi_qla_host_t *vha;
2808 struct qla_hw_data *ha;
2809
2810 vha = pci_get_drvdata(pdev);
2811 ha = vha->hw;
2812
2813 /* Turn-off FCE trace */
2814 if (ha->flags.fce_enabled) {
2815 qla2x00_disable_fce_trace(vha, NULL, NULL);
2816 ha->flags.fce_enabled = 0;
2817 }
2818
2819 /* Turn-off EFT trace */
2820 if (ha->eft)
2821 qla2x00_disable_eft_trace(vha);
2822
2823 /* Stop currently executing firmware. */
2824 qla2x00_try_to_stop_firmware(vha);
2825
2826 /* Turn adapter off line */
2827 vha->flags.online = 0;
2828
2829 /* turn-off interrupts on the card */
2830 if (ha->interrupts_on) {
2831 vha->flags.init_done = 0;
2832 ha->isp_ops->disable_intrs(ha);
2833 }
2834
2835 qla2x00_free_irqs(vha);
2836
2837 qla2x00_free_fw_dump(ha);
2838}
2839
2840static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002841qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842{
Arun Easifeafb7b2010-09-03 14:57:00 -07002843 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002845 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002847 /*
2848 * If the PCI device is disabled that means that probe failed and any
2849 * resources should be have cleaned up on probe exit.
2850 */
2851 if (!atomic_read(&pdev->enable_cnt))
2852 return;
2853
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002854 base_vha = pci_get_drvdata(pdev);
2855 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002857 ha->flags.host_shutting_down = 1;
2858
Giridhar Malavali220d36b2012-11-21 02:39:55 -05002859 set_bit(UNLOADING, &base_vha->dpc_flags);
Arun Easi43ebf162011-05-10 11:18:16 -07002860 mutex_lock(&ha->vport_lock);
2861 while (ha->cur_vport_count) {
2862 struct Scsi_Host *scsi_host;
Arun Easifeafb7b2010-09-03 14:57:00 -07002863
Arun Easi43ebf162011-05-10 11:18:16 -07002864 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002865
Arun Easi43ebf162011-05-10 11:18:16 -07002866 BUG_ON(base_vha->list.next == &ha->vp_list);
2867 /* This assumes first entry in ha->vp_list is always base vha */
2868 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2869 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002870
Arun Easi43ebf162011-05-10 11:18:16 -07002871 spin_unlock_irqrestore(&ha->vport_slock, flags);
2872 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002873
Arun Easi43ebf162011-05-10 11:18:16 -07002874 fc_vport_terminate(vha->fc_vport);
2875 scsi_host_put(vha->host);
2876
2877 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 }
Arun Easi43ebf162011-05-10 11:18:16 -07002879 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002880
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002881 if (IS_QLA8031(ha)) {
2882 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
2883 "Clearing fcoe driver presence.\n");
2884 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
2885 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
2886 "Error while clearing DRV-Presence.\n");
2887 }
2888
Andrew Vasquezb9978762009-03-24 09:08:05 -07002889 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2890
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002893 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002894
Andrew Vasquezb9978762009-03-24 09:08:05 -07002895 /* Disable timer */
2896 if (base_vha->timer_active)
2897 qla2x00_stop_timer(base_vha);
2898
2899 base_vha->flags.online = 0;
2900
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002901 /* Flush the work queue and remove it */
2902 if (ha->wq) {
2903 flush_workqueue(ha->wq);
2904 destroy_workqueue(ha->wq);
2905 ha->wq = NULL;
2906 }
2907
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002908 /* Cancel all work and destroy DPC workqueues */
2909 if (ha->dpc_lp_wq) {
2910 cancel_work_sync(&ha->idc_aen);
2911 destroy_workqueue(ha->dpc_lp_wq);
2912 ha->dpc_lp_wq = NULL;
2913 }
2914
2915 if (ha->dpc_hp_wq) {
2916 cancel_work_sync(&ha->nic_core_reset);
2917 cancel_work_sync(&ha->idc_state_handler);
2918 cancel_work_sync(&ha->nic_core_unrecoverable);
2919 destroy_workqueue(ha->dpc_hp_wq);
2920 ha->dpc_hp_wq = NULL;
2921 }
2922
Andrew Vasquezb9978762009-03-24 09:08:05 -07002923 /* Kill the kernel thread for this host */
2924 if (ha->dpc_thread) {
2925 struct task_struct *t = ha->dpc_thread;
2926
2927 /*
2928 * qla2xxx_wake_dpc checks for ->dpc_thread
2929 * so we need to zero it out.
2930 */
2931 ha->dpc_thread = NULL;
2932 kthread_stop(t);
2933 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002934 qlt_remove_target(ha, base_vha);
Andrew Vasquezb9978762009-03-24 09:08:05 -07002935
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002936 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002944 scsi_host_put(base_vha->host);
2945
Giridhar Malavalia9083012010-04-12 17:59:55 -07002946 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002947 qla82xx_idc_lock(ha);
2948 qla82xx_clear_drv_active(ha);
2949 qla82xx_idc_unlock(ha);
2950
Giridhar Malavalia9083012010-04-12 17:59:55 -07002951 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2952 if (!ql2xdbwr)
2953 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2954 } else {
2955 if (ha->iobase)
2956 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957
Giridhar Malavalia9083012010-04-12 17:59:55 -07002958 if (ha->mqiobase)
2959 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002960
2961 if (IS_QLA83XX(ha) && ha->msixbase)
2962 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002963 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 pci_release_selected_regions(ha->pdev, ha->bars);
2966 kfree(ha);
2967 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002969 pci_disable_pcie_error_reporting(pdev);
2970
Bernhard Walle665db932007-03-28 00:49:49 +02002971 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 pci_set_drvdata(pdev, NULL);
2973}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979
Andrew Vasquez85880802009-12-15 21:29:46 -08002980 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2981
2982 /* Disable timer */
2983 if (vha->timer_active)
2984 qla2x00_stop_timer(vha);
2985
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002986 qla2x00_stop_dpc_thread(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08002987
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002988 qla25xx_delete_queues(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002989 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002991
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002992 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002993 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002994
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002995 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Andrew Vasquez85880802009-12-15 21:29:46 -08002998 vha->flags.online = 0;
2999
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003000 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003001 if (ha->interrupts_on) {
3002 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003003 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003004 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 qla2x00_free_irqs(vha);
3007
Chad Dupuis88670482010-07-23 15:28:30 +05003008 qla2x00_free_fcports(vha);
3009
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003010 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003011
Giridhar Malavali08de2842011-08-16 11:31:44 -07003012 qla82xx_md_free(vha);
3013
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003014 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015}
3016
Chad Dupuis88670482010-07-23 15:28:30 +05003017void qla2x00_free_fcports(struct scsi_qla_host *vha)
3018{
3019 fc_port_t *fcport, *tfcport;
3020
3021 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3022 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003023 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003024 kfree(fcport);
3025 fcport = NULL;
3026 }
3027}
3028
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003029static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003031 int defer)
3032{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003033 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003034 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003035 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003036
3037 if (!fcport->rport)
3038 return;
3039
3040 rport = fcport->rport;
3041 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003042 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003043 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003044 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003045 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003046 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3047 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003048 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003049 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003050 qlt_fc_port_deleted(vha, fcport);
3051 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003052}
3053
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3056 *
3057 * Input: ha = adapter block pointer. fcport = port structure pointer.
3058 *
3059 * Return: None.
3060 *
3061 * Context:
3062 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003064 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003066 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003067 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003068 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003069 qla2x00_schedule_rport_del(vha, fcport, defer);
3070 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003071 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 * We may need to retry the login, so don't change the state of the
3073 * port but do the retries.
3074 */
3075 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003076 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
3078 if (!do_login)
3079 return;
3080
3081 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 fcport->login_retry = vha->hw->login_retry_count;
3083 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003085 ql_dbg(ql_dbg_disc, vha, 0x2067,
3086 "Port login retry "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 "%02x%02x%02x%02x%02x%02x%02x%02x, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003088 "id = 0x%04x retry cnt=%d.\n",
3089 fcport->port_name[0], fcport->port_name[1],
3090 fcport->port_name[2], fcport->port_name[3],
3091 fcport->port_name[4], fcport->port_name[5],
3092 fcport->port_name[6], fcport->port_name[7],
3093 fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 }
3095}
3096
3097/*
3098 * qla2x00_mark_all_devices_lost
3099 * Updates fcport state when device goes offline.
3100 *
3101 * Input:
3102 * ha = adapter block pointer.
3103 * fcport = port structure pointer.
3104 *
3105 * Return:
3106 * None.
3107 *
3108 * Context:
3109 */
3110void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112{
3113 fc_port_t *fcport;
3114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003115 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003116 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003118
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 /*
3120 * No point in marking the device as lost, if the device is
3121 * already DEAD.
3122 */
3123 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3124 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003126 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003127 if (defer)
3128 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003129 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003130 qla2x00_schedule_rport_del(vha, fcport, defer);
3131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 }
3133}
3134
3135/*
3136* qla2x00_mem_alloc
3137* Allocates adapter memory.
3138*
3139* Returns:
3140* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003141* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003143static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003144qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3145 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146{
3147 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Andrew Vasqueze8711082008-01-31 12:33:48 -08003149 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003151 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003154 if (qlt_mem_alloc(ha) < 0)
3155 goto fail_free_init_cb;
3156
Chad Dupuis642ef982012-02-09 11:15:57 -08003157 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3158 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003160 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
Andrew Vasqueze8711082008-01-31 12:33:48 -08003162 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3163 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
Giridhar Malavalia9083012010-04-12 17:59:55 -07003166 if (IS_QLA82XX(ha)) {
3167 /* Allocate cache for CT6 Ctx. */
3168 if (!ctx_cachep) {
3169 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3170 sizeof(struct ct6_dsd), 0,
3171 SLAB_HWCACHE_ALIGN, NULL);
3172 if (!ctx_cachep)
3173 goto fail_free_gid_list;
3174 }
3175 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3176 ctx_cachep);
3177 if (!ha->ctx_mempool)
3178 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003179 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3180 "ctx_cachep=%p ctx_mempool=%p.\n",
3181 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003182 }
3183
Andrew Vasqueze8711082008-01-31 12:33:48 -08003184 /* Get memory for cached NVRAM */
3185 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3186 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003187 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3190 ha->pdev->device);
3191 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3192 DMA_POOL_SIZE, 8, 0);
3193 if (!ha->s_dma_pool)
3194 goto fail_free_nvram;
3195
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003196 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3197 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3198 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3199
Arun Easibad75002010-05-04 15:01:30 -07003200 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003201 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3202 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3203 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003204 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3205 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003206 goto fail_s_dma_pool;
3207 }
3208
3209 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3210 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3211 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003212 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3213 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003214 goto fail_dl_dma_pool;
3215 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003216 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3217 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3218 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003219 }
3220
Andrew Vasqueze8711082008-01-31 12:33:48 -08003221 /* Allocate memory for SNS commands */
3222 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003224 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003225 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003226 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003227 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003229 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003230 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003232 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003234 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235 goto fail_dma_pool;
3236 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003237 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003239 if (!ha->ct_sns)
3240 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003241 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3242 "ms_iocb=%p ct_sns=%p.\n",
3243 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 }
3245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003247 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3248 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003249 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3250 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 goto fail_req;
3252 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003253 (*req)->length = req_len;
3254 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3255 ((*req)->length + 1) * sizeof(request_t),
3256 &(*req)->dma, GFP_KERNEL);
3257 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003258 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3259 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 goto fail_req_ring;
3261 }
3262 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003263 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3264 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003265 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3266 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 goto fail_rsp;
3268 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003269 (*rsp)->hw = ha;
3270 (*rsp)->length = rsp_len;
3271 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3272 ((*rsp)->length + 1) * sizeof(response_t),
3273 &(*rsp)->dma, GFP_KERNEL);
3274 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003275 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3276 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 goto fail_rsp_ring;
3278 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003279 (*req)->rsp = *rsp;
3280 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003281 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3282 "req=%p req->length=%d req->ring=%p rsp=%p "
3283 "rsp->length=%d rsp->ring=%p.\n",
3284 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3285 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003286 /* Allocate memory for NVRAM data for vports */
3287 if (ha->nvram_npiv_size) {
3288 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003289 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003290 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003291 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3292 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003293 goto fail_npiv_info;
3294 }
3295 } else
3296 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003298 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003299 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003300 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3301 &ha->ex_init_cb_dma);
3302 if (!ha->ex_init_cb)
3303 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003304 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3305 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003306 }
3307
Giridhar Malavalia9083012010-04-12 17:59:55 -07003308 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3309
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003310 /* Get consistent memory allocated for Async Port-Database. */
3311 if (!IS_FWI2_CAPABLE(ha)) {
3312 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3313 &ha->async_pd_dma);
3314 if (!ha->async_pd)
3315 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003316 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3317 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003318 }
3319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003320 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003321
3322 /* Allocate memory for our loop_id bitmap */
3323 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3324 GFP_KERNEL);
3325 if (!ha->loop_id_map)
3326 goto fail_async_pd;
3327 else {
3328 qla2x00_set_reserved_loop_ids(ha);
3329 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
3330 "loop_id_map=%p. \n", ha->loop_id_map);
3331 }
3332
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333 return 1;
3334
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003335fail_async_pd:
3336 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003337fail_ex_init_cb:
3338 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003339fail_npiv_info:
3340 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3341 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3342 (*rsp)->ring = NULL;
3343 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003345 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003347 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3348 sizeof(request_t), (*req)->ring, (*req)->dma);
3349 (*req)->ring = NULL;
3350 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003352 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353fail_req:
3354 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3355 ha->ct_sns, ha->ct_sns_dma);
3356 ha->ct_sns = NULL;
3357 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003358fail_free_ms_iocb:
3359 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3360 ha->ms_iocb = NULL;
3361 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003362fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003363 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003364 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3365 ha->fcp_cmnd_dma_pool = NULL;
3366 }
3367fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003368 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003369 dma_pool_destroy(ha->dl_dma_pool);
3370 ha->dl_dma_pool = NULL;
3371 }
3372fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003373 dma_pool_destroy(ha->s_dma_pool);
3374 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003375fail_free_nvram:
3376 kfree(ha->nvram);
3377 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003378fail_free_ctx_mempool:
3379 mempool_destroy(ha->ctx_mempool);
3380 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003381fail_free_srb_mempool:
3382 mempool_destroy(ha->srb_mempool);
3383 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003384fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003385 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3386 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003388 ha->gid_list = NULL;
3389 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003390fail_free_tgt_mem:
3391 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392fail_free_init_cb:
3393 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3394 ha->init_cb_dma);
3395 ha->init_cb = NULL;
3396 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003397fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003398 ql_log(ql_log_fatal, NULL, 0x0030,
3399 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003400 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401}
3402
3403/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003404* qla2x00_free_fw_dump
3405* Frees fw dump stuff.
3406*
3407* Input:
3408* ha = adapter block pointer.
3409*/
3410static void
3411qla2x00_free_fw_dump(struct qla_hw_data *ha)
3412{
3413 if (ha->fce)
3414 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3415 ha->fce_dma);
3416
3417 if (ha->fw_dump) {
3418 if (ha->eft)
3419 dma_free_coherent(&ha->pdev->dev,
3420 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3421 vfree(ha->fw_dump);
3422 }
3423 ha->fce = NULL;
3424 ha->fce_dma = 0;
3425 ha->eft = NULL;
3426 ha->eft_dma = 0;
3427 ha->fw_dump = NULL;
3428 ha->fw_dumped = 0;
3429 ha->fw_dump_reading = 0;
3430}
3431
3432/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433* qla2x00_mem_free
3434* Frees all adapter allocated memory.
3435*
3436* Input:
3437* ha = adapter block pointer.
3438*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003439static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003442 qla2x00_free_fw_dump(ha);
3443
Saurav Kashyap81178772012-08-22 14:21:04 -04003444 if (ha->mctp_dump)
3445 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3446 ha->mctp_dump_dma);
3447
Andrew Vasqueze8711082008-01-31 12:33:48 -08003448 if (ha->srb_mempool)
3449 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003451 if (ha->dcbx_tlv)
3452 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3453 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3454
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003455 if (ha->xgmac_data)
3456 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3457 ha->xgmac_data, ha->xgmac_data_dma);
3458
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 if (ha->sns_cmd)
3460 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003461 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
3463 if (ha->ct_sns)
3464 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003465 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466
Andrew Vasquez88729e52006-06-23 16:10:50 -07003467 if (ha->sfp_data)
3468 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3469
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 if (ha->ms_iocb)
3471 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3472
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003473 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003474 dma_pool_free(ha->s_dma_pool,
3475 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003476
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003477 if (ha->async_pd)
3478 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3479
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 if (ha->s_dma_pool)
3481 dma_pool_destroy(ha->s_dma_pool);
3482
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003484 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3485 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
Giridhar Malavalia9083012010-04-12 17:59:55 -07003487 if (IS_QLA82XX(ha)) {
3488 if (!list_empty(&ha->gbl_dsd_list)) {
3489 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3490
3491 /* clean up allocated prev pool */
3492 list_for_each_entry_safe(dsd_ptr,
3493 tdsd_ptr, &ha->gbl_dsd_list, list) {
3494 dma_pool_free(ha->dl_dma_pool,
3495 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3496 list_del(&dsd_ptr->list);
3497 kfree(dsd_ptr);
3498 }
3499 }
3500 }
3501
3502 if (ha->dl_dma_pool)
3503 dma_pool_destroy(ha->dl_dma_pool);
3504
3505 if (ha->fcp_cmnd_dma_pool)
3506 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3507
3508 if (ha->ctx_mempool)
3509 mempool_destroy(ha->ctx_mempool);
3510
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003511 qlt_mem_free(ha);
3512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 if (ha->init_cb)
3514 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003515 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516 vfree(ha->optrom_buffer);
3517 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003518 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003519 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003520 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Andrew Vasqueze8711082008-01-31 12:33:48 -08003522 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003523 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 ha->sns_cmd = NULL;
3525 ha->sns_cmd_dma = 0;
3526 ha->ct_sns = NULL;
3527 ha->ct_sns_dma = 0;
3528 ha->ms_iocb = NULL;
3529 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 ha->init_cb = NULL;
3531 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003532 ha->ex_init_cb = NULL;
3533 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003534 ha->async_pd = NULL;
3535 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536
3537 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003538 ha->dl_dma_pool = NULL;
3539 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 ha->gid_list = NULL;
3542 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003543
3544 ha->tgt.atio_ring = NULL;
3545 ha->tgt.atio_dma = 0;
3546 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547}
3548
3549struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3550 struct qla_hw_data *ha)
3551{
3552 struct Scsi_Host *host;
3553 struct scsi_qla_host *vha = NULL;
3554
3555 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3556 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003557 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3558 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559 goto fail;
3560 }
3561
3562 /* Clear our data area */
3563 vha = shost_priv(host);
3564 memset(vha, 0, sizeof(scsi_qla_host_t));
3565
3566 vha->host = host;
3567 vha->host_no = host->host_no;
3568 vha->hw = ha;
3569
3570 INIT_LIST_HEAD(&vha->vp_fcports);
3571 INIT_LIST_HEAD(&vha->work_list);
3572 INIT_LIST_HEAD(&vha->list);
3573
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003574 spin_lock_init(&vha->work_lock);
3575
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003577 ql_dbg(ql_dbg_init, vha, 0x0041,
3578 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3579 vha->host, vha->hw, vha,
3580 dev_name(&(ha->pdev->dev)));
3581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582 return vha;
3583
3584fail:
3585 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586}
3587
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003588static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003589qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003590{
3591 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003592 uint8_t bail;
3593
3594 QLA_VHA_MARK_BUSY(vha, bail);
3595 if (bail)
3596 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003597
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003598 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003599 if (!e) {
3600 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003601 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003602 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003603
3604 INIT_LIST_HEAD(&e->list);
3605 e->type = type;
3606 e->flags = QLA_EVT_FLAG_FREE;
3607 return e;
3608}
3609
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003610static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003611qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003612{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003613 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003614
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003615 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003617 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003619
Andrew Vasquez0971de72008-04-03 13:13:18 -07003620 return QLA_SUCCESS;
3621}
3622
3623int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003624qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003625 u32 data)
3626{
3627 struct qla_work_evt *e;
3628
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003629 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003630 if (!e)
3631 return QLA_FUNCTION_FAILED;
3632
3633 e->u.aen.code = code;
3634 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003635 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003636}
3637
Andrew Vasquez8a659572009-02-08 20:50:12 -08003638int
3639qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3640{
3641 struct qla_work_evt *e;
3642
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003643 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003644 if (!e)
3645 return QLA_FUNCTION_FAILED;
3646
3647 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003648 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003649}
3650
Andrew Vasquezac280b62009-08-20 11:06:05 -07003651#define qla2x00_post_async_work(name, type) \
3652int qla2x00_post_async_##name##_work( \
3653 struct scsi_qla_host *vha, \
3654 fc_port_t *fcport, uint16_t *data) \
3655{ \
3656 struct qla_work_evt *e; \
3657 \
3658 e = qla2x00_alloc_work(vha, type); \
3659 if (!e) \
3660 return QLA_FUNCTION_FAILED; \
3661 \
3662 e->u.logio.fcport = fcport; \
3663 if (data) { \
3664 e->u.logio.data[0] = data[0]; \
3665 e->u.logio.data[1] = data[1]; \
3666 } \
3667 return qla2x00_post_work(vha, e); \
3668}
3669
3670qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3671qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3672qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3673qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003674qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3675qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003676
Andrew Vasquez3420d362009-10-13 15:16:45 -07003677int
3678qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3679{
3680 struct qla_work_evt *e;
3681
3682 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3683 if (!e)
3684 return QLA_FUNCTION_FAILED;
3685
3686 e->u.uevent.code = code;
3687 return qla2x00_post_work(vha, e);
3688}
3689
3690static void
3691qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3692{
3693 char event_string[40];
3694 char *envp[] = { event_string, NULL };
3695
3696 switch (code) {
3697 case QLA_UEVENT_CODE_FW_DUMP:
3698 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3699 vha->host_no);
3700 break;
3701 default:
3702 /* do nothing */
3703 break;
3704 }
3705 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3706}
3707
Andrew Vasquezac280b62009-08-20 11:06:05 -07003708void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003709qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003710{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003711 struct qla_work_evt *e, *tmp;
3712 unsigned long flags;
3713 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003714
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003715 spin_lock_irqsave(&vha->work_lock, flags);
3716 list_splice_init(&vha->work_list, &work);
3717 spin_unlock_irqrestore(&vha->work_lock, flags);
3718
3719 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003720 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003721
3722 switch (e->type) {
3723 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003724 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003725 e->u.aen.code, e->u.aen.data);
3726 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003727 case QLA_EVT_IDC_ACK:
3728 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3729 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003730 case QLA_EVT_ASYNC_LOGIN:
3731 qla2x00_async_login(vha, e->u.logio.fcport,
3732 e->u.logio.data);
3733 break;
3734 case QLA_EVT_ASYNC_LOGIN_DONE:
3735 qla2x00_async_login_done(vha, e->u.logio.fcport,
3736 e->u.logio.data);
3737 break;
3738 case QLA_EVT_ASYNC_LOGOUT:
3739 qla2x00_async_logout(vha, e->u.logio.fcport);
3740 break;
3741 case QLA_EVT_ASYNC_LOGOUT_DONE:
3742 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3743 e->u.logio.data);
3744 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003745 case QLA_EVT_ASYNC_ADISC:
3746 qla2x00_async_adisc(vha, e->u.logio.fcport,
3747 e->u.logio.data);
3748 break;
3749 case QLA_EVT_ASYNC_ADISC_DONE:
3750 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3751 e->u.logio.data);
3752 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003753 case QLA_EVT_UEVENT:
3754 qla2x00_uevent_emit(vha, e->u.uevent.code);
3755 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003756 }
3757 if (e->flags & QLA_EVT_FLAG_FREE)
3758 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003759
3760 /* For each work completed decrement vha ref count */
3761 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003762 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003764
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003765/* Relogins all the fcports of a vport
3766 * Context: dpc thread
3767 */
3768void qla2x00_relogin(struct scsi_qla_host *vha)
3769{
3770 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003771 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003772 uint16_t next_loopid = 0;
3773 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003774 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003775
3776 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3777 /*
3778 * If the port is not ONLINE then try to login
3779 * to it if we haven't run out of retries.
3780 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003781 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3782 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003783 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003784 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003785 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003786 ha->isp_ops->fabric_logout(vha,
3787 fcport->loop_id,
3788 fcport->d_id.b.domain,
3789 fcport->d_id.b.area,
3790 fcport->d_id.b.al_pa);
3791
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003792 if (fcport->loop_id == FC_NO_LOOP_ID) {
3793 fcport->loop_id = next_loopid =
3794 ha->min_external_loopid;
3795 status = qla2x00_find_new_loop_id(
3796 vha, fcport);
3797 if (status != QLA_SUCCESS) {
3798 /* Ran out of IDs to use */
3799 break;
3800 }
3801 }
3802
Andrew Vasquezac280b62009-08-20 11:06:05 -07003803 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003804 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003805 data[0] = 0;
3806 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3807 status = qla2x00_post_async_login_work(
3808 vha, fcport, data);
3809 if (status == QLA_SUCCESS)
3810 continue;
3811 /* Attempt a retry. */
3812 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003813 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003814 status = qla2x00_fabric_login(vha,
3815 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003816 if (status == QLA_SUCCESS) {
3817 int status2;
3818 uint8_t opts;
3819
3820 opts = 0;
3821 if (fcport->flags &
3822 FCF_FCP2_DEVICE)
3823 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05003824 status2 =
3825 qla2x00_get_port_database(
3826 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003827 if (status2 != QLA_SUCCESS)
3828 status = 1;
3829 }
3830 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 } else
3832 status = qla2x00_local_device_login(vha,
3833 fcport);
3834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 if (status == QLA_SUCCESS) {
3836 fcport->old_loop_id = fcport->loop_id;
3837
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003838 ql_dbg(ql_dbg_disc, vha, 0x2003,
3839 "Port login OK: logged in ID 0x%x.\n",
3840 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841
3842 qla2x00_update_fcport(vha, fcport);
3843
3844 } else if (status == 1) {
3845 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3846 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003847 ql_dbg(ql_dbg_disc, vha, 0x2007,
3848 "Retrying %d login again loop_id 0x%x.\n",
3849 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003850 } else {
3851 fcport->login_retry = 0;
3852 }
3853
3854 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04003855 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 }
3857 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3858 break;
3859 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003860}
3861
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003862/* Schedule work on any of the dpc-workqueues */
3863void
3864qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
3865{
3866 struct qla_hw_data *ha = base_vha->hw;
3867
3868 switch (work_code) {
3869 case MBA_IDC_AEN: /* 0x8200 */
3870 if (ha->dpc_lp_wq)
3871 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
3872 break;
3873
3874 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
3875 if (!ha->flags.nic_core_reset_hdlr_active) {
3876 if (ha->dpc_hp_wq)
3877 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
3878 } else
3879 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
3880 "NIC Core reset is already active. Skip "
3881 "scheduling it again.\n");
3882 break;
3883 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
3884 if (ha->dpc_hp_wq)
3885 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
3886 break;
3887 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
3888 if (ha->dpc_hp_wq)
3889 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
3890 break;
3891 default:
3892 ql_log(ql_log_warn, base_vha, 0xb05f,
3893 "Unknow work-code=0x%x.\n", work_code);
3894 }
3895
3896 return;
3897}
3898
3899/* Work: Perform NIC Core Unrecoverable state handling */
3900void
3901qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
3902{
3903 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04003904 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003905 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3906 uint32_t dev_state = 0;
3907
3908 qla83xx_idc_lock(base_vha, 0);
3909 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3910 qla83xx_reset_ownership(base_vha);
3911 if (ha->flags.nic_core_reset_owner) {
3912 ha->flags.nic_core_reset_owner = 0;
3913 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
3914 QLA8XXX_DEV_FAILED);
3915 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
3916 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
3917 }
3918 qla83xx_idc_unlock(base_vha, 0);
3919}
3920
3921/* Work: Execute IDC state handler */
3922void
3923qla83xx_idc_state_handler_work(struct work_struct *work)
3924{
3925 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04003926 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003927 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3928 uint32_t dev_state = 0;
3929
3930 qla83xx_idc_lock(base_vha, 0);
3931 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3932 if (dev_state == QLA8XXX_DEV_FAILED ||
3933 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
3934 qla83xx_idc_state_handler(base_vha);
3935 qla83xx_idc_unlock(base_vha, 0);
3936}
3937
Saurav Kashyapfa492632012-11-21 02:40:29 -05003938static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003939qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
3940{
3941 int rval = QLA_SUCCESS;
3942 unsigned long heart_beat_wait = jiffies + (1 * HZ);
3943 uint32_t heart_beat_counter1, heart_beat_counter2;
3944
3945 do {
3946 if (time_after(jiffies, heart_beat_wait)) {
3947 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
3948 "Nic Core f/w is not alive.\n");
3949 rval = QLA_FUNCTION_FAILED;
3950 break;
3951 }
3952
3953 qla83xx_idc_lock(base_vha, 0);
3954 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
3955 &heart_beat_counter1);
3956 qla83xx_idc_unlock(base_vha, 0);
3957 msleep(100);
3958 qla83xx_idc_lock(base_vha, 0);
3959 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
3960 &heart_beat_counter2);
3961 qla83xx_idc_unlock(base_vha, 0);
3962 } while (heart_beat_counter1 == heart_beat_counter2);
3963
3964 return rval;
3965}
3966
3967/* Work: Perform NIC Core Reset handling */
3968void
3969qla83xx_nic_core_reset_work(struct work_struct *work)
3970{
3971 struct qla_hw_data *ha =
3972 container_of(work, struct qla_hw_data, nic_core_reset);
3973 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3974 uint32_t dev_state = 0;
3975
Saurav Kashyap81178772012-08-22 14:21:04 -04003976 if (IS_QLA2031(ha)) {
3977 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
3978 ql_log(ql_log_warn, base_vha, 0xb081,
3979 "Failed to dump mctp\n");
3980 return;
3981 }
3982
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003983 if (!ha->flags.nic_core_reset_hdlr_active) {
3984 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
3985 qla83xx_idc_lock(base_vha, 0);
3986 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
3987 &dev_state);
3988 qla83xx_idc_unlock(base_vha, 0);
3989 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
3990 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
3991 "Nic Core f/w is alive.\n");
3992 return;
3993 }
3994 }
3995
3996 ha->flags.nic_core_reset_hdlr_active = 1;
3997 if (qla83xx_nic_core_reset(base_vha)) {
3998 /* NIC Core reset failed. */
3999 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4000 "NIC Core reset failed.\n");
4001 }
4002 ha->flags.nic_core_reset_hdlr_active = 0;
4003 }
4004}
4005
4006/* Work: Handle 8200 IDC aens */
4007void
4008qla83xx_service_idc_aen(struct work_struct *work)
4009{
4010 struct qla_hw_data *ha =
4011 container_of(work, struct qla_hw_data, idc_aen);
4012 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4013 uint32_t dev_state, idc_control;
4014
4015 qla83xx_idc_lock(base_vha, 0);
4016 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4017 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4018 qla83xx_idc_unlock(base_vha, 0);
4019 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4020 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4021 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4022 "Application requested NIC Core Reset.\n");
4023 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4024 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4025 QLA_SUCCESS) {
4026 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4027 "Other protocol driver requested NIC Core Reset.\n");
4028 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4029 }
4030 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4031 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4032 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4033 }
4034}
4035
4036static void
4037qla83xx_wait_logic(void)
4038{
4039 int i;
4040
4041 /* Yield CPU */
4042 if (!in_interrupt()) {
4043 /*
4044 * Wait about 200ms before retrying again.
4045 * This controls the number of retries for single
4046 * lock operation.
4047 */
4048 msleep(100);
4049 schedule();
4050 } else {
4051 for (i = 0; i < 20; i++)
4052 cpu_relax(); /* This a nop instr on i386 */
4053 }
4054}
4055
Saurav Kashyapfa492632012-11-21 02:40:29 -05004056static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004057qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4058{
4059 int rval;
4060 uint32_t data;
4061 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4062 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4063 struct qla_hw_data *ha = base_vha->hw;
4064
4065 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4066 if (rval)
4067 return rval;
4068
4069 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4070 return QLA_SUCCESS;
4071 } else {
4072 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4073 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4074 data);
4075 if (rval)
4076 return rval;
4077
4078 msleep(200);
4079
4080 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4081 &data);
4082 if (rval)
4083 return rval;
4084
4085 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4086 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4087 ~(idc_lck_rcvry_stage_mask));
4088 rval = qla83xx_wr_reg(base_vha,
4089 QLA83XX_IDC_LOCK_RECOVERY, data);
4090 if (rval)
4091 return rval;
4092
4093 /* Forcefully perform IDC UnLock */
4094 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4095 &data);
4096 if (rval)
4097 return rval;
4098 /* Clear lock-id by setting 0xff */
4099 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4100 0xff);
4101 if (rval)
4102 return rval;
4103 /* Clear lock-recovery by setting 0x0 */
4104 rval = qla83xx_wr_reg(base_vha,
4105 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4106 if (rval)
4107 return rval;
4108 } else
4109 return QLA_SUCCESS;
4110 }
4111
4112 return rval;
4113}
4114
Saurav Kashyapfa492632012-11-21 02:40:29 -05004115static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004116qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4117{
4118 int rval = QLA_SUCCESS;
4119 uint32_t o_drv_lockid, n_drv_lockid;
4120 unsigned long lock_recovery_timeout;
4121
4122 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4123retry_lockid:
4124 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4125 if (rval)
4126 goto exit;
4127
4128 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4129 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4130 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4131 return QLA_SUCCESS;
4132 else
4133 return QLA_FUNCTION_FAILED;
4134 }
4135
4136 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4137 if (rval)
4138 goto exit;
4139
4140 if (o_drv_lockid == n_drv_lockid) {
4141 qla83xx_wait_logic();
4142 goto retry_lockid;
4143 } else
4144 return QLA_SUCCESS;
4145
4146exit:
4147 return rval;
4148}
4149
4150void
4151qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4152{
4153 uint16_t options = (requester_id << 15) | BIT_6;
4154 uint32_t data;
4155 struct qla_hw_data *ha = base_vha->hw;
4156
4157 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4158retry_lock:
4159 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4160 == QLA_SUCCESS) {
4161 if (data) {
4162 /* Setting lock-id to our function-number */
4163 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4164 ha->portnum);
4165 } else {
4166 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
4167 "Failed to acquire IDC lock. retrying...\n");
4168
4169 /* Retry/Perform IDC-Lock recovery */
4170 if (qla83xx_idc_lock_recovery(base_vha)
4171 == QLA_SUCCESS) {
4172 qla83xx_wait_logic();
4173 goto retry_lock;
4174 } else
4175 ql_log(ql_log_warn, base_vha, 0xb075,
4176 "IDC Lock recovery FAILED.\n");
4177 }
4178
4179 }
4180
4181 return;
4182
4183 /* XXX: IDC-lock implementation using access-control mbx */
4184retry_lock2:
4185 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4186 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4187 "Failed to acquire IDC lock. retrying...\n");
4188 /* Retry/Perform IDC-Lock recovery */
4189 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4190 qla83xx_wait_logic();
4191 goto retry_lock2;
4192 } else
4193 ql_log(ql_log_warn, base_vha, 0xb076,
4194 "IDC Lock recovery FAILED.\n");
4195 }
4196
4197 return;
4198}
4199
4200void
4201qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4202{
4203 uint16_t options = (requester_id << 15) | BIT_7, retry;
4204 uint32_t data;
4205 struct qla_hw_data *ha = base_vha->hw;
4206
4207 /* IDC-unlock implementation using driver-unlock/lock-id
4208 * remote registers
4209 */
4210 retry = 0;
4211retry_unlock:
4212 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4213 == QLA_SUCCESS) {
4214 if (data == ha->portnum) {
4215 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4216 /* Clearing lock-id by setting 0xff */
4217 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4218 } else if (retry < 10) {
4219 /* SV: XXX: IDC unlock retrying needed here? */
4220
4221 /* Retry for IDC-unlock */
4222 qla83xx_wait_logic();
4223 retry++;
4224 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4225 "Failed to release IDC lock, retyring=%d\n", retry);
4226 goto retry_unlock;
4227 }
4228 } else if (retry < 10) {
4229 /* Retry for IDC-unlock */
4230 qla83xx_wait_logic();
4231 retry++;
4232 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4233 "Failed to read drv-lockid, retyring=%d\n", retry);
4234 goto retry_unlock;
4235 }
4236
4237 return;
4238
4239 /* XXX: IDC-unlock implementation using access-control mbx */
4240 retry = 0;
4241retry_unlock2:
4242 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4243 if (retry < 10) {
4244 /* Retry for IDC-unlock */
4245 qla83xx_wait_logic();
4246 retry++;
4247 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4248 "Failed to release IDC lock, retyring=%d\n", retry);
4249 goto retry_unlock2;
4250 }
4251 }
4252
4253 return;
4254}
4255
4256int
4257__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4258{
4259 int rval = QLA_SUCCESS;
4260 struct qla_hw_data *ha = vha->hw;
4261 uint32_t drv_presence;
4262
4263 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4264 if (rval == QLA_SUCCESS) {
4265 drv_presence |= (1 << ha->portnum);
4266 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4267 drv_presence);
4268 }
4269
4270 return rval;
4271}
4272
4273int
4274qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4275{
4276 int rval = QLA_SUCCESS;
4277
4278 qla83xx_idc_lock(vha, 0);
4279 rval = __qla83xx_set_drv_presence(vha);
4280 qla83xx_idc_unlock(vha, 0);
4281
4282 return rval;
4283}
4284
4285int
4286__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4287{
4288 int rval = QLA_SUCCESS;
4289 struct qla_hw_data *ha = vha->hw;
4290 uint32_t drv_presence;
4291
4292 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4293 if (rval == QLA_SUCCESS) {
4294 drv_presence &= ~(1 << ha->portnum);
4295 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4296 drv_presence);
4297 }
4298
4299 return rval;
4300}
4301
4302int
4303qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4304{
4305 int rval = QLA_SUCCESS;
4306
4307 qla83xx_idc_lock(vha, 0);
4308 rval = __qla83xx_clear_drv_presence(vha);
4309 qla83xx_idc_unlock(vha, 0);
4310
4311 return rval;
4312}
4313
Saurav Kashyapfa492632012-11-21 02:40:29 -05004314static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004315qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4316{
4317 struct qla_hw_data *ha = vha->hw;
4318 uint32_t drv_ack, drv_presence;
4319 unsigned long ack_timeout;
4320
4321 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4322 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4323 while (1) {
4324 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4325 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004326 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004327 break;
4328
4329 if (time_after_eq(jiffies, ack_timeout)) {
4330 ql_log(ql_log_warn, vha, 0xb067,
4331 "RESET ACK TIMEOUT! drv_presence=0x%x "
4332 "drv_ack=0x%x\n", drv_presence, drv_ack);
4333 /*
4334 * The function(s) which did not ack in time are forced
4335 * to withdraw any further participation in the IDC
4336 * reset.
4337 */
4338 if (drv_ack != drv_presence)
4339 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4340 drv_ack);
4341 break;
4342 }
4343
4344 qla83xx_idc_unlock(vha, 0);
4345 msleep(1000);
4346 qla83xx_idc_lock(vha, 0);
4347 }
4348
4349 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4350 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4351}
4352
Saurav Kashyapfa492632012-11-21 02:40:29 -05004353static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004354qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4355{
4356 int rval = QLA_SUCCESS;
4357 uint32_t idc_control;
4358
4359 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4360 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4361
4362 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4363 __qla83xx_get_idc_control(vha, &idc_control);
4364 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4365 __qla83xx_set_idc_control(vha, 0);
4366
4367 qla83xx_idc_unlock(vha, 0);
4368 rval = qla83xx_restart_nic_firmware(vha);
4369 qla83xx_idc_lock(vha, 0);
4370
4371 if (rval != QLA_SUCCESS) {
4372 ql_log(ql_log_fatal, vha, 0xb06a,
4373 "Failed to restart NIC f/w.\n");
4374 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4375 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4376 } else {
4377 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4378 "Success in restarting nic f/w.\n");
4379 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4380 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4381 }
4382
4383 return rval;
4384}
4385
4386/* Assumes idc_lock always held on entry */
4387int
4388qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4389{
4390 struct qla_hw_data *ha = base_vha->hw;
4391 int rval = QLA_SUCCESS;
4392 unsigned long dev_init_timeout;
4393 uint32_t dev_state;
4394
4395 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4396 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4397
4398 while (1) {
4399
4400 if (time_after_eq(jiffies, dev_init_timeout)) {
4401 ql_log(ql_log_warn, base_vha, 0xb06e,
4402 "Initialization TIMEOUT!\n");
4403 /* Init timeout. Disable further NIC Core
4404 * communication.
4405 */
4406 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4407 QLA8XXX_DEV_FAILED);
4408 ql_log(ql_log_info, base_vha, 0xb06f,
4409 "HW State: FAILED.\n");
4410 }
4411
4412 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4413 switch (dev_state) {
4414 case QLA8XXX_DEV_READY:
4415 if (ha->flags.nic_core_reset_owner)
4416 qla83xx_idc_audit(base_vha,
4417 IDC_AUDIT_COMPLETION);
4418 ha->flags.nic_core_reset_owner = 0;
4419 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4420 "Reset_owner reset by 0x%x.\n",
4421 ha->portnum);
4422 goto exit;
4423 case QLA8XXX_DEV_COLD:
4424 if (ha->flags.nic_core_reset_owner)
4425 rval = qla83xx_device_bootstrap(base_vha);
4426 else {
4427 /* Wait for AEN to change device-state */
4428 qla83xx_idc_unlock(base_vha, 0);
4429 msleep(1000);
4430 qla83xx_idc_lock(base_vha, 0);
4431 }
4432 break;
4433 case QLA8XXX_DEV_INITIALIZING:
4434 /* Wait for AEN to change device-state */
4435 qla83xx_idc_unlock(base_vha, 0);
4436 msleep(1000);
4437 qla83xx_idc_lock(base_vha, 0);
4438 break;
4439 case QLA8XXX_DEV_NEED_RESET:
4440 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4441 qla83xx_need_reset_handler(base_vha);
4442 else {
4443 /* Wait for AEN to change device-state */
4444 qla83xx_idc_unlock(base_vha, 0);
4445 msleep(1000);
4446 qla83xx_idc_lock(base_vha, 0);
4447 }
4448 /* reset timeout value after need reset handler */
4449 dev_init_timeout = jiffies +
4450 (ha->fcoe_dev_init_timeout * HZ);
4451 break;
4452 case QLA8XXX_DEV_NEED_QUIESCENT:
4453 /* XXX: DEBUG for now */
4454 qla83xx_idc_unlock(base_vha, 0);
4455 msleep(1000);
4456 qla83xx_idc_lock(base_vha, 0);
4457 break;
4458 case QLA8XXX_DEV_QUIESCENT:
4459 /* XXX: DEBUG for now */
4460 if (ha->flags.quiesce_owner)
4461 goto exit;
4462
4463 qla83xx_idc_unlock(base_vha, 0);
4464 msleep(1000);
4465 qla83xx_idc_lock(base_vha, 0);
4466 dev_init_timeout = jiffies +
4467 (ha->fcoe_dev_init_timeout * HZ);
4468 break;
4469 case QLA8XXX_DEV_FAILED:
4470 if (ha->flags.nic_core_reset_owner)
4471 qla83xx_idc_audit(base_vha,
4472 IDC_AUDIT_COMPLETION);
4473 ha->flags.nic_core_reset_owner = 0;
4474 __qla83xx_clear_drv_presence(base_vha);
4475 qla83xx_idc_unlock(base_vha, 0);
4476 qla8xxx_dev_failed_handler(base_vha);
4477 rval = QLA_FUNCTION_FAILED;
4478 qla83xx_idc_lock(base_vha, 0);
4479 goto exit;
4480 case QLA8XXX_BAD_VALUE:
4481 qla83xx_idc_unlock(base_vha, 0);
4482 msleep(1000);
4483 qla83xx_idc_lock(base_vha, 0);
4484 break;
4485 default:
4486 ql_log(ql_log_warn, base_vha, 0xb071,
4487 "Unknow Device State: %x.\n", dev_state);
4488 qla83xx_idc_unlock(base_vha, 0);
4489 qla8xxx_dev_failed_handler(base_vha);
4490 rval = QLA_FUNCTION_FAILED;
4491 qla83xx_idc_lock(base_vha, 0);
4492 goto exit;
4493 }
4494 }
4495
4496exit:
4497 return rval;
4498}
4499
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500/**************************************************************************
4501* qla2x00_do_dpc
4502* This kernel thread is a task that is schedule by the interrupt handler
4503* to perform the background processing for interrupts.
4504*
4505* Notes:
4506* This task always run in the context of a kernel thread. It
4507* is kick-off by the driver's detect code and starts up
4508* up one per adapter. It immediately goes to sleep and waits for
4509* some fibre event. When either the interrupt handler or
4510* the timer routine detects a event it will one of the task
4511* bits then wake us up.
4512**************************************************************************/
4513static int
4514qla2x00_do_dpc(void *data)
4515{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004516 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004517 scsi_qla_host_t *base_vha;
4518 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004520 ha = (struct qla_hw_data *)data;
4521 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 set_user_nice(current, -20);
4524
James Bottomley563585e2011-01-27 16:12:37 -05004525 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004526 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004527 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4528 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529
Christoph Hellwig39a11242006-02-14 18:46:22 +01004530 schedule();
4531 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004533 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4534 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535
Andrew Vasquez85880802009-12-15 21:29:46 -08004536 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004537 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4538 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004539 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004540 }
4541
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 ha->dpc_active = 1;
4543
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004544 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4545 "DPC handler waking up, dpc_flags=0x%lx.\n",
4546 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004548 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004549
Giridhar Malavalia9083012010-04-12 17:59:55 -07004550 if (IS_QLA82XX(ha)) {
4551 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4552 &base_vha->dpc_flags)) {
4553 qla82xx_idc_lock(ha);
4554 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004555 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004556 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004557 ql_log(ql_log_info, base_vha, 0x4004,
4558 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004559 qla82xx_device_state_handler(base_vha);
4560 continue;
4561 }
4562
4563 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4564 &base_vha->dpc_flags)) {
4565
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004566 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4567 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004568 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4569 &base_vha->dpc_flags))) {
4570 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4571 /* FCoE-ctx reset failed.
4572 * Escalate to chip-reset
4573 */
4574 set_bit(ISP_ABORT_NEEDED,
4575 &base_vha->dpc_flags);
4576 }
4577 clear_bit(ABORT_ISP_ACTIVE,
4578 &base_vha->dpc_flags);
4579 }
4580
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004581 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4582 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004583 }
4584 }
4585
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004586 if (test_and_clear_bit(ISP_ABORT_NEEDED,
4587 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004589 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
4590 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004592 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593
Giridhar Malavalia9083012010-04-12 17:59:55 -07004594 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 /* failed. retry later */
4596 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004597 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004599 clear_bit(ABORT_ISP_ACTIVE,
4600 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08004601 }
4602
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004603 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
4604 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 }
4606
David Jefferya394aac2012-11-21 02:39:54 -05004607 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
4608 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004609 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07004610 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004611
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004612 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
4613 int ret;
4614 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
4615 if (ret != QLA_SUCCESS)
4616 ql_log(ql_log_warn, base_vha, 0x121,
4617 "Failed to enable receiving of RSCN "
4618 "requests: 0x%x.\n", ret);
4619 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
4620 }
4621
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004622 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004623 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
4624 "Quiescence mode scheduled.\n");
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004625 if (IS_QLA82XX(ha)) {
4626 qla82xx_device_state_handler(base_vha);
4627 clear_bit(ISP_QUIESCE_NEEDED,
4628 &base_vha->dpc_flags);
4629 if (!ha->flags.quiesce_owner) {
4630 qla2x00_perform_loop_resync(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004631
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004632 qla82xx_idc_lock(ha);
4633 qla82xx_clear_qsnt_ready(base_vha);
4634 qla82xx_idc_unlock(ha);
4635 }
4636 } else {
4637 clear_bit(ISP_QUIESCE_NEEDED,
4638 &base_vha->dpc_flags);
4639 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004640 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004641 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
4642 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004643 }
4644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004645 if (test_and_clear_bit(RESET_MARKER_NEEDED,
4646 &base_vha->dpc_flags) &&
4647 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004649 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
4650 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004651 qla2x00_rst_aen(base_vha);
4652 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004653 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
4654 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 }
4656
4657 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004658 if ((test_and_clear_bit(RELOGIN_NEEDED,
4659 &base_vha->dpc_flags)) &&
4660 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
4661 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004663 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
4664 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004665 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004666 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
4667 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 }
4669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
4671 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004673 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
4674 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675
4676 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004677 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004679 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004681 clear_bit(LOOP_RESYNC_ACTIVE,
4682 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683 }
4684
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004685 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
4686 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 }
4688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004689 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
4690 atomic_read(&base_vha->loop_state) == LOOP_READY) {
4691 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
4692 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07004693 }
4694
Chad Dupuis3c290d02013-01-30 03:34:38 -05004695 if (test_and_clear_bit(HOST_RAMP_DOWN_QUEUE_DEPTH,
4696 &base_vha->dpc_flags)) {
4697 /* Prevents simultaneous ramp up and down */
4698 clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
4699 &base_vha->dpc_flags);
4700 qla2x00_host_ramp_down_queuedepth(base_vha);
4701 }
4702
4703 if (test_and_clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
4704 &base_vha->dpc_flags))
4705 qla2x00_host_ramp_up_queuedepth(base_vha);
4706
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004708 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004710 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
4711 &base_vha->dpc_flags))
4712 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08004713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004714 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004715
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004717end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05004718 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05004720 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004722 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
4723 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724
4725 /*
4726 * Make sure that nobody tries to wake us up again.
4727 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 ha->dpc_active = 0;
4729
Andrew Vasquezac280b62009-08-20 11:06:05 -07004730 /* Cleanup any residual CTX SRBs. */
4731 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4732
Christoph Hellwig39a11242006-02-14 18:46:22 +01004733 return 0;
4734}
4735
4736void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004737qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01004738{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004739 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07004740 struct task_struct *t = ha->dpc_thread;
4741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004742 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07004743 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744}
4745
4746/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747* qla2x00_rst_aen
4748* Processes asynchronous reset.
4749*
4750* Input:
4751* ha = adapter block pointer.
4752*/
4753static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004754qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004756 if (vha->flags.online && !vha->flags.reset_active &&
4757 !atomic_read(&vha->loop_down_timer) &&
4758 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004760 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761
4762 /*
4763 * Issue marker command only when we are going to start
4764 * the I/O.
4765 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004766 vha->marker_needed = 1;
4767 } while (!atomic_read(&vha->loop_down_timer) &&
4768 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 }
4770}
4771
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772/**************************************************************************
4773* qla2x00_timer
4774*
4775* Description:
4776* One second timer
4777*
4778* Context: Interrupt
4779***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004780void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004781qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 int start_dpc = 0;
4785 int index;
4786 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08004787 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004788 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004789 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08004790
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004791 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004792 ql_dbg(ql_dbg_timer, vha, 0x6000,
4793 "EEH = %d, restarting timer.\n",
4794 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004795 qla2x00_restart_timer(vha, WATCH_INTERVAL);
4796 return;
4797 }
4798
Andrew Vasquez85880802009-12-15 21:29:46 -08004799 /* Hardware read to raise pending EEH errors during mailbox waits. */
4800 if (!pci_channel_offline(ha->pdev))
4801 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07004803 /* Make sure qla82xx_watchdog is run only for physical port */
4804 if (!vha->vp_idx && IS_QLA82XX(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004805 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
4806 start_dpc++;
4807 qla82xx_watchdog(vha);
4808 }
4809
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004812 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
4813 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004814 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004816 if (atomic_read(&vha->loop_down_timer) ==
4817 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004819 ql_log(ql_log_info, vha, 0x6008,
4820 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004822 if (!IS_QLA2100(ha) && vha->link_down_timeout)
4823 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004825 /*
4826 * Schedule an ISP abort to return any FCP2-device
4827 * commands.
4828 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004829 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004830 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004831 spin_lock_irqsave(&ha->hardware_lock,
4832 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004833 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004834 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05004835 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004836 index++) {
4837 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05004838
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004840 if (!sp)
4841 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08004842 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07004843 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004844 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004845 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004846 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004848 if (IS_QLA82XX(ha))
4849 set_bit(FCOE_CTX_RESET_NEEDED,
4850 &vha->dpc_flags);
4851 else
4852 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004853 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004854 break;
4855 }
4856 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004857 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 start_dpc++;
4860 }
4861
4862 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004863 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004864 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004865 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 "Loop down - aborting ISP.\n");
4867
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004868 if (IS_QLA82XX(ha))
4869 set_bit(FCOE_CTX_RESET_NEEDED,
4870 &vha->dpc_flags);
4871 else
4872 set_bit(ISP_ABORT_NEEDED,
4873 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 }
4875 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004876 ql_dbg(ql_dbg_timer, vha, 0x600a,
4877 "Loop down - seconds remaining %d.\n",
4878 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 }
4880
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07004881 /* Check if beacon LED needs to be blinked for physical host only */
4882 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07004883 /* There is no beacon_blink function for ISP82xx */
4884 if (!IS_QLA82XX(ha)) {
4885 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
4886 start_dpc++;
4887 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08004888 }
4889
Andrew Vasquez550bf572008-04-24 15:21:23 -07004890 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004891 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07004892 start_dpc++;
4893
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004895 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
4896 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
4897 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004899 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
4900 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07004901 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
4902 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004903 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis3c290d02013-01-30 03:34:38 -05004904 test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
4905 test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags) ||
4906 test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004907 ql_dbg(ql_dbg_timer, vha, 0x600b,
4908 "isp_abort_needed=%d loop_resync_needed=%d "
4909 "fcport_update_needed=%d start_dpc=%d "
4910 "reset_marker_needed=%d",
4911 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
4912 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
4913 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
4914 start_dpc,
4915 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
4916 ql_dbg(ql_dbg_timer, vha, 0x600c,
4917 "beacon_blink_needed=%d isp_unrecoverable=%d "
4918 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis3c290d02013-01-30 03:34:38 -05004919 "relogin_needed=%d, host_ramp_down_needed=%d "
4920 "host_ramp_up_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004921 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
4922 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
4923 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
4924 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis3c290d02013-01-30 03:34:38 -05004925 test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
4926 test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags),
4927 test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004928 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004931 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932}
4933
Andrew Vasquez54333832005-11-09 15:49:04 -08004934/* Firmware interface routines. */
4935
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004936#define FW_BLOBS 10
Andrew Vasquez54333832005-11-09 15:49:04 -08004937#define FW_ISP21XX 0
4938#define FW_ISP22XX 1
4939#define FW_ISP2300 2
4940#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004941#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004942#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004943#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07004944#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004945#define FW_ISP2031 8
4946#define FW_ISP8031 9
Andrew Vasquez54333832005-11-09 15:49:04 -08004947
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004948#define FW_FILE_ISP21XX "ql2100_fw.bin"
4949#define FW_FILE_ISP22XX "ql2200_fw.bin"
4950#define FW_FILE_ISP2300 "ql2300_fw.bin"
4951#define FW_FILE_ISP2322 "ql2322_fw.bin"
4952#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004953#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004954#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07004955#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004956#define FW_FILE_ISP2031 "ql2600_fw.bin"
4957#define FW_FILE_ISP8031 "ql8300_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004958
Daniel Walkere1e82b62008-05-12 22:21:10 -07004959static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004960
4961static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004962 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
4963 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
4964 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
4965 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
4966 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004967 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004968 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004969 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004970 { .name = FW_FILE_ISP2031, },
4971 { .name = FW_FILE_ISP8031, },
Andrew Vasquez54333832005-11-09 15:49:04 -08004972};
4973
4974struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004975qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08004976{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004977 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08004978 struct fw_blob *blob;
4979
Andrew Vasquez54333832005-11-09 15:49:04 -08004980 if (IS_QLA2100(ha)) {
4981 blob = &qla_fw_blobs[FW_ISP21XX];
4982 } else if (IS_QLA2200(ha)) {
4983 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004984 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004985 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004986 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004987 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004988 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004989 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004990 } else if (IS_QLA25XX(ha)) {
4991 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004992 } else if (IS_QLA81XX(ha)) {
4993 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07004994 } else if (IS_QLA82XX(ha)) {
4995 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004996 } else if (IS_QLA2031(ha)) {
4997 blob = &qla_fw_blobs[FW_ISP2031];
4998 } else if (IS_QLA8031(ha)) {
4999 blob = &qla_fw_blobs[FW_ISP8031];
Dan Carpenter8a655222012-02-21 10:29:40 +03005000 } else {
5001 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08005002 }
5003
Daniel Walkere1e82b62008-05-12 22:21:10 -07005004 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005005 if (blob->fw)
5006 goto out;
5007
5008 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005009 ql_log(ql_log_warn, vha, 0x0063,
5010 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08005011 blob->fw = NULL;
5012 blob = NULL;
5013 goto out;
5014 }
5015
5016out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07005017 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005018 return blob;
5019}
5020
5021static void
5022qla2x00_release_firmware(void)
5023{
5024 int idx;
5025
Daniel Walkere1e82b62008-05-12 22:21:10 -07005026 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005027 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02005028 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07005029 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08005030}
5031
Seokmann Ju14e660e2007-09-20 14:07:36 -07005032static pci_ers_result_t
5033qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5034{
Andrew Vasquez85880802009-12-15 21:29:46 -08005035 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5036 struct qla_hw_data *ha = vha->hw;
5037
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005038 ql_dbg(ql_dbg_aer, vha, 0x9000,
5039 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07005040
Seokmann Ju14e660e2007-09-20 14:07:36 -07005041 switch (state) {
5042 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08005043 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005044 return PCI_ERS_RESULT_CAN_RECOVER;
5045 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08005046 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005047 /* For ISP82XX complete any pending mailbox cmd */
5048 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005049 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08005050 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5051 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005052 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005053 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005054 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005055 /* Return back all IOs */
5056 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005057 return PCI_ERS_RESULT_NEED_RESET;
5058 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08005059 ha->flags.pci_channel_io_perm_failure = 1;
5060 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005061 return PCI_ERS_RESULT_DISCONNECT;
5062 }
5063 return PCI_ERS_RESULT_NEED_RESET;
5064}
5065
5066static pci_ers_result_t
5067qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
5068{
5069 int risc_paused = 0;
5070 uint32_t stat;
5071 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005072 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5073 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005074 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5075 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
5076
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07005077 if (IS_QLA82XX(ha))
5078 return PCI_ERS_RESULT_RECOVERED;
5079
Seokmann Ju14e660e2007-09-20 14:07:36 -07005080 spin_lock_irqsave(&ha->hardware_lock, flags);
5081 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
5082 stat = RD_REG_DWORD(&reg->hccr);
5083 if (stat & HCCR_RISC_PAUSE)
5084 risc_paused = 1;
5085 } else if (IS_QLA23XX(ha)) {
5086 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
5087 if (stat & HSR_RISC_PAUSED)
5088 risc_paused = 1;
5089 } else if (IS_FWI2_CAPABLE(ha)) {
5090 stat = RD_REG_DWORD(&reg24->host_status);
5091 if (stat & HSRX_RISC_PAUSED)
5092 risc_paused = 1;
5093 }
5094 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5095
5096 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005097 ql_log(ql_log_info, base_vha, 0x9003,
5098 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005099 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005100
5101 return PCI_ERS_RESULT_NEED_RESET;
5102 } else
5103 return PCI_ERS_RESULT_RECOVERED;
5104}
5105
Saurav Kashyapfa492632012-11-21 02:40:29 -05005106static uint32_t
5107qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005108{
5109 uint32_t rval = QLA_FUNCTION_FAILED;
5110 uint32_t drv_active = 0;
5111 struct qla_hw_data *ha = base_vha->hw;
5112 int fn;
5113 struct pci_dev *other_pdev = NULL;
5114
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005115 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5116 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005117
5118 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5119
5120 if (base_vha->flags.online) {
5121 /* Abort all outstanding commands,
5122 * so as to be requeued later */
5123 qla2x00_abort_isp_cleanup(base_vha);
5124 }
5125
5126
5127 fn = PCI_FUNC(ha->pdev->devfn);
5128 while (fn > 0) {
5129 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005130 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5131 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005132 other_pdev =
5133 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5134 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5135 fn));
5136
5137 if (!other_pdev)
5138 continue;
5139 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005140 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5141 "Found PCI func available and enable at 0x%x.\n",
5142 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005143 pci_dev_put(other_pdev);
5144 break;
5145 }
5146 pci_dev_put(other_pdev);
5147 }
5148
5149 if (!fn) {
5150 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005151 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5152 "This devfn is reset owner = 0x%x.\n",
5153 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005154 qla82xx_idc_lock(ha);
5155
5156 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005157 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005158
5159 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5160 QLA82XX_IDC_VERSION);
5161
5162 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005163 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5164 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005165
5166 qla82xx_idc_unlock(ha);
5167 /* Reset if device is not already reset
5168 * drv_active would be 0 if a reset has already been done
5169 */
5170 if (drv_active)
5171 rval = qla82xx_start_firmware(base_vha);
5172 else
5173 rval = QLA_SUCCESS;
5174 qla82xx_idc_lock(ha);
5175
5176 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005177 ql_log(ql_log_info, base_vha, 0x900b,
5178 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005179 qla82xx_clear_drv_active(ha);
5180 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005181 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005182 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005183 ql_log(ql_log_info, base_vha, 0x900c,
5184 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005185 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005186 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005187 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005188 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005189 rval = qla82xx_restart_isp(base_vha);
5190 qla82xx_idc_lock(ha);
5191 /* Clear driver state register */
5192 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5193 qla82xx_set_drv_active(base_vha);
5194 }
5195 qla82xx_idc_unlock(ha);
5196 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005197 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5198 "This devfn is not reset owner = 0x%x.\n",
5199 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005200 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005201 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005202 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005203 rval = qla82xx_restart_isp(base_vha);
5204 qla82xx_idc_lock(ha);
5205 qla82xx_set_drv_active(base_vha);
5206 qla82xx_idc_unlock(ha);
5207 }
5208 }
5209 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5210
5211 return rval;
5212}
5213
Seokmann Ju14e660e2007-09-20 14:07:36 -07005214static pci_ers_result_t
5215qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5216{
5217 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005218 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5219 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005220 struct rsp_que *rsp;
5221 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005222
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005223 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5224 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005225
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005226 /* Workaround: qla2xxx driver which access hardware earlier
5227 * needs error state to be pci_channel_io_online.
5228 * Otherwise mailbox command timesout.
5229 */
5230 pdev->error_state = pci_channel_io_normal;
5231
5232 pci_restore_state(pdev);
5233
Richard Lary8c1496b2010-02-18 10:07:29 -08005234 /* pci_restore_state() clears the saved_state flag of the device
5235 * save restored state which resets saved_state flag
5236 */
5237 pci_save_state(pdev);
5238
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005239 if (ha->mem_only)
5240 rc = pci_enable_device_mem(pdev);
5241 else
5242 rc = pci_enable_device(pdev);
5243
5244 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005245 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005246 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005247 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005248 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005249
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005250 rsp = ha->rsp_q_map[0];
5251 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005252 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005253
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005254 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005255 goto exit_slot_reset;
5256
5257 if (IS_QLA82XX(ha)) {
5258 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5259 ret = PCI_ERS_RESULT_RECOVERED;
5260 goto exit_slot_reset;
5261 } else
5262 goto exit_slot_reset;
5263 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005264
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005265 while (ha->flags.mbox_busy && retries--)
5266 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005268 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005269 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005270 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005271 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005272
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005273
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005274exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005275 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5276 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005277
Seokmann Ju14e660e2007-09-20 14:07:36 -07005278 return ret;
5279}
5280
5281static void
5282qla2xxx_pci_resume(struct pci_dev *pdev)
5283{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005284 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5285 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005286 int ret;
5287
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005288 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5289 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005291 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005292 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005293 ql_log(ql_log_fatal, base_vha, 0x9002,
5294 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005295 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005296
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005297 pci_cleanup_aer_uncorrect_error_status(pdev);
5298
Andrew Vasquez85880802009-12-15 21:29:46 -08005299 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005300}
5301
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005302static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005303 .error_detected = qla2xxx_pci_error_detected,
5304 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5305 .slot_reset = qla2xxx_pci_slot_reset,
5306 .resume = qla2xxx_pci_resume,
5307};
5308
Andrew Vasquez54333832005-11-09 15:49:04 -08005309static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005310 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5311 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5312 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5313 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5314 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5315 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5316 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5317 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5318 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005319 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005320 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5321 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005322 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005323 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005324 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005325 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005326 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005327 { 0 },
5328};
5329MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5330
Andrew Vasquezfca29702005-07-06 10:31:47 -07005331static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005332 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005333 .driver = {
5334 .owner = THIS_MODULE,
5335 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005336 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005337 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005338 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005339 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005340 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005341};
5342
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005343static struct file_operations apidev_fops = {
5344 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005345 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005346};
5347
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348/**
5349 * qla2x00_module_init - Module initialization.
5350 **/
5351static int __init
5352qla2x00_module_init(void)
5353{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005354 int ret = 0;
5355
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005357 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005358 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005360 ql_log(ql_log_fatal, NULL, 0x0001,
5361 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 return -ENOMEM;
5363 }
5364
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005365 /* Initialize target kmem_cache and mem_pools */
5366 ret = qlt_init();
5367 if (ret < 0) {
5368 kmem_cache_destroy(srb_cachep);
5369 return ret;
5370 } else if (ret > 0) {
5371 /*
5372 * If initiator mode is explictly disabled by qlt_init(),
5373 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5374 * performing scsi_scan_target() during LOOP UP event.
5375 */
5376 qla2xxx_transport_functions.disable_target_scan = 1;
5377 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5378 }
5379
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380 /* Derive version string. */
5381 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005382 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005383 strcat(qla2x00_version_str, "-debug");
5384
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005385 qla2xxx_transport_template =
5386 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005387 if (!qla2xxx_transport_template) {
5388 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005389 ql_log(ql_log_fatal, NULL, 0x0002,
5390 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005391 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005393 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005394
5395 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5396 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005397 ql_log(ql_log_fatal, NULL, 0x0003,
5398 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005399 }
5400
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005401 qla2xxx_transport_vport_template =
5402 fc_attach_transport(&qla2xxx_transport_vport_functions);
5403 if (!qla2xxx_transport_vport_template) {
5404 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005405 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005406 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005407 ql_log(ql_log_fatal, NULL, 0x0004,
5408 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005409 return -ENODEV;
5410 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005411 ql_log(ql_log_info, NULL, 0x0005,
5412 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005413 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005414 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005415 if (ret) {
5416 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005417 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005418 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005419 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005420 ql_log(ql_log_fatal, NULL, 0x0006,
5421 "pci_register_driver failed...ret=%d Failing load!.\n",
5422 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005423 }
5424 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425}
5426
5427/**
5428 * qla2x00_module_exit - Module cleanup.
5429 **/
5430static void __exit
5431qla2x00_module_exit(void)
5432{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005433 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005434 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005435 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005436 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005437 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005438 if (ctx_cachep)
5439 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005441 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442}
5443
5444module_init(qla2x00_module_init);
5445module_exit(qla2x00_module_exit);
5446
5447MODULE_AUTHOR("QLogic Corporation");
5448MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5449MODULE_LICENSE("GPL");
5450MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005451MODULE_FIRMWARE(FW_FILE_ISP21XX);
5452MODULE_FIRMWARE(FW_FILE_ISP22XX);
5453MODULE_FIRMWARE(FW_FILE_ISP2300);
5454MODULE_FIRMWARE(FW_FILE_ISP2322);
5455MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005456MODULE_FIRMWARE(FW_FILE_ISP25XX);