blob: 3a1661cf8c1e59bcc94837fc003a68d6963e70ce [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
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700114#define MAX_Q_DEPTH 32
115static int ql2xmaxqdepth = MAX_Q_DEPTH;
116module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
117MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400118 "Maximum queue depth to set for each LUN. "
119 "Default is 32.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700120
Arun Easi9e522cd2012-08-22 14:21:31 -0400121int ql2xenabledif = 2;
122module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700123MODULE_PARM_DESC(ql2xenabledif,
124 " Enable T10-CRC-DIF "
Arun Easi8cb20492011-08-16 11:29:22 -0700125 " Default is 0 - No DIF Support. 1 - Enable it"
126 ", 2 - Enable DIF for all types, except Type 0.");
Arun Easibad75002010-05-04 15:01:30 -0700127
Arun Easi8cb20492011-08-16 11:29:22 -0700128int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700129module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
130MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700131 " Enable T10-CRC-DIF Error isolation by HBA:\n"
132 " Default is 1.\n"
133 " 0 -- Error isolation disabled\n"
134 " 1 -- Error isolation enabled only for DIX Type 0\n"
135 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700136
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700137int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800138module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700139MODULE_PARM_DESC(ql2xiidmaenable,
140 "Enables iIDMA settings "
141 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
142
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800143int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800144module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800145MODULE_PARM_DESC(ql2xmaxqueues,
146 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700147 "Default is 1 for single queue. Set it to number "
148 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700149
150int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800151module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700152MODULE_PARM_DESC(ql2xmultique_tag,
153 "Enables CPU affinity settings for the driver "
154 "Default is 0 for no affinity of request and response IO. "
155 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700156
157int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700158module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700159MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700160 "Option to specify location from which to load ISP firmware:.\n"
161 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700162 " interface.\n"
163 " 1 -- load firmware from flash.\n"
164 " 0 -- use default semantics.\n");
165
Andrew Vasquezae97c912010-02-18 10:07:28 -0800166int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800167module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800168MODULE_PARM_DESC(ql2xetsenable,
169 "Enables firmware ETS burst."
170 "Default is 0 - skip ETS enablement.");
171
Giridhar Malavali69078692010-05-28 15:08:28 -0700172int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700173module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700174MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700175 "Option to specify scheme for request queue posting.\n"
176 " 0 -- Regular doorbell.\n"
177 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700178
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700179int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800180module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700181MODULE_PARM_DESC(ql2xtargetreset,
182 "Enable target reset."
183 "Default is 1 - use hw defaults.");
184
Chad Dupuis4da26e12010-10-15 11:27:40 -0700185int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800186module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700187MODULE_PARM_DESC(ql2xgffidenable,
188 "Enables GFF_ID checks of port type. "
189 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700190
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700191int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800192module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700193MODULE_PARM_DESC(ql2xasynctmfenable,
194 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
195 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700196
197int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700198module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700199MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700200 "Option to specify reset behaviour.\n"
201 " 0 (Default) -- Reset on failure.\n"
202 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700203
Andrew Vasquez82515922011-05-10 11:30:13 -0700204uint ql2xmaxlun = MAX_LUNS;
205module_param(ql2xmaxlun, uint, S_IRUGO);
206MODULE_PARM_DESC(ql2xmaxlun,
207 "Defines the maximum LU number to register with the SCSI "
208 "midlayer. Default is 65535.");
209
Giridhar Malavali08de2842011-08-16 11:31:44 -0700210int ql2xmdcapmask = 0x1F;
211module_param(ql2xmdcapmask, int, S_IRUGO);
212MODULE_PARM_DESC(ql2xmdcapmask,
213 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800214 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700215
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800216int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700217module_param(ql2xmdenable, int, S_IRUGO);
218MODULE_PARM_DESC(ql2xmdenable,
219 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800220 "0 - MiniDump disabled. "
221 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700224 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 */
226static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500227static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800228static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
229static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500230static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500231static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static int qla2xxx_eh_abort(struct scsi_cmnd *);
233static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700234static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
236static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Mike Christiee881a172009-10-15 17:46:39 -0700238static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700239static int qla2x00_change_queue_type(struct scsi_device *, int);
240
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700241struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700243 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700244 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700245
246 .eh_abort_handler = qla2xxx_eh_abort,
247 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700248 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700249 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
250 .eh_host_reset_handler = qla2xxx_eh_host_reset,
251
252 .slave_configure = qla2xxx_slave_configure,
253
254 .slave_alloc = qla2xxx_slave_alloc,
255 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700256 .scan_finished = qla2xxx_scan_finished,
257 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700258 .change_queue_depth = qla2x00_change_queue_depth,
259 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700260 .this_id = -1,
261 .cmd_per_lun = 3,
262 .use_clustering = ENABLE_CLUSTERING,
263 .sg_tablesize = SG_ALL,
264
265 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700266 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400267
268 .supported_mode = MODE_INITIATOR,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700269};
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700272struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274/* TODO Convert to inlines
275 *
276 * Timer routines
277 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700279__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800280qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800282 init_timer(&vha->timer);
283 vha->timer.expires = jiffies + interval * HZ;
284 vha->timer.data = (unsigned long)vha;
285 vha->timer.function = (void (*)(unsigned long))func;
286 add_timer(&vha->timer);
287 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
290static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800291qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700293 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 if (vha->device_flags & DFLG_DEV_FAILED) {
295 ql_dbg(ql_dbg_timer, vha, 0x600d,
296 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700297 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700298 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700299
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800300 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Adrian Bunka824ebb2008-01-17 09:02:15 -0800303static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800304qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306 del_timer_sync(&vha->timer);
307 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310static int qla2x00_do_dpc(void *data);
311
312static void qla2x00_rst_aen(scsi_qla_host_t *);
313
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800314static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
315 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700316static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800317static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400320static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
321 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800322{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700323 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700324 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800325 GFP_KERNEL);
326 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700327 ql_log(ql_log_fatal, vha, 0x003b,
328 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800329 goto fail_req_map;
330 }
331
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700332 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800333 GFP_KERNEL);
334 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700335 ql_log(ql_log_fatal, vha, 0x003c,
336 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800337 goto fail_rsp_map;
338 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400339 /*
340 * Make sure we record at least the request and response queue zero in
341 * case we need to free them if part of the probe fails.
342 */
343 ha->rsp_q_map[0] = rsp;
344 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800345 set_bit(0, ha->rsp_qid_map);
346 set_bit(0, ha->req_qid_map);
347 return 1;
348
349fail_rsp_map:
350 kfree(ha->req_q_map);
351 ha->req_q_map = NULL;
352fail_req_map:
353 return -ENOMEM;
354}
355
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700356static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800357{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800358 if (req && req->ring)
359 dma_free_coherent(&ha->pdev->dev,
360 (req->length + 1) * sizeof(request_t),
361 req->ring, req->dma);
362
363 kfree(req);
364 req = NULL;
365}
366
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700367static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
368{
369 if (rsp && rsp->ring)
370 dma_free_coherent(&ha->pdev->dev,
371 (rsp->length + 1) * sizeof(response_t),
372 rsp->ring, rsp->dma);
373
374 kfree(rsp);
375 rsp = NULL;
376}
377
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800378static void qla2x00_free_queues(struct qla_hw_data *ha)
379{
380 struct req_que *req;
381 struct rsp_que *rsp;
382 int cnt;
383
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700384 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800385 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700386 qla2x00_free_req_que(ha, req);
387 }
388 kfree(ha->req_q_map);
389 ha->req_q_map = NULL;
390
391 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
392 rsp = ha->rsp_q_map[cnt];
393 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800394 }
395 kfree(ha->rsp_q_map);
396 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800397}
398
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700399static int qla25xx_setup_mode(struct scsi_qla_host *vha)
400{
401 uint16_t options = 0;
402 int ques, req, ret;
403 struct qla_hw_data *ha = vha->hw;
404
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700405 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700406 ql_log(ql_log_warn, vha, 0x00d8,
407 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700408 goto fail;
409 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700410 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700411 /* create a request queue for IO */
412 options |= BIT_7;
413 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
414 QLA_DEFAULT_QUE_QOS);
415 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700416 ql_log(ql_log_warn, vha, 0x00e0,
417 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700418 goto fail;
419 }
Tejun Heo278274d2011-02-01 11:42:42 +0100420 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700421 vha->req = ha->req_q_map[req];
422 options |= BIT_1;
423 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
424 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
425 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700426 ql_log(ql_log_warn, vha, 0x00e8,
427 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700428 goto fail2;
429 }
430 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700431 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700432 ql_dbg(ql_dbg_multiq, vha, 0xc007,
433 "CPU affinity mode enalbed, "
434 "no. of response queues:%d no. of request queues:%d.\n",
435 ha->max_rsp_queues, ha->max_req_queues);
436 ql_dbg(ql_dbg_init, vha, 0x00e9,
437 "CPU affinity mode enalbed, "
438 "no. of response queues:%d no. of request queues:%d.\n",
439 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700440 }
441 return 0;
442fail2:
443 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700444 destroy_workqueue(ha->wq);
445 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800446 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700447fail:
448 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700449 kfree(ha->req_q_map);
450 kfree(ha->rsp_q_map);
451 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700452 return 1;
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800456qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800458 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 static char *pci_bus_modes[] = {
460 "33", "66", "100", "133",
461 };
462 uint16_t pci_bus;
463
464 strcpy(str, "PCI");
465 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
466 if (pci_bus) {
467 strcat(str, "-X (");
468 strcat(str, pci_bus_modes[pci_bus]);
469 } else {
470 pci_bus = (ha->pci_attr & BIT_8) >> 8;
471 strcat(str, " (");
472 strcat(str, pci_bus_modes[pci_bus]);
473 }
474 strcat(str, " MHz)");
475
476 return (str);
477}
478
Andrew Vasquezfca29702005-07-06 10:31:47 -0700479static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800480qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700481{
482 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700484 uint32_t pci_bus;
485 int pcie_reg;
486
Jon Masone67f1322012-07-10 14:57:56 -0700487 pcie_reg = pci_pcie_cap(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700488 if (pcie_reg) {
489 char lwstr[6];
490 uint16_t pcie_lstat, lspeed, lwidth;
491
Jon Masone67f1322012-07-10 14:57:56 -0700492 pcie_reg += PCI_EXP_LNKCAP;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700493 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
494 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
495 lwidth = (pcie_lstat &
496 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
497
498 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500499 switch (lspeed) {
500 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700501 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500502 break;
503 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700504 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500505 break;
506 case 3:
507 strcat(str, "8.0GT/s ");
508 break;
509 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700510 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500511 break;
512 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700513 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
514 strcat(str, lwstr);
515
516 return str;
517 }
518
519 strcpy(str, "PCI");
520 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
521 if (pci_bus == 0 || pci_bus == 8) {
522 strcat(str, " (");
523 strcat(str, pci_bus_modes[pci_bus >> 3]);
524 } else {
525 strcat(str, "-X ");
526 if (pci_bus & BIT_2)
527 strcat(str, "Mode 2");
528 else
529 strcat(str, "Mode 1");
530 strcat(str, " (");
531 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
532 }
533 strcat(str, " MHz)");
534
535 return str;
536}
537
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800538static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800539qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
541 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800542 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
545 ha->fw_minor_version,
546 ha->fw_subminor_version);
547
548 if (ha->fw_attributes & BIT_9) {
549 strcat(str, "FLX");
550 return (str);
551 }
552
553 switch (ha->fw_attributes & 0xFF) {
554 case 0x7:
555 strcat(str, "EF");
556 break;
557 case 0x17:
558 strcat(str, "TP");
559 break;
560 case 0x37:
561 strcat(str, "IP");
562 break;
563 case 0x77:
564 strcat(str, "VI");
565 break;
566 default:
567 sprintf(un_str, "(%x)", ha->fw_attributes);
568 strcat(str, un_str);
569 break;
570 }
571 if (ha->fw_attributes & 0x100)
572 strcat(str, "X");
573
574 return (str);
575}
576
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800577static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700579{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700581
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800582 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
583 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700584 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700585}
586
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800587void
588qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700589{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800590 srb_t *sp = (srb_t *)ptr;
591 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
592 struct qla_hw_data *ha = sp->fcport->vha->hw;
593 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700594
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800595 if (sp->flags & SRB_DMA_VALID) {
596 scsi_dma_unmap(cmd);
597 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700598 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700599
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800600 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
601 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
602 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
603 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
604 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700605
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800606 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
607 /* List assured to be having elements */
608 qla2x00_clean_dsd_pool(ha, sp);
609 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
610 }
611
612 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
613 dma_pool_free(ha->dl_dma_pool, ctx,
614 ((struct crc_context *)ctx)->crc_ctx_dma);
615 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
616 }
617
618 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
619 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
620
621 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
622 ctx1->fcp_cmnd_dma);
623 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
624 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
625 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
626 mempool_free(ctx1, ha->ctx_mempool);
627 ctx1 = NULL;
628 }
629
630 CMD_SP(cmd) = NULL;
631 mempool_free(sp, ha->srb_mempool);
632}
633
634static void
635qla2x00_sp_compl(void *data, void *ptr, int res)
636{
637 struct qla_hw_data *ha = (struct qla_hw_data *)data;
638 srb_t *sp = (srb_t *)ptr;
639 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
640
641 cmd->result = res;
642
643 if (atomic_read(&sp->ref_count) == 0) {
644 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
645 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
646 sp, GET_CMD_SP(sp));
647 if (ql2xextended_error_logging & ql_dbg_io)
648 BUG();
649 return;
650 }
651 if (!atomic_dec_and_test(&sp->ref_count))
652 return;
653
654 qla2x00_sp_free_dma(ha, sp);
655 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700656}
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800659qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700660{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700661 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700662 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400663 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800664 struct qla_hw_data *ha = vha->hw;
665 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700666 srb_t *sp;
667 int rval;
668
Andrew Vasquez85880802009-12-15 21:29:46 -0800669 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700670 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400671 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700672 "PCI Channel IO permanent failure, exiting "
673 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700674 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700675 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400676 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700677 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800678 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700679 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700680 goto qc24_fail_command;
681 }
682
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400683 rval = fc_remote_port_chkready(rport);
684 if (rval) {
685 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400686 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
688 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700689 goto qc24_fail_command;
690 }
691
Arun Easibad75002010-05-04 15:01:30 -0700692 if (!vha->flags.difdix_supported &&
693 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 ql_dbg(ql_dbg_io, vha, 0x3004,
695 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
696 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700697 cmd->result = DID_NO_CONNECT << 16;
698 goto qc24_fail_command;
699 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800700
701 if (!fcport) {
702 cmd->result = DID_NO_CONNECT << 16;
703 goto qc24_fail_command;
704 }
705
Andrew Vasquezfca29702005-07-06 10:31:47 -0700706 if (atomic_read(&fcport->state) != FCS_ONLINE) {
707 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700708 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700709 ql_dbg(ql_dbg_io, vha, 0x3005,
710 "Returning DNC, fcport_state=%d loop_state=%d.\n",
711 atomic_read(&fcport->state),
712 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700713 cmd->result = DID_NO_CONNECT << 16;
714 goto qc24_fail_command;
715 }
Mike Christie7b594132008-08-17 15:24:40 -0500716 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700717 }
718
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800719 sp = qla2x00_get_sp(base_vha, fcport, GFP_ATOMIC);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700720 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800721 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700722
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800723 sp->u.scmd.cmd = cmd;
724 sp->type = SRB_SCSI_CMD;
725 atomic_set(&sp->ref_count, 1);
726 CMD_SP(cmd) = (void *)sp;
727 sp->free = qla2x00_sp_free_dma;
728 sp->done = qla2x00_sp_compl;
729
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700731 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500732 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700733 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700734 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700735 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700736
Andrew Vasquezfca29702005-07-06 10:31:47 -0700737 return 0;
738
739qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800740 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700741
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800742qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700743 return SCSI_MLQUEUE_HOST_BUSY;
744
Mike Christie7b594132008-08-17 15:24:40 -0500745qc24_target_busy:
746 return SCSI_MLQUEUE_TARGET_BUSY;
747
Andrew Vasquezfca29702005-07-06 10:31:47 -0700748qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800749 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700750
751 return 0;
752}
753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754/*
755 * qla2x00_eh_wait_on_command
756 * Waits for the command to be returned by the Firmware for some
757 * max time.
758 *
759 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 *
762 * Return:
763 * Not Found : 0
764 * Found : 1
765 */
766static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800767qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700769#define ABORT_POLLING_PERIOD 1000
770#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500771 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800772 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
773 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500774 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Andrew Vasquez85880802009-12-15 21:29:46 -0800776 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700777 ql_dbg(ql_dbg_taskm, vha, 0x8005,
778 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800779 return ret;
780 }
781
Lalit Chandivaded9704322009-08-25 11:36:18 -0700782 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700783 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500784 }
785 if (CMD_SP(cmd))
786 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
f4f051e2005-04-17 15:02:26 -0500788 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
791/*
792 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700793 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 * <= MAX_RETRIES_OF_ISP_ABORT or
795 * finally HBA is disabled ie marked offline
796 *
797 * Input:
798 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700799 *
800 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 * Does context switching-Release SPIN_LOCK
802 * (if any) before calling this routine.
803 *
804 * Return:
805 * Success (Adapter is online) : 0
806 * Failed (Adapter is offline/disabled) : 1
807 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800808int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800809qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700811 int return_status;
812 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800813 struct qla_hw_data *ha = vha->hw;
814 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700816 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800817 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
818 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
819 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
820 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 msleep(1000);
823 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800824 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700825 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 else
827 return_status = QLA_FUNCTION_FAILED;
828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 return (return_status);
830}
831
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700832/*
833 * qla2x00_wait_for_reset_ready
834 * Wait till the HBA is online after going through
835 * <= MAX_RETRIES_OF_ISP_ABORT or
836 * finally HBA is disabled ie marked offline or flash
837 * operations are in progress.
838 *
839 * Input:
840 * ha - pointer to host adapter structure
841 *
842 * Note:
843 * Does context switching-Release SPIN_LOCK
844 * (if any) before calling this routine.
845 *
846 * Return:
847 * Success (Adapter is online/no flash ops) : 0
848 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
849 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500850static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700851qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
852{
853 int return_status;
854 unsigned long wait_online;
855 struct qla_hw_data *ha = vha->hw;
856 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
857
858 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
859 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
860 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
861 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
862 ha->optrom_state != QLA_SWAITING ||
863 ha->dpc_active) && time_before(jiffies, wait_online))
864 msleep(1000);
865
866 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
867 return_status = QLA_SUCCESS;
868 else
869 return_status = QLA_FUNCTION_FAILED;
870
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700871 ql_dbg(ql_dbg_taskm, vha, 0x8019,
872 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700873
874 return return_status;
875}
876
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700877int
878qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
879{
880 int return_status;
881 unsigned long wait_reset;
882 struct qla_hw_data *ha = vha->hw;
883 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
884
885 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
886 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
887 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
888 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
889 ha->dpc_active) && time_before(jiffies, wait_reset)) {
890
891 msleep(1000);
892
893 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
894 ha->flags.chip_reset_done)
895 break;
896 }
897 if (ha->flags.chip_reset_done)
898 return_status = QLA_SUCCESS;
899 else
900 return_status = QLA_FUNCTION_FAILED;
901
902 return return_status;
903}
904
Giridhar Malavali083a4692010-05-28 15:08:18 -0700905static void
906sp_get(struct srb *sp)
907{
908 atomic_inc(&sp->ref_count);
909}
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911/**************************************************************************
912* qla2xxx_eh_abort
913*
914* Description:
915* The abort function will abort the specified command.
916*
917* Input:
918* cmd = Linux SCSI command packet to be aborted.
919*
920* Returns:
921* Either SUCCESS or FAILED.
922*
923* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700924* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800926static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927qla2xxx_eh_abort(struct scsi_cmnd *cmd)
928{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500930 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800931 int ret;
f4f051e2005-04-17 15:02:26 -0500932 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700933 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700934 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800935 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
f4f051e2005-04-17 15:02:26 -0500937 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700938 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800940 ret = fc_block_scsi_eh(cmd);
941 if (ret != 0)
942 return ret;
943 ret = SUCCESS;
944
f4f051e2005-04-17 15:02:26 -0500945 id = cmd->device->id;
946 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800948 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700949 sp = (srb_t *) CMD_SP(cmd);
950 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700952 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500953 }
Mike Christie170babc2010-10-15 11:27:47 -0700954
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700955 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800956 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
957 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700958
959 /* Get a reference to the sp and drop the lock.*/
960 sp_get(sp);
961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700963 if (ha->isp_ops->abort_command(sp)) {
Arun Easia55aac72012-02-09 11:14:03 -0800964 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700965 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800966 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700967 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700968 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800969 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700970 wait = 1;
971 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700972
973 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800974 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700975 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500976
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700977 /* Did the command return during mailbox execution? */
978 if (ret == FAILED && !CMD_SP(cmd))
979 ret = SUCCESS;
980
f4f051e2005-04-17 15:02:26 -0500981 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700982 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800983 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700984 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800985 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -0700986 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700990 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800991 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
992 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
f4f051e2005-04-17 15:02:26 -0500994 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500997int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800998qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500999 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001001 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001002 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001004 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001005 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001006 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Andrew Vasquez523ec772008-04-03 13:13:24 -07001008 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001010 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001011 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001012 for (cnt = 1; status == QLA_SUCCESS &&
1013 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1014 sp = req->outstanding_cmds[cnt];
1015 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001016 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001017 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001018 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001019 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1020 continue;
1021 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001022 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001023 switch (type) {
1024 case WAIT_HOST:
1025 match = 1;
1026 break;
1027 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001028 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001029 break;
1030 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001031 match = (cmd->device->id == t &&
1032 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001033 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001035 if (!match)
1036 continue;
1037
1038 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001039 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001040 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001042 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001043
1044 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045}
1046
Andrew Vasquez523ec772008-04-03 13:13:24 -07001047static char *reset_errors[] = {
1048 "HBA not online",
1049 "HBA not ready",
1050 "Task management failed",
1051 "Waiting for command completions",
1052};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Andrew Vasquez523ec772008-04-03 13:13:24 -07001054static int
1055__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001056 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001057{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001058 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001059 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1060 int err;
1061
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001062 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001063 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001064 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001065
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001066 err = fc_block_scsi_eh(cmd);
1067 if (err != 0)
1068 return err;
1069
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001070 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001071 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001072 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001073
1074 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001075 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1076 ql_log(ql_log_warn, vha, 0x800a,
1077 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001078 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001079 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001080 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001081 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001082 != QLA_SUCCESS) {
1083 ql_log(ql_log_warn, vha, 0x800c,
1084 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001085 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001086 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001087 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001089 cmd->device->lun, type) != QLA_SUCCESS) {
1090 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001091 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001092 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001093 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001094
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001095 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001096 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1097 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001098
1099 return SUCCESS;
1100
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001101eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001102 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001103 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1104 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1105 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001106 return FAILED;
1107}
1108
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001109static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1111{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1113 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Andrew Vasquez523ec772008-04-03 13:13:24 -07001115 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1116 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001120qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1123 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Andrew Vasquez523ec772008-04-03 13:13:24 -07001125 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1126 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129/**************************************************************************
1130* qla2xxx_eh_bus_reset
1131*
1132* Description:
1133* The bus reset function will reset the bus and abort any executing
1134* commands.
1135*
1136* Input:
1137* cmd = Linux SCSI command packet of the command that cause the
1138* bus reset.
1139*
1140* Returns:
1141* SUCCESS/FAILURE (defined as macro in scsi.h).
1142*
1143**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001144static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1146{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001148 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001149 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001150 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
f4f051e2005-04-17 15:02:26 -05001152 id = cmd->device->id;
1153 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001154
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001155 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001156 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001159 ret = fc_block_scsi_eh(cmd);
1160 if (ret != 0)
1161 return ret;
1162 ret = FAILED;
1163
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001164 ql_log(ql_log_info, vha, 0x8012,
Andrew Vasquez46270af2012-05-15 14:34:17 -04001165 "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001167 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001168 ql_log(ql_log_fatal, vha, 0x8013,
1169 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001170 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
1172
Saurav Kashyapad537682011-11-18 09:02:09 -08001173 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1174 ret = SUCCESS;
1175
f4f051e2005-04-17 15:02:26 -05001176 if (ret == FAILED)
1177 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001179 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001180 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001181 QLA_SUCCESS) {
1182 ql_log(ql_log_warn, vha, 0x8014,
1183 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001184 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
f4f051e2005-04-17 15:02:26 -05001187eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001188 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001189 "BUS RESET %s nexus=%ld:%d:%d.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001190 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
f4f051e2005-04-17 15:02:26 -05001192 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
1195/**************************************************************************
1196* qla2xxx_eh_host_reset
1197*
1198* Description:
1199* The reset function will reset the Adapter.
1200*
1201* Input:
1202* cmd = Linux SCSI command packet of the command that cause the
1203* adapter reset.
1204*
1205* Returns:
1206* Either SUCCESS or FAILED.
1207*
1208* Note:
1209**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001210static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1212{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001213 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001214 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001215 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001216 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001217 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
f4f051e2005-04-17 15:02:26 -05001219 id = cmd->device->id;
1220 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001221
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001222 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001223 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001225 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001226 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001228 if (vha != base_vha) {
1229 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001230 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001231 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001232 if (IS_QLA82XX(vha->hw)) {
1233 if (!qla82xx_fcoe_ctx_reset(vha)) {
1234 /* Ctx reset success */
1235 ret = SUCCESS;
1236 goto eh_host_reset_lock;
1237 }
1238 /* fall thru if ctx reset failed */
1239 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001240 if (ha->wq)
1241 flush_workqueue(ha->wq);
1242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001243 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001244 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001245 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1246 /* failed. schedule dpc to try */
1247 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1248
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001249 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1250 ql_log(ql_log_warn, vha, 0x802a,
1251 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001252 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001253 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001254 }
1255 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001258 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001259 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001260 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001261 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
f4f051e2005-04-17 15:02:26 -05001263eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001264 ql_log(ql_log_info, vha, 0x8017,
1265 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1266 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
f4f051e2005-04-17 15:02:26 -05001268 return ret;
1269}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271/*
1272* qla2x00_loop_reset
1273* Issue loop reset.
1274*
1275* Input:
1276* ha = adapter block pointer.
1277*
1278* Returns:
1279* 0 = success
1280*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001281int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001282qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001284 int ret;
bdf79622005-04-17 15:06:53 -05001285 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001286 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001288 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001289 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1290 if (fcport->port_type != FCT_TARGET)
1291 continue;
1292
1293 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1294 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001295 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1296 "Bus Reset failed: Target Reset=%d "
1297 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001298 }
1299 }
1300 }
1301
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001302 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001303 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001304 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001305 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1306 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001307 }
1308 atomic_set(&vha->loop_state, LOOP_DOWN);
1309 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1310 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001313 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001314 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001315 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001316 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1317 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001318 }
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001321 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001323 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001326void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001328{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001329 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001330 unsigned long flags;
1331 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001332 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001333 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001334
1335 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001336 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001337 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001338 if (!req)
1339 continue;
1340 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1341 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001342 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001343 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001344 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001345 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001346 }
1347 }
1348 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1349}
1350
f4f051e2005-04-17 15:02:26 -05001351static int
1352qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
bdf79622005-04-17 15:06:53 -05001354 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001356 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001357 return -ENXIO;
1358
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001359 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001360
1361 return 0;
1362}
1363
1364static int
1365qla2xxx_slave_configure(struct scsi_device *sdev)
1366{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001367 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001368 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001369
Arun Easi9e522cd2012-08-22 14:21:31 -04001370 if (IS_T10_PI_CAPABLE(vha->hw))
1371 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1372
f4f051e2005-04-17 15:02:26 -05001373 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001374 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001376 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001377 return 0;
1378}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
f4f051e2005-04-17 15:02:26 -05001380static void
1381qla2xxx_slave_destroy(struct scsi_device *sdev)
1382{
1383 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001386static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1387{
1388 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1389
1390 if (!scsi_track_queue_full(sdev, qdepth))
1391 return;
1392
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001393 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001394 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1395 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001396}
1397
1398static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1399{
1400 fc_port_t *fcport = sdev->hostdata;
1401 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001402 struct req_que *req = NULL;
1403
1404 req = vha->req;
1405 if (!req)
1406 return;
1407
1408 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1409 return;
1410
1411 if (sdev->ordered_tags)
1412 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1413 else
1414 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1415
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001416 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001417 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1418 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001419}
1420
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001421static int
Mike Christiee881a172009-10-15 17:46:39 -07001422qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001423{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001424 switch (reason) {
1425 case SCSI_QDEPTH_DEFAULT:
1426 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1427 break;
1428 case SCSI_QDEPTH_QFULL:
1429 qla2x00_handle_queue_full(sdev, qdepth);
1430 break;
1431 case SCSI_QDEPTH_RAMP_UP:
1432 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1433 break;
1434 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001435 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001436 }
Mike Christiee881a172009-10-15 17:46:39 -07001437
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001438 return sdev->queue_depth;
1439}
1440
1441static int
1442qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1443{
1444 if (sdev->tagged_supported) {
1445 scsi_set_tag_type(sdev, tag_type);
1446 if (tag_type)
1447 scsi_activate_tcq(sdev, sdev->queue_depth);
1448 else
1449 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1450 } else
1451 tag_type = 0;
1452
1453 return tag_type;
1454}
1455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456/**
1457 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1458 * @ha: HA context
1459 *
1460 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1461 * supported addressing method.
1462 */
1463static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001464qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001466 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Yang Hongyang6a355282009-04-06 19:01:13 -07001469 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001470 /* Any upper-dword bits set? */
1471 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001472 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001473 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001475 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1476 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001477 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001480
Yang Hongyang284901a2009-04-06 19:01:15 -07001481 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1482 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001485static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001486qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001487{
1488 unsigned long flags = 0;
1489 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1490
1491 spin_lock_irqsave(&ha->hardware_lock, flags);
1492 ha->interrupts_on = 1;
1493 /* enable risc and host interrupts */
1494 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1495 RD_REG_WORD(&reg->ictrl);
1496 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1497
1498}
1499
1500static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001501qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001502{
1503 unsigned long flags = 0;
1504 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1505
1506 spin_lock_irqsave(&ha->hardware_lock, flags);
1507 ha->interrupts_on = 0;
1508 /* disable risc and host interrupts */
1509 WRT_REG_WORD(&reg->ictrl, 0);
1510 RD_REG_WORD(&reg->ictrl);
1511 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1512}
1513
1514static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001515qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001516{
1517 unsigned long flags = 0;
1518 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1519
1520 spin_lock_irqsave(&ha->hardware_lock, flags);
1521 ha->interrupts_on = 1;
1522 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1523 RD_REG_DWORD(&reg->ictrl);
1524 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1525}
1526
1527static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001528qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001529{
1530 unsigned long flags = 0;
1531 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1532
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001533 if (IS_NOPOLLING_TYPE(ha))
1534 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001535 spin_lock_irqsave(&ha->hardware_lock, flags);
1536 ha->interrupts_on = 0;
1537 WRT_REG_DWORD(&reg->ictrl, 0);
1538 RD_REG_DWORD(&reg->ictrl);
1539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1540}
1541
Giridhar Malavali706f4572011-11-18 09:03:16 -08001542static int
1543qla2x00_iospace_config(struct qla_hw_data *ha)
1544{
1545 resource_size_t pio;
1546 uint16_t msix;
1547 int cpus;
1548
Giridhar Malavali706f4572011-11-18 09:03:16 -08001549 if (pci_request_selected_regions(ha->pdev, ha->bars,
1550 QLA2XXX_DRIVER_NAME)) {
1551 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1552 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1553 pci_name(ha->pdev));
1554 goto iospace_error_exit;
1555 }
1556 if (!(ha->bars & 1))
1557 goto skip_pio;
1558
1559 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1560 pio = pci_resource_start(ha->pdev, 0);
1561 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1562 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1563 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1564 "Invalid pci I/O region size (%s).\n",
1565 pci_name(ha->pdev));
1566 pio = 0;
1567 }
1568 } else {
1569 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1570 "Region #0 no a PIO resource (%s).\n",
1571 pci_name(ha->pdev));
1572 pio = 0;
1573 }
1574 ha->pio_address = pio;
1575 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1576 "PIO address=%llu.\n",
1577 (unsigned long long)ha->pio_address);
1578
1579skip_pio:
1580 /* Use MMIO operations for all accesses. */
1581 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1582 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1583 "Region #1 not an MMIO resource (%s), aborting.\n",
1584 pci_name(ha->pdev));
1585 goto iospace_error_exit;
1586 }
1587 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1588 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1589 "Invalid PCI mem region size (%s), aborting.\n",
1590 pci_name(ha->pdev));
1591 goto iospace_error_exit;
1592 }
1593
1594 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1595 if (!ha->iobase) {
1596 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1597 "Cannot remap MMIO (%s), aborting.\n",
1598 pci_name(ha->pdev));
1599 goto iospace_error_exit;
1600 }
1601
1602 /* Determine queue resources */
1603 ha->max_req_queues = ha->max_rsp_queues = 1;
1604 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1605 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1606 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1607 goto mqiobase_exit;
1608
1609 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1610 pci_resource_len(ha->pdev, 3));
1611 if (ha->mqiobase) {
1612 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1613 "MQIO Base=%p.\n", ha->mqiobase);
1614 /* Read MSIX vector size of the board */
1615 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1616 ha->msix_count = msix;
1617 /* Max queues are bounded by available msix vectors */
1618 /* queue 0 uses two msix vectors */
1619 if (ql2xmultique_tag) {
1620 cpus = num_online_cpus();
1621 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1622 (cpus + 1) : (ha->msix_count - 1);
1623 ha->max_req_queues = 2;
1624 } else if (ql2xmaxqueues > 1) {
1625 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1626 QLA_MQ_SIZE : ql2xmaxqueues;
1627 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1628 "QoS mode set, max no of request queues:%d.\n",
1629 ha->max_req_queues);
1630 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1631 "QoS mode set, max no of request queues:%d.\n",
1632 ha->max_req_queues);
1633 }
1634 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1635 "MSI-X vector count: %d.\n", msix);
1636 } else
1637 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1638 "BAR 3 not enabled.\n");
1639
1640mqiobase_exit:
1641 ha->msix_count = ha->max_rsp_queues + 1;
1642 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1643 "MSIX Count:%d.\n", ha->msix_count);
1644 return (0);
1645
1646iospace_error_exit:
1647 return (-ENOMEM);
1648}
1649
1650
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001651static int
1652qla83xx_iospace_config(struct qla_hw_data *ha)
1653{
1654 uint16_t msix;
1655 int cpus;
1656
1657 if (pci_request_selected_regions(ha->pdev, ha->bars,
1658 QLA2XXX_DRIVER_NAME)) {
1659 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1660 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1661 pci_name(ha->pdev));
1662
1663 goto iospace_error_exit;
1664 }
1665
1666 /* Use MMIO operations for all accesses. */
1667 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1668 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1669 "Invalid pci I/O region size (%s).\n",
1670 pci_name(ha->pdev));
1671 goto iospace_error_exit;
1672 }
1673 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1674 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1675 "Invalid PCI mem region size (%s), aborting\n",
1676 pci_name(ha->pdev));
1677 goto iospace_error_exit;
1678 }
1679
1680 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1681 if (!ha->iobase) {
1682 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1683 "Cannot remap MMIO (%s), aborting.\n",
1684 pci_name(ha->pdev));
1685 goto iospace_error_exit;
1686 }
1687
1688 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1689 /* 83XX 26XX always use MQ type access for queues
1690 * - mbar 2, a.k.a region 4 */
1691 ha->max_req_queues = ha->max_rsp_queues = 1;
1692 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1693 pci_resource_len(ha->pdev, 4));
1694
1695 if (!ha->mqiobase) {
1696 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1697 "BAR2/region4 not enabled\n");
1698 goto mqiobase_exit;
1699 }
1700
1701 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1702 pci_resource_len(ha->pdev, 2));
1703 if (ha->msixbase) {
1704 /* Read MSIX vector size of the board */
1705 pci_read_config_word(ha->pdev,
1706 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1707 ha->msix_count = msix;
1708 /* Max queues are bounded by available msix vectors */
1709 /* queue 0 uses two msix vectors */
1710 if (ql2xmultique_tag) {
1711 cpus = num_online_cpus();
1712 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1713 (cpus + 1) : (ha->msix_count - 1);
1714 ha->max_req_queues = 2;
1715 } else if (ql2xmaxqueues > 1) {
1716 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1717 QLA_MQ_SIZE : ql2xmaxqueues;
1718 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1719 "QoS mode set, max no of request queues:%d.\n",
1720 ha->max_req_queues);
1721 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1722 "QoS mode set, max no of request queues:%d.\n",
1723 ha->max_req_queues);
1724 }
1725 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1726 "MSI-X vector count: %d.\n", msix);
1727 } else
1728 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1729 "BAR 1 not enabled.\n");
1730
1731mqiobase_exit:
1732 ha->msix_count = ha->max_rsp_queues + 1;
1733 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1734 "MSIX Count:%d.\n", ha->msix_count);
1735 return 0;
1736
1737iospace_error_exit:
1738 return -ENOMEM;
1739}
1740
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001741static struct isp_operations qla2100_isp_ops = {
1742 .pci_config = qla2100_pci_config,
1743 .reset_chip = qla2x00_reset_chip,
1744 .chip_diag = qla2x00_chip_diag,
1745 .config_rings = qla2x00_config_rings,
1746 .reset_adapter = qla2x00_reset_adapter,
1747 .nvram_config = qla2x00_nvram_config,
1748 .update_fw_options = qla2x00_update_fw_options,
1749 .load_risc = qla2x00_load_risc,
1750 .pci_info_str = qla2x00_pci_info_str,
1751 .fw_version_str = qla2x00_fw_version_str,
1752 .intr_handler = qla2100_intr_handler,
1753 .enable_intrs = qla2x00_enable_intrs,
1754 .disable_intrs = qla2x00_disable_intrs,
1755 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001756 .target_reset = qla2x00_abort_target,
1757 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001758 .fabric_login = qla2x00_login_fabric,
1759 .fabric_logout = qla2x00_fabric_logout,
1760 .calc_req_entries = qla2x00_calc_iocbs_32,
1761 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1762 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1763 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1764 .read_nvram = qla2x00_read_nvram_data,
1765 .write_nvram = qla2x00_write_nvram_data,
1766 .fw_dump = qla2100_fw_dump,
1767 .beacon_on = NULL,
1768 .beacon_off = NULL,
1769 .beacon_blink = NULL,
1770 .read_optrom = qla2x00_read_optrom_data,
1771 .write_optrom = qla2x00_write_optrom_data,
1772 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001774 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001775 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001776};
1777
1778static struct isp_operations qla2300_isp_ops = {
1779 .pci_config = qla2300_pci_config,
1780 .reset_chip = qla2x00_reset_chip,
1781 .chip_diag = qla2x00_chip_diag,
1782 .config_rings = qla2x00_config_rings,
1783 .reset_adapter = qla2x00_reset_adapter,
1784 .nvram_config = qla2x00_nvram_config,
1785 .update_fw_options = qla2x00_update_fw_options,
1786 .load_risc = qla2x00_load_risc,
1787 .pci_info_str = qla2x00_pci_info_str,
1788 .fw_version_str = qla2x00_fw_version_str,
1789 .intr_handler = qla2300_intr_handler,
1790 .enable_intrs = qla2x00_enable_intrs,
1791 .disable_intrs = qla2x00_disable_intrs,
1792 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001793 .target_reset = qla2x00_abort_target,
1794 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001795 .fabric_login = qla2x00_login_fabric,
1796 .fabric_logout = qla2x00_fabric_logout,
1797 .calc_req_entries = qla2x00_calc_iocbs_32,
1798 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1799 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1800 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1801 .read_nvram = qla2x00_read_nvram_data,
1802 .write_nvram = qla2x00_write_nvram_data,
1803 .fw_dump = qla2300_fw_dump,
1804 .beacon_on = qla2x00_beacon_on,
1805 .beacon_off = qla2x00_beacon_off,
1806 .beacon_blink = qla2x00_beacon_blink,
1807 .read_optrom = qla2x00_read_optrom_data,
1808 .write_optrom = qla2x00_write_optrom_data,
1809 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001810 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001811 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001812 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001813};
1814
1815static struct isp_operations qla24xx_isp_ops = {
1816 .pci_config = qla24xx_pci_config,
1817 .reset_chip = qla24xx_reset_chip,
1818 .chip_diag = qla24xx_chip_diag,
1819 .config_rings = qla24xx_config_rings,
1820 .reset_adapter = qla24xx_reset_adapter,
1821 .nvram_config = qla24xx_nvram_config,
1822 .update_fw_options = qla24xx_update_fw_options,
1823 .load_risc = qla24xx_load_risc,
1824 .pci_info_str = qla24xx_pci_info_str,
1825 .fw_version_str = qla24xx_fw_version_str,
1826 .intr_handler = qla24xx_intr_handler,
1827 .enable_intrs = qla24xx_enable_intrs,
1828 .disable_intrs = qla24xx_disable_intrs,
1829 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001830 .target_reset = qla24xx_abort_target,
1831 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001832 .fabric_login = qla24xx_login_fabric,
1833 .fabric_logout = qla24xx_fabric_logout,
1834 .calc_req_entries = NULL,
1835 .build_iocbs = NULL,
1836 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1837 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1838 .read_nvram = qla24xx_read_nvram_data,
1839 .write_nvram = qla24xx_write_nvram_data,
1840 .fw_dump = qla24xx_fw_dump,
1841 .beacon_on = qla24xx_beacon_on,
1842 .beacon_off = qla24xx_beacon_off,
1843 .beacon_blink = qla24xx_beacon_blink,
1844 .read_optrom = qla24xx_read_optrom_data,
1845 .write_optrom = qla24xx_write_optrom_data,
1846 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001847 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001848 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001849 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001850};
1851
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001852static struct isp_operations qla25xx_isp_ops = {
1853 .pci_config = qla25xx_pci_config,
1854 .reset_chip = qla24xx_reset_chip,
1855 .chip_diag = qla24xx_chip_diag,
1856 .config_rings = qla24xx_config_rings,
1857 .reset_adapter = qla24xx_reset_adapter,
1858 .nvram_config = qla24xx_nvram_config,
1859 .update_fw_options = qla24xx_update_fw_options,
1860 .load_risc = qla24xx_load_risc,
1861 .pci_info_str = qla24xx_pci_info_str,
1862 .fw_version_str = qla24xx_fw_version_str,
1863 .intr_handler = qla24xx_intr_handler,
1864 .enable_intrs = qla24xx_enable_intrs,
1865 .disable_intrs = qla24xx_disable_intrs,
1866 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001867 .target_reset = qla24xx_abort_target,
1868 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001869 .fabric_login = qla24xx_login_fabric,
1870 .fabric_logout = qla24xx_fabric_logout,
1871 .calc_req_entries = NULL,
1872 .build_iocbs = NULL,
1873 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1874 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1875 .read_nvram = qla25xx_read_nvram_data,
1876 .write_nvram = qla25xx_write_nvram_data,
1877 .fw_dump = qla25xx_fw_dump,
1878 .beacon_on = qla24xx_beacon_on,
1879 .beacon_off = qla24xx_beacon_off,
1880 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001881 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001882 .write_optrom = qla24xx_write_optrom_data,
1883 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001884 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001885 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001886 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001887};
1888
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001889static struct isp_operations qla81xx_isp_ops = {
1890 .pci_config = qla25xx_pci_config,
1891 .reset_chip = qla24xx_reset_chip,
1892 .chip_diag = qla24xx_chip_diag,
1893 .config_rings = qla24xx_config_rings,
1894 .reset_adapter = qla24xx_reset_adapter,
1895 .nvram_config = qla81xx_nvram_config,
1896 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001897 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001898 .pci_info_str = qla24xx_pci_info_str,
1899 .fw_version_str = qla24xx_fw_version_str,
1900 .intr_handler = qla24xx_intr_handler,
1901 .enable_intrs = qla24xx_enable_intrs,
1902 .disable_intrs = qla24xx_disable_intrs,
1903 .abort_command = qla24xx_abort_command,
1904 .target_reset = qla24xx_abort_target,
1905 .lun_reset = qla24xx_lun_reset,
1906 .fabric_login = qla24xx_login_fabric,
1907 .fabric_logout = qla24xx_fabric_logout,
1908 .calc_req_entries = NULL,
1909 .build_iocbs = NULL,
1910 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1911 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001912 .read_nvram = NULL,
1913 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001914 .fw_dump = qla81xx_fw_dump,
1915 .beacon_on = qla24xx_beacon_on,
1916 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001917 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001918 .read_optrom = qla25xx_read_optrom_data,
1919 .write_optrom = qla24xx_write_optrom_data,
1920 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001921 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001922 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001923 .iospace_config = qla2x00_iospace_config,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001924};
1925
1926static struct isp_operations qla82xx_isp_ops = {
1927 .pci_config = qla82xx_pci_config,
1928 .reset_chip = qla82xx_reset_chip,
1929 .chip_diag = qla24xx_chip_diag,
1930 .config_rings = qla82xx_config_rings,
1931 .reset_adapter = qla24xx_reset_adapter,
1932 .nvram_config = qla81xx_nvram_config,
1933 .update_fw_options = qla24xx_update_fw_options,
1934 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04001935 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001936 .fw_version_str = qla24xx_fw_version_str,
1937 .intr_handler = qla82xx_intr_handler,
1938 .enable_intrs = qla82xx_enable_intrs,
1939 .disable_intrs = qla82xx_disable_intrs,
1940 .abort_command = qla24xx_abort_command,
1941 .target_reset = qla24xx_abort_target,
1942 .lun_reset = qla24xx_lun_reset,
1943 .fabric_login = qla24xx_login_fabric,
1944 .fabric_logout = qla24xx_fabric_logout,
1945 .calc_req_entries = NULL,
1946 .build_iocbs = NULL,
1947 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1948 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1949 .read_nvram = qla24xx_read_nvram_data,
1950 .write_nvram = qla24xx_write_nvram_data,
1951 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001952 .beacon_on = qla82xx_beacon_on,
1953 .beacon_off = qla82xx_beacon_off,
1954 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001955 .read_optrom = qla82xx_read_optrom_data,
1956 .write_optrom = qla82xx_write_optrom_data,
1957 .get_flash_version = qla24xx_get_flash_version,
1958 .start_scsi = qla82xx_start_scsi,
1959 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001960 .iospace_config = qla82xx_iospace_config,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001961};
1962
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001963static struct isp_operations qla83xx_isp_ops = {
1964 .pci_config = qla25xx_pci_config,
1965 .reset_chip = qla24xx_reset_chip,
1966 .chip_diag = qla24xx_chip_diag,
1967 .config_rings = qla24xx_config_rings,
1968 .reset_adapter = qla24xx_reset_adapter,
1969 .nvram_config = qla81xx_nvram_config,
1970 .update_fw_options = qla81xx_update_fw_options,
1971 .load_risc = qla81xx_load_risc,
1972 .pci_info_str = qla24xx_pci_info_str,
1973 .fw_version_str = qla24xx_fw_version_str,
1974 .intr_handler = qla24xx_intr_handler,
1975 .enable_intrs = qla24xx_enable_intrs,
1976 .disable_intrs = qla24xx_disable_intrs,
1977 .abort_command = qla24xx_abort_command,
1978 .target_reset = qla24xx_abort_target,
1979 .lun_reset = qla24xx_lun_reset,
1980 .fabric_login = qla24xx_login_fabric,
1981 .fabric_logout = qla24xx_fabric_logout,
1982 .calc_req_entries = NULL,
1983 .build_iocbs = NULL,
1984 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1985 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1986 .read_nvram = NULL,
1987 .write_nvram = NULL,
1988 .fw_dump = qla83xx_fw_dump,
1989 .beacon_on = qla24xx_beacon_on,
1990 .beacon_off = qla24xx_beacon_off,
1991 .beacon_blink = qla83xx_beacon_blink,
1992 .read_optrom = qla25xx_read_optrom_data,
1993 .write_optrom = qla24xx_write_optrom_data,
1994 .get_flash_version = qla24xx_get_flash_version,
1995 .start_scsi = qla24xx_dif_start_scsi,
1996 .abort_isp = qla2x00_abort_isp,
1997 .iospace_config = qla83xx_iospace_config,
1998};
1999
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002000static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002002{
2003 ha->device_type = DT_EXTENDED_IDS;
2004 switch (ha->pdev->device) {
2005 case PCI_DEVICE_ID_QLOGIC_ISP2100:
2006 ha->device_type |= DT_ISP2100;
2007 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002008 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002009 break;
2010 case PCI_DEVICE_ID_QLOGIC_ISP2200:
2011 ha->device_type |= DT_ISP2200;
2012 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002013 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002014 break;
2015 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2016 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002017 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002018 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002019 break;
2020 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2021 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002022 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002023 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002024 break;
2025 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2026 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002027 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002028 if (ha->pdev->subsystem_vendor == 0x1028 &&
2029 ha->pdev->subsystem_device == 0x0170)
2030 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002031 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002032 break;
2033 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2034 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002035 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002036 break;
2037 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2038 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002039 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002040 break;
2041 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2042 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002043 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002044 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002045 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002046 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002047 break;
2048 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2049 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002050 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002051 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002052 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002053 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002054 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002055 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2056 ha->device_type |= DT_ISP8432;
2057 ha->device_type |= DT_ZIO_SUPPORTED;
2058 ha->device_type |= DT_FWI2;
2059 ha->device_type |= DT_IIDMA;
2060 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2061 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002062 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2063 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002064 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002065 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002066 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002067 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2068 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002069 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002070 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002071 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002072 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2073 ha->device_type |= DT_ISP2532;
2074 ha->device_type |= DT_ZIO_SUPPORTED;
2075 ha->device_type |= DT_FWI2;
2076 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002077 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2078 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002079 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2080 ha->device_type |= DT_ISP8001;
2081 ha->device_type |= DT_ZIO_SUPPORTED;
2082 ha->device_type |= DT_FWI2;
2083 ha->device_type |= DT_IIDMA;
2084 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2085 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002086 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2087 ha->device_type |= DT_ISP8021;
2088 ha->device_type |= DT_ZIO_SUPPORTED;
2089 ha->device_type |= DT_FWI2;
2090 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2091 /* Initialize 82XX ISP flags */
2092 qla82xx_init_flags(ha);
2093 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002094 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2095 ha->device_type |= DT_ISP2031;
2096 ha->device_type |= DT_ZIO_SUPPORTED;
2097 ha->device_type |= DT_FWI2;
2098 ha->device_type |= DT_IIDMA;
2099 ha->device_type |= DT_T10_PI;
2100 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2101 break;
2102 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2103 ha->device_type |= DT_ISP8031;
2104 ha->device_type |= DT_ZIO_SUPPORTED;
2105 ha->device_type |= DT_FWI2;
2106 ha->device_type |= DT_IIDMA;
2107 ha->device_type |= DT_T10_PI;
2108 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2109 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002110 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002111
Giridhar Malavalia9083012010-04-12 17:59:55 -07002112 if (IS_QLA82XX(ha))
2113 ha->port_no = !(ha->portnum & 1);
2114 else
2115 /* Get adapter physical port no from interrupt pin register. */
2116 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2117
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002118 if (ha->port_no & 1)
2119 ha->flags.port0 = 1;
2120 else
2121 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002122 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002123 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002124 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002125}
2126
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002127static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002128qla2xxx_scan_start(struct Scsi_Host *shost)
2129{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002130 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002131
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002132 if (vha->hw->flags.running_gold_fw)
2133 return;
2134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2136 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2137 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2138 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002139}
2140
2141static int
2142qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2143{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002144 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002145
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002147 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002149 return 1;
2150
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002151 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002152}
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154/*
2155 * PCI driver interface
2156 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002157static int __devinit
2158qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002160 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162 scsi_qla_host_t *base_vha = NULL;
2163 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002164 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002165 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002166 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002167 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002169 struct req_que *req = NULL;
2170 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Andrew Vasquez285d0322007-10-19 15:59:17 -07002172 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002173 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002174 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2175 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002176 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002177 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2178 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002179 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002180 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002181 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2182 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2183 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002184 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002185 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002186 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2187 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002188 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002189 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2190 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002191
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002192 if (mem_only) {
2193 if (pci_enable_device_mem(pdev))
2194 goto probe_out;
2195 } else {
2196 if (pci_enable_device(pdev))
2197 goto probe_out;
2198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Jesse Barnes09276782008-10-18 17:33:19 -07002200 /* This may fail but that's ok */
2201 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002202
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002203 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2204 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002205 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2206 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002207 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002209 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2210 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002211 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002212 ha->tgt.enable_class_2 = ql2xenableclass2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
2214 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002215 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002216 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002217 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002218 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002219 mutex_init(&ha->selflogin_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002221 /* Set ISP-type information. */
2222 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002223
2224 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002225 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2226 IS_QLA83XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002227 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002228
Chad Dupuiscba1e472011-11-18 09:03:21 -08002229 ha->prev_topology = 0;
2230 ha->init_cb_size = sizeof(init_cb_t);
2231 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2232 ha->optrom_size = OPTROM_SIZE_2300;
2233
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002234 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002236 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002238 req_length = REQUEST_ENTRY_CNT_2100;
2239 rsp_length = RESPONSE_ENTRY_CNT_2100;
2240 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002241 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002242 ha->flash_conf_off = ~0;
2243 ha->flash_data_off = ~0;
2244 ha->nvram_conf_off = ~0;
2245 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002246 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002248 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002249 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 req_length = REQUEST_ENTRY_CNT_2200;
2251 rsp_length = RESPONSE_ENTRY_CNT_2100;
2252 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002253 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002254 ha->flash_conf_off = ~0;
2255 ha->flash_data_off = ~0;
2256 ha->nvram_conf_off = ~0;
2257 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002258 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002259 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002260 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 req_length = REQUEST_ENTRY_CNT_2200;
2263 rsp_length = RESPONSE_ENTRY_CNT_2300;
2264 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002265 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002266 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2267 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002268 ha->flash_conf_off = ~0;
2269 ha->flash_data_off = ~0;
2270 ha->nvram_conf_off = ~0;
2271 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002272 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002273 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002274 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002275 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276 req_length = REQUEST_ENTRY_CNT_24XX;
2277 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002278 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002279 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002280 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002281 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002282 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002283 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002284 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002285 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2286 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2287 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2288 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002289 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002290 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002291 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 req_length = REQUEST_ENTRY_CNT_24XX;
2293 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002294 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002296 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002297 ha->gid_list_info_size = 8;
2298 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002299 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002300 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002301 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2302 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2303 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2304 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2305 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002306 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002307 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2308 req_length = REQUEST_ENTRY_CNT_24XX;
2309 rsp_length = RESPONSE_ENTRY_CNT_2300;
2310 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2311 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2312 ha->gid_list_info_size = 8;
2313 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002314 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002315 ha->isp_ops = &qla81xx_isp_ops;
2316 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2317 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2318 ha->nvram_conf_off = ~0;
2319 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002320 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002321 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002322 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2323 req_length = REQUEST_ENTRY_CNT_82XX;
2324 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2325 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2326 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2327 ha->gid_list_info_size = 8;
2328 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002329 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002330 ha->isp_ops = &qla82xx_isp_ops;
2331 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2332 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2333 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2334 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002335 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002336 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002337 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002338 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2339 req_length = REQUEST_ENTRY_CNT_24XX;
2340 rsp_length = RESPONSE_ENTRY_CNT_2300;
2341 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2342 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2343 ha->gid_list_info_size = 8;
2344 ha->optrom_size = OPTROM_SIZE_83XX;
2345 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2346 ha->isp_ops = &qla83xx_isp_ops;
2347 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2348 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2349 ha->nvram_conf_off = ~0;
2350 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002352
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002353 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2354 "mbx_count=%d, req_length=%d, "
2355 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002356 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2357 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002358 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2359 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002360 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002361 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2362 "isp_ops=%p, flash_conf_off=%d, "
2363 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2364 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2365 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002366
2367 /* Configure PCI I/O space */
2368 ret = ha->isp_ops->iospace_config(ha);
2369 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002370 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002371
2372 ql_log_pci(ql_log_info, pdev, 0x001d,
2373 "Found an ISP%04X irq %d iobase 0x%p.\n",
2374 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002375 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002376 init_completion(&ha->mbx_cmd_comp);
2377 complete(&ha->mbx_cmd_comp);
2378 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002379 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002381 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Andrew Vasquez53303c42009-01-22 09:45:37 -08002383 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002384 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2385 "64 Bit addressing is %s.\n",
2386 ha->flags.enable_64bit_addressing ? "enable" :
2387 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002388 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002390 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2391 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 goto probe_hw_failed;
2394 }
2395
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002396 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002398 req->max_q_depth = ql2xmaxqdepth;
2399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400
2401 base_vha = qla2x00_create_host(sht, ha);
2402 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002403 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002404 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002405 qla2x00_free_req_que(ha, req);
2406 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 }
2409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002413 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002414 host->can_queue = req->length + 128;
2415 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002417 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2419 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002420
2421 /* Set the SG table size based on ISP type */
2422 if (!IS_FWI2_CAPABLE(ha)) {
2423 if (IS_QLA2100(ha))
2424 host->sg_tablesize = 32;
2425 } else {
2426 if (!IS_QLA82XX(ha))
2427 host->sg_tablesize = QLA_SG_ALL;
2428 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002429 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2430 "can_queue=%d, req=%p, "
2431 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2432 host->can_queue, base_vha->req,
2433 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Chad Dupuis642ef982012-02-09 11:15:57 -08002434 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002435 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002436 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002437 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002438 host->max_cmd_len = 32;
2439 else
2440 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002441 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002442 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002443 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002444 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002445
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002446 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2447 "max_id=%d this_id=%d "
2448 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002449 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002450 host->this_id, host->cmd_per_lun, host->unique_id,
2451 host->max_cmd_len, host->max_channel, host->max_lun,
2452 host->transportt, sht->vendor_id);
2453
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002454que_init:
2455 /* Alloc arrays of request and response ring ptrs */
2456 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2457 ql_log(ql_log_fatal, base_vha, 0x003d,
2458 "Failed to allocate memory for queue pointers..."
2459 "aborting.\n");
2460 goto probe_init_failed;
2461 }
2462
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002463 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002464
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002465 /* Set up the irqs */
2466 ret = qla2x00_request_irqs(ha, rsp);
2467 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002468 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002469
2470 pci_save_state(pdev);
2471
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002472 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002473 rsp->req = req;
2474 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002475
Andrew Vasquez08029992009-03-24 09:07:55 -07002476 /* FWI2-capable only. */
2477 req->req_q_in = &ha->iobase->isp24.req_q_in;
2478 req->req_q_out = &ha->iobase->isp24.req_q_out;
2479 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2480 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002481 if (ha->mqenable || IS_QLA83XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002482 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2483 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2484 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2485 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002486 }
2487
Giridhar Malavalia9083012010-04-12 17:59:55 -07002488 if (IS_QLA82XX(ha)) {
2489 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2490 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2491 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2492 }
2493
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002494 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2495 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2496 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2497 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2498 "req->req_q_in=%p req->req_q_out=%p "
2499 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2500 req->req_q_in, req->req_q_out,
2501 rsp->rsp_q_in, rsp->rsp_q_out);
2502 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2503 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2504 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2505 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2506 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2507 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002509 if (qla2x00_initialize_adapter(base_vha)) {
2510 ql_log(ql_log_fatal, base_vha, 0x00d6,
2511 "Failed to initialize adapter - Adapter flags %x.\n",
2512 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513
Giridhar Malavalia9083012010-04-12 17:59:55 -07002514 if (IS_QLA82XX(ha)) {
2515 qla82xx_idc_lock(ha);
2516 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002517 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002518 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002519 ql_log(ql_log_fatal, base_vha, 0x00d7,
2520 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002521 }
2522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 ret = -ENODEV;
2524 goto probe_failed;
2525 }
2526
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002527 if (ha->mqenable) {
2528 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002529 ql_log(ql_log_warn, base_vha, 0x00ec,
2530 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002531 goto que_init;
2532 }
2533 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002534
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002535 if (ha->flags.running_gold_fw)
2536 goto skip_dpc;
2537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538 /*
2539 * Startup the kernel thread for this host adapter
2540 */
2541 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002542 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002544 ql_log(ql_log_fatal, base_vha, 0x00ed,
2545 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002546 ret = PTR_ERR(ha->dpc_thread);
2547 goto probe_failed;
2548 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002549 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2550 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002551
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002552 /*
2553 * If we're not coming up in initiator mode, we might sit for
2554 * a while without waking up the dpc thread, which leads to a
2555 * stuck process warning. So just kick the dpc once here and
2556 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2557 */
2558 qla2xxx_wake_dpc(base_vha);
2559
Saurav Kashyap81178772012-08-22 14:21:04 -04002560 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
2561 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
2562 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
2563 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
2564
2565 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
2566 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
2567 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
2568 INIT_WORK(&ha->idc_state_handler,
2569 qla83xx_idc_state_handler_work);
2570 INIT_WORK(&ha->nic_core_unrecoverable,
2571 qla83xx_nic_core_unrecoverable_work);
2572 }
2573
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002574skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 list_add_tail(&base_vha->list, &ha->vp_list);
2576 base_vha->host->irq = ha->pdev->irq;
2577
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002580 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2581 "Started qla2x00_timer with "
2582 "interval=%d.\n", WATCH_INTERVAL);
2583 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2584 "Detected hba at address=%p.\n",
2585 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
Arun Easie02587d2011-08-16 11:29:23 -07002587 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002588 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04002589 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07002590 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002591 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2592 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002593 if (ql2xenabledif == 1)
2594 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002595 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002596 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002597 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002598 | SHOST_DIF_TYPE3_PROTECTION
2599 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002600 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002601 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04002602
2603 guard = SHOST_DIX_GUARD_CRC;
2604
2605 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2606 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2607 guard |= SHOST_DIX_GUARD_IP;
2608
2609 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07002610 } else
2611 base_vha->flags.difdix_supported = 0;
2612 }
2613
Giridhar Malavalia9083012010-04-12 17:59:55 -07002614 ha->isp_ops->enable_intrs(ha);
2615
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002616 ret = scsi_add_host(host, &pdev->dev);
2617 if (ret)
2618 goto probe_failed;
2619
Michael Reed14864002009-12-02 09:11:16 -06002620 base_vha->flags.init_done = 1;
2621 base_vha->flags.online = 1;
2622
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002623 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2624 "Init done and hba is online.\n");
2625
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002626 if (qla_ini_mode_enabled(base_vha))
2627 scsi_scan_host(host);
2628 else
2629 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2630 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002632 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002633
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002635
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002637
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002638 ql_log(ql_log_info, base_vha, 0x00fb,
2639 "QLogic %s - %s.\n",
2640 ha->model_number, ha->model_desc ? ha->model_desc : "");
2641 ql_log(ql_log_info, base_vha, 0x00fc,
2642 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2643 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2644 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2645 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002648 qlt_add_target(ha, base_vha);
2649
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 return 0;
2651
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002652probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002653 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002654 ha->req_q_map[0] = NULL;
2655 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002656 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002657 ha->rsp_q_map[0] = NULL;
2658 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002659 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002662 if (base_vha->timer_active)
2663 qla2x00_stop_timer(base_vha);
2664 base_vha->flags.online = 0;
2665 if (ha->dpc_thread) {
2666 struct task_struct *t = ha->dpc_thread;
2667
2668 ha->dpc_thread = NULL;
2669 kthread_stop(t);
2670 }
2671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002677 if (IS_QLA82XX(ha)) {
2678 qla82xx_idc_lock(ha);
2679 qla82xx_clear_drv_active(ha);
2680 qla82xx_idc_unlock(ha);
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002681 }
2682iospace_config_failed:
2683 if (IS_QLA82XX(ha)) {
2684 if (!ha->nx_pcibase)
2685 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002686 if (!ql2xdbwr)
2687 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2688 } else {
2689 if (ha->iobase)
2690 iounmap(ha->iobase);
2691 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 pci_release_selected_regions(ha->pdev, ha->bars);
2693 kfree(ha);
2694 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002696probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002698 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Adrian Bunk4c993f72008-01-14 00:55:16 -08002701static void
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002702qla2x00_stop_dpc_thread(scsi_qla_host_t *vha)
2703{
2704 struct qla_hw_data *ha = vha->hw;
2705 struct task_struct *t = ha->dpc_thread;
2706
2707 if (ha->dpc_thread == NULL)
2708 return;
2709 /*
2710 * qla2xxx_wake_dpc checks for ->dpc_thread
2711 * so we need to zero it out.
2712 */
2713 ha->dpc_thread = NULL;
2714 kthread_stop(t);
2715}
2716
2717static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002718qla2x00_shutdown(struct pci_dev *pdev)
2719{
2720 scsi_qla_host_t *vha;
2721 struct qla_hw_data *ha;
2722
2723 vha = pci_get_drvdata(pdev);
2724 ha = vha->hw;
2725
2726 /* Turn-off FCE trace */
2727 if (ha->flags.fce_enabled) {
2728 qla2x00_disable_fce_trace(vha, NULL, NULL);
2729 ha->flags.fce_enabled = 0;
2730 }
2731
2732 /* Turn-off EFT trace */
2733 if (ha->eft)
2734 qla2x00_disable_eft_trace(vha);
2735
2736 /* Stop currently executing firmware. */
2737 qla2x00_try_to_stop_firmware(vha);
2738
2739 /* Turn adapter off line */
2740 vha->flags.online = 0;
2741
2742 /* turn-off interrupts on the card */
2743 if (ha->interrupts_on) {
2744 vha->flags.init_done = 0;
2745 ha->isp_ops->disable_intrs(ha);
2746 }
2747
2748 qla2x00_free_irqs(vha);
2749
2750 qla2x00_free_fw_dump(ha);
2751}
2752
2753static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002754qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755{
Arun Easifeafb7b2010-09-03 14:57:00 -07002756 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002758 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002760 /*
2761 * If the PCI device is disabled that means that probe failed and any
2762 * resources should be have cleaned up on probe exit.
2763 */
2764 if (!atomic_read(&pdev->enable_cnt))
2765 return;
2766
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 base_vha = pci_get_drvdata(pdev);
2768 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002770 ha->flags.host_shutting_down = 1;
2771
Giridhar Malavali220d36b2012-11-21 02:39:55 -05002772 set_bit(UNLOADING, &base_vha->dpc_flags);
Arun Easi43ebf162011-05-10 11:18:16 -07002773 mutex_lock(&ha->vport_lock);
2774 while (ha->cur_vport_count) {
2775 struct Scsi_Host *scsi_host;
Arun Easifeafb7b2010-09-03 14:57:00 -07002776
Arun Easi43ebf162011-05-10 11:18:16 -07002777 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002778
Arun Easi43ebf162011-05-10 11:18:16 -07002779 BUG_ON(base_vha->list.next == &ha->vp_list);
2780 /* This assumes first entry in ha->vp_list is always base vha */
2781 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2782 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002783
Arun Easi43ebf162011-05-10 11:18:16 -07002784 spin_unlock_irqrestore(&ha->vport_slock, flags);
2785 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002786
Arun Easi43ebf162011-05-10 11:18:16 -07002787 fc_vport_terminate(vha->fc_vport);
2788 scsi_host_put(vha->host);
2789
2790 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 }
Arun Easi43ebf162011-05-10 11:18:16 -07002792 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002793
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002794 if (IS_QLA8031(ha)) {
2795 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
2796 "Clearing fcoe driver presence.\n");
2797 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
2798 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
2799 "Error while clearing DRV-Presence.\n");
2800 }
2801
Andrew Vasquezb9978762009-03-24 09:08:05 -07002802 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002804 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002805
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002806 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002807
Andrew Vasquezb9978762009-03-24 09:08:05 -07002808 /* Disable timer */
2809 if (base_vha->timer_active)
2810 qla2x00_stop_timer(base_vha);
2811
2812 base_vha->flags.online = 0;
2813
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002814 /* Flush the work queue and remove it */
2815 if (ha->wq) {
2816 flush_workqueue(ha->wq);
2817 destroy_workqueue(ha->wq);
2818 ha->wq = NULL;
2819 }
2820
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002821 /* Cancel all work and destroy DPC workqueues */
2822 if (ha->dpc_lp_wq) {
2823 cancel_work_sync(&ha->idc_aen);
2824 destroy_workqueue(ha->dpc_lp_wq);
2825 ha->dpc_lp_wq = NULL;
2826 }
2827
2828 if (ha->dpc_hp_wq) {
2829 cancel_work_sync(&ha->nic_core_reset);
2830 cancel_work_sync(&ha->idc_state_handler);
2831 cancel_work_sync(&ha->nic_core_unrecoverable);
2832 destroy_workqueue(ha->dpc_hp_wq);
2833 ha->dpc_hp_wq = NULL;
2834 }
2835
Andrew Vasquezb9978762009-03-24 09:08:05 -07002836 /* Kill the kernel thread for this host */
2837 if (ha->dpc_thread) {
2838 struct task_struct *t = ha->dpc_thread;
2839
2840 /*
2841 * qla2xxx_wake_dpc checks for ->dpc_thread
2842 * so we need to zero it out.
2843 */
2844 ha->dpc_thread = NULL;
2845 kthread_stop(t);
2846 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002847 qlt_remove_target(ha, base_vha);
Andrew Vasquezb9978762009-03-24 09:08:05 -07002848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002849 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 scsi_host_put(base_vha->host);
2858
Giridhar Malavalia9083012010-04-12 17:59:55 -07002859 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002860 qla82xx_idc_lock(ha);
2861 qla82xx_clear_drv_active(ha);
2862 qla82xx_idc_unlock(ha);
2863
Giridhar Malavalia9083012010-04-12 17:59:55 -07002864 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2865 if (!ql2xdbwr)
2866 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2867 } else {
2868 if (ha->iobase)
2869 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002870
Giridhar Malavalia9083012010-04-12 17:59:55 -07002871 if (ha->mqiobase)
2872 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002873
2874 if (IS_QLA83XX(ha) && ha->msixbase)
2875 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002876 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 pci_release_selected_regions(ha->pdev, ha->bars);
2879 kfree(ha);
2880 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002882 pci_disable_pcie_error_reporting(pdev);
2883
Bernhard Walle665db932007-03-28 00:49:49 +02002884 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 pci_set_drvdata(pdev, NULL);
2886}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
2888static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
Andrew Vasquez85880802009-12-15 21:29:46 -08002893 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2894
2895 /* Disable timer */
2896 if (vha->timer_active)
2897 qla2x00_stop_timer(vha);
2898
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002899 qla2x00_stop_dpc_thread(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08002900
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002901 qla25xx_delete_queues(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002902 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002904
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002905 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002906 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002907
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002908 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
Andrew Vasquez85880802009-12-15 21:29:46 -08002911 vha->flags.online = 0;
2912
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002913 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002914 if (ha->interrupts_on) {
2915 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002916 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002917 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002918
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 qla2x00_free_irqs(vha);
2920
Chad Dupuis88670482010-07-23 15:28:30 +05002921 qla2x00_free_fcports(vha);
2922
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002923 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002924
Giridhar Malavali08de2842011-08-16 11:31:44 -07002925 qla82xx_md_free(vha);
2926
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002927 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928}
2929
Chad Dupuis88670482010-07-23 15:28:30 +05002930void qla2x00_free_fcports(struct scsi_qla_host *vha)
2931{
2932 fc_port_t *fcport, *tfcport;
2933
2934 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2935 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04002936 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05002937 kfree(fcport);
2938 fcport = NULL;
2939 }
2940}
2941
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002942static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002944 int defer)
2945{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002946 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002947 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002948 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002949
2950 if (!fcport->rport)
2951 return;
2952
2953 rport = fcport->rport;
2954 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002955 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002956 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002957 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002958 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002959 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2960 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002961 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002962 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002963 qlt_fc_port_deleted(vha, fcport);
2964 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002965}
2966
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2969 *
2970 * Input: ha = adapter block pointer. fcport = port structure pointer.
2971 *
2972 * Return: None.
2973 *
2974 * Context:
2975 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002977 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002979 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002980 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002981 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002982 qla2x00_schedule_rport_del(vha, fcport, defer);
2983 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002984 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 * We may need to retry the login, so don't change the state of the
2986 * port but do the retries.
2987 */
2988 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07002989 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991 if (!do_login)
2992 return;
2993
2994 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 fcport->login_retry = vha->hw->login_retry_count;
2996 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002998 ql_dbg(ql_dbg_disc, vha, 0x2067,
2999 "Port login retry "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 "%02x%02x%02x%02x%02x%02x%02x%02x, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003001 "id = 0x%04x retry cnt=%d.\n",
3002 fcport->port_name[0], fcport->port_name[1],
3003 fcport->port_name[2], fcport->port_name[3],
3004 fcport->port_name[4], fcport->port_name[5],
3005 fcport->port_name[6], fcport->port_name[7],
3006 fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 }
3008}
3009
3010/*
3011 * qla2x00_mark_all_devices_lost
3012 * Updates fcport state when device goes offline.
3013 *
3014 * Input:
3015 * ha = adapter block pointer.
3016 * fcport = port structure pointer.
3017 *
3018 * Return:
3019 * None.
3020 *
3021 * Context:
3022 */
3023void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025{
3026 fc_port_t *fcport;
3027
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003029 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003031
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 /*
3033 * No point in marking the device as lost, if the device is
3034 * already DEAD.
3035 */
3036 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3037 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003039 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003040 if (defer)
3041 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003042 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003043 qla2x00_schedule_rport_del(vha, fcport, defer);
3044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
3046}
3047
3048/*
3049* qla2x00_mem_alloc
3050* Allocates adapter memory.
3051*
3052* Returns:
3053* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003054* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003056static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003057qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3058 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059{
3060 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061
Andrew Vasqueze8711082008-01-31 12:33:48 -08003062 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003064 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003065 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003067 if (qlt_mem_alloc(ha) < 0)
3068 goto fail_free_init_cb;
3069
Chad Dupuis642ef982012-02-09 11:15:57 -08003070 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3071 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003072 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003073 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
Andrew Vasqueze8711082008-01-31 12:33:48 -08003075 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3076 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
Giridhar Malavalia9083012010-04-12 17:59:55 -07003079 if (IS_QLA82XX(ha)) {
3080 /* Allocate cache for CT6 Ctx. */
3081 if (!ctx_cachep) {
3082 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3083 sizeof(struct ct6_dsd), 0,
3084 SLAB_HWCACHE_ALIGN, NULL);
3085 if (!ctx_cachep)
3086 goto fail_free_gid_list;
3087 }
3088 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3089 ctx_cachep);
3090 if (!ha->ctx_mempool)
3091 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003092 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3093 "ctx_cachep=%p ctx_mempool=%p.\n",
3094 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003095 }
3096
Andrew Vasqueze8711082008-01-31 12:33:48 -08003097 /* Get memory for cached NVRAM */
3098 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3099 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003100 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003102 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3103 ha->pdev->device);
3104 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3105 DMA_POOL_SIZE, 8, 0);
3106 if (!ha->s_dma_pool)
3107 goto fail_free_nvram;
3108
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003109 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3110 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3111 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3112
Arun Easibad75002010-05-04 15:01:30 -07003113 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003114 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3115 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3116 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003117 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3118 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003119 goto fail_s_dma_pool;
3120 }
3121
3122 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3123 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3124 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003125 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3126 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003127 goto fail_dl_dma_pool;
3128 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003129 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3130 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3131 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003132 }
3133
Andrew Vasqueze8711082008-01-31 12:33:48 -08003134 /* Allocate memory for SNS commands */
3135 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003137 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003139 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003140 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003141 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003142 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003143 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003144 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003145 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003147 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148 goto fail_dma_pool;
3149 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003150 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003152 if (!ha->ct_sns)
3153 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003154 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3155 "ms_iocb=%p ct_sns=%p.\n",
3156 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 }
3158
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003160 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3161 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003162 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3163 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 goto fail_req;
3165 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003166 (*req)->length = req_len;
3167 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3168 ((*req)->length + 1) * sizeof(request_t),
3169 &(*req)->dma, GFP_KERNEL);
3170 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003171 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3172 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 goto fail_req_ring;
3174 }
3175 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003176 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3177 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003178 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3179 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 goto fail_rsp;
3181 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003182 (*rsp)->hw = ha;
3183 (*rsp)->length = rsp_len;
3184 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3185 ((*rsp)->length + 1) * sizeof(response_t),
3186 &(*rsp)->dma, GFP_KERNEL);
3187 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003188 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3189 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190 goto fail_rsp_ring;
3191 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003192 (*req)->rsp = *rsp;
3193 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003194 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3195 "req=%p req->length=%d req->ring=%p rsp=%p "
3196 "rsp->length=%d rsp->ring=%p.\n",
3197 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3198 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003199 /* Allocate memory for NVRAM data for vports */
3200 if (ha->nvram_npiv_size) {
3201 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003202 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003203 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003204 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3205 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003206 goto fail_npiv_info;
3207 }
3208 } else
3209 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003211 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003212 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003213 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3214 &ha->ex_init_cb_dma);
3215 if (!ha->ex_init_cb)
3216 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003217 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3218 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003219 }
3220
Giridhar Malavalia9083012010-04-12 17:59:55 -07003221 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3222
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003223 /* Get consistent memory allocated for Async Port-Database. */
3224 if (!IS_FWI2_CAPABLE(ha)) {
3225 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3226 &ha->async_pd_dma);
3227 if (!ha->async_pd)
3228 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003229 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3230 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003231 }
3232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003234
3235 /* Allocate memory for our loop_id bitmap */
3236 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3237 GFP_KERNEL);
3238 if (!ha->loop_id_map)
3239 goto fail_async_pd;
3240 else {
3241 qla2x00_set_reserved_loop_ids(ha);
3242 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
3243 "loop_id_map=%p. \n", ha->loop_id_map);
3244 }
3245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 return 1;
3247
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003248fail_async_pd:
3249 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003250fail_ex_init_cb:
3251 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003252fail_npiv_info:
3253 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3254 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3255 (*rsp)->ring = NULL;
3256 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003258 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003260 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3261 sizeof(request_t), (*req)->ring, (*req)->dma);
3262 (*req)->ring = NULL;
3263 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003265 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266fail_req:
3267 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3268 ha->ct_sns, ha->ct_sns_dma);
3269 ha->ct_sns = NULL;
3270 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003271fail_free_ms_iocb:
3272 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3273 ha->ms_iocb = NULL;
3274 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003276 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003277 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3278 ha->fcp_cmnd_dma_pool = NULL;
3279 }
3280fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003281 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003282 dma_pool_destroy(ha->dl_dma_pool);
3283 ha->dl_dma_pool = NULL;
3284 }
3285fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286 dma_pool_destroy(ha->s_dma_pool);
3287 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003288fail_free_nvram:
3289 kfree(ha->nvram);
3290 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003291fail_free_ctx_mempool:
3292 mempool_destroy(ha->ctx_mempool);
3293 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003294fail_free_srb_mempool:
3295 mempool_destroy(ha->srb_mempool);
3296 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003297fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003298 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3299 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003301 ha->gid_list = NULL;
3302 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003303fail_free_tgt_mem:
3304 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305fail_free_init_cb:
3306 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3307 ha->init_cb_dma);
3308 ha->init_cb = NULL;
3309 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003310fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003311 ql_log(ql_log_fatal, NULL, 0x0030,
3312 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003313 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314}
3315
3316/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003317* qla2x00_free_fw_dump
3318* Frees fw dump stuff.
3319*
3320* Input:
3321* ha = adapter block pointer.
3322*/
3323static void
3324qla2x00_free_fw_dump(struct qla_hw_data *ha)
3325{
3326 if (ha->fce)
3327 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3328 ha->fce_dma);
3329
3330 if (ha->fw_dump) {
3331 if (ha->eft)
3332 dma_free_coherent(&ha->pdev->dev,
3333 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3334 vfree(ha->fw_dump);
3335 }
3336 ha->fce = NULL;
3337 ha->fce_dma = 0;
3338 ha->eft = NULL;
3339 ha->eft_dma = 0;
3340 ha->fw_dump = NULL;
3341 ha->fw_dumped = 0;
3342 ha->fw_dump_reading = 0;
3343}
3344
3345/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346* qla2x00_mem_free
3347* Frees all adapter allocated memory.
3348*
3349* Input:
3350* ha = adapter block pointer.
3351*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003352static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003355 qla2x00_free_fw_dump(ha);
3356
Saurav Kashyap81178772012-08-22 14:21:04 -04003357 if (ha->mctp_dump)
3358 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
3359 ha->mctp_dump_dma);
3360
Andrew Vasqueze8711082008-01-31 12:33:48 -08003361 if (ha->srb_mempool)
3362 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003364 if (ha->dcbx_tlv)
3365 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3366 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3367
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003368 if (ha->xgmac_data)
3369 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3370 ha->xgmac_data, ha->xgmac_data_dma);
3371
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 if (ha->sns_cmd)
3373 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
3376 if (ha->ct_sns)
3377 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
Andrew Vasquez88729e52006-06-23 16:10:50 -07003380 if (ha->sfp_data)
3381 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3382
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 if (ha->ms_iocb)
3384 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3385
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003386 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003387 dma_pool_free(ha->s_dma_pool,
3388 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003389
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003390 if (ha->async_pd)
3391 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3392
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 if (ha->s_dma_pool)
3394 dma_pool_destroy(ha->s_dma_pool);
3395
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003397 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3398 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
Giridhar Malavalia9083012010-04-12 17:59:55 -07003400 if (IS_QLA82XX(ha)) {
3401 if (!list_empty(&ha->gbl_dsd_list)) {
3402 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3403
3404 /* clean up allocated prev pool */
3405 list_for_each_entry_safe(dsd_ptr,
3406 tdsd_ptr, &ha->gbl_dsd_list, list) {
3407 dma_pool_free(ha->dl_dma_pool,
3408 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3409 list_del(&dsd_ptr->list);
3410 kfree(dsd_ptr);
3411 }
3412 }
3413 }
3414
3415 if (ha->dl_dma_pool)
3416 dma_pool_destroy(ha->dl_dma_pool);
3417
3418 if (ha->fcp_cmnd_dma_pool)
3419 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3420
3421 if (ha->ctx_mempool)
3422 mempool_destroy(ha->ctx_mempool);
3423
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003424 qlt_mem_free(ha);
3425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003426 if (ha->init_cb)
3427 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003428 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 vfree(ha->optrom_buffer);
3430 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003431 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003432 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003433 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
Andrew Vasqueze8711082008-01-31 12:33:48 -08003435 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003436 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 ha->sns_cmd = NULL;
3438 ha->sns_cmd_dma = 0;
3439 ha->ct_sns = NULL;
3440 ha->ct_sns_dma = 0;
3441 ha->ms_iocb = NULL;
3442 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 ha->init_cb = NULL;
3444 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003445 ha->ex_init_cb = NULL;
3446 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003447 ha->async_pd = NULL;
3448 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
3450 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003451 ha->dl_dma_pool = NULL;
3452 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 ha->gid_list = NULL;
3455 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003456
3457 ha->tgt.atio_ring = NULL;
3458 ha->tgt.atio_dma = 0;
3459 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460}
3461
3462struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3463 struct qla_hw_data *ha)
3464{
3465 struct Scsi_Host *host;
3466 struct scsi_qla_host *vha = NULL;
3467
3468 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3469 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003470 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3471 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472 goto fail;
3473 }
3474
3475 /* Clear our data area */
3476 vha = shost_priv(host);
3477 memset(vha, 0, sizeof(scsi_qla_host_t));
3478
3479 vha->host = host;
3480 vha->host_no = host->host_no;
3481 vha->hw = ha;
3482
3483 INIT_LIST_HEAD(&vha->vp_fcports);
3484 INIT_LIST_HEAD(&vha->work_list);
3485 INIT_LIST_HEAD(&vha->list);
3486
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003487 spin_lock_init(&vha->work_lock);
3488
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003490 ql_dbg(ql_dbg_init, vha, 0x0041,
3491 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3492 vha->host, vha->hw, vha,
3493 dev_name(&(ha->pdev->dev)));
3494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 return vha;
3496
3497fail:
3498 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499}
3500
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003501static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003502qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003503{
3504 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003505 uint8_t bail;
3506
3507 QLA_VHA_MARK_BUSY(vha, bail);
3508 if (bail)
3509 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003510
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003511 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003512 if (!e) {
3513 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003514 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003515 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003516
3517 INIT_LIST_HEAD(&e->list);
3518 e->type = type;
3519 e->flags = QLA_EVT_FLAG_FREE;
3520 return e;
3521}
3522
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003523static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003524qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003525{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003526 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003527
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003528 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003529 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003530 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003532
Andrew Vasquez0971de72008-04-03 13:13:18 -07003533 return QLA_SUCCESS;
3534}
3535
3536int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003537qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003538 u32 data)
3539{
3540 struct qla_work_evt *e;
3541
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003542 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003543 if (!e)
3544 return QLA_FUNCTION_FAILED;
3545
3546 e->u.aen.code = code;
3547 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003548 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003549}
3550
Andrew Vasquez8a659572009-02-08 20:50:12 -08003551int
3552qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3553{
3554 struct qla_work_evt *e;
3555
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003556 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003557 if (!e)
3558 return QLA_FUNCTION_FAILED;
3559
3560 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003561 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003562}
3563
Andrew Vasquezac280b62009-08-20 11:06:05 -07003564#define qla2x00_post_async_work(name, type) \
3565int qla2x00_post_async_##name##_work( \
3566 struct scsi_qla_host *vha, \
3567 fc_port_t *fcport, uint16_t *data) \
3568{ \
3569 struct qla_work_evt *e; \
3570 \
3571 e = qla2x00_alloc_work(vha, type); \
3572 if (!e) \
3573 return QLA_FUNCTION_FAILED; \
3574 \
3575 e->u.logio.fcport = fcport; \
3576 if (data) { \
3577 e->u.logio.data[0] = data[0]; \
3578 e->u.logio.data[1] = data[1]; \
3579 } \
3580 return qla2x00_post_work(vha, e); \
3581}
3582
3583qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3584qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3585qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3586qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003587qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3588qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003589
Andrew Vasquez3420d362009-10-13 15:16:45 -07003590int
3591qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3592{
3593 struct qla_work_evt *e;
3594
3595 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3596 if (!e)
3597 return QLA_FUNCTION_FAILED;
3598
3599 e->u.uevent.code = code;
3600 return qla2x00_post_work(vha, e);
3601}
3602
3603static void
3604qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3605{
3606 char event_string[40];
3607 char *envp[] = { event_string, NULL };
3608
3609 switch (code) {
3610 case QLA_UEVENT_CODE_FW_DUMP:
3611 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3612 vha->host_no);
3613 break;
3614 default:
3615 /* do nothing */
3616 break;
3617 }
3618 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3619}
3620
Andrew Vasquezac280b62009-08-20 11:06:05 -07003621void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003622qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003623{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003624 struct qla_work_evt *e, *tmp;
3625 unsigned long flags;
3626 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003627
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003628 spin_lock_irqsave(&vha->work_lock, flags);
3629 list_splice_init(&vha->work_list, &work);
3630 spin_unlock_irqrestore(&vha->work_lock, flags);
3631
3632 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003633 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003634
3635 switch (e->type) {
3636 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003637 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003638 e->u.aen.code, e->u.aen.data);
3639 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003640 case QLA_EVT_IDC_ACK:
3641 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3642 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003643 case QLA_EVT_ASYNC_LOGIN:
3644 qla2x00_async_login(vha, e->u.logio.fcport,
3645 e->u.logio.data);
3646 break;
3647 case QLA_EVT_ASYNC_LOGIN_DONE:
3648 qla2x00_async_login_done(vha, e->u.logio.fcport,
3649 e->u.logio.data);
3650 break;
3651 case QLA_EVT_ASYNC_LOGOUT:
3652 qla2x00_async_logout(vha, e->u.logio.fcport);
3653 break;
3654 case QLA_EVT_ASYNC_LOGOUT_DONE:
3655 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3656 e->u.logio.data);
3657 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003658 case QLA_EVT_ASYNC_ADISC:
3659 qla2x00_async_adisc(vha, e->u.logio.fcport,
3660 e->u.logio.data);
3661 break;
3662 case QLA_EVT_ASYNC_ADISC_DONE:
3663 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3664 e->u.logio.data);
3665 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003666 case QLA_EVT_UEVENT:
3667 qla2x00_uevent_emit(vha, e->u.uevent.code);
3668 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003669 }
3670 if (e->flags & QLA_EVT_FLAG_FREE)
3671 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003672
3673 /* For each work completed decrement vha ref count */
3674 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003675 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003676}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678/* Relogins all the fcports of a vport
3679 * Context: dpc thread
3680 */
3681void qla2x00_relogin(struct scsi_qla_host *vha)
3682{
3683 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003684 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003685 uint16_t next_loopid = 0;
3686 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003687 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688
3689 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3690 /*
3691 * If the port is not ONLINE then try to login
3692 * to it if we haven't run out of retries.
3693 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003694 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3695 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003696 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003698 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003699 ha->isp_ops->fabric_logout(vha,
3700 fcport->loop_id,
3701 fcport->d_id.b.domain,
3702 fcport->d_id.b.area,
3703 fcport->d_id.b.al_pa);
3704
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003705 if (fcport->loop_id == FC_NO_LOOP_ID) {
3706 fcport->loop_id = next_loopid =
3707 ha->min_external_loopid;
3708 status = qla2x00_find_new_loop_id(
3709 vha, fcport);
3710 if (status != QLA_SUCCESS) {
3711 /* Ran out of IDs to use */
3712 break;
3713 }
3714 }
3715
Andrew Vasquezac280b62009-08-20 11:06:05 -07003716 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003717 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003718 data[0] = 0;
3719 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3720 status = qla2x00_post_async_login_work(
3721 vha, fcport, data);
3722 if (status == QLA_SUCCESS)
3723 continue;
3724 /* Attempt a retry. */
3725 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003726 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003727 status = qla2x00_fabric_login(vha,
3728 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003729 if (status == QLA_SUCCESS) {
3730 int status2;
3731 uint8_t opts;
3732
3733 opts = 0;
3734 if (fcport->flags &
3735 FCF_FCP2_DEVICE)
3736 opts |= BIT_1;
Saurav Kashyap03003962012-11-21 02:40:31 -05003737 status2 =
3738 qla2x00_get_port_database(
3739 vha, fcport, opts);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003740 if (status2 != QLA_SUCCESS)
3741 status = 1;
3742 }
3743 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003744 } else
3745 status = qla2x00_local_device_login(vha,
3746 fcport);
3747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003748 if (status == QLA_SUCCESS) {
3749 fcport->old_loop_id = fcport->loop_id;
3750
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003751 ql_dbg(ql_dbg_disc, vha, 0x2003,
3752 "Port login OK: logged in ID 0x%x.\n",
3753 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003754
3755 qla2x00_update_fcport(vha, fcport);
3756
3757 } else if (status == 1) {
3758 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3759 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003760 ql_dbg(ql_dbg_disc, vha, 0x2007,
3761 "Retrying %d login again loop_id 0x%x.\n",
3762 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763 } else {
3764 fcport->login_retry = 0;
3765 }
3766
3767 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Chad Dupuis5f16b332012-08-22 14:21:00 -04003768 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003769 }
3770 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3771 break;
3772 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003773}
3774
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003775/* Schedule work on any of the dpc-workqueues */
3776void
3777qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
3778{
3779 struct qla_hw_data *ha = base_vha->hw;
3780
3781 switch (work_code) {
3782 case MBA_IDC_AEN: /* 0x8200 */
3783 if (ha->dpc_lp_wq)
3784 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
3785 break;
3786
3787 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
3788 if (!ha->flags.nic_core_reset_hdlr_active) {
3789 if (ha->dpc_hp_wq)
3790 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
3791 } else
3792 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
3793 "NIC Core reset is already active. Skip "
3794 "scheduling it again.\n");
3795 break;
3796 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
3797 if (ha->dpc_hp_wq)
3798 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
3799 break;
3800 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
3801 if (ha->dpc_hp_wq)
3802 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
3803 break;
3804 default:
3805 ql_log(ql_log_warn, base_vha, 0xb05f,
3806 "Unknow work-code=0x%x.\n", work_code);
3807 }
3808
3809 return;
3810}
3811
3812/* Work: Perform NIC Core Unrecoverable state handling */
3813void
3814qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
3815{
3816 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04003817 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003818 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3819 uint32_t dev_state = 0;
3820
3821 qla83xx_idc_lock(base_vha, 0);
3822 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3823 qla83xx_reset_ownership(base_vha);
3824 if (ha->flags.nic_core_reset_owner) {
3825 ha->flags.nic_core_reset_owner = 0;
3826 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
3827 QLA8XXX_DEV_FAILED);
3828 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
3829 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
3830 }
3831 qla83xx_idc_unlock(base_vha, 0);
3832}
3833
3834/* Work: Execute IDC state handler */
3835void
3836qla83xx_idc_state_handler_work(struct work_struct *work)
3837{
3838 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04003839 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003840 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3841 uint32_t dev_state = 0;
3842
3843 qla83xx_idc_lock(base_vha, 0);
3844 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3845 if (dev_state == QLA8XXX_DEV_FAILED ||
3846 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
3847 qla83xx_idc_state_handler(base_vha);
3848 qla83xx_idc_unlock(base_vha, 0);
3849}
3850
Saurav Kashyapfa492632012-11-21 02:40:29 -05003851static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003852qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
3853{
3854 int rval = QLA_SUCCESS;
3855 unsigned long heart_beat_wait = jiffies + (1 * HZ);
3856 uint32_t heart_beat_counter1, heart_beat_counter2;
3857
3858 do {
3859 if (time_after(jiffies, heart_beat_wait)) {
3860 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
3861 "Nic Core f/w is not alive.\n");
3862 rval = QLA_FUNCTION_FAILED;
3863 break;
3864 }
3865
3866 qla83xx_idc_lock(base_vha, 0);
3867 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
3868 &heart_beat_counter1);
3869 qla83xx_idc_unlock(base_vha, 0);
3870 msleep(100);
3871 qla83xx_idc_lock(base_vha, 0);
3872 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
3873 &heart_beat_counter2);
3874 qla83xx_idc_unlock(base_vha, 0);
3875 } while (heart_beat_counter1 == heart_beat_counter2);
3876
3877 return rval;
3878}
3879
3880/* Work: Perform NIC Core Reset handling */
3881void
3882qla83xx_nic_core_reset_work(struct work_struct *work)
3883{
3884 struct qla_hw_data *ha =
3885 container_of(work, struct qla_hw_data, nic_core_reset);
3886 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3887 uint32_t dev_state = 0;
3888
Saurav Kashyap81178772012-08-22 14:21:04 -04003889 if (IS_QLA2031(ha)) {
3890 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
3891 ql_log(ql_log_warn, base_vha, 0xb081,
3892 "Failed to dump mctp\n");
3893 return;
3894 }
3895
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003896 if (!ha->flags.nic_core_reset_hdlr_active) {
3897 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
3898 qla83xx_idc_lock(base_vha, 0);
3899 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
3900 &dev_state);
3901 qla83xx_idc_unlock(base_vha, 0);
3902 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
3903 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
3904 "Nic Core f/w is alive.\n");
3905 return;
3906 }
3907 }
3908
3909 ha->flags.nic_core_reset_hdlr_active = 1;
3910 if (qla83xx_nic_core_reset(base_vha)) {
3911 /* NIC Core reset failed. */
3912 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
3913 "NIC Core reset failed.\n");
3914 }
3915 ha->flags.nic_core_reset_hdlr_active = 0;
3916 }
3917}
3918
3919/* Work: Handle 8200 IDC aens */
3920void
3921qla83xx_service_idc_aen(struct work_struct *work)
3922{
3923 struct qla_hw_data *ha =
3924 container_of(work, struct qla_hw_data, idc_aen);
3925 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3926 uint32_t dev_state, idc_control;
3927
3928 qla83xx_idc_lock(base_vha, 0);
3929 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3930 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
3931 qla83xx_idc_unlock(base_vha, 0);
3932 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
3933 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
3934 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
3935 "Application requested NIC Core Reset.\n");
3936 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
3937 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
3938 QLA_SUCCESS) {
3939 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
3940 "Other protocol driver requested NIC Core Reset.\n");
3941 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
3942 }
3943 } else if (dev_state == QLA8XXX_DEV_FAILED ||
3944 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
3945 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
3946 }
3947}
3948
3949static void
3950qla83xx_wait_logic(void)
3951{
3952 int i;
3953
3954 /* Yield CPU */
3955 if (!in_interrupt()) {
3956 /*
3957 * Wait about 200ms before retrying again.
3958 * This controls the number of retries for single
3959 * lock operation.
3960 */
3961 msleep(100);
3962 schedule();
3963 } else {
3964 for (i = 0; i < 20; i++)
3965 cpu_relax(); /* This a nop instr on i386 */
3966 }
3967}
3968
Saurav Kashyapfa492632012-11-21 02:40:29 -05003969static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003970qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
3971{
3972 int rval;
3973 uint32_t data;
3974 uint32_t idc_lck_rcvry_stage_mask = 0x3;
3975 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
3976 struct qla_hw_data *ha = base_vha->hw;
3977
3978 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
3979 if (rval)
3980 return rval;
3981
3982 if ((data & idc_lck_rcvry_stage_mask) > 0) {
3983 return QLA_SUCCESS;
3984 } else {
3985 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
3986 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
3987 data);
3988 if (rval)
3989 return rval;
3990
3991 msleep(200);
3992
3993 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
3994 &data);
3995 if (rval)
3996 return rval;
3997
3998 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
3999 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4000 ~(idc_lck_rcvry_stage_mask));
4001 rval = qla83xx_wr_reg(base_vha,
4002 QLA83XX_IDC_LOCK_RECOVERY, data);
4003 if (rval)
4004 return rval;
4005
4006 /* Forcefully perform IDC UnLock */
4007 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4008 &data);
4009 if (rval)
4010 return rval;
4011 /* Clear lock-id by setting 0xff */
4012 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4013 0xff);
4014 if (rval)
4015 return rval;
4016 /* Clear lock-recovery by setting 0x0 */
4017 rval = qla83xx_wr_reg(base_vha,
4018 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4019 if (rval)
4020 return rval;
4021 } else
4022 return QLA_SUCCESS;
4023 }
4024
4025 return rval;
4026}
4027
Saurav Kashyapfa492632012-11-21 02:40:29 -05004028static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004029qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4030{
4031 int rval = QLA_SUCCESS;
4032 uint32_t o_drv_lockid, n_drv_lockid;
4033 unsigned long lock_recovery_timeout;
4034
4035 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4036retry_lockid:
4037 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4038 if (rval)
4039 goto exit;
4040
4041 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4042 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4043 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4044 return QLA_SUCCESS;
4045 else
4046 return QLA_FUNCTION_FAILED;
4047 }
4048
4049 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4050 if (rval)
4051 goto exit;
4052
4053 if (o_drv_lockid == n_drv_lockid) {
4054 qla83xx_wait_logic();
4055 goto retry_lockid;
4056 } else
4057 return QLA_SUCCESS;
4058
4059exit:
4060 return rval;
4061}
4062
4063void
4064qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4065{
4066 uint16_t options = (requester_id << 15) | BIT_6;
4067 uint32_t data;
4068 struct qla_hw_data *ha = base_vha->hw;
4069
4070 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4071retry_lock:
4072 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4073 == QLA_SUCCESS) {
4074 if (data) {
4075 /* Setting lock-id to our function-number */
4076 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4077 ha->portnum);
4078 } else {
4079 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
4080 "Failed to acquire IDC lock. retrying...\n");
4081
4082 /* Retry/Perform IDC-Lock recovery */
4083 if (qla83xx_idc_lock_recovery(base_vha)
4084 == QLA_SUCCESS) {
4085 qla83xx_wait_logic();
4086 goto retry_lock;
4087 } else
4088 ql_log(ql_log_warn, base_vha, 0xb075,
4089 "IDC Lock recovery FAILED.\n");
4090 }
4091
4092 }
4093
4094 return;
4095
4096 /* XXX: IDC-lock implementation using access-control mbx */
4097retry_lock2:
4098 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4099 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4100 "Failed to acquire IDC lock. retrying...\n");
4101 /* Retry/Perform IDC-Lock recovery */
4102 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4103 qla83xx_wait_logic();
4104 goto retry_lock2;
4105 } else
4106 ql_log(ql_log_warn, base_vha, 0xb076,
4107 "IDC Lock recovery FAILED.\n");
4108 }
4109
4110 return;
4111}
4112
4113void
4114qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4115{
4116 uint16_t options = (requester_id << 15) | BIT_7, retry;
4117 uint32_t data;
4118 struct qla_hw_data *ha = base_vha->hw;
4119
4120 /* IDC-unlock implementation using driver-unlock/lock-id
4121 * remote registers
4122 */
4123 retry = 0;
4124retry_unlock:
4125 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4126 == QLA_SUCCESS) {
4127 if (data == ha->portnum) {
4128 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4129 /* Clearing lock-id by setting 0xff */
4130 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4131 } else if (retry < 10) {
4132 /* SV: XXX: IDC unlock retrying needed here? */
4133
4134 /* Retry for IDC-unlock */
4135 qla83xx_wait_logic();
4136 retry++;
4137 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
4138 "Failed to release IDC lock, retyring=%d\n", retry);
4139 goto retry_unlock;
4140 }
4141 } else if (retry < 10) {
4142 /* Retry for IDC-unlock */
4143 qla83xx_wait_logic();
4144 retry++;
4145 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
4146 "Failed to read drv-lockid, retyring=%d\n", retry);
4147 goto retry_unlock;
4148 }
4149
4150 return;
4151
4152 /* XXX: IDC-unlock implementation using access-control mbx */
4153 retry = 0;
4154retry_unlock2:
4155 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4156 if (retry < 10) {
4157 /* Retry for IDC-unlock */
4158 qla83xx_wait_logic();
4159 retry++;
4160 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
4161 "Failed to release IDC lock, retyring=%d\n", retry);
4162 goto retry_unlock2;
4163 }
4164 }
4165
4166 return;
4167}
4168
4169int
4170__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4171{
4172 int rval = QLA_SUCCESS;
4173 struct qla_hw_data *ha = vha->hw;
4174 uint32_t drv_presence;
4175
4176 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4177 if (rval == QLA_SUCCESS) {
4178 drv_presence |= (1 << ha->portnum);
4179 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4180 drv_presence);
4181 }
4182
4183 return rval;
4184}
4185
4186int
4187qla83xx_set_drv_presence(scsi_qla_host_t *vha)
4188{
4189 int rval = QLA_SUCCESS;
4190
4191 qla83xx_idc_lock(vha, 0);
4192 rval = __qla83xx_set_drv_presence(vha);
4193 qla83xx_idc_unlock(vha, 0);
4194
4195 return rval;
4196}
4197
4198int
4199__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4200{
4201 int rval = QLA_SUCCESS;
4202 struct qla_hw_data *ha = vha->hw;
4203 uint32_t drv_presence;
4204
4205 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4206 if (rval == QLA_SUCCESS) {
4207 drv_presence &= ~(1 << ha->portnum);
4208 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4209 drv_presence);
4210 }
4211
4212 return rval;
4213}
4214
4215int
4216qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
4217{
4218 int rval = QLA_SUCCESS;
4219
4220 qla83xx_idc_lock(vha, 0);
4221 rval = __qla83xx_clear_drv_presence(vha);
4222 qla83xx_idc_unlock(vha, 0);
4223
4224 return rval;
4225}
4226
Saurav Kashyapfa492632012-11-21 02:40:29 -05004227static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004228qla83xx_need_reset_handler(scsi_qla_host_t *vha)
4229{
4230 struct qla_hw_data *ha = vha->hw;
4231 uint32_t drv_ack, drv_presence;
4232 unsigned long ack_timeout;
4233
4234 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
4235 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
4236 while (1) {
4237 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4238 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05004239 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004240 break;
4241
4242 if (time_after_eq(jiffies, ack_timeout)) {
4243 ql_log(ql_log_warn, vha, 0xb067,
4244 "RESET ACK TIMEOUT! drv_presence=0x%x "
4245 "drv_ack=0x%x\n", drv_presence, drv_ack);
4246 /*
4247 * The function(s) which did not ack in time are forced
4248 * to withdraw any further participation in the IDC
4249 * reset.
4250 */
4251 if (drv_ack != drv_presence)
4252 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
4253 drv_ack);
4254 break;
4255 }
4256
4257 qla83xx_idc_unlock(vha, 0);
4258 msleep(1000);
4259 qla83xx_idc_lock(vha, 0);
4260 }
4261
4262 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
4263 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
4264}
4265
Saurav Kashyapfa492632012-11-21 02:40:29 -05004266static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004267qla83xx_device_bootstrap(scsi_qla_host_t *vha)
4268{
4269 int rval = QLA_SUCCESS;
4270 uint32_t idc_control;
4271
4272 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
4273 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
4274
4275 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
4276 __qla83xx_get_idc_control(vha, &idc_control);
4277 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
4278 __qla83xx_set_idc_control(vha, 0);
4279
4280 qla83xx_idc_unlock(vha, 0);
4281 rval = qla83xx_restart_nic_firmware(vha);
4282 qla83xx_idc_lock(vha, 0);
4283
4284 if (rval != QLA_SUCCESS) {
4285 ql_log(ql_log_fatal, vha, 0xb06a,
4286 "Failed to restart NIC f/w.\n");
4287 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
4288 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
4289 } else {
4290 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
4291 "Success in restarting nic f/w.\n");
4292 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
4293 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
4294 }
4295
4296 return rval;
4297}
4298
4299/* Assumes idc_lock always held on entry */
4300int
4301qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
4302{
4303 struct qla_hw_data *ha = base_vha->hw;
4304 int rval = QLA_SUCCESS;
4305 unsigned long dev_init_timeout;
4306 uint32_t dev_state;
4307
4308 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
4309 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
4310
4311 while (1) {
4312
4313 if (time_after_eq(jiffies, dev_init_timeout)) {
4314 ql_log(ql_log_warn, base_vha, 0xb06e,
4315 "Initialization TIMEOUT!\n");
4316 /* Init timeout. Disable further NIC Core
4317 * communication.
4318 */
4319 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4320 QLA8XXX_DEV_FAILED);
4321 ql_log(ql_log_info, base_vha, 0xb06f,
4322 "HW State: FAILED.\n");
4323 }
4324
4325 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4326 switch (dev_state) {
4327 case QLA8XXX_DEV_READY:
4328 if (ha->flags.nic_core_reset_owner)
4329 qla83xx_idc_audit(base_vha,
4330 IDC_AUDIT_COMPLETION);
4331 ha->flags.nic_core_reset_owner = 0;
4332 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
4333 "Reset_owner reset by 0x%x.\n",
4334 ha->portnum);
4335 goto exit;
4336 case QLA8XXX_DEV_COLD:
4337 if (ha->flags.nic_core_reset_owner)
4338 rval = qla83xx_device_bootstrap(base_vha);
4339 else {
4340 /* Wait for AEN to change device-state */
4341 qla83xx_idc_unlock(base_vha, 0);
4342 msleep(1000);
4343 qla83xx_idc_lock(base_vha, 0);
4344 }
4345 break;
4346 case QLA8XXX_DEV_INITIALIZING:
4347 /* Wait for AEN to change device-state */
4348 qla83xx_idc_unlock(base_vha, 0);
4349 msleep(1000);
4350 qla83xx_idc_lock(base_vha, 0);
4351 break;
4352 case QLA8XXX_DEV_NEED_RESET:
4353 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
4354 qla83xx_need_reset_handler(base_vha);
4355 else {
4356 /* Wait for AEN to change device-state */
4357 qla83xx_idc_unlock(base_vha, 0);
4358 msleep(1000);
4359 qla83xx_idc_lock(base_vha, 0);
4360 }
4361 /* reset timeout value after need reset handler */
4362 dev_init_timeout = jiffies +
4363 (ha->fcoe_dev_init_timeout * HZ);
4364 break;
4365 case QLA8XXX_DEV_NEED_QUIESCENT:
4366 /* XXX: DEBUG for now */
4367 qla83xx_idc_unlock(base_vha, 0);
4368 msleep(1000);
4369 qla83xx_idc_lock(base_vha, 0);
4370 break;
4371 case QLA8XXX_DEV_QUIESCENT:
4372 /* XXX: DEBUG for now */
4373 if (ha->flags.quiesce_owner)
4374 goto exit;
4375
4376 qla83xx_idc_unlock(base_vha, 0);
4377 msleep(1000);
4378 qla83xx_idc_lock(base_vha, 0);
4379 dev_init_timeout = jiffies +
4380 (ha->fcoe_dev_init_timeout * HZ);
4381 break;
4382 case QLA8XXX_DEV_FAILED:
4383 if (ha->flags.nic_core_reset_owner)
4384 qla83xx_idc_audit(base_vha,
4385 IDC_AUDIT_COMPLETION);
4386 ha->flags.nic_core_reset_owner = 0;
4387 __qla83xx_clear_drv_presence(base_vha);
4388 qla83xx_idc_unlock(base_vha, 0);
4389 qla8xxx_dev_failed_handler(base_vha);
4390 rval = QLA_FUNCTION_FAILED;
4391 qla83xx_idc_lock(base_vha, 0);
4392 goto exit;
4393 case QLA8XXX_BAD_VALUE:
4394 qla83xx_idc_unlock(base_vha, 0);
4395 msleep(1000);
4396 qla83xx_idc_lock(base_vha, 0);
4397 break;
4398 default:
4399 ql_log(ql_log_warn, base_vha, 0xb071,
4400 "Unknow Device State: %x.\n", dev_state);
4401 qla83xx_idc_unlock(base_vha, 0);
4402 qla8xxx_dev_failed_handler(base_vha);
4403 rval = QLA_FUNCTION_FAILED;
4404 qla83xx_idc_lock(base_vha, 0);
4405 goto exit;
4406 }
4407 }
4408
4409exit:
4410 return rval;
4411}
4412
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413/**************************************************************************
4414* qla2x00_do_dpc
4415* This kernel thread is a task that is schedule by the interrupt handler
4416* to perform the background processing for interrupts.
4417*
4418* Notes:
4419* This task always run in the context of a kernel thread. It
4420* is kick-off by the driver's detect code and starts up
4421* up one per adapter. It immediately goes to sleep and waits for
4422* some fibre event. When either the interrupt handler or
4423* the timer routine detects a event it will one of the task
4424* bits then wake us up.
4425**************************************************************************/
4426static int
4427qla2x00_do_dpc(void *data)
4428{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004429 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004430 scsi_qla_host_t *base_vha;
4431 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08004432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004433 ha = (struct qla_hw_data *)data;
4434 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 set_user_nice(current, -20);
4437
James Bottomley563585e2011-01-27 16:12:37 -05004438 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01004439 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004440 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
4441 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442
Christoph Hellwig39a11242006-02-14 18:46:22 +01004443 schedule();
4444 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004446 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
4447 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448
Andrew Vasquez85880802009-12-15 21:29:46 -08004449 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004450 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
4451 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004452 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08004453 }
4454
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 ha->dpc_active = 1;
4456
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004457 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
4458 "DPC handler waking up, dpc_flags=0x%lx.\n",
4459 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004462
Giridhar Malavalia9083012010-04-12 17:59:55 -07004463 if (IS_QLA82XX(ha)) {
4464 if (test_and_clear_bit(ISP_UNRECOVERABLE,
4465 &base_vha->dpc_flags)) {
4466 qla82xx_idc_lock(ha);
4467 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004468 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004469 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004470 ql_log(ql_log_info, base_vha, 0x4004,
4471 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004472 qla82xx_device_state_handler(base_vha);
4473 continue;
4474 }
4475
4476 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
4477 &base_vha->dpc_flags)) {
4478
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004479 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
4480 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004481 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
4482 &base_vha->dpc_flags))) {
4483 if (qla82xx_fcoe_ctx_reset(base_vha)) {
4484 /* FCoE-ctx reset failed.
4485 * Escalate to chip-reset
4486 */
4487 set_bit(ISP_ABORT_NEEDED,
4488 &base_vha->dpc_flags);
4489 }
4490 clear_bit(ABORT_ISP_ACTIVE,
4491 &base_vha->dpc_flags);
4492 }
4493
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004494 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
4495 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004496 }
4497 }
4498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004499 if (test_and_clear_bit(ISP_ABORT_NEEDED,
4500 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004502 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
4503 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004505 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506
Giridhar Malavalia9083012010-04-12 17:59:55 -07004507 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 /* failed. retry later */
4509 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004510 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004512 clear_bit(ABORT_ISP_ACTIVE,
4513 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08004514 }
4515
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004516 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
4517 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 }
4519
David Jefferya394aac2012-11-21 02:39:54 -05004520 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
4521 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004522 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07004523 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004524
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004525 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
4526 int ret;
4527 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
4528 if (ret != QLA_SUCCESS)
4529 ql_log(ql_log_warn, base_vha, 0x121,
4530 "Failed to enable receiving of RSCN "
4531 "requests: 0x%x.\n", ret);
4532 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
4533 }
4534
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004535 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004536 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
4537 "Quiescence mode scheduled.\n");
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004538 if (IS_QLA82XX(ha)) {
4539 qla82xx_device_state_handler(base_vha);
4540 clear_bit(ISP_QUIESCE_NEEDED,
4541 &base_vha->dpc_flags);
4542 if (!ha->flags.quiesce_owner) {
4543 qla2x00_perform_loop_resync(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004544
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004545 qla82xx_idc_lock(ha);
4546 qla82xx_clear_qsnt_ready(base_vha);
4547 qla82xx_idc_unlock(ha);
4548 }
4549 } else {
4550 clear_bit(ISP_QUIESCE_NEEDED,
4551 &base_vha->dpc_flags);
4552 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004553 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004554 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
4555 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004556 }
4557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004558 if (test_and_clear_bit(RESET_MARKER_NEEDED,
4559 &base_vha->dpc_flags) &&
4560 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004562 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
4563 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004564 qla2x00_rst_aen(base_vha);
4565 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004566 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
4567 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 }
4569
4570 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004571 if ((test_and_clear_bit(RELOGIN_NEEDED,
4572 &base_vha->dpc_flags)) &&
4573 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
4574 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004576 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
4577 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004578 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004579 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
4580 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 }
4582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004583 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
4584 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004586 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
4587 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588
4589 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004590 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004592 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004594 clear_bit(LOOP_RESYNC_ACTIVE,
4595 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 }
4597
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004598 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
4599 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 }
4601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004602 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
4603 atomic_read(&base_vha->loop_state) == LOOP_READY) {
4604 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
4605 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07004606 }
4607
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004609 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004611 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
4612 &base_vha->dpc_flags))
4613 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08004614
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004615 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004616
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08004618end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05004619 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05004621 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004623 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
4624 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625
4626 /*
4627 * Make sure that nobody tries to wake us up again.
4628 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 ha->dpc_active = 0;
4630
Andrew Vasquezac280b62009-08-20 11:06:05 -07004631 /* Cleanup any residual CTX SRBs. */
4632 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
4633
Christoph Hellwig39a11242006-02-14 18:46:22 +01004634 return 0;
4635}
4636
4637void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004638qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01004639{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004640 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07004641 struct task_struct *t = ha->dpc_thread;
4642
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004643 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07004644 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645}
4646
4647/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648* qla2x00_rst_aen
4649* Processes asynchronous reset.
4650*
4651* Input:
4652* ha = adapter block pointer.
4653*/
4654static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004655qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004657 if (vha->flags.online && !vha->flags.reset_active &&
4658 !atomic_read(&vha->loop_down_timer) &&
4659 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004661 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
4663 /*
4664 * Issue marker command only when we are going to start
4665 * the I/O.
4666 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004667 vha->marker_needed = 1;
4668 } while (!atomic_read(&vha->loop_down_timer) &&
4669 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 }
4671}
4672
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673/**************************************************************************
4674* qla2x00_timer
4675*
4676* Description:
4677* One second timer
4678*
4679* Context: Interrupt
4680***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004681void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004682qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 int start_dpc = 0;
4686 int index;
4687 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08004688 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004689 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004690 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08004691
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004692 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004693 ql_dbg(ql_dbg_timer, vha, 0x6000,
4694 "EEH = %d, restarting timer.\n",
4695 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004696 qla2x00_restart_timer(vha, WATCH_INTERVAL);
4697 return;
4698 }
4699
Andrew Vasquez85880802009-12-15 21:29:46 -08004700 /* Hardware read to raise pending EEH errors during mailbox waits. */
4701 if (!pci_channel_offline(ha->pdev))
4702 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07004704 /* Make sure qla82xx_watchdog is run only for physical port */
4705 if (!vha->vp_idx && IS_QLA82XX(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004706 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
4707 start_dpc++;
4708 qla82xx_watchdog(vha);
4709 }
4710
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004712 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004713 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
4714 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004715 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004717 if (atomic_read(&vha->loop_down_timer) ==
4718 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004720 ql_log(ql_log_info, vha, 0x6008,
4721 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004723 if (!IS_QLA2100(ha) && vha->link_down_timeout)
4724 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004726 /*
4727 * Schedule an ISP abort to return any FCP2-device
4728 * commands.
4729 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004730 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004731 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004732 spin_lock_irqsave(&ha->hardware_lock,
4733 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004734 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004735 for (index = 1;
4736 index < MAX_OUTSTANDING_COMMANDS;
4737 index++) {
4738 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05004739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004740 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004741 if (!sp)
4742 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08004743 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07004744 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004745 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004746 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004747 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004749 if (IS_QLA82XX(ha))
4750 set_bit(FCOE_CTX_RESET_NEEDED,
4751 &vha->dpc_flags);
4752 else
4753 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004754 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004755 break;
4756 }
4757 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004758 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 start_dpc++;
4761 }
4762
4763 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004764 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004765 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004766 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 "Loop down - aborting ISP.\n");
4768
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004769 if (IS_QLA82XX(ha))
4770 set_bit(FCOE_CTX_RESET_NEEDED,
4771 &vha->dpc_flags);
4772 else
4773 set_bit(ISP_ABORT_NEEDED,
4774 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 }
4776 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004777 ql_dbg(ql_dbg_timer, vha, 0x600a,
4778 "Loop down - seconds remaining %d.\n",
4779 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 }
4781
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07004782 /* Check if beacon LED needs to be blinked for physical host only */
4783 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07004784 /* There is no beacon_blink function for ISP82xx */
4785 if (!IS_QLA82XX(ha)) {
4786 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
4787 start_dpc++;
4788 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08004789 }
4790
Andrew Vasquez550bf572008-04-24 15:21:23 -07004791 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004792 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07004793 start_dpc++;
4794
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004796 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
4797 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
4798 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004800 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
4801 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07004802 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
4803 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004804 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004805 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
4806 ql_dbg(ql_dbg_timer, vha, 0x600b,
4807 "isp_abort_needed=%d loop_resync_needed=%d "
4808 "fcport_update_needed=%d start_dpc=%d "
4809 "reset_marker_needed=%d",
4810 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
4811 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
4812 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
4813 start_dpc,
4814 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
4815 ql_dbg(ql_dbg_timer, vha, 0x600c,
4816 "beacon_blink_needed=%d isp_unrecoverable=%d "
4817 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
4818 "relogin_needed=%d.\n",
4819 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
4820 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
4821 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
4822 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
4823 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004824 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004827 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828}
4829
Andrew Vasquez54333832005-11-09 15:49:04 -08004830/* Firmware interface routines. */
4831
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004832#define FW_BLOBS 10
Andrew Vasquez54333832005-11-09 15:49:04 -08004833#define FW_ISP21XX 0
4834#define FW_ISP22XX 1
4835#define FW_ISP2300 2
4836#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004837#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004838#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004839#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07004840#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004841#define FW_ISP2031 8
4842#define FW_ISP8031 9
Andrew Vasquez54333832005-11-09 15:49:04 -08004843
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004844#define FW_FILE_ISP21XX "ql2100_fw.bin"
4845#define FW_FILE_ISP22XX "ql2200_fw.bin"
4846#define FW_FILE_ISP2300 "ql2300_fw.bin"
4847#define FW_FILE_ISP2322 "ql2322_fw.bin"
4848#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004849#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004850#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07004851#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004852#define FW_FILE_ISP2031 "ql2600_fw.bin"
4853#define FW_FILE_ISP8031 "ql8300_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004854
Daniel Walkere1e82b62008-05-12 22:21:10 -07004855static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004856
4857static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004858 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
4859 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
4860 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
4861 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
4862 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004863 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004864 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004865 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004866 { .name = FW_FILE_ISP2031, },
4867 { .name = FW_FILE_ISP8031, },
Andrew Vasquez54333832005-11-09 15:49:04 -08004868};
4869
4870struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004871qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08004872{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004873 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08004874 struct fw_blob *blob;
4875
Andrew Vasquez54333832005-11-09 15:49:04 -08004876 if (IS_QLA2100(ha)) {
4877 blob = &qla_fw_blobs[FW_ISP21XX];
4878 } else if (IS_QLA2200(ha)) {
4879 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004880 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004881 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004882 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004883 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004884 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004885 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004886 } else if (IS_QLA25XX(ha)) {
4887 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004888 } else if (IS_QLA81XX(ha)) {
4889 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07004890 } else if (IS_QLA82XX(ha)) {
4891 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004892 } else if (IS_QLA2031(ha)) {
4893 blob = &qla_fw_blobs[FW_ISP2031];
4894 } else if (IS_QLA8031(ha)) {
4895 blob = &qla_fw_blobs[FW_ISP8031];
Dan Carpenter8a655222012-02-21 10:29:40 +03004896 } else {
4897 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08004898 }
4899
Daniel Walkere1e82b62008-05-12 22:21:10 -07004900 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004901 if (blob->fw)
4902 goto out;
4903
4904 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004905 ql_log(ql_log_warn, vha, 0x0063,
4906 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08004907 blob->fw = NULL;
4908 blob = NULL;
4909 goto out;
4910 }
4911
4912out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07004913 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004914 return blob;
4915}
4916
4917static void
4918qla2x00_release_firmware(void)
4919{
4920 int idx;
4921
Daniel Walkere1e82b62008-05-12 22:21:10 -07004922 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004923 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02004924 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07004925 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004926}
4927
Seokmann Ju14e660e2007-09-20 14:07:36 -07004928static pci_ers_result_t
4929qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4930{
Andrew Vasquez85880802009-12-15 21:29:46 -08004931 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
4932 struct qla_hw_data *ha = vha->hw;
4933
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004934 ql_dbg(ql_dbg_aer, vha, 0x9000,
4935 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07004936
Seokmann Ju14e660e2007-09-20 14:07:36 -07004937 switch (state) {
4938 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08004939 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004940 return PCI_ERS_RESULT_CAN_RECOVER;
4941 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08004942 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004943 /* For ISP82XX complete any pending mailbox cmd */
4944 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004945 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08004946 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
4947 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004948 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004949 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004950 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004951 /* Return back all IOs */
4952 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004953 return PCI_ERS_RESULT_NEED_RESET;
4954 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08004955 ha->flags.pci_channel_io_perm_failure = 1;
4956 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004957 return PCI_ERS_RESULT_DISCONNECT;
4958 }
4959 return PCI_ERS_RESULT_NEED_RESET;
4960}
4961
4962static pci_ers_result_t
4963qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4964{
4965 int risc_paused = 0;
4966 uint32_t stat;
4967 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004968 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4969 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004970 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4971 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4972
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07004973 if (IS_QLA82XX(ha))
4974 return PCI_ERS_RESULT_RECOVERED;
4975
Seokmann Ju14e660e2007-09-20 14:07:36 -07004976 spin_lock_irqsave(&ha->hardware_lock, flags);
4977 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4978 stat = RD_REG_DWORD(&reg->hccr);
4979 if (stat & HCCR_RISC_PAUSE)
4980 risc_paused = 1;
4981 } else if (IS_QLA23XX(ha)) {
4982 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
4983 if (stat & HSR_RISC_PAUSED)
4984 risc_paused = 1;
4985 } else if (IS_FWI2_CAPABLE(ha)) {
4986 stat = RD_REG_DWORD(&reg24->host_status);
4987 if (stat & HSRX_RISC_PAUSED)
4988 risc_paused = 1;
4989 }
4990 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4991
4992 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004993 ql_log(ql_log_info, base_vha, 0x9003,
4994 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004995 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004996
4997 return PCI_ERS_RESULT_NEED_RESET;
4998 } else
4999 return PCI_ERS_RESULT_RECOVERED;
5000}
5001
Saurav Kashyapfa492632012-11-21 02:40:29 -05005002static uint32_t
5003qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005004{
5005 uint32_t rval = QLA_FUNCTION_FAILED;
5006 uint32_t drv_active = 0;
5007 struct qla_hw_data *ha = base_vha->hw;
5008 int fn;
5009 struct pci_dev *other_pdev = NULL;
5010
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005011 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
5012 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005013
5014 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5015
5016 if (base_vha->flags.online) {
5017 /* Abort all outstanding commands,
5018 * so as to be requeued later */
5019 qla2x00_abort_isp_cleanup(base_vha);
5020 }
5021
5022
5023 fn = PCI_FUNC(ha->pdev->devfn);
5024 while (fn > 0) {
5025 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005026 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
5027 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005028 other_pdev =
5029 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5030 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5031 fn));
5032
5033 if (!other_pdev)
5034 continue;
5035 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005036 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
5037 "Found PCI func available and enable at 0x%x.\n",
5038 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005039 pci_dev_put(other_pdev);
5040 break;
5041 }
5042 pci_dev_put(other_pdev);
5043 }
5044
5045 if (!fn) {
5046 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005047 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
5048 "This devfn is reset owner = 0x%x.\n",
5049 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005050 qla82xx_idc_lock(ha);
5051
5052 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005053 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005054
5055 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5056 QLA82XX_IDC_VERSION);
5057
5058 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005059 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
5060 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005061
5062 qla82xx_idc_unlock(ha);
5063 /* Reset if device is not already reset
5064 * drv_active would be 0 if a reset has already been done
5065 */
5066 if (drv_active)
5067 rval = qla82xx_start_firmware(base_vha);
5068 else
5069 rval = QLA_SUCCESS;
5070 qla82xx_idc_lock(ha);
5071
5072 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005073 ql_log(ql_log_info, base_vha, 0x900b,
5074 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005075 qla82xx_clear_drv_active(ha);
5076 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005077 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005078 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005079 ql_log(ql_log_info, base_vha, 0x900c,
5080 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005081 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005082 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005083 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08005084 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005085 rval = qla82xx_restart_isp(base_vha);
5086 qla82xx_idc_lock(ha);
5087 /* Clear driver state register */
5088 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5089 qla82xx_set_drv_active(base_vha);
5090 }
5091 qla82xx_idc_unlock(ha);
5092 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005093 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
5094 "This devfn is not reset owner = 0x%x.\n",
5095 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005096 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005097 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005098 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005099 rval = qla82xx_restart_isp(base_vha);
5100 qla82xx_idc_lock(ha);
5101 qla82xx_set_drv_active(base_vha);
5102 qla82xx_idc_unlock(ha);
5103 }
5104 }
5105 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
5106
5107 return rval;
5108}
5109
Seokmann Ju14e660e2007-09-20 14:07:36 -07005110static pci_ers_result_t
5111qla2xxx_pci_slot_reset(struct pci_dev *pdev)
5112{
5113 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005114 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5115 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005116 struct rsp_que *rsp;
5117 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005118
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005119 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
5120 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005121
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005122 /* Workaround: qla2xxx driver which access hardware earlier
5123 * needs error state to be pci_channel_io_online.
5124 * Otherwise mailbox command timesout.
5125 */
5126 pdev->error_state = pci_channel_io_normal;
5127
5128 pci_restore_state(pdev);
5129
Richard Lary8c1496b2010-02-18 10:07:29 -08005130 /* pci_restore_state() clears the saved_state flag of the device
5131 * save restored state which resets saved_state flag
5132 */
5133 pci_save_state(pdev);
5134
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11005135 if (ha->mem_only)
5136 rc = pci_enable_device_mem(pdev);
5137 else
5138 rc = pci_enable_device(pdev);
5139
5140 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005141 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005142 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005143 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005144 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005145
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005146 rsp = ha->rsp_q_map[0];
5147 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005148 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005150 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005151 goto exit_slot_reset;
5152
5153 if (IS_QLA82XX(ha)) {
5154 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
5155 ret = PCI_ERS_RESULT_RECOVERED;
5156 goto exit_slot_reset;
5157 } else
5158 goto exit_slot_reset;
5159 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07005160
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005161 while (ha->flags.mbox_busy && retries--)
5162 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08005163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005164 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005165 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07005166 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005167 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005168
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08005169
Lalit Chandivadea5b36322010-09-03 15:20:50 -07005170exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005171 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
5172 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08005173
Seokmann Ju14e660e2007-09-20 14:07:36 -07005174 return ret;
5175}
5176
5177static void
5178qla2xxx_pci_resume(struct pci_dev *pdev)
5179{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005180 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
5181 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005182 int ret;
5183
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005184 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
5185 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08005186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005187 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07005188 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005189 ql_log(ql_log_fatal, base_vha, 0x9002,
5190 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07005191 }
Andrew Vasquez85880802009-12-15 21:29:46 -08005192
Lalit Chandivade3e46f032010-05-04 15:01:23 -07005193 pci_cleanup_aer_uncorrect_error_status(pdev);
5194
Andrew Vasquez85880802009-12-15 21:29:46 -08005195 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07005196}
5197
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07005198static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07005199 .error_detected = qla2xxx_pci_error_detected,
5200 .mmio_enabled = qla2xxx_pci_mmio_enabled,
5201 .slot_reset = qla2xxx_pci_slot_reset,
5202 .resume = qla2xxx_pci_resume,
5203};
5204
Andrew Vasquez54333832005-11-09 15:49:04 -08005205static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005206 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
5207 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
5208 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
5209 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
5210 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
5211 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
5212 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
5213 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
5214 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005215 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07005216 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
5217 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07005218 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005219 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005220 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07005221 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04005222 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Andrew Vasquez54333832005-11-09 15:49:04 -08005223 { 0 },
5224};
5225MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
5226
Andrew Vasquezfca29702005-07-06 10:31:47 -07005227static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07005228 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06005229 .driver = {
5230 .owner = THIS_MODULE,
5231 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07005232 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005233 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08005234 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07005235 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07005236 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07005237};
5238
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005239static struct file_operations apidev_fops = {
5240 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02005241 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005242};
5243
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244/**
5245 * qla2x00_module_init - Module initialization.
5246 **/
5247static int __init
5248qla2x00_module_init(void)
5249{
Andrew Vasquezfca29702005-07-06 10:31:47 -07005250 int ret = 0;
5251
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005253 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005254 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005256 ql_log(ql_log_fatal, NULL, 0x0001,
5257 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 return -ENOMEM;
5259 }
5260
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005261 /* Initialize target kmem_cache and mem_pools */
5262 ret = qlt_init();
5263 if (ret < 0) {
5264 kmem_cache_destroy(srb_cachep);
5265 return ret;
5266 } else if (ret > 0) {
5267 /*
5268 * If initiator mode is explictly disabled by qlt_init(),
5269 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
5270 * performing scsi_scan_target() during LOOP UP event.
5271 */
5272 qla2xxx_transport_functions.disable_target_scan = 1;
5273 qla2xxx_transport_vport_functions.disable_target_scan = 1;
5274 }
5275
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 /* Derive version string. */
5277 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005278 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07005279 strcat(qla2x00_version_str, "-debug");
5280
Andrew Vasquez1c97a122005-04-21 16:13:36 -04005281 qla2xxx_transport_template =
5282 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005283 if (!qla2xxx_transport_template) {
5284 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005285 ql_log(ql_log_fatal, NULL, 0x0002,
5286 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005287 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005289 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005290
5291 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
5292 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005293 ql_log(ql_log_fatal, NULL, 0x0003,
5294 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005295 }
5296
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005297 qla2xxx_transport_vport_template =
5298 fc_attach_transport(&qla2xxx_transport_vport_functions);
5299 if (!qla2xxx_transport_vport_template) {
5300 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005301 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005302 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005303 ql_log(ql_log_fatal, NULL, 0x0004,
5304 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005305 return -ENODEV;
5306 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005307 ql_log(ql_log_info, NULL, 0x0005,
5308 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07005309 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005310 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005311 if (ret) {
5312 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005313 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07005314 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005315 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005316 ql_log(ql_log_fatal, NULL, 0x0006,
5317 "pci_register_driver failed...ret=%d Failing load!.\n",
5318 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07005319 }
5320 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321}
5322
5323/**
5324 * qla2x00_module_exit - Module cleanup.
5325 **/
5326static void __exit
5327qla2x00_module_exit(void)
5328{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07005329 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07005330 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08005331 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04005332 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005333 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07005334 if (ctx_cachep)
5335 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005337 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338}
5339
5340module_init(qla2x00_module_init);
5341module_exit(qla2x00_module_exit);
5342
5343MODULE_AUTHOR("QLogic Corporation");
5344MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
5345MODULE_LICENSE("GPL");
5346MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07005347MODULE_FIRMWARE(FW_FILE_ISP21XX);
5348MODULE_FIRMWARE(FW_FILE_ISP22XX);
5349MODULE_FIRMWARE(FW_FILE_ISP2300);
5350MODULE_FIRMWARE(FW_FILE_ISP2322);
5351MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08005352MODULE_FIRMWARE(FW_FILE_ISP25XX);