blob: b3028f546848fefc2f2206ac10178224b589f7e9 [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
17#include <scsi/scsi_tcq.h>
18#include <scsi/scsicam.h>
19#include <scsi/scsi_transport.h>
20#include <scsi/scsi_transport_fc.h>
21
22/*
23 * Driver version
24 */
25char qla2x00_version_str[40];
26
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070027static int apidev_major;
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029/*
30 * SRB allocation cache
31 */
Christoph Lametere18b8902006-12-06 20:33:20 -080032static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Giridhar Malavalia9083012010-04-12 17:59:55 -070034/*
35 * CT6 CTX allocation cache
36 */
37static struct kmem_cache *ctx_cachep;
Saurav Kashyap3ce88662011-07-14 12:00:12 -070038/*
39 * error level for logging
40 */
41int ql_errlev = ql_log_all;
Giridhar Malavalia9083012010-04-12 17:59:55 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080044module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045MODULE_PARM_DESC(ql2xlogintimeout,
46 "Login timeout value in seconds.");
47
Andrew Vasqueza7b61842007-05-07 07:42:59 -070048int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080049module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070051 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 "a PORT-DOWN status.");
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054int ql2xplogiabsentdevice;
55module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
56MODULE_PARM_DESC(ql2xplogiabsentdevice,
57 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070058 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080062module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063MODULE_PARM_DESC(ql2xloginretrycount,
64 "Specify an alternate value for the NVRAM login retry count.");
65
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070066int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080067module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070068MODULE_PARM_DESC(ql2xallocfwdump,
69 "Option to enable allocation of memory for a firmware dump "
70 "during HBA initialization. Memory allocation requirements "
71 "vary by ISP type. Default is 1 - allocate memory.");
72
Andrew Vasquez11010fe2006-10-06 09:54:59 -070073int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070074module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070075MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070076 "Option to enable extended error logging,\n"
77 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
78 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
79 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
80 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
81 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
82 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
83 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
84 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
85 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080086 "\t\t0x1e400000 - Preferred value for capturing essential "
87 "debug information (equivalent to old "
88 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070089 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -070090
Giridhar Malavalia9083012010-04-12 17:59:55 -070091int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080092module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -070093MODULE_PARM_DESC(ql2xshiftctondsd,
94 "Set to control shifting of command type processing "
95 "based on total number of SG elements.");
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static void qla2x00_free_device(scsi_qla_host_t *);
98
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070099int ql2xfdmienable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800100module_param(ql2xfdmienable, int, S_IRUGO);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700101MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100102 "Enables FDMI registrations. "
103 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700104
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700105#define MAX_Q_DEPTH 32
106static int ql2xmaxqdepth = MAX_Q_DEPTH;
107module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
108MODULE_PARM_DESC(ql2xmaxqdepth,
109 "Maximum queue depth to report for target devices.");
110
Arun Easibad75002010-05-04 15:01:30 -0700111/* Do not change the value of this after module load */
Arun Easi8cb20492011-08-16 11:29:22 -0700112int ql2xenabledif = 0;
Arun Easibad75002010-05-04 15:01:30 -0700113module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
114MODULE_PARM_DESC(ql2xenabledif,
115 " Enable T10-CRC-DIF "
Arun Easi8cb20492011-08-16 11:29:22 -0700116 " Default is 0 - No DIF Support. 1 - Enable it"
117 ", 2 - Enable DIF for all types, except Type 0.");
Arun Easibad75002010-05-04 15:01:30 -0700118
Arun Easi8cb20492011-08-16 11:29:22 -0700119int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700120module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
121MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700122 " Enable T10-CRC-DIF Error isolation by HBA:\n"
123 " Default is 1.\n"
124 " 0 -- Error isolation disabled\n"
125 " 1 -- Error isolation enabled only for DIX Type 0\n"
126 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700127
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700128int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800129module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700130MODULE_PARM_DESC(ql2xiidmaenable,
131 "Enables iIDMA settings "
132 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
133
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800134int ql2xmaxqueues = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800135module_param(ql2xmaxqueues, int, S_IRUGO);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800136MODULE_PARM_DESC(ql2xmaxqueues,
137 "Enables MQ settings "
Joe Perchesae682302010-08-10 18:01:21 -0700138 "Default is 1 for single queue. Set it to number "
139 "of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700140
141int ql2xmultique_tag;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800142module_param(ql2xmultique_tag, int, S_IRUGO);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700143MODULE_PARM_DESC(ql2xmultique_tag,
144 "Enables CPU affinity settings for the driver "
145 "Default is 0 for no affinity of request and response IO. "
146 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700147
148int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700149module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700150MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700151 "Option to specify location from which to load ISP firmware:.\n"
152 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700153 " interface.\n"
154 " 1 -- load firmware from flash.\n"
155 " 0 -- use default semantics.\n");
156
Andrew Vasquezae97c912010-02-18 10:07:28 -0800157int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800158module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800159MODULE_PARM_DESC(ql2xetsenable,
160 "Enables firmware ETS burst."
161 "Default is 0 - skip ETS enablement.");
162
Giridhar Malavali69078692010-05-28 15:08:28 -0700163int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700164module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700165MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700166 "Option to specify scheme for request queue posting.\n"
167 " 0 -- Regular doorbell.\n"
168 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700169
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700170int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800171module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700172MODULE_PARM_DESC(ql2xtargetreset,
173 "Enable target reset."
174 "Default is 1 - use hw defaults.");
175
Chad Dupuis4da26e12010-10-15 11:27:40 -0700176int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800177module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700178MODULE_PARM_DESC(ql2xgffidenable,
179 "Enables GFF_ID checks of port type. "
180 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700181
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700182int ql2xasynctmfenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800183module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700184MODULE_PARM_DESC(ql2xasynctmfenable,
185 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
186 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700187
188int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700189module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700190MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700191 "Option to specify reset behaviour.\n"
192 " 0 (Default) -- Reset on failure.\n"
193 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700194
Andrew Vasquez82515922011-05-10 11:30:13 -0700195uint ql2xmaxlun = MAX_LUNS;
196module_param(ql2xmaxlun, uint, S_IRUGO);
197MODULE_PARM_DESC(ql2xmaxlun,
198 "Defines the maximum LU number to register with the SCSI "
199 "midlayer. Default is 65535.");
200
Giridhar Malavali08de2842011-08-16 11:31:44 -0700201int ql2xmdcapmask = 0x1F;
202module_param(ql2xmdcapmask, int, S_IRUGO);
203MODULE_PARM_DESC(ql2xmdcapmask,
204 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800205 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700206
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800207int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700208module_param(ql2xmdenable, int, S_IRUGO);
209MODULE_PARM_DESC(ql2xmdenable,
210 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800211 "0 - MiniDump disabled. "
212 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700215 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 */
217static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500218static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800219static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
220static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500221static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500222static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static int qla2xxx_eh_abort(struct scsi_cmnd *);
224static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700225static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
227static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Mike Christiee881a172009-10-15 17:46:39 -0700229static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700230static int qla2x00_change_queue_type(struct scsi_device *, int);
231
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700232struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700234 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700235 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700236
237 .eh_abort_handler = qla2xxx_eh_abort,
238 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700239 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700240 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
241 .eh_host_reset_handler = qla2xxx_eh_host_reset,
242
243 .slave_configure = qla2xxx_slave_configure,
244
245 .slave_alloc = qla2xxx_slave_alloc,
246 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700247 .scan_finished = qla2xxx_scan_finished,
248 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700249 .change_queue_depth = qla2x00_change_queue_depth,
250 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700251 .this_id = -1,
252 .cmd_per_lun = 3,
253 .use_clustering = ENABLE_CLUSTERING,
254 .sg_tablesize = SG_ALL,
255
256 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700257 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700258};
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700261struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/* TODO Convert to inlines
264 *
265 * Timer routines
266 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700268__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800269qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800271 init_timer(&vha->timer);
272 vha->timer.expires = jiffies + interval * HZ;
273 vha->timer.data = (unsigned long)vha;
274 vha->timer.function = (void (*)(unsigned long))func;
275 add_timer(&vha->timer);
276 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
279static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800280qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700282 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700283 if (vha->device_flags & DFLG_DEV_FAILED) {
284 ql_dbg(ql_dbg_timer, vha, 0x600d,
285 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700286 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700287 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800289 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Adrian Bunka824ebb2008-01-17 09:02:15 -0800292static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800293qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800295 del_timer_sync(&vha->timer);
296 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299static int qla2x00_do_dpc(void *data);
300
301static void qla2x00_rst_aen(scsi_qla_host_t *);
302
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800303static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
304 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700305static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306static void qla2x00_mem_free(struct qla_hw_data *);
307static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800310static int qla2x00_alloc_queues(struct qla_hw_data *ha)
311{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700312 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700313 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800314 GFP_KERNEL);
315 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_log(ql_log_fatal, vha, 0x003b,
317 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800318 goto fail_req_map;
319 }
320
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700321 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800322 GFP_KERNEL);
323 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700324 ql_log(ql_log_fatal, vha, 0x003c,
325 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800326 goto fail_rsp_map;
327 }
328 set_bit(0, ha->rsp_qid_map);
329 set_bit(0, ha->req_qid_map);
330 return 1;
331
332fail_rsp_map:
333 kfree(ha->req_q_map);
334 ha->req_q_map = NULL;
335fail_req_map:
336 return -ENOMEM;
337}
338
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700339static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800340{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800341 if (req && req->ring)
342 dma_free_coherent(&ha->pdev->dev,
343 (req->length + 1) * sizeof(request_t),
344 req->ring, req->dma);
345
346 kfree(req);
347 req = NULL;
348}
349
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700350static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
351{
352 if (rsp && rsp->ring)
353 dma_free_coherent(&ha->pdev->dev,
354 (rsp->length + 1) * sizeof(response_t),
355 rsp->ring, rsp->dma);
356
357 kfree(rsp);
358 rsp = NULL;
359}
360
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800361static void qla2x00_free_queues(struct qla_hw_data *ha)
362{
363 struct req_que *req;
364 struct rsp_que *rsp;
365 int cnt;
366
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700367 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800368 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700369 qla2x00_free_req_que(ha, req);
370 }
371 kfree(ha->req_q_map);
372 ha->req_q_map = NULL;
373
374 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
375 rsp = ha->rsp_q_map[cnt];
376 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800377 }
378 kfree(ha->rsp_q_map);
379 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800380}
381
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700382static int qla25xx_setup_mode(struct scsi_qla_host *vha)
383{
384 uint16_t options = 0;
385 int ques, req, ret;
386 struct qla_hw_data *ha = vha->hw;
387
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700388 if (!(ha->fw_attributes & BIT_6)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700389 ql_log(ql_log_warn, vha, 0x00d8,
390 "Firmware is not multi-queue capable.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700391 goto fail;
392 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700393 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700394 /* create a request queue for IO */
395 options |= BIT_7;
396 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
397 QLA_DEFAULT_QUE_QOS);
398 if (!req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700399 ql_log(ql_log_warn, vha, 0x00e0,
400 "Failed to create request queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700401 goto fail;
402 }
Tejun Heo278274d2011-02-01 11:42:42 +0100403 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700404 vha->req = ha->req_q_map[req];
405 options |= BIT_1;
406 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
407 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
408 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700409 ql_log(ql_log_warn, vha, 0x00e8,
410 "Failed to create response queue.\n");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700411 goto fail2;
412 }
413 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700414 ha->flags.cpu_affinity_enabled = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700415 ql_dbg(ql_dbg_multiq, vha, 0xc007,
416 "CPU affinity mode enalbed, "
417 "no. of response queues:%d no. of request queues:%d.\n",
418 ha->max_rsp_queues, ha->max_req_queues);
419 ql_dbg(ql_dbg_init, vha, 0x00e9,
420 "CPU affinity mode enalbed, "
421 "no. of response queues:%d no. of request queues:%d.\n",
422 ha->max_rsp_queues, ha->max_req_queues);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700423 }
424 return 0;
425fail2:
426 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700427 destroy_workqueue(ha->wq);
428 ha->wq = NULL;
Giridhar Malavali0cd33fc2011-11-18 09:02:12 -0800429 vha->req = ha->req_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700430fail:
431 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700432 kfree(ha->req_q_map);
433 kfree(ha->rsp_q_map);
434 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700435 return 1;
436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800439qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800441 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 static char *pci_bus_modes[] = {
443 "33", "66", "100", "133",
444 };
445 uint16_t pci_bus;
446
447 strcpy(str, "PCI");
448 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
449 if (pci_bus) {
450 strcat(str, "-X (");
451 strcat(str, pci_bus_modes[pci_bus]);
452 } else {
453 pci_bus = (ha->pci_attr & BIT_8) >> 8;
454 strcat(str, " (");
455 strcat(str, pci_bus_modes[pci_bus]);
456 }
457 strcat(str, " MHz)");
458
459 return (str);
460}
461
Andrew Vasquezfca29702005-07-06 10:31:47 -0700462static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800463qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700464{
465 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800466 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700467 uint32_t pci_bus;
468 int pcie_reg;
469
470 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
471 if (pcie_reg) {
472 char lwstr[6];
473 uint16_t pcie_lstat, lspeed, lwidth;
474
475 pcie_reg += 0x12;
476 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
477 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
478 lwidth = (pcie_lstat &
479 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
480
481 strcpy(str, "PCIe (");
482 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700483 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700484 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700485 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700486 else
487 strcat(str, "<unknown> ");
488 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
489 strcat(str, lwstr);
490
491 return str;
492 }
493
494 strcpy(str, "PCI");
495 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
496 if (pci_bus == 0 || pci_bus == 8) {
497 strcat(str, " (");
498 strcat(str, pci_bus_modes[pci_bus >> 3]);
499 } else {
500 strcat(str, "-X ");
501 if (pci_bus & BIT_2)
502 strcat(str, "Mode 2");
503 else
504 strcat(str, "Mode 1");
505 strcat(str, " (");
506 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
507 }
508 strcat(str, " MHz)");
509
510 return str;
511}
512
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800513static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
520 ha->fw_minor_version,
521 ha->fw_subminor_version);
522
523 if (ha->fw_attributes & BIT_9) {
524 strcat(str, "FLX");
525 return (str);
526 }
527
528 switch (ha->fw_attributes & 0xFF) {
529 case 0x7:
530 strcat(str, "EF");
531 break;
532 case 0x17:
533 strcat(str, "TP");
534 break;
535 case 0x37:
536 strcat(str, "IP");
537 break;
538 case 0x77:
539 strcat(str, "VI");
540 break;
541 default:
542 sprintf(un_str, "(%x)", ha->fw_attributes);
543 strcat(str, un_str);
544 break;
545 }
546 if (ha->fw_attributes & 0x100)
547 strcat(str, "X");
548
549 return (str);
550}
551
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800552static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800553qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700554{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700556
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800557 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
558 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700559 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700560}
561
562static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800564 struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700565{
566 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800567 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700568
569 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700570 if (!sp) {
571 ql_log(ql_log_warn, vha, 0x3006,
572 "Memory allocation failed for sp.\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700573 return sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700574 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700575
Giridhar Malavali083a4692010-05-28 15:08:18 -0700576 atomic_set(&sp->ref_count, 1);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700577 sp->fcport = fcport;
578 sp->cmd = cmd;
579 sp->flags = 0;
580 CMD_SP(cmd) = (void *)sp;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700581 sp->ctx = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700582
583 return sp;
584}
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800587qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700588{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700589 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700590 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400591 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592 struct qla_hw_data *ha = vha->hw;
593 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700594 srb_t *sp;
595 int rval;
596
Andrew Vasquez85880802009-12-15 21:29:46 -0800597 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700598 if (ha->flags.pci_channel_io_perm_failure) {
599 ql_dbg(ql_dbg_io, vha, 0x3001,
600 "PCI Channel IO permanent failure, exiting "
601 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700602 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700603 } else {
604 ql_dbg(ql_dbg_io, vha, 0x3002,
605 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800606 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700607 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700608 goto qc24_fail_command;
609 }
610
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400611 rval = fc_remote_port_chkready(rport);
612 if (rval) {
613 cmd->result = rval;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700614 ql_dbg(ql_dbg_io, vha, 0x3003,
615 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
616 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700617 goto qc24_fail_command;
618 }
619
Arun Easibad75002010-05-04 15:01:30 -0700620 if (!vha->flags.difdix_supported &&
621 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700622 ql_dbg(ql_dbg_io, vha, 0x3004,
623 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
624 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700625 cmd->result = DID_NO_CONNECT << 16;
626 goto qc24_fail_command;
627 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700628 if (atomic_read(&fcport->state) != FCS_ONLINE) {
629 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700630 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700631 ql_dbg(ql_dbg_io, vha, 0x3005,
632 "Returning DNC, fcport_state=%d loop_state=%d.\n",
633 atomic_read(&fcport->state),
634 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700635 cmd->result = DID_NO_CONNECT << 16;
636 goto qc24_fail_command;
637 }
Mike Christie7b594132008-08-17 15:24:40 -0500638 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700639 }
640
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800641 sp = qla2x00_get_new_sp(base_vha, fcport, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700642 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800643 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800645 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700646 if (rval != QLA_SUCCESS) {
647 ql_dbg(ql_dbg_io, vha, 0x3013,
648 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700649 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700651
Andrew Vasquezfca29702005-07-06 10:31:47 -0700652 return 0;
653
654qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800655 qla2x00_sp_free_dma(sp);
656 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700657
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800658qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700659 return SCSI_MLQUEUE_HOST_BUSY;
660
Mike Christie7b594132008-08-17 15:24:40 -0500661qc24_target_busy:
662 return SCSI_MLQUEUE_TARGET_BUSY;
663
Andrew Vasquezfca29702005-07-06 10:31:47 -0700664qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800665 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700666
667 return 0;
668}
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/*
671 * qla2x00_eh_wait_on_command
672 * Waits for the command to be returned by the Firmware for some
673 * max time.
674 *
675 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 *
678 * Return:
679 * Not Found : 0
680 * Found : 1
681 */
682static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800683qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700685#define ABORT_POLLING_PERIOD 1000
686#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500687 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800688 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
689 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500690 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Andrew Vasquez85880802009-12-15 21:29:46 -0800692 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700693 ql_dbg(ql_dbg_taskm, vha, 0x8005,
694 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800695 return ret;
696 }
697
Lalit Chandivaded9704322009-08-25 11:36:18 -0700698 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700699 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500700 }
701 if (CMD_SP(cmd))
702 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
f4f051e2005-04-17 15:02:26 -0500704 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
707/*
708 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700709 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 * <= MAX_RETRIES_OF_ISP_ABORT or
711 * finally HBA is disabled ie marked offline
712 *
713 * Input:
714 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700715 *
716 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 * Does context switching-Release SPIN_LOCK
718 * (if any) before calling this routine.
719 *
720 * Return:
721 * Success (Adapter is online) : 0
722 * Failed (Adapter is offline/disabled) : 1
723 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800724int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800725qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700727 int return_status;
728 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729 struct qla_hw_data *ha = vha->hw;
730 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700732 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800733 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
734 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
735 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
736 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 msleep(1000);
739 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700741 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 else
743 return_status = QLA_FUNCTION_FAILED;
744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 return (return_status);
746}
747
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700748/*
749 * qla2x00_wait_for_reset_ready
750 * Wait till the HBA is online after going through
751 * <= MAX_RETRIES_OF_ISP_ABORT or
752 * finally HBA is disabled ie marked offline or flash
753 * operations are in progress.
754 *
755 * Input:
756 * ha - pointer to host adapter structure
757 *
758 * Note:
759 * Does context switching-Release SPIN_LOCK
760 * (if any) before calling this routine.
761 *
762 * Return:
763 * Success (Adapter is online/no flash ops) : 0
764 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
765 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500766static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700767qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
768{
769 int return_status;
770 unsigned long wait_online;
771 struct qla_hw_data *ha = vha->hw;
772 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
773
774 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
775 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
776 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
777 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
778 ha->optrom_state != QLA_SWAITING ||
779 ha->dpc_active) && time_before(jiffies, wait_online))
780 msleep(1000);
781
782 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
783 return_status = QLA_SUCCESS;
784 else
785 return_status = QLA_FUNCTION_FAILED;
786
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700787 ql_dbg(ql_dbg_taskm, vha, 0x8019,
788 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700789
790 return return_status;
791}
792
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700793int
794qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
795{
796 int return_status;
797 unsigned long wait_reset;
798 struct qla_hw_data *ha = vha->hw;
799 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
800
801 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
802 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
803 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
804 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
805 ha->dpc_active) && time_before(jiffies, wait_reset)) {
806
807 msleep(1000);
808
809 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
810 ha->flags.chip_reset_done)
811 break;
812 }
813 if (ha->flags.chip_reset_done)
814 return_status = QLA_SUCCESS;
815 else
816 return_status = QLA_FUNCTION_FAILED;
817
818 return return_status;
819}
820
Giridhar Malavali083a4692010-05-28 15:08:18 -0700821static void
822sp_get(struct srb *sp)
823{
824 atomic_inc(&sp->ref_count);
825}
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827/**************************************************************************
828* qla2xxx_eh_abort
829*
830* Description:
831* The abort function will abort the specified command.
832*
833* Input:
834* cmd = Linux SCSI command packet to be aborted.
835*
836* Returns:
837* Either SUCCESS or FAILED.
838*
839* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700840* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800842static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843qla2xxx_eh_abort(struct scsi_cmnd *cmd)
844{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800845 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500846 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800847 int ret;
f4f051e2005-04-17 15:02:26 -0500848 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700849 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700850 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
f4f051e2005-04-17 15:02:26 -0500853 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700854 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800856 ret = fc_block_scsi_eh(cmd);
857 if (ret != 0)
858 return ret;
859 ret = SUCCESS;
860
f4f051e2005-04-17 15:02:26 -0500861 id = cmd->device->id;
862 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500863
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800864 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700865 sp = (srb_t *) CMD_SP(cmd);
866 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800867 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700868 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500869 }
Mike Christie170babc2010-10-15 11:27:47 -0700870
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700871 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800872 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
873 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700874
875 /* Get a reference to the sp and drop the lock.*/
876 sp_get(sp);
877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800878 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700879 if (ha->isp_ops->abort_command(sp)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700880 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800881 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700882 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700883 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800884 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700885 wait = 1;
886 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700887
888 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700889 qla2x00_sp_compl(ha, sp);
Saurav Kashyap75942062011-08-16 11:29:25 -0700890 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500891
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700892 /* Did the command return during mailbox execution? */
893 if (ret == FAILED && !CMD_SP(cmd))
894 ret = SUCCESS;
895
f4f051e2005-04-17 15:02:26 -0500896 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700897 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800898 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700899 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800900 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -0700901 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700905 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800906 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
907 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
f4f051e2005-04-17 15:02:26 -0500909 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910}
911
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500912int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800913qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500914 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800916 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700917 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800919 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500920 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Andrew Vasquez523ec772008-04-03 13:13:24 -0700922 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800924 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700925 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800926 for (cnt = 1; status == QLA_SUCCESS &&
927 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
928 sp = req->outstanding_cmds[cnt];
929 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700930 continue;
Arun Easibad75002010-05-04 15:01:30 -0700931 if ((sp->ctx) && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700932 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800933 if (vha->vp_idx != sp->fcport->vha->vp_idx)
934 continue;
935 match = 0;
936 switch (type) {
937 case WAIT_HOST:
938 match = 1;
939 break;
940 case WAIT_TARGET:
941 match = sp->cmd->device->id == t;
942 break;
943 case WAIT_LUN:
944 match = (sp->cmd->device->id == t &&
945 sp->cmd->device->lun == l);
946 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800948 if (!match)
949 continue;
950
951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
952 status = qla2x00_eh_wait_on_command(sp->cmd);
953 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800955 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700956
957 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
Andrew Vasquez523ec772008-04-03 13:13:24 -0700960static char *reset_errors[] = {
961 "HBA not online",
962 "HBA not ready",
963 "Task management failed",
964 "Waiting for command completions",
965};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Andrew Vasquez523ec772008-04-03 13:13:24 -0700967static int
968__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700969 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700970{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700972 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
973 int err;
974
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700975 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700976 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700977 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700978
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800979 err = fc_block_scsi_eh(cmd);
980 if (err != 0)
981 return err;
982
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700983 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800984 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700985 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986
987 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700988 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
989 ql_log(ql_log_warn, vha, 0x800a,
990 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700991 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700992 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700993 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700994 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700995 != QLA_SUCCESS) {
996 ql_log(ql_log_warn, vha, 0x800c,
997 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700998 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700999 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001000 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001001 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 cmd->device->lun, type) != QLA_SUCCESS) {
1003 ql_log(ql_log_warn, vha, 0x800d,
1004 "wait for peding cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001005 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001006 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001007
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001008 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001009 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1010 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001011
1012 return SUCCESS;
1013
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001014eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001015 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001016 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1017 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1018 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001019 return FAILED;
1020}
1021
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001022static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1024{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001025 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1026 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Andrew Vasquez523ec772008-04-03 13:13:24 -07001028 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1029 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001033qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001035 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1036 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Andrew Vasquez523ec772008-04-03 13:13:24 -07001038 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1039 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042/**************************************************************************
1043* qla2xxx_eh_bus_reset
1044*
1045* Description:
1046* The bus reset function will reset the bus and abort any executing
1047* commands.
1048*
1049* Input:
1050* cmd = Linux SCSI command packet of the command that cause the
1051* bus reset.
1052*
1053* Returns:
1054* SUCCESS/FAILURE (defined as macro in scsi.h).
1055*
1056**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001057static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1059{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001061 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001062 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001063 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
f4f051e2005-04-17 15:02:26 -05001065 id = cmd->device->id;
1066 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001067
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001068 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001069 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001072 ret = fc_block_scsi_eh(cmd);
1073 if (ret != 0)
1074 return ret;
1075 ret = FAILED;
1076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001077 ql_log(ql_log_info, vha, 0x8012,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001078 "BUS RESET ISSUED nexus=%ld:%d%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001080 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001081 ql_log(ql_log_fatal, vha, 0x8013,
1082 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001083 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 }
1085
Saurav Kashyapad537682011-11-18 09:02:09 -08001086 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1087 ret = SUCCESS;
1088
f4f051e2005-04-17 15:02:26 -05001089 if (ret == FAILED)
1090 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001092 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001093 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001094 QLA_SUCCESS) {
1095 ql_log(ql_log_warn, vha, 0x8014,
1096 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001097 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
f4f051e2005-04-17 15:02:26 -05001100eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001102 "BUS RESET %s nexus=%ld:%d:%d.\n",
1103 (ret == FAILED) ? "FAILED" : "SUCCEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
f4f051e2005-04-17 15:02:26 -05001105 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
1108/**************************************************************************
1109* qla2xxx_eh_host_reset
1110*
1111* Description:
1112* The reset function will reset the Adapter.
1113*
1114* Input:
1115* cmd = Linux SCSI command packet of the command that cause the
1116* adapter reset.
1117*
1118* Returns:
1119* Either SUCCESS or FAILED.
1120*
1121* Note:
1122**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001123static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1125{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001126 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001127 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001129 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001130 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001131 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
f4f051e2005-04-17 15:02:26 -05001133 id = cmd->device->id;
1134 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001135
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001136 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001137 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001138 }
f4f051e2005-04-17 15:02:26 -05001139
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001140 ret = fc_block_scsi_eh(cmd);
1141 if (ret != 0)
1142 return ret;
1143 ret = FAILED;
1144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001146 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001148 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001149 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151 if (vha != base_vha) {
1152 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001153 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001154 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001155 if (IS_QLA82XX(vha->hw)) {
1156 if (!qla82xx_fcoe_ctx_reset(vha)) {
1157 /* Ctx reset success */
1158 ret = SUCCESS;
1159 goto eh_host_reset_lock;
1160 }
1161 /* fall thru if ctx reset failed */
1162 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001163 if (ha->wq)
1164 flush_workqueue(ha->wq);
1165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001167 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1169 /* failed. schedule dpc to try */
1170 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1171
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001172 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1173 ql_log(ql_log_warn, vha, 0x802a,
1174 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001176 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001177 }
1178 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001181 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001182 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001184 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
f4f051e2005-04-17 15:02:26 -05001186eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001187 ql_log(ql_log_info, vha, 0x8017,
1188 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1189 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
f4f051e2005-04-17 15:02:26 -05001191 return ret;
1192}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194/*
1195* qla2x00_loop_reset
1196* Issue loop reset.
1197*
1198* Input:
1199* ha = adapter block pointer.
1200*
1201* Returns:
1202* 0 = success
1203*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001204int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001205qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001207 int ret;
bdf79622005-04-17 15:06:53 -05001208 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001209 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001211 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001212 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1213 if (fcport->port_type != FCT_TARGET)
1214 continue;
1215
1216 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1217 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001218 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1219 "Bus Reset failed: Target Reset=%d "
1220 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001221 }
1222 }
1223 }
1224
Giridhar Malavalia9083012010-04-12 17:59:55 -07001225 if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001226 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001227 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001228 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1229 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001230 }
1231 atomic_set(&vha->loop_state, LOOP_DOWN);
1232 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1233 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 }
1235
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001236 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001237 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001238 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001239 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1240 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001241 }
1242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001246 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001249void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001250qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001251{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001252 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001253 unsigned long flags;
1254 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001255 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001256 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001257 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001258
1259 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001260 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001261 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001262 if (!req)
1263 continue;
1264 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1265 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001266 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001267 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001268 if (!sp->ctx ||
Arun Easibad75002010-05-04 15:01:30 -07001269 (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
1270 IS_PROT_IO(sp)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001271 sp->cmd->result = res;
1272 qla2x00_sp_compl(ha, sp);
1273 } else {
1274 ctx = sp->ctx;
Roland Dreier9bfacd02011-09-22 00:06:05 -07001275 if (ctx->type == SRB_ELS_CMD_RPT ||
1276 ctx->type == SRB_ELS_CMD_HST ||
1277 ctx->type == SRB_CT_CMD) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001278 struct fc_bsg_job *bsg_job =
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001279 ctx->u.bsg_job;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001280 if (bsg_job->request->msgcode
1281 == FC_BSG_HST_CT)
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001282 kfree(sp->fcport);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001283 bsg_job->req->errors = 0;
1284 bsg_job->reply->result = res;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001285 bsg_job->job_done(bsg_job);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001286 kfree(sp->ctx);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001287 mempool_free(sp,
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001288 ha->srb_mempool);
Roland Dreier9bfacd02011-09-22 00:06:05 -07001289 } else {
1290 ctx->u.iocb_cmd->free(sp);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001291 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001292 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001293 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001294 }
1295 }
1296 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1297}
1298
f4f051e2005-04-17 15:02:26 -05001299static int
1300qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
bdf79622005-04-17 15:06:53 -05001302 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001304 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001305 return -ENXIO;
1306
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001307 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001308
1309 return 0;
1310}
1311
1312static int
1313qla2xxx_slave_configure(struct scsi_device *sdev)
1314{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001315 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001316 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001317
f4f051e2005-04-17 15:02:26 -05001318 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001319 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001321 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001322 return 0;
1323}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
f4f051e2005-04-17 15:02:26 -05001325static void
1326qla2xxx_slave_destroy(struct scsi_device *sdev)
1327{
1328 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001331static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1332{
1333 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1334
1335 if (!scsi_track_queue_full(sdev, qdepth))
1336 return;
1337
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001338 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001339 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1340 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001341}
1342
1343static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1344{
1345 fc_port_t *fcport = sdev->hostdata;
1346 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001347 struct req_que *req = NULL;
1348
1349 req = vha->req;
1350 if (!req)
1351 return;
1352
1353 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1354 return;
1355
1356 if (sdev->ordered_tags)
1357 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1358 else
1359 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1360
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001361 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001362 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1363 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001364}
1365
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001366static int
Mike Christiee881a172009-10-15 17:46:39 -07001367qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001368{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001369 switch (reason) {
1370 case SCSI_QDEPTH_DEFAULT:
1371 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1372 break;
1373 case SCSI_QDEPTH_QFULL:
1374 qla2x00_handle_queue_full(sdev, qdepth);
1375 break;
1376 case SCSI_QDEPTH_RAMP_UP:
1377 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1378 break;
1379 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001380 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001381 }
Mike Christiee881a172009-10-15 17:46:39 -07001382
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001383 return sdev->queue_depth;
1384}
1385
1386static int
1387qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1388{
1389 if (sdev->tagged_supported) {
1390 scsi_set_tag_type(sdev, tag_type);
1391 if (tag_type)
1392 scsi_activate_tcq(sdev, sdev->queue_depth);
1393 else
1394 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1395 } else
1396 tag_type = 0;
1397
1398 return tag_type;
1399}
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401/**
1402 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1403 * @ha: HA context
1404 *
1405 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1406 * supported addressing method.
1407 */
1408static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001409qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001411 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Yang Hongyang6a355282009-04-06 19:01:13 -07001414 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001415 /* Any upper-dword bits set? */
1416 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001417 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001418 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001420 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1421 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001422 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001425
Yang Hongyang284901a2009-04-06 19:01:15 -07001426 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1427 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001430static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001431qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001432{
1433 unsigned long flags = 0;
1434 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1435
1436 spin_lock_irqsave(&ha->hardware_lock, flags);
1437 ha->interrupts_on = 1;
1438 /* enable risc and host interrupts */
1439 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1440 RD_REG_WORD(&reg->ictrl);
1441 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1442
1443}
1444
1445static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001446qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001447{
1448 unsigned long flags = 0;
1449 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1450
1451 spin_lock_irqsave(&ha->hardware_lock, flags);
1452 ha->interrupts_on = 0;
1453 /* disable risc and host interrupts */
1454 WRT_REG_WORD(&reg->ictrl, 0);
1455 RD_REG_WORD(&reg->ictrl);
1456 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1457}
1458
1459static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001460qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001461{
1462 unsigned long flags = 0;
1463 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1464
1465 spin_lock_irqsave(&ha->hardware_lock, flags);
1466 ha->interrupts_on = 1;
1467 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1468 RD_REG_DWORD(&reg->ictrl);
1469 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1470}
1471
1472static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001474{
1475 unsigned long flags = 0;
1476 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1477
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001478 if (IS_NOPOLLING_TYPE(ha))
1479 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001480 spin_lock_irqsave(&ha->hardware_lock, flags);
1481 ha->interrupts_on = 0;
1482 WRT_REG_DWORD(&reg->ictrl, 0);
1483 RD_REG_DWORD(&reg->ictrl);
1484 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1485}
1486
1487static struct isp_operations qla2100_isp_ops = {
1488 .pci_config = qla2100_pci_config,
1489 .reset_chip = qla2x00_reset_chip,
1490 .chip_diag = qla2x00_chip_diag,
1491 .config_rings = qla2x00_config_rings,
1492 .reset_adapter = qla2x00_reset_adapter,
1493 .nvram_config = qla2x00_nvram_config,
1494 .update_fw_options = qla2x00_update_fw_options,
1495 .load_risc = qla2x00_load_risc,
1496 .pci_info_str = qla2x00_pci_info_str,
1497 .fw_version_str = qla2x00_fw_version_str,
1498 .intr_handler = qla2100_intr_handler,
1499 .enable_intrs = qla2x00_enable_intrs,
1500 .disable_intrs = qla2x00_disable_intrs,
1501 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001502 .target_reset = qla2x00_abort_target,
1503 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001504 .fabric_login = qla2x00_login_fabric,
1505 .fabric_logout = qla2x00_fabric_logout,
1506 .calc_req_entries = qla2x00_calc_iocbs_32,
1507 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1508 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1509 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1510 .read_nvram = qla2x00_read_nvram_data,
1511 .write_nvram = qla2x00_write_nvram_data,
1512 .fw_dump = qla2100_fw_dump,
1513 .beacon_on = NULL,
1514 .beacon_off = NULL,
1515 .beacon_blink = NULL,
1516 .read_optrom = qla2x00_read_optrom_data,
1517 .write_optrom = qla2x00_write_optrom_data,
1518 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001520 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001521};
1522
1523static struct isp_operations qla2300_isp_ops = {
1524 .pci_config = qla2300_pci_config,
1525 .reset_chip = qla2x00_reset_chip,
1526 .chip_diag = qla2x00_chip_diag,
1527 .config_rings = qla2x00_config_rings,
1528 .reset_adapter = qla2x00_reset_adapter,
1529 .nvram_config = qla2x00_nvram_config,
1530 .update_fw_options = qla2x00_update_fw_options,
1531 .load_risc = qla2x00_load_risc,
1532 .pci_info_str = qla2x00_pci_info_str,
1533 .fw_version_str = qla2x00_fw_version_str,
1534 .intr_handler = qla2300_intr_handler,
1535 .enable_intrs = qla2x00_enable_intrs,
1536 .disable_intrs = qla2x00_disable_intrs,
1537 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001538 .target_reset = qla2x00_abort_target,
1539 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001540 .fabric_login = qla2x00_login_fabric,
1541 .fabric_logout = qla2x00_fabric_logout,
1542 .calc_req_entries = qla2x00_calc_iocbs_32,
1543 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1544 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1545 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1546 .read_nvram = qla2x00_read_nvram_data,
1547 .write_nvram = qla2x00_write_nvram_data,
1548 .fw_dump = qla2300_fw_dump,
1549 .beacon_on = qla2x00_beacon_on,
1550 .beacon_off = qla2x00_beacon_off,
1551 .beacon_blink = qla2x00_beacon_blink,
1552 .read_optrom = qla2x00_read_optrom_data,
1553 .write_optrom = qla2x00_write_optrom_data,
1554 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001555 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001556 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001557};
1558
1559static struct isp_operations qla24xx_isp_ops = {
1560 .pci_config = qla24xx_pci_config,
1561 .reset_chip = qla24xx_reset_chip,
1562 .chip_diag = qla24xx_chip_diag,
1563 .config_rings = qla24xx_config_rings,
1564 .reset_adapter = qla24xx_reset_adapter,
1565 .nvram_config = qla24xx_nvram_config,
1566 .update_fw_options = qla24xx_update_fw_options,
1567 .load_risc = qla24xx_load_risc,
1568 .pci_info_str = qla24xx_pci_info_str,
1569 .fw_version_str = qla24xx_fw_version_str,
1570 .intr_handler = qla24xx_intr_handler,
1571 .enable_intrs = qla24xx_enable_intrs,
1572 .disable_intrs = qla24xx_disable_intrs,
1573 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001574 .target_reset = qla24xx_abort_target,
1575 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001576 .fabric_login = qla24xx_login_fabric,
1577 .fabric_logout = qla24xx_fabric_logout,
1578 .calc_req_entries = NULL,
1579 .build_iocbs = NULL,
1580 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1581 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1582 .read_nvram = qla24xx_read_nvram_data,
1583 .write_nvram = qla24xx_write_nvram_data,
1584 .fw_dump = qla24xx_fw_dump,
1585 .beacon_on = qla24xx_beacon_on,
1586 .beacon_off = qla24xx_beacon_off,
1587 .beacon_blink = qla24xx_beacon_blink,
1588 .read_optrom = qla24xx_read_optrom_data,
1589 .write_optrom = qla24xx_write_optrom_data,
1590 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001591 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001592 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001593};
1594
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001595static struct isp_operations qla25xx_isp_ops = {
1596 .pci_config = qla25xx_pci_config,
1597 .reset_chip = qla24xx_reset_chip,
1598 .chip_diag = qla24xx_chip_diag,
1599 .config_rings = qla24xx_config_rings,
1600 .reset_adapter = qla24xx_reset_adapter,
1601 .nvram_config = qla24xx_nvram_config,
1602 .update_fw_options = qla24xx_update_fw_options,
1603 .load_risc = qla24xx_load_risc,
1604 .pci_info_str = qla24xx_pci_info_str,
1605 .fw_version_str = qla24xx_fw_version_str,
1606 .intr_handler = qla24xx_intr_handler,
1607 .enable_intrs = qla24xx_enable_intrs,
1608 .disable_intrs = qla24xx_disable_intrs,
1609 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001610 .target_reset = qla24xx_abort_target,
1611 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001612 .fabric_login = qla24xx_login_fabric,
1613 .fabric_logout = qla24xx_fabric_logout,
1614 .calc_req_entries = NULL,
1615 .build_iocbs = NULL,
1616 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1617 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1618 .read_nvram = qla25xx_read_nvram_data,
1619 .write_nvram = qla25xx_write_nvram_data,
1620 .fw_dump = qla25xx_fw_dump,
1621 .beacon_on = qla24xx_beacon_on,
1622 .beacon_off = qla24xx_beacon_off,
1623 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001624 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001625 .write_optrom = qla24xx_write_optrom_data,
1626 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001627 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001628 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001629};
1630
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001631static struct isp_operations qla81xx_isp_ops = {
1632 .pci_config = qla25xx_pci_config,
1633 .reset_chip = qla24xx_reset_chip,
1634 .chip_diag = qla24xx_chip_diag,
1635 .config_rings = qla24xx_config_rings,
1636 .reset_adapter = qla24xx_reset_adapter,
1637 .nvram_config = qla81xx_nvram_config,
1638 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001639 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001640 .pci_info_str = qla24xx_pci_info_str,
1641 .fw_version_str = qla24xx_fw_version_str,
1642 .intr_handler = qla24xx_intr_handler,
1643 .enable_intrs = qla24xx_enable_intrs,
1644 .disable_intrs = qla24xx_disable_intrs,
1645 .abort_command = qla24xx_abort_command,
1646 .target_reset = qla24xx_abort_target,
1647 .lun_reset = qla24xx_lun_reset,
1648 .fabric_login = qla24xx_login_fabric,
1649 .fabric_logout = qla24xx_fabric_logout,
1650 .calc_req_entries = NULL,
1651 .build_iocbs = NULL,
1652 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1653 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001654 .read_nvram = NULL,
1655 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001656 .fw_dump = qla81xx_fw_dump,
1657 .beacon_on = qla24xx_beacon_on,
1658 .beacon_off = qla24xx_beacon_off,
1659 .beacon_blink = qla24xx_beacon_blink,
1660 .read_optrom = qla25xx_read_optrom_data,
1661 .write_optrom = qla24xx_write_optrom_data,
1662 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001663 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001664 .abort_isp = qla2x00_abort_isp,
1665};
1666
1667static struct isp_operations qla82xx_isp_ops = {
1668 .pci_config = qla82xx_pci_config,
1669 .reset_chip = qla82xx_reset_chip,
1670 .chip_diag = qla24xx_chip_diag,
1671 .config_rings = qla82xx_config_rings,
1672 .reset_adapter = qla24xx_reset_adapter,
1673 .nvram_config = qla81xx_nvram_config,
1674 .update_fw_options = qla24xx_update_fw_options,
1675 .load_risc = qla82xx_load_risc,
1676 .pci_info_str = qla82xx_pci_info_str,
1677 .fw_version_str = qla24xx_fw_version_str,
1678 .intr_handler = qla82xx_intr_handler,
1679 .enable_intrs = qla82xx_enable_intrs,
1680 .disable_intrs = qla82xx_disable_intrs,
1681 .abort_command = qla24xx_abort_command,
1682 .target_reset = qla24xx_abort_target,
1683 .lun_reset = qla24xx_lun_reset,
1684 .fabric_login = qla24xx_login_fabric,
1685 .fabric_logout = qla24xx_fabric_logout,
1686 .calc_req_entries = NULL,
1687 .build_iocbs = NULL,
1688 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1689 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1690 .read_nvram = qla24xx_read_nvram_data,
1691 .write_nvram = qla24xx_write_nvram_data,
1692 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001693 .beacon_on = qla82xx_beacon_on,
1694 .beacon_off = qla82xx_beacon_off,
1695 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001696 .read_optrom = qla82xx_read_optrom_data,
1697 .write_optrom = qla82xx_write_optrom_data,
1698 .get_flash_version = qla24xx_get_flash_version,
1699 .start_scsi = qla82xx_start_scsi,
1700 .abort_isp = qla82xx_abort_isp,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001701};
1702
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001703static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001704qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001705{
1706 ha->device_type = DT_EXTENDED_IDS;
1707 switch (ha->pdev->device) {
1708 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1709 ha->device_type |= DT_ISP2100;
1710 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001711 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001712 break;
1713 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1714 ha->device_type |= DT_ISP2200;
1715 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001716 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001717 break;
1718 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1719 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001720 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001721 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001722 break;
1723 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1724 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001725 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001726 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001727 break;
1728 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1729 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001730 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001731 if (ha->pdev->subsystem_vendor == 0x1028 &&
1732 ha->pdev->subsystem_device == 0x0170)
1733 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001734 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001735 break;
1736 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1737 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001738 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001739 break;
1740 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1741 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001742 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001743 break;
1744 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1745 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001746 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001747 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001748 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001749 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001750 break;
1751 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1752 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001753 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001754 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001755 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001756 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001757 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001758 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1759 ha->device_type |= DT_ISP8432;
1760 ha->device_type |= DT_ZIO_SUPPORTED;
1761 ha->device_type |= DT_FWI2;
1762 ha->device_type |= DT_IIDMA;
1763 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1764 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001765 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1766 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001767 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001768 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001769 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001770 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1771 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001772 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001773 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001774 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001775 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1776 ha->device_type |= DT_ISP2532;
1777 ha->device_type |= DT_ZIO_SUPPORTED;
1778 ha->device_type |= DT_FWI2;
1779 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001780 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1781 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001782 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1783 ha->device_type |= DT_ISP8001;
1784 ha->device_type |= DT_ZIO_SUPPORTED;
1785 ha->device_type |= DT_FWI2;
1786 ha->device_type |= DT_IIDMA;
1787 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1788 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001789 case PCI_DEVICE_ID_QLOGIC_ISP8021:
1790 ha->device_type |= DT_ISP8021;
1791 ha->device_type |= DT_ZIO_SUPPORTED;
1792 ha->device_type |= DT_FWI2;
1793 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1794 /* Initialize 82XX ISP flags */
1795 qla82xx_init_flags(ha);
1796 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001797 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001798
Giridhar Malavalia9083012010-04-12 17:59:55 -07001799 if (IS_QLA82XX(ha))
1800 ha->port_no = !(ha->portnum & 1);
1801 else
1802 /* Get adapter physical port no from interrupt pin register. */
1803 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1804
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001805 if (ha->port_no & 1)
1806 ha->flags.port0 = 1;
1807 else
1808 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001809 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08001810 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001811 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001812}
1813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001815qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816{
Andrew Vasquez37765412008-01-17 09:02:09 -08001817 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001818 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001819 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Giridhar Malavalia9083012010-04-12 17:59:55 -07001821 if (IS_QLA82XX(ha))
1822 return qla82xx_iospace_config(ha);
1823
Andrew Vasquez285d0322007-10-19 15:59:17 -07001824 if (pci_request_selected_regions(ha->pdev, ha->bars,
1825 QLA2XXX_DRIVER_NAME)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001826 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1827 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
Andrew Vasquez285d0322007-10-19 15:59:17 -07001828 pci_name(ha->pdev));
Andrew Vasquez285d0322007-10-19 15:59:17 -07001829 goto iospace_error_exit;
1830 }
1831 if (!(ha->bars & 1))
1832 goto skip_pio;
1833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1835 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001836 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1837 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001838 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1839 "Invalid pci I/O region size (%s).\n",
1840 pci_name(ha->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 pio = 0;
1842 }
1843 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001844 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1845 "Region #0 no a PIO resource (%s).\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 pci_name(ha->pdev));
1847 pio = 0;
1848 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001849 ha->pio_address = pio;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001850 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
Joe Perchesd8424f62011-11-18 09:03:06 -08001851 "PIO address=%llu.\n",
1852 (unsigned long long)ha->pio_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
Andrew Vasquez285d0322007-10-19 15:59:17 -07001854skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001856 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001857 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1858 "Region #1 not an MMIO resource (%s), aborting.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 pci_name(ha->pdev));
1860 goto iospace_error_exit;
1861 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001862 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001863 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1864 "Invalid PCI mem region size (%s), aborting.\n",
1865 pci_name(ha->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 goto iospace_error_exit;
1867 }
1868
Andrew Vasquez37765412008-01-17 09:02:09 -08001869 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 if (!ha->iobase) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001871 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1872 "Cannot remap MMIO (%s), aborting.\n",
1873 pci_name(ha->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 goto iospace_error_exit;
1875 }
1876
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001877 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001878 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezd84a47c2010-03-19 16:59:18 -07001879 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1880 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001881 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001882 goto mqiobase_exit;
Michael Hernandezd84a47c2010-03-19 16:59:18 -07001883
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001884 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1885 pci_resource_len(ha->pdev, 3));
1886 if (ha->mqiobase) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001887 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1888 "MQIO Base=%p.\n", ha->mqiobase);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001889 /* Read MSIX vector size of the board */
1890 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1891 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001892 /* Max queues are bounded by available msix vectors */
1893 /* queue 0 uses two msix vectors */
1894 if (ql2xmultique_tag) {
1895 cpus = num_online_cpus();
Anirban Chakraborty27dc9c52009-06-17 10:30:28 -07001896 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001897 (cpus + 1) : (ha->msix_count - 1);
1898 ha->max_req_queues = 2;
1899 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001900 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001901 QLA_MQ_SIZE : ql2xmaxqueues;
1902 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1903 "QoS mode set, max no of request queues:%d.\n",
1904 ha->max_req_queues);
1905 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1906 "QoS mode set, max no of request queues:%d.\n",
1907 ha->max_req_queues);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001908 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001909 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1910 "MSI-X vector count: %d.\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001911 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001912 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1913 "BAR 3 not enabled.\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001914
1915mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001916 ha->msix_count = ha->max_rsp_queues + 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001917 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1918 "MSIX Count:%d.\n", ha->msix_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 return (0);
1920
1921iospace_error_exit:
1922 return (-ENOMEM);
1923}
1924
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001925static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001926qla2xxx_scan_start(struct Scsi_Host *shost)
1927{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001929
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001930 if (vha->hw->flags.running_gold_fw)
1931 return;
1932
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1934 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1935 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1936 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001937}
1938
1939static int
1940qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1941{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001945 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001947 return 1;
1948
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001950}
1951
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952/*
1953 * PCI driver interface
1954 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001955static int __devinit
1956qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001958 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 scsi_qla_host_t *base_vha = NULL;
1961 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001962 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001964 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001965 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001966 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001967 struct req_que *req = NULL;
1968 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
Andrew Vasquez285d0322007-10-19 15:59:17 -07001970 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001971 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001972 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1973 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001974 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001975 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1976 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001977 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07001978 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
1979 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001980 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001981 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001982 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
1983 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07001984 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001985 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
1986 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07001987
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001988 if (mem_only) {
1989 if (pci_enable_device_mem(pdev))
1990 goto probe_out;
1991 } else {
1992 if (pci_enable_device(pdev))
1993 goto probe_out;
1994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Jesse Barnes09276782008-10-18 17:33:19 -07001996 /* This may fail but that's ok */
1997 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001999 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2000 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002001 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2002 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002005 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2006 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
2009 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002010 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002011 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002012 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002013 spin_lock_init(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002015 /* Set ISP-type information. */
2016 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002017
2018 /* Set EEH reset type to fundamental if required by hba */
2019 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
2020 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002021 }
2022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 /* Configure PCI I/O space */
2024 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002025 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002028 ql_log_pci(ql_log_info, pdev, 0x001d,
2029 "Found an ISP%04X irq %d iobase 0x%p.\n",
2030 pdev->device, pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002032 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002033 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002034 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002036 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041 req_length = REQUEST_ENTRY_CNT_2100;
2042 rsp_length = RESPONSE_ENTRY_CNT_2100;
2043 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002044 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002045 ha->flash_conf_off = ~0;
2046 ha->flash_data_off = ~0;
2047 ha->nvram_conf_off = ~0;
2048 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002049 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 req_length = REQUEST_ENTRY_CNT_2200;
2053 rsp_length = RESPONSE_ENTRY_CNT_2100;
2054 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002055 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002056 ha->flash_conf_off = ~0;
2057 ha->flash_data_off = ~0;
2058 ha->nvram_conf_off = ~0;
2059 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002060 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002061 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 req_length = REQUEST_ENTRY_CNT_2200;
2064 rsp_length = RESPONSE_ENTRY_CNT_2300;
2065 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002066 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002067 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2068 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002069 ha->flash_conf_off = ~0;
2070 ha->flash_data_off = ~0;
2071 ha->nvram_conf_off = ~0;
2072 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002073 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002074 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07002075 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 req_length = REQUEST_ENTRY_CNT_24XX;
2077 rsp_length = RESPONSE_ENTRY_CNT_2300;
2078 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002079 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002080 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002081 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002082 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002083 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002084 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2085 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2086 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2087 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002088 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002089 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002090 req_length = REQUEST_ENTRY_CNT_24XX;
2091 rsp_length = RESPONSE_ENTRY_CNT_2300;
2092 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002093 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002094 ha->gid_list_info_size = 8;
2095 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002096 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002097 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002098 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2099 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2100 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2101 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2102 } else if (IS_QLA81XX(ha)) {
2103 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2104 req_length = REQUEST_ENTRY_CNT_24XX;
2105 rsp_length = RESPONSE_ENTRY_CNT_2300;
2106 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2107 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2108 ha->gid_list_info_size = 8;
2109 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002110 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002111 ha->isp_ops = &qla81xx_isp_ops;
2112 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2113 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2114 ha->nvram_conf_off = ~0;
2115 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002116 } else if (IS_QLA82XX(ha)) {
2117 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2118 req_length = REQUEST_ENTRY_CNT_82XX;
2119 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2120 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2121 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2122 ha->gid_list_info_size = 8;
2123 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002124 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002125 ha->isp_ops = &qla82xx_isp_ops;
2126 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2127 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2128 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2129 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002131 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2132 "mbx_count=%d, req_length=%d, "
2133 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2134 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
2135 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2136 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2137 ha->nvram_npiv_size);
2138 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2139 "isp_ops=%p, flash_conf_off=%d, "
2140 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2141 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2142 ha->nvram_conf_off, ha->nvram_data_off);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002143 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002144 init_completion(&ha->mbx_cmd_comp);
2145 complete(&ha->mbx_cmd_comp);
2146 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002147 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002149 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Andrew Vasquez53303c42009-01-22 09:45:37 -08002151 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002152 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2153 "64 Bit addressing is %s.\n",
2154 ha->flags.enable_64bit_addressing ? "enable" :
2155 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002156 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002158 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2159 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161 goto probe_hw_failed;
2162 }
2163
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002164 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002165 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002166 req->max_q_depth = ql2xmaxqdepth;
2167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168
2169 base_vha = qla2x00_create_host(sht, ha);
2170 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002171 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002172 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002173 qla2x00_free_req_que(ha, req);
2174 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002175 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 }
2177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002178 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002180 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002181 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002182 host->can_queue = req->length + 128;
2183 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002184 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002185 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2187 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002188
2189 /* Set the SG table size based on ISP type */
2190 if (!IS_FWI2_CAPABLE(ha)) {
2191 if (IS_QLA2100(ha))
2192 host->sg_tablesize = 32;
2193 } else {
2194 if (!IS_QLA82XX(ha))
2195 host->sg_tablesize = QLA_SG_ALL;
2196 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002197 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2198 "can_queue=%d, req=%p, "
2199 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2200 host->can_queue, base_vha->req,
2201 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002202 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002203 host->this_id = 255;
2204 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002205 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002206 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002207 host->max_cmd_len = 32;
2208 else
2209 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002210 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002211 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002212 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002213 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002214
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002215 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2216 "max_id=%d this_id=%d "
2217 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002218 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002219 host->this_id, host->cmd_per_lun, host->unique_id,
2220 host->max_cmd_len, host->max_channel, host->max_lun,
2221 host->transportt, sht->vendor_id);
2222
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002223 /* Set up the irqs */
2224 ret = qla2x00_request_irqs(ha, rsp);
2225 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002226 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002227
2228 pci_save_state(pdev);
2229
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002230 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002231que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002232 if (!qla2x00_alloc_queues(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002233 ql_log(ql_log_fatal, base_vha, 0x003d,
2234 "Failed to allocate memory for queue pointers.. aborting.\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002235 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002236 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002237
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002238 ha->rsp_q_map[0] = rsp;
2239 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002240 rsp->req = req;
2241 req->rsp = rsp;
2242 set_bit(0, ha->req_qid_map);
2243 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07002244 /* FWI2-capable only. */
2245 req->req_q_in = &ha->iobase->isp24.req_q_in;
2246 req->req_q_out = &ha->iobase->isp24.req_q_out;
2247 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2248 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002249 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002250 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2251 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2252 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2253 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002254 }
2255
Giridhar Malavalia9083012010-04-12 17:59:55 -07002256 if (IS_QLA82XX(ha)) {
2257 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2258 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2259 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2260 }
2261
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002262 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2263 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2264 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2265 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2266 "req->req_q_in=%p req->req_q_out=%p "
2267 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2268 req->req_q_in, req->req_q_out,
2269 rsp->rsp_q_in, rsp->rsp_q_out);
2270 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2271 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2272 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2273 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2274 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2275 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002277 if (qla2x00_initialize_adapter(base_vha)) {
2278 ql_log(ql_log_fatal, base_vha, 0x00d6,
2279 "Failed to initialize adapter - Adapter flags %x.\n",
2280 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281
Giridhar Malavalia9083012010-04-12 17:59:55 -07002282 if (IS_QLA82XX(ha)) {
2283 qla82xx_idc_lock(ha);
2284 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2285 QLA82XX_DEV_FAILED);
2286 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002287 ql_log(ql_log_fatal, base_vha, 0x00d7,
2288 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002289 }
2290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 ret = -ENODEV;
2292 goto probe_failed;
2293 }
2294
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002295 if (ha->mqenable) {
2296 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002297 ql_log(ql_log_warn, base_vha, 0x00ec,
2298 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002299 goto que_init;
2300 }
2301 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002302
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002303 if (ha->flags.running_gold_fw)
2304 goto skip_dpc;
2305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 /*
2307 * Startup the kernel thread for this host adapter
2308 */
2309 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002310 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002312 ql_log(ql_log_fatal, base_vha, 0x00ed,
2313 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002314 ret = PTR_ERR(ha->dpc_thread);
2315 goto probe_failed;
2316 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002317 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2318 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002320skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 list_add_tail(&base_vha->list, &ha->vp_list);
2322 base_vha->host->irq = ha->pdev->irq;
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002326 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2327 "Started qla2x00_timer with "
2328 "interval=%d.\n", WATCH_INTERVAL);
2329 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2330 "Detected hba at address=%p.\n",
2331 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Arun Easie02587d2011-08-16 11:29:23 -07002333 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002334 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07002335 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07002336 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002337 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2338 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002339 if (ql2xenabledif == 1)
2340 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002341 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002342 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002343 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002344 | SHOST_DIF_TYPE3_PROTECTION
2345 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002346 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002347 | SHOST_DIX_TYPE3_PROTECTION);
2348 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2349 } else
2350 base_vha->flags.difdix_supported = 0;
2351 }
2352
Giridhar Malavalia9083012010-04-12 17:59:55 -07002353 ha->isp_ops->enable_intrs(ha);
2354
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002355 ret = scsi_add_host(host, &pdev->dev);
2356 if (ret)
2357 goto probe_failed;
2358
Michael Reed14864002009-12-02 09:11:16 -06002359 base_vha->flags.init_done = 1;
2360 base_vha->flags.online = 1;
2361
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002362 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2363 "Init done and hba is online.\n");
2364
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002365 scsi_scan_host(host);
2366
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002372
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002373 ql_log(ql_log_info, base_vha, 0x00fb,
2374 "QLogic %s - %s.\n",
2375 ha->model_number, ha->model_desc ? ha->model_desc : "");
2376 ql_log(ql_log_info, base_vha, 0x00fc,
2377 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2378 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2379 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2380 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 return 0;
2384
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002385probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002386 qla2x00_free_req_que(ha, req);
2387 qla2x00_free_rsp_que(ha, rsp);
2388 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002391 if (base_vha->timer_active)
2392 qla2x00_stop_timer(base_vha);
2393 base_vha->flags.online = 0;
2394 if (ha->dpc_thread) {
2395 struct task_struct *t = ha->dpc_thread;
2396
2397 ha->dpc_thread = NULL;
2398 kthread_stop(t);
2399 }
2400
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002401 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002406 if (IS_QLA82XX(ha)) {
2407 qla82xx_idc_lock(ha);
2408 qla82xx_clear_drv_active(ha);
2409 qla82xx_idc_unlock(ha);
2410 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2411 if (!ql2xdbwr)
2412 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2413 } else {
2414 if (ha->iobase)
2415 iounmap(ha->iobase);
2416 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417 pci_release_selected_regions(ha->pdev, ha->bars);
2418 kfree(ha);
2419 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002421probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002423 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Adrian Bunk4c993f72008-01-14 00:55:16 -08002426static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002427qla2x00_shutdown(struct pci_dev *pdev)
2428{
2429 scsi_qla_host_t *vha;
2430 struct qla_hw_data *ha;
2431
2432 vha = pci_get_drvdata(pdev);
2433 ha = vha->hw;
2434
2435 /* Turn-off FCE trace */
2436 if (ha->flags.fce_enabled) {
2437 qla2x00_disable_fce_trace(vha, NULL, NULL);
2438 ha->flags.fce_enabled = 0;
2439 }
2440
2441 /* Turn-off EFT trace */
2442 if (ha->eft)
2443 qla2x00_disable_eft_trace(vha);
2444
2445 /* Stop currently executing firmware. */
2446 qla2x00_try_to_stop_firmware(vha);
2447
2448 /* Turn adapter off line */
2449 vha->flags.online = 0;
2450
2451 /* turn-off interrupts on the card */
2452 if (ha->interrupts_on) {
2453 vha->flags.init_done = 0;
2454 ha->isp_ops->disable_intrs(ha);
2455 }
2456
2457 qla2x00_free_irqs(vha);
2458
2459 qla2x00_free_fw_dump(ha);
2460}
2461
2462static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002463qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Arun Easifeafb7b2010-09-03 14:57:00 -07002465 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002467 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 base_vha = pci_get_drvdata(pdev);
2470 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Arun Easi43ebf162011-05-10 11:18:16 -07002472 mutex_lock(&ha->vport_lock);
2473 while (ha->cur_vport_count) {
2474 struct Scsi_Host *scsi_host;
Arun Easifeafb7b2010-09-03 14:57:00 -07002475
Arun Easi43ebf162011-05-10 11:18:16 -07002476 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002477
Arun Easi43ebf162011-05-10 11:18:16 -07002478 BUG_ON(base_vha->list.next == &ha->vp_list);
2479 /* This assumes first entry in ha->vp_list is always base vha */
2480 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2481 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002482
Arun Easi43ebf162011-05-10 11:18:16 -07002483 spin_unlock_irqrestore(&ha->vport_slock, flags);
2484 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002485
Arun Easi43ebf162011-05-10 11:18:16 -07002486 fc_vport_terminate(vha->fc_vport);
2487 scsi_host_put(vha->host);
2488
2489 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002490 }
Arun Easi43ebf162011-05-10 11:18:16 -07002491 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002492
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002494
Andrew Vasquezb9978762009-03-24 09:08:05 -07002495 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2496
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002499 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002500
Andrew Vasquezb9978762009-03-24 09:08:05 -07002501 /* Disable timer */
2502 if (base_vha->timer_active)
2503 qla2x00_stop_timer(base_vha);
2504
2505 base_vha->flags.online = 0;
2506
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002507 /* Flush the work queue and remove it */
2508 if (ha->wq) {
2509 flush_workqueue(ha->wq);
2510 destroy_workqueue(ha->wq);
2511 ha->wq = NULL;
2512 }
2513
Andrew Vasquezb9978762009-03-24 09:08:05 -07002514 /* Kill the kernel thread for this host */
2515 if (ha->dpc_thread) {
2516 struct task_struct *t = ha->dpc_thread;
2517
2518 /*
2519 * qla2xxx_wake_dpc checks for ->dpc_thread
2520 * so we need to zero it out.
2521 */
2522 ha->dpc_thread = NULL;
2523 kthread_stop(t);
2524 }
2525
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002529
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002532 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002534 scsi_host_put(base_vha->host);
2535
Giridhar Malavalia9083012010-04-12 17:59:55 -07002536 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002537 qla82xx_idc_lock(ha);
2538 qla82xx_clear_drv_active(ha);
2539 qla82xx_idc_unlock(ha);
2540
Giridhar Malavalia9083012010-04-12 17:59:55 -07002541 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2542 if (!ql2xdbwr)
2543 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2544 } else {
2545 if (ha->iobase)
2546 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547
Giridhar Malavalia9083012010-04-12 17:59:55 -07002548 if (ha->mqiobase)
2549 iounmap(ha->mqiobase);
2550 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 pci_release_selected_regions(ha->pdev, ha->bars);
2553 kfree(ha);
2554 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002556 pci_disable_pcie_error_reporting(pdev);
2557
Bernhard Walle665db932007-03-28 00:49:49 +02002558 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 pci_set_drvdata(pdev, NULL);
2560}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
2562static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Andrew Vasquez85880802009-12-15 21:29:46 -08002567 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2568
2569 /* Disable timer */
2570 if (vha->timer_active)
2571 qla2x00_stop_timer(vha);
2572
2573 /* Kill the kernel thread for this host */
2574 if (ha->dpc_thread) {
2575 struct task_struct *t = ha->dpc_thread;
2576
2577 /*
2578 * qla2xxx_wake_dpc checks for ->dpc_thread
2579 * so we need to zero it out.
2580 */
2581 ha->dpc_thread = NULL;
2582 kthread_stop(t);
2583 }
2584
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002585 qla25xx_delete_queues(vha);
2586
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002587 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002589
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002590 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002592
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002593 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002594 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Andrew Vasquez85880802009-12-15 21:29:46 -08002596 vha->flags.online = 0;
2597
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002598 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002599 if (ha->interrupts_on) {
2600 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002601 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002602 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 qla2x00_free_irqs(vha);
2605
Chad Dupuis88670482010-07-23 15:28:30 +05002606 qla2x00_free_fcports(vha);
2607
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002608 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002609
Giridhar Malavali08de2842011-08-16 11:31:44 -07002610 qla82xx_md_free(vha);
2611
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002612 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
Chad Dupuis88670482010-07-23 15:28:30 +05002615void qla2x00_free_fcports(struct scsi_qla_host *vha)
2616{
2617 fc_port_t *fcport, *tfcport;
2618
2619 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2620 list_del(&fcport->list);
2621 kfree(fcport);
2622 fcport = NULL;
2623 }
2624}
2625
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002626static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002628 int defer)
2629{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002630 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002631 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002632 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002633
2634 if (!fcport->rport)
2635 return;
2636
2637 rport = fcport->rport;
2638 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002639 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002640 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002641 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002642 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002643 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2644 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002645 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002646 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002647}
2648
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2651 *
2652 * Input: ha = adapter block pointer. fcport = port structure pointer.
2653 *
2654 * Return: None.
2655 *
2656 * Context:
2657 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002659 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002661 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 vha->vp_idx == fcport->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002663 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 qla2x00_schedule_rport_del(vha, fcport, defer);
2665 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002666 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 * We may need to retry the login, so don't change the state of the
2668 * port but do the retries.
2669 */
2670 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07002671 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
2673 if (!do_login)
2674 return;
2675
2676 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 fcport->login_retry = vha->hw->login_retry_count;
2678 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002680 ql_dbg(ql_dbg_disc, vha, 0x2067,
2681 "Port login retry "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 "%02x%02x%02x%02x%02x%02x%02x%02x, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002683 "id = 0x%04x retry cnt=%d.\n",
2684 fcport->port_name[0], fcport->port_name[1],
2685 fcport->port_name[2], fcport->port_name[3],
2686 fcport->port_name[4], fcport->port_name[5],
2687 fcport->port_name[6], fcport->port_name[7],
2688 fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 }
2690}
2691
2692/*
2693 * qla2x00_mark_all_devices_lost
2694 * Updates fcport state when device goes offline.
2695 *
2696 * Input:
2697 * ha = adapter block pointer.
2698 * fcport = port structure pointer.
2699 *
2700 * Return:
2701 * None.
2702 *
2703 * Context:
2704 */
2705void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707{
2708 fc_port_t *fcport;
2709
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002710 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002711 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002713
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 /*
2715 * No point in marking the device as lost, if the device is
2716 * already DEAD.
2717 */
2718 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2719 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002721 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002722 if (defer)
2723 qla2x00_schedule_rport_del(vha, fcport, defer);
2724 else if (vha->vp_idx == fcport->vp_idx)
2725 qla2x00_schedule_rport_del(vha, fcport, defer);
2726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 }
2728}
2729
2730/*
2731* qla2x00_mem_alloc
2732* Allocates adapter memory.
2733*
2734* Returns:
2735* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002736* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002738static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002739qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2740 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741{
2742 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
Andrew Vasqueze8711082008-01-31 12:33:48 -08002744 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002746 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002747 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002749 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2750 &ha->gid_list_dma, GFP_KERNEL);
2751 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002752 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
Andrew Vasqueze8711082008-01-31 12:33:48 -08002754 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2755 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002756 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
Giridhar Malavalia9083012010-04-12 17:59:55 -07002758 if (IS_QLA82XX(ha)) {
2759 /* Allocate cache for CT6 Ctx. */
2760 if (!ctx_cachep) {
2761 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2762 sizeof(struct ct6_dsd), 0,
2763 SLAB_HWCACHE_ALIGN, NULL);
2764 if (!ctx_cachep)
2765 goto fail_free_gid_list;
2766 }
2767 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2768 ctx_cachep);
2769 if (!ha->ctx_mempool)
2770 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002771 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
2772 "ctx_cachep=%p ctx_mempool=%p.\n",
2773 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002774 }
2775
Andrew Vasqueze8711082008-01-31 12:33:48 -08002776 /* Get memory for cached NVRAM */
2777 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2778 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002779 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2782 ha->pdev->device);
2783 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2784 DMA_POOL_SIZE, 8, 0);
2785 if (!ha->s_dma_pool)
2786 goto fail_free_nvram;
2787
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002788 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
2789 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
2790 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
2791
Arun Easibad75002010-05-04 15:01:30 -07002792 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002793 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2794 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2795 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002796 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
2797 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002798 goto fail_s_dma_pool;
2799 }
2800
2801 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2802 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2803 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002804 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
2805 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002806 goto fail_dl_dma_pool;
2807 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002808 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
2809 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
2810 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002811 }
2812
Andrew Vasqueze8711082008-01-31 12:33:48 -08002813 /* Allocate memory for SNS commands */
2814 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002816 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002818 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002820 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08002821 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002822 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002824 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002825 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002826 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 goto fail_dma_pool;
2828 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002829 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002831 if (!ha->ct_sns)
2832 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002833 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
2834 "ms_iocb=%p ct_sns=%p.\n",
2835 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 }
2837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002838 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002839 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2840 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002841 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
2842 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 goto fail_req;
2844 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002845 (*req)->length = req_len;
2846 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2847 ((*req)->length + 1) * sizeof(request_t),
2848 &(*req)->dma, GFP_KERNEL);
2849 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002850 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
2851 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 goto fail_req_ring;
2853 }
2854 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002855 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2856 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002857 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
2858 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 goto fail_rsp;
2860 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002861 (*rsp)->hw = ha;
2862 (*rsp)->length = rsp_len;
2863 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2864 ((*rsp)->length + 1) * sizeof(response_t),
2865 &(*rsp)->dma, GFP_KERNEL);
2866 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002867 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
2868 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 goto fail_rsp_ring;
2870 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002871 (*req)->rsp = *rsp;
2872 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002873 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
2874 "req=%p req->length=%d req->ring=%p rsp=%p "
2875 "rsp->length=%d rsp->ring=%p.\n",
2876 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
2877 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002878 /* Allocate memory for NVRAM data for vports */
2879 if (ha->nvram_npiv_size) {
2880 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002881 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002882 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002883 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
2884 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002885 goto fail_npiv_info;
2886 }
2887 } else
2888 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002890 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002891 if (IS_QLA8XXX_TYPE(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002892 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2893 &ha->ex_init_cb_dma);
2894 if (!ha->ex_init_cb)
2895 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002896 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
2897 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002898 }
2899
Giridhar Malavalia9083012010-04-12 17:59:55 -07002900 INIT_LIST_HEAD(&ha->gbl_dsd_list);
2901
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002902 /* Get consistent memory allocated for Async Port-Database. */
2903 if (!IS_FWI2_CAPABLE(ha)) {
2904 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2905 &ha->async_pd_dma);
2906 if (!ha->async_pd)
2907 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002908 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
2909 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002910 }
2911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912 INIT_LIST_HEAD(&ha->vp_list);
2913 return 1;
2914
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002915fail_async_pd:
2916 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002917fail_ex_init_cb:
2918 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002919fail_npiv_info:
2920 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2921 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2922 (*rsp)->ring = NULL;
2923 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002925 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002927 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2928 sizeof(request_t), (*req)->ring, (*req)->dma);
2929 (*req)->ring = NULL;
2930 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002932 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933fail_req:
2934 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2935 ha->ct_sns, ha->ct_sns_dma);
2936 ha->ct_sns = NULL;
2937 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002938fail_free_ms_iocb:
2939 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2940 ha->ms_iocb = NULL;
2941 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002943 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002944 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2945 ha->fcp_cmnd_dma_pool = NULL;
2946 }
2947fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002948 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002949 dma_pool_destroy(ha->dl_dma_pool);
2950 ha->dl_dma_pool = NULL;
2951 }
2952fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 dma_pool_destroy(ha->s_dma_pool);
2954 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002955fail_free_nvram:
2956 kfree(ha->nvram);
2957 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002958fail_free_ctx_mempool:
2959 mempool_destroy(ha->ctx_mempool);
2960 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002961fail_free_srb_mempool:
2962 mempool_destroy(ha->srb_mempool);
2963 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002964fail_free_gid_list:
2965 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002967 ha->gid_list = NULL;
2968 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969fail_free_init_cb:
2970 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2971 ha->init_cb_dma);
2972 ha->init_cb = NULL;
2973 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002974fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002975 ql_log(ql_log_fatal, NULL, 0x0030,
2976 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08002977 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978}
2979
2980/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002981* qla2x00_free_fw_dump
2982* Frees fw dump stuff.
2983*
2984* Input:
2985* ha = adapter block pointer.
2986*/
2987static void
2988qla2x00_free_fw_dump(struct qla_hw_data *ha)
2989{
2990 if (ha->fce)
2991 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2992 ha->fce_dma);
2993
2994 if (ha->fw_dump) {
2995 if (ha->eft)
2996 dma_free_coherent(&ha->pdev->dev,
2997 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2998 vfree(ha->fw_dump);
2999 }
3000 ha->fce = NULL;
3001 ha->fce_dma = 0;
3002 ha->eft = NULL;
3003 ha->eft_dma = 0;
3004 ha->fw_dump = NULL;
3005 ha->fw_dumped = 0;
3006 ha->fw_dump_reading = 0;
3007}
3008
3009/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010* qla2x00_mem_free
3011* Frees all adapter allocated memory.
3012*
3013* Input:
3014* ha = adapter block pointer.
3015*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003016static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003019 qla2x00_free_fw_dump(ha);
3020
Andrew Vasqueze8711082008-01-31 12:33:48 -08003021 if (ha->srb_mempool)
3022 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003024 if (ha->dcbx_tlv)
3025 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3026 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3027
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003028 if (ha->xgmac_data)
3029 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3030 ha->xgmac_data, ha->xgmac_data_dma);
3031
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 if (ha->sns_cmd)
3033 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003034 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
3036 if (ha->ct_sns)
3037 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Andrew Vasquez88729e52006-06-23 16:10:50 -07003040 if (ha->sfp_data)
3041 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3042
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003043 if (ha->edc_data)
3044 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
3045
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 if (ha->ms_iocb)
3047 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3048
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003049 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003050 dma_pool_free(ha->s_dma_pool,
3051 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003052
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003053 if (ha->async_pd)
3054 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3055
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 if (ha->s_dma_pool)
3057 dma_pool_destroy(ha->s_dma_pool);
3058
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 if (ha->gid_list)
3060 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003061 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Giridhar Malavalia9083012010-04-12 17:59:55 -07003063 if (IS_QLA82XX(ha)) {
3064 if (!list_empty(&ha->gbl_dsd_list)) {
3065 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3066
3067 /* clean up allocated prev pool */
3068 list_for_each_entry_safe(dsd_ptr,
3069 tdsd_ptr, &ha->gbl_dsd_list, list) {
3070 dma_pool_free(ha->dl_dma_pool,
3071 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3072 list_del(&dsd_ptr->list);
3073 kfree(dsd_ptr);
3074 }
3075 }
3076 }
3077
3078 if (ha->dl_dma_pool)
3079 dma_pool_destroy(ha->dl_dma_pool);
3080
3081 if (ha->fcp_cmnd_dma_pool)
3082 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3083
3084 if (ha->ctx_mempool)
3085 mempool_destroy(ha->ctx_mempool);
3086
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003087 if (ha->init_cb)
3088 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003089 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 vfree(ha->optrom_buffer);
3091 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003092 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
Andrew Vasqueze8711082008-01-31 12:33:48 -08003094 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003095 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 ha->sns_cmd = NULL;
3097 ha->sns_cmd_dma = 0;
3098 ha->ct_sns = NULL;
3099 ha->ct_sns_dma = 0;
3100 ha->ms_iocb = NULL;
3101 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 ha->init_cb = NULL;
3103 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003104 ha->ex_init_cb = NULL;
3105 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003106 ha->async_pd = NULL;
3107 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108
3109 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003110 ha->dl_dma_pool = NULL;
3111 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 ha->gid_list = NULL;
3114 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003115}
3116
3117struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3118 struct qla_hw_data *ha)
3119{
3120 struct Scsi_Host *host;
3121 struct scsi_qla_host *vha = NULL;
3122
3123 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3124 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003125 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3126 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003127 goto fail;
3128 }
3129
3130 /* Clear our data area */
3131 vha = shost_priv(host);
3132 memset(vha, 0, sizeof(scsi_qla_host_t));
3133
3134 vha->host = host;
3135 vha->host_no = host->host_no;
3136 vha->hw = ha;
3137
3138 INIT_LIST_HEAD(&vha->vp_fcports);
3139 INIT_LIST_HEAD(&vha->work_list);
3140 INIT_LIST_HEAD(&vha->list);
3141
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003142 spin_lock_init(&vha->work_lock);
3143
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003144 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003145 ql_dbg(ql_dbg_init, vha, 0x0041,
3146 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3147 vha->host, vha->hw, vha,
3148 dev_name(&(ha->pdev->dev)));
3149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 return vha;
3151
3152fail:
3153 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154}
3155
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003156static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003157qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003158{
3159 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003160 uint8_t bail;
3161
3162 QLA_VHA_MARK_BUSY(vha, bail);
3163 if (bail)
3164 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003165
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003166 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003167 if (!e) {
3168 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003169 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003170 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003171
3172 INIT_LIST_HEAD(&e->list);
3173 e->type = type;
3174 e->flags = QLA_EVT_FLAG_FREE;
3175 return e;
3176}
3177
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003178static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003179qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003180{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003181 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003182
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003183 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003185 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003187
Andrew Vasquez0971de72008-04-03 13:13:18 -07003188 return QLA_SUCCESS;
3189}
3190
3191int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003193 u32 data)
3194{
3195 struct qla_work_evt *e;
3196
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003197 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003198 if (!e)
3199 return QLA_FUNCTION_FAILED;
3200
3201 e->u.aen.code = code;
3202 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003203 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003204}
3205
Andrew Vasquez8a659572009-02-08 20:50:12 -08003206int
3207qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3208{
3209 struct qla_work_evt *e;
3210
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003211 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003212 if (!e)
3213 return QLA_FUNCTION_FAILED;
3214
3215 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003216 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003217}
3218
Andrew Vasquezac280b62009-08-20 11:06:05 -07003219#define qla2x00_post_async_work(name, type) \
3220int qla2x00_post_async_##name##_work( \
3221 struct scsi_qla_host *vha, \
3222 fc_port_t *fcport, uint16_t *data) \
3223{ \
3224 struct qla_work_evt *e; \
3225 \
3226 e = qla2x00_alloc_work(vha, type); \
3227 if (!e) \
3228 return QLA_FUNCTION_FAILED; \
3229 \
3230 e->u.logio.fcport = fcport; \
3231 if (data) { \
3232 e->u.logio.data[0] = data[0]; \
3233 e->u.logio.data[1] = data[1]; \
3234 } \
3235 return qla2x00_post_work(vha, e); \
3236}
3237
3238qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3239qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3240qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3241qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003242qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3243qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003244
Andrew Vasquez3420d362009-10-13 15:16:45 -07003245int
3246qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3247{
3248 struct qla_work_evt *e;
3249
3250 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3251 if (!e)
3252 return QLA_FUNCTION_FAILED;
3253
3254 e->u.uevent.code = code;
3255 return qla2x00_post_work(vha, e);
3256}
3257
3258static void
3259qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3260{
3261 char event_string[40];
3262 char *envp[] = { event_string, NULL };
3263
3264 switch (code) {
3265 case QLA_UEVENT_CODE_FW_DUMP:
3266 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3267 vha->host_no);
3268 break;
3269 default:
3270 /* do nothing */
3271 break;
3272 }
3273 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3274}
3275
Andrew Vasquezac280b62009-08-20 11:06:05 -07003276void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003278{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003279 struct qla_work_evt *e, *tmp;
3280 unsigned long flags;
3281 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003282
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003283 spin_lock_irqsave(&vha->work_lock, flags);
3284 list_splice_init(&vha->work_list, &work);
3285 spin_unlock_irqrestore(&vha->work_lock, flags);
3286
3287 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003288 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003289
3290 switch (e->type) {
3291 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003293 e->u.aen.code, e->u.aen.data);
3294 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003295 case QLA_EVT_IDC_ACK:
3296 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3297 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003298 case QLA_EVT_ASYNC_LOGIN:
3299 qla2x00_async_login(vha, e->u.logio.fcport,
3300 e->u.logio.data);
3301 break;
3302 case QLA_EVT_ASYNC_LOGIN_DONE:
3303 qla2x00_async_login_done(vha, e->u.logio.fcport,
3304 e->u.logio.data);
3305 break;
3306 case QLA_EVT_ASYNC_LOGOUT:
3307 qla2x00_async_logout(vha, e->u.logio.fcport);
3308 break;
3309 case QLA_EVT_ASYNC_LOGOUT_DONE:
3310 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3311 e->u.logio.data);
3312 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003313 case QLA_EVT_ASYNC_ADISC:
3314 qla2x00_async_adisc(vha, e->u.logio.fcport,
3315 e->u.logio.data);
3316 break;
3317 case QLA_EVT_ASYNC_ADISC_DONE:
3318 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3319 e->u.logio.data);
3320 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003321 case QLA_EVT_UEVENT:
3322 qla2x00_uevent_emit(vha, e->u.uevent.code);
3323 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003324 }
3325 if (e->flags & QLA_EVT_FLAG_FREE)
3326 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003327
3328 /* For each work completed decrement vha ref count */
3329 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003330 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003331}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003332
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333/* Relogins all the fcports of a vport
3334 * Context: dpc thread
3335 */
3336void qla2x00_relogin(struct scsi_qla_host *vha)
3337{
3338 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003339 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 uint16_t next_loopid = 0;
3341 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003342 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003343
3344 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3345 /*
3346 * If the port is not ONLINE then try to login
3347 * to it if we haven't run out of retries.
3348 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003349 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3350 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003351 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003353 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003354 ha->isp_ops->fabric_logout(vha,
3355 fcport->loop_id,
3356 fcport->d_id.b.domain,
3357 fcport->d_id.b.area,
3358 fcport->d_id.b.al_pa);
3359
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003360 if (fcport->loop_id == FC_NO_LOOP_ID) {
3361 fcport->loop_id = next_loopid =
3362 ha->min_external_loopid;
3363 status = qla2x00_find_new_loop_id(
3364 vha, fcport);
3365 if (status != QLA_SUCCESS) {
3366 /* Ran out of IDs to use */
3367 break;
3368 }
3369 }
3370
Andrew Vasquezac280b62009-08-20 11:06:05 -07003371 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003372 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003373 data[0] = 0;
3374 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3375 status = qla2x00_post_async_login_work(
3376 vha, fcport, data);
3377 if (status == QLA_SUCCESS)
3378 continue;
3379 /* Attempt a retry. */
3380 status = 1;
3381 } else
3382 status = qla2x00_fabric_login(vha,
3383 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 } else
3385 status = qla2x00_local_device_login(vha,
3386 fcport);
3387
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 if (status == QLA_SUCCESS) {
3389 fcport->old_loop_id = fcport->loop_id;
3390
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003391 ql_dbg(ql_dbg_disc, vha, 0x2003,
3392 "Port login OK: logged in ID 0x%x.\n",
3393 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394
3395 qla2x00_update_fcport(vha, fcport);
3396
3397 } else if (status == 1) {
3398 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3399 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003400 ql_dbg(ql_dbg_disc, vha, 0x2007,
3401 "Retrying %d login again loop_id 0x%x.\n",
3402 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 } else {
3404 fcport->login_retry = 0;
3405 }
3406
3407 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3408 fcport->loop_id = FC_NO_LOOP_ID;
3409 }
3410 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3411 break;
3412 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003413}
3414
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415/**************************************************************************
3416* qla2x00_do_dpc
3417* This kernel thread is a task that is schedule by the interrupt handler
3418* to perform the background processing for interrupts.
3419*
3420* Notes:
3421* This task always run in the context of a kernel thread. It
3422* is kick-off by the driver's detect code and starts up
3423* up one per adapter. It immediately goes to sleep and waits for
3424* some fibre event. When either the interrupt handler or
3425* the timer routine detects a event it will one of the task
3426* bits then wake us up.
3427**************************************************************************/
3428static int
3429qla2x00_do_dpc(void *data)
3430{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003431 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 scsi_qla_host_t *base_vha;
3433 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08003434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003435 ha = (struct qla_hw_data *)data;
3436 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 set_user_nice(current, -20);
3439
James Bottomley563585e2011-01-27 16:12:37 -05003440 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01003441 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003442 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
3443 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
Christoph Hellwig39a11242006-02-14 18:46:22 +01003445 schedule();
3446 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003448 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
3449 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
Andrew Vasquez85880802009-12-15 21:29:46 -08003451 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003452 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
3453 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003454 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08003455 }
3456
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 ha->dpc_active = 1;
3458
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003459 ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
3460 "DPC handler waking up.\n");
3461 ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
3462 "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003464 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003465
Giridhar Malavalia9083012010-04-12 17:59:55 -07003466 if (IS_QLA82XX(ha)) {
3467 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3468 &base_vha->dpc_flags)) {
3469 qla82xx_idc_lock(ha);
3470 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3471 QLA82XX_DEV_FAILED);
3472 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003473 ql_log(ql_log_info, base_vha, 0x4004,
3474 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003475 qla82xx_device_state_handler(base_vha);
3476 continue;
3477 }
3478
3479 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3480 &base_vha->dpc_flags)) {
3481
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003482 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
3483 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003484 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3485 &base_vha->dpc_flags))) {
3486 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3487 /* FCoE-ctx reset failed.
3488 * Escalate to chip-reset
3489 */
3490 set_bit(ISP_ABORT_NEEDED,
3491 &base_vha->dpc_flags);
3492 }
3493 clear_bit(ABORT_ISP_ACTIVE,
3494 &base_vha->dpc_flags);
3495 }
3496
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003497 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
3498 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003499 }
3500 }
3501
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3503 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003505 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
3506 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003508 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
Giridhar Malavalia9083012010-04-12 17:59:55 -07003510 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 /* failed. retry later */
3512 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 clear_bit(ABORT_ISP_ACTIVE,
3516 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08003517 }
3518
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003519 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
3520 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 }
3522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003523 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3524 qla2x00_update_fcports(base_vha);
3525 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003526 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003527
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003528 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003529 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
3530 "Quiescence mode scheduled.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003531 qla82xx_device_state_handler(base_vha);
3532 clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
3533 if (!ha->flags.quiesce_owner) {
3534 qla2x00_perform_loop_resync(base_vha);
3535
3536 qla82xx_idc_lock(ha);
3537 qla82xx_clear_qsnt_ready(base_vha);
3538 qla82xx_idc_unlock(ha);
3539 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003540 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
3541 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003542 }
3543
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003544 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3545 &base_vha->dpc_flags) &&
3546 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003548 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
3549 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 qla2x00_rst_aen(base_vha);
3551 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003552 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
3553 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 }
3555
3556 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 if ((test_and_clear_bit(RELOGIN_NEEDED,
3558 &base_vha->dpc_flags)) &&
3559 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3560 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003562 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
3563 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003564 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003565 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
3566 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 }
3568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003569 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3570 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003572 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
3573 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574
3575 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003580 clear_bit(LOOP_RESYNC_ACTIVE,
3581 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 }
3583
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003584 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
3585 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 }
3587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003588 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3589 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3590 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3591 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07003592 }
3593
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003595 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003597 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3598 &base_vha->dpc_flags))
3599 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003600
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003601 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003602
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003604end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05003605 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05003607 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003609 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
3610 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611
3612 /*
3613 * Make sure that nobody tries to wake us up again.
3614 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 ha->dpc_active = 0;
3616
Andrew Vasquezac280b62009-08-20 11:06:05 -07003617 /* Cleanup any residual CTX SRBs. */
3618 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3619
Christoph Hellwig39a11242006-02-14 18:46:22 +01003620 return 0;
3621}
3622
3623void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003624qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003625{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003626 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003627 struct task_struct *t = ha->dpc_thread;
3628
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003630 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631}
3632
3633/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634* qla2x00_rst_aen
3635* Processes asynchronous reset.
3636*
3637* Input:
3638* ha = adapter block pointer.
3639*/
3640static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003643 if (vha->flags.online && !vha->flags.reset_active &&
3644 !atomic_read(&vha->loop_down_timer) &&
3645 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648
3649 /*
3650 * Issue marker command only when we are going to start
3651 * the I/O.
3652 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 vha->marker_needed = 1;
3654 } while (!atomic_read(&vha->loop_down_timer) &&
3655 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 }
3657}
3658
f4f051e2005-04-17 15:02:26 -05003659static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003660qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003661{
3662 struct scsi_cmnd *cmd = sp->cmd;
Arun Easibad75002010-05-04 15:01:30 -07003663 struct qla_hw_data *ha = sp->fcport->vha->hw;
f4f051e2005-04-17 15:02:26 -05003664
3665 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003666 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003667 sp->flags &= ~SRB_DMA_VALID;
3668 }
Arun Easibad75002010-05-04 15:01:30 -07003669
3670 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
3671 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
3672 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
3673 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
3674 }
3675
3676 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
3677 /* List assured to be having elements */
3678 qla2x00_clean_dsd_pool(ha, sp);
3679 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
3680 }
3681
3682 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
3683 dma_pool_free(ha->dl_dma_pool, sp->ctx,
3684 ((struct crc_context *)sp->ctx)->crc_ctx_dma);
3685 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
3686 }
3687
Giridhar Malavalia9083012010-04-12 17:59:55 -07003688 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
3689 struct ct6_dsd *ctx = sp->ctx;
3690 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
3691 ctx->fcp_cmnd_dma);
3692 list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
3693 ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
3694 ha->gbl_dsd_avail += ctx->dsd_use_cnt;
3695 mempool_free(sp->ctx, ha->ctx_mempool);
3696 sp->ctx = NULL;
3697 }
f4f051e2005-04-17 15:02:26 -05003698
Giridhar Malavalic4631192011-11-18 09:03:08 -08003699 CMD_SP(cmd) = NULL;
3700}
3701
3702static void
3703qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
3704{
3705 struct scsi_cmnd *cmd = sp->cmd;
3706
3707 qla2x00_sp_free_dma(sp);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003708 mempool_free(sp, ha->srb_mempool);
f4f051e2005-04-17 15:02:26 -05003709 cmd->scsi_done(cmd);
3710}
bdf79622005-04-17 15:06:53 -05003711
Giridhar Malavali083a4692010-05-28 15:08:18 -07003712void
3713qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3714{
3715 if (atomic_read(&sp->ref_count) == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003716 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
3717 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
3718 sp, sp->cmd);
3719 if (ql2xextended_error_logging & ql_dbg_io)
3720 BUG();
Giridhar Malavali083a4692010-05-28 15:08:18 -07003721 return;
3722 }
3723 if (!atomic_dec_and_test(&sp->ref_count))
3724 return;
3725 qla2x00_sp_final_compl(ha, sp);
3726}
3727
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728/**************************************************************************
3729* qla2x00_timer
3730*
3731* Description:
3732* One second timer
3733*
3734* Context: Interrupt
3735***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003736void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003737qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 int start_dpc = 0;
3741 int index;
3742 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08003743 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003744 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003745 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003746
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003747 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003748 ql_dbg(ql_dbg_timer, vha, 0x6000,
3749 "EEH = %d, restarting timer.\n",
3750 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003751 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3752 return;
3753 }
3754
Andrew Vasquez85880802009-12-15 21:29:46 -08003755 /* Hardware read to raise pending EEH errors during mailbox waits. */
3756 if (!pci_channel_offline(ha->pdev))
3757 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003759 /* Make sure qla82xx_watchdog is run only for physical port */
3760 if (!vha->vp_idx && IS_QLA82XX(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003761 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
3762 start_dpc++;
3763 qla82xx_watchdog(vha);
3764 }
3765
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003768 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
3769 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003770 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003772 if (atomic_read(&vha->loop_down_timer) ==
3773 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003775 ql_log(ql_log_info, vha, 0x6008,
3776 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003778 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3779 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003781 /*
3782 * Schedule an ISP abort to return any FCP2-device
3783 * commands.
3784 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003785 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003786 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003787 spin_lock_irqsave(&ha->hardware_lock,
3788 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003789 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003790 for (index = 1;
3791 index < MAX_OUTSTANDING_COMMANDS;
3792 index++) {
3793 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003795 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003796 if (!sp)
3797 continue;
Arun Easibad75002010-05-04 15:01:30 -07003798 if (sp->ctx && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003799 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003800 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003801 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003802 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003804 if (IS_QLA82XX(ha))
3805 set_bit(FCOE_CTX_RESET_NEEDED,
3806 &vha->dpc_flags);
3807 else
3808 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003810 break;
3811 }
3812 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003813 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 start_dpc++;
3816 }
3817
3818 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003820 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003821 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 "Loop down - aborting ISP.\n");
3823
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003824 if (IS_QLA82XX(ha))
3825 set_bit(FCOE_CTX_RESET_NEEDED,
3826 &vha->dpc_flags);
3827 else
3828 set_bit(ISP_ABORT_NEEDED,
3829 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 }
3831 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003832 ql_dbg(ql_dbg_timer, vha, 0x600a,
3833 "Loop down - seconds remaining %d.\n",
3834 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 }
3836
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003837 /* Check if beacon LED needs to be blinked for physical host only */
3838 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07003839 /* There is no beacon_blink function for ISP82xx */
3840 if (!IS_QLA82XX(ha)) {
3841 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3842 start_dpc++;
3843 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003844 }
3845
Andrew Vasquez550bf572008-04-24 15:21:23 -07003846 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003847 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003848 start_dpc++;
3849
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003851 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3852 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3853 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003855 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3856 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07003857 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3858 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003859 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003860 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
3861 ql_dbg(ql_dbg_timer, vha, 0x600b,
3862 "isp_abort_needed=%d loop_resync_needed=%d "
3863 "fcport_update_needed=%d start_dpc=%d "
3864 "reset_marker_needed=%d",
3865 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
3866 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
3867 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
3868 start_dpc,
3869 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
3870 ql_dbg(ql_dbg_timer, vha, 0x600c,
3871 "beacon_blink_needed=%d isp_unrecoverable=%d "
3872 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
3873 "relogin_needed=%d.\n",
3874 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
3875 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
3876 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
3877 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
3878 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003879 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883}
3884
Andrew Vasquez54333832005-11-09 15:49:04 -08003885/* Firmware interface routines. */
3886
Giridhar Malavalia9083012010-04-12 17:59:55 -07003887#define FW_BLOBS 8
Andrew Vasquez54333832005-11-09 15:49:04 -08003888#define FW_ISP21XX 0
3889#define FW_ISP22XX 1
3890#define FW_ISP2300 2
3891#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003892#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003893#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003894#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07003895#define FW_ISP82XX 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003896
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003897#define FW_FILE_ISP21XX "ql2100_fw.bin"
3898#define FW_FILE_ISP22XX "ql2200_fw.bin"
3899#define FW_FILE_ISP2300 "ql2300_fw.bin"
3900#define FW_FILE_ISP2322 "ql2322_fw.bin"
3901#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003902#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003903#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07003904#define FW_FILE_ISP82XX "ql8200_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003905
Daniel Walkere1e82b62008-05-12 22:21:10 -07003906static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003907
3908static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003909 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3910 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3911 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3912 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3913 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003914 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003915 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07003916 { .name = FW_FILE_ISP82XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003917};
3918
3919struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003920qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003921{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003923 struct fw_blob *blob;
3924
3925 blob = NULL;
3926 if (IS_QLA2100(ha)) {
3927 blob = &qla_fw_blobs[FW_ISP21XX];
3928 } else if (IS_QLA2200(ha)) {
3929 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003930 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003931 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003932 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003933 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003934 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003935 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003936 } else if (IS_QLA25XX(ha)) {
3937 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003938 } else if (IS_QLA81XX(ha)) {
3939 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07003940 } else if (IS_QLA82XX(ha)) {
3941 blob = &qla_fw_blobs[FW_ISP82XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003942 }
3943
Daniel Walkere1e82b62008-05-12 22:21:10 -07003944 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003945 if (blob->fw)
3946 goto out;
3947
3948 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003949 ql_log(ql_log_warn, vha, 0x0063,
3950 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08003951 blob->fw = NULL;
3952 blob = NULL;
3953 goto out;
3954 }
3955
3956out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003957 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003958 return blob;
3959}
3960
3961static void
3962qla2x00_release_firmware(void)
3963{
3964 int idx;
3965
Daniel Walkere1e82b62008-05-12 22:21:10 -07003966 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003967 for (idx = 0; idx < FW_BLOBS; idx++)
3968 if (qla_fw_blobs[idx].fw)
3969 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003970 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003971}
3972
Seokmann Ju14e660e2007-09-20 14:07:36 -07003973static pci_ers_result_t
3974qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3975{
Andrew Vasquez85880802009-12-15 21:29:46 -08003976 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3977 struct qla_hw_data *ha = vha->hw;
3978
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003979 ql_dbg(ql_dbg_aer, vha, 0x9000,
3980 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07003981
Seokmann Ju14e660e2007-09-20 14:07:36 -07003982 switch (state) {
3983 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003984 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003985 return PCI_ERS_RESULT_CAN_RECOVER;
3986 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08003987 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003988 /* For ISP82XX complete any pending mailbox cmd */
3989 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08003990 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08003991 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
3992 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003993 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003994 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003995 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003996 /* Return back all IOs */
3997 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003998 return PCI_ERS_RESULT_NEED_RESET;
3999 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08004000 ha->flags.pci_channel_io_perm_failure = 1;
4001 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004002 return PCI_ERS_RESULT_DISCONNECT;
4003 }
4004 return PCI_ERS_RESULT_NEED_RESET;
4005}
4006
4007static pci_ers_result_t
4008qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4009{
4010 int risc_paused = 0;
4011 uint32_t stat;
4012 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004013 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4014 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004015 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4016 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4017
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07004018 if (IS_QLA82XX(ha))
4019 return PCI_ERS_RESULT_RECOVERED;
4020
Seokmann Ju14e660e2007-09-20 14:07:36 -07004021 spin_lock_irqsave(&ha->hardware_lock, flags);
4022 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4023 stat = RD_REG_DWORD(&reg->hccr);
4024 if (stat & HCCR_RISC_PAUSE)
4025 risc_paused = 1;
4026 } else if (IS_QLA23XX(ha)) {
4027 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
4028 if (stat & HSR_RISC_PAUSED)
4029 risc_paused = 1;
4030 } else if (IS_FWI2_CAPABLE(ha)) {
4031 stat = RD_REG_DWORD(&reg24->host_status);
4032 if (stat & HSRX_RISC_PAUSED)
4033 risc_paused = 1;
4034 }
4035 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4036
4037 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004038 ql_log(ql_log_info, base_vha, 0x9003,
4039 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004041
4042 return PCI_ERS_RESULT_NEED_RESET;
4043 } else
4044 return PCI_ERS_RESULT_RECOVERED;
4045}
4046
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004047uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
4048{
4049 uint32_t rval = QLA_FUNCTION_FAILED;
4050 uint32_t drv_active = 0;
4051 struct qla_hw_data *ha = base_vha->hw;
4052 int fn;
4053 struct pci_dev *other_pdev = NULL;
4054
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004055 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
4056 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004057
4058 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4059
4060 if (base_vha->flags.online) {
4061 /* Abort all outstanding commands,
4062 * so as to be requeued later */
4063 qla2x00_abort_isp_cleanup(base_vha);
4064 }
4065
4066
4067 fn = PCI_FUNC(ha->pdev->devfn);
4068 while (fn > 0) {
4069 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004070 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
4071 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004072 other_pdev =
4073 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4074 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4075 fn));
4076
4077 if (!other_pdev)
4078 continue;
4079 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004080 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
4081 "Found PCI func available and enable at 0x%x.\n",
4082 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004083 pci_dev_put(other_pdev);
4084 break;
4085 }
4086 pci_dev_put(other_pdev);
4087 }
4088
4089 if (!fn) {
4090 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004091 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
4092 "This devfn is reset owner = 0x%x.\n",
4093 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004094 qla82xx_idc_lock(ha);
4095
4096 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4097 QLA82XX_DEV_INITIALIZING);
4098
4099 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
4100 QLA82XX_IDC_VERSION);
4101
4102 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004103 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
4104 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004105
4106 qla82xx_idc_unlock(ha);
4107 /* Reset if device is not already reset
4108 * drv_active would be 0 if a reset has already been done
4109 */
4110 if (drv_active)
4111 rval = qla82xx_start_firmware(base_vha);
4112 else
4113 rval = QLA_SUCCESS;
4114 qla82xx_idc_lock(ha);
4115
4116 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004117 ql_log(ql_log_info, base_vha, 0x900b,
4118 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004119 qla82xx_clear_drv_active(ha);
4120 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4121 QLA82XX_DEV_FAILED);
4122 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004123 ql_log(ql_log_info, base_vha, 0x900c,
4124 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004125 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4126 QLA82XX_DEV_READY);
4127 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08004128 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004129 rval = qla82xx_restart_isp(base_vha);
4130 qla82xx_idc_lock(ha);
4131 /* Clear driver state register */
4132 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
4133 qla82xx_set_drv_active(base_vha);
4134 }
4135 qla82xx_idc_unlock(ha);
4136 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004137 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
4138 "This devfn is not reset owner = 0x%x.\n",
4139 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004140 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
4141 QLA82XX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004142 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004143 rval = qla82xx_restart_isp(base_vha);
4144 qla82xx_idc_lock(ha);
4145 qla82xx_set_drv_active(base_vha);
4146 qla82xx_idc_unlock(ha);
4147 }
4148 }
4149 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4150
4151 return rval;
4152}
4153
Seokmann Ju14e660e2007-09-20 14:07:36 -07004154static pci_ers_result_t
4155qla2xxx_pci_slot_reset(struct pci_dev *pdev)
4156{
4157 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4159 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004160 struct rsp_que *rsp;
4161 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004162
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004163 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
4164 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004165
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004166 /* Workaround: qla2xxx driver which access hardware earlier
4167 * needs error state to be pci_channel_io_online.
4168 * Otherwise mailbox command timesout.
4169 */
4170 pdev->error_state = pci_channel_io_normal;
4171
4172 pci_restore_state(pdev);
4173
Richard Lary8c1496b2010-02-18 10:07:29 -08004174 /* pci_restore_state() clears the saved_state flag of the device
4175 * save restored state which resets saved_state flag
4176 */
4177 pci_save_state(pdev);
4178
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11004179 if (ha->mem_only)
4180 rc = pci_enable_device_mem(pdev);
4181 else
4182 rc = pci_enable_device(pdev);
4183
4184 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004185 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004186 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004187 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004188 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004189
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004190 rsp = ha->rsp_q_map[0];
4191 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004192 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004193
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004194 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004195 goto exit_slot_reset;
4196
4197 if (IS_QLA82XX(ha)) {
4198 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
4199 ret = PCI_ERS_RESULT_RECOVERED;
4200 goto exit_slot_reset;
4201 } else
4202 goto exit_slot_reset;
4203 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004204
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004205 while (ha->flags.mbox_busy && retries--)
4206 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08004207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004209 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07004210 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004212
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004213
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004214exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004215 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
4216 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08004217
Seokmann Ju14e660e2007-09-20 14:07:36 -07004218 return ret;
4219}
4220
4221static void
4222qla2xxx_pci_resume(struct pci_dev *pdev)
4223{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004224 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4225 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004226 int ret;
4227
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004228 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
4229 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004230
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004231 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004232 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004233 ql_log(ql_log_fatal, base_vha, 0x9002,
4234 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07004235 }
Andrew Vasquez85880802009-12-15 21:29:46 -08004236
Lalit Chandivade3e46f032010-05-04 15:01:23 -07004237 pci_cleanup_aer_uncorrect_error_status(pdev);
4238
Andrew Vasquez85880802009-12-15 21:29:46 -08004239 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004240}
4241
4242static struct pci_error_handlers qla2xxx_err_handler = {
4243 .error_detected = qla2xxx_pci_error_detected,
4244 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4245 .slot_reset = qla2xxx_pci_slot_reset,
4246 .resume = qla2xxx_pci_resume,
4247};
4248
Andrew Vasquez54333832005-11-09 15:49:04 -08004249static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004250 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4251 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4252 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4253 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4254 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4255 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4256 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4257 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4258 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004259 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004260 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4261 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004262 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004263 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004264 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Andrew Vasquez54333832005-11-09 15:49:04 -08004265 { 0 },
4266};
4267MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4268
Andrew Vasquezfca29702005-07-06 10:31:47 -07004269static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07004270 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06004271 .driver = {
4272 .owner = THIS_MODULE,
4273 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07004274 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004275 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08004276 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004277 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004278 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07004279};
4280
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004281static struct file_operations apidev_fops = {
4282 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02004283 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004284};
4285
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286/**
4287 * qla2x00_module_init - Module initialization.
4288 **/
4289static int __init
4290qla2x00_module_init(void)
4291{
Andrew Vasquezfca29702005-07-06 10:31:47 -07004292 int ret = 0;
4293
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004295 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09004296 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004298 ql_log(ql_log_fatal, NULL, 0x0001,
4299 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 return -ENOMEM;
4301 }
4302
4303 /* Derive version string. */
4304 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07004305 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07004306 strcat(qla2x00_version_str, "-debug");
4307
Andrew Vasquez1c97a122005-04-21 16:13:36 -04004308 qla2xxx_transport_template =
4309 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004310 if (!qla2xxx_transport_template) {
4311 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004312 ql_log(ql_log_fatal, NULL, 0x0002,
4313 "fc_attach_transport failed...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004315 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004316
4317 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4318 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004319 ql_log(ql_log_fatal, NULL, 0x0003,
4320 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004321 }
4322
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004323 qla2xxx_transport_vport_template =
4324 fc_attach_transport(&qla2xxx_transport_vport_functions);
4325 if (!qla2xxx_transport_vport_template) {
4326 kmem_cache_destroy(srb_cachep);
4327 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004328 ql_log(ql_log_fatal, NULL, 0x0004,
4329 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004330 return -ENODEV;
4331 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004332 ql_log(ql_log_info, NULL, 0x0005,
4333 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07004334 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004335 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004336 if (ret) {
4337 kmem_cache_destroy(srb_cachep);
4338 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004339 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004340 ql_log(ql_log_fatal, NULL, 0x0006,
4341 "pci_register_driver failed...ret=%d Failing load!.\n",
4342 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004343 }
4344 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345}
4346
4347/**
4348 * qla2x00_module_exit - Module cleanup.
4349 **/
4350static void __exit
4351qla2x00_module_exit(void)
4352{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004353 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004354 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08004355 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004356 kmem_cache_destroy(srb_cachep);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004357 if (ctx_cachep)
4358 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004360 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361}
4362
4363module_init(qla2x00_module_init);
4364module_exit(qla2x00_module_exit);
4365
4366MODULE_AUTHOR("QLogic Corporation");
4367MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4368MODULE_LICENSE("GPL");
4369MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004370MODULE_FIRMWARE(FW_FILE_ISP21XX);
4371MODULE_FIRMWARE(FW_FILE_ISP22XX);
4372MODULE_FIRMWARE(FW_FILE_ISP2300);
4373MODULE_FIRMWARE(FW_FILE_ISP2322);
4374MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08004375MODULE_FIRMWARE(FW_FILE_ISP25XX);