blob: d3052622e77abe203f53b81710688b20e7eb0894 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040044int ql2xenableclass2;
45module_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"
92 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080093 "\t\t0x1e400000 - Preferred value for capturing essential "
94 "debug information (equivalent to old "
95 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070096 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -070097
Giridhar Malavalia9083012010-04-12 17:59:55 -070098int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080099module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700100MODULE_PARM_DESC(ql2xshiftctondsd,
101 "Set to control shifting of command type processing "
102 "based on total number of SG elements.");
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static void qla2x00_free_device(scsi_qla_host_t *);
105
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700106int ql2xfdmienable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800107module_param(ql2xfdmienable, int, S_IRUGO);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700108MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100109 "Enables FDMI registrations. "
110 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700111
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700112#define MAX_Q_DEPTH 32
113static int ql2xmaxqdepth = MAX_Q_DEPTH;
114module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
115MODULE_PARM_DESC(ql2xmaxqdepth,
116 "Maximum queue depth to report for target devices.");
117
Arun Easibad75002010-05-04 15:01:30 -0700118/* Do not change the value of this after module load */
Arun Easi8cb20492011-08-16 11:29:22 -0700119int ql2xenabledif = 0;
Arun Easibad75002010-05-04 15:01:30 -0700120module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
121MODULE_PARM_DESC(ql2xenabledif,
122 " Enable T10-CRC-DIF "
Arun Easi8cb20492011-08-16 11:29:22 -0700123 " Default is 0 - No DIF Support. 1 - Enable it"
124 ", 2 - Enable DIF for all types, except Type 0.");
Arun Easibad75002010-05-04 15:01:30 -0700125
Arun Easi8cb20492011-08-16 11:29:22 -0700126int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700127module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
128MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700129 " Enable T10-CRC-DIF Error isolation by HBA:\n"
130 " Default is 1.\n"
131 " 0 -- Error isolation disabled\n"
132 " 1 -- Error isolation enabled only for DIX Type 0\n"
133 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700134
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700135int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800136module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700137MODULE_PARM_DESC(ql2xiidmaenable,
138 "Enables iIDMA settings "
139 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
140
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800141int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800142module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800143MODULE_PARM_DESC(ql2xmaxqueues,
144 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700145 "Default is 1 for single queue. Set it to number "
146 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700147
148int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800149module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700150MODULE_PARM_DESC(ql2xmultique_tag,
151 "Enables CPU affinity settings for the driver "
152 "Default is 0 for no affinity of request and response IO. "
153 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700154
155int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700156module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700157MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700158 "Option to specify location from which to load ISP firmware:.\n"
159 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700160 " interface.\n"
161 " 1 -- load firmware from flash.\n"
162 " 0 -- use default semantics.\n");
163
Andrew Vasquezae97c912010-02-18 10:07:28 -0800164int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800165module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800166MODULE_PARM_DESC(ql2xetsenable,
167 "Enables firmware ETS burst."
168 "Default is 0 - skip ETS enablement.");
169
Giridhar Malavali69078692010-05-28 15:08:28 -0700170int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700171module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700172MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700173 "Option to specify scheme for request queue posting.\n"
174 " 0 -- Regular doorbell.\n"
175 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700176
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700177int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800178module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700179MODULE_PARM_DESC(ql2xtargetreset,
180 "Enable target reset."
181 "Default is 1 - use hw defaults.");
182
Chad Dupuis4da26e12010-10-15 11:27:40 -0700183int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800184module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700185MODULE_PARM_DESC(ql2xgffidenable,
186 "Enables GFF_ID checks of port type. "
187 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700189int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800190module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700191MODULE_PARM_DESC(ql2xasynctmfenable,
192 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
193 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700194
195int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700196module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700197MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700198 "Option to specify reset behaviour.\n"
199 " 0 (Default) -- Reset on failure.\n"
200 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700201
Andrew Vasquez82515922011-05-10 11:30:13 -0700202uint ql2xmaxlun = MAX_LUNS;
203module_param(ql2xmaxlun, uint, S_IRUGO);
204MODULE_PARM_DESC(ql2xmaxlun,
205 "Defines the maximum LU number to register with the SCSI "
206 "midlayer. Default is 65535.");
207
Giridhar Malavali08de2842011-08-16 11:31:44 -0700208int ql2xmdcapmask = 0x1F;
209module_param(ql2xmdcapmask, int, S_IRUGO);
210MODULE_PARM_DESC(ql2xmdcapmask,
211 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800212 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700213
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800214int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700215module_param(ql2xmdenable, int, S_IRUGO);
216MODULE_PARM_DESC(ql2xmdenable,
217 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800218 "0 - MiniDump disabled. "
219 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700222 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 */
224static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500225static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800226static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
227static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500228static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500229static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static int qla2xxx_eh_abort(struct scsi_cmnd *);
231static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700232static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
234static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Mike Christiee881a172009-10-15 17:46:39 -0700236static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700237static int qla2x00_change_queue_type(struct scsi_device *, int);
238
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700239struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700241 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700242 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700243
244 .eh_abort_handler = qla2xxx_eh_abort,
245 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700246 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700247 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
248 .eh_host_reset_handler = qla2xxx_eh_host_reset,
249
250 .slave_configure = qla2xxx_slave_configure,
251
252 .slave_alloc = qla2xxx_slave_alloc,
253 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700254 .scan_finished = qla2xxx_scan_finished,
255 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700256 .change_queue_depth = qla2x00_change_queue_depth,
257 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700258 .this_id = -1,
259 .cmd_per_lun = 3,
260 .use_clustering = ENABLE_CLUSTERING,
261 .sg_tablesize = SG_ALL,
262
263 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700264 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400265
266 .supported_mode = MODE_INITIATOR,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700267};
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700270struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272/* TODO Convert to inlines
273 *
274 * Timer routines
275 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700277__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800278qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800280 init_timer(&vha->timer);
281 vha->timer.expires = jiffies + interval * HZ;
282 vha->timer.data = (unsigned long)vha;
283 vha->timer.function = (void (*)(unsigned long))func;
284 add_timer(&vha->timer);
285 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800289qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700291 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700292 if (vha->device_flags & DFLG_DEV_FAILED) {
293 ql_dbg(ql_dbg_timer, vha, 0x600d,
294 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700295 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700296 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700297
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800298 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Adrian Bunka824ebb2008-01-17 09:02:15 -0800301static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800302qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800304 del_timer_sync(&vha->timer);
305 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308static int qla2x00_do_dpc(void *data);
309
310static void qla2x00_rst_aen(scsi_qla_host_t *);
311
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800312static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
313 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700314static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800315static void qla2x00_mem_free(struct qla_hw_data *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/* -------------------------------------------------------------------------- */
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400318static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
319 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800320{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700321 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700322 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800323 GFP_KERNEL);
324 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700325 ql_log(ql_log_fatal, vha, 0x003b,
326 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800327 goto fail_req_map;
328 }
329
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700330 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800331 GFP_KERNEL);
332 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700333 ql_log(ql_log_fatal, vha, 0x003c,
334 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800335 goto fail_rsp_map;
336 }
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400337 /*
338 * Make sure we record at least the request and response queue zero in
339 * case we need to free them if part of the probe fails.
340 */
341 ha->rsp_q_map[0] = rsp;
342 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800343 set_bit(0, ha->rsp_qid_map);
344 set_bit(0, ha->req_qid_map);
345 return 1;
346
347fail_rsp_map:
348 kfree(ha->req_q_map);
349 ha->req_q_map = NULL;
350fail_req_map:
351 return -ENOMEM;
352}
353
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700354static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800355{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800356 if (req && req->ring)
357 dma_free_coherent(&ha->pdev->dev,
358 (req->length + 1) * sizeof(request_t),
359 req->ring, req->dma);
360
361 kfree(req);
362 req = NULL;
363}
364
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700365static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
366{
367 if (rsp && rsp->ring)
368 dma_free_coherent(&ha->pdev->dev,
369 (rsp->length + 1) * sizeof(response_t),
370 rsp->ring, rsp->dma);
371
372 kfree(rsp);
373 rsp = NULL;
374}
375
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800376static void qla2x00_free_queues(struct qla_hw_data *ha)
377{
378 struct req_que *req;
379 struct rsp_que *rsp;
380 int cnt;
381
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700382 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800383 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700384 qla2x00_free_req_que(ha, req);
385 }
386 kfree(ha->req_q_map);
387 ha->req_q_map = NULL;
388
389 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
390 rsp = ha->rsp_q_map[cnt];
391 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800392 }
393 kfree(ha->rsp_q_map);
394 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800395}
396
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700397static int qla25xx_setup_mode(struct scsi_qla_host *vha)
398{
399 uint16_t options = 0;
400 int ques, req, ret;
401 struct qla_hw_data *ha = vha->hw;
402
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700403 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700404 ql_log(ql_log_warn, vha, 0x00d8,
405 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700406 goto fail;
407 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700408 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700409 /* create a request queue for IO */
410 options |= BIT_7;
411 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
412 QLA_DEFAULT_QUE_QOS);
413 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700414 ql_log(ql_log_warn, vha, 0x00e0,
415 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700416 goto fail;
417 }
Tejun Heo278274d2011-02-01 11:42:42 +0100418 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700419 vha->req = ha->req_q_map[req];
420 options |= BIT_1;
421 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
422 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
423 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700424 ql_log(ql_log_warn, vha, 0x00e8,
425 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700426 goto fail2;
427 }
428 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700429 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700430 ql_dbg(ql_dbg_multiq, vha, 0xc007,
431 "CPU affinity mode enalbed, "
432 "no. of response queues:%d no. of request queues:%d.\n",
433 ha->max_rsp_queues, ha->max_req_queues);
434 ql_dbg(ql_dbg_init, vha, 0x00e9,
435 "CPU affinity mode enalbed, "
436 "no. of response queues:%d no. of request queues:%d.\n",
437 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700438 }
439 return 0;
440fail2:
441 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700442 destroy_workqueue(ha->wq);
443 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800444 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700445fail:
446 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700447 kfree(ha->req_q_map);
448 kfree(ha->rsp_q_map);
449 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700450 return 1;
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800454qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800456 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 static char *pci_bus_modes[] = {
458 "33", "66", "100", "133",
459 };
460 uint16_t pci_bus;
461
462 strcpy(str, "PCI");
463 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
464 if (pci_bus) {
465 strcat(str, "-X (");
466 strcat(str, pci_bus_modes[pci_bus]);
467 } else {
468 pci_bus = (ha->pci_attr & BIT_8) >> 8;
469 strcat(str, " (");
470 strcat(str, pci_bus_modes[pci_bus]);
471 }
472 strcat(str, " MHz)");
473
474 return (str);
475}
476
Andrew Vasquezfca29702005-07-06 10:31:47 -0700477static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800478qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700479{
480 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800481 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700482 uint32_t pci_bus;
483 int pcie_reg;
484
Jon Masone67f1322012-07-10 14:57:56 -0700485 pcie_reg = pci_pcie_cap(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700486 if (pcie_reg) {
487 char lwstr[6];
488 uint16_t pcie_lstat, lspeed, lwidth;
489
Jon Masone67f1322012-07-10 14:57:56 -0700490 pcie_reg += PCI_EXP_LNKCAP;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700491 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
492 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
493 lwidth = (pcie_lstat &
494 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
495
496 strcpy(str, "PCIe (");
497 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700498 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700499 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700500 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700501 else
502 strcat(str, "<unknown> ");
503 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
504 strcat(str, lwstr);
505
506 return str;
507 }
508
509 strcpy(str, "PCI");
510 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
511 if (pci_bus == 0 || pci_bus == 8) {
512 strcat(str, " (");
513 strcat(str, pci_bus_modes[pci_bus >> 3]);
514 } else {
515 strcat(str, "-X ");
516 if (pci_bus & BIT_2)
517 strcat(str, "Mode 2");
518 else
519 strcat(str, "Mode 1");
520 strcat(str, " (");
521 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
522 }
523 strcat(str, " MHz)");
524
525 return str;
526}
527
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800528static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
531 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800532 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
535 ha->fw_minor_version,
536 ha->fw_subminor_version);
537
538 if (ha->fw_attributes & BIT_9) {
539 strcat(str, "FLX");
540 return (str);
541 }
542
543 switch (ha->fw_attributes & 0xFF) {
544 case 0x7:
545 strcat(str, "EF");
546 break;
547 case 0x17:
548 strcat(str, "TP");
549 break;
550 case 0x37:
551 strcat(str, "IP");
552 break;
553 case 0x77:
554 strcat(str, "VI");
555 break;
556 default:
557 sprintf(un_str, "(%x)", ha->fw_attributes);
558 strcat(str, un_str);
559 break;
560 }
561 if (ha->fw_attributes & 0x100)
562 strcat(str, "X");
563
564 return (str);
565}
566
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800567static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800568qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700569{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800570 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700571
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800572 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
573 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700574 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700575}
576
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800577void
578qla2x00_sp_free_dma(void *vha, void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700579{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800580 srb_t *sp = (srb_t *)ptr;
581 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
582 struct qla_hw_data *ha = sp->fcport->vha->hw;
583 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700584
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800585 if (sp->flags & SRB_DMA_VALID) {
586 scsi_dma_unmap(cmd);
587 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700588 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700589
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800590 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
591 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
592 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
593 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
594 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700595
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800596 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
597 /* List assured to be having elements */
598 qla2x00_clean_dsd_pool(ha, sp);
599 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
600 }
601
602 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
603 dma_pool_free(ha->dl_dma_pool, ctx,
604 ((struct crc_context *)ctx)->crc_ctx_dma);
605 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
606 }
607
608 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
609 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
610
611 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
612 ctx1->fcp_cmnd_dma);
613 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
614 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
615 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
616 mempool_free(ctx1, ha->ctx_mempool);
617 ctx1 = NULL;
618 }
619
620 CMD_SP(cmd) = NULL;
621 mempool_free(sp, ha->srb_mempool);
622}
623
624static void
625qla2x00_sp_compl(void *data, void *ptr, int res)
626{
627 struct qla_hw_data *ha = (struct qla_hw_data *)data;
628 srb_t *sp = (srb_t *)ptr;
629 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
630
631 cmd->result = res;
632
633 if (atomic_read(&sp->ref_count) == 0) {
634 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
635 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
636 sp, GET_CMD_SP(sp));
637 if (ql2xextended_error_logging & ql_dbg_io)
638 BUG();
639 return;
640 }
641 if (!atomic_dec_and_test(&sp->ref_count))
642 return;
643
644 qla2x00_sp_free_dma(ha, sp);
645 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700646}
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800649qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700650{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700651 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700652 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400653 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800654 struct qla_hw_data *ha = vha->hw;
655 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700656 srb_t *sp;
657 int rval;
658
Andrew Vasquez85880802009-12-15 21:29:46 -0800659 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700660 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400661 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700662 "PCI Channel IO permanent failure, exiting "
663 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700664 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700665 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400666 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700667 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800668 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700669 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700670 goto qc24_fail_command;
671 }
672
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400673 rval = fc_remote_port_chkready(rport);
674 if (rval) {
675 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400676 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700677 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
678 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700679 goto qc24_fail_command;
680 }
681
Arun Easibad75002010-05-04 15:01:30 -0700682 if (!vha->flags.difdix_supported &&
683 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700684 ql_dbg(ql_dbg_io, vha, 0x3004,
685 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
686 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700687 cmd->result = DID_NO_CONNECT << 16;
688 goto qc24_fail_command;
689 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800690
691 if (!fcport) {
692 cmd->result = DID_NO_CONNECT << 16;
693 goto qc24_fail_command;
694 }
695
Andrew Vasquezfca29702005-07-06 10:31:47 -0700696 if (atomic_read(&fcport->state) != FCS_ONLINE) {
697 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700698 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700699 ql_dbg(ql_dbg_io, vha, 0x3005,
700 "Returning DNC, fcport_state=%d loop_state=%d.\n",
701 atomic_read(&fcport->state),
702 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700703 cmd->result = DID_NO_CONNECT << 16;
704 goto qc24_fail_command;
705 }
Mike Christie7b594132008-08-17 15:24:40 -0500706 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700707 }
708
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800709 sp = qla2x00_get_sp(base_vha, fcport, GFP_ATOMIC);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700710 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800711 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700712
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800713 sp->u.scmd.cmd = cmd;
714 sp->type = SRB_SCSI_CMD;
715 atomic_set(&sp->ref_count, 1);
716 CMD_SP(cmd) = (void *)sp;
717 sp->free = qla2x00_sp_free_dma;
718 sp->done = qla2x00_sp_compl;
719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800720 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700721 if (rval != QLA_SUCCESS) {
722 ql_dbg(ql_dbg_io, vha, 0x3013,
723 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700724 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700725 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700726
Andrew Vasquezfca29702005-07-06 10:31:47 -0700727 return 0;
728
729qc24_host_busy_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800730 qla2x00_sp_free_dma(ha, sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700731
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800732qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700733 return SCSI_MLQUEUE_HOST_BUSY;
734
Mike Christie7b594132008-08-17 15:24:40 -0500735qc24_target_busy:
736 return SCSI_MLQUEUE_TARGET_BUSY;
737
Andrew Vasquezfca29702005-07-06 10:31:47 -0700738qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800739 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700740
741 return 0;
742}
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*
745 * qla2x00_eh_wait_on_command
746 * Waits for the command to be returned by the Firmware for some
747 * max time.
748 *
749 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 *
752 * Return:
753 * Not Found : 0
754 * Found : 1
755 */
756static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800757qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700759#define ABORT_POLLING_PERIOD 1000
760#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500761 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800762 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
763 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500764 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Andrew Vasquez85880802009-12-15 21:29:46 -0800766 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700767 ql_dbg(ql_dbg_taskm, vha, 0x8005,
768 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800769 return ret;
770 }
771
Lalit Chandivaded9704322009-08-25 11:36:18 -0700772 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700773 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500774 }
775 if (CMD_SP(cmd))
776 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
f4f051e2005-04-17 15:02:26 -0500778 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
781/*
782 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700783 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 * <= MAX_RETRIES_OF_ISP_ABORT or
785 * finally HBA is disabled ie marked offline
786 *
787 * Input:
788 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700789 *
790 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 * Does context switching-Release SPIN_LOCK
792 * (if any) before calling this routine.
793 *
794 * Return:
795 * Success (Adapter is online) : 0
796 * Failed (Adapter is offline/disabled) : 1
797 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800798int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700801 int return_status;
802 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800803 struct qla_hw_data *ha = vha->hw;
804 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700806 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800807 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
808 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
809 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
810 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 msleep(1000);
813 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800814 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700815 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 else
817 return_status = QLA_FUNCTION_FAILED;
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return (return_status);
820}
821
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700822/*
823 * qla2x00_wait_for_reset_ready
824 * Wait till the HBA is online after going through
825 * <= MAX_RETRIES_OF_ISP_ABORT or
826 * finally HBA is disabled ie marked offline or flash
827 * operations are in progress.
828 *
829 * Input:
830 * ha - pointer to host adapter structure
831 *
832 * Note:
833 * Does context switching-Release SPIN_LOCK
834 * (if any) before calling this routine.
835 *
836 * Return:
837 * Success (Adapter is online/no flash ops) : 0
838 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
839 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500840static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700841qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
842{
843 int return_status;
844 unsigned long wait_online;
845 struct qla_hw_data *ha = vha->hw;
846 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
847
848 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
849 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
850 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
851 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
852 ha->optrom_state != QLA_SWAITING ||
853 ha->dpc_active) && time_before(jiffies, wait_online))
854 msleep(1000);
855
856 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
857 return_status = QLA_SUCCESS;
858 else
859 return_status = QLA_FUNCTION_FAILED;
860
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700861 ql_dbg(ql_dbg_taskm, vha, 0x8019,
862 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700863
864 return return_status;
865}
866
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700867int
868qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
869{
870 int return_status;
871 unsigned long wait_reset;
872 struct qla_hw_data *ha = vha->hw;
873 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
874
875 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
876 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
877 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
878 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
879 ha->dpc_active) && time_before(jiffies, wait_reset)) {
880
881 msleep(1000);
882
883 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
884 ha->flags.chip_reset_done)
885 break;
886 }
887 if (ha->flags.chip_reset_done)
888 return_status = QLA_SUCCESS;
889 else
890 return_status = QLA_FUNCTION_FAILED;
891
892 return return_status;
893}
894
Giridhar Malavali083a4692010-05-28 15:08:18 -0700895static void
896sp_get(struct srb *sp)
897{
898 atomic_inc(&sp->ref_count);
899}
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901/**************************************************************************
902* qla2xxx_eh_abort
903*
904* Description:
905* The abort function will abort the specified command.
906*
907* Input:
908* cmd = Linux SCSI command packet to be aborted.
909*
910* Returns:
911* Either SUCCESS or FAILED.
912*
913* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700914* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800916static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917qla2xxx_eh_abort(struct scsi_cmnd *cmd)
918{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800919 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500920 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800921 int ret;
f4f051e2005-04-17 15:02:26 -0500922 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700923 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700924 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
f4f051e2005-04-17 15:02:26 -0500927 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700928 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800930 ret = fc_block_scsi_eh(cmd);
931 if (ret != 0)
932 return ret;
933 ret = SUCCESS;
934
f4f051e2005-04-17 15:02:26 -0500935 id = cmd->device->id;
936 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800938 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700939 sp = (srb_t *) CMD_SP(cmd);
940 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800941 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700942 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500943 }
Mike Christie170babc2010-10-15 11:27:47 -0700944
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800946 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
947 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700948
949 /* Get a reference to the sp and drop the lock.*/
950 sp_get(sp);
951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800952 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700953 if (ha->isp_ops->abort_command(sp)) {
Arun Easia55aac72012-02-09 11:14:03 -0800954 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700955 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800956 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700957 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700958 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800959 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700960 wait = 1;
961 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700962
963 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800964 sp->done(ha, sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -0700965 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500966
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700967 /* Did the command return during mailbox execution? */
968 if (ret == FAILED && !CMD_SP(cmd))
969 ret = SUCCESS;
970
f4f051e2005-04-17 15:02:26 -0500971 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700972 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800973 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700974 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800975 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -0700976 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700980 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800981 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
982 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
f4f051e2005-04-17 15:02:26 -0500984 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500987int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500989 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800991 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700992 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800993 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800994 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500995 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800996 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Andrew Vasquez523ec772008-04-03 13:13:24 -0700998 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001000 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001001 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001002 for (cnt = 1; status == QLA_SUCCESS &&
1003 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1004 sp = req->outstanding_cmds[cnt];
1005 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001006 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001007 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001008 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001009 if (vha->vp_idx != sp->fcport->vha->vp_idx)
1010 continue;
1011 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001012 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001013 switch (type) {
1014 case WAIT_HOST:
1015 match = 1;
1016 break;
1017 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001018 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001019 break;
1020 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001021 match = (cmd->device->id == t &&
1022 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001023 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001025 if (!match)
1026 continue;
1027
1028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001029 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001030 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001033
1034 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035}
1036
Andrew Vasquez523ec772008-04-03 13:13:24 -07001037static char *reset_errors[] = {
1038 "HBA not online",
1039 "HBA not ready",
1040 "Task management failed",
1041 "Waiting for command completions",
1042};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Andrew Vasquez523ec772008-04-03 13:13:24 -07001044static int
1045__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001046 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001047{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001048 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001049 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1050 int err;
1051
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001052 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001053 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001054 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001055
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001056 err = fc_block_scsi_eh(cmd);
1057 if (err != 0)
1058 return err;
1059
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001060 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001061 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001062 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001063
1064 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001065 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1066 ql_log(ql_log_warn, vha, 0x800a,
1067 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001068 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001069 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001070 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001071 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001072 != QLA_SUCCESS) {
1073 ql_log(ql_log_warn, vha, 0x800c,
1074 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001075 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001076 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001077 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001079 cmd->device->lun, type) != QLA_SUCCESS) {
1080 ql_log(ql_log_warn, vha, 0x800d,
1081 "wait for peding cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001082 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001083 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001084
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001085 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001086 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1087 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001088
1089 return SUCCESS;
1090
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001091eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001092 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001093 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1094 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1095 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001096 return FAILED;
1097}
1098
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001099static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1101{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001102 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1103 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Andrew Vasquez523ec772008-04-03 13:13:24 -07001105 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1106 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001110qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
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("TARGET", WAIT_TARGET, cmd,
1116 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119/**************************************************************************
1120* qla2xxx_eh_bus_reset
1121*
1122* Description:
1123* The bus reset function will reset the bus and abort any executing
1124* commands.
1125*
1126* Input:
1127* cmd = Linux SCSI command packet of the command that cause the
1128* bus reset.
1129*
1130* Returns:
1131* SUCCESS/FAILURE (defined as macro in scsi.h).
1132*
1133**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001134static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1136{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001137 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001138 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001139 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001140 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
f4f051e2005-04-17 15:02:26 -05001142 id = cmd->device->id;
1143 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001146 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001149 ret = fc_block_scsi_eh(cmd);
1150 if (ret != 0)
1151 return ret;
1152 ret = FAILED;
1153
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001154 ql_log(ql_log_info, vha, 0x8012,
Andrew Vasquez46270af2012-05-15 14:34:17 -04001155 "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001158 ql_log(ql_log_fatal, vha, 0x8013,
1159 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001160 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 }
1162
Saurav Kashyapad537682011-11-18 09:02:09 -08001163 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1164 ret = SUCCESS;
1165
f4f051e2005-04-17 15:02:26 -05001166 if (ret == FAILED)
1167 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001169 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001170 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001171 QLA_SUCCESS) {
1172 ql_log(ql_log_warn, vha, 0x8014,
1173 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001174 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
f4f051e2005-04-17 15:02:26 -05001177eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001178 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001179 "BUS RESET %s nexus=%ld:%d:%d.\n",
1180 (ret == FAILED) ? "FAILED" : "SUCCEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
f4f051e2005-04-17 15:02:26 -05001182 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
1185/**************************************************************************
1186* qla2xxx_eh_host_reset
1187*
1188* Description:
1189* The reset function will reset the Adapter.
1190*
1191* Input:
1192* cmd = Linux SCSI command packet of the command that cause the
1193* adapter reset.
1194*
1195* Returns:
1196* Either SUCCESS or FAILED.
1197*
1198* Note:
1199**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001200static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1202{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001203 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001205 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001206 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001207 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
f4f051e2005-04-17 15:02:26 -05001209 id = cmd->device->id;
1210 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001211
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001212 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001213 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001215 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001216 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218 if (vha != base_vha) {
1219 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001220 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001221 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001222 if (IS_QLA82XX(vha->hw)) {
1223 if (!qla82xx_fcoe_ctx_reset(vha)) {
1224 /* Ctx reset success */
1225 ret = SUCCESS;
1226 goto eh_host_reset_lock;
1227 }
1228 /* fall thru if ctx reset failed */
1229 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001230 if (ha->wq)
1231 flush_workqueue(ha->wq);
1232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001234 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1236 /* failed. schedule dpc to try */
1237 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1238
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001239 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1240 ql_log(ql_log_warn, vha, 0x802a,
1241 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001242 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 }
1245 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001249 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001250 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001251 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
f4f051e2005-04-17 15:02:26 -05001253eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001254 ql_log(ql_log_info, vha, 0x8017,
1255 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1256 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
f4f051e2005-04-17 15:02:26 -05001258 return ret;
1259}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261/*
1262* qla2x00_loop_reset
1263* Issue loop reset.
1264*
1265* Input:
1266* ha = adapter block pointer.
1267*
1268* Returns:
1269* 0 = success
1270*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001271int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001274 int ret;
bdf79622005-04-17 15:06:53 -05001275 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001276 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001278 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001279 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1280 if (fcport->port_type != FCT_TARGET)
1281 continue;
1282
1283 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1284 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001285 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1286 "Bus Reset failed: Target Reset=%d "
1287 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001288 }
1289 }
1290 }
1291
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001292 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001293 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001294 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001295 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1296 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001297 }
1298 atomic_set(&vha->loop_state, LOOP_DOWN);
1299 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1300 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 }
1302
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001303 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001305 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001306 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1307 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001308 }
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001313 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314}
1315
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001316void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001318{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001319 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001320 unsigned long flags;
1321 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001323 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001324
1325 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001326 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001327 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001328 if (!req)
1329 continue;
1330 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1331 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001332 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001333 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001334 sp->done(vha, sp, res);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001335 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001336 }
1337 }
1338 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1339}
1340
f4f051e2005-04-17 15:02:26 -05001341static int
1342qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
bdf79622005-04-17 15:06:53 -05001344 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001346 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001347 return -ENXIO;
1348
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001349 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001350
1351 return 0;
1352}
1353
1354static int
1355qla2xxx_slave_configure(struct scsi_device *sdev)
1356{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001357 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001358 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001359
f4f051e2005-04-17 15:02:26 -05001360 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001361 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001363 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001364 return 0;
1365}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
f4f051e2005-04-17 15:02:26 -05001367static void
1368qla2xxx_slave_destroy(struct scsi_device *sdev)
1369{
1370 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371}
1372
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001373static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1374{
1375 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1376
1377 if (!scsi_track_queue_full(sdev, qdepth))
1378 return;
1379
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001381 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1382 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001383}
1384
1385static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1386{
1387 fc_port_t *fcport = sdev->hostdata;
1388 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001389 struct req_que *req = NULL;
1390
1391 req = vha->req;
1392 if (!req)
1393 return;
1394
1395 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1396 return;
1397
1398 if (sdev->ordered_tags)
1399 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1400 else
1401 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1402
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001403 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001404 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1405 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001406}
1407
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001408static int
Mike Christiee881a172009-10-15 17:46:39 -07001409qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001410{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001411 switch (reason) {
1412 case SCSI_QDEPTH_DEFAULT:
1413 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1414 break;
1415 case SCSI_QDEPTH_QFULL:
1416 qla2x00_handle_queue_full(sdev, qdepth);
1417 break;
1418 case SCSI_QDEPTH_RAMP_UP:
1419 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1420 break;
1421 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001422 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001423 }
Mike Christiee881a172009-10-15 17:46:39 -07001424
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001425 return sdev->queue_depth;
1426}
1427
1428static int
1429qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1430{
1431 if (sdev->tagged_supported) {
1432 scsi_set_tag_type(sdev, tag_type);
1433 if (tag_type)
1434 scsi_activate_tcq(sdev, sdev->queue_depth);
1435 else
1436 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1437 } else
1438 tag_type = 0;
1439
1440 return tag_type;
1441}
1442
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443/**
1444 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1445 * @ha: HA context
1446 *
1447 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1448 * supported addressing method.
1449 */
1450static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001451qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001453 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Yang Hongyang6a355282009-04-06 19:01:13 -07001456 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001457 /* Any upper-dword bits set? */
1458 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001459 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001460 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001462 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1463 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001464 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001467
Yang Hongyang284901a2009-04-06 19:01:15 -07001468 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1469 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470}
1471
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001472static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001474{
1475 unsigned long flags = 0;
1476 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1477
1478 spin_lock_irqsave(&ha->hardware_lock, flags);
1479 ha->interrupts_on = 1;
1480 /* enable risc and host interrupts */
1481 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1482 RD_REG_WORD(&reg->ictrl);
1483 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1484
1485}
1486
1487static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001489{
1490 unsigned long flags = 0;
1491 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1492
1493 spin_lock_irqsave(&ha->hardware_lock, flags);
1494 ha->interrupts_on = 0;
1495 /* disable risc and host interrupts */
1496 WRT_REG_WORD(&reg->ictrl, 0);
1497 RD_REG_WORD(&reg->ictrl);
1498 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1499}
1500
1501static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001502qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001503{
1504 unsigned long flags = 0;
1505 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1506
1507 spin_lock_irqsave(&ha->hardware_lock, flags);
1508 ha->interrupts_on = 1;
1509 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1510 RD_REG_DWORD(&reg->ictrl);
1511 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1512}
1513
1514static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001515qla24xx_disable_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
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001520 if (IS_NOPOLLING_TYPE(ha))
1521 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001522 spin_lock_irqsave(&ha->hardware_lock, flags);
1523 ha->interrupts_on = 0;
1524 WRT_REG_DWORD(&reg->ictrl, 0);
1525 RD_REG_DWORD(&reg->ictrl);
1526 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1527}
1528
Giridhar Malavali706f4572011-11-18 09:03:16 -08001529static int
1530qla2x00_iospace_config(struct qla_hw_data *ha)
1531{
1532 resource_size_t pio;
1533 uint16_t msix;
1534 int cpus;
1535
Giridhar Malavali706f4572011-11-18 09:03:16 -08001536 if (pci_request_selected_regions(ha->pdev, ha->bars,
1537 QLA2XXX_DRIVER_NAME)) {
1538 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1539 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1540 pci_name(ha->pdev));
1541 goto iospace_error_exit;
1542 }
1543 if (!(ha->bars & 1))
1544 goto skip_pio;
1545
1546 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1547 pio = pci_resource_start(ha->pdev, 0);
1548 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1549 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1550 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1551 "Invalid pci I/O region size (%s).\n",
1552 pci_name(ha->pdev));
1553 pio = 0;
1554 }
1555 } else {
1556 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1557 "Region #0 no a PIO resource (%s).\n",
1558 pci_name(ha->pdev));
1559 pio = 0;
1560 }
1561 ha->pio_address = pio;
1562 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1563 "PIO address=%llu.\n",
1564 (unsigned long long)ha->pio_address);
1565
1566skip_pio:
1567 /* Use MMIO operations for all accesses. */
1568 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1569 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1570 "Region #1 not an MMIO resource (%s), aborting.\n",
1571 pci_name(ha->pdev));
1572 goto iospace_error_exit;
1573 }
1574 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1575 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1576 "Invalid PCI mem region size (%s), aborting.\n",
1577 pci_name(ha->pdev));
1578 goto iospace_error_exit;
1579 }
1580
1581 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1582 if (!ha->iobase) {
1583 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1584 "Cannot remap MMIO (%s), aborting.\n",
1585 pci_name(ha->pdev));
1586 goto iospace_error_exit;
1587 }
1588
1589 /* Determine queue resources */
1590 ha->max_req_queues = ha->max_rsp_queues = 1;
1591 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1592 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1593 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1594 goto mqiobase_exit;
1595
1596 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1597 pci_resource_len(ha->pdev, 3));
1598 if (ha->mqiobase) {
1599 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1600 "MQIO Base=%p.\n", ha->mqiobase);
1601 /* Read MSIX vector size of the board */
1602 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1603 ha->msix_count = msix;
1604 /* Max queues are bounded by available msix vectors */
1605 /* queue 0 uses two msix vectors */
1606 if (ql2xmultique_tag) {
1607 cpus = num_online_cpus();
1608 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1609 (cpus + 1) : (ha->msix_count - 1);
1610 ha->max_req_queues = 2;
1611 } else if (ql2xmaxqueues > 1) {
1612 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1613 QLA_MQ_SIZE : ql2xmaxqueues;
1614 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1615 "QoS mode set, max no of request queues:%d.\n",
1616 ha->max_req_queues);
1617 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1618 "QoS mode set, max no of request queues:%d.\n",
1619 ha->max_req_queues);
1620 }
1621 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1622 "MSI-X vector count: %d.\n", msix);
1623 } else
1624 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1625 "BAR 3 not enabled.\n");
1626
1627mqiobase_exit:
1628 ha->msix_count = ha->max_rsp_queues + 1;
1629 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1630 "MSIX Count:%d.\n", ha->msix_count);
1631 return (0);
1632
1633iospace_error_exit:
1634 return (-ENOMEM);
1635}
1636
1637
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001638static int
1639qla83xx_iospace_config(struct qla_hw_data *ha)
1640{
1641 uint16_t msix;
1642 int cpus;
1643
1644 if (pci_request_selected_regions(ha->pdev, ha->bars,
1645 QLA2XXX_DRIVER_NAME)) {
1646 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1647 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1648 pci_name(ha->pdev));
1649
1650 goto iospace_error_exit;
1651 }
1652
1653 /* Use MMIO operations for all accesses. */
1654 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1655 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1656 "Invalid pci I/O region size (%s).\n",
1657 pci_name(ha->pdev));
1658 goto iospace_error_exit;
1659 }
1660 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1661 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1662 "Invalid PCI mem region size (%s), aborting\n",
1663 pci_name(ha->pdev));
1664 goto iospace_error_exit;
1665 }
1666
1667 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1668 if (!ha->iobase) {
1669 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1670 "Cannot remap MMIO (%s), aborting.\n",
1671 pci_name(ha->pdev));
1672 goto iospace_error_exit;
1673 }
1674
1675 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1676 /* 83XX 26XX always use MQ type access for queues
1677 * - mbar 2, a.k.a region 4 */
1678 ha->max_req_queues = ha->max_rsp_queues = 1;
1679 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1680 pci_resource_len(ha->pdev, 4));
1681
1682 if (!ha->mqiobase) {
1683 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1684 "BAR2/region4 not enabled\n");
1685 goto mqiobase_exit;
1686 }
1687
1688 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1689 pci_resource_len(ha->pdev, 2));
1690 if (ha->msixbase) {
1691 /* Read MSIX vector size of the board */
1692 pci_read_config_word(ha->pdev,
1693 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1694 ha->msix_count = msix;
1695 /* Max queues are bounded by available msix vectors */
1696 /* queue 0 uses two msix vectors */
1697 if (ql2xmultique_tag) {
1698 cpus = num_online_cpus();
1699 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1700 (cpus + 1) : (ha->msix_count - 1);
1701 ha->max_req_queues = 2;
1702 } else if (ql2xmaxqueues > 1) {
1703 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1704 QLA_MQ_SIZE : ql2xmaxqueues;
1705 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1706 "QoS mode set, max no of request queues:%d.\n",
1707 ha->max_req_queues);
1708 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1709 "QoS mode set, max no of request queues:%d.\n",
1710 ha->max_req_queues);
1711 }
1712 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1713 "MSI-X vector count: %d.\n", msix);
1714 } else
1715 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1716 "BAR 1 not enabled.\n");
1717
1718mqiobase_exit:
1719 ha->msix_count = ha->max_rsp_queues + 1;
1720 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1721 "MSIX Count:%d.\n", ha->msix_count);
1722 return 0;
1723
1724iospace_error_exit:
1725 return -ENOMEM;
1726}
1727
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001728static struct isp_operations qla2100_isp_ops = {
1729 .pci_config = qla2100_pci_config,
1730 .reset_chip = qla2x00_reset_chip,
1731 .chip_diag = qla2x00_chip_diag,
1732 .config_rings = qla2x00_config_rings,
1733 .reset_adapter = qla2x00_reset_adapter,
1734 .nvram_config = qla2x00_nvram_config,
1735 .update_fw_options = qla2x00_update_fw_options,
1736 .load_risc = qla2x00_load_risc,
1737 .pci_info_str = qla2x00_pci_info_str,
1738 .fw_version_str = qla2x00_fw_version_str,
1739 .intr_handler = qla2100_intr_handler,
1740 .enable_intrs = qla2x00_enable_intrs,
1741 .disable_intrs = qla2x00_disable_intrs,
1742 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001743 .target_reset = qla2x00_abort_target,
1744 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001745 .fabric_login = qla2x00_login_fabric,
1746 .fabric_logout = qla2x00_fabric_logout,
1747 .calc_req_entries = qla2x00_calc_iocbs_32,
1748 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1749 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1750 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1751 .read_nvram = qla2x00_read_nvram_data,
1752 .write_nvram = qla2x00_write_nvram_data,
1753 .fw_dump = qla2100_fw_dump,
1754 .beacon_on = NULL,
1755 .beacon_off = NULL,
1756 .beacon_blink = NULL,
1757 .read_optrom = qla2x00_read_optrom_data,
1758 .write_optrom = qla2x00_write_optrom_data,
1759 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001760 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001761 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001762 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001763};
1764
1765static struct isp_operations qla2300_isp_ops = {
1766 .pci_config = qla2300_pci_config,
1767 .reset_chip = qla2x00_reset_chip,
1768 .chip_diag = qla2x00_chip_diag,
1769 .config_rings = qla2x00_config_rings,
1770 .reset_adapter = qla2x00_reset_adapter,
1771 .nvram_config = qla2x00_nvram_config,
1772 .update_fw_options = qla2x00_update_fw_options,
1773 .load_risc = qla2x00_load_risc,
1774 .pci_info_str = qla2x00_pci_info_str,
1775 .fw_version_str = qla2x00_fw_version_str,
1776 .intr_handler = qla2300_intr_handler,
1777 .enable_intrs = qla2x00_enable_intrs,
1778 .disable_intrs = qla2x00_disable_intrs,
1779 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001780 .target_reset = qla2x00_abort_target,
1781 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001782 .fabric_login = qla2x00_login_fabric,
1783 .fabric_logout = qla2x00_fabric_logout,
1784 .calc_req_entries = qla2x00_calc_iocbs_32,
1785 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1786 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1787 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1788 .read_nvram = qla2x00_read_nvram_data,
1789 .write_nvram = qla2x00_write_nvram_data,
1790 .fw_dump = qla2300_fw_dump,
1791 .beacon_on = qla2x00_beacon_on,
1792 .beacon_off = qla2x00_beacon_off,
1793 .beacon_blink = qla2x00_beacon_blink,
1794 .read_optrom = qla2x00_read_optrom_data,
1795 .write_optrom = qla2x00_write_optrom_data,
1796 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001798 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001799 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001800};
1801
1802static struct isp_operations qla24xx_isp_ops = {
1803 .pci_config = qla24xx_pci_config,
1804 .reset_chip = qla24xx_reset_chip,
1805 .chip_diag = qla24xx_chip_diag,
1806 .config_rings = qla24xx_config_rings,
1807 .reset_adapter = qla24xx_reset_adapter,
1808 .nvram_config = qla24xx_nvram_config,
1809 .update_fw_options = qla24xx_update_fw_options,
1810 .load_risc = qla24xx_load_risc,
1811 .pci_info_str = qla24xx_pci_info_str,
1812 .fw_version_str = qla24xx_fw_version_str,
1813 .intr_handler = qla24xx_intr_handler,
1814 .enable_intrs = qla24xx_enable_intrs,
1815 .disable_intrs = qla24xx_disable_intrs,
1816 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001817 .target_reset = qla24xx_abort_target,
1818 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001819 .fabric_login = qla24xx_login_fabric,
1820 .fabric_logout = qla24xx_fabric_logout,
1821 .calc_req_entries = NULL,
1822 .build_iocbs = NULL,
1823 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1824 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1825 .read_nvram = qla24xx_read_nvram_data,
1826 .write_nvram = qla24xx_write_nvram_data,
1827 .fw_dump = qla24xx_fw_dump,
1828 .beacon_on = qla24xx_beacon_on,
1829 .beacon_off = qla24xx_beacon_off,
1830 .beacon_blink = qla24xx_beacon_blink,
1831 .read_optrom = qla24xx_read_optrom_data,
1832 .write_optrom = qla24xx_write_optrom_data,
1833 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001834 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001835 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001836 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001837};
1838
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001839static struct isp_operations qla25xx_isp_ops = {
1840 .pci_config = qla25xx_pci_config,
1841 .reset_chip = qla24xx_reset_chip,
1842 .chip_diag = qla24xx_chip_diag,
1843 .config_rings = qla24xx_config_rings,
1844 .reset_adapter = qla24xx_reset_adapter,
1845 .nvram_config = qla24xx_nvram_config,
1846 .update_fw_options = qla24xx_update_fw_options,
1847 .load_risc = qla24xx_load_risc,
1848 .pci_info_str = qla24xx_pci_info_str,
1849 .fw_version_str = qla24xx_fw_version_str,
1850 .intr_handler = qla24xx_intr_handler,
1851 .enable_intrs = qla24xx_enable_intrs,
1852 .disable_intrs = qla24xx_disable_intrs,
1853 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001854 .target_reset = qla24xx_abort_target,
1855 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001856 .fabric_login = qla24xx_login_fabric,
1857 .fabric_logout = qla24xx_fabric_logout,
1858 .calc_req_entries = NULL,
1859 .build_iocbs = NULL,
1860 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1861 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1862 .read_nvram = qla25xx_read_nvram_data,
1863 .write_nvram = qla25xx_write_nvram_data,
1864 .fw_dump = qla25xx_fw_dump,
1865 .beacon_on = qla24xx_beacon_on,
1866 .beacon_off = qla24xx_beacon_off,
1867 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001868 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001869 .write_optrom = qla24xx_write_optrom_data,
1870 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001871 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001872 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001873 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001874};
1875
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001876static struct isp_operations qla81xx_isp_ops = {
1877 .pci_config = qla25xx_pci_config,
1878 .reset_chip = qla24xx_reset_chip,
1879 .chip_diag = qla24xx_chip_diag,
1880 .config_rings = qla24xx_config_rings,
1881 .reset_adapter = qla24xx_reset_adapter,
1882 .nvram_config = qla81xx_nvram_config,
1883 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001884 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001885 .pci_info_str = qla24xx_pci_info_str,
1886 .fw_version_str = qla24xx_fw_version_str,
1887 .intr_handler = qla24xx_intr_handler,
1888 .enable_intrs = qla24xx_enable_intrs,
1889 .disable_intrs = qla24xx_disable_intrs,
1890 .abort_command = qla24xx_abort_command,
1891 .target_reset = qla24xx_abort_target,
1892 .lun_reset = qla24xx_lun_reset,
1893 .fabric_login = qla24xx_login_fabric,
1894 .fabric_logout = qla24xx_fabric_logout,
1895 .calc_req_entries = NULL,
1896 .build_iocbs = NULL,
1897 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1898 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001899 .read_nvram = NULL,
1900 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001901 .fw_dump = qla81xx_fw_dump,
1902 .beacon_on = qla24xx_beacon_on,
1903 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001904 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001905 .read_optrom = qla25xx_read_optrom_data,
1906 .write_optrom = qla24xx_write_optrom_data,
1907 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001908 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001909 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001910 .iospace_config = qla2x00_iospace_config,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001911};
1912
1913static struct isp_operations qla82xx_isp_ops = {
1914 .pci_config = qla82xx_pci_config,
1915 .reset_chip = qla82xx_reset_chip,
1916 .chip_diag = qla24xx_chip_diag,
1917 .config_rings = qla82xx_config_rings,
1918 .reset_adapter = qla24xx_reset_adapter,
1919 .nvram_config = qla81xx_nvram_config,
1920 .update_fw_options = qla24xx_update_fw_options,
1921 .load_risc = qla82xx_load_risc,
1922 .pci_info_str = qla82xx_pci_info_str,
1923 .fw_version_str = qla24xx_fw_version_str,
1924 .intr_handler = qla82xx_intr_handler,
1925 .enable_intrs = qla82xx_enable_intrs,
1926 .disable_intrs = qla82xx_disable_intrs,
1927 .abort_command = qla24xx_abort_command,
1928 .target_reset = qla24xx_abort_target,
1929 .lun_reset = qla24xx_lun_reset,
1930 .fabric_login = qla24xx_login_fabric,
1931 .fabric_logout = qla24xx_fabric_logout,
1932 .calc_req_entries = NULL,
1933 .build_iocbs = NULL,
1934 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1935 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1936 .read_nvram = qla24xx_read_nvram_data,
1937 .write_nvram = qla24xx_write_nvram_data,
1938 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001939 .beacon_on = qla82xx_beacon_on,
1940 .beacon_off = qla82xx_beacon_off,
1941 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001942 .read_optrom = qla82xx_read_optrom_data,
1943 .write_optrom = qla82xx_write_optrom_data,
1944 .get_flash_version = qla24xx_get_flash_version,
1945 .start_scsi = qla82xx_start_scsi,
1946 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001947 .iospace_config = qla82xx_iospace_config,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001948};
1949
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001950static struct isp_operations qla83xx_isp_ops = {
1951 .pci_config = qla25xx_pci_config,
1952 .reset_chip = qla24xx_reset_chip,
1953 .chip_diag = qla24xx_chip_diag,
1954 .config_rings = qla24xx_config_rings,
1955 .reset_adapter = qla24xx_reset_adapter,
1956 .nvram_config = qla81xx_nvram_config,
1957 .update_fw_options = qla81xx_update_fw_options,
1958 .load_risc = qla81xx_load_risc,
1959 .pci_info_str = qla24xx_pci_info_str,
1960 .fw_version_str = qla24xx_fw_version_str,
1961 .intr_handler = qla24xx_intr_handler,
1962 .enable_intrs = qla24xx_enable_intrs,
1963 .disable_intrs = qla24xx_disable_intrs,
1964 .abort_command = qla24xx_abort_command,
1965 .target_reset = qla24xx_abort_target,
1966 .lun_reset = qla24xx_lun_reset,
1967 .fabric_login = qla24xx_login_fabric,
1968 .fabric_logout = qla24xx_fabric_logout,
1969 .calc_req_entries = NULL,
1970 .build_iocbs = NULL,
1971 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1972 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1973 .read_nvram = NULL,
1974 .write_nvram = NULL,
1975 .fw_dump = qla83xx_fw_dump,
1976 .beacon_on = qla24xx_beacon_on,
1977 .beacon_off = qla24xx_beacon_off,
1978 .beacon_blink = qla83xx_beacon_blink,
1979 .read_optrom = qla25xx_read_optrom_data,
1980 .write_optrom = qla24xx_write_optrom_data,
1981 .get_flash_version = qla24xx_get_flash_version,
1982 .start_scsi = qla24xx_dif_start_scsi,
1983 .abort_isp = qla2x00_abort_isp,
1984 .iospace_config = qla83xx_iospace_config,
1985};
1986
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001987static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001989{
1990 ha->device_type = DT_EXTENDED_IDS;
1991 switch (ha->pdev->device) {
1992 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1993 ha->device_type |= DT_ISP2100;
1994 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001995 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001996 break;
1997 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1998 ha->device_type |= DT_ISP2200;
1999 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002000 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002001 break;
2002 case PCI_DEVICE_ID_QLOGIC_ISP2300:
2003 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002004 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002005 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002006 break;
2007 case PCI_DEVICE_ID_QLOGIC_ISP2312:
2008 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002009 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002010 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002011 break;
2012 case PCI_DEVICE_ID_QLOGIC_ISP2322:
2013 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002014 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002015 if (ha->pdev->subsystem_vendor == 0x1028 &&
2016 ha->pdev->subsystem_device == 0x0170)
2017 ha->device_type |= DT_OEM_001;
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_ISP6312:
2021 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002022 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002023 break;
2024 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2025 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002026 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002027 break;
2028 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2029 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002030 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002031 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002032 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002033 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002034 break;
2035 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2036 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002037 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002038 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002039 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002040 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002041 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002042 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2043 ha->device_type |= DT_ISP8432;
2044 ha->device_type |= DT_ZIO_SUPPORTED;
2045 ha->device_type |= DT_FWI2;
2046 ha->device_type |= DT_IIDMA;
2047 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2048 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002049 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2050 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002051 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002052 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002053 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002054 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2055 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002056 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002057 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002058 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002059 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2060 ha->device_type |= DT_ISP2532;
2061 ha->device_type |= DT_ZIO_SUPPORTED;
2062 ha->device_type |= DT_FWI2;
2063 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002064 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2065 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002066 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2067 ha->device_type |= DT_ISP8001;
2068 ha->device_type |= DT_ZIO_SUPPORTED;
2069 ha->device_type |= DT_FWI2;
2070 ha->device_type |= DT_IIDMA;
2071 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2072 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002073 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2074 ha->device_type |= DT_ISP8021;
2075 ha->device_type |= DT_ZIO_SUPPORTED;
2076 ha->device_type |= DT_FWI2;
2077 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2078 /* Initialize 82XX ISP flags */
2079 qla82xx_init_flags(ha);
2080 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002081 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2082 ha->device_type |= DT_ISP2031;
2083 ha->device_type |= DT_ZIO_SUPPORTED;
2084 ha->device_type |= DT_FWI2;
2085 ha->device_type |= DT_IIDMA;
2086 ha->device_type |= DT_T10_PI;
2087 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2088 break;
2089 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2090 ha->device_type |= DT_ISP8031;
2091 ha->device_type |= DT_ZIO_SUPPORTED;
2092 ha->device_type |= DT_FWI2;
2093 ha->device_type |= DT_IIDMA;
2094 ha->device_type |= DT_T10_PI;
2095 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2096 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002097 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002098
Giridhar Malavalia9083012010-04-12 17:59:55 -07002099 if (IS_QLA82XX(ha))
2100 ha->port_no = !(ha->portnum & 1);
2101 else
2102 /* Get adapter physical port no from interrupt pin register. */
2103 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2104
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002105 if (ha->port_no & 1)
2106 ha->flags.port0 = 1;
2107 else
2108 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002109 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002110 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002111 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002112}
2113
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002114static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002115qla2xxx_scan_start(struct Scsi_Host *shost)
2116{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002117 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002118
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002119 if (vha->hw->flags.running_gold_fw)
2120 return;
2121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002122 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2123 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2124 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2125 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002126}
2127
2128static int
2129qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2130{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002131 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002132
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002134 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002136 return 1;
2137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002139}
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141/*
2142 * PCI driver interface
2143 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002144static int __devinit
2145qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002147 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002149 scsi_qla_host_t *base_vha = NULL;
2150 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002151 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002153 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002154 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002156 struct req_que *req = NULL;
2157 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Andrew Vasquez285d0322007-10-19 15:59:17 -07002159 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002160 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002161 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2162 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002163 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002164 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2165 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002166 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002167 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002168 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2169 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2170 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002171 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002172 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002173 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2174 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002175 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002176 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2177 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002178
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002179 if (mem_only) {
2180 if (pci_enable_device_mem(pdev))
2181 goto probe_out;
2182 } else {
2183 if (pci_enable_device(pdev))
2184 goto probe_out;
2185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Jesse Barnes09276782008-10-18 17:33:19 -07002187 /* This may fail but that's ok */
2188 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002189
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2191 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002192 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2193 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002196 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2197 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198 ha->pdev = pdev;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002199 ha->tgt.enable_class_2 = ql2xenableclass2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
2201 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002202 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002203 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002204 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002205 spin_lock_init(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002207 /* Set ISP-type information. */
2208 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002209
2210 /* Set EEH reset type to fundamental if required by hba */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002211 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002212 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002213
Chad Dupuiscba1e472011-11-18 09:03:21 -08002214 ha->prev_topology = 0;
2215 ha->init_cb_size = sizeof(init_cb_t);
2216 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2217 ha->optrom_size = OPTROM_SIZE_2300;
2218
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002219 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002221 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002223 req_length = REQUEST_ENTRY_CNT_2100;
2224 rsp_length = RESPONSE_ENTRY_CNT_2100;
2225 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002226 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002227 ha->flash_conf_off = ~0;
2228 ha->flash_data_off = ~0;
2229 ha->nvram_conf_off = ~0;
2230 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002231 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002233 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002234 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 req_length = REQUEST_ENTRY_CNT_2200;
2236 rsp_length = RESPONSE_ENTRY_CNT_2100;
2237 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002238 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002239 ha->flash_conf_off = ~0;
2240 ha->flash_data_off = ~0;
2241 ha->nvram_conf_off = ~0;
2242 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002243 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002244 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002245 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002247 req_length = REQUEST_ENTRY_CNT_2200;
2248 rsp_length = RESPONSE_ENTRY_CNT_2300;
2249 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002250 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002251 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2252 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002253 ha->flash_conf_off = ~0;
2254 ha->flash_data_off = ~0;
2255 ha->nvram_conf_off = ~0;
2256 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002257 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002258 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002259 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002260 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261 req_length = REQUEST_ENTRY_CNT_24XX;
2262 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002263 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002264 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002265 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002266 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002267 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002268 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002269 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002270 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2271 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2272 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2273 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002274 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002275 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002276 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 req_length = REQUEST_ENTRY_CNT_24XX;
2278 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002279 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002280 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002281 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002282 ha->gid_list_info_size = 8;
2283 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002284 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002285 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002286 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2287 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2288 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2289 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2290 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002291 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002292 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2293 req_length = REQUEST_ENTRY_CNT_24XX;
2294 rsp_length = RESPONSE_ENTRY_CNT_2300;
2295 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2296 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2297 ha->gid_list_info_size = 8;
2298 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002299 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002300 ha->isp_ops = &qla81xx_isp_ops;
2301 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2302 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2303 ha->nvram_conf_off = ~0;
2304 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002305 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002306 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002307 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2308 req_length = REQUEST_ENTRY_CNT_82XX;
2309 rsp_length = RESPONSE_ENTRY_CNT_82XX;
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_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002314 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002315 ha->isp_ops = &qla82xx_isp_ops;
2316 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2317 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2318 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2319 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002320 } else if (IS_QLA83XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002321 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002322 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2323 req_length = REQUEST_ENTRY_CNT_24XX;
2324 rsp_length = RESPONSE_ENTRY_CNT_2300;
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_83XX;
2329 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2330 ha->isp_ops = &qla83xx_isp_ops;
2331 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2332 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2333 ha->nvram_conf_off = ~0;
2334 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002336
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002337 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2338 "mbx_count=%d, req_length=%d, "
2339 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002340 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2341 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002342 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2343 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002344 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002345 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2346 "isp_ops=%p, flash_conf_off=%d, "
2347 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2348 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2349 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002350
2351 /* Configure PCI I/O space */
2352 ret = ha->isp_ops->iospace_config(ha);
2353 if (ret)
2354 goto probe_hw_failed;
2355
2356 ql_log_pci(ql_log_info, pdev, 0x001d,
2357 "Found an ISP%04X irq %d iobase 0x%p.\n",
2358 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002359 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002360 init_completion(&ha->mbx_cmd_comp);
2361 complete(&ha->mbx_cmd_comp);
2362 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002363 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002365 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Andrew Vasquez53303c42009-01-22 09:45:37 -08002367 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002368 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2369 "64 Bit addressing is %s.\n",
2370 ha->flags.enable_64bit_addressing ? "enable" :
2371 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002372 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002374 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2375 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 goto probe_hw_failed;
2378 }
2379
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002380 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002382 req->max_q_depth = ql2xmaxqdepth;
2383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384
2385 base_vha = qla2x00_create_host(sht, ha);
2386 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002387 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002388 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002389 qla2x00_free_req_que(ha, req);
2390 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 }
2393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002397 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002398 host->can_queue = req->length + 128;
2399 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002401 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2403 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002404
2405 /* Set the SG table size based on ISP type */
2406 if (!IS_FWI2_CAPABLE(ha)) {
2407 if (IS_QLA2100(ha))
2408 host->sg_tablesize = 32;
2409 } else {
2410 if (!IS_QLA82XX(ha))
2411 host->sg_tablesize = QLA_SG_ALL;
2412 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002413 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2414 "can_queue=%d, req=%p, "
2415 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2416 host->can_queue, base_vha->req,
2417 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Chad Dupuis642ef982012-02-09 11:15:57 -08002418 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002419 host->this_id = 255;
2420 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002421 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002422 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002423 host->max_cmd_len = 32;
2424 else
2425 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002426 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002427 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002428 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002429 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002430
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002431 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2432 "max_id=%d this_id=%d "
2433 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002434 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002435 host->this_id, host->cmd_per_lun, host->unique_id,
2436 host->max_cmd_len, host->max_channel, host->max_lun,
2437 host->transportt, sht->vendor_id);
2438
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002439que_init:
2440 /* Alloc arrays of request and response ring ptrs */
2441 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2442 ql_log(ql_log_fatal, base_vha, 0x003d,
2443 "Failed to allocate memory for queue pointers..."
2444 "aborting.\n");
2445 goto probe_init_failed;
2446 }
2447
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002448 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002449
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002450 /* Set up the irqs */
2451 ret = qla2x00_request_irqs(ha, rsp);
2452 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002453 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002454
2455 pci_save_state(pdev);
2456
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002457 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002458 rsp->req = req;
2459 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002460
Andrew Vasquez08029992009-03-24 09:07:55 -07002461 /* FWI2-capable only. */
2462 req->req_q_in = &ha->iobase->isp24.req_q_in;
2463 req->req_q_out = &ha->iobase->isp24.req_q_out;
2464 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2465 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002466 if (ha->mqenable || IS_QLA83XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002467 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2468 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2469 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2470 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002471 }
2472
Giridhar Malavalia9083012010-04-12 17:59:55 -07002473 if (IS_QLA82XX(ha)) {
2474 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2475 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2476 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2477 }
2478
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002479 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2480 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2481 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2482 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2483 "req->req_q_in=%p req->req_q_out=%p "
2484 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2485 req->req_q_in, req->req_q_out,
2486 rsp->rsp_q_in, rsp->rsp_q_out);
2487 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2488 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2489 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2490 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2491 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2492 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002494 if (qla2x00_initialize_adapter(base_vha)) {
2495 ql_log(ql_log_fatal, base_vha, 0x00d6,
2496 "Failed to initialize adapter - Adapter flags %x.\n",
2497 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498
Giridhar Malavalia9083012010-04-12 17:59:55 -07002499 if (IS_QLA82XX(ha)) {
2500 qla82xx_idc_lock(ha);
2501 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2502 QLA82XX_DEV_FAILED);
2503 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002504 ql_log(ql_log_fatal, base_vha, 0x00d7,
2505 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002506 }
2507
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 ret = -ENODEV;
2509 goto probe_failed;
2510 }
2511
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002512 if (ha->mqenable) {
2513 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002514 ql_log(ql_log_warn, base_vha, 0x00ec,
2515 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002516 goto que_init;
2517 }
2518 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002519
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002520 if (ha->flags.running_gold_fw)
2521 goto skip_dpc;
2522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 /*
2524 * Startup the kernel thread for this host adapter
2525 */
2526 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002527 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002529 ql_log(ql_log_fatal, base_vha, 0x00ed,
2530 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002531 ret = PTR_ERR(ha->dpc_thread);
2532 goto probe_failed;
2533 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002534 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2535 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002537 /*
2538 * If we're not coming up in initiator mode, we might sit for
2539 * a while without waking up the dpc thread, which leads to a
2540 * stuck process warning. So just kick the dpc once here and
2541 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
2542 */
2543 qla2xxx_wake_dpc(base_vha);
2544
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002545skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002546 list_add_tail(&base_vha->list, &ha->vp_list);
2547 base_vha->host->irq = ha->pdev->irq;
2548
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002550 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002551 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2552 "Started qla2x00_timer with "
2553 "interval=%d.\n", WATCH_INTERVAL);
2554 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2555 "Detected hba at address=%p.\n",
2556 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
Arun Easie02587d2011-08-16 11:29:23 -07002558 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002559 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07002560 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07002561 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002562 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2563 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002564 if (ql2xenabledif == 1)
2565 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002566 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002567 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002568 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002569 | SHOST_DIF_TYPE3_PROTECTION
2570 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002571 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002572 | SHOST_DIX_TYPE3_PROTECTION);
2573 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2574 } else
2575 base_vha->flags.difdix_supported = 0;
2576 }
2577
Giridhar Malavalia9083012010-04-12 17:59:55 -07002578 ha->isp_ops->enable_intrs(ha);
2579
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002580 ret = scsi_add_host(host, &pdev->dev);
2581 if (ret)
2582 goto probe_failed;
2583
Michael Reed14864002009-12-02 09:11:16 -06002584 base_vha->flags.init_done = 1;
2585 base_vha->flags.online = 1;
2586
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002587 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2588 "Init done and hba is online.\n");
2589
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002590 if (qla_ini_mode_enabled(base_vha))
2591 scsi_scan_host(host);
2592 else
2593 ql_dbg(ql_dbg_init, base_vha, 0x0122,
2594 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002599
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002601
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002602 ql_log(ql_log_info, base_vha, 0x00fb,
2603 "QLogic %s - %s.\n",
2604 ha->model_number, ha->model_desc ? ha->model_desc : "");
2605 ql_log(ql_log_info, base_vha, 0x00fc,
2606 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2607 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2608 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2609 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002612 qlt_add_target(ha, base_vha);
2613
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 return 0;
2615
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002616probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002617 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002618 ha->req_q_map[0] = NULL;
2619 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002620 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002621 ha->rsp_q_map[0] = NULL;
2622 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002623 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002624
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002626 if (base_vha->timer_active)
2627 qla2x00_stop_timer(base_vha);
2628 base_vha->flags.online = 0;
2629 if (ha->dpc_thread) {
2630 struct task_struct *t = ha->dpc_thread;
2631
2632 ha->dpc_thread = NULL;
2633 kthread_stop(t);
2634 }
2635
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002641 if (IS_QLA82XX(ha)) {
2642 qla82xx_idc_lock(ha);
2643 qla82xx_clear_drv_active(ha);
2644 qla82xx_idc_unlock(ha);
2645 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2646 if (!ql2xdbwr)
2647 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2648 } else {
2649 if (ha->iobase)
2650 iounmap(ha->iobase);
2651 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 pci_release_selected_regions(ha->pdev, ha->bars);
2653 kfree(ha);
2654 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002656probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002657 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002658 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
Adrian Bunk4c993f72008-01-14 00:55:16 -08002661static void
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002662qla2x00_stop_dpc_thread(scsi_qla_host_t *vha)
2663{
2664 struct qla_hw_data *ha = vha->hw;
2665 struct task_struct *t = ha->dpc_thread;
2666
2667 if (ha->dpc_thread == NULL)
2668 return;
2669 /*
2670 * qla2xxx_wake_dpc checks for ->dpc_thread
2671 * so we need to zero it out.
2672 */
2673 ha->dpc_thread = NULL;
2674 kthread_stop(t);
2675}
2676
2677static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002678qla2x00_shutdown(struct pci_dev *pdev)
2679{
2680 scsi_qla_host_t *vha;
2681 struct qla_hw_data *ha;
2682
2683 vha = pci_get_drvdata(pdev);
2684 ha = vha->hw;
2685
2686 /* Turn-off FCE trace */
2687 if (ha->flags.fce_enabled) {
2688 qla2x00_disable_fce_trace(vha, NULL, NULL);
2689 ha->flags.fce_enabled = 0;
2690 }
2691
2692 /* Turn-off EFT trace */
2693 if (ha->eft)
2694 qla2x00_disable_eft_trace(vha);
2695
2696 /* Stop currently executing firmware. */
2697 qla2x00_try_to_stop_firmware(vha);
2698
2699 /* Turn adapter off line */
2700 vha->flags.online = 0;
2701
2702 /* turn-off interrupts on the card */
2703 if (ha->interrupts_on) {
2704 vha->flags.init_done = 0;
2705 ha->isp_ops->disable_intrs(ha);
2706 }
2707
2708 qla2x00_free_irqs(vha);
2709
2710 qla2x00_free_fw_dump(ha);
2711}
2712
2713static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002714qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715{
Arun Easifeafb7b2010-09-03 14:57:00 -07002716 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002718 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
Chad Dupuis9a347ff2012-05-15 14:34:14 -04002720 /*
2721 * If the PCI device is disabled that means that probe failed and any
2722 * resources should be have cleaned up on probe exit.
2723 */
2724 if (!atomic_read(&pdev->enable_cnt))
2725 return;
2726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 base_vha = pci_get_drvdata(pdev);
2728 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002730 ha->flags.host_shutting_down = 1;
2731
Arun Easi43ebf162011-05-10 11:18:16 -07002732 mutex_lock(&ha->vport_lock);
2733 while (ha->cur_vport_count) {
2734 struct Scsi_Host *scsi_host;
Arun Easifeafb7b2010-09-03 14:57:00 -07002735
Arun Easi43ebf162011-05-10 11:18:16 -07002736 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002737
Arun Easi43ebf162011-05-10 11:18:16 -07002738 BUG_ON(base_vha->list.next == &ha->vp_list);
2739 /* This assumes first entry in ha->vp_list is always base vha */
2740 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2741 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002742
Arun Easi43ebf162011-05-10 11:18:16 -07002743 spin_unlock_irqrestore(&ha->vport_slock, flags);
2744 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002745
Arun Easi43ebf162011-05-10 11:18:16 -07002746 fc_vport_terminate(vha->fc_vport);
2747 scsi_host_put(vha->host);
2748
2749 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002750 }
Arun Easi43ebf162011-05-10 11:18:16 -07002751 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002752
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002754
Andrew Vasquezb9978762009-03-24 09:08:05 -07002755 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002758
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002760
Andrew Vasquezb9978762009-03-24 09:08:05 -07002761 /* Disable timer */
2762 if (base_vha->timer_active)
2763 qla2x00_stop_timer(base_vha);
2764
2765 base_vha->flags.online = 0;
2766
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002767 /* Flush the work queue and remove it */
2768 if (ha->wq) {
2769 flush_workqueue(ha->wq);
2770 destroy_workqueue(ha->wq);
2771 ha->wq = NULL;
2772 }
2773
Andrew Vasquezb9978762009-03-24 09:08:05 -07002774 /* Kill the kernel thread for this host */
2775 if (ha->dpc_thread) {
2776 struct task_struct *t = ha->dpc_thread;
2777
2778 /*
2779 * qla2xxx_wake_dpc checks for ->dpc_thread
2780 * so we need to zero it out.
2781 */
2782 ha->dpc_thread = NULL;
2783 kthread_stop(t);
2784 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002785 qlt_remove_target(ha, base_vha);
Andrew Vasquezb9978762009-03-24 09:08:05 -07002786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 scsi_host_put(base_vha->host);
2796
Giridhar Malavalia9083012010-04-12 17:59:55 -07002797 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002798 qla82xx_idc_lock(ha);
2799 qla82xx_clear_drv_active(ha);
2800 qla82xx_idc_unlock(ha);
2801
Giridhar Malavalia9083012010-04-12 17:59:55 -07002802 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2803 if (!ql2xdbwr)
2804 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2805 } else {
2806 if (ha->iobase)
2807 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808
Giridhar Malavalia9083012010-04-12 17:59:55 -07002809 if (ha->mqiobase)
2810 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002811
2812 if (IS_QLA83XX(ha) && ha->msixbase)
2813 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002814 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 pci_release_selected_regions(ha->pdev, ha->bars);
2817 kfree(ha);
2818 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002820 pci_disable_pcie_error_reporting(pdev);
2821
Bernhard Walle665db932007-03-28 00:49:49 +02002822 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 pci_set_drvdata(pdev, NULL);
2824}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830
Andrew Vasquez85880802009-12-15 21:29:46 -08002831 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2832
2833 /* Disable timer */
2834 if (vha->timer_active)
2835 qla2x00_stop_timer(vha);
2836
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002837 qla2x00_stop_dpc_thread(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08002838
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002839 qla25xx_delete_queues(vha);
2840
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002841 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002843
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002844 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002845 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002846
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002847 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
Andrew Vasquez85880802009-12-15 21:29:46 -08002850 vha->flags.online = 0;
2851
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002852 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002853 if (ha->interrupts_on) {
2854 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002855 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002856 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 qla2x00_free_irqs(vha);
2859
Chad Dupuis88670482010-07-23 15:28:30 +05002860 qla2x00_free_fcports(vha);
2861
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002862 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002863
Giridhar Malavali08de2842011-08-16 11:31:44 -07002864 qla82xx_md_free(vha);
2865
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002866 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867}
2868
Chad Dupuis88670482010-07-23 15:28:30 +05002869void qla2x00_free_fcports(struct scsi_qla_host *vha)
2870{
2871 fc_port_t *fcport, *tfcport;
2872
2873 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2874 list_del(&fcport->list);
2875 kfree(fcport);
2876 fcport = NULL;
2877 }
2878}
2879
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002880static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002882 int defer)
2883{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002884 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002885 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002886 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002887
2888 if (!fcport->rport)
2889 return;
2890
2891 rport = fcport->rport;
2892 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002893 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002894 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002895 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002896 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002897 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2898 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002899 } else {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002900 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002901 qlt_fc_port_deleted(vha, fcport);
2902 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002903}
2904
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2907 *
2908 * Input: ha = adapter block pointer. fcport = port structure pointer.
2909 *
2910 * Return: None.
2911 *
2912 * Context:
2913 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002915 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002917 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002918 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002919 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 qla2x00_schedule_rport_del(vha, fcport, defer);
2921 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002922 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 * We may need to retry the login, so don't change the state of the
2924 * port but do the retries.
2925 */
2926 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07002927 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
2929 if (!do_login)
2930 return;
2931
2932 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 fcport->login_retry = vha->hw->login_retry_count;
2934 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002936 ql_dbg(ql_dbg_disc, vha, 0x2067,
2937 "Port login retry "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 "%02x%02x%02x%02x%02x%02x%02x%02x, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002939 "id = 0x%04x retry cnt=%d.\n",
2940 fcport->port_name[0], fcport->port_name[1],
2941 fcport->port_name[2], fcport->port_name[3],
2942 fcport->port_name[4], fcport->port_name[5],
2943 fcport->port_name[6], fcport->port_name[7],
2944 fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 }
2946}
2947
2948/*
2949 * qla2x00_mark_all_devices_lost
2950 * Updates fcport state when device goes offline.
2951 *
2952 * Input:
2953 * ha = adapter block pointer.
2954 * fcport = port structure pointer.
2955 *
2956 * Return:
2957 * None.
2958 *
2959 * Context:
2960 */
2961void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963{
2964 fc_port_t *fcport;
2965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002967 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002969
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 /*
2971 * No point in marking the device as lost, if the device is
2972 * already DEAD.
2973 */
2974 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2975 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002977 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002978 if (defer)
2979 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002980 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002981 qla2x00_schedule_rport_del(vha, fcport, defer);
2982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 }
2984}
2985
2986/*
2987* qla2x00_mem_alloc
2988* Allocates adapter memory.
2989*
2990* Returns:
2991* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002992* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002994static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002995qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2996 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997{
2998 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Andrew Vasqueze8711082008-01-31 12:33:48 -08003000 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003002 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003005 if (qlt_mem_alloc(ha) < 0)
3006 goto fail_free_init_cb;
3007
Chad Dupuis642ef982012-02-09 11:15:57 -08003008 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3009 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003011 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
Andrew Vasqueze8711082008-01-31 12:33:48 -08003013 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3014 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Giridhar Malavalia9083012010-04-12 17:59:55 -07003017 if (IS_QLA82XX(ha)) {
3018 /* Allocate cache for CT6 Ctx. */
3019 if (!ctx_cachep) {
3020 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3021 sizeof(struct ct6_dsd), 0,
3022 SLAB_HWCACHE_ALIGN, NULL);
3023 if (!ctx_cachep)
3024 goto fail_free_gid_list;
3025 }
3026 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3027 ctx_cachep);
3028 if (!ha->ctx_mempool)
3029 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003030 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3031 "ctx_cachep=%p ctx_mempool=%p.\n",
3032 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003033 }
3034
Andrew Vasqueze8711082008-01-31 12:33:48 -08003035 /* Get memory for cached NVRAM */
3036 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3037 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003038 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3041 ha->pdev->device);
3042 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3043 DMA_POOL_SIZE, 8, 0);
3044 if (!ha->s_dma_pool)
3045 goto fail_free_nvram;
3046
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003047 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3048 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3049 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3050
Arun Easibad75002010-05-04 15:01:30 -07003051 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003052 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3053 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3054 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003055 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3056 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003057 goto fail_s_dma_pool;
3058 }
3059
3060 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3061 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3062 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003063 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3064 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003065 goto fail_dl_dma_pool;
3066 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003067 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3068 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3069 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003070 }
3071
Andrew Vasqueze8711082008-01-31 12:33:48 -08003072 /* Allocate memory for SNS commands */
3073 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003074 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003075 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003077 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003079 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003080 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003081 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003083 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003085 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003086 goto fail_dma_pool;
3087 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003088 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003089 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003090 if (!ha->ct_sns)
3091 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003092 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3093 "ms_iocb=%p ct_sns=%p.\n",
3094 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 }
3096
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003097 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003098 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3099 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003100 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3101 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003102 goto fail_req;
3103 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003104 (*req)->length = req_len;
3105 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3106 ((*req)->length + 1) * sizeof(request_t),
3107 &(*req)->dma, GFP_KERNEL);
3108 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003109 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3110 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111 goto fail_req_ring;
3112 }
3113 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003114 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3115 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003116 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3117 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 goto fail_rsp;
3119 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003120 (*rsp)->hw = ha;
3121 (*rsp)->length = rsp_len;
3122 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3123 ((*rsp)->length + 1) * sizeof(response_t),
3124 &(*rsp)->dma, GFP_KERNEL);
3125 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003126 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3127 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128 goto fail_rsp_ring;
3129 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003130 (*req)->rsp = *rsp;
3131 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003132 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3133 "req=%p req->length=%d req->ring=%p rsp=%p "
3134 "rsp->length=%d rsp->ring=%p.\n",
3135 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3136 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003137 /* Allocate memory for NVRAM data for vports */
3138 if (ha->nvram_npiv_size) {
3139 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003140 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003141 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003142 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3143 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003144 goto fail_npiv_info;
3145 }
3146 } else
3147 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003149 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003150 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003151 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3152 &ha->ex_init_cb_dma);
3153 if (!ha->ex_init_cb)
3154 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003155 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3156 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003157 }
3158
Giridhar Malavalia9083012010-04-12 17:59:55 -07003159 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3160
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003161 /* Get consistent memory allocated for Async Port-Database. */
3162 if (!IS_FWI2_CAPABLE(ha)) {
3163 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3164 &ha->async_pd_dma);
3165 if (!ha->async_pd)
3166 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003167 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3168 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003169 }
3170
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 INIT_LIST_HEAD(&ha->vp_list);
3172 return 1;
3173
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003174fail_async_pd:
3175 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003176fail_ex_init_cb:
3177 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003178fail_npiv_info:
3179 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3180 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3181 (*rsp)->ring = NULL;
3182 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003184 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003185fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003186 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3187 sizeof(request_t), (*req)->ring, (*req)->dma);
3188 (*req)->ring = NULL;
3189 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003191 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192fail_req:
3193 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3194 ha->ct_sns, ha->ct_sns_dma);
3195 ha->ct_sns = NULL;
3196 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003197fail_free_ms_iocb:
3198 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3199 ha->ms_iocb = NULL;
3200 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003201fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003202 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003203 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3204 ha->fcp_cmnd_dma_pool = NULL;
3205 }
3206fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07003207 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003208 dma_pool_destroy(ha->dl_dma_pool);
3209 ha->dl_dma_pool = NULL;
3210 }
3211fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 dma_pool_destroy(ha->s_dma_pool);
3213 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003214fail_free_nvram:
3215 kfree(ha->nvram);
3216 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003217fail_free_ctx_mempool:
3218 mempool_destroy(ha->ctx_mempool);
3219 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003220fail_free_srb_mempool:
3221 mempool_destroy(ha->srb_mempool);
3222 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003223fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08003224 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3225 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003226 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003227 ha->gid_list = NULL;
3228 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003229fail_free_tgt_mem:
3230 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231fail_free_init_cb:
3232 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3233 ha->init_cb_dma);
3234 ha->init_cb = NULL;
3235 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08003236fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003237 ql_log(ql_log_fatal, NULL, 0x0030,
3238 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08003239 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240}
3241
3242/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003243* qla2x00_free_fw_dump
3244* Frees fw dump stuff.
3245*
3246* Input:
3247* ha = adapter block pointer.
3248*/
3249static void
3250qla2x00_free_fw_dump(struct qla_hw_data *ha)
3251{
3252 if (ha->fce)
3253 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3254 ha->fce_dma);
3255
3256 if (ha->fw_dump) {
3257 if (ha->eft)
3258 dma_free_coherent(&ha->pdev->dev,
3259 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3260 vfree(ha->fw_dump);
3261 }
3262 ha->fce = NULL;
3263 ha->fce_dma = 0;
3264 ha->eft = NULL;
3265 ha->eft_dma = 0;
3266 ha->fw_dump = NULL;
3267 ha->fw_dumped = 0;
3268 ha->fw_dump_reading = 0;
3269}
3270
3271/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272* qla2x00_mem_free
3273* Frees all adapter allocated memory.
3274*
3275* Input:
3276* ha = adapter block pointer.
3277*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003278static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003281 qla2x00_free_fw_dump(ha);
3282
Andrew Vasqueze8711082008-01-31 12:33:48 -08003283 if (ha->srb_mempool)
3284 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003286 if (ha->dcbx_tlv)
3287 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3288 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3289
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003290 if (ha->xgmac_data)
3291 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3292 ha->xgmac_data, ha->xgmac_data_dma);
3293
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 if (ha->sns_cmd)
3295 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003296 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
3298 if (ha->ct_sns)
3299 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
Andrew Vasquez88729e52006-06-23 16:10:50 -07003302 if (ha->sfp_data)
3303 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3304
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 if (ha->ms_iocb)
3306 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3307
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003308 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003309 dma_pool_free(ha->s_dma_pool,
3310 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003311
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003312 if (ha->async_pd)
3313 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3314
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 if (ha->s_dma_pool)
3316 dma_pool_destroy(ha->s_dma_pool);
3317
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08003319 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3320 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
Giridhar Malavalia9083012010-04-12 17:59:55 -07003322 if (IS_QLA82XX(ha)) {
3323 if (!list_empty(&ha->gbl_dsd_list)) {
3324 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3325
3326 /* clean up allocated prev pool */
3327 list_for_each_entry_safe(dsd_ptr,
3328 tdsd_ptr, &ha->gbl_dsd_list, list) {
3329 dma_pool_free(ha->dl_dma_pool,
3330 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3331 list_del(&dsd_ptr->list);
3332 kfree(dsd_ptr);
3333 }
3334 }
3335 }
3336
3337 if (ha->dl_dma_pool)
3338 dma_pool_destroy(ha->dl_dma_pool);
3339
3340 if (ha->fcp_cmnd_dma_pool)
3341 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3342
3343 if (ha->ctx_mempool)
3344 mempool_destroy(ha->ctx_mempool);
3345
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003346 qlt_mem_free(ha);
3347
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 if (ha->init_cb)
3349 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003350 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 vfree(ha->optrom_buffer);
3352 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003353 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08003354 kfree(ha->swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
Andrew Vasqueze8711082008-01-31 12:33:48 -08003356 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003357 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 ha->sns_cmd = NULL;
3359 ha->sns_cmd_dma = 0;
3360 ha->ct_sns = NULL;
3361 ha->ct_sns_dma = 0;
3362 ha->ms_iocb = NULL;
3363 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 ha->init_cb = NULL;
3365 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003366 ha->ex_init_cb = NULL;
3367 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003368 ha->async_pd = NULL;
3369 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003372 ha->dl_dma_pool = NULL;
3373 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 ha->gid_list = NULL;
3376 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003377
3378 ha->tgt.atio_ring = NULL;
3379 ha->tgt.atio_dma = 0;
3380 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381}
3382
3383struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3384 struct qla_hw_data *ha)
3385{
3386 struct Scsi_Host *host;
3387 struct scsi_qla_host *vha = NULL;
3388
3389 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3390 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003391 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3392 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003393 goto fail;
3394 }
3395
3396 /* Clear our data area */
3397 vha = shost_priv(host);
3398 memset(vha, 0, sizeof(scsi_qla_host_t));
3399
3400 vha->host = host;
3401 vha->host_no = host->host_no;
3402 vha->hw = ha;
3403
3404 INIT_LIST_HEAD(&vha->vp_fcports);
3405 INIT_LIST_HEAD(&vha->work_list);
3406 INIT_LIST_HEAD(&vha->list);
3407
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003408 spin_lock_init(&vha->work_lock);
3409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003411 ql_dbg(ql_dbg_init, vha, 0x0041,
3412 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3413 vha->host, vha->hw, vha,
3414 dev_name(&(ha->pdev->dev)));
3415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 return vha;
3417
3418fail:
3419 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420}
3421
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003422static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003423qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003424{
3425 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003426 uint8_t bail;
3427
3428 QLA_VHA_MARK_BUSY(vha, bail);
3429 if (bail)
3430 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003431
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003432 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003433 if (!e) {
3434 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003435 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003436 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003437
3438 INIT_LIST_HEAD(&e->list);
3439 e->type = type;
3440 e->flags = QLA_EVT_FLAG_FREE;
3441 return e;
3442}
3443
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003444static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003445qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003446{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003447 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003448
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003449 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003451 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003452 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003453
Andrew Vasquez0971de72008-04-03 13:13:18 -07003454 return QLA_SUCCESS;
3455}
3456
3457int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003458qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003459 u32 data)
3460{
3461 struct qla_work_evt *e;
3462
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003463 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003464 if (!e)
3465 return QLA_FUNCTION_FAILED;
3466
3467 e->u.aen.code = code;
3468 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003469 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003470}
3471
Andrew Vasquez8a659572009-02-08 20:50:12 -08003472int
3473qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3474{
3475 struct qla_work_evt *e;
3476
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003477 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003478 if (!e)
3479 return QLA_FUNCTION_FAILED;
3480
3481 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003482 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003483}
3484
Andrew Vasquezac280b62009-08-20 11:06:05 -07003485#define qla2x00_post_async_work(name, type) \
3486int qla2x00_post_async_##name##_work( \
3487 struct scsi_qla_host *vha, \
3488 fc_port_t *fcport, uint16_t *data) \
3489{ \
3490 struct qla_work_evt *e; \
3491 \
3492 e = qla2x00_alloc_work(vha, type); \
3493 if (!e) \
3494 return QLA_FUNCTION_FAILED; \
3495 \
3496 e->u.logio.fcport = fcport; \
3497 if (data) { \
3498 e->u.logio.data[0] = data[0]; \
3499 e->u.logio.data[1] = data[1]; \
3500 } \
3501 return qla2x00_post_work(vha, e); \
3502}
3503
3504qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3505qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3506qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3507qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003508qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3509qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003510
Andrew Vasquez3420d362009-10-13 15:16:45 -07003511int
3512qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3513{
3514 struct qla_work_evt *e;
3515
3516 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3517 if (!e)
3518 return QLA_FUNCTION_FAILED;
3519
3520 e->u.uevent.code = code;
3521 return qla2x00_post_work(vha, e);
3522}
3523
3524static void
3525qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3526{
3527 char event_string[40];
3528 char *envp[] = { event_string, NULL };
3529
3530 switch (code) {
3531 case QLA_UEVENT_CODE_FW_DUMP:
3532 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3533 vha->host_no);
3534 break;
3535 default:
3536 /* do nothing */
3537 break;
3538 }
3539 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3540}
3541
Andrew Vasquezac280b62009-08-20 11:06:05 -07003542void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003544{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003545 struct qla_work_evt *e, *tmp;
3546 unsigned long flags;
3547 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003548
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003549 spin_lock_irqsave(&vha->work_lock, flags);
3550 list_splice_init(&vha->work_list, &work);
3551 spin_unlock_irqrestore(&vha->work_lock, flags);
3552
3553 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003554 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003555
3556 switch (e->type) {
3557 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003559 e->u.aen.code, e->u.aen.data);
3560 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003561 case QLA_EVT_IDC_ACK:
3562 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3563 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003564 case QLA_EVT_ASYNC_LOGIN:
3565 qla2x00_async_login(vha, e->u.logio.fcport,
3566 e->u.logio.data);
3567 break;
3568 case QLA_EVT_ASYNC_LOGIN_DONE:
3569 qla2x00_async_login_done(vha, e->u.logio.fcport,
3570 e->u.logio.data);
3571 break;
3572 case QLA_EVT_ASYNC_LOGOUT:
3573 qla2x00_async_logout(vha, e->u.logio.fcport);
3574 break;
3575 case QLA_EVT_ASYNC_LOGOUT_DONE:
3576 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3577 e->u.logio.data);
3578 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003579 case QLA_EVT_ASYNC_ADISC:
3580 qla2x00_async_adisc(vha, e->u.logio.fcport,
3581 e->u.logio.data);
3582 break;
3583 case QLA_EVT_ASYNC_ADISC_DONE:
3584 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3585 e->u.logio.data);
3586 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003587 case QLA_EVT_UEVENT:
3588 qla2x00_uevent_emit(vha, e->u.uevent.code);
3589 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003590 }
3591 if (e->flags & QLA_EVT_FLAG_FREE)
3592 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003593
3594 /* For each work completed decrement vha ref count */
3595 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003596 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003597}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003599/* Relogins all the fcports of a vport
3600 * Context: dpc thread
3601 */
3602void qla2x00_relogin(struct scsi_qla_host *vha)
3603{
3604 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003605 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003606 uint16_t next_loopid = 0;
3607 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003608 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003609
3610 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3611 /*
3612 * If the port is not ONLINE then try to login
3613 * to it if we haven't run out of retries.
3614 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003615 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3616 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003617 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003619 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003620 ha->isp_ops->fabric_logout(vha,
3621 fcport->loop_id,
3622 fcport->d_id.b.domain,
3623 fcport->d_id.b.area,
3624 fcport->d_id.b.al_pa);
3625
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003626 if (fcport->loop_id == FC_NO_LOOP_ID) {
3627 fcport->loop_id = next_loopid =
3628 ha->min_external_loopid;
3629 status = qla2x00_find_new_loop_id(
3630 vha, fcport);
3631 if (status != QLA_SUCCESS) {
3632 /* Ran out of IDs to use */
3633 break;
3634 }
3635 }
3636
Andrew Vasquezac280b62009-08-20 11:06:05 -07003637 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003638 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003639 data[0] = 0;
3640 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3641 status = qla2x00_post_async_login_work(
3642 vha, fcport, data);
3643 if (status == QLA_SUCCESS)
3644 continue;
3645 /* Attempt a retry. */
3646 status = 1;
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003647 } else {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003648 status = qla2x00_fabric_login(vha,
3649 fcport, &next_loopid);
Saurav Kashyapaaf4d3e2012-04-25 07:26:16 -07003650 if (status == QLA_SUCCESS) {
3651 int status2;
3652 uint8_t opts;
3653
3654 opts = 0;
3655 if (fcport->flags &
3656 FCF_FCP2_DEVICE)
3657 opts |= BIT_1;
3658 status2 =
3659 qla2x00_get_port_database(
3660 vha, fcport,
3661 opts);
3662 if (status2 != QLA_SUCCESS)
3663 status = 1;
3664 }
3665 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003666 } else
3667 status = qla2x00_local_device_login(vha,
3668 fcport);
3669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003670 if (status == QLA_SUCCESS) {
3671 fcport->old_loop_id = fcport->loop_id;
3672
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003673 ql_dbg(ql_dbg_disc, vha, 0x2003,
3674 "Port login OK: logged in ID 0x%x.\n",
3675 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003676
3677 qla2x00_update_fcport(vha, fcport);
3678
3679 } else if (status == 1) {
3680 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3681 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003682 ql_dbg(ql_dbg_disc, vha, 0x2007,
3683 "Retrying %d login again loop_id 0x%x.\n",
3684 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003685 } else {
3686 fcport->login_retry = 0;
3687 }
3688
3689 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3690 fcport->loop_id = FC_NO_LOOP_ID;
3691 }
3692 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3693 break;
3694 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003695}
3696
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697/**************************************************************************
3698* qla2x00_do_dpc
3699* This kernel thread is a task that is schedule by the interrupt handler
3700* to perform the background processing for interrupts.
3701*
3702* Notes:
3703* This task always run in the context of a kernel thread. It
3704* is kick-off by the driver's detect code and starts up
3705* up one per adapter. It immediately goes to sleep and waits for
3706* some fibre event. When either the interrupt handler or
3707* the timer routine detects a event it will one of the task
3708* bits then wake us up.
3709**************************************************************************/
3710static int
3711qla2x00_do_dpc(void *data)
3712{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003713 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003714 scsi_qla_host_t *base_vha;
3715 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08003716
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003717 ha = (struct qla_hw_data *)data;
3718 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 set_user_nice(current, -20);
3721
James Bottomley563585e2011-01-27 16:12:37 -05003722 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01003723 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003724 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
3725 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726
Christoph Hellwig39a11242006-02-14 18:46:22 +01003727 schedule();
3728 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003730 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
3731 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732
Andrew Vasquez85880802009-12-15 21:29:46 -08003733 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003734 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
3735 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003736 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08003737 }
3738
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 ha->dpc_active = 1;
3740
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003741 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
3742 "DPC handler waking up, dpc_flags=0x%lx.\n",
3743 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003745 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003746
Giridhar Malavalia9083012010-04-12 17:59:55 -07003747 if (IS_QLA82XX(ha)) {
3748 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3749 &base_vha->dpc_flags)) {
3750 qla82xx_idc_lock(ha);
3751 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3752 QLA82XX_DEV_FAILED);
3753 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003754 ql_log(ql_log_info, base_vha, 0x4004,
3755 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003756 qla82xx_device_state_handler(base_vha);
3757 continue;
3758 }
3759
3760 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3761 &base_vha->dpc_flags)) {
3762
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003763 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
3764 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003765 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3766 &base_vha->dpc_flags))) {
3767 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3768 /* FCoE-ctx reset failed.
3769 * Escalate to chip-reset
3770 */
3771 set_bit(ISP_ABORT_NEEDED,
3772 &base_vha->dpc_flags);
3773 }
3774 clear_bit(ABORT_ISP_ACTIVE,
3775 &base_vha->dpc_flags);
3776 }
3777
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003778 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
3779 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003780 }
3781 }
3782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3784 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003786 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
3787 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003789 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
Giridhar Malavalia9083012010-04-12 17:59:55 -07003791 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 /* failed. retry later */
3793 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003794 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796 clear_bit(ABORT_ISP_ACTIVE,
3797 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08003798 }
3799
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003800 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
3801 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 }
3803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003804 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3805 qla2x00_update_fcports(base_vha);
3806 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003807 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003808
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003809 if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
3810 int ret;
3811 ret = qla2x00_send_change_request(base_vha, 0x3, 0);
3812 if (ret != QLA_SUCCESS)
3813 ql_log(ql_log_warn, base_vha, 0x121,
3814 "Failed to enable receiving of RSCN "
3815 "requests: 0x%x.\n", ret);
3816 clear_bit(SCR_PENDING, &base_vha->dpc_flags);
3817 }
3818
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003819 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003820 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
3821 "Quiescence mode scheduled.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003822 qla82xx_device_state_handler(base_vha);
3823 clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
3824 if (!ha->flags.quiesce_owner) {
3825 qla2x00_perform_loop_resync(base_vha);
3826
3827 qla82xx_idc_lock(ha);
3828 qla82xx_clear_qsnt_ready(base_vha);
3829 qla82xx_idc_unlock(ha);
3830 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003831 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
3832 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003833 }
3834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3836 &base_vha->dpc_flags) &&
3837 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003839 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
3840 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841 qla2x00_rst_aen(base_vha);
3842 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003843 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
3844 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
3846
3847 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 if ((test_and_clear_bit(RELOGIN_NEEDED,
3849 &base_vha->dpc_flags)) &&
3850 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3851 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003853 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
3854 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003855 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003856 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
3857 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 }
3859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003860 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3861 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003863 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
3864 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865
3866 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003867 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003869 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003871 clear_bit(LOOP_RESYNC_ACTIVE,
3872 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 }
3874
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003875 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
3876 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 }
3878
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003879 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3880 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3881 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3882 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07003883 }
3884
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003886 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003888 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3889 &base_vha->dpc_flags))
3890 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003892 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003893
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003895end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05003896 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05003898 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003900 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
3901 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902
3903 /*
3904 * Make sure that nobody tries to wake us up again.
3905 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 ha->dpc_active = 0;
3907
Andrew Vasquezac280b62009-08-20 11:06:05 -07003908 /* Cleanup any residual CTX SRBs. */
3909 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3910
Christoph Hellwig39a11242006-02-14 18:46:22 +01003911 return 0;
3912}
3913
3914void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003916{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003918 struct task_struct *t = ha->dpc_thread;
3919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003920 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003921 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922}
3923
3924/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925* qla2x00_rst_aen
3926* Processes asynchronous reset.
3927*
3928* Input:
3929* ha = adapter block pointer.
3930*/
3931static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003932qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934 if (vha->flags.online && !vha->flags.reset_active &&
3935 !atomic_read(&vha->loop_down_timer) &&
3936 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003938 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939
3940 /*
3941 * Issue marker command only when we are going to start
3942 * the I/O.
3943 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003944 vha->marker_needed = 1;
3945 } while (!atomic_read(&vha->loop_down_timer) &&
3946 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 }
3948}
3949
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950/**************************************************************************
3951* qla2x00_timer
3952*
3953* Description:
3954* One second timer
3955*
3956* Context: Interrupt
3957***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003958void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003959qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 int start_dpc = 0;
3963 int index;
3964 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08003965 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003967 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003968
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003969 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003970 ql_dbg(ql_dbg_timer, vha, 0x6000,
3971 "EEH = %d, restarting timer.\n",
3972 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003973 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3974 return;
3975 }
3976
Andrew Vasquez85880802009-12-15 21:29:46 -08003977 /* Hardware read to raise pending EEH errors during mailbox waits. */
3978 if (!pci_channel_offline(ha->pdev))
3979 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003981 /* Make sure qla82xx_watchdog is run only for physical port */
3982 if (!vha->vp_idx && IS_QLA82XX(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003983 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
3984 start_dpc++;
3985 qla82xx_watchdog(vha);
3986 }
3987
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003990 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
3991 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003992 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003994 if (atomic_read(&vha->loop_down_timer) ==
3995 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003997 ql_log(ql_log_info, vha, 0x6008,
3998 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004000 if (!IS_QLA2100(ha) && vha->link_down_timeout)
4001 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004003 /*
4004 * Schedule an ISP abort to return any FCP2-device
4005 * commands.
4006 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004007 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004009 spin_lock_irqsave(&ha->hardware_lock,
4010 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004011 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004012 for (index = 1;
4013 index < MAX_OUTSTANDING_COMMANDS;
4014 index++) {
4015 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05004016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004017 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004018 if (!sp)
4019 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08004020 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07004021 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004022 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004023 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004024 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004026 if (IS_QLA82XX(ha))
4027 set_bit(FCOE_CTX_RESET_NEEDED,
4028 &vha->dpc_flags);
4029 else
4030 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004031 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004032 break;
4033 }
4034 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 start_dpc++;
4038 }
4039
4040 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004041 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004042 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004043 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 "Loop down - aborting ISP.\n");
4045
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07004046 if (IS_QLA82XX(ha))
4047 set_bit(FCOE_CTX_RESET_NEEDED,
4048 &vha->dpc_flags);
4049 else
4050 set_bit(ISP_ABORT_NEEDED,
4051 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 }
4053 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004054 ql_dbg(ql_dbg_timer, vha, 0x600a,
4055 "Loop down - seconds remaining %d.\n",
4056 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 }
4058
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07004059 /* Check if beacon LED needs to be blinked for physical host only */
4060 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07004061 /* There is no beacon_blink function for ISP82xx */
4062 if (!IS_QLA82XX(ha)) {
4063 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
4064 start_dpc++;
4065 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08004066 }
4067
Andrew Vasquez550bf572008-04-24 15:21:23 -07004068 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07004070 start_dpc++;
4071
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004073 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
4074 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
4075 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
4078 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07004079 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
4080 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004081 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004082 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
4083 ql_dbg(ql_dbg_timer, vha, 0x600b,
4084 "isp_abort_needed=%d loop_resync_needed=%d "
4085 "fcport_update_needed=%d start_dpc=%d "
4086 "reset_marker_needed=%d",
4087 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
4088 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
4089 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
4090 start_dpc,
4091 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
4092 ql_dbg(ql_dbg_timer, vha, 0x600c,
4093 "beacon_blink_needed=%d isp_unrecoverable=%d "
4094 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
4095 "relogin_needed=%d.\n",
4096 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
4097 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
4098 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
4099 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
4100 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004101 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004104 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105}
4106
Andrew Vasquez54333832005-11-09 15:49:04 -08004107/* Firmware interface routines. */
4108
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004109#define FW_BLOBS 10
Andrew Vasquez54333832005-11-09 15:49:04 -08004110#define FW_ISP21XX 0
4111#define FW_ISP22XX 1
4112#define FW_ISP2300 2
4113#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004114#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004115#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004116#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07004117#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004118#define FW_ISP2031 8
4119#define FW_ISP8031 9
Andrew Vasquez54333832005-11-09 15:49:04 -08004120
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004121#define FW_FILE_ISP21XX "ql2100_fw.bin"
4122#define FW_FILE_ISP22XX "ql2200_fw.bin"
4123#define FW_FILE_ISP2300 "ql2300_fw.bin"
4124#define FW_FILE_ISP2322 "ql2322_fw.bin"
4125#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004126#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004127#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07004128#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004129#define FW_FILE_ISP2031 "ql2600_fw.bin"
4130#define FW_FILE_ISP8031 "ql8300_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004131
Daniel Walkere1e82b62008-05-12 22:21:10 -07004132static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004133
4134static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004135 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
4136 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
4137 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
4138 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
4139 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004140 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004141 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004142 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004143 { .name = FW_FILE_ISP2031, },
4144 { .name = FW_FILE_ISP8031, },
Andrew Vasquez54333832005-11-09 15:49:04 -08004145};
4146
4147struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08004149{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004150 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08004151 struct fw_blob *blob;
4152
Andrew Vasquez54333832005-11-09 15:49:04 -08004153 if (IS_QLA2100(ha)) {
4154 blob = &qla_fw_blobs[FW_ISP21XX];
4155 } else if (IS_QLA2200(ha)) {
4156 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004157 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004158 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08004159 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004160 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004161 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08004162 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004163 } else if (IS_QLA25XX(ha)) {
4164 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004165 } else if (IS_QLA81XX(ha)) {
4166 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07004167 } else if (IS_QLA82XX(ha)) {
4168 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004169 } else if (IS_QLA2031(ha)) {
4170 blob = &qla_fw_blobs[FW_ISP2031];
4171 } else if (IS_QLA8031(ha)) {
4172 blob = &qla_fw_blobs[FW_ISP8031];
Dan Carpenter8a655222012-02-21 10:29:40 +03004173 } else {
4174 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08004175 }
4176
Daniel Walkere1e82b62008-05-12 22:21:10 -07004177 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004178 if (blob->fw)
4179 goto out;
4180
4181 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004182 ql_log(ql_log_warn, vha, 0x0063,
4183 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08004184 blob->fw = NULL;
4185 blob = NULL;
4186 goto out;
4187 }
4188
4189out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07004190 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004191 return blob;
4192}
4193
4194static void
4195qla2x00_release_firmware(void)
4196{
4197 int idx;
4198
Daniel Walkere1e82b62008-05-12 22:21:10 -07004199 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004200 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02004201 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07004202 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08004203}
4204
Seokmann Ju14e660e2007-09-20 14:07:36 -07004205static pci_ers_result_t
4206qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4207{
Andrew Vasquez85880802009-12-15 21:29:46 -08004208 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
4209 struct qla_hw_data *ha = vha->hw;
4210
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004211 ql_dbg(ql_dbg_aer, vha, 0x9000,
4212 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07004213
Seokmann Ju14e660e2007-09-20 14:07:36 -07004214 switch (state) {
4215 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08004216 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004217 return PCI_ERS_RESULT_CAN_RECOVER;
4218 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08004219 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004220 /* For ISP82XX complete any pending mailbox cmd */
4221 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004222 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08004223 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
4224 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004225 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004226 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004227 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004228 /* Return back all IOs */
4229 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004230 return PCI_ERS_RESULT_NEED_RESET;
4231 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08004232 ha->flags.pci_channel_io_perm_failure = 1;
4233 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004234 return PCI_ERS_RESULT_DISCONNECT;
4235 }
4236 return PCI_ERS_RESULT_NEED_RESET;
4237}
4238
4239static pci_ers_result_t
4240qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4241{
4242 int risc_paused = 0;
4243 uint32_t stat;
4244 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004245 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4246 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004247 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4248 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4249
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07004250 if (IS_QLA82XX(ha))
4251 return PCI_ERS_RESULT_RECOVERED;
4252
Seokmann Ju14e660e2007-09-20 14:07:36 -07004253 spin_lock_irqsave(&ha->hardware_lock, flags);
4254 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4255 stat = RD_REG_DWORD(&reg->hccr);
4256 if (stat & HCCR_RISC_PAUSE)
4257 risc_paused = 1;
4258 } else if (IS_QLA23XX(ha)) {
4259 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
4260 if (stat & HSR_RISC_PAUSED)
4261 risc_paused = 1;
4262 } else if (IS_FWI2_CAPABLE(ha)) {
4263 stat = RD_REG_DWORD(&reg24->host_status);
4264 if (stat & HSRX_RISC_PAUSED)
4265 risc_paused = 1;
4266 }
4267 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4268
4269 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004270 ql_log(ql_log_info, base_vha, 0x9003,
4271 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004272 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004273
4274 return PCI_ERS_RESULT_NEED_RESET;
4275 } else
4276 return PCI_ERS_RESULT_RECOVERED;
4277}
4278
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004279uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
4280{
4281 uint32_t rval = QLA_FUNCTION_FAILED;
4282 uint32_t drv_active = 0;
4283 struct qla_hw_data *ha = base_vha->hw;
4284 int fn;
4285 struct pci_dev *other_pdev = NULL;
4286
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004287 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
4288 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004289
4290 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4291
4292 if (base_vha->flags.online) {
4293 /* Abort all outstanding commands,
4294 * so as to be requeued later */
4295 qla2x00_abort_isp_cleanup(base_vha);
4296 }
4297
4298
4299 fn = PCI_FUNC(ha->pdev->devfn);
4300 while (fn > 0) {
4301 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004302 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
4303 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004304 other_pdev =
4305 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4306 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4307 fn));
4308
4309 if (!other_pdev)
4310 continue;
4311 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004312 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
4313 "Found PCI func available and enable at 0x%x.\n",
4314 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004315 pci_dev_put(other_pdev);
4316 break;
4317 }
4318 pci_dev_put(other_pdev);
4319 }
4320
4321 if (!fn) {
4322 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004323 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
4324 "This devfn is reset owner = 0x%x.\n",
4325 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004326 qla82xx_idc_lock(ha);
4327
4328 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4329 QLA82XX_DEV_INITIALIZING);
4330
4331 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
4332 QLA82XX_IDC_VERSION);
4333
4334 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004335 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
4336 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004337
4338 qla82xx_idc_unlock(ha);
4339 /* Reset if device is not already reset
4340 * drv_active would be 0 if a reset has already been done
4341 */
4342 if (drv_active)
4343 rval = qla82xx_start_firmware(base_vha);
4344 else
4345 rval = QLA_SUCCESS;
4346 qla82xx_idc_lock(ha);
4347
4348 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004349 ql_log(ql_log_info, base_vha, 0x900b,
4350 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004351 qla82xx_clear_drv_active(ha);
4352 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4353 QLA82XX_DEV_FAILED);
4354 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004355 ql_log(ql_log_info, base_vha, 0x900c,
4356 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004357 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4358 QLA82XX_DEV_READY);
4359 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08004360 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004361 rval = qla82xx_restart_isp(base_vha);
4362 qla82xx_idc_lock(ha);
4363 /* Clear driver state register */
4364 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
4365 qla82xx_set_drv_active(base_vha);
4366 }
4367 qla82xx_idc_unlock(ha);
4368 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004369 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
4370 "This devfn is not reset owner = 0x%x.\n",
4371 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004372 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
4373 QLA82XX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004374 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004375 rval = qla82xx_restart_isp(base_vha);
4376 qla82xx_idc_lock(ha);
4377 qla82xx_set_drv_active(base_vha);
4378 qla82xx_idc_unlock(ha);
4379 }
4380 }
4381 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4382
4383 return rval;
4384}
4385
Seokmann Ju14e660e2007-09-20 14:07:36 -07004386static pci_ers_result_t
4387qla2xxx_pci_slot_reset(struct pci_dev *pdev)
4388{
4389 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004390 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4391 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004392 struct rsp_que *rsp;
4393 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004394
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004395 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
4396 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004397
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004398 /* Workaround: qla2xxx driver which access hardware earlier
4399 * needs error state to be pci_channel_io_online.
4400 * Otherwise mailbox command timesout.
4401 */
4402 pdev->error_state = pci_channel_io_normal;
4403
4404 pci_restore_state(pdev);
4405
Richard Lary8c1496b2010-02-18 10:07:29 -08004406 /* pci_restore_state() clears the saved_state flag of the device
4407 * save restored state which resets saved_state flag
4408 */
4409 pci_save_state(pdev);
4410
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11004411 if (ha->mem_only)
4412 rc = pci_enable_device_mem(pdev);
4413 else
4414 rc = pci_enable_device(pdev);
4415
4416 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004417 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004418 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004419 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004420 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004421
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004422 rsp = ha->rsp_q_map[0];
4423 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004424 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004426 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004427 goto exit_slot_reset;
4428
4429 if (IS_QLA82XX(ha)) {
4430 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
4431 ret = PCI_ERS_RESULT_RECOVERED;
4432 goto exit_slot_reset;
4433 } else
4434 goto exit_slot_reset;
4435 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004436
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004437 while (ha->flags.mbox_busy && retries--)
4438 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08004439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004440 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004441 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07004442 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004443 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004444
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004445
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004446exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004447 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
4448 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08004449
Seokmann Ju14e660e2007-09-20 14:07:36 -07004450 return ret;
4451}
4452
4453static void
4454qla2xxx_pci_resume(struct pci_dev *pdev)
4455{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004456 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4457 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004458 int ret;
4459
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004460 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
4461 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004462
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004463 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004464 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004465 ql_log(ql_log_fatal, base_vha, 0x9002,
4466 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07004467 }
Andrew Vasquez85880802009-12-15 21:29:46 -08004468
Lalit Chandivade3e46f032010-05-04 15:01:23 -07004469 pci_cleanup_aer_uncorrect_error_status(pdev);
4470
Andrew Vasquez85880802009-12-15 21:29:46 -08004471 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004472}
4473
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07004474static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07004475 .error_detected = qla2xxx_pci_error_detected,
4476 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4477 .slot_reset = qla2xxx_pci_slot_reset,
4478 .resume = qla2xxx_pci_resume,
4479};
4480
Andrew Vasquez54333832005-11-09 15:49:04 -08004481static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004482 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4483 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4484 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4485 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4486 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4487 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4488 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4489 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4490 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004491 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004492 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4493 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004494 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004495 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004496 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004497 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Andrew Vasquez54333832005-11-09 15:49:04 -08004498 { 0 },
4499};
4500MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4501
Andrew Vasquezfca29702005-07-06 10:31:47 -07004502static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07004503 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06004504 .driver = {
4505 .owner = THIS_MODULE,
4506 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07004507 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004508 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08004509 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004510 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004511 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07004512};
4513
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004514static struct file_operations apidev_fops = {
4515 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02004516 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004517};
4518
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519/**
4520 * qla2x00_module_init - Module initialization.
4521 **/
4522static int __init
4523qla2x00_module_init(void)
4524{
Andrew Vasquezfca29702005-07-06 10:31:47 -07004525 int ret = 0;
4526
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004528 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09004529 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004531 ql_log(ql_log_fatal, NULL, 0x0001,
4532 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 return -ENOMEM;
4534 }
4535
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004536 /* Initialize target kmem_cache and mem_pools */
4537 ret = qlt_init();
4538 if (ret < 0) {
4539 kmem_cache_destroy(srb_cachep);
4540 return ret;
4541 } else if (ret > 0) {
4542 /*
4543 * If initiator mode is explictly disabled by qlt_init(),
4544 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
4545 * performing scsi_scan_target() during LOOP UP event.
4546 */
4547 qla2xxx_transport_functions.disable_target_scan = 1;
4548 qla2xxx_transport_vport_functions.disable_target_scan = 1;
4549 }
4550
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 /* Derive version string. */
4552 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07004553 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07004554 strcat(qla2x00_version_str, "-debug");
4555
Andrew Vasquez1c97a122005-04-21 16:13:36 -04004556 qla2xxx_transport_template =
4557 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004558 if (!qla2xxx_transport_template) {
4559 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004560 ql_log(ql_log_fatal, NULL, 0x0002,
4561 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004562 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004564 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004565
4566 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4567 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004568 ql_log(ql_log_fatal, NULL, 0x0003,
4569 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004570 }
4571
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004572 qla2xxx_transport_vport_template =
4573 fc_attach_transport(&qla2xxx_transport_vport_functions);
4574 if (!qla2xxx_transport_vport_template) {
4575 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004576 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004577 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004578 ql_log(ql_log_fatal, NULL, 0x0004,
4579 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004580 return -ENODEV;
4581 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004582 ql_log(ql_log_info, NULL, 0x0005,
4583 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07004584 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004585 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004586 if (ret) {
4587 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004588 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07004589 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004590 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004591 ql_log(ql_log_fatal, NULL, 0x0006,
4592 "pci_register_driver failed...ret=%d Failing load!.\n",
4593 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004594 }
4595 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596}
4597
4598/**
4599 * qla2x00_module_exit - Module cleanup.
4600 **/
4601static void __exit
4602qla2x00_module_exit(void)
4603{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004604 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004605 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08004606 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004607 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004608 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07004609 if (ctx_cachep)
4610 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004612 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613}
4614
4615module_init(qla2x00_module_init);
4616module_exit(qla2x00_module_exit);
4617
4618MODULE_AUTHOR("QLogic Corporation");
4619MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4620MODULE_LICENSE("GPL");
4621MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004622MODULE_FIRMWARE(FW_FILE_ISP21XX);
4623MODULE_FIRMWARE(FW_FILE_ISP22XX);
4624MODULE_FIRMWARE(FW_FILE_ISP2300);
4625MODULE_FIRMWARE(FW_FILE_ISP2322);
4626MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08004627MODULE_FIRMWARE(FW_FILE_ISP25XX);