blob: 7e617a60e71ff489563a56d12a30d4bf5ed29d70 [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 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800628
629 if (!fcport) {
630 cmd->result = DID_NO_CONNECT << 16;
631 goto qc24_fail_command;
632 }
633
Andrew Vasquezfca29702005-07-06 10:31:47 -0700634 if (atomic_read(&fcport->state) != FCS_ONLINE) {
635 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700636 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700637 ql_dbg(ql_dbg_io, vha, 0x3005,
638 "Returning DNC, fcport_state=%d loop_state=%d.\n",
639 atomic_read(&fcport->state),
640 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700641 cmd->result = DID_NO_CONNECT << 16;
642 goto qc24_fail_command;
643 }
Mike Christie7b594132008-08-17 15:24:40 -0500644 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700645 }
646
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800647 sp = qla2x00_get_new_sp(base_vha, fcport, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700648 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800649 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800651 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700652 if (rval != QLA_SUCCESS) {
653 ql_dbg(ql_dbg_io, vha, 0x3013,
654 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700655 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700656 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700657
Andrew Vasquezfca29702005-07-06 10:31:47 -0700658 return 0;
659
660qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800661 qla2x00_sp_free_dma(sp);
662 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700663
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800664qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700665 return SCSI_MLQUEUE_HOST_BUSY;
666
Mike Christie7b594132008-08-17 15:24:40 -0500667qc24_target_busy:
668 return SCSI_MLQUEUE_TARGET_BUSY;
669
Andrew Vasquezfca29702005-07-06 10:31:47 -0700670qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800671 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700672
673 return 0;
674}
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676/*
677 * qla2x00_eh_wait_on_command
678 * Waits for the command to be returned by the Firmware for some
679 * max time.
680 *
681 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 *
684 * Return:
685 * Not Found : 0
686 * Found : 1
687 */
688static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700691#define ABORT_POLLING_PERIOD 1000
692#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500693 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800694 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
695 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500696 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Andrew Vasquez85880802009-12-15 21:29:46 -0800698 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700699 ql_dbg(ql_dbg_taskm, vha, 0x8005,
700 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800701 return ret;
702 }
703
Lalit Chandivaded9704322009-08-25 11:36:18 -0700704 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700705 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500706 }
707 if (CMD_SP(cmd))
708 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
f4f051e2005-04-17 15:02:26 -0500710 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
713/*
714 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700715 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 * <= MAX_RETRIES_OF_ISP_ABORT or
717 * finally HBA is disabled ie marked offline
718 *
719 * Input:
720 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700721 *
722 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 * Does context switching-Release SPIN_LOCK
724 * (if any) before calling this routine.
725 *
726 * Return:
727 * Success (Adapter is online) : 0
728 * Failed (Adapter is offline/disabled) : 1
729 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800730int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800731qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700733 int return_status;
734 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800735 struct qla_hw_data *ha = vha->hw;
736 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700738 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800739 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
740 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
741 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
742 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 msleep(1000);
745 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800746 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700747 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 else
749 return_status = QLA_FUNCTION_FAILED;
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 return (return_status);
752}
753
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700754/*
755 * qla2x00_wait_for_reset_ready
756 * Wait till the HBA is online after going through
757 * <= MAX_RETRIES_OF_ISP_ABORT or
758 * finally HBA is disabled ie marked offline or flash
759 * operations are in progress.
760 *
761 * Input:
762 * ha - pointer to host adapter structure
763 *
764 * Note:
765 * Does context switching-Release SPIN_LOCK
766 * (if any) before calling this routine.
767 *
768 * Return:
769 * Success (Adapter is online/no flash ops) : 0
770 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
771 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500772static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700773qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
774{
775 int return_status;
776 unsigned long wait_online;
777 struct qla_hw_data *ha = vha->hw;
778 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
779
780 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
781 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
782 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
783 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
784 ha->optrom_state != QLA_SWAITING ||
785 ha->dpc_active) && time_before(jiffies, wait_online))
786 msleep(1000);
787
788 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
789 return_status = QLA_SUCCESS;
790 else
791 return_status = QLA_FUNCTION_FAILED;
792
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700793 ql_dbg(ql_dbg_taskm, vha, 0x8019,
794 "%s return status=%d.\n", __func__, return_status);
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700795
796 return return_status;
797}
798
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700799int
800qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
801{
802 int return_status;
803 unsigned long wait_reset;
804 struct qla_hw_data *ha = vha->hw;
805 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
806
807 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
808 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
809 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
810 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
811 ha->dpc_active) && time_before(jiffies, wait_reset)) {
812
813 msleep(1000);
814
815 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
816 ha->flags.chip_reset_done)
817 break;
818 }
819 if (ha->flags.chip_reset_done)
820 return_status = QLA_SUCCESS;
821 else
822 return_status = QLA_FUNCTION_FAILED;
823
824 return return_status;
825}
826
Giridhar Malavali083a4692010-05-28 15:08:18 -0700827static void
828sp_get(struct srb *sp)
829{
830 atomic_inc(&sp->ref_count);
831}
832
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833/**************************************************************************
834* qla2xxx_eh_abort
835*
836* Description:
837* The abort function will abort the specified command.
838*
839* Input:
840* cmd = Linux SCSI command packet to be aborted.
841*
842* Returns:
843* Either SUCCESS or FAILED.
844*
845* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700846* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800848static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849qla2xxx_eh_abort(struct scsi_cmnd *cmd)
850{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500852 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800853 int ret;
f4f051e2005-04-17 15:02:26 -0500854 unsigned int id, lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700855 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700856 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800857 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
f4f051e2005-04-17 15:02:26 -0500859 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700860 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800862 ret = fc_block_scsi_eh(cmd);
863 if (ret != 0)
864 return ret;
865 ret = SUCCESS;
866
f4f051e2005-04-17 15:02:26 -0500867 id = cmd->device->id;
868 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -0500869
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800870 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700871 sp = (srb_t *) CMD_SP(cmd);
872 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800873 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700874 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500875 }
Mike Christie170babc2010-10-15 11:27:47 -0700876
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700877 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800878 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
879 vha->host_no, id, lun, sp, cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700880
881 /* Get a reference to the sp and drop the lock.*/
882 sp_get(sp);
883
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800884 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700885 if (ha->isp_ops->abort_command(sp)) {
Arun Easia55aac72012-02-09 11:14:03 -0800886 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700887 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800888 "Abort command mbx failed cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700889 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700890 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800891 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -0700892 wait = 1;
893 }
Saurav Kashyap75942062011-08-16 11:29:25 -0700894
895 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -0700896 qla2x00_sp_compl(ha, sp);
Saurav Kashyap75942062011-08-16 11:29:25 -0700897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500898
Chad Dupuisbc91ade2011-08-16 11:29:26 -0700899 /* Did the command return during mailbox execution? */
900 if (ret == FAILED && !CMD_SP(cmd))
901 ret = SUCCESS;
902
f4f051e2005-04-17 15:02:26 -0500903 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700904 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700906 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800907 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -0700908 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700912 ql_log(ql_log_info, vha, 0x801c,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800913 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
914 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
f4f051e2005-04-17 15:02:26 -0500916 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917}
918
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500919int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800920qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500921 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800923 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700924 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800926 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500927 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Andrew Vasquez523ec772008-04-03 13:13:24 -0700929 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700932 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800933 for (cnt = 1; status == QLA_SUCCESS &&
934 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
935 sp = req->outstanding_cmds[cnt];
936 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700937 continue;
Arun Easibad75002010-05-04 15:01:30 -0700938 if ((sp->ctx) && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700939 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800940 if (vha->vp_idx != sp->fcport->vha->vp_idx)
941 continue;
942 match = 0;
943 switch (type) {
944 case WAIT_HOST:
945 match = 1;
946 break;
947 case WAIT_TARGET:
948 match = sp->cmd->device->id == t;
949 break;
950 case WAIT_LUN:
951 match = (sp->cmd->device->id == t &&
952 sp->cmd->device->lun == l);
953 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800955 if (!match)
956 continue;
957
958 spin_unlock_irqrestore(&ha->hardware_lock, flags);
959 status = qla2x00_eh_wait_on_command(sp->cmd);
960 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700963
964 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
Andrew Vasquez523ec772008-04-03 13:13:24 -0700967static char *reset_errors[] = {
968 "HBA not online",
969 "HBA not ready",
970 "Task management failed",
971 "Waiting for command completions",
972};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Andrew Vasquez523ec772008-04-03 13:13:24 -0700974static int
975__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700976 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700977{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700979 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
980 int err;
981
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700982 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700983 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700984 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700985
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -0800986 err = fc_block_scsi_eh(cmd);
987 if (err != 0)
988 return err;
989
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700990 ql_log(ql_log_info, vha, 0x8009,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800991 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700992 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700993
994 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700995 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
996 ql_log(ql_log_warn, vha, 0x800a,
997 "Wait for hba online 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 = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001001 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 != QLA_SUCCESS) {
1003 ql_log(ql_log_warn, vha, 0x800c,
1004 "do_reset 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 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001008 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001009 cmd->device->lun, type) != QLA_SUCCESS) {
1010 ql_log(ql_log_warn, vha, 0x800d,
1011 "wait for peding cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001012 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001013 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001014
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001015 ql_log(ql_log_info, vha, 0x800e,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001016 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1017 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001018
1019 return SUCCESS;
1020
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001021eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001022 ql_log(ql_log_info, vha, 0x800f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001023 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1024 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1025 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001026 return FAILED;
1027}
1028
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001029static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1031{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001032 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1033 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Andrew Vasquez523ec772008-04-03 13:13:24 -07001035 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1036 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001040qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001042 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1043 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Andrew Vasquez523ec772008-04-03 13:13:24 -07001045 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1046 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049/**************************************************************************
1050* qla2xxx_eh_bus_reset
1051*
1052* Description:
1053* The bus reset function will reset the bus and abort any executing
1054* commands.
1055*
1056* Input:
1057* cmd = Linux SCSI command packet of the command that cause the
1058* bus reset.
1059*
1060* Returns:
1061* SUCCESS/FAILURE (defined as macro in scsi.h).
1062*
1063**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001064static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1066{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001067 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001068 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001069 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001070 unsigned int id, lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
f4f051e2005-04-17 15:02:26 -05001072 id = cmd->device->id;
1073 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001074
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001075 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001076 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001079 ret = fc_block_scsi_eh(cmd);
1080 if (ret != 0)
1081 return ret;
1082 ret = FAILED;
1083
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 ql_log(ql_log_info, vha, 0x8012,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001085 "BUS RESET ISSUED nexus=%ld:%d%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001087 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001088 ql_log(ql_log_fatal, vha, 0x8013,
1089 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001090 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092
Saurav Kashyapad537682011-11-18 09:02:09 -08001093 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1094 ret = SUCCESS;
1095
f4f051e2005-04-17 15:02:26 -05001096 if (ret == FAILED)
1097 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001099 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001100 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 QLA_SUCCESS) {
1102 ql_log(ql_log_warn, vha, 0x8014,
1103 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001104 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001105 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
f4f051e2005-04-17 15:02:26 -05001107eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001108 ql_log(ql_log_warn, vha, 0x802b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001109 "BUS RESET %s nexus=%ld:%d:%d.\n",
1110 (ret == FAILED) ? "FAILED" : "SUCCEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
f4f051e2005-04-17 15:02:26 -05001112 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
1115/**************************************************************************
1116* qla2xxx_eh_host_reset
1117*
1118* Description:
1119* The reset function will reset the Adapter.
1120*
1121* Input:
1122* cmd = Linux SCSI command packet of the command that cause the
1123* adapter reset.
1124*
1125* Returns:
1126* Either SUCCESS or FAILED.
1127*
1128* Note:
1129**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001130static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1132{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001134 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001135 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001136 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001137 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
f4f051e2005-04-17 15:02:26 -05001140 id = cmd->device->id;
1141 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001142
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001143 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001144 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 }
f4f051e2005-04-17 15:02:26 -05001146
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001147 ret = fc_block_scsi_eh(cmd);
1148 if (ret != 0)
1149 return ret;
1150 ret = FAILED;
1151
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001152 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001153 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001155 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001156 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001158 if (vha != base_vha) {
1159 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001160 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001161 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001162 if (IS_QLA82XX(vha->hw)) {
1163 if (!qla82xx_fcoe_ctx_reset(vha)) {
1164 /* Ctx reset success */
1165 ret = SUCCESS;
1166 goto eh_host_reset_lock;
1167 }
1168 /* fall thru if ctx reset failed */
1169 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001170 if (ha->wq)
1171 flush_workqueue(ha->wq);
1172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001174 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1176 /* failed. schedule dpc to try */
1177 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1178
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001179 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1180 ql_log(ql_log_warn, vha, 0x802a,
1181 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001183 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001184 }
1185 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001188 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001189 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001190 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001191 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
f4f051e2005-04-17 15:02:26 -05001193eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001194 ql_log(ql_log_info, vha, 0x8017,
1195 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1196 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
f4f051e2005-04-17 15:02:26 -05001198 return ret;
1199}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201/*
1202* qla2x00_loop_reset
1203* Issue loop reset.
1204*
1205* Input:
1206* ha = adapter block pointer.
1207*
1208* Returns:
1209* 0 = success
1210*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001211int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001212qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001214 int ret;
bdf79622005-04-17 15:06:53 -05001215 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001218 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001219 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1220 if (fcport->port_type != FCT_TARGET)
1221 continue;
1222
1223 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1224 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001225 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1226 "Bus Reset failed: Target Reset=%d "
1227 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001228 }
1229 }
1230 }
1231
Giridhar Malavalia9083012010-04-12 17:59:55 -07001232 if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001234 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001235 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1236 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001237 }
1238 atomic_set(&vha->loop_state, LOOP_DOWN);
1239 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1240 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 }
1242
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001243 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad537682011-11-18 09:02:09 -08001245 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001246 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1247 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001248 }
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001251 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001253 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001256void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001257qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001258{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001259 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001260 unsigned long flags;
1261 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001262 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001264 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001265
1266 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001267 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001268 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001269 if (!req)
1270 continue;
1271 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1272 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001273 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001274 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001275 if (!sp->ctx ||
Arun Easibad75002010-05-04 15:01:30 -07001276 (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
1277 IS_PROT_IO(sp)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001278 sp->cmd->result = res;
1279 qla2x00_sp_compl(ha, sp);
1280 } else {
1281 ctx = sp->ctx;
Roland Dreier9bfacd02011-09-22 00:06:05 -07001282 if (ctx->type == SRB_ELS_CMD_RPT ||
1283 ctx->type == SRB_ELS_CMD_HST ||
1284 ctx->type == SRB_CT_CMD) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001285 struct fc_bsg_job *bsg_job =
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001286 ctx->u.bsg_job;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001287 if (bsg_job->request->msgcode
1288 == FC_BSG_HST_CT)
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001289 kfree(sp->fcport);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001290 bsg_job->req->errors = 0;
1291 bsg_job->reply->result = res;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001292 bsg_job->job_done(bsg_job);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001293 kfree(sp->ctx);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001294 mempool_free(sp,
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001295 ha->srb_mempool);
Roland Dreier9bfacd02011-09-22 00:06:05 -07001296 } else {
1297 ctx->u.iocb_cmd->free(sp);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001298 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001299 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001300 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001301 }
1302 }
1303 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1304}
1305
f4f051e2005-04-17 15:02:26 -05001306static int
1307qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
bdf79622005-04-17 15:06:53 -05001309 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001311 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001312 return -ENXIO;
1313
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001314 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001315
1316 return 0;
1317}
1318
1319static int
1320qla2xxx_slave_configure(struct scsi_device *sdev)
1321{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001323 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001324
f4f051e2005-04-17 15:02:26 -05001325 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001326 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001328 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001329 return 0;
1330}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
f4f051e2005-04-17 15:02:26 -05001332static void
1333qla2xxx_slave_destroy(struct scsi_device *sdev)
1334{
1335 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001338static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1339{
1340 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1341
1342 if (!scsi_track_queue_full(sdev, qdepth))
1343 return;
1344
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001345 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001346 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1347 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001348}
1349
1350static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1351{
1352 fc_port_t *fcport = sdev->hostdata;
1353 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001354 struct req_que *req = NULL;
1355
1356 req = vha->req;
1357 if (!req)
1358 return;
1359
1360 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1361 return;
1362
1363 if (sdev->ordered_tags)
1364 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1365 else
1366 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1367
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001368 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001369 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1370 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001371}
1372
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001373static int
Mike Christiee881a172009-10-15 17:46:39 -07001374qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001375{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001376 switch (reason) {
1377 case SCSI_QDEPTH_DEFAULT:
1378 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1379 break;
1380 case SCSI_QDEPTH_QFULL:
1381 qla2x00_handle_queue_full(sdev, qdepth);
1382 break;
1383 case SCSI_QDEPTH_RAMP_UP:
1384 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1385 break;
1386 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001387 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001388 }
Mike Christiee881a172009-10-15 17:46:39 -07001389
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001390 return sdev->queue_depth;
1391}
1392
1393static int
1394qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1395{
1396 if (sdev->tagged_supported) {
1397 scsi_set_tag_type(sdev, tag_type);
1398 if (tag_type)
1399 scsi_activate_tcq(sdev, sdev->queue_depth);
1400 else
1401 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1402 } else
1403 tag_type = 0;
1404
1405 return tag_type;
1406}
1407
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408/**
1409 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1410 * @ha: HA context
1411 *
1412 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1413 * supported addressing method.
1414 */
1415static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001416qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001418 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Yang Hongyang6a355282009-04-06 19:01:13 -07001421 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001422 /* Any upper-dword bits set? */
1423 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001424 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001425 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001427 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1428 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001429 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001432
Yang Hongyang284901a2009-04-06 19:01:15 -07001433 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1434 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435}
1436
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001437static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001438qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001439{
1440 unsigned long flags = 0;
1441 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1442
1443 spin_lock_irqsave(&ha->hardware_lock, flags);
1444 ha->interrupts_on = 1;
1445 /* enable risc and host interrupts */
1446 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1447 RD_REG_WORD(&reg->ictrl);
1448 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1449
1450}
1451
1452static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001454{
1455 unsigned long flags = 0;
1456 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1457
1458 spin_lock_irqsave(&ha->hardware_lock, flags);
1459 ha->interrupts_on = 0;
1460 /* disable risc and host interrupts */
1461 WRT_REG_WORD(&reg->ictrl, 0);
1462 RD_REG_WORD(&reg->ictrl);
1463 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1464}
1465
1466static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001467qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001468{
1469 unsigned long flags = 0;
1470 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1471
1472 spin_lock_irqsave(&ha->hardware_lock, flags);
1473 ha->interrupts_on = 1;
1474 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1475 RD_REG_DWORD(&reg->ictrl);
1476 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1477}
1478
1479static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001481{
1482 unsigned long flags = 0;
1483 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1484
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001485 if (IS_NOPOLLING_TYPE(ha))
1486 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001487 spin_lock_irqsave(&ha->hardware_lock, flags);
1488 ha->interrupts_on = 0;
1489 WRT_REG_DWORD(&reg->ictrl, 0);
1490 RD_REG_DWORD(&reg->ictrl);
1491 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1492}
1493
Giridhar Malavali706f4572011-11-18 09:03:16 -08001494static int
1495qla2x00_iospace_config(struct qla_hw_data *ha)
1496{
1497 resource_size_t pio;
1498 uint16_t msix;
1499 int cpus;
1500
1501 if (IS_QLA82XX(ha))
1502 return qla82xx_iospace_config(ha);
1503
1504 if (pci_request_selected_regions(ha->pdev, ha->bars,
1505 QLA2XXX_DRIVER_NAME)) {
1506 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1507 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1508 pci_name(ha->pdev));
1509 goto iospace_error_exit;
1510 }
1511 if (!(ha->bars & 1))
1512 goto skip_pio;
1513
1514 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1515 pio = pci_resource_start(ha->pdev, 0);
1516 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1517 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1518 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1519 "Invalid pci I/O region size (%s).\n",
1520 pci_name(ha->pdev));
1521 pio = 0;
1522 }
1523 } else {
1524 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1525 "Region #0 no a PIO resource (%s).\n",
1526 pci_name(ha->pdev));
1527 pio = 0;
1528 }
1529 ha->pio_address = pio;
1530 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1531 "PIO address=%llu.\n",
1532 (unsigned long long)ha->pio_address);
1533
1534skip_pio:
1535 /* Use MMIO operations for all accesses. */
1536 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1537 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1538 "Region #1 not an MMIO resource (%s), aborting.\n",
1539 pci_name(ha->pdev));
1540 goto iospace_error_exit;
1541 }
1542 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1543 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1544 "Invalid PCI mem region size (%s), aborting.\n",
1545 pci_name(ha->pdev));
1546 goto iospace_error_exit;
1547 }
1548
1549 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1550 if (!ha->iobase) {
1551 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1552 "Cannot remap MMIO (%s), aborting.\n",
1553 pci_name(ha->pdev));
1554 goto iospace_error_exit;
1555 }
1556
1557 /* Determine queue resources */
1558 ha->max_req_queues = ha->max_rsp_queues = 1;
1559 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1560 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1561 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1562 goto mqiobase_exit;
1563
1564 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1565 pci_resource_len(ha->pdev, 3));
1566 if (ha->mqiobase) {
1567 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1568 "MQIO Base=%p.\n", ha->mqiobase);
1569 /* Read MSIX vector size of the board */
1570 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1571 ha->msix_count = msix;
1572 /* Max queues are bounded by available msix vectors */
1573 /* queue 0 uses two msix vectors */
1574 if (ql2xmultique_tag) {
1575 cpus = num_online_cpus();
1576 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1577 (cpus + 1) : (ha->msix_count - 1);
1578 ha->max_req_queues = 2;
1579 } else if (ql2xmaxqueues > 1) {
1580 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1581 QLA_MQ_SIZE : ql2xmaxqueues;
1582 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1583 "QoS mode set, max no of request queues:%d.\n",
1584 ha->max_req_queues);
1585 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1586 "QoS mode set, max no of request queues:%d.\n",
1587 ha->max_req_queues);
1588 }
1589 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1590 "MSI-X vector count: %d.\n", msix);
1591 } else
1592 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1593 "BAR 3 not enabled.\n");
1594
1595mqiobase_exit:
1596 ha->msix_count = ha->max_rsp_queues + 1;
1597 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1598 "MSIX Count:%d.\n", ha->msix_count);
1599 return (0);
1600
1601iospace_error_exit:
1602 return (-ENOMEM);
1603}
1604
1605
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001606static struct isp_operations qla2100_isp_ops = {
1607 .pci_config = qla2100_pci_config,
1608 .reset_chip = qla2x00_reset_chip,
1609 .chip_diag = qla2x00_chip_diag,
1610 .config_rings = qla2x00_config_rings,
1611 .reset_adapter = qla2x00_reset_adapter,
1612 .nvram_config = qla2x00_nvram_config,
1613 .update_fw_options = qla2x00_update_fw_options,
1614 .load_risc = qla2x00_load_risc,
1615 .pci_info_str = qla2x00_pci_info_str,
1616 .fw_version_str = qla2x00_fw_version_str,
1617 .intr_handler = qla2100_intr_handler,
1618 .enable_intrs = qla2x00_enable_intrs,
1619 .disable_intrs = qla2x00_disable_intrs,
1620 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001621 .target_reset = qla2x00_abort_target,
1622 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001623 .fabric_login = qla2x00_login_fabric,
1624 .fabric_logout = qla2x00_fabric_logout,
1625 .calc_req_entries = qla2x00_calc_iocbs_32,
1626 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1627 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1628 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1629 .read_nvram = qla2x00_read_nvram_data,
1630 .write_nvram = qla2x00_write_nvram_data,
1631 .fw_dump = qla2100_fw_dump,
1632 .beacon_on = NULL,
1633 .beacon_off = NULL,
1634 .beacon_blink = NULL,
1635 .read_optrom = qla2x00_read_optrom_data,
1636 .write_optrom = qla2x00_write_optrom_data,
1637 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001639 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001640 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001641};
1642
1643static struct isp_operations qla2300_isp_ops = {
1644 .pci_config = qla2300_pci_config,
1645 .reset_chip = qla2x00_reset_chip,
1646 .chip_diag = qla2x00_chip_diag,
1647 .config_rings = qla2x00_config_rings,
1648 .reset_adapter = qla2x00_reset_adapter,
1649 .nvram_config = qla2x00_nvram_config,
1650 .update_fw_options = qla2x00_update_fw_options,
1651 .load_risc = qla2x00_load_risc,
1652 .pci_info_str = qla2x00_pci_info_str,
1653 .fw_version_str = qla2x00_fw_version_str,
1654 .intr_handler = qla2300_intr_handler,
1655 .enable_intrs = qla2x00_enable_intrs,
1656 .disable_intrs = qla2x00_disable_intrs,
1657 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001658 .target_reset = qla2x00_abort_target,
1659 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001660 .fabric_login = qla2x00_login_fabric,
1661 .fabric_logout = qla2x00_fabric_logout,
1662 .calc_req_entries = qla2x00_calc_iocbs_32,
1663 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1664 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1665 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1666 .read_nvram = qla2x00_read_nvram_data,
1667 .write_nvram = qla2x00_write_nvram_data,
1668 .fw_dump = qla2300_fw_dump,
1669 .beacon_on = qla2x00_beacon_on,
1670 .beacon_off = qla2x00_beacon_off,
1671 .beacon_blink = qla2x00_beacon_blink,
1672 .read_optrom = qla2x00_read_optrom_data,
1673 .write_optrom = qla2x00_write_optrom_data,
1674 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001675 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001676 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001677 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001678};
1679
1680static struct isp_operations qla24xx_isp_ops = {
1681 .pci_config = qla24xx_pci_config,
1682 .reset_chip = qla24xx_reset_chip,
1683 .chip_diag = qla24xx_chip_diag,
1684 .config_rings = qla24xx_config_rings,
1685 .reset_adapter = qla24xx_reset_adapter,
1686 .nvram_config = qla24xx_nvram_config,
1687 .update_fw_options = qla24xx_update_fw_options,
1688 .load_risc = qla24xx_load_risc,
1689 .pci_info_str = qla24xx_pci_info_str,
1690 .fw_version_str = qla24xx_fw_version_str,
1691 .intr_handler = qla24xx_intr_handler,
1692 .enable_intrs = qla24xx_enable_intrs,
1693 .disable_intrs = qla24xx_disable_intrs,
1694 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001695 .target_reset = qla24xx_abort_target,
1696 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001697 .fabric_login = qla24xx_login_fabric,
1698 .fabric_logout = qla24xx_fabric_logout,
1699 .calc_req_entries = NULL,
1700 .build_iocbs = NULL,
1701 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1702 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1703 .read_nvram = qla24xx_read_nvram_data,
1704 .write_nvram = qla24xx_write_nvram_data,
1705 .fw_dump = qla24xx_fw_dump,
1706 .beacon_on = qla24xx_beacon_on,
1707 .beacon_off = qla24xx_beacon_off,
1708 .beacon_blink = qla24xx_beacon_blink,
1709 .read_optrom = qla24xx_read_optrom_data,
1710 .write_optrom = qla24xx_write_optrom_data,
1711 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001712 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001713 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001714 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001715};
1716
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001717static struct isp_operations qla25xx_isp_ops = {
1718 .pci_config = qla25xx_pci_config,
1719 .reset_chip = qla24xx_reset_chip,
1720 .chip_diag = qla24xx_chip_diag,
1721 .config_rings = qla24xx_config_rings,
1722 .reset_adapter = qla24xx_reset_adapter,
1723 .nvram_config = qla24xx_nvram_config,
1724 .update_fw_options = qla24xx_update_fw_options,
1725 .load_risc = qla24xx_load_risc,
1726 .pci_info_str = qla24xx_pci_info_str,
1727 .fw_version_str = qla24xx_fw_version_str,
1728 .intr_handler = qla24xx_intr_handler,
1729 .enable_intrs = qla24xx_enable_intrs,
1730 .disable_intrs = qla24xx_disable_intrs,
1731 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001732 .target_reset = qla24xx_abort_target,
1733 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001734 .fabric_login = qla24xx_login_fabric,
1735 .fabric_logout = qla24xx_fabric_logout,
1736 .calc_req_entries = NULL,
1737 .build_iocbs = NULL,
1738 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1739 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1740 .read_nvram = qla25xx_read_nvram_data,
1741 .write_nvram = qla25xx_write_nvram_data,
1742 .fw_dump = qla25xx_fw_dump,
1743 .beacon_on = qla24xx_beacon_on,
1744 .beacon_off = qla24xx_beacon_off,
1745 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001746 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001747 .write_optrom = qla24xx_write_optrom_data,
1748 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001749 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001750 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001751 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001752};
1753
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001754static struct isp_operations qla81xx_isp_ops = {
1755 .pci_config = qla25xx_pci_config,
1756 .reset_chip = qla24xx_reset_chip,
1757 .chip_diag = qla24xx_chip_diag,
1758 .config_rings = qla24xx_config_rings,
1759 .reset_adapter = qla24xx_reset_adapter,
1760 .nvram_config = qla81xx_nvram_config,
1761 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001762 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001763 .pci_info_str = qla24xx_pci_info_str,
1764 .fw_version_str = qla24xx_fw_version_str,
1765 .intr_handler = qla24xx_intr_handler,
1766 .enable_intrs = qla24xx_enable_intrs,
1767 .disable_intrs = qla24xx_disable_intrs,
1768 .abort_command = qla24xx_abort_command,
1769 .target_reset = qla24xx_abort_target,
1770 .lun_reset = qla24xx_lun_reset,
1771 .fabric_login = qla24xx_login_fabric,
1772 .fabric_logout = qla24xx_fabric_logout,
1773 .calc_req_entries = NULL,
1774 .build_iocbs = NULL,
1775 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1776 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001777 .read_nvram = NULL,
1778 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001779 .fw_dump = qla81xx_fw_dump,
1780 .beacon_on = qla24xx_beacon_on,
1781 .beacon_off = qla24xx_beacon_off,
1782 .beacon_blink = qla24xx_beacon_blink,
1783 .read_optrom = qla25xx_read_optrom_data,
1784 .write_optrom = qla24xx_write_optrom_data,
1785 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001786 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001787 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001788 .iospace_config = qla2x00_iospace_config,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001789};
1790
1791static struct isp_operations qla82xx_isp_ops = {
1792 .pci_config = qla82xx_pci_config,
1793 .reset_chip = qla82xx_reset_chip,
1794 .chip_diag = qla24xx_chip_diag,
1795 .config_rings = qla82xx_config_rings,
1796 .reset_adapter = qla24xx_reset_adapter,
1797 .nvram_config = qla81xx_nvram_config,
1798 .update_fw_options = qla24xx_update_fw_options,
1799 .load_risc = qla82xx_load_risc,
1800 .pci_info_str = qla82xx_pci_info_str,
1801 .fw_version_str = qla24xx_fw_version_str,
1802 .intr_handler = qla82xx_intr_handler,
1803 .enable_intrs = qla82xx_enable_intrs,
1804 .disable_intrs = qla82xx_disable_intrs,
1805 .abort_command = qla24xx_abort_command,
1806 .target_reset = qla24xx_abort_target,
1807 .lun_reset = qla24xx_lun_reset,
1808 .fabric_login = qla24xx_login_fabric,
1809 .fabric_logout = qla24xx_fabric_logout,
1810 .calc_req_entries = NULL,
1811 .build_iocbs = NULL,
1812 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1813 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1814 .read_nvram = qla24xx_read_nvram_data,
1815 .write_nvram = qla24xx_write_nvram_data,
1816 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001817 .beacon_on = qla82xx_beacon_on,
1818 .beacon_off = qla82xx_beacon_off,
1819 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001820 .read_optrom = qla82xx_read_optrom_data,
1821 .write_optrom = qla82xx_write_optrom_data,
1822 .get_flash_version = qla24xx_get_flash_version,
1823 .start_scsi = qla82xx_start_scsi,
1824 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001825 .iospace_config = qla82xx_iospace_config,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001826};
1827
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001828static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001829qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001830{
1831 ha->device_type = DT_EXTENDED_IDS;
1832 switch (ha->pdev->device) {
1833 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1834 ha->device_type |= DT_ISP2100;
1835 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001836 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001837 break;
1838 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1839 ha->device_type |= DT_ISP2200;
1840 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001841 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001842 break;
1843 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1844 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001845 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001846 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001847 break;
1848 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1849 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001850 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001851 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001852 break;
1853 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1854 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001855 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001856 if (ha->pdev->subsystem_vendor == 0x1028 &&
1857 ha->pdev->subsystem_device == 0x0170)
1858 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001859 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001860 break;
1861 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1862 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001863 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001864 break;
1865 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1866 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001867 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001868 break;
1869 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1870 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001871 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001872 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001873 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001874 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001875 break;
1876 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1877 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001878 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001879 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001880 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001881 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001882 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001883 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1884 ha->device_type |= DT_ISP8432;
1885 ha->device_type |= DT_ZIO_SUPPORTED;
1886 ha->device_type |= DT_FWI2;
1887 ha->device_type |= DT_IIDMA;
1888 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1889 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001890 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1891 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001892 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001893 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001894 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001895 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1896 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001897 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001898 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001899 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001900 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1901 ha->device_type |= DT_ISP2532;
1902 ha->device_type |= DT_ZIO_SUPPORTED;
1903 ha->device_type |= DT_FWI2;
1904 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001905 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1906 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001907 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1908 ha->device_type |= DT_ISP8001;
1909 ha->device_type |= DT_ZIO_SUPPORTED;
1910 ha->device_type |= DT_FWI2;
1911 ha->device_type |= DT_IIDMA;
1912 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1913 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001914 case PCI_DEVICE_ID_QLOGIC_ISP8021:
1915 ha->device_type |= DT_ISP8021;
1916 ha->device_type |= DT_ZIO_SUPPORTED;
1917 ha->device_type |= DT_FWI2;
1918 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1919 /* Initialize 82XX ISP flags */
1920 qla82xx_init_flags(ha);
1921 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001922 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001923
Giridhar Malavalia9083012010-04-12 17:59:55 -07001924 if (IS_QLA82XX(ha))
1925 ha->port_no = !(ha->portnum & 1);
1926 else
1927 /* Get adapter physical port no from interrupt pin register. */
1928 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1929
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001930 if (ha->port_no & 1)
1931 ha->flags.port0 = 1;
1932 else
1933 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001934 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08001935 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001936 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001937}
1938
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001939static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001940qla2xxx_scan_start(struct Scsi_Host *shost)
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
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001944 if (vha->hw->flags.running_gold_fw)
1945 return;
1946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1948 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1949 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1950 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001951}
1952
1953static int
1954qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1955{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001956 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001957
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001958 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001959 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001961 return 1;
1962
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001963 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001964}
1965
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966/*
1967 * PCI driver interface
1968 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001969static int __devinit
1970qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001972 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974 scsi_qla_host_t *base_vha = NULL;
1975 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001976 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001978 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001979 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001981 struct req_que *req = NULL;
1982 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
Andrew Vasquez285d0322007-10-19 15:59:17 -07001984 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001985 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001986 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1987 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001988 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001989 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1990 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001991 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07001992 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
1993 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001994 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001995 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001996 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
1997 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07001998 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001999 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2000 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002001
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002002 if (mem_only) {
2003 if (pci_enable_device_mem(pdev))
2004 goto probe_out;
2005 } else {
2006 if (pci_enable_device(pdev))
2007 goto probe_out;
2008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
Jesse Barnes09276782008-10-18 17:33:19 -07002010 /* This may fail but that's ok */
2011 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002013 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2014 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002015 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2016 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002017 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002019 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2020 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
2023 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002024 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002025 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002026 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002027 spin_lock_init(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002029 /* Set ISP-type information. */
2030 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002031
2032 /* Set EEH reset type to fundamental if required by hba */
2033 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
2034 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002035 }
2036
Chad Dupuiscba1e472011-11-18 09:03:21 -08002037 ha->prev_topology = 0;
2038 ha->init_cb_size = sizeof(init_cb_t);
2039 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2040 ha->optrom_size = OPTROM_SIZE_2300;
2041
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002042 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 req_length = REQUEST_ENTRY_CNT_2100;
2048 rsp_length = RESPONSE_ENTRY_CNT_2100;
2049 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002050 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002051 ha->flash_conf_off = ~0;
2052 ha->flash_data_off = ~0;
2053 ha->nvram_conf_off = ~0;
2054 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002055 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 } else if (IS_QLA2200(ha)) {
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002057 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002058 req_length = REQUEST_ENTRY_CNT_2200;
2059 rsp_length = RESPONSE_ENTRY_CNT_2100;
2060 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002061 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002062 ha->flash_conf_off = ~0;
2063 ha->flash_data_off = ~0;
2064 ha->nvram_conf_off = ~0;
2065 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002066 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002067 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 req_length = REQUEST_ENTRY_CNT_2200;
2070 rsp_length = RESPONSE_ENTRY_CNT_2300;
2071 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002072 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002073 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2074 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002075 ha->flash_conf_off = ~0;
2076 ha->flash_data_off = ~0;
2077 ha->nvram_conf_off = ~0;
2078 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002079 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002080 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07002081 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 req_length = REQUEST_ENTRY_CNT_24XX;
2083 rsp_length = RESPONSE_ENTRY_CNT_2300;
2084 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002085 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002086 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002087 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002088 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002089 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002090 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2091 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2092 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2093 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002094 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002095 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 req_length = REQUEST_ENTRY_CNT_24XX;
2097 rsp_length = RESPONSE_ENTRY_CNT_2300;
2098 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002099 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002100 ha->gid_list_info_size = 8;
2101 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002102 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002103 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002104 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2105 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2106 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2107 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2108 } else if (IS_QLA81XX(ha)) {
2109 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2110 req_length = REQUEST_ENTRY_CNT_24XX;
2111 rsp_length = RESPONSE_ENTRY_CNT_2300;
2112 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2113 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2114 ha->gid_list_info_size = 8;
2115 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002116 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002117 ha->isp_ops = &qla81xx_isp_ops;
2118 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2119 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2120 ha->nvram_conf_off = ~0;
2121 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002122 } else if (IS_QLA82XX(ha)) {
2123 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2124 req_length = REQUEST_ENTRY_CNT_82XX;
2125 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2126 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2127 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2128 ha->gid_list_info_size = 8;
2129 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002130 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002131 ha->isp_ops = &qla82xx_isp_ops;
2132 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2133 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2134 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2135 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002137 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2138 "mbx_count=%d, req_length=%d, "
2139 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2140 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
2141 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2142 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2143 ha->nvram_npiv_size);
2144 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2145 "isp_ops=%p, flash_conf_off=%d, "
2146 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2147 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2148 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002149
2150 /* Configure PCI I/O space */
2151 ret = ha->isp_ops->iospace_config(ha);
2152 if (ret)
2153 goto probe_hw_failed;
2154
2155 ql_log_pci(ql_log_info, pdev, 0x001d,
2156 "Found an ISP%04X irq %d iobase 0x%p.\n",
2157 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002158 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002159 init_completion(&ha->mbx_cmd_comp);
2160 complete(&ha->mbx_cmd_comp);
2161 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002162 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002164 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Andrew Vasquez53303c42009-01-22 09:45:37 -08002166 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002167 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2168 "64 Bit addressing is %s.\n",
2169 ha->flags.enable_64bit_addressing ? "enable" :
2170 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002171 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002172 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002173 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2174 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002176 goto probe_hw_failed;
2177 }
2178
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002179 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002180 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002181 req->max_q_depth = ql2xmaxqdepth;
2182
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183
2184 base_vha = qla2x00_create_host(sht, ha);
2185 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002186 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002187 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002188 qla2x00_free_req_que(ha, req);
2189 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 }
2192
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002195 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002196 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002197 host->can_queue = req->length + 128;
2198 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002200 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2202 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002203
2204 /* Set the SG table size based on ISP type */
2205 if (!IS_FWI2_CAPABLE(ha)) {
2206 if (IS_QLA2100(ha))
2207 host->sg_tablesize = 32;
2208 } else {
2209 if (!IS_QLA82XX(ha))
2210 host->sg_tablesize = QLA_SG_ALL;
2211 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002212 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2213 "can_queue=%d, req=%p, "
2214 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2215 host->can_queue, base_vha->req,
2216 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002217 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002218 host->this_id = 255;
2219 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002220 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002221 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002222 host->max_cmd_len = 32;
2223 else
2224 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002225 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002226 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002227 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002228 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002229
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002230 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2231 "max_id=%d this_id=%d "
2232 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002233 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002234 host->this_id, host->cmd_per_lun, host->unique_id,
2235 host->max_cmd_len, host->max_channel, host->max_lun,
2236 host->transportt, sht->vendor_id);
2237
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002238 /* Set up the irqs */
2239 ret = qla2x00_request_irqs(ha, rsp);
2240 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002241 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002242
2243 pci_save_state(pdev);
2244
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002245 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002246que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002247 if (!qla2x00_alloc_queues(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002248 ql_log(ql_log_fatal, base_vha, 0x003d,
2249 "Failed to allocate memory for queue pointers.. aborting.\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002250 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002251 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002252
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002253 ha->rsp_q_map[0] = rsp;
2254 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002255 rsp->req = req;
2256 req->rsp = rsp;
2257 set_bit(0, ha->req_qid_map);
2258 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07002259 /* FWI2-capable only. */
2260 req->req_q_in = &ha->iobase->isp24.req_q_in;
2261 req->req_q_out = &ha->iobase->isp24.req_q_out;
2262 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2263 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002264 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002265 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2266 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2267 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2268 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002269 }
2270
Giridhar Malavalia9083012010-04-12 17:59:55 -07002271 if (IS_QLA82XX(ha)) {
2272 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2273 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2274 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2275 }
2276
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002277 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2278 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2279 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2280 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2281 "req->req_q_in=%p req->req_q_out=%p "
2282 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2283 req->req_q_in, req->req_q_out,
2284 rsp->rsp_q_in, rsp->rsp_q_out);
2285 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2286 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2287 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2288 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2289 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2290 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002292 if (qla2x00_initialize_adapter(base_vha)) {
2293 ql_log(ql_log_fatal, base_vha, 0x00d6,
2294 "Failed to initialize adapter - Adapter flags %x.\n",
2295 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002296
Giridhar Malavalia9083012010-04-12 17:59:55 -07002297 if (IS_QLA82XX(ha)) {
2298 qla82xx_idc_lock(ha);
2299 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2300 QLA82XX_DEV_FAILED);
2301 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002302 ql_log(ql_log_fatal, base_vha, 0x00d7,
2303 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002304 }
2305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 ret = -ENODEV;
2307 goto probe_failed;
2308 }
2309
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002310 if (ha->mqenable) {
2311 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002312 ql_log(ql_log_warn, base_vha, 0x00ec,
2313 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002314 goto que_init;
2315 }
2316 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002317
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002318 if (ha->flags.running_gold_fw)
2319 goto skip_dpc;
2320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 /*
2322 * Startup the kernel thread for this host adapter
2323 */
2324 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002325 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002326 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002327 ql_log(ql_log_fatal, base_vha, 0x00ed,
2328 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329 ret = PTR_ERR(ha->dpc_thread);
2330 goto probe_failed;
2331 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002332 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2333 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002335skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 list_add_tail(&base_vha->list, &ha->vp_list);
2337 base_vha->host->irq = ha->pdev->irq;
2338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002340 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002341 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2342 "Started qla2x00_timer with "
2343 "interval=%d.\n", WATCH_INTERVAL);
2344 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2345 "Detected hba at address=%p.\n",
2346 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Arun Easie02587d2011-08-16 11:29:23 -07002348 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002349 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07002350 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07002351 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002352 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2353 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002354 if (ql2xenabledif == 1)
2355 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002356 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002357 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002358 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002359 | SHOST_DIF_TYPE3_PROTECTION
2360 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002361 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002362 | SHOST_DIX_TYPE3_PROTECTION);
2363 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2364 } else
2365 base_vha->flags.difdix_supported = 0;
2366 }
2367
Giridhar Malavalia9083012010-04-12 17:59:55 -07002368 ha->isp_ops->enable_intrs(ha);
2369
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002370 ret = scsi_add_host(host, &pdev->dev);
2371 if (ret)
2372 goto probe_failed;
2373
Michael Reed14864002009-12-02 09:11:16 -06002374 base_vha->flags.init_done = 1;
2375 base_vha->flags.online = 1;
2376
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002377 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2378 "Init done and hba is online.\n");
2379
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002380 scsi_scan_host(host);
2381
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002382 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002387
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002388 ql_log(ql_log_info, base_vha, 0x00fb,
2389 "QLogic %s - %s.\n",
2390 ha->model_number, ha->model_desc ? ha->model_desc : "");
2391 ql_log(ql_log_info, base_vha, 0x00fc,
2392 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2393 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2394 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2395 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 return 0;
2399
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002400probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002401 qla2x00_free_req_que(ha, req);
2402 qla2x00_free_rsp_que(ha, rsp);
2403 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002404
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002406 if (base_vha->timer_active)
2407 qla2x00_stop_timer(base_vha);
2408 base_vha->flags.online = 0;
2409 if (ha->dpc_thread) {
2410 struct task_struct *t = ha->dpc_thread;
2411
2412 ha->dpc_thread = NULL;
2413 kthread_stop(t);
2414 }
2415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002421 if (IS_QLA82XX(ha)) {
2422 qla82xx_idc_lock(ha);
2423 qla82xx_clear_drv_active(ha);
2424 qla82xx_idc_unlock(ha);
2425 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2426 if (!ql2xdbwr)
2427 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2428 } else {
2429 if (ha->iobase)
2430 iounmap(ha->iobase);
2431 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 pci_release_selected_regions(ha->pdev, ha->bars);
2433 kfree(ha);
2434 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002436probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002438 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Adrian Bunk4c993f72008-01-14 00:55:16 -08002441static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002442qla2x00_shutdown(struct pci_dev *pdev)
2443{
2444 scsi_qla_host_t *vha;
2445 struct qla_hw_data *ha;
2446
2447 vha = pci_get_drvdata(pdev);
2448 ha = vha->hw;
2449
2450 /* Turn-off FCE trace */
2451 if (ha->flags.fce_enabled) {
2452 qla2x00_disable_fce_trace(vha, NULL, NULL);
2453 ha->flags.fce_enabled = 0;
2454 }
2455
2456 /* Turn-off EFT trace */
2457 if (ha->eft)
2458 qla2x00_disable_eft_trace(vha);
2459
2460 /* Stop currently executing firmware. */
2461 qla2x00_try_to_stop_firmware(vha);
2462
2463 /* Turn adapter off line */
2464 vha->flags.online = 0;
2465
2466 /* turn-off interrupts on the card */
2467 if (ha->interrupts_on) {
2468 vha->flags.init_done = 0;
2469 ha->isp_ops->disable_intrs(ha);
2470 }
2471
2472 qla2x00_free_irqs(vha);
2473
2474 qla2x00_free_fw_dump(ha);
2475}
2476
2477static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002478qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479{
Arun Easifeafb7b2010-09-03 14:57:00 -07002480 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002482 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 base_vha = pci_get_drvdata(pdev);
2485 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Arun Easi43ebf162011-05-10 11:18:16 -07002487 mutex_lock(&ha->vport_lock);
2488 while (ha->cur_vport_count) {
2489 struct Scsi_Host *scsi_host;
Arun Easifeafb7b2010-09-03 14:57:00 -07002490
Arun Easi43ebf162011-05-10 11:18:16 -07002491 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002492
Arun Easi43ebf162011-05-10 11:18:16 -07002493 BUG_ON(base_vha->list.next == &ha->vp_list);
2494 /* This assumes first entry in ha->vp_list is always base vha */
2495 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2496 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002497
Arun Easi43ebf162011-05-10 11:18:16 -07002498 spin_unlock_irqrestore(&ha->vport_slock, flags);
2499 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002500
Arun Easi43ebf162011-05-10 11:18:16 -07002501 fc_vport_terminate(vha->fc_vport);
2502 scsi_host_put(vha->host);
2503
2504 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505 }
Arun Easi43ebf162011-05-10 11:18:16 -07002506 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002507
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002509
Andrew Vasquezb9978762009-03-24 09:08:05 -07002510 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2511
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002512 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002513
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002514 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002515
Andrew Vasquezb9978762009-03-24 09:08:05 -07002516 /* Disable timer */
2517 if (base_vha->timer_active)
2518 qla2x00_stop_timer(base_vha);
2519
2520 base_vha->flags.online = 0;
2521
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002522 /* Flush the work queue and remove it */
2523 if (ha->wq) {
2524 flush_workqueue(ha->wq);
2525 destroy_workqueue(ha->wq);
2526 ha->wq = NULL;
2527 }
2528
Andrew Vasquezb9978762009-03-24 09:08:05 -07002529 /* Kill the kernel thread for this host */
2530 if (ha->dpc_thread) {
2531 struct task_struct *t = ha->dpc_thread;
2532
2533 /*
2534 * qla2xxx_wake_dpc checks for ->dpc_thread
2535 * so we need to zero it out.
2536 */
2537 ha->dpc_thread = NULL;
2538 kthread_stop(t);
2539 }
2540
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002541 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002544
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549 scsi_host_put(base_vha->host);
2550
Giridhar Malavalia9083012010-04-12 17:59:55 -07002551 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002552 qla82xx_idc_lock(ha);
2553 qla82xx_clear_drv_active(ha);
2554 qla82xx_idc_unlock(ha);
2555
Giridhar Malavalia9083012010-04-12 17:59:55 -07002556 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2557 if (!ql2xdbwr)
2558 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2559 } else {
2560 if (ha->iobase)
2561 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562
Giridhar Malavalia9083012010-04-12 17:59:55 -07002563 if (ha->mqiobase)
2564 iounmap(ha->mqiobase);
2565 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002566
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 pci_release_selected_regions(ha->pdev, ha->bars);
2568 kfree(ha);
2569 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002571 pci_disable_pcie_error_reporting(pdev);
2572
Bernhard Walle665db932007-03-28 00:49:49 +02002573 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 pci_set_drvdata(pdev, NULL);
2575}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
2577static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Andrew Vasquez85880802009-12-15 21:29:46 -08002582 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2583
2584 /* Disable timer */
2585 if (vha->timer_active)
2586 qla2x00_stop_timer(vha);
2587
2588 /* Kill the kernel thread for this host */
2589 if (ha->dpc_thread) {
2590 struct task_struct *t = ha->dpc_thread;
2591
2592 /*
2593 * qla2xxx_wake_dpc checks for ->dpc_thread
2594 * so we need to zero it out.
2595 */
2596 ha->dpc_thread = NULL;
2597 kthread_stop(t);
2598 }
2599
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002600 qla25xx_delete_queues(vha);
2601
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002602 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002604
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002605 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002607
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002608 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
Andrew Vasquez85880802009-12-15 21:29:46 -08002611 vha->flags.online = 0;
2612
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002613 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002614 if (ha->interrupts_on) {
2615 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002616 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002617 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002618
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 qla2x00_free_irqs(vha);
2620
Chad Dupuis88670482010-07-23 15:28:30 +05002621 qla2x00_free_fcports(vha);
2622
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002623 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002624
Giridhar Malavali08de2842011-08-16 11:31:44 -07002625 qla82xx_md_free(vha);
2626
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002627 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628}
2629
Chad Dupuis88670482010-07-23 15:28:30 +05002630void qla2x00_free_fcports(struct scsi_qla_host *vha)
2631{
2632 fc_port_t *fcport, *tfcport;
2633
2634 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2635 list_del(&fcport->list);
2636 kfree(fcport);
2637 fcport = NULL;
2638 }
2639}
2640
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002641static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002643 int defer)
2644{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002645 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002646 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002647 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002648
2649 if (!fcport->rport)
2650 return;
2651
2652 rport = fcport->rport;
2653 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002654 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002655 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002656 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002657 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002658 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2659 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002660 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002661 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002662}
2663
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2666 *
2667 * Input: ha = adapter block pointer. fcport = port structure pointer.
2668 *
2669 * Return: None.
2670 *
2671 * Context:
2672 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002673void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002674 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002676 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 vha->vp_idx == fcport->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002678 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 qla2x00_schedule_rport_del(vha, fcport, defer);
2680 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002681 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 * We may need to retry the login, so don't change the state of the
2683 * port but do the retries.
2684 */
2685 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07002686 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
2688 if (!do_login)
2689 return;
2690
2691 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 fcport->login_retry = vha->hw->login_retry_count;
2693 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002695 ql_dbg(ql_dbg_disc, vha, 0x2067,
2696 "Port login retry "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 "%02x%02x%02x%02x%02x%02x%02x%02x, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002698 "id = 0x%04x retry cnt=%d.\n",
2699 fcport->port_name[0], fcport->port_name[1],
2700 fcport->port_name[2], fcport->port_name[3],
2701 fcport->port_name[4], fcport->port_name[5],
2702 fcport->port_name[6], fcport->port_name[7],
2703 fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 }
2705}
2706
2707/*
2708 * qla2x00_mark_all_devices_lost
2709 * Updates fcport state when device goes offline.
2710 *
2711 * Input:
2712 * ha = adapter block pointer.
2713 * fcport = port structure pointer.
2714 *
2715 * Return:
2716 * None.
2717 *
2718 * Context:
2719 */
2720void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722{
2723 fc_port_t *fcport;
2724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002726 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /*
2730 * No point in marking the device as lost, if the device is
2731 * already DEAD.
2732 */
2733 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2734 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002735 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002736 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002737 if (defer)
2738 qla2x00_schedule_rport_del(vha, fcport, defer);
2739 else if (vha->vp_idx == fcport->vp_idx)
2740 qla2x00_schedule_rport_del(vha, fcport, defer);
2741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 }
2743}
2744
2745/*
2746* qla2x00_mem_alloc
2747* Allocates adapter memory.
2748*
2749* Returns:
2750* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002751* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002753static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002754qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2755 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756{
2757 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758
Andrew Vasqueze8711082008-01-31 12:33:48 -08002759 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002761 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2765 &ha->gid_list_dma, GFP_KERNEL);
2766 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002767 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
Andrew Vasqueze8711082008-01-31 12:33:48 -08002769 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2770 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
Giridhar Malavalia9083012010-04-12 17:59:55 -07002773 if (IS_QLA82XX(ha)) {
2774 /* Allocate cache for CT6 Ctx. */
2775 if (!ctx_cachep) {
2776 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2777 sizeof(struct ct6_dsd), 0,
2778 SLAB_HWCACHE_ALIGN, NULL);
2779 if (!ctx_cachep)
2780 goto fail_free_gid_list;
2781 }
2782 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2783 ctx_cachep);
2784 if (!ha->ctx_mempool)
2785 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002786 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
2787 "ctx_cachep=%p ctx_mempool=%p.\n",
2788 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002789 }
2790
Andrew Vasqueze8711082008-01-31 12:33:48 -08002791 /* Get memory for cached NVRAM */
2792 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2793 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002794 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2797 ha->pdev->device);
2798 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2799 DMA_POOL_SIZE, 8, 0);
2800 if (!ha->s_dma_pool)
2801 goto fail_free_nvram;
2802
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002803 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
2804 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
2805 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
2806
Arun Easibad75002010-05-04 15:01:30 -07002807 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002808 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2809 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2810 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002811 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
2812 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002813 goto fail_s_dma_pool;
2814 }
2815
2816 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2817 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2818 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002819 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
2820 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002821 goto fail_dl_dma_pool;
2822 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
2824 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
2825 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002826 }
2827
Andrew Vasqueze8711082008-01-31 12:33:48 -08002828 /* Allocate memory for SNS commands */
2829 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002831 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002833 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002835 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08002836 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002837 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002838 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002839 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002841 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 goto fail_dma_pool;
2843 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002844 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002845 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002846 if (!ha->ct_sns)
2847 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002848 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
2849 "ms_iocb=%p ct_sns=%p.\n",
2850 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 }
2852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002854 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2855 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002856 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
2857 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 goto fail_req;
2859 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002860 (*req)->length = req_len;
2861 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2862 ((*req)->length + 1) * sizeof(request_t),
2863 &(*req)->dma, GFP_KERNEL);
2864 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002865 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
2866 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 goto fail_req_ring;
2868 }
2869 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002870 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2871 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002872 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
2873 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002874 goto fail_rsp;
2875 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002876 (*rsp)->hw = ha;
2877 (*rsp)->length = rsp_len;
2878 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2879 ((*rsp)->length + 1) * sizeof(response_t),
2880 &(*rsp)->dma, GFP_KERNEL);
2881 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002882 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
2883 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002884 goto fail_rsp_ring;
2885 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002886 (*req)->rsp = *rsp;
2887 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002888 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
2889 "req=%p req->length=%d req->ring=%p rsp=%p "
2890 "rsp->length=%d rsp->ring=%p.\n",
2891 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
2892 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002893 /* Allocate memory for NVRAM data for vports */
2894 if (ha->nvram_npiv_size) {
2895 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002896 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002897 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002898 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
2899 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002900 goto fail_npiv_info;
2901 }
2902 } else
2903 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002905 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002906 if (IS_QLA8XXX_TYPE(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002907 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2908 &ha->ex_init_cb_dma);
2909 if (!ha->ex_init_cb)
2910 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002911 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
2912 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002913 }
2914
Giridhar Malavalia9083012010-04-12 17:59:55 -07002915 INIT_LIST_HEAD(&ha->gbl_dsd_list);
2916
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002917 /* Get consistent memory allocated for Async Port-Database. */
2918 if (!IS_FWI2_CAPABLE(ha)) {
2919 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2920 &ha->async_pd_dma);
2921 if (!ha->async_pd)
2922 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002923 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
2924 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002925 }
2926
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 INIT_LIST_HEAD(&ha->vp_list);
2928 return 1;
2929
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002930fail_async_pd:
2931 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002932fail_ex_init_cb:
2933 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002934fail_npiv_info:
2935 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2936 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2937 (*rsp)->ring = NULL;
2938 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002940 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002942 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2943 sizeof(request_t), (*req)->ring, (*req)->dma);
2944 (*req)->ring = NULL;
2945 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002946fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002947 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948fail_req:
2949 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2950 ha->ct_sns, ha->ct_sns_dma);
2951 ha->ct_sns = NULL;
2952 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002953fail_free_ms_iocb:
2954 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2955 ha->ms_iocb = NULL;
2956 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002958 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002959 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2960 ha->fcp_cmnd_dma_pool = NULL;
2961 }
2962fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002963 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002964 dma_pool_destroy(ha->dl_dma_pool);
2965 ha->dl_dma_pool = NULL;
2966 }
2967fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 dma_pool_destroy(ha->s_dma_pool);
2969 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002970fail_free_nvram:
2971 kfree(ha->nvram);
2972 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002973fail_free_ctx_mempool:
2974 mempool_destroy(ha->ctx_mempool);
2975 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002976fail_free_srb_mempool:
2977 mempool_destroy(ha->srb_mempool);
2978 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002979fail_free_gid_list:
2980 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002981 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002982 ha->gid_list = NULL;
2983 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984fail_free_init_cb:
2985 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2986 ha->init_cb_dma);
2987 ha->init_cb = NULL;
2988 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002989fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002990 ql_log(ql_log_fatal, NULL, 0x0030,
2991 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08002992 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993}
2994
2995/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002996* qla2x00_free_fw_dump
2997* Frees fw dump stuff.
2998*
2999* Input:
3000* ha = adapter block pointer.
3001*/
3002static void
3003qla2x00_free_fw_dump(struct qla_hw_data *ha)
3004{
3005 if (ha->fce)
3006 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3007 ha->fce_dma);
3008
3009 if (ha->fw_dump) {
3010 if (ha->eft)
3011 dma_free_coherent(&ha->pdev->dev,
3012 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3013 vfree(ha->fw_dump);
3014 }
3015 ha->fce = NULL;
3016 ha->fce_dma = 0;
3017 ha->eft = NULL;
3018 ha->eft_dma = 0;
3019 ha->fw_dump = NULL;
3020 ha->fw_dumped = 0;
3021 ha->fw_dump_reading = 0;
3022}
3023
3024/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025* qla2x00_mem_free
3026* Frees all adapter allocated memory.
3027*
3028* Input:
3029* ha = adapter block pointer.
3030*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003031static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003034 qla2x00_free_fw_dump(ha);
3035
Andrew Vasqueze8711082008-01-31 12:33:48 -08003036 if (ha->srb_mempool)
3037 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003039 if (ha->dcbx_tlv)
3040 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3041 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3042
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003043 if (ha->xgmac_data)
3044 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3045 ha->xgmac_data, ha->xgmac_data_dma);
3046
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 if (ha->sns_cmd)
3048 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003049 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050
3051 if (ha->ct_sns)
3052 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
Andrew Vasquez88729e52006-06-23 16:10:50 -07003055 if (ha->sfp_data)
3056 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3057
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003058 if (ha->edc_data)
3059 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
3060
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 if (ha->ms_iocb)
3062 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3063
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003064 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003065 dma_pool_free(ha->s_dma_pool,
3066 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003067
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003068 if (ha->async_pd)
3069 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3070
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 if (ha->s_dma_pool)
3072 dma_pool_destroy(ha->s_dma_pool);
3073
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 if (ha->gid_list)
3075 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
Giridhar Malavalia9083012010-04-12 17:59:55 -07003078 if (IS_QLA82XX(ha)) {
3079 if (!list_empty(&ha->gbl_dsd_list)) {
3080 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3081
3082 /* clean up allocated prev pool */
3083 list_for_each_entry_safe(dsd_ptr,
3084 tdsd_ptr, &ha->gbl_dsd_list, list) {
3085 dma_pool_free(ha->dl_dma_pool,
3086 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3087 list_del(&dsd_ptr->list);
3088 kfree(dsd_ptr);
3089 }
3090 }
3091 }
3092
3093 if (ha->dl_dma_pool)
3094 dma_pool_destroy(ha->dl_dma_pool);
3095
3096 if (ha->fcp_cmnd_dma_pool)
3097 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3098
3099 if (ha->ctx_mempool)
3100 mempool_destroy(ha->ctx_mempool);
3101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003102 if (ha->init_cb)
3103 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003104 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003105 vfree(ha->optrom_buffer);
3106 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003107 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108
Andrew Vasqueze8711082008-01-31 12:33:48 -08003109 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003110 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 ha->sns_cmd = NULL;
3112 ha->sns_cmd_dma = 0;
3113 ha->ct_sns = NULL;
3114 ha->ct_sns_dma = 0;
3115 ha->ms_iocb = NULL;
3116 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 ha->init_cb = NULL;
3118 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003119 ha->ex_init_cb = NULL;
3120 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003121 ha->async_pd = NULL;
3122 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
3124 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003125 ha->dl_dma_pool = NULL;
3126 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 ha->gid_list = NULL;
3129 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130}
3131
3132struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3133 struct qla_hw_data *ha)
3134{
3135 struct Scsi_Host *host;
3136 struct scsi_qla_host *vha = NULL;
3137
3138 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3139 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003140 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3141 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003142 goto fail;
3143 }
3144
3145 /* Clear our data area */
3146 vha = shost_priv(host);
3147 memset(vha, 0, sizeof(scsi_qla_host_t));
3148
3149 vha->host = host;
3150 vha->host_no = host->host_no;
3151 vha->hw = ha;
3152
3153 INIT_LIST_HEAD(&vha->vp_fcports);
3154 INIT_LIST_HEAD(&vha->work_list);
3155 INIT_LIST_HEAD(&vha->list);
3156
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003157 spin_lock_init(&vha->work_lock);
3158
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003160 ql_dbg(ql_dbg_init, vha, 0x0041,
3161 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3162 vha->host, vha->hw, vha,
3163 dev_name(&(ha->pdev->dev)));
3164
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 return vha;
3166
3167fail:
3168 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169}
3170
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003171static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003172qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003173{
3174 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003175 uint8_t bail;
3176
3177 QLA_VHA_MARK_BUSY(vha, bail);
3178 if (bail)
3179 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003180
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003181 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003182 if (!e) {
3183 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003184 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003185 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003186
3187 INIT_LIST_HEAD(&e->list);
3188 e->type = type;
3189 e->flags = QLA_EVT_FLAG_FREE;
3190 return e;
3191}
3192
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003193static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003194qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003195{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003196 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003197
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003198 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003200 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003201 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003202
Andrew Vasquez0971de72008-04-03 13:13:18 -07003203 return QLA_SUCCESS;
3204}
3205
3206int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003208 u32 data)
3209{
3210 struct qla_work_evt *e;
3211
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003212 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003213 if (!e)
3214 return QLA_FUNCTION_FAILED;
3215
3216 e->u.aen.code = code;
3217 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003218 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003219}
3220
Andrew Vasquez8a659572009-02-08 20:50:12 -08003221int
3222qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3223{
3224 struct qla_work_evt *e;
3225
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003226 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003227 if (!e)
3228 return QLA_FUNCTION_FAILED;
3229
3230 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003231 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003232}
3233
Andrew Vasquezac280b62009-08-20 11:06:05 -07003234#define qla2x00_post_async_work(name, type) \
3235int qla2x00_post_async_##name##_work( \
3236 struct scsi_qla_host *vha, \
3237 fc_port_t *fcport, uint16_t *data) \
3238{ \
3239 struct qla_work_evt *e; \
3240 \
3241 e = qla2x00_alloc_work(vha, type); \
3242 if (!e) \
3243 return QLA_FUNCTION_FAILED; \
3244 \
3245 e->u.logio.fcport = fcport; \
3246 if (data) { \
3247 e->u.logio.data[0] = data[0]; \
3248 e->u.logio.data[1] = data[1]; \
3249 } \
3250 return qla2x00_post_work(vha, e); \
3251}
3252
3253qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3254qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3255qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3256qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003257qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3258qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003259
Andrew Vasquez3420d362009-10-13 15:16:45 -07003260int
3261qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3262{
3263 struct qla_work_evt *e;
3264
3265 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3266 if (!e)
3267 return QLA_FUNCTION_FAILED;
3268
3269 e->u.uevent.code = code;
3270 return qla2x00_post_work(vha, e);
3271}
3272
3273static void
3274qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3275{
3276 char event_string[40];
3277 char *envp[] = { event_string, NULL };
3278
3279 switch (code) {
3280 case QLA_UEVENT_CODE_FW_DUMP:
3281 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3282 vha->host_no);
3283 break;
3284 default:
3285 /* do nothing */
3286 break;
3287 }
3288 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3289}
3290
Andrew Vasquezac280b62009-08-20 11:06:05 -07003291void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003293{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003294 struct qla_work_evt *e, *tmp;
3295 unsigned long flags;
3296 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003297
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003298 spin_lock_irqsave(&vha->work_lock, flags);
3299 list_splice_init(&vha->work_list, &work);
3300 spin_unlock_irqrestore(&vha->work_lock, flags);
3301
3302 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003303 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003304
3305 switch (e->type) {
3306 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003307 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003308 e->u.aen.code, e->u.aen.data);
3309 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003310 case QLA_EVT_IDC_ACK:
3311 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3312 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003313 case QLA_EVT_ASYNC_LOGIN:
3314 qla2x00_async_login(vha, e->u.logio.fcport,
3315 e->u.logio.data);
3316 break;
3317 case QLA_EVT_ASYNC_LOGIN_DONE:
3318 qla2x00_async_login_done(vha, e->u.logio.fcport,
3319 e->u.logio.data);
3320 break;
3321 case QLA_EVT_ASYNC_LOGOUT:
3322 qla2x00_async_logout(vha, e->u.logio.fcport);
3323 break;
3324 case QLA_EVT_ASYNC_LOGOUT_DONE:
3325 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3326 e->u.logio.data);
3327 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003328 case QLA_EVT_ASYNC_ADISC:
3329 qla2x00_async_adisc(vha, e->u.logio.fcport,
3330 e->u.logio.data);
3331 break;
3332 case QLA_EVT_ASYNC_ADISC_DONE:
3333 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3334 e->u.logio.data);
3335 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003336 case QLA_EVT_UEVENT:
3337 qla2x00_uevent_emit(vha, e->u.uevent.code);
3338 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003339 }
3340 if (e->flags & QLA_EVT_FLAG_FREE)
3341 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003342
3343 /* For each work completed decrement vha ref count */
3344 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003345 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003347
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348/* Relogins all the fcports of a vport
3349 * Context: dpc thread
3350 */
3351void qla2x00_relogin(struct scsi_qla_host *vha)
3352{
3353 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003354 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003355 uint16_t next_loopid = 0;
3356 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003357 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003358
3359 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3360 /*
3361 * If the port is not ONLINE then try to login
3362 * to it if we haven't run out of retries.
3363 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003364 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3365 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003366 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003367 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003368 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 ha->isp_ops->fabric_logout(vha,
3370 fcport->loop_id,
3371 fcport->d_id.b.domain,
3372 fcport->d_id.b.area,
3373 fcport->d_id.b.al_pa);
3374
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003375 if (fcport->loop_id == FC_NO_LOOP_ID) {
3376 fcport->loop_id = next_loopid =
3377 ha->min_external_loopid;
3378 status = qla2x00_find_new_loop_id(
3379 vha, fcport);
3380 if (status != QLA_SUCCESS) {
3381 /* Ran out of IDs to use */
3382 break;
3383 }
3384 }
3385
Andrew Vasquezac280b62009-08-20 11:06:05 -07003386 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003387 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003388 data[0] = 0;
3389 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3390 status = qla2x00_post_async_login_work(
3391 vha, fcport, data);
3392 if (status == QLA_SUCCESS)
3393 continue;
3394 /* Attempt a retry. */
3395 status = 1;
3396 } else
3397 status = qla2x00_fabric_login(vha,
3398 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003399 } else
3400 status = qla2x00_local_device_login(vha,
3401 fcport);
3402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 if (status == QLA_SUCCESS) {
3404 fcport->old_loop_id = fcport->loop_id;
3405
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003406 ql_dbg(ql_dbg_disc, vha, 0x2003,
3407 "Port login OK: logged in ID 0x%x.\n",
3408 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003409
3410 qla2x00_update_fcport(vha, fcport);
3411
3412 } else if (status == 1) {
3413 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3414 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003415 ql_dbg(ql_dbg_disc, vha, 0x2007,
3416 "Retrying %d login again loop_id 0x%x.\n",
3417 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 } else {
3419 fcport->login_retry = 0;
3420 }
3421
3422 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3423 fcport->loop_id = FC_NO_LOOP_ID;
3424 }
3425 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3426 break;
3427 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003428}
3429
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430/**************************************************************************
3431* qla2x00_do_dpc
3432* This kernel thread is a task that is schedule by the interrupt handler
3433* to perform the background processing for interrupts.
3434*
3435* Notes:
3436* This task always run in the context of a kernel thread. It
3437* is kick-off by the driver's detect code and starts up
3438* up one per adapter. It immediately goes to sleep and waits for
3439* some fibre event. When either the interrupt handler or
3440* the timer routine detects a event it will one of the task
3441* bits then wake us up.
3442**************************************************************************/
3443static int
3444qla2x00_do_dpc(void *data)
3445{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003446 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003447 scsi_qla_host_t *base_vha;
3448 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08003449
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 ha = (struct qla_hw_data *)data;
3451 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 set_user_nice(current, -20);
3454
James Bottomley563585e2011-01-27 16:12:37 -05003455 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01003456 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003457 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
3458 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
Christoph Hellwig39a11242006-02-14 18:46:22 +01003460 schedule();
3461 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003463 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
3464 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465
Andrew Vasquez85880802009-12-15 21:29:46 -08003466 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003467 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
3468 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003469 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08003470 }
3471
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 ha->dpc_active = 1;
3473
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003474 ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
3475 "DPC handler waking up.\n");
3476 ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
3477 "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003480
Giridhar Malavalia9083012010-04-12 17:59:55 -07003481 if (IS_QLA82XX(ha)) {
3482 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3483 &base_vha->dpc_flags)) {
3484 qla82xx_idc_lock(ha);
3485 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3486 QLA82XX_DEV_FAILED);
3487 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003488 ql_log(ql_log_info, base_vha, 0x4004,
3489 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003490 qla82xx_device_state_handler(base_vha);
3491 continue;
3492 }
3493
3494 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3495 &base_vha->dpc_flags)) {
3496
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003497 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
3498 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003499 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3500 &base_vha->dpc_flags))) {
3501 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3502 /* FCoE-ctx reset failed.
3503 * Escalate to chip-reset
3504 */
3505 set_bit(ISP_ABORT_NEEDED,
3506 &base_vha->dpc_flags);
3507 }
3508 clear_bit(ABORT_ISP_ACTIVE,
3509 &base_vha->dpc_flags);
3510 }
3511
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003512 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
3513 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003514 }
3515 }
3516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3518 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003520 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
3521 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003523 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524
Giridhar Malavalia9083012010-04-12 17:59:55 -07003525 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 /* failed. retry later */
3527 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530 clear_bit(ABORT_ISP_ACTIVE,
3531 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08003532 }
3533
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003534 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
3535 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 }
3537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3539 qla2x00_update_fcports(base_vha);
3540 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003541 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003542
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003543 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003544 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
3545 "Quiescence mode scheduled.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003546 qla82xx_device_state_handler(base_vha);
3547 clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
3548 if (!ha->flags.quiesce_owner) {
3549 qla2x00_perform_loop_resync(base_vha);
3550
3551 qla82xx_idc_lock(ha);
3552 qla82xx_clear_qsnt_ready(base_vha);
3553 qla82xx_idc_unlock(ha);
3554 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003555 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
3556 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003557 }
3558
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3560 &base_vha->dpc_flags) &&
3561 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003563 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
3564 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003565 qla2x00_rst_aen(base_vha);
3566 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003567 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
3568 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 }
3570
3571 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 if ((test_and_clear_bit(RELOGIN_NEEDED,
3573 &base_vha->dpc_flags)) &&
3574 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3575 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003577 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
3578 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003580 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
3581 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 }
3583
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003584 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3585 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003587 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
3588 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
3590 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003595 clear_bit(LOOP_RESYNC_ACTIVE,
3596 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 }
3598
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003599 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
3600 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 }
3602
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3604 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3605 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3606 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07003607 }
3608
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003610 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003612 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3613 &base_vha->dpc_flags))
3614 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003615
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003617
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003619end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05003620 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05003622 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003624 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
3625 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626
3627 /*
3628 * Make sure that nobody tries to wake us up again.
3629 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 ha->dpc_active = 0;
3631
Andrew Vasquezac280b62009-08-20 11:06:05 -07003632 /* Cleanup any residual CTX SRBs. */
3633 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3634
Christoph Hellwig39a11242006-02-14 18:46:22 +01003635 return 0;
3636}
3637
3638void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003640{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003642 struct task_struct *t = ha->dpc_thread;
3643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003644 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003645 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646}
3647
3648/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649* qla2x00_rst_aen
3650* Processes asynchronous reset.
3651*
3652* Input:
3653* ha = adapter block pointer.
3654*/
3655static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003656qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003658 if (vha->flags.online && !vha->flags.reset_active &&
3659 !atomic_read(&vha->loop_down_timer) &&
3660 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
3664 /*
3665 * Issue marker command only when we are going to start
3666 * the I/O.
3667 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668 vha->marker_needed = 1;
3669 } while (!atomic_read(&vha->loop_down_timer) &&
3670 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 }
3672}
3673
f4f051e2005-04-17 15:02:26 -05003674static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003676{
3677 struct scsi_cmnd *cmd = sp->cmd;
Arun Easibad75002010-05-04 15:01:30 -07003678 struct qla_hw_data *ha = sp->fcport->vha->hw;
f4f051e2005-04-17 15:02:26 -05003679
3680 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003681 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003682 sp->flags &= ~SRB_DMA_VALID;
3683 }
Arun Easibad75002010-05-04 15:01:30 -07003684
3685 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
3686 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
3687 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
3688 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
3689 }
3690
3691 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
3692 /* List assured to be having elements */
3693 qla2x00_clean_dsd_pool(ha, sp);
3694 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
3695 }
3696
3697 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
3698 dma_pool_free(ha->dl_dma_pool, sp->ctx,
3699 ((struct crc_context *)sp->ctx)->crc_ctx_dma);
3700 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
3701 }
3702
Giridhar Malavalia9083012010-04-12 17:59:55 -07003703 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
3704 struct ct6_dsd *ctx = sp->ctx;
3705 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
3706 ctx->fcp_cmnd_dma);
3707 list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
3708 ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
3709 ha->gbl_dsd_avail += ctx->dsd_use_cnt;
3710 mempool_free(sp->ctx, ha->ctx_mempool);
3711 sp->ctx = NULL;
3712 }
f4f051e2005-04-17 15:02:26 -05003713
Giridhar Malavalic4631192011-11-18 09:03:08 -08003714 CMD_SP(cmd) = NULL;
3715}
3716
3717static void
3718qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
3719{
3720 struct scsi_cmnd *cmd = sp->cmd;
3721
3722 qla2x00_sp_free_dma(sp);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003723 mempool_free(sp, ha->srb_mempool);
f4f051e2005-04-17 15:02:26 -05003724 cmd->scsi_done(cmd);
3725}
bdf79622005-04-17 15:06:53 -05003726
Giridhar Malavali083a4692010-05-28 15:08:18 -07003727void
3728qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3729{
3730 if (atomic_read(&sp->ref_count) == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003731 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
3732 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
3733 sp, sp->cmd);
3734 if (ql2xextended_error_logging & ql_dbg_io)
3735 BUG();
Giridhar Malavali083a4692010-05-28 15:08:18 -07003736 return;
3737 }
3738 if (!atomic_dec_and_test(&sp->ref_count))
3739 return;
3740 qla2x00_sp_final_compl(ha, sp);
3741}
3742
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743/**************************************************************************
3744* qla2x00_timer
3745*
3746* Description:
3747* One second timer
3748*
3749* Context: Interrupt
3750***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003751void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 int start_dpc = 0;
3756 int index;
3757 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08003758 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003760 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003761
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003762 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003763 ql_dbg(ql_dbg_timer, vha, 0x6000,
3764 "EEH = %d, restarting timer.\n",
3765 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003766 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3767 return;
3768 }
3769
Andrew Vasquez85880802009-12-15 21:29:46 -08003770 /* Hardware read to raise pending EEH errors during mailbox waits. */
3771 if (!pci_channel_offline(ha->pdev))
3772 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003774 /* Make sure qla82xx_watchdog is run only for physical port */
3775 if (!vha->vp_idx && IS_QLA82XX(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003776 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
3777 start_dpc++;
3778 qla82xx_watchdog(vha);
3779 }
3780
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003782 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003783 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
3784 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003785 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787 if (atomic_read(&vha->loop_down_timer) ==
3788 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003790 ql_log(ql_log_info, vha, 0x6008,
3791 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3794 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003796 /*
3797 * Schedule an ISP abort to return any FCP2-device
3798 * commands.
3799 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003800 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003802 spin_lock_irqsave(&ha->hardware_lock,
3803 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003804 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003805 for (index = 1;
3806 index < MAX_OUTSTANDING_COMMANDS;
3807 index++) {
3808 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003809
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003810 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003811 if (!sp)
3812 continue;
Arun Easibad75002010-05-04 15:01:30 -07003813 if (sp->ctx && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003814 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003815 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003816 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003817 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003819 if (IS_QLA82XX(ha))
3820 set_bit(FCOE_CTX_RESET_NEEDED,
3821 &vha->dpc_flags);
3822 else
3823 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003825 break;
3826 }
3827 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 start_dpc++;
3831 }
3832
3833 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003834 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003835 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003836 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 "Loop down - aborting ISP.\n");
3838
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003839 if (IS_QLA82XX(ha))
3840 set_bit(FCOE_CTX_RESET_NEEDED,
3841 &vha->dpc_flags);
3842 else
3843 set_bit(ISP_ABORT_NEEDED,
3844 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
3846 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003847 ql_dbg(ql_dbg_timer, vha, 0x600a,
3848 "Loop down - seconds remaining %d.\n",
3849 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 }
3851
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003852 /* Check if beacon LED needs to be blinked for physical host only */
3853 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07003854 /* There is no beacon_blink function for ISP82xx */
3855 if (!IS_QLA82XX(ha)) {
3856 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3857 start_dpc++;
3858 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003859 }
3860
Andrew Vasquez550bf572008-04-24 15:21:23 -07003861 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003862 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003863 start_dpc++;
3864
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003866 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3867 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3868 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3871 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07003872 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3873 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003874 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003875 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
3876 ql_dbg(ql_dbg_timer, vha, 0x600b,
3877 "isp_abort_needed=%d loop_resync_needed=%d "
3878 "fcport_update_needed=%d start_dpc=%d "
3879 "reset_marker_needed=%d",
3880 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
3881 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
3882 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
3883 start_dpc,
3884 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
3885 ql_dbg(ql_dbg_timer, vha, 0x600c,
3886 "beacon_blink_needed=%d isp_unrecoverable=%d "
3887 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
3888 "relogin_needed=%d.\n",
3889 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
3890 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
3891 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
3892 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
3893 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003894 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003897 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898}
3899
Andrew Vasquez54333832005-11-09 15:49:04 -08003900/* Firmware interface routines. */
3901
Giridhar Malavalia9083012010-04-12 17:59:55 -07003902#define FW_BLOBS 8
Andrew Vasquez54333832005-11-09 15:49:04 -08003903#define FW_ISP21XX 0
3904#define FW_ISP22XX 1
3905#define FW_ISP2300 2
3906#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003907#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003908#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003909#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07003910#define FW_ISP82XX 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003911
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003912#define FW_FILE_ISP21XX "ql2100_fw.bin"
3913#define FW_FILE_ISP22XX "ql2200_fw.bin"
3914#define FW_FILE_ISP2300 "ql2300_fw.bin"
3915#define FW_FILE_ISP2322 "ql2322_fw.bin"
3916#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003917#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003918#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07003919#define FW_FILE_ISP82XX "ql8200_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003920
Daniel Walkere1e82b62008-05-12 22:21:10 -07003921static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003922
3923static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003924 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3925 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3926 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3927 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3928 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003929 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003930 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07003931 { .name = FW_FILE_ISP82XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003932};
3933
3934struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003936{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003937 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003938 struct fw_blob *blob;
3939
3940 blob = NULL;
3941 if (IS_QLA2100(ha)) {
3942 blob = &qla_fw_blobs[FW_ISP21XX];
3943 } else if (IS_QLA2200(ha)) {
3944 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003945 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003946 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003947 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003948 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003949 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003950 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003951 } else if (IS_QLA25XX(ha)) {
3952 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003953 } else if (IS_QLA81XX(ha)) {
3954 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07003955 } else if (IS_QLA82XX(ha)) {
3956 blob = &qla_fw_blobs[FW_ISP82XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003957 }
3958
Daniel Walkere1e82b62008-05-12 22:21:10 -07003959 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003960 if (blob->fw)
3961 goto out;
3962
3963 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003964 ql_log(ql_log_warn, vha, 0x0063,
3965 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08003966 blob->fw = NULL;
3967 blob = NULL;
3968 goto out;
3969 }
3970
3971out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003972 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003973 return blob;
3974}
3975
3976static void
3977qla2x00_release_firmware(void)
3978{
3979 int idx;
3980
Daniel Walkere1e82b62008-05-12 22:21:10 -07003981 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003982 for (idx = 0; idx < FW_BLOBS; idx++)
3983 if (qla_fw_blobs[idx].fw)
3984 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003985 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003986}
3987
Seokmann Ju14e660e2007-09-20 14:07:36 -07003988static pci_ers_result_t
3989qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3990{
Andrew Vasquez85880802009-12-15 21:29:46 -08003991 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3992 struct qla_hw_data *ha = vha->hw;
3993
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003994 ql_dbg(ql_dbg_aer, vha, 0x9000,
3995 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07003996
Seokmann Ju14e660e2007-09-20 14:07:36 -07003997 switch (state) {
3998 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003999 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004000 return PCI_ERS_RESULT_CAN_RECOVER;
4001 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08004002 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004003 /* For ISP82XX complete any pending mailbox cmd */
4004 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004005 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08004006 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
4007 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004008 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004009 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004010 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004011 /* Return back all IOs */
4012 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004013 return PCI_ERS_RESULT_NEED_RESET;
4014 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08004015 ha->flags.pci_channel_io_perm_failure = 1;
4016 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004017 return PCI_ERS_RESULT_DISCONNECT;
4018 }
4019 return PCI_ERS_RESULT_NEED_RESET;
4020}
4021
4022static pci_ers_result_t
4023qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4024{
4025 int risc_paused = 0;
4026 uint32_t stat;
4027 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004028 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4029 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004030 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4031 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4032
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07004033 if (IS_QLA82XX(ha))
4034 return PCI_ERS_RESULT_RECOVERED;
4035
Seokmann Ju14e660e2007-09-20 14:07:36 -07004036 spin_lock_irqsave(&ha->hardware_lock, flags);
4037 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4038 stat = RD_REG_DWORD(&reg->hccr);
4039 if (stat & HCCR_RISC_PAUSE)
4040 risc_paused = 1;
4041 } else if (IS_QLA23XX(ha)) {
4042 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
4043 if (stat & HSR_RISC_PAUSED)
4044 risc_paused = 1;
4045 } else if (IS_FWI2_CAPABLE(ha)) {
4046 stat = RD_REG_DWORD(&reg24->host_status);
4047 if (stat & HSRX_RISC_PAUSED)
4048 risc_paused = 1;
4049 }
4050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4051
4052 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004053 ql_log(ql_log_info, base_vha, 0x9003,
4054 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004056
4057 return PCI_ERS_RESULT_NEED_RESET;
4058 } else
4059 return PCI_ERS_RESULT_RECOVERED;
4060}
4061
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004062uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
4063{
4064 uint32_t rval = QLA_FUNCTION_FAILED;
4065 uint32_t drv_active = 0;
4066 struct qla_hw_data *ha = base_vha->hw;
4067 int fn;
4068 struct pci_dev *other_pdev = NULL;
4069
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004070 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
4071 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004072
4073 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4074
4075 if (base_vha->flags.online) {
4076 /* Abort all outstanding commands,
4077 * so as to be requeued later */
4078 qla2x00_abort_isp_cleanup(base_vha);
4079 }
4080
4081
4082 fn = PCI_FUNC(ha->pdev->devfn);
4083 while (fn > 0) {
4084 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004085 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
4086 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004087 other_pdev =
4088 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4089 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4090 fn));
4091
4092 if (!other_pdev)
4093 continue;
4094 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004095 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
4096 "Found PCI func available and enable at 0x%x.\n",
4097 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004098 pci_dev_put(other_pdev);
4099 break;
4100 }
4101 pci_dev_put(other_pdev);
4102 }
4103
4104 if (!fn) {
4105 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004106 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
4107 "This devfn is reset owner = 0x%x.\n",
4108 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004109 qla82xx_idc_lock(ha);
4110
4111 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4112 QLA82XX_DEV_INITIALIZING);
4113
4114 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
4115 QLA82XX_IDC_VERSION);
4116
4117 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004118 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
4119 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004120
4121 qla82xx_idc_unlock(ha);
4122 /* Reset if device is not already reset
4123 * drv_active would be 0 if a reset has already been done
4124 */
4125 if (drv_active)
4126 rval = qla82xx_start_firmware(base_vha);
4127 else
4128 rval = QLA_SUCCESS;
4129 qla82xx_idc_lock(ha);
4130
4131 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004132 ql_log(ql_log_info, base_vha, 0x900b,
4133 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004134 qla82xx_clear_drv_active(ha);
4135 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4136 QLA82XX_DEV_FAILED);
4137 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004138 ql_log(ql_log_info, base_vha, 0x900c,
4139 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004140 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4141 QLA82XX_DEV_READY);
4142 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08004143 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004144 rval = qla82xx_restart_isp(base_vha);
4145 qla82xx_idc_lock(ha);
4146 /* Clear driver state register */
4147 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
4148 qla82xx_set_drv_active(base_vha);
4149 }
4150 qla82xx_idc_unlock(ha);
4151 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004152 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
4153 "This devfn is not reset owner = 0x%x.\n",
4154 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004155 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
4156 QLA82XX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004157 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004158 rval = qla82xx_restart_isp(base_vha);
4159 qla82xx_idc_lock(ha);
4160 qla82xx_set_drv_active(base_vha);
4161 qla82xx_idc_unlock(ha);
4162 }
4163 }
4164 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4165
4166 return rval;
4167}
4168
Seokmann Ju14e660e2007-09-20 14:07:36 -07004169static pci_ers_result_t
4170qla2xxx_pci_slot_reset(struct pci_dev *pdev)
4171{
4172 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4174 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004175 struct rsp_que *rsp;
4176 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004177
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004178 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
4179 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004180
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004181 /* Workaround: qla2xxx driver which access hardware earlier
4182 * needs error state to be pci_channel_io_online.
4183 * Otherwise mailbox command timesout.
4184 */
4185 pdev->error_state = pci_channel_io_normal;
4186
4187 pci_restore_state(pdev);
4188
Richard Lary8c1496b2010-02-18 10:07:29 -08004189 /* pci_restore_state() clears the saved_state flag of the device
4190 * save restored state which resets saved_state flag
4191 */
4192 pci_save_state(pdev);
4193
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11004194 if (ha->mem_only)
4195 rc = pci_enable_device_mem(pdev);
4196 else
4197 rc = pci_enable_device(pdev);
4198
4199 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004200 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004201 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004202 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004203 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004204
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004205 rsp = ha->rsp_q_map[0];
4206 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004207 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004209 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004210 goto exit_slot_reset;
4211
4212 if (IS_QLA82XX(ha)) {
4213 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
4214 ret = PCI_ERS_RESULT_RECOVERED;
4215 goto exit_slot_reset;
4216 } else
4217 goto exit_slot_reset;
4218 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004219
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004220 while (ha->flags.mbox_busy && retries--)
4221 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08004222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004224 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07004225 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004226 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004227
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004228
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004229exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004230 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
4231 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08004232
Seokmann Ju14e660e2007-09-20 14:07:36 -07004233 return ret;
4234}
4235
4236static void
4237qla2xxx_pci_resume(struct pci_dev *pdev)
4238{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004239 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4240 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004241 int ret;
4242
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004243 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
4244 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004246 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004247 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004248 ql_log(ql_log_fatal, base_vha, 0x9002,
4249 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07004250 }
Andrew Vasquez85880802009-12-15 21:29:46 -08004251
Lalit Chandivade3e46f032010-05-04 15:01:23 -07004252 pci_cleanup_aer_uncorrect_error_status(pdev);
4253
Andrew Vasquez85880802009-12-15 21:29:46 -08004254 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004255}
4256
4257static struct pci_error_handlers qla2xxx_err_handler = {
4258 .error_detected = qla2xxx_pci_error_detected,
4259 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4260 .slot_reset = qla2xxx_pci_slot_reset,
4261 .resume = qla2xxx_pci_resume,
4262};
4263
Andrew Vasquez54333832005-11-09 15:49:04 -08004264static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004265 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4266 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4267 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4268 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4269 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4270 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4271 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4272 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4273 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004274 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004275 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4276 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004277 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004278 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004279 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Andrew Vasquez54333832005-11-09 15:49:04 -08004280 { 0 },
4281};
4282MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4283
Andrew Vasquezfca29702005-07-06 10:31:47 -07004284static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07004285 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06004286 .driver = {
4287 .owner = THIS_MODULE,
4288 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07004289 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004290 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08004291 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004292 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004293 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07004294};
4295
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004296static struct file_operations apidev_fops = {
4297 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02004298 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004299};
4300
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301/**
4302 * qla2x00_module_init - Module initialization.
4303 **/
4304static int __init
4305qla2x00_module_init(void)
4306{
Andrew Vasquezfca29702005-07-06 10:31:47 -07004307 int ret = 0;
4308
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004310 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09004311 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004313 ql_log(ql_log_fatal, NULL, 0x0001,
4314 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 return -ENOMEM;
4316 }
4317
4318 /* Derive version string. */
4319 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07004320 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07004321 strcat(qla2x00_version_str, "-debug");
4322
Andrew Vasquez1c97a122005-04-21 16:13:36 -04004323 qla2xxx_transport_template =
4324 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004325 if (!qla2xxx_transport_template) {
4326 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004327 ql_log(ql_log_fatal, NULL, 0x0002,
4328 "fc_attach_transport failed...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004330 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004331
4332 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4333 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004334 ql_log(ql_log_fatal, NULL, 0x0003,
4335 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004336 }
4337
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004338 qla2xxx_transport_vport_template =
4339 fc_attach_transport(&qla2xxx_transport_vport_functions);
4340 if (!qla2xxx_transport_vport_template) {
4341 kmem_cache_destroy(srb_cachep);
4342 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004343 ql_log(ql_log_fatal, NULL, 0x0004,
4344 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004345 return -ENODEV;
4346 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004347 ql_log(ql_log_info, NULL, 0x0005,
4348 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07004349 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004350 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004351 if (ret) {
4352 kmem_cache_destroy(srb_cachep);
4353 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004354 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004355 ql_log(ql_log_fatal, NULL, 0x0006,
4356 "pci_register_driver failed...ret=%d Failing load!.\n",
4357 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004358 }
4359 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360}
4361
4362/**
4363 * qla2x00_module_exit - Module cleanup.
4364 **/
4365static void __exit
4366qla2x00_module_exit(void)
4367{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004368 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004369 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08004370 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004371 kmem_cache_destroy(srb_cachep);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004372 if (ctx_cachep)
4373 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004375 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376}
4377
4378module_init(qla2x00_module_init);
4379module_exit(qla2x00_module_exit);
4380
4381MODULE_AUTHOR("QLogic Corporation");
4382MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4383MODULE_LICENSE("GPL");
4384MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004385MODULE_FIRMWARE(FW_FILE_ISP21XX);
4386MODULE_FIRMWARE(FW_FILE_ISP22XX);
4387MODULE_FIRMWARE(FW_FILE_ISP2300);
4388MODULE_FIRMWARE(FW_FILE_ISP2322);
4389MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08004390MODULE_FIRMWARE(FW_FILE_ISP25XX);