blob: 036030c953392e3fbd57220f5d314770bce769bf [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 Kashyapad5376892011-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);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001134 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001135 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001136 unsigned int id, lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001137 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
f4f051e2005-04-17 15:02:26 -05001139 id = cmd->device->id;
1140 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001141
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001142 ql_log(ql_log_info, vha, 0x8018,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001143 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001145 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001146 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001148 if (vha != base_vha) {
1149 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001150 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001152 if (IS_QLA82XX(vha->hw)) {
1153 if (!qla82xx_fcoe_ctx_reset(vha)) {
1154 /* Ctx reset success */
1155 ret = SUCCESS;
1156 goto eh_host_reset_lock;
1157 }
1158 /* fall thru if ctx reset failed */
1159 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001160 if (ha->wq)
1161 flush_workqueue(ha->wq);
1162
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001164 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001165 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1166 /* failed. schedule dpc to try */
1167 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1168
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001169 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1170 ql_log(ql_log_warn, vha, 0x802a,
1171 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001173 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001174 }
1175 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001178 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001179 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001181 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
f4f051e2005-04-17 15:02:26 -05001183eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001184 ql_log(ql_log_info, vha, 0x8017,
1185 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1186 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
f4f051e2005-04-17 15:02:26 -05001188 return ret;
1189}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
1191/*
1192* qla2x00_loop_reset
1193* Issue loop reset.
1194*
1195* Input:
1196* ha = adapter block pointer.
1197*
1198* Returns:
1199* 0 = success
1200*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001201int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001202qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001204 int ret;
bdf79622005-04-17 15:06:53 -05001205 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001206 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001208 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001209 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1210 if (fcport->port_type != FCT_TARGET)
1211 continue;
1212
1213 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1214 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001215 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1216 "Bus Reset failed: Target Reset=%d "
1217 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001218 }
1219 }
1220 }
1221
Giridhar Malavalia9083012010-04-12 17:59:55 -07001222 if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001223 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001224 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001225 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1226 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001227 }
1228 atomic_set(&vha->loop_state, LOOP_DOWN);
1229 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1230 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 }
1232
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001233 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001234 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001235 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001236 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1237 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001238 }
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001241 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001243 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001246void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001247qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001248{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001249 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001250 unsigned long flags;
1251 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001252 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001254 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001255
1256 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001257 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001258 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001259 if (!req)
1260 continue;
1261 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1262 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001263 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001264 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001265 if (!sp->ctx ||
Arun Easibad75002010-05-04 15:01:30 -07001266 (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
1267 IS_PROT_IO(sp)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001268 sp->cmd->result = res;
1269 qla2x00_sp_compl(ha, sp);
1270 } else {
1271 ctx = sp->ctx;
Roland Dreier9bfacd02011-09-22 00:06:05 -07001272 if (ctx->type == SRB_ELS_CMD_RPT ||
1273 ctx->type == SRB_ELS_CMD_HST ||
1274 ctx->type == SRB_CT_CMD) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001275 struct fc_bsg_job *bsg_job =
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001276 ctx->u.bsg_job;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001277 if (bsg_job->request->msgcode
1278 == FC_BSG_HST_CT)
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001279 kfree(sp->fcport);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001280 bsg_job->req->errors = 0;
1281 bsg_job->reply->result = res;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001282 bsg_job->job_done(bsg_job);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001283 kfree(sp->ctx);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001284 mempool_free(sp,
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001285 ha->srb_mempool);
Roland Dreier9bfacd02011-09-22 00:06:05 -07001286 } else {
1287 ctx->u.iocb_cmd->free(sp);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001288 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001289 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001290 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001291 }
1292 }
1293 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1294}
1295
f4f051e2005-04-17 15:02:26 -05001296static int
1297qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
bdf79622005-04-17 15:06:53 -05001299 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001301 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001302 return -ENXIO;
1303
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001304 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001305
1306 return 0;
1307}
1308
1309static int
1310qla2xxx_slave_configure(struct scsi_device *sdev)
1311{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001313 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001314
f4f051e2005-04-17 15:02:26 -05001315 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001316 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001318 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001319 return 0;
1320}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
f4f051e2005-04-17 15:02:26 -05001322static void
1323qla2xxx_slave_destroy(struct scsi_device *sdev)
1324{
1325 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001328static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1329{
1330 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1331
1332 if (!scsi_track_queue_full(sdev, qdepth))
1333 return;
1334
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001335 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001336 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1337 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001338}
1339
1340static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1341{
1342 fc_port_t *fcport = sdev->hostdata;
1343 struct scsi_qla_host *vha = fcport->vha;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001344 struct req_que *req = NULL;
1345
1346 req = vha->req;
1347 if (!req)
1348 return;
1349
1350 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1351 return;
1352
1353 if (sdev->ordered_tags)
1354 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1355 else
1356 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1357
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001358 ql_dbg(ql_dbg_io, vha, 0x302a,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001359 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1360 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001361}
1362
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001363static int
Mike Christiee881a172009-10-15 17:46:39 -07001364qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001365{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001366 switch (reason) {
1367 case SCSI_QDEPTH_DEFAULT:
1368 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1369 break;
1370 case SCSI_QDEPTH_QFULL:
1371 qla2x00_handle_queue_full(sdev, qdepth);
1372 break;
1373 case SCSI_QDEPTH_RAMP_UP:
1374 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1375 break;
1376 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001377 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001378 }
Mike Christiee881a172009-10-15 17:46:39 -07001379
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001380 return sdev->queue_depth;
1381}
1382
1383static int
1384qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1385{
1386 if (sdev->tagged_supported) {
1387 scsi_set_tag_type(sdev, tag_type);
1388 if (tag_type)
1389 scsi_activate_tcq(sdev, sdev->queue_depth);
1390 else
1391 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1392 } else
1393 tag_type = 0;
1394
1395 return tag_type;
1396}
1397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398/**
1399 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1400 * @ha: HA context
1401 *
1402 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1403 * supported addressing method.
1404 */
1405static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001406qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001408 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Yang Hongyang6a355282009-04-06 19:01:13 -07001411 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001412 /* Any upper-dword bits set? */
1413 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001414 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001415 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001417 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1418 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001419 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001422
Yang Hongyang284901a2009-04-06 19:01:15 -07001423 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1424 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001427static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001428qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001429{
1430 unsigned long flags = 0;
1431 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1432
1433 spin_lock_irqsave(&ha->hardware_lock, flags);
1434 ha->interrupts_on = 1;
1435 /* enable risc and host interrupts */
1436 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1437 RD_REG_WORD(&reg->ictrl);
1438 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1439
1440}
1441
1442static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001443qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001444{
1445 unsigned long flags = 0;
1446 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1447
1448 spin_lock_irqsave(&ha->hardware_lock, flags);
1449 ha->interrupts_on = 0;
1450 /* disable risc and host interrupts */
1451 WRT_REG_WORD(&reg->ictrl, 0);
1452 RD_REG_WORD(&reg->ictrl);
1453 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1454}
1455
1456static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001458{
1459 unsigned long flags = 0;
1460 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1461
1462 spin_lock_irqsave(&ha->hardware_lock, flags);
1463 ha->interrupts_on = 1;
1464 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1465 RD_REG_DWORD(&reg->ictrl);
1466 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1467}
1468
1469static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001471{
1472 unsigned long flags = 0;
1473 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1474
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001475 if (IS_NOPOLLING_TYPE(ha))
1476 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001477 spin_lock_irqsave(&ha->hardware_lock, flags);
1478 ha->interrupts_on = 0;
1479 WRT_REG_DWORD(&reg->ictrl, 0);
1480 RD_REG_DWORD(&reg->ictrl);
1481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1482}
1483
Giridhar Malavali706f4572011-11-18 09:03:16 -08001484static int
1485qla2x00_iospace_config(struct qla_hw_data *ha)
1486{
1487 resource_size_t pio;
1488 uint16_t msix;
1489 int cpus;
1490
1491 if (IS_QLA82XX(ha))
1492 return qla82xx_iospace_config(ha);
1493
1494 if (pci_request_selected_regions(ha->pdev, ha->bars,
1495 QLA2XXX_DRIVER_NAME)) {
1496 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1497 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1498 pci_name(ha->pdev));
1499 goto iospace_error_exit;
1500 }
1501 if (!(ha->bars & 1))
1502 goto skip_pio;
1503
1504 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1505 pio = pci_resource_start(ha->pdev, 0);
1506 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1507 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1508 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1509 "Invalid pci I/O region size (%s).\n",
1510 pci_name(ha->pdev));
1511 pio = 0;
1512 }
1513 } else {
1514 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1515 "Region #0 no a PIO resource (%s).\n",
1516 pci_name(ha->pdev));
1517 pio = 0;
1518 }
1519 ha->pio_address = pio;
1520 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1521 "PIO address=%llu.\n",
1522 (unsigned long long)ha->pio_address);
1523
1524skip_pio:
1525 /* Use MMIO operations for all accesses. */
1526 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1527 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1528 "Region #1 not an MMIO resource (%s), aborting.\n",
1529 pci_name(ha->pdev));
1530 goto iospace_error_exit;
1531 }
1532 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1533 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1534 "Invalid PCI mem region size (%s), aborting.\n",
1535 pci_name(ha->pdev));
1536 goto iospace_error_exit;
1537 }
1538
1539 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1540 if (!ha->iobase) {
1541 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1542 "Cannot remap MMIO (%s), aborting.\n",
1543 pci_name(ha->pdev));
1544 goto iospace_error_exit;
1545 }
1546
1547 /* Determine queue resources */
1548 ha->max_req_queues = ha->max_rsp_queues = 1;
1549 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1550 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1551 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1552 goto mqiobase_exit;
1553
1554 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1555 pci_resource_len(ha->pdev, 3));
1556 if (ha->mqiobase) {
1557 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1558 "MQIO Base=%p.\n", ha->mqiobase);
1559 /* Read MSIX vector size of the board */
1560 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1561 ha->msix_count = msix;
1562 /* Max queues are bounded by available msix vectors */
1563 /* queue 0 uses two msix vectors */
1564 if (ql2xmultique_tag) {
1565 cpus = num_online_cpus();
1566 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1567 (cpus + 1) : (ha->msix_count - 1);
1568 ha->max_req_queues = 2;
1569 } else if (ql2xmaxqueues > 1) {
1570 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1571 QLA_MQ_SIZE : ql2xmaxqueues;
1572 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1573 "QoS mode set, max no of request queues:%d.\n",
1574 ha->max_req_queues);
1575 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1576 "QoS mode set, max no of request queues:%d.\n",
1577 ha->max_req_queues);
1578 }
1579 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1580 "MSI-X vector count: %d.\n", msix);
1581 } else
1582 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1583 "BAR 3 not enabled.\n");
1584
1585mqiobase_exit:
1586 ha->msix_count = ha->max_rsp_queues + 1;
1587 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1588 "MSIX Count:%d.\n", ha->msix_count);
1589 return (0);
1590
1591iospace_error_exit:
1592 return (-ENOMEM);
1593}
1594
1595
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001596static struct isp_operations qla2100_isp_ops = {
1597 .pci_config = qla2100_pci_config,
1598 .reset_chip = qla2x00_reset_chip,
1599 .chip_diag = qla2x00_chip_diag,
1600 .config_rings = qla2x00_config_rings,
1601 .reset_adapter = qla2x00_reset_adapter,
1602 .nvram_config = qla2x00_nvram_config,
1603 .update_fw_options = qla2x00_update_fw_options,
1604 .load_risc = qla2x00_load_risc,
1605 .pci_info_str = qla2x00_pci_info_str,
1606 .fw_version_str = qla2x00_fw_version_str,
1607 .intr_handler = qla2100_intr_handler,
1608 .enable_intrs = qla2x00_enable_intrs,
1609 .disable_intrs = qla2x00_disable_intrs,
1610 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001611 .target_reset = qla2x00_abort_target,
1612 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001613 .fabric_login = qla2x00_login_fabric,
1614 .fabric_logout = qla2x00_fabric_logout,
1615 .calc_req_entries = qla2x00_calc_iocbs_32,
1616 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1617 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1618 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1619 .read_nvram = qla2x00_read_nvram_data,
1620 .write_nvram = qla2x00_write_nvram_data,
1621 .fw_dump = qla2100_fw_dump,
1622 .beacon_on = NULL,
1623 .beacon_off = NULL,
1624 .beacon_blink = NULL,
1625 .read_optrom = qla2x00_read_optrom_data,
1626 .write_optrom = qla2x00_write_optrom_data,
1627 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001628 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001629 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001630 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001631};
1632
1633static struct isp_operations qla2300_isp_ops = {
1634 .pci_config = qla2300_pci_config,
1635 .reset_chip = qla2x00_reset_chip,
1636 .chip_diag = qla2x00_chip_diag,
1637 .config_rings = qla2x00_config_rings,
1638 .reset_adapter = qla2x00_reset_adapter,
1639 .nvram_config = qla2x00_nvram_config,
1640 .update_fw_options = qla2x00_update_fw_options,
1641 .load_risc = qla2x00_load_risc,
1642 .pci_info_str = qla2x00_pci_info_str,
1643 .fw_version_str = qla2x00_fw_version_str,
1644 .intr_handler = qla2300_intr_handler,
1645 .enable_intrs = qla2x00_enable_intrs,
1646 .disable_intrs = qla2x00_disable_intrs,
1647 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001648 .target_reset = qla2x00_abort_target,
1649 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001650 .fabric_login = qla2x00_login_fabric,
1651 .fabric_logout = qla2x00_fabric_logout,
1652 .calc_req_entries = qla2x00_calc_iocbs_32,
1653 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1654 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1655 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1656 .read_nvram = qla2x00_read_nvram_data,
1657 .write_nvram = qla2x00_write_nvram_data,
1658 .fw_dump = qla2300_fw_dump,
1659 .beacon_on = qla2x00_beacon_on,
1660 .beacon_off = qla2x00_beacon_off,
1661 .beacon_blink = qla2x00_beacon_blink,
1662 .read_optrom = qla2x00_read_optrom_data,
1663 .write_optrom = qla2x00_write_optrom_data,
1664 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001665 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001666 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001667 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001668};
1669
1670static struct isp_operations qla24xx_isp_ops = {
1671 .pci_config = qla24xx_pci_config,
1672 .reset_chip = qla24xx_reset_chip,
1673 .chip_diag = qla24xx_chip_diag,
1674 .config_rings = qla24xx_config_rings,
1675 .reset_adapter = qla24xx_reset_adapter,
1676 .nvram_config = qla24xx_nvram_config,
1677 .update_fw_options = qla24xx_update_fw_options,
1678 .load_risc = qla24xx_load_risc,
1679 .pci_info_str = qla24xx_pci_info_str,
1680 .fw_version_str = qla24xx_fw_version_str,
1681 .intr_handler = qla24xx_intr_handler,
1682 .enable_intrs = qla24xx_enable_intrs,
1683 .disable_intrs = qla24xx_disable_intrs,
1684 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001685 .target_reset = qla24xx_abort_target,
1686 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001687 .fabric_login = qla24xx_login_fabric,
1688 .fabric_logout = qla24xx_fabric_logout,
1689 .calc_req_entries = NULL,
1690 .build_iocbs = NULL,
1691 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1692 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1693 .read_nvram = qla24xx_read_nvram_data,
1694 .write_nvram = qla24xx_write_nvram_data,
1695 .fw_dump = qla24xx_fw_dump,
1696 .beacon_on = qla24xx_beacon_on,
1697 .beacon_off = qla24xx_beacon_off,
1698 .beacon_blink = qla24xx_beacon_blink,
1699 .read_optrom = qla24xx_read_optrom_data,
1700 .write_optrom = qla24xx_write_optrom_data,
1701 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001702 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001703 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001704 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001705};
1706
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001707static struct isp_operations qla25xx_isp_ops = {
1708 .pci_config = qla25xx_pci_config,
1709 .reset_chip = qla24xx_reset_chip,
1710 .chip_diag = qla24xx_chip_diag,
1711 .config_rings = qla24xx_config_rings,
1712 .reset_adapter = qla24xx_reset_adapter,
1713 .nvram_config = qla24xx_nvram_config,
1714 .update_fw_options = qla24xx_update_fw_options,
1715 .load_risc = qla24xx_load_risc,
1716 .pci_info_str = qla24xx_pci_info_str,
1717 .fw_version_str = qla24xx_fw_version_str,
1718 .intr_handler = qla24xx_intr_handler,
1719 .enable_intrs = qla24xx_enable_intrs,
1720 .disable_intrs = qla24xx_disable_intrs,
1721 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001722 .target_reset = qla24xx_abort_target,
1723 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001724 .fabric_login = qla24xx_login_fabric,
1725 .fabric_logout = qla24xx_fabric_logout,
1726 .calc_req_entries = NULL,
1727 .build_iocbs = NULL,
1728 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1729 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1730 .read_nvram = qla25xx_read_nvram_data,
1731 .write_nvram = qla25xx_write_nvram_data,
1732 .fw_dump = qla25xx_fw_dump,
1733 .beacon_on = qla24xx_beacon_on,
1734 .beacon_off = qla24xx_beacon_off,
1735 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001736 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001737 .write_optrom = qla24xx_write_optrom_data,
1738 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001739 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001740 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001741 .iospace_config = qla2x00_iospace_config,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001742};
1743
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001744static struct isp_operations qla81xx_isp_ops = {
1745 .pci_config = qla25xx_pci_config,
1746 .reset_chip = qla24xx_reset_chip,
1747 .chip_diag = qla24xx_chip_diag,
1748 .config_rings = qla24xx_config_rings,
1749 .reset_adapter = qla24xx_reset_adapter,
1750 .nvram_config = qla81xx_nvram_config,
1751 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001752 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001753 .pci_info_str = qla24xx_pci_info_str,
1754 .fw_version_str = qla24xx_fw_version_str,
1755 .intr_handler = qla24xx_intr_handler,
1756 .enable_intrs = qla24xx_enable_intrs,
1757 .disable_intrs = qla24xx_disable_intrs,
1758 .abort_command = qla24xx_abort_command,
1759 .target_reset = qla24xx_abort_target,
1760 .lun_reset = qla24xx_lun_reset,
1761 .fabric_login = qla24xx_login_fabric,
1762 .fabric_logout = qla24xx_fabric_logout,
1763 .calc_req_entries = NULL,
1764 .build_iocbs = NULL,
1765 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1766 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001767 .read_nvram = NULL,
1768 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001769 .fw_dump = qla81xx_fw_dump,
1770 .beacon_on = qla24xx_beacon_on,
1771 .beacon_off = qla24xx_beacon_off,
1772 .beacon_blink = qla24xx_beacon_blink,
1773 .read_optrom = qla25xx_read_optrom_data,
1774 .write_optrom = qla24xx_write_optrom_data,
1775 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001776 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001777 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001778 .iospace_config = qla2x00_iospace_config,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001779};
1780
1781static struct isp_operations qla82xx_isp_ops = {
1782 .pci_config = qla82xx_pci_config,
1783 .reset_chip = qla82xx_reset_chip,
1784 .chip_diag = qla24xx_chip_diag,
1785 .config_rings = qla82xx_config_rings,
1786 .reset_adapter = qla24xx_reset_adapter,
1787 .nvram_config = qla81xx_nvram_config,
1788 .update_fw_options = qla24xx_update_fw_options,
1789 .load_risc = qla82xx_load_risc,
1790 .pci_info_str = qla82xx_pci_info_str,
1791 .fw_version_str = qla24xx_fw_version_str,
1792 .intr_handler = qla82xx_intr_handler,
1793 .enable_intrs = qla82xx_enable_intrs,
1794 .disable_intrs = qla82xx_disable_intrs,
1795 .abort_command = qla24xx_abort_command,
1796 .target_reset = qla24xx_abort_target,
1797 .lun_reset = qla24xx_lun_reset,
1798 .fabric_login = qla24xx_login_fabric,
1799 .fabric_logout = qla24xx_fabric_logout,
1800 .calc_req_entries = NULL,
1801 .build_iocbs = NULL,
1802 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1803 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1804 .read_nvram = qla24xx_read_nvram_data,
1805 .write_nvram = qla24xx_write_nvram_data,
1806 .fw_dump = qla24xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07001807 .beacon_on = qla82xx_beacon_on,
1808 .beacon_off = qla82xx_beacon_off,
1809 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001810 .read_optrom = qla82xx_read_optrom_data,
1811 .write_optrom = qla82xx_write_optrom_data,
1812 .get_flash_version = qla24xx_get_flash_version,
1813 .start_scsi = qla82xx_start_scsi,
1814 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08001815 .iospace_config = qla82xx_iospace_config,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001816};
1817
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001818static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001819qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001820{
1821 ha->device_type = DT_EXTENDED_IDS;
1822 switch (ha->pdev->device) {
1823 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1824 ha->device_type |= DT_ISP2100;
1825 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001826 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001827 break;
1828 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1829 ha->device_type |= DT_ISP2200;
1830 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001831 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001832 break;
1833 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1834 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001835 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001836 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001837 break;
1838 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1839 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001840 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001841 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001842 break;
1843 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1844 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001845 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001846 if (ha->pdev->subsystem_vendor == 0x1028 &&
1847 ha->pdev->subsystem_device == 0x0170)
1848 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001849 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001850 break;
1851 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1852 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001853 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001854 break;
1855 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1856 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001857 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001858 break;
1859 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1860 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001861 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001862 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001863 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001864 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001865 break;
1866 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1867 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001868 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001869 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001870 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001871 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001872 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001873 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1874 ha->device_type |= DT_ISP8432;
1875 ha->device_type |= DT_ZIO_SUPPORTED;
1876 ha->device_type |= DT_FWI2;
1877 ha->device_type |= DT_IIDMA;
1878 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1879 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001880 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1881 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001882 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001883 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001884 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001885 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1886 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001887 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001888 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001889 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001890 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1891 ha->device_type |= DT_ISP2532;
1892 ha->device_type |= DT_ZIO_SUPPORTED;
1893 ha->device_type |= DT_FWI2;
1894 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001895 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1896 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001897 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1898 ha->device_type |= DT_ISP8001;
1899 ha->device_type |= DT_ZIO_SUPPORTED;
1900 ha->device_type |= DT_FWI2;
1901 ha->device_type |= DT_IIDMA;
1902 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1903 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001904 case PCI_DEVICE_ID_QLOGIC_ISP8021:
1905 ha->device_type |= DT_ISP8021;
1906 ha->device_type |= DT_ZIO_SUPPORTED;
1907 ha->device_type |= DT_FWI2;
1908 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1909 /* Initialize 82XX ISP flags */
1910 qla82xx_init_flags(ha);
1911 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001912 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001913
Giridhar Malavalia9083012010-04-12 17:59:55 -07001914 if (IS_QLA82XX(ha))
1915 ha->port_no = !(ha->portnum & 1);
1916 else
1917 /* Get adapter physical port no from interrupt pin register. */
1918 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1919
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001920 if (ha->port_no & 1)
1921 ha->flags.port0 = 1;
1922 else
1923 ha->flags.port0 = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001924 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08001925 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001926 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001927}
1928
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001929static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001930qla2xxx_scan_start(struct Scsi_Host *shost)
1931{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001933
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001934 if (vha->hw->flags.running_gold_fw)
1935 return;
1936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1938 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1939 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1940 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001941}
1942
1943static int
1944qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1945{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001949 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001951 return 1;
1952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001954}
1955
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956/*
1957 * PCI driver interface
1958 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001959static int __devinit
1960qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001962 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 scsi_qla_host_t *base_vha = NULL;
1965 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001966 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001968 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001969 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001970 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001971 struct req_que *req = NULL;
1972 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Andrew Vasquez285d0322007-10-19 15:59:17 -07001974 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001975 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001976 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1977 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001978 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001979 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1980 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001981 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07001982 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
1983 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001984 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001985 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001986 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
1987 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07001988 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001989 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
1990 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07001991
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001992 if (mem_only) {
1993 if (pci_enable_device_mem(pdev))
1994 goto probe_out;
1995 } else {
1996 if (pci_enable_device(pdev))
1997 goto probe_out;
1998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Jesse Barnes09276782008-10-18 17:33:19 -07002000 /* This may fail but that's ok */
2001 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002002
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2004 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002005 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2006 "Unable to allocate memory for ha.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002009 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2010 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
2013 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002014 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002015 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002016 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002017 spin_lock_init(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002019 /* Set ISP-type information. */
2020 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002021
2022 /* Set EEH reset type to fundamental if required by hba */
2023 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
2024 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002025 }
2026
Chad Dupuiscba1e472011-11-18 09:03:21 -08002027 ha->prev_topology = 0;
2028 ha->init_cb_size = sizeof(init_cb_t);
2029 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2030 ha->optrom_size = OPTROM_SIZE_2300;
2031
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002032 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 req_length = REQUEST_ENTRY_CNT_2100;
2038 rsp_length = RESPONSE_ENTRY_CNT_2100;
2039 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002040 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002041 ha->flash_conf_off = ~0;
2042 ha->flash_data_off = ~0;
2043 ha->nvram_conf_off = ~0;
2044 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002045 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 } else if (IS_QLA2200(ha)) {
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002047 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 req_length = REQUEST_ENTRY_CNT_2200;
2049 rsp_length = RESPONSE_ENTRY_CNT_2100;
2050 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002051 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002052 ha->flash_conf_off = ~0;
2053 ha->flash_data_off = ~0;
2054 ha->nvram_conf_off = ~0;
2055 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002056 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002057 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 req_length = REQUEST_ENTRY_CNT_2200;
2060 rsp_length = RESPONSE_ENTRY_CNT_2300;
2061 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002062 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002063 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2064 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002065 ha->flash_conf_off = ~0;
2066 ha->flash_data_off = ~0;
2067 ha->nvram_conf_off = ~0;
2068 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002069 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002070 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07002071 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 req_length = REQUEST_ENTRY_CNT_24XX;
2073 rsp_length = RESPONSE_ENTRY_CNT_2300;
2074 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002075 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002076 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002077 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002078 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002079 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002080 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2081 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2082 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2083 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002084 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002085 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086 req_length = REQUEST_ENTRY_CNT_24XX;
2087 rsp_length = RESPONSE_ENTRY_CNT_2300;
2088 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002089 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002090 ha->gid_list_info_size = 8;
2091 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002092 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002093 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002094 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2095 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2096 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2097 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2098 } else if (IS_QLA81XX(ha)) {
2099 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2100 req_length = REQUEST_ENTRY_CNT_24XX;
2101 rsp_length = RESPONSE_ENTRY_CNT_2300;
2102 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2103 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2104 ha->gid_list_info_size = 8;
2105 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002106 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002107 ha->isp_ops = &qla81xx_isp_ops;
2108 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2109 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2110 ha->nvram_conf_off = ~0;
2111 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002112 } else if (IS_QLA82XX(ha)) {
2113 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2114 req_length = REQUEST_ENTRY_CNT_82XX;
2115 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2116 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2117 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2118 ha->gid_list_info_size = 8;
2119 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002120 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002121 ha->isp_ops = &qla82xx_isp_ops;
2122 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2123 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2124 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2125 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002127 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2128 "mbx_count=%d, req_length=%d, "
2129 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2130 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
2131 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2132 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2133 ha->nvram_npiv_size);
2134 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2135 "isp_ops=%p, flash_conf_off=%d, "
2136 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2137 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2138 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002139
2140 /* Configure PCI I/O space */
2141 ret = ha->isp_ops->iospace_config(ha);
2142 if (ret)
2143 goto probe_hw_failed;
2144
2145 ql_log_pci(ql_log_info, pdev, 0x001d,
2146 "Found an ISP%04X irq %d iobase 0x%p.\n",
2147 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002148 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002149 init_completion(&ha->mbx_cmd_comp);
2150 complete(&ha->mbx_cmd_comp);
2151 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002152 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002154 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Andrew Vasquez53303c42009-01-22 09:45:37 -08002156 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002157 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2158 "64 Bit addressing is %s.\n",
2159 ha->flags.enable_64bit_addressing ? "enable" :
2160 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002161 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162 if (!ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002163 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2164 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 goto probe_hw_failed;
2167 }
2168
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002169 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002171 req->max_q_depth = ql2xmaxqdepth;
2172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173
2174 base_vha = qla2x00_create_host(sht, ha);
2175 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002176 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002177 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002178 qla2x00_free_req_que(ha, req);
2179 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002180 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 }
2182
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002185 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002186 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002187 host->can_queue = req->length + 128;
2188 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002189 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002190 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002191 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2192 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07002193
2194 /* Set the SG table size based on ISP type */
2195 if (!IS_FWI2_CAPABLE(ha)) {
2196 if (IS_QLA2100(ha))
2197 host->sg_tablesize = 32;
2198 } else {
2199 if (!IS_QLA82XX(ha))
2200 host->sg_tablesize = QLA_SG_ALL;
2201 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002202 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2203 "can_queue=%d, req=%p, "
2204 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2205 host->can_queue, base_vha->req,
2206 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002207 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002208 host->this_id = 255;
2209 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002210 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07002211 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05002212 host->max_cmd_len = 32;
2213 else
2214 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002215 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -07002216 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002217 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002218 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002219
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002220 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2221 "max_id=%d this_id=%d "
2222 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Joe Perchesd8424f62011-11-18 09:03:06 -08002223 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002224 host->this_id, host->cmd_per_lun, host->unique_id,
2225 host->max_cmd_len, host->max_channel, host->max_lun,
2226 host->transportt, sht->vendor_id);
2227
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002228 /* Set up the irqs */
2229 ret = qla2x00_request_irqs(ha, rsp);
2230 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002231 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002232
2233 pci_save_state(pdev);
2234
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002235 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002236que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002237 if (!qla2x00_alloc_queues(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002238 ql_log(ql_log_fatal, base_vha, 0x003d,
2239 "Failed to allocate memory for queue pointers.. aborting.\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002240 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002241 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002242
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002243 ha->rsp_q_map[0] = rsp;
2244 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002245 rsp->req = req;
2246 req->rsp = rsp;
2247 set_bit(0, ha->req_qid_map);
2248 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07002249 /* FWI2-capable only. */
2250 req->req_q_in = &ha->iobase->isp24.req_q_in;
2251 req->req_q_out = &ha->iobase->isp24.req_q_out;
2252 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2253 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002254 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002255 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2256 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2257 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2258 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002259 }
2260
Giridhar Malavalia9083012010-04-12 17:59:55 -07002261 if (IS_QLA82XX(ha)) {
2262 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2263 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2264 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2265 }
2266
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002267 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2268 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2269 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2270 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2271 "req->req_q_in=%p req->req_q_out=%p "
2272 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2273 req->req_q_in, req->req_q_out,
2274 rsp->rsp_q_in, rsp->rsp_q_out);
2275 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2276 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2277 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2278 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2279 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2280 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002282 if (qla2x00_initialize_adapter(base_vha)) {
2283 ql_log(ql_log_fatal, base_vha, 0x00d6,
2284 "Failed to initialize adapter - Adapter flags %x.\n",
2285 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002286
Giridhar Malavalia9083012010-04-12 17:59:55 -07002287 if (IS_QLA82XX(ha)) {
2288 qla82xx_idc_lock(ha);
2289 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2290 QLA82XX_DEV_FAILED);
2291 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002292 ql_log(ql_log_fatal, base_vha, 0x00d7,
2293 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002294 }
2295
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002296 ret = -ENODEV;
2297 goto probe_failed;
2298 }
2299
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002300 if (ha->mqenable) {
2301 if (qla25xx_setup_mode(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002302 ql_log(ql_log_warn, base_vha, 0x00ec,
2303 "Failed to create queues, falling back to single queue mode.\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002304 goto que_init;
2305 }
2306 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002307
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002308 if (ha->flags.running_gold_fw)
2309 goto skip_dpc;
2310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 /*
2312 * Startup the kernel thread for this host adapter
2313 */
2314 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002315 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002317 ql_log(ql_log_fatal, base_vha, 0x00ed,
2318 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 ret = PTR_ERR(ha->dpc_thread);
2320 goto probe_failed;
2321 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002322 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2323 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002324
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002325skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002326 list_add_tail(&base_vha->list, &ha->vp_list);
2327 base_vha->host->irq = ha->pdev->irq;
2328
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002331 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2332 "Started qla2x00_timer with "
2333 "interval=%d.\n", WATCH_INTERVAL);
2334 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2335 "Detected hba at address=%p.\n",
2336 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Arun Easie02587d2011-08-16 11:29:23 -07002338 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002339 if (ha->fw_attributes & BIT_4) {
Arun Easi8cb20492011-08-16 11:29:22 -07002340 int prot = 0;
Arun Easibad75002010-05-04 15:01:30 -07002341 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002342 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2343 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07002344 if (ql2xenabledif == 1)
2345 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07002346 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07002347 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002348 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002349 | SHOST_DIF_TYPE3_PROTECTION
2350 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002351 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002352 | SHOST_DIX_TYPE3_PROTECTION);
2353 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2354 } else
2355 base_vha->flags.difdix_supported = 0;
2356 }
2357
Giridhar Malavalia9083012010-04-12 17:59:55 -07002358 ha->isp_ops->enable_intrs(ha);
2359
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002360 ret = scsi_add_host(host, &pdev->dev);
2361 if (ret)
2362 goto probe_failed;
2363
Michael Reed14864002009-12-02 09:11:16 -06002364 base_vha->flags.init_done = 1;
2365 base_vha->flags.online = 1;
2366
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002367 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2368 "Init done and hba is online.\n");
2369
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002370 scsi_scan_host(host);
2371
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002372 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002373
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002374 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002375
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002377
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002378 ql_log(ql_log_info, base_vha, 0x00fb,
2379 "QLogic %s - %s.\n",
2380 ha->model_number, ha->model_desc ? ha->model_desc : "");
2381 ql_log(ql_log_info, base_vha, 0x00fc,
2382 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2383 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2384 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2385 base_vha->host_no,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 return 0;
2389
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002390probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002391 qla2x00_free_req_que(ha, req);
2392 qla2x00_free_rsp_que(ha, rsp);
2393 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002394
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002396 if (base_vha->timer_active)
2397 qla2x00_stop_timer(base_vha);
2398 base_vha->flags.online = 0;
2399 if (ha->dpc_thread) {
2400 struct task_struct *t = ha->dpc_thread;
2401
2402 ha->dpc_thread = NULL;
2403 kthread_stop(t);
2404 }
2405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002408 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002411 if (IS_QLA82XX(ha)) {
2412 qla82xx_idc_lock(ha);
2413 qla82xx_clear_drv_active(ha);
2414 qla82xx_idc_unlock(ha);
2415 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2416 if (!ql2xdbwr)
2417 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2418 } else {
2419 if (ha->iobase)
2420 iounmap(ha->iobase);
2421 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 pci_release_selected_regions(ha->pdev, ha->bars);
2423 kfree(ha);
2424 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002426probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002428 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Adrian Bunk4c993f72008-01-14 00:55:16 -08002431static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002432qla2x00_shutdown(struct pci_dev *pdev)
2433{
2434 scsi_qla_host_t *vha;
2435 struct qla_hw_data *ha;
2436
2437 vha = pci_get_drvdata(pdev);
2438 ha = vha->hw;
2439
2440 /* Turn-off FCE trace */
2441 if (ha->flags.fce_enabled) {
2442 qla2x00_disable_fce_trace(vha, NULL, NULL);
2443 ha->flags.fce_enabled = 0;
2444 }
2445
2446 /* Turn-off EFT trace */
2447 if (ha->eft)
2448 qla2x00_disable_eft_trace(vha);
2449
2450 /* Stop currently executing firmware. */
2451 qla2x00_try_to_stop_firmware(vha);
2452
2453 /* Turn adapter off line */
2454 vha->flags.online = 0;
2455
2456 /* turn-off interrupts on the card */
2457 if (ha->interrupts_on) {
2458 vha->flags.init_done = 0;
2459 ha->isp_ops->disable_intrs(ha);
2460 }
2461
2462 qla2x00_free_irqs(vha);
2463
2464 qla2x00_free_fw_dump(ha);
2465}
2466
2467static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002468qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469{
Arun Easifeafb7b2010-09-03 14:57:00 -07002470 scsi_qla_host_t *base_vha, *vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 struct qla_hw_data *ha;
Arun Easifeafb7b2010-09-03 14:57:00 -07002472 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002474 base_vha = pci_get_drvdata(pdev);
2475 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Arun Easi43ebf162011-05-10 11:18:16 -07002477 mutex_lock(&ha->vport_lock);
2478 while (ha->cur_vport_count) {
2479 struct Scsi_Host *scsi_host;
Arun Easifeafb7b2010-09-03 14:57:00 -07002480
Arun Easi43ebf162011-05-10 11:18:16 -07002481 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07002482
Arun Easi43ebf162011-05-10 11:18:16 -07002483 BUG_ON(base_vha->list.next == &ha->vp_list);
2484 /* This assumes first entry in ha->vp_list is always base vha */
2485 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2486 scsi_host = scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07002487
Arun Easi43ebf162011-05-10 11:18:16 -07002488 spin_unlock_irqrestore(&ha->vport_slock, flags);
2489 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07002490
Arun Easi43ebf162011-05-10 11:18:16 -07002491 fc_vport_terminate(vha->fc_vport);
2492 scsi_host_put(vha->host);
2493
2494 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 }
Arun Easi43ebf162011-05-10 11:18:16 -07002496 mutex_unlock(&ha->vport_lock);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002497
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002499
Andrew Vasquezb9978762009-03-24 09:08:05 -07002500 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2501
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002502 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002503
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002505
Andrew Vasquezb9978762009-03-24 09:08:05 -07002506 /* Disable timer */
2507 if (base_vha->timer_active)
2508 qla2x00_stop_timer(base_vha);
2509
2510 base_vha->flags.online = 0;
2511
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002512 /* Flush the work queue and remove it */
2513 if (ha->wq) {
2514 flush_workqueue(ha->wq);
2515 destroy_workqueue(ha->wq);
2516 ha->wq = NULL;
2517 }
2518
Andrew Vasquezb9978762009-03-24 09:08:05 -07002519 /* Kill the kernel thread for this host */
2520 if (ha->dpc_thread) {
2521 struct task_struct *t = ha->dpc_thread;
2522
2523 /*
2524 * qla2xxx_wake_dpc checks for ->dpc_thread
2525 * so we need to zero it out.
2526 */
2527 ha->dpc_thread = NULL;
2528 kthread_stop(t);
2529 }
2530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002531 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002533 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002534
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 scsi_host_put(base_vha->host);
2540
Giridhar Malavalia9083012010-04-12 17:59:55 -07002541 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002542 qla82xx_idc_lock(ha);
2543 qla82xx_clear_drv_active(ha);
2544 qla82xx_idc_unlock(ha);
2545
Giridhar Malavalia9083012010-04-12 17:59:55 -07002546 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2547 if (!ql2xdbwr)
2548 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2549 } else {
2550 if (ha->iobase)
2551 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552
Giridhar Malavalia9083012010-04-12 17:59:55 -07002553 if (ha->mqiobase)
2554 iounmap(ha->mqiobase);
2555 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002556
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557 pci_release_selected_regions(ha->pdev, ha->bars);
2558 kfree(ha);
2559 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002561 pci_disable_pcie_error_reporting(pdev);
2562
Bernhard Walle665db932007-03-28 00:49:49 +02002563 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 pci_set_drvdata(pdev, NULL);
2565}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
2567static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
Andrew Vasquez85880802009-12-15 21:29:46 -08002572 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2573
2574 /* Disable timer */
2575 if (vha->timer_active)
2576 qla2x00_stop_timer(vha);
2577
2578 /* Kill the kernel thread for this host */
2579 if (ha->dpc_thread) {
2580 struct task_struct *t = ha->dpc_thread;
2581
2582 /*
2583 * qla2xxx_wake_dpc checks for ->dpc_thread
2584 * so we need to zero it out.
2585 */
2586 ha->dpc_thread = NULL;
2587 kthread_stop(t);
2588 }
2589
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002590 qla25xx_delete_queues(vha);
2591
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002592 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002594
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002595 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002597
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002598 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
Andrew Vasquez85880802009-12-15 21:29:46 -08002601 vha->flags.online = 0;
2602
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002603 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002604 if (ha->interrupts_on) {
2605 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002606 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002607 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 qla2x00_free_irqs(vha);
2610
Chad Dupuis88670482010-07-23 15:28:30 +05002611 qla2x00_free_fcports(vha);
2612
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002613 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002614
Giridhar Malavali08de2842011-08-16 11:31:44 -07002615 qla82xx_md_free(vha);
2616
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002617 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618}
2619
Chad Dupuis88670482010-07-23 15:28:30 +05002620void qla2x00_free_fcports(struct scsi_qla_host *vha)
2621{
2622 fc_port_t *fcport, *tfcport;
2623
2624 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2625 list_del(&fcport->list);
2626 kfree(fcport);
2627 fcport = NULL;
2628 }
2629}
2630
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002631static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002632qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002633 int defer)
2634{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002635 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002636 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002637 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002638
2639 if (!fcport->rport)
2640 return;
2641
2642 rport = fcport->rport;
2643 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002644 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002645 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002646 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002647 spin_unlock_irqrestore(vha->host->host_lock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002648 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2649 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002650 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002651 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002652}
2653
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2656 *
2657 * Input: ha = adapter block pointer. fcport = port structure pointer.
2658 *
2659 * Return: None.
2660 *
2661 * Context:
2662 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002663void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002664 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002666 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 vha->vp_idx == fcport->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002668 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002669 qla2x00_schedule_rport_del(vha, fcport, defer);
2670 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002671 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 * We may need to retry the login, so don't change the state of the
2673 * port but do the retries.
2674 */
2675 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07002676 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
2678 if (!do_login)
2679 return;
2680
2681 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 fcport->login_retry = vha->hw->login_retry_count;
2683 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002685 ql_dbg(ql_dbg_disc, vha, 0x2067,
2686 "Port login retry "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 "%02x%02x%02x%02x%02x%02x%02x%02x, "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002688 "id = 0x%04x retry cnt=%d.\n",
2689 fcport->port_name[0], fcport->port_name[1],
2690 fcport->port_name[2], fcport->port_name[3],
2691 fcport->port_name[4], fcport->port_name[5],
2692 fcport->port_name[6], fcport->port_name[7],
2693 fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 }
2695}
2696
2697/*
2698 * qla2x00_mark_all_devices_lost
2699 * Updates fcport state when device goes offline.
2700 *
2701 * Input:
2702 * ha = adapter block pointer.
2703 * fcport = port structure pointer.
2704 *
2705 * Return:
2706 * None.
2707 *
2708 * Context:
2709 */
2710void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002711qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
2713 fc_port_t *fcport;
2714
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002716 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002718
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 /*
2720 * No point in marking the device as lost, if the device is
2721 * already DEAD.
2722 */
2723 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2724 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07002726 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002727 if (defer)
2728 qla2x00_schedule_rport_del(vha, fcport, defer);
2729 else if (vha->vp_idx == fcport->vp_idx)
2730 qla2x00_schedule_rport_del(vha, fcport, defer);
2731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 }
2733}
2734
2735/*
2736* qla2x00_mem_alloc
2737* Allocates adapter memory.
2738*
2739* Returns:
2740* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002741* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002743static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002744qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2745 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746{
2747 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
Andrew Vasqueze8711082008-01-31 12:33:48 -08002749 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002750 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002751 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002754 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2755 &ha->gid_list_dma, GFP_KERNEL);
2756 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002757 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758
Andrew Vasqueze8711082008-01-31 12:33:48 -08002759 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2760 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Giridhar Malavalia9083012010-04-12 17:59:55 -07002763 if (IS_QLA82XX(ha)) {
2764 /* Allocate cache for CT6 Ctx. */
2765 if (!ctx_cachep) {
2766 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2767 sizeof(struct ct6_dsd), 0,
2768 SLAB_HWCACHE_ALIGN, NULL);
2769 if (!ctx_cachep)
2770 goto fail_free_gid_list;
2771 }
2772 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2773 ctx_cachep);
2774 if (!ha->ctx_mempool)
2775 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002776 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
2777 "ctx_cachep=%p ctx_mempool=%p.\n",
2778 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002779 }
2780
Andrew Vasqueze8711082008-01-31 12:33:48 -08002781 /* Get memory for cached NVRAM */
2782 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2783 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002784 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2787 ha->pdev->device);
2788 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2789 DMA_POOL_SIZE, 8, 0);
2790 if (!ha->s_dma_pool)
2791 goto fail_free_nvram;
2792
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002793 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
2794 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
2795 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
2796
Arun Easibad75002010-05-04 15:01:30 -07002797 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002798 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2799 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2800 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002801 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
2802 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002803 goto fail_s_dma_pool;
2804 }
2805
2806 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2807 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2808 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002809 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
2810 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07002811 goto fail_dl_dma_pool;
2812 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002813 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
2814 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
2815 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002816 }
2817
Andrew Vasqueze8711082008-01-31 12:33:48 -08002818 /* Allocate memory for SNS commands */
2819 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002820 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002821 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002823 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08002826 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002827 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002829 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002831 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 goto fail_dma_pool;
2833 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002834 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002836 if (!ha->ct_sns)
2837 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002838 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
2839 "ms_iocb=%p ct_sns=%p.\n",
2840 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 }
2842
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002844 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2845 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002846 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
2847 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 goto fail_req;
2849 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002850 (*req)->length = req_len;
2851 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2852 ((*req)->length + 1) * sizeof(request_t),
2853 &(*req)->dma, GFP_KERNEL);
2854 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002855 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
2856 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 goto fail_req_ring;
2858 }
2859 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002860 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2861 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002862 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
2863 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 goto fail_rsp;
2865 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002866 (*rsp)->hw = ha;
2867 (*rsp)->length = rsp_len;
2868 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2869 ((*rsp)->length + 1) * sizeof(response_t),
2870 &(*rsp)->dma, GFP_KERNEL);
2871 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002872 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
2873 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002874 goto fail_rsp_ring;
2875 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002876 (*req)->rsp = *rsp;
2877 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002878 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
2879 "req=%p req->length=%d req->ring=%p rsp=%p "
2880 "rsp->length=%d rsp->ring=%p.\n",
2881 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
2882 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002883 /* Allocate memory for NVRAM data for vports */
2884 if (ha->nvram_npiv_size) {
2885 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002886 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002887 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002888 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
2889 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002890 goto fail_npiv_info;
2891 }
2892 } else
2893 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002895 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002896 if (IS_QLA8XXX_TYPE(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002897 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2898 &ha->ex_init_cb_dma);
2899 if (!ha->ex_init_cb)
2900 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002901 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
2902 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002903 }
2904
Giridhar Malavalia9083012010-04-12 17:59:55 -07002905 INIT_LIST_HEAD(&ha->gbl_dsd_list);
2906
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002907 /* Get consistent memory allocated for Async Port-Database. */
2908 if (!IS_FWI2_CAPABLE(ha)) {
2909 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2910 &ha->async_pd_dma);
2911 if (!ha->async_pd)
2912 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002913 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
2914 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002915 }
2916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 INIT_LIST_HEAD(&ha->vp_list);
2918 return 1;
2919
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002920fail_async_pd:
2921 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002922fail_ex_init_cb:
2923 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002924fail_npiv_info:
2925 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2926 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2927 (*rsp)->ring = NULL;
2928 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002930 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002932 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2933 sizeof(request_t), (*req)->ring, (*req)->dma);
2934 (*req)->ring = NULL;
2935 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002936fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002937 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938fail_req:
2939 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2940 ha->ct_sns, ha->ct_sns_dma);
2941 ha->ct_sns = NULL;
2942 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002943fail_free_ms_iocb:
2944 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2945 ha->ms_iocb = NULL;
2946 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002948 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002949 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2950 ha->fcp_cmnd_dma_pool = NULL;
2951 }
2952fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002953 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002954 dma_pool_destroy(ha->dl_dma_pool);
2955 ha->dl_dma_pool = NULL;
2956 }
2957fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002958 dma_pool_destroy(ha->s_dma_pool);
2959 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002960fail_free_nvram:
2961 kfree(ha->nvram);
2962 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002963fail_free_ctx_mempool:
2964 mempool_destroy(ha->ctx_mempool);
2965 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002966fail_free_srb_mempool:
2967 mempool_destroy(ha->srb_mempool);
2968 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002969fail_free_gid_list:
2970 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002971 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002972 ha->gid_list = NULL;
2973 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974fail_free_init_cb:
2975 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2976 ha->init_cb_dma);
2977 ha->init_cb = NULL;
2978 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002979fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002980 ql_log(ql_log_fatal, NULL, 0x0030,
2981 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08002982 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983}
2984
2985/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002986* qla2x00_free_fw_dump
2987* Frees fw dump stuff.
2988*
2989* Input:
2990* ha = adapter block pointer.
2991*/
2992static void
2993qla2x00_free_fw_dump(struct qla_hw_data *ha)
2994{
2995 if (ha->fce)
2996 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2997 ha->fce_dma);
2998
2999 if (ha->fw_dump) {
3000 if (ha->eft)
3001 dma_free_coherent(&ha->pdev->dev,
3002 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3003 vfree(ha->fw_dump);
3004 }
3005 ha->fce = NULL;
3006 ha->fce_dma = 0;
3007 ha->eft = NULL;
3008 ha->eft_dma = 0;
3009 ha->fw_dump = NULL;
3010 ha->fw_dumped = 0;
3011 ha->fw_dump_reading = 0;
3012}
3013
3014/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015* qla2x00_mem_free
3016* Frees all adapter allocated memory.
3017*
3018* Input:
3019* ha = adapter block pointer.
3020*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08003021static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003024 qla2x00_free_fw_dump(ha);
3025
Andrew Vasqueze8711082008-01-31 12:33:48 -08003026 if (ha->srb_mempool)
3027 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003029 if (ha->dcbx_tlv)
3030 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3031 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3032
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003033 if (ha->xgmac_data)
3034 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3035 ha->xgmac_data, ha->xgmac_data_dma);
3036
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 if (ha->sns_cmd)
3038 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003039 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
3041 if (ha->ct_sns)
3042 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003043 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Andrew Vasquez88729e52006-06-23 16:10:50 -07003045 if (ha->sfp_data)
3046 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3047
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003048 if (ha->edc_data)
3049 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
3050
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 if (ha->ms_iocb)
3052 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3053
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003054 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003055 dma_pool_free(ha->s_dma_pool,
3056 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003057
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003058 if (ha->async_pd)
3059 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3060
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 if (ha->s_dma_pool)
3062 dma_pool_destroy(ha->s_dma_pool);
3063
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 if (ha->gid_list)
3065 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003066 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
Giridhar Malavalia9083012010-04-12 17:59:55 -07003068 if (IS_QLA82XX(ha)) {
3069 if (!list_empty(&ha->gbl_dsd_list)) {
3070 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3071
3072 /* clean up allocated prev pool */
3073 list_for_each_entry_safe(dsd_ptr,
3074 tdsd_ptr, &ha->gbl_dsd_list, list) {
3075 dma_pool_free(ha->dl_dma_pool,
3076 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3077 list_del(&dsd_ptr->list);
3078 kfree(dsd_ptr);
3079 }
3080 }
3081 }
3082
3083 if (ha->dl_dma_pool)
3084 dma_pool_destroy(ha->dl_dma_pool);
3085
3086 if (ha->fcp_cmnd_dma_pool)
3087 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3088
3089 if (ha->ctx_mempool)
3090 mempool_destroy(ha->ctx_mempool);
3091
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003092 if (ha->init_cb)
3093 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07003094 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003095 vfree(ha->optrom_buffer);
3096 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003097 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098
Andrew Vasqueze8711082008-01-31 12:33:48 -08003099 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003100 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 ha->sns_cmd = NULL;
3102 ha->sns_cmd_dma = 0;
3103 ha->ct_sns = NULL;
3104 ha->ct_sns_dma = 0;
3105 ha->ms_iocb = NULL;
3106 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 ha->init_cb = NULL;
3108 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07003109 ha->ex_init_cb = NULL;
3110 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003111 ha->async_pd = NULL;
3112 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
3114 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003115 ha->dl_dma_pool = NULL;
3116 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 ha->gid_list = NULL;
3119 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003120}
3121
3122struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3123 struct qla_hw_data *ha)
3124{
3125 struct Scsi_Host *host;
3126 struct scsi_qla_host *vha = NULL;
3127
3128 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3129 if (host == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003130 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3131 "Failed to allocate host from the scsi layer, aborting.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003132 goto fail;
3133 }
3134
3135 /* Clear our data area */
3136 vha = shost_priv(host);
3137 memset(vha, 0, sizeof(scsi_qla_host_t));
3138
3139 vha->host = host;
3140 vha->host_no = host->host_no;
3141 vha->hw = ha;
3142
3143 INIT_LIST_HEAD(&vha->vp_fcports);
3144 INIT_LIST_HEAD(&vha->work_list);
3145 INIT_LIST_HEAD(&vha->list);
3146
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003147 spin_lock_init(&vha->work_lock);
3148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003149 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003150 ql_dbg(ql_dbg_init, vha, 0x0041,
3151 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3152 vha->host, vha->hw, vha,
3153 dev_name(&(ha->pdev->dev)));
3154
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 return vha;
3156
3157fail:
3158 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159}
3160
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003161static struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003162qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003163{
3164 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07003165 uint8_t bail;
3166
3167 QLA_VHA_MARK_BUSY(vha, bail);
3168 if (bail)
3169 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003170
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003171 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07003172 if (!e) {
3173 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003174 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003175 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003176
3177 INIT_LIST_HEAD(&e->list);
3178 e->type = type;
3179 e->flags = QLA_EVT_FLAG_FREE;
3180 return e;
3181}
3182
Adrian Bunk01ef66b2008-04-24 15:21:27 -07003183static int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003184qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003185{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003186 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003187
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003188 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003190 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003191 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003192
Andrew Vasquez0971de72008-04-03 13:13:18 -07003193 return QLA_SUCCESS;
3194}
3195
3196int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003198 u32 data)
3199{
3200 struct qla_work_evt *e;
3201
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003202 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003203 if (!e)
3204 return QLA_FUNCTION_FAILED;
3205
3206 e->u.aen.code = code;
3207 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003208 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003209}
3210
Andrew Vasquez8a659572009-02-08 20:50:12 -08003211int
3212qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3213{
3214 struct qla_work_evt *e;
3215
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003216 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003217 if (!e)
3218 return QLA_FUNCTION_FAILED;
3219
3220 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003221 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003222}
3223
Andrew Vasquezac280b62009-08-20 11:06:05 -07003224#define qla2x00_post_async_work(name, type) \
3225int qla2x00_post_async_##name##_work( \
3226 struct scsi_qla_host *vha, \
3227 fc_port_t *fcport, uint16_t *data) \
3228{ \
3229 struct qla_work_evt *e; \
3230 \
3231 e = qla2x00_alloc_work(vha, type); \
3232 if (!e) \
3233 return QLA_FUNCTION_FAILED; \
3234 \
3235 e->u.logio.fcport = fcport; \
3236 if (data) { \
3237 e->u.logio.data[0] = data[0]; \
3238 e->u.logio.data[1] = data[1]; \
3239 } \
3240 return qla2x00_post_work(vha, e); \
3241}
3242
3243qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3244qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3245qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3246qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003247qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3248qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003249
Andrew Vasquez3420d362009-10-13 15:16:45 -07003250int
3251qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3252{
3253 struct qla_work_evt *e;
3254
3255 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3256 if (!e)
3257 return QLA_FUNCTION_FAILED;
3258
3259 e->u.uevent.code = code;
3260 return qla2x00_post_work(vha, e);
3261}
3262
3263static void
3264qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3265{
3266 char event_string[40];
3267 char *envp[] = { event_string, NULL };
3268
3269 switch (code) {
3270 case QLA_UEVENT_CODE_FW_DUMP:
3271 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3272 vha->host_no);
3273 break;
3274 default:
3275 /* do nothing */
3276 break;
3277 }
3278 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3279}
3280
Andrew Vasquezac280b62009-08-20 11:06:05 -07003281void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003283{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003284 struct qla_work_evt *e, *tmp;
3285 unsigned long flags;
3286 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003287
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003288 spin_lock_irqsave(&vha->work_lock, flags);
3289 list_splice_init(&vha->work_list, &work);
3290 spin_unlock_irqrestore(&vha->work_lock, flags);
3291
3292 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003293 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003294
3295 switch (e->type) {
3296 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003298 e->u.aen.code, e->u.aen.data);
3299 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003300 case QLA_EVT_IDC_ACK:
3301 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3302 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003303 case QLA_EVT_ASYNC_LOGIN:
3304 qla2x00_async_login(vha, e->u.logio.fcport,
3305 e->u.logio.data);
3306 break;
3307 case QLA_EVT_ASYNC_LOGIN_DONE:
3308 qla2x00_async_login_done(vha, e->u.logio.fcport,
3309 e->u.logio.data);
3310 break;
3311 case QLA_EVT_ASYNC_LOGOUT:
3312 qla2x00_async_logout(vha, e->u.logio.fcport);
3313 break;
3314 case QLA_EVT_ASYNC_LOGOUT_DONE:
3315 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3316 e->u.logio.data);
3317 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003318 case QLA_EVT_ASYNC_ADISC:
3319 qla2x00_async_adisc(vha, e->u.logio.fcport,
3320 e->u.logio.data);
3321 break;
3322 case QLA_EVT_ASYNC_ADISC_DONE:
3323 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3324 e->u.logio.data);
3325 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003326 case QLA_EVT_UEVENT:
3327 qla2x00_uevent_emit(vha, e->u.uevent.code);
3328 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003329 }
3330 if (e->flags & QLA_EVT_FLAG_FREE)
3331 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07003332
3333 /* For each work completed decrement vha ref count */
3334 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003335 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07003337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338/* Relogins all the fcports of a vport
3339 * Context: dpc thread
3340 */
3341void qla2x00_relogin(struct scsi_qla_host *vha)
3342{
3343 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003344 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003345 uint16_t next_loopid = 0;
3346 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003347 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348
3349 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3350 /*
3351 * If the port is not ONLINE then try to login
3352 * to it if we haven't run out of retries.
3353 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003354 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3355 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003356 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003357 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003358 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003359 ha->isp_ops->fabric_logout(vha,
3360 fcport->loop_id,
3361 fcport->d_id.b.domain,
3362 fcport->d_id.b.area,
3363 fcport->d_id.b.al_pa);
3364
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003365 if (fcport->loop_id == FC_NO_LOOP_ID) {
3366 fcport->loop_id = next_loopid =
3367 ha->min_external_loopid;
3368 status = qla2x00_find_new_loop_id(
3369 vha, fcport);
3370 if (status != QLA_SUCCESS) {
3371 /* Ran out of IDs to use */
3372 break;
3373 }
3374 }
3375
Andrew Vasquezac280b62009-08-20 11:06:05 -07003376 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003377 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003378 data[0] = 0;
3379 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3380 status = qla2x00_post_async_login_work(
3381 vha, fcport, data);
3382 if (status == QLA_SUCCESS)
3383 continue;
3384 /* Attempt a retry. */
3385 status = 1;
3386 } else
3387 status = qla2x00_fabric_login(vha,
3388 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 } else
3390 status = qla2x00_local_device_login(vha,
3391 fcport);
3392
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003393 if (status == QLA_SUCCESS) {
3394 fcport->old_loop_id = fcport->loop_id;
3395
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003396 ql_dbg(ql_dbg_disc, vha, 0x2003,
3397 "Port login OK: logged in ID 0x%x.\n",
3398 fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003399
3400 qla2x00_update_fcport(vha, fcport);
3401
3402 } else if (status == 1) {
3403 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3404 /* retry the login again */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003405 ql_dbg(ql_dbg_disc, vha, 0x2007,
3406 "Retrying %d login again loop_id 0x%x.\n",
3407 fcport->login_retry, fcport->loop_id);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408 } else {
3409 fcport->login_retry = 0;
3410 }
3411
3412 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3413 fcport->loop_id = FC_NO_LOOP_ID;
3414 }
3415 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3416 break;
3417 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003418}
3419
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420/**************************************************************************
3421* qla2x00_do_dpc
3422* This kernel thread is a task that is schedule by the interrupt handler
3423* to perform the background processing for interrupts.
3424*
3425* Notes:
3426* This task always run in the context of a kernel thread. It
3427* is kick-off by the driver's detect code and starts up
3428* up one per adapter. It immediately goes to sleep and waits for
3429* some fibre event. When either the interrupt handler or
3430* the timer routine detects a event it will one of the task
3431* bits then wake us up.
3432**************************************************************************/
3433static int
3434qla2x00_do_dpc(void *data)
3435{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003436 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 scsi_qla_host_t *base_vha;
3438 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08003439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440 ha = (struct qla_hw_data *)data;
3441 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 set_user_nice(current, -20);
3444
James Bottomley563585e2011-01-27 16:12:37 -05003445 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01003446 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003447 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
3448 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
Christoph Hellwig39a11242006-02-14 18:46:22 +01003450 schedule();
3451 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003453 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
3454 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455
Andrew Vasquez85880802009-12-15 21:29:46 -08003456 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003457 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
3458 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003459 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08003460 }
3461
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 ha->dpc_active = 1;
3463
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003464 ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
3465 "DPC handler waking up.\n");
3466 ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
3467 "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003470
Giridhar Malavalia9083012010-04-12 17:59:55 -07003471 if (IS_QLA82XX(ha)) {
3472 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3473 &base_vha->dpc_flags)) {
3474 qla82xx_idc_lock(ha);
3475 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3476 QLA82XX_DEV_FAILED);
3477 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003478 ql_log(ql_log_info, base_vha, 0x4004,
3479 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003480 qla82xx_device_state_handler(base_vha);
3481 continue;
3482 }
3483
3484 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3485 &base_vha->dpc_flags)) {
3486
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003487 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
3488 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003489 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3490 &base_vha->dpc_flags))) {
3491 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3492 /* FCoE-ctx reset failed.
3493 * Escalate to chip-reset
3494 */
3495 set_bit(ISP_ABORT_NEEDED,
3496 &base_vha->dpc_flags);
3497 }
3498 clear_bit(ABORT_ISP_ACTIVE,
3499 &base_vha->dpc_flags);
3500 }
3501
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003502 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
3503 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003504 }
3505 }
3506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003507 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3508 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003510 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
3511 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514
Giridhar Malavalia9083012010-04-12 17:59:55 -07003515 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 /* failed. retry later */
3517 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003518 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 clear_bit(ABORT_ISP_ACTIVE,
3521 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08003522 }
3523
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003524 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
3525 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 }
3527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3529 qla2x00_update_fcports(base_vha);
3530 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003531 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003532
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003533 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003534 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
3535 "Quiescence mode scheduled.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003536 qla82xx_device_state_handler(base_vha);
3537 clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
3538 if (!ha->flags.quiesce_owner) {
3539 qla2x00_perform_loop_resync(base_vha);
3540
3541 qla82xx_idc_lock(ha);
3542 qla82xx_clear_qsnt_ready(base_vha);
3543 qla82xx_idc_unlock(ha);
3544 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003545 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
3546 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003547 }
3548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003549 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3550 &base_vha->dpc_flags) &&
3551 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003553 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
3554 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003555 qla2x00_rst_aen(base_vha);
3556 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003557 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
3558 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 }
3560
3561 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562 if ((test_and_clear_bit(RELOGIN_NEEDED,
3563 &base_vha->dpc_flags)) &&
3564 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3565 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003567 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
3568 "Relogin scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003569 qla2x00_relogin(base_vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003570 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
3571 "Relogin end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 }
3573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3575 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003577 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
3578 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579
3580 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003581 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003583 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003585 clear_bit(LOOP_RESYNC_ACTIVE,
3586 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 }
3588
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003589 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
3590 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 }
3592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3594 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3595 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3596 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07003597 }
3598
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003600 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3603 &base_vha->dpc_flags))
3604 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003605
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003606 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003607
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08003609end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05003610 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05003612 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003614 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
3615 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616
3617 /*
3618 * Make sure that nobody tries to wake us up again.
3619 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 ha->dpc_active = 0;
3621
Andrew Vasquezac280b62009-08-20 11:06:05 -07003622 /* Cleanup any residual CTX SRBs. */
3623 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3624
Christoph Hellwig39a11242006-02-14 18:46:22 +01003625 return 0;
3626}
3627
3628void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003630{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003631 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003632 struct task_struct *t = ha->dpc_thread;
3633
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003634 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003635 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636}
3637
3638/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639* qla2x00_rst_aen
3640* Processes asynchronous reset.
3641*
3642* Input:
3643* ha = adapter block pointer.
3644*/
3645static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003646qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 if (vha->flags.online && !vha->flags.reset_active &&
3649 !atomic_read(&vha->loop_down_timer) &&
3650 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003652 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653
3654 /*
3655 * Issue marker command only when we are going to start
3656 * the I/O.
3657 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003658 vha->marker_needed = 1;
3659 } while (!atomic_read(&vha->loop_down_timer) &&
3660 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 }
3662}
3663
f4f051e2005-04-17 15:02:26 -05003664static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003665qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003666{
3667 struct scsi_cmnd *cmd = sp->cmd;
Arun Easibad75002010-05-04 15:01:30 -07003668 struct qla_hw_data *ha = sp->fcport->vha->hw;
f4f051e2005-04-17 15:02:26 -05003669
3670 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003671 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003672 sp->flags &= ~SRB_DMA_VALID;
3673 }
Arun Easibad75002010-05-04 15:01:30 -07003674
3675 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
3676 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
3677 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
3678 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
3679 }
3680
3681 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
3682 /* List assured to be having elements */
3683 qla2x00_clean_dsd_pool(ha, sp);
3684 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
3685 }
3686
3687 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
3688 dma_pool_free(ha->dl_dma_pool, sp->ctx,
3689 ((struct crc_context *)sp->ctx)->crc_ctx_dma);
3690 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
3691 }
3692
Giridhar Malavalia9083012010-04-12 17:59:55 -07003693 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
3694 struct ct6_dsd *ctx = sp->ctx;
3695 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
3696 ctx->fcp_cmnd_dma);
3697 list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
3698 ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
3699 ha->gbl_dsd_avail += ctx->dsd_use_cnt;
3700 mempool_free(sp->ctx, ha->ctx_mempool);
3701 sp->ctx = NULL;
3702 }
f4f051e2005-04-17 15:02:26 -05003703
Giridhar Malavalic4631192011-11-18 09:03:08 -08003704 CMD_SP(cmd) = NULL;
3705}
3706
3707static void
3708qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
3709{
3710 struct scsi_cmnd *cmd = sp->cmd;
3711
3712 qla2x00_sp_free_dma(sp);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003713 mempool_free(sp, ha->srb_mempool);
f4f051e2005-04-17 15:02:26 -05003714 cmd->scsi_done(cmd);
3715}
bdf79622005-04-17 15:06:53 -05003716
Giridhar Malavali083a4692010-05-28 15:08:18 -07003717void
3718qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3719{
3720 if (atomic_read(&sp->ref_count) == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003721 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
3722 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
3723 sp, sp->cmd);
3724 if (ql2xextended_error_logging & ql_dbg_io)
3725 BUG();
Giridhar Malavali083a4692010-05-28 15:08:18 -07003726 return;
3727 }
3728 if (!atomic_dec_and_test(&sp->ref_count))
3729 return;
3730 qla2x00_sp_final_compl(ha, sp);
3731}
3732
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733/**************************************************************************
3734* qla2x00_timer
3735*
3736* Description:
3737* One second timer
3738*
3739* Context: Interrupt
3740***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003741void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003742qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 int start_dpc = 0;
3746 int index;
3747 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08003748 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003749 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003750 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003751
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003752 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003753 ql_dbg(ql_dbg_timer, vha, 0x6000,
3754 "EEH = %d, restarting timer.\n",
3755 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003756 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3757 return;
3758 }
3759
Andrew Vasquez85880802009-12-15 21:29:46 -08003760 /* Hardware read to raise pending EEH errors during mailbox waits. */
3761 if (!pci_channel_offline(ha->pdev))
3762 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003764 /* Make sure qla82xx_watchdog is run only for physical port */
3765 if (!vha->vp_idx && IS_QLA82XX(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003766 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
3767 start_dpc++;
3768 qla82xx_watchdog(vha);
3769 }
3770
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003772 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003773 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
3774 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003775 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777 if (atomic_read(&vha->loop_down_timer) ==
3778 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003780 ql_log(ql_log_info, vha, 0x6008,
3781 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3784 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003786 /*
3787 * Schedule an ISP abort to return any FCP2-device
3788 * commands.
3789 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003790 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003792 spin_lock_irqsave(&ha->hardware_lock,
3793 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003794 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003795 for (index = 1;
3796 index < MAX_OUTSTANDING_COMMANDS;
3797 index++) {
3798 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003800 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003801 if (!sp)
3802 continue;
Arun Easibad75002010-05-04 15:01:30 -07003803 if (sp->ctx && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003804 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003805 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003806 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003807 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003809 if (IS_QLA82XX(ha))
3810 set_bit(FCOE_CTX_RESET_NEEDED,
3811 &vha->dpc_flags);
3812 else
3813 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003815 break;
3816 }
3817 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 start_dpc++;
3821 }
3822
3823 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003825 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003826 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 "Loop down - aborting ISP.\n");
3828
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07003829 if (IS_QLA82XX(ha))
3830 set_bit(FCOE_CTX_RESET_NEEDED,
3831 &vha->dpc_flags);
3832 else
3833 set_bit(ISP_ABORT_NEEDED,
3834 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 }
3836 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003837 ql_dbg(ql_dbg_timer, vha, 0x600a,
3838 "Loop down - seconds remaining %d.\n",
3839 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 }
3841
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07003842 /* Check if beacon LED needs to be blinked for physical host only */
3843 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07003844 /* There is no beacon_blink function for ISP82xx */
3845 if (!IS_QLA82XX(ha)) {
3846 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3847 start_dpc++;
3848 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003849 }
3850
Andrew Vasquez550bf572008-04-24 15:21:23 -07003851 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003852 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003853 start_dpc++;
3854
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3857 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3858 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003860 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3861 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07003862 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3863 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003864 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003865 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
3866 ql_dbg(ql_dbg_timer, vha, 0x600b,
3867 "isp_abort_needed=%d loop_resync_needed=%d "
3868 "fcport_update_needed=%d start_dpc=%d "
3869 "reset_marker_needed=%d",
3870 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
3871 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
3872 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
3873 start_dpc,
3874 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
3875 ql_dbg(ql_dbg_timer, vha, 0x600c,
3876 "beacon_blink_needed=%d isp_unrecoverable=%d "
3877 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
3878 "relogin_needed=%d.\n",
3879 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
3880 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
3881 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
3882 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
3883 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003884 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003887 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888}
3889
Andrew Vasquez54333832005-11-09 15:49:04 -08003890/* Firmware interface routines. */
3891
Giridhar Malavalia9083012010-04-12 17:59:55 -07003892#define FW_BLOBS 8
Andrew Vasquez54333832005-11-09 15:49:04 -08003893#define FW_ISP21XX 0
3894#define FW_ISP22XX 1
3895#define FW_ISP2300 2
3896#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003897#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003898#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003899#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07003900#define FW_ISP82XX 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003901
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003902#define FW_FILE_ISP21XX "ql2100_fw.bin"
3903#define FW_FILE_ISP22XX "ql2200_fw.bin"
3904#define FW_FILE_ISP2300 "ql2300_fw.bin"
3905#define FW_FILE_ISP2322 "ql2322_fw.bin"
3906#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003907#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003908#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07003909#define FW_FILE_ISP82XX "ql8200_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003910
Daniel Walkere1e82b62008-05-12 22:21:10 -07003911static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003912
3913static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003914 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3915 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3916 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3917 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3918 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003919 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003920 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07003921 { .name = FW_FILE_ISP82XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003922};
3923
3924struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003925qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003926{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003927 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003928 struct fw_blob *blob;
3929
3930 blob = NULL;
3931 if (IS_QLA2100(ha)) {
3932 blob = &qla_fw_blobs[FW_ISP21XX];
3933 } else if (IS_QLA2200(ha)) {
3934 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003935 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003936 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003937 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003938 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003939 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003940 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003941 } else if (IS_QLA25XX(ha)) {
3942 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003943 } else if (IS_QLA81XX(ha)) {
3944 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07003945 } else if (IS_QLA82XX(ha)) {
3946 blob = &qla_fw_blobs[FW_ISP82XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003947 }
3948
Daniel Walkere1e82b62008-05-12 22:21:10 -07003949 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003950 if (blob->fw)
3951 goto out;
3952
3953 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003954 ql_log(ql_log_warn, vha, 0x0063,
3955 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08003956 blob->fw = NULL;
3957 blob = NULL;
3958 goto out;
3959 }
3960
3961out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003962 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003963 return blob;
3964}
3965
3966static void
3967qla2x00_release_firmware(void)
3968{
3969 int idx;
3970
Daniel Walkere1e82b62008-05-12 22:21:10 -07003971 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003972 for (idx = 0; idx < FW_BLOBS; idx++)
3973 if (qla_fw_blobs[idx].fw)
3974 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003975 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003976}
3977
Seokmann Ju14e660e2007-09-20 14:07:36 -07003978static pci_ers_result_t
3979qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3980{
Andrew Vasquez85880802009-12-15 21:29:46 -08003981 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3982 struct qla_hw_data *ha = vha->hw;
3983
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003984 ql_dbg(ql_dbg_aer, vha, 0x9000,
3985 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07003986
Seokmann Ju14e660e2007-09-20 14:07:36 -07003987 switch (state) {
3988 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003989 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003990 return PCI_ERS_RESULT_CAN_RECOVER;
3991 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08003992 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003993 /* For ISP82XX complete any pending mailbox cmd */
3994 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08003995 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08003996 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
3997 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003998 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003999 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004000 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004001 /* Return back all IOs */
4002 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004003 return PCI_ERS_RESULT_NEED_RESET;
4004 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08004005 ha->flags.pci_channel_io_perm_failure = 1;
4006 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004007 return PCI_ERS_RESULT_DISCONNECT;
4008 }
4009 return PCI_ERS_RESULT_NEED_RESET;
4010}
4011
4012static pci_ers_result_t
4013qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4014{
4015 int risc_paused = 0;
4016 uint32_t stat;
4017 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4019 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004020 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4021 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4022
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07004023 if (IS_QLA82XX(ha))
4024 return PCI_ERS_RESULT_RECOVERED;
4025
Seokmann Ju14e660e2007-09-20 14:07:36 -07004026 spin_lock_irqsave(&ha->hardware_lock, flags);
4027 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4028 stat = RD_REG_DWORD(&reg->hccr);
4029 if (stat & HCCR_RISC_PAUSE)
4030 risc_paused = 1;
4031 } else if (IS_QLA23XX(ha)) {
4032 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
4033 if (stat & HSR_RISC_PAUSED)
4034 risc_paused = 1;
4035 } else if (IS_FWI2_CAPABLE(ha)) {
4036 stat = RD_REG_DWORD(&reg24->host_status);
4037 if (stat & HSRX_RISC_PAUSED)
4038 risc_paused = 1;
4039 }
4040 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4041
4042 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004043 ql_log(ql_log_info, base_vha, 0x9003,
4044 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004046
4047 return PCI_ERS_RESULT_NEED_RESET;
4048 } else
4049 return PCI_ERS_RESULT_RECOVERED;
4050}
4051
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004052uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
4053{
4054 uint32_t rval = QLA_FUNCTION_FAILED;
4055 uint32_t drv_active = 0;
4056 struct qla_hw_data *ha = base_vha->hw;
4057 int fn;
4058 struct pci_dev *other_pdev = NULL;
4059
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004060 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
4061 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004062
4063 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4064
4065 if (base_vha->flags.online) {
4066 /* Abort all outstanding commands,
4067 * so as to be requeued later */
4068 qla2x00_abort_isp_cleanup(base_vha);
4069 }
4070
4071
4072 fn = PCI_FUNC(ha->pdev->devfn);
4073 while (fn > 0) {
4074 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004075 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
4076 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004077 other_pdev =
4078 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4079 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4080 fn));
4081
4082 if (!other_pdev)
4083 continue;
4084 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004085 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
4086 "Found PCI func available and enable at 0x%x.\n",
4087 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004088 pci_dev_put(other_pdev);
4089 break;
4090 }
4091 pci_dev_put(other_pdev);
4092 }
4093
4094 if (!fn) {
4095 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004096 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
4097 "This devfn is reset owner = 0x%x.\n",
4098 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004099 qla82xx_idc_lock(ha);
4100
4101 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4102 QLA82XX_DEV_INITIALIZING);
4103
4104 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
4105 QLA82XX_IDC_VERSION);
4106
4107 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004108 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
4109 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004110
4111 qla82xx_idc_unlock(ha);
4112 /* Reset if device is not already reset
4113 * drv_active would be 0 if a reset has already been done
4114 */
4115 if (drv_active)
4116 rval = qla82xx_start_firmware(base_vha);
4117 else
4118 rval = QLA_SUCCESS;
4119 qla82xx_idc_lock(ha);
4120
4121 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004122 ql_log(ql_log_info, base_vha, 0x900b,
4123 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004124 qla82xx_clear_drv_active(ha);
4125 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4126 QLA82XX_DEV_FAILED);
4127 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004128 ql_log(ql_log_info, base_vha, 0x900c,
4129 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004130 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4131 QLA82XX_DEV_READY);
4132 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08004133 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004134 rval = qla82xx_restart_isp(base_vha);
4135 qla82xx_idc_lock(ha);
4136 /* Clear driver state register */
4137 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
4138 qla82xx_set_drv_active(base_vha);
4139 }
4140 qla82xx_idc_unlock(ha);
4141 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004142 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
4143 "This devfn is not reset owner = 0x%x.\n",
4144 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004145 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
4146 QLA82XX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004147 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004148 rval = qla82xx_restart_isp(base_vha);
4149 qla82xx_idc_lock(ha);
4150 qla82xx_set_drv_active(base_vha);
4151 qla82xx_idc_unlock(ha);
4152 }
4153 }
4154 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4155
4156 return rval;
4157}
4158
Seokmann Ju14e660e2007-09-20 14:07:36 -07004159static pci_ers_result_t
4160qla2xxx_pci_slot_reset(struct pci_dev *pdev)
4161{
4162 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4164 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004165 struct rsp_que *rsp;
4166 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004167
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004168 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
4169 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004170
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004171 /* Workaround: qla2xxx driver which access hardware earlier
4172 * needs error state to be pci_channel_io_online.
4173 * Otherwise mailbox command timesout.
4174 */
4175 pdev->error_state = pci_channel_io_normal;
4176
4177 pci_restore_state(pdev);
4178
Richard Lary8c1496b2010-02-18 10:07:29 -08004179 /* pci_restore_state() clears the saved_state flag of the device
4180 * save restored state which resets saved_state flag
4181 */
4182 pci_save_state(pdev);
4183
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11004184 if (ha->mem_only)
4185 rc = pci_enable_device_mem(pdev);
4186 else
4187 rc = pci_enable_device(pdev);
4188
4189 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004190 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004191 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004192 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004193 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004194
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004195 rsp = ha->rsp_q_map[0];
4196 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004197 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004198
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004199 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004200 goto exit_slot_reset;
4201
4202 if (IS_QLA82XX(ha)) {
4203 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
4204 ret = PCI_ERS_RESULT_RECOVERED;
4205 goto exit_slot_reset;
4206 } else
4207 goto exit_slot_reset;
4208 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07004209
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004210 while (ha->flags.mbox_busy && retries--)
4211 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08004212
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004213 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004214 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07004215 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004217
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08004218
Lalit Chandivadea5b36322010-09-03 15:20:50 -07004219exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004220 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
4221 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08004222
Seokmann Ju14e660e2007-09-20 14:07:36 -07004223 return ret;
4224}
4225
4226static void
4227qla2xxx_pci_resume(struct pci_dev *pdev)
4228{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004229 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4230 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004231 int ret;
4232
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004233 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
4234 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08004235
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004236 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004237 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004238 ql_log(ql_log_fatal, base_vha, 0x9002,
4239 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07004240 }
Andrew Vasquez85880802009-12-15 21:29:46 -08004241
Lalit Chandivade3e46f032010-05-04 15:01:23 -07004242 pci_cleanup_aer_uncorrect_error_status(pdev);
4243
Andrew Vasquez85880802009-12-15 21:29:46 -08004244 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004245}
4246
4247static struct pci_error_handlers qla2xxx_err_handler = {
4248 .error_detected = qla2xxx_pci_error_detected,
4249 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4250 .slot_reset = qla2xxx_pci_slot_reset,
4251 .resume = qla2xxx_pci_resume,
4252};
4253
Andrew Vasquez54333832005-11-09 15:49:04 -08004254static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004255 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4256 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4257 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4258 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4259 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4260 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4261 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4262 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4263 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004264 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004265 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4266 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004267 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004268 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004269 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Andrew Vasquez54333832005-11-09 15:49:04 -08004270 { 0 },
4271};
4272MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4273
Andrew Vasquezfca29702005-07-06 10:31:47 -07004274static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07004275 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06004276 .driver = {
4277 .owner = THIS_MODULE,
4278 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07004279 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004280 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08004281 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004282 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004283 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07004284};
4285
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004286static struct file_operations apidev_fops = {
4287 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02004288 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004289};
4290
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291/**
4292 * qla2x00_module_init - Module initialization.
4293 **/
4294static int __init
4295qla2x00_module_init(void)
4296{
Andrew Vasquezfca29702005-07-06 10:31:47 -07004297 int ret = 0;
4298
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004300 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09004301 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004303 ql_log(ql_log_fatal, NULL, 0x0001,
4304 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 return -ENOMEM;
4306 }
4307
4308 /* Derive version string. */
4309 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07004310 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07004311 strcat(qla2x00_version_str, "-debug");
4312
Andrew Vasquez1c97a122005-04-21 16:13:36 -04004313 qla2xxx_transport_template =
4314 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004315 if (!qla2xxx_transport_template) {
4316 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004317 ql_log(ql_log_fatal, NULL, 0x0002,
4318 "fc_attach_transport failed...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004320 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004321
4322 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4323 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004324 ql_log(ql_log_fatal, NULL, 0x0003,
4325 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004326 }
4327
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004328 qla2xxx_transport_vport_template =
4329 fc_attach_transport(&qla2xxx_transport_vport_functions);
4330 if (!qla2xxx_transport_vport_template) {
4331 kmem_cache_destroy(srb_cachep);
4332 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004333 ql_log(ql_log_fatal, NULL, 0x0004,
4334 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004335 return -ENODEV;
4336 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004337 ql_log(ql_log_info, NULL, 0x0005,
4338 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07004339 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004340 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004341 if (ret) {
4342 kmem_cache_destroy(srb_cachep);
4343 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004344 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004345 ql_log(ql_log_fatal, NULL, 0x0006,
4346 "pci_register_driver failed...ret=%d Failing load!.\n",
4347 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004348 }
4349 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350}
4351
4352/**
4353 * qla2x00_module_exit - Module cleanup.
4354 **/
4355static void __exit
4356qla2x00_module_exit(void)
4357{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004358 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004359 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08004360 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004361 kmem_cache_destroy(srb_cachep);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004362 if (ctx_cachep)
4363 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004365 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366}
4367
4368module_init(qla2x00_module_init);
4369module_exit(qla2x00_module_exit);
4370
4371MODULE_AUTHOR("QLogic Corporation");
4372MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4373MODULE_LICENSE("GPL");
4374MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004375MODULE_FIRMWARE(FW_FILE_ISP21XX);
4376MODULE_FIRMWARE(FW_FILE_ISP22XX);
4377MODULE_FIRMWARE(FW_FILE_ISP2300);
4378MODULE_FIRMWARE(FW_FILE_ISP2322);
4379MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08004380MODULE_FIRMWARE(FW_FILE_ISP25XX);