blob: a1aef661108b93afc70b1d6a3153d664d61d856d [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 Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <scsi/scsi_tcq.h>
17#include <scsi/scsicam.h>
18#include <scsi/scsi_transport.h>
19#include <scsi/scsi_transport_fc.h>
20
21/*
22 * Driver version
23 */
24char qla2x00_version_str[40];
25
26/*
27 * SRB allocation cache
28 */
Christoph Lametere18b8902006-12-06 20:33:20 -080029static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031int ql2xlogintimeout = 20;
32module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
33MODULE_PARM_DESC(ql2xlogintimeout,
34 "Login timeout value in seconds.");
35
Andrew Vasqueza7b61842007-05-07 07:42:59 -070036int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
38MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070039 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 "a PORT-DOWN status.");
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042int ql2xplogiabsentdevice;
43module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
44MODULE_PARM_DESC(ql2xplogiabsentdevice,
45 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070046 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049int ql2xloginretrycount = 0;
50module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
51MODULE_PARM_DESC(ql2xloginretrycount,
52 "Specify an alternate value for the NVRAM login retry count.");
53
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070054int ql2xallocfwdump = 1;
55module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
56MODULE_PARM_DESC(ql2xallocfwdump,
57 "Option to enable allocation of memory for a firmware dump "
58 "during HBA initialization. Memory allocation requirements "
59 "vary by ISP type. Default is 1 - allocate memory.");
60
Andrew Vasquez11010fe2006-10-06 09:54:59 -070061int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070062module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070063MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070064 "Option to enable extended error logging, "
65 "Default is 0 - no logging. 1 - log errors.");
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static void qla2x00_free_device(scsi_qla_host_t *);
68
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070069int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070070module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
71MODULE_PARM_DESC(ql2xfdmienable,
72 "Enables FDMI registratons "
73 "Default is 0 - no FDMI. 1 - perfom FDMI.");
74
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070075#define MAX_Q_DEPTH 32
76static int ql2xmaxqdepth = MAX_Q_DEPTH;
77module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
78MODULE_PARM_DESC(ql2xmaxqdepth,
79 "Maximum queue depth to report for target devices.");
80
Andrew Vasqueze5896bd2008-07-10 16:55:52 -070081int ql2xiidmaenable=1;
82module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
83MODULE_PARM_DESC(ql2xiidmaenable,
84 "Enables iIDMA settings "
85 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
86
Anirban Chakraborty73208df2008-12-09 16:45:39 -080087int ql2xmaxqueues = 1;
88module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
89MODULE_PARM_DESC(ql2xmaxqueues,
90 "Enables MQ settings "
91 "Default is 1 for single queue. Set it to number \
92 of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -070093
94int ql2xmultique_tag;
95module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
96MODULE_PARM_DESC(ql2xmultique_tag,
97 "Enables CPU affinity settings for the driver "
98 "Default is 0 for no affinity of request and response IO. "
99 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700100
101int ql2xfwloadbin;
102module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
103MODULE_PARM_DESC(ql2xfwloadbin,
104 "Option to specify location from which to load ISP firmware:\n"
105 " 2 -- load firmware via the request_firmware() (hotplug)\n"
106 " interface.\n"
107 " 1 -- load firmware from flash.\n"
108 " 0 -- use default semantics.\n");
109
Andrew Vasquezae97c912010-02-18 10:07:28 -0800110int ql2xetsenable;
111module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
112MODULE_PARM_DESC(ql2xetsenable,
113 "Enables firmware ETS burst."
114 "Default is 0 - skip ETS enablement.");
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700117 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 */
119static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500120static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800121static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
122static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500123static void qla2xxx_slave_destroy(struct scsi_device *);
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700124static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700125 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static int qla2xxx_eh_abort(struct scsi_cmnd *);
127static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700128static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
130static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Mike Christiee881a172009-10-15 17:46:39 -0700132static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700133static int qla2x00_change_queue_type(struct scsi_device *, int);
134
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700135struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700137 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700138 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700139
140 .eh_abort_handler = qla2xxx_eh_abort,
141 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700142 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700143 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
144 .eh_host_reset_handler = qla2xxx_eh_host_reset,
145
146 .slave_configure = qla2xxx_slave_configure,
147
148 .slave_alloc = qla2xxx_slave_alloc,
149 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700150 .scan_finished = qla2xxx_scan_finished,
151 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700152 .change_queue_depth = qla2x00_change_queue_depth,
153 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700154 .this_id = -1,
155 .cmd_per_lun = 3,
156 .use_clustering = ENABLE_CLUSTERING,
157 .sg_tablesize = SG_ALL,
158
159 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700160 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700161};
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700164struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* TODO Convert to inlines
167 *
168 * Timer routines
169 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700171__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800172qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800174 init_timer(&vha->timer);
175 vha->timer.expires = jiffies + interval * HZ;
176 vha->timer.data = (unsigned long)vha;
177 vha->timer.function = (void (*)(unsigned long))func;
178 add_timer(&vha->timer);
179 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
182static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800183qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800185 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Adrian Bunka824ebb2008-01-17 09:02:15 -0800188static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800189qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800191 del_timer_sync(&vha->timer);
192 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195static int qla2x00_do_dpc(void *data);
196
197static void qla2x00_rst_aen(scsi_qla_host_t *);
198
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800199static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
200 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800201static void qla2x00_mem_free(struct qla_hw_data *);
202static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800205static int qla2x00_alloc_queues(struct qla_hw_data *ha)
206{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700207 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800208 GFP_KERNEL);
209 if (!ha->req_q_map) {
210 qla_printk(KERN_WARNING, ha,
211 "Unable to allocate memory for request queue ptrs\n");
212 goto fail_req_map;
213 }
214
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700215 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800216 GFP_KERNEL);
217 if (!ha->rsp_q_map) {
218 qla_printk(KERN_WARNING, ha,
219 "Unable to allocate memory for response queue ptrs\n");
220 goto fail_rsp_map;
221 }
222 set_bit(0, ha->rsp_qid_map);
223 set_bit(0, ha->req_qid_map);
224 return 1;
225
226fail_rsp_map:
227 kfree(ha->req_q_map);
228 ha->req_q_map = NULL;
229fail_req_map:
230 return -ENOMEM;
231}
232
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700233static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800234{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800235 if (req && req->ring)
236 dma_free_coherent(&ha->pdev->dev,
237 (req->length + 1) * sizeof(request_t),
238 req->ring, req->dma);
239
240 kfree(req);
241 req = NULL;
242}
243
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700244static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
245{
246 if (rsp && rsp->ring)
247 dma_free_coherent(&ha->pdev->dev,
248 (rsp->length + 1) * sizeof(response_t),
249 rsp->ring, rsp->dma);
250
251 kfree(rsp);
252 rsp = NULL;
253}
254
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800255static void qla2x00_free_queues(struct qla_hw_data *ha)
256{
257 struct req_que *req;
258 struct rsp_que *rsp;
259 int cnt;
260
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700261 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800262 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700263 qla2x00_free_req_que(ha, req);
264 }
265 kfree(ha->req_q_map);
266 ha->req_q_map = NULL;
267
268 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
269 rsp = ha->rsp_q_map[cnt];
270 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800271 }
272 kfree(ha->rsp_q_map);
273 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800274}
275
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700276static int qla25xx_setup_mode(struct scsi_qla_host *vha)
277{
278 uint16_t options = 0;
279 int ques, req, ret;
280 struct qla_hw_data *ha = vha->hw;
281
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700282 if (!(ha->fw_attributes & BIT_6)) {
283 qla_printk(KERN_INFO, ha,
284 "Firmware is not multi-queue capable\n");
285 goto fail;
286 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700287 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700288 /* create a request queue for IO */
289 options |= BIT_7;
290 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
291 QLA_DEFAULT_QUE_QOS);
292 if (!req) {
293 qla_printk(KERN_WARNING, ha,
294 "Can't create request queue\n");
295 goto fail;
296 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700297 ha->wq = create_workqueue("qla2xxx_wq");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700298 vha->req = ha->req_q_map[req];
299 options |= BIT_1;
300 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
301 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
302 if (!ret) {
303 qla_printk(KERN_WARNING, ha,
304 "Response Queue create failed\n");
305 goto fail2;
306 }
307 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700308 ha->flags.cpu_affinity_enabled = 1;
309
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700310 DEBUG2(qla_printk(KERN_INFO, ha,
311 "CPU affinity mode enabled, no. of response"
312 " queues:%d, no. of request queues:%d\n",
313 ha->max_rsp_queues, ha->max_req_queues));
314 }
315 return 0;
316fail2:
317 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700318 destroy_workqueue(ha->wq);
319 ha->wq = NULL;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700320fail:
321 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700322 kfree(ha->req_q_map);
323 kfree(ha->rsp_q_map);
324 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700325 return 1;
326}
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800329qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800331 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 static char *pci_bus_modes[] = {
333 "33", "66", "100", "133",
334 };
335 uint16_t pci_bus;
336
337 strcpy(str, "PCI");
338 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
339 if (pci_bus) {
340 strcat(str, "-X (");
341 strcat(str, pci_bus_modes[pci_bus]);
342 } else {
343 pci_bus = (ha->pci_attr & BIT_8) >> 8;
344 strcat(str, " (");
345 strcat(str, pci_bus_modes[pci_bus]);
346 }
347 strcat(str, " MHz)");
348
349 return (str);
350}
351
Andrew Vasquezfca29702005-07-06 10:31:47 -0700352static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700354{
355 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800356 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700357 uint32_t pci_bus;
358 int pcie_reg;
359
360 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
361 if (pcie_reg) {
362 char lwstr[6];
363 uint16_t pcie_lstat, lspeed, lwidth;
364
365 pcie_reg += 0x12;
366 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
367 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
368 lwidth = (pcie_lstat &
369 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
370
371 strcpy(str, "PCIe (");
372 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700373 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700374 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700375 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700376 else
377 strcat(str, "<unknown> ");
378 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
379 strcat(str, lwstr);
380
381 return str;
382 }
383
384 strcpy(str, "PCI");
385 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
386 if (pci_bus == 0 || pci_bus == 8) {
387 strcat(str, " (");
388 strcat(str, pci_bus_modes[pci_bus >> 3]);
389 } else {
390 strcat(str, "-X ");
391 if (pci_bus & BIT_2)
392 strcat(str, "Mode 2");
393 else
394 strcat(str, "Mode 1");
395 strcat(str, " (");
396 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
397 }
398 strcat(str, " MHz)");
399
400 return str;
401}
402
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800403static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800404qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
406 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800407 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
410 ha->fw_minor_version,
411 ha->fw_subminor_version);
412
413 if (ha->fw_attributes & BIT_9) {
414 strcat(str, "FLX");
415 return (str);
416 }
417
418 switch (ha->fw_attributes & 0xFF) {
419 case 0x7:
420 strcat(str, "EF");
421 break;
422 case 0x17:
423 strcat(str, "TP");
424 break;
425 case 0x37:
426 strcat(str, "IP");
427 break;
428 case 0x77:
429 strcat(str, "VI");
430 break;
431 default:
432 sprintf(un_str, "(%x)", ha->fw_attributes);
433 strcat(str, un_str);
434 break;
435 }
436 if (ha->fw_attributes & 0x100)
437 strcat(str, "X");
438
439 return (str);
440}
441
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800442static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700444{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800445 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700446
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800447 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
448 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700449 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700450}
451
452static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800453qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700454 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
455{
456 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800457 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700458
459 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
460 if (!sp)
461 return sp;
462
Andrew Vasquezfca29702005-07-06 10:31:47 -0700463 sp->fcport = fcport;
464 sp->cmd = cmd;
465 sp->flags = 0;
466 CMD_SP(cmd) = (void *)sp;
467 cmd->scsi_done = done;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700468 sp->ctx = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700469
470 return sp;
471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700474qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700475{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800476 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700477 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400478 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479 struct qla_hw_data *ha = vha->hw;
480 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700481 srb_t *sp;
482 int rval;
483
Andrew Vasquez85880802009-12-15 21:29:46 -0800484 if (ha->flags.eeh_busy) {
485 if (ha->flags.pci_channel_io_perm_failure)
Seokmann Jub9b12f72009-03-24 09:08:18 -0700486 cmd->result = DID_NO_CONNECT << 16;
Andrew Vasquez85880802009-12-15 21:29:46 -0800487 else
488 cmd->result = DID_REQUEUE << 16;
Seokmann Ju14e660e2007-09-20 14:07:36 -0700489 goto qc24_fail_command;
490 }
491
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400492 rval = fc_remote_port_chkready(rport);
493 if (rval) {
494 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700495 goto qc24_fail_command;
496 }
497
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800498 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500499 if (fcport->drport)
500 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800501
Andrew Vasquezfca29702005-07-06 10:31:47 -0700502 if (atomic_read(&fcport->state) != FCS_ONLINE) {
503 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700505 cmd->result = DID_NO_CONNECT << 16;
506 goto qc24_fail_command;
507 }
Mike Christie7b594132008-08-17 15:24:40 -0500508 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700509 }
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700514 if (!sp)
515 goto qc24_host_busy_lock;
516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700518 if (rval != QLA_SUCCESS)
519 goto qc24_host_busy_free_sp;
520
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522
523 return 0;
524
525qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 qla2x00_sp_free_dma(sp);
527 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700528
529qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700531 return SCSI_MLQUEUE_HOST_BUSY;
532
Mike Christie7b594132008-08-17 15:24:40 -0500533qc24_target_busy:
534 return SCSI_MLQUEUE_TARGET_BUSY;
535
Andrew Vasquezfca29702005-07-06 10:31:47 -0700536qc24_fail_command:
537 done(cmd);
538
539 return 0;
540}
541
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543/*
544 * qla2x00_eh_wait_on_command
545 * Waits for the command to be returned by the Firmware for some
546 * max time.
547 *
548 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 *
551 * Return:
552 * Not Found : 0
553 * Found : 1
554 */
555static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700558#define ABORT_POLLING_PERIOD 1000
559#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500560 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800561 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
562 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500563 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Andrew Vasquez85880802009-12-15 21:29:46 -0800565 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
566 DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
567 return ret;
568 }
569
Lalit Chandivaded9704322009-08-25 11:36:18 -0700570 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700571 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500572 }
573 if (CMD_SP(cmd))
574 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
f4f051e2005-04-17 15:02:26 -0500576 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579/*
580 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700581 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 * <= MAX_RETRIES_OF_ISP_ABORT or
583 * finally HBA is disabled ie marked offline
584 *
585 * Input:
586 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700587 *
588 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 * Does context switching-Release SPIN_LOCK
590 * (if any) before calling this routine.
591 *
592 * Return:
593 * Success (Adapter is online) : 0
594 * Failed (Adapter is offline/disabled) : 1
595 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800596int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700599 int return_status;
600 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601 struct qla_hw_data *ha = vha->hw;
602 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700604 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800605 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
606 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
607 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
608 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 msleep(1000);
611 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800612 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700613 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 else
615 return_status = QLA_FUNCTION_FAILED;
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 return (return_status);
618}
619
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700620int
621qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
622{
623 int return_status;
624 unsigned long wait_reset;
625 struct qla_hw_data *ha = vha->hw;
626 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
627
628 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
629 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
630 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
631 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
632 ha->dpc_active) && time_before(jiffies, wait_reset)) {
633
634 msleep(1000);
635
636 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
637 ha->flags.chip_reset_done)
638 break;
639 }
640 if (ha->flags.chip_reset_done)
641 return_status = QLA_SUCCESS;
642 else
643 return_status = QLA_FUNCTION_FAILED;
644
645 return return_status;
646}
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648/*
649 * qla2x00_wait_for_loop_ready
650 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700651 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 * Input:
653 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700654 *
655 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 * Does context switching-Release SPIN_LOCK
657 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700658 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 *
660 * Return:
661 * Success (LOOP_READY) : 0
662 * Failed (LOOP_NOT_READY) : 1
663 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700664static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
667 int return_status = QLA_SUCCESS;
668 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800669 struct qla_hw_data *ha = vha->hw;
670 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700673 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800675 while ((!atomic_read(&base_vha->loop_down_timer) &&
676 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
677 atomic_read(&base_vha->loop_state) != LOOP_READY) {
678 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700679 return_status = QLA_FUNCTION_FAILED;
680 break;
681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 msleep(1000);
683 if (time_after_eq(jiffies, loop_timeout)) {
684 return_status = QLA_FUNCTION_FAILED;
685 break;
686 }
687 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700688 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691/**************************************************************************
692* qla2xxx_eh_abort
693*
694* Description:
695* The abort function will abort the specified command.
696*
697* Input:
698* cmd = Linux SCSI command packet to be aborted.
699*
700* Returns:
701* Either SUCCESS or FAILED.
702*
703* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700704* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800706static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707qla2xxx_eh_abort(struct scsi_cmnd *cmd)
708{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800709 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500710 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800711 int ret, i;
f4f051e2005-04-17 15:02:26 -0500712 unsigned int id, lun;
713 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700714 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700715 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800716 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700717 struct req_que *req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800718 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Christof Schmitt65d430f2009-10-30 17:59:29 +0100720 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -0700721
f4f051e2005-04-17 15:02:26 -0500722 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700723 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Michael Reed2ea00202006-04-27 16:25:30 -0700725 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
f4f051e2005-04-17 15:02:26 -0500727 id = cmd->device->id;
728 lun = cmd->device->lun;
729 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800730 spt = (srb_t *) CMD_SP(cmd);
731 if (!spt)
732 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500733
734 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800735 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800736 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
737 sp = req->outstanding_cmds[i];
738
739 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500740 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700741 if (sp->ctx)
742 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800743 if (sp->cmd != cmd)
744 continue;
f4f051e2005-04-17 15:02:26 -0500745
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800746 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
747 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500748
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800749 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700750 if (ha->isp_ops->abort_command(sp)) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800751 DEBUG2(printk("%s(%ld): abort_command "
752 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800753 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800754 } else {
755 DEBUG3(printk("%s(%ld): abort_command "
756 "mbx success.\n", __func__, vha->host_no));
757 wait = 1;
f4f051e2005-04-17 15:02:26 -0500758 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800759 spin_lock_irqsave(&ha->hardware_lock, flags);
760 break;
f4f051e2005-04-17 15:02:26 -0500761 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800762 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500763
764 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700765 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800766 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700767 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500768 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800769 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700770 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700774 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700775 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800776 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
f4f051e2005-04-17 15:02:26 -0500778 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
Andrew Vasquez523ec772008-04-03 13:13:24 -0700781enum nexus_wait_type {
782 WAIT_HOST = 0,
783 WAIT_TARGET,
784 WAIT_LUN,
785};
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800788qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800789 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800791 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700792 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800793 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800794 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Andrew Vasquez523ec772008-04-03 13:13:24 -0700796 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800797 if (!sp)
798 return status;
799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800800 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700801 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800802 for (cnt = 1; status == QLA_SUCCESS &&
803 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
804 sp = req->outstanding_cmds[cnt];
805 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700806 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700807 if (sp->ctx)
808 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800809 if (vha->vp_idx != sp->fcport->vha->vp_idx)
810 continue;
811 match = 0;
812 switch (type) {
813 case WAIT_HOST:
814 match = 1;
815 break;
816 case WAIT_TARGET:
817 match = sp->cmd->device->id == t;
818 break;
819 case WAIT_LUN:
820 match = (sp->cmd->device->id == t &&
821 sp->cmd->device->lun == l);
822 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800824 if (!match)
825 continue;
826
827 spin_unlock_irqrestore(&ha->hardware_lock, flags);
828 status = qla2x00_eh_wait_on_command(sp->cmd);
829 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700832
833 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
Andrew Vasquez523ec772008-04-03 13:13:24 -0700836static char *reset_errors[] = {
837 "HBA not online",
838 "HBA not ready",
839 "Task management failed",
840 "Waiting for command completions",
841};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Andrew Vasquez523ec772008-04-03 13:13:24 -0700843static int
844__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700845 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700846{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800847 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700848 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
849 int err;
850
Christof Schmitt65d430f2009-10-30 17:59:29 +0100851 fc_block_scsi_eh(cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700852
853 if (!fcport)
854 return FAILED;
855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800856 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
857 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700858
859 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700861 goto eh_reset_failed;
862 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800863 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700864 goto eh_reset_failed;
865 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700866 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
867 != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700868 goto eh_reset_failed;
869 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800870 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800871 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700872 goto eh_reset_failed;
873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800874 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
875 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700876
877 return SUCCESS;
878
879 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800880 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
881 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700882 reset_errors[err]);
883 return FAILED;
884}
885
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800886static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
888{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800889 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
890 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Andrew Vasquez523ec772008-04-03 13:13:24 -0700892 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
893 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700897qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
900 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Andrew Vasquez523ec772008-04-03 13:13:24 -0700902 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
903 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906/**************************************************************************
907* qla2xxx_eh_bus_reset
908*
909* Description:
910* The bus reset function will reset the bus and abort any executing
911* commands.
912*
913* Input:
914* cmd = Linux SCSI command packet of the command that cause the
915* bus reset.
916*
917* Returns:
918* SUCCESS/FAILURE (defined as macro in scsi.h).
919*
920**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800921static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
923{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800924 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500925 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700926 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500927 unsigned int id, lun;
928 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800929 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Christof Schmitt65d430f2009-10-30 17:59:29 +0100931 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -0700932
f4f051e2005-04-17 15:02:26 -0500933 id = cmd->device->id;
934 lun = cmd->device->lun;
935 serial = cmd->serial_number;
936
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700937 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500938 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800941 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500945 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 }
947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800948 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
949 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500950 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 }
f4f051e2005-04-17 15:02:26 -0500952 if (ret == FAILED)
953 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700955 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800956 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -0700957 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700958 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
f4f051e2005-04-17 15:02:26 -0500960eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800961 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500962 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
f4f051e2005-04-17 15:02:26 -0500964 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
967/**************************************************************************
968* qla2xxx_eh_host_reset
969*
970* Description:
971* The reset function will reset the Adapter.
972*
973* Input:
974* cmd = Linux SCSI command packet of the command that cause the
975* adapter reset.
976*
977* Returns:
978* Either SUCCESS or FAILED.
979*
980* Note:
981**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800982static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
984{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500986 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800987 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700988 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500989 unsigned int id, lun;
990 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800991 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800992 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Christof Schmitt65d430f2009-10-30 17:59:29 +0100994 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -0700995
f4f051e2005-04-17 15:02:26 -0500996 id = cmd->device->id;
997 lun = cmd->device->lun;
998 serial = cmd->serial_number;
999
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001000 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001001 return ret;
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001004 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001006 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001007 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 /*
1010 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001011 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 * be completed and then issue big hammer.Otherwise
1013 * it may cause I/O failure as big hammer marks the
1014 * devices as lost kicking of the port_down_timer
1015 * while dpc is stuck for the mailbox to complete.
1016 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001017 qla2x00_wait_for_loop_ready(vha);
1018 if (vha != base_vha) {
1019 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001020 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001021 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001022 if (ha->wq)
1023 flush_workqueue(ha->wq);
1024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001025 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1026 if (qla2x00_abort_isp(base_vha)) {
1027 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1028 /* failed. schedule dpc to try */
1029 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1030
1031 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1032 goto eh_host_reset_lock;
1033 }
1034 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001038 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001039 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001040 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
f4f051e2005-04-17 15:02:26 -05001042eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001043 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1044 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
f4f051e2005-04-17 15:02:26 -05001046 return ret;
1047}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049/*
1050* qla2x00_loop_reset
1051* Issue loop reset.
1052*
1053* Input:
1054* ha = adapter block pointer.
1055*
1056* Returns:
1057* 0 = success
1058*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001059int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001062 int ret;
bdf79622005-04-17 15:06:53 -05001063 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001064 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001066 if (ha->flags.enable_target_reset) {
1067 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1068 if (fcport->port_type != FCT_TARGET)
1069 continue;
1070
1071 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1072 if (ret != QLA_SUCCESS) {
1073 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1074 "target_reset=%d d_id=%x.\n", __func__,
1075 vha->host_no, ret, fcport->d_id.b24));
1076 }
1077 }
1078 }
1079
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001080 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001081 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001082 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001083 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001084 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001085 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001086 }
1087 atomic_set(&vha->loop_state, LOOP_DOWN);
1088 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1089 qla2x00_mark_all_devices_lost(vha, 0);
1090 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001093 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001094 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001095 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001096 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001097 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1098 } else
1099 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001100 }
1101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001103 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001105 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001108void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001110{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001111 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001112 unsigned long flags;
1113 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001114 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001116 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001117
1118 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001119 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001120 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001121 if (!req)
1122 continue;
1123 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1124 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001125 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001126 req->outstanding_cmds[cnt] = NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001127 if (!sp->ctx) {
1128 sp->cmd->result = res;
1129 qla2x00_sp_compl(ha, sp);
1130 } else {
1131 ctx = sp->ctx;
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001132 if (ctx->type == SRB_LOGIN_CMD || ctx->type == SRB_LOGOUT_CMD) {
1133 del_timer_sync(&ctx->timer);
1134 ctx->free(sp);
1135 } else {
1136 struct srb_bsg* sp_bsg = (struct srb_bsg*)sp->ctx;
1137 if (sp_bsg->bsg_job->request->msgcode == FC_BSG_HST_CT)
1138 kfree(sp->fcport);
1139 sp_bsg->bsg_job->req->errors = 0;
1140 sp_bsg->bsg_job->reply->result = res;
1141 sp_bsg->bsg_job->job_done(sp_bsg->bsg_job);
1142 kfree(sp->ctx);
1143 mempool_free(sp, ha->srb_mempool);
1144 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001145 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001146 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001147 }
1148 }
1149 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1150}
1151
f4f051e2005-04-17 15:02:26 -05001152static int
1153qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
bdf79622005-04-17 15:06:53 -05001155 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001157 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001158 return -ENXIO;
1159
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001160 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001161
1162 return 0;
1163}
1164
1165static int
1166qla2xxx_slave_configure(struct scsi_device *sdev)
1167{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 scsi_qla_host_t *vha = shost_priv(sdev->host);
1169 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001170 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001171 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001172
f4f051e2005-04-17 15:02:26 -05001173 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001174 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001176 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Andrew Vasquez85821c92008-07-10 16:55:48 -07001178 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001179
f4f051e2005-04-17 15:02:26 -05001180 return 0;
1181}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
f4f051e2005-04-17 15:02:26 -05001183static void
1184qla2xxx_slave_destroy(struct scsi_device *sdev)
1185{
1186 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001189static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1190{
1191 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1192
1193 if (!scsi_track_queue_full(sdev, qdepth))
1194 return;
1195
1196 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1197 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1198 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1199 sdev->queue_depth));
1200}
1201
1202static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1203{
1204 fc_port_t *fcport = sdev->hostdata;
1205 struct scsi_qla_host *vha = fcport->vha;
1206 struct qla_hw_data *ha = vha->hw;
1207 struct req_que *req = NULL;
1208
1209 req = vha->req;
1210 if (!req)
1211 return;
1212
1213 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1214 return;
1215
1216 if (sdev->ordered_tags)
1217 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1218 else
1219 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1220
1221 DEBUG2(qla_printk(KERN_INFO, ha,
1222 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1223 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1224 sdev->queue_depth));
1225}
1226
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001227static int
Mike Christiee881a172009-10-15 17:46:39 -07001228qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001229{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001230 switch (reason) {
1231 case SCSI_QDEPTH_DEFAULT:
1232 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1233 break;
1234 case SCSI_QDEPTH_QFULL:
1235 qla2x00_handle_queue_full(sdev, qdepth);
1236 break;
1237 case SCSI_QDEPTH_RAMP_UP:
1238 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1239 break;
1240 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001241 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001242 }
Mike Christiee881a172009-10-15 17:46:39 -07001243
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001244 return sdev->queue_depth;
1245}
1246
1247static int
1248qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1249{
1250 if (sdev->tagged_supported) {
1251 scsi_set_tag_type(sdev, tag_type);
1252 if (tag_type)
1253 scsi_activate_tcq(sdev, sdev->queue_depth);
1254 else
1255 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1256 } else
1257 tag_type = 0;
1258
1259 return tag_type;
1260}
1261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262/**
1263 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1264 * @ha: HA context
1265 *
1266 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1267 * supported addressing method.
1268 */
1269static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001270qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001272 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Yang Hongyang6a355282009-04-06 19:01:13 -07001275 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001276 /* Any upper-dword bits set? */
1277 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001278 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001279 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001281 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1282 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001283 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001286
Yang Hongyang284901a2009-04-06 19:01:15 -07001287 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1288 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001291static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001292qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001293{
1294 unsigned long flags = 0;
1295 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1296
1297 spin_lock_irqsave(&ha->hardware_lock, flags);
1298 ha->interrupts_on = 1;
1299 /* enable risc and host interrupts */
1300 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1301 RD_REG_WORD(&reg->ictrl);
1302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1303
1304}
1305
1306static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001308{
1309 unsigned long flags = 0;
1310 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1311
1312 spin_lock_irqsave(&ha->hardware_lock, flags);
1313 ha->interrupts_on = 0;
1314 /* disable risc and host interrupts */
1315 WRT_REG_WORD(&reg->ictrl, 0);
1316 RD_REG_WORD(&reg->ictrl);
1317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1318}
1319
1320static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001321qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001322{
1323 unsigned long flags = 0;
1324 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1325
1326 spin_lock_irqsave(&ha->hardware_lock, flags);
1327 ha->interrupts_on = 1;
1328 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1329 RD_REG_DWORD(&reg->ictrl);
1330 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1331}
1332
1333static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001334qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001335{
1336 unsigned long flags = 0;
1337 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1338
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001339 if (IS_NOPOLLING_TYPE(ha))
1340 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001341 spin_lock_irqsave(&ha->hardware_lock, flags);
1342 ha->interrupts_on = 0;
1343 WRT_REG_DWORD(&reg->ictrl, 0);
1344 RD_REG_DWORD(&reg->ictrl);
1345 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1346}
1347
1348static struct isp_operations qla2100_isp_ops = {
1349 .pci_config = qla2100_pci_config,
1350 .reset_chip = qla2x00_reset_chip,
1351 .chip_diag = qla2x00_chip_diag,
1352 .config_rings = qla2x00_config_rings,
1353 .reset_adapter = qla2x00_reset_adapter,
1354 .nvram_config = qla2x00_nvram_config,
1355 .update_fw_options = qla2x00_update_fw_options,
1356 .load_risc = qla2x00_load_risc,
1357 .pci_info_str = qla2x00_pci_info_str,
1358 .fw_version_str = qla2x00_fw_version_str,
1359 .intr_handler = qla2100_intr_handler,
1360 .enable_intrs = qla2x00_enable_intrs,
1361 .disable_intrs = qla2x00_disable_intrs,
1362 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001363 .target_reset = qla2x00_abort_target,
1364 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001365 .fabric_login = qla2x00_login_fabric,
1366 .fabric_logout = qla2x00_fabric_logout,
1367 .calc_req_entries = qla2x00_calc_iocbs_32,
1368 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1369 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1370 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1371 .read_nvram = qla2x00_read_nvram_data,
1372 .write_nvram = qla2x00_write_nvram_data,
1373 .fw_dump = qla2100_fw_dump,
1374 .beacon_on = NULL,
1375 .beacon_off = NULL,
1376 .beacon_blink = NULL,
1377 .read_optrom = qla2x00_read_optrom_data,
1378 .write_optrom = qla2x00_write_optrom_data,
1379 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001381};
1382
1383static struct isp_operations qla2300_isp_ops = {
1384 .pci_config = qla2300_pci_config,
1385 .reset_chip = qla2x00_reset_chip,
1386 .chip_diag = qla2x00_chip_diag,
1387 .config_rings = qla2x00_config_rings,
1388 .reset_adapter = qla2x00_reset_adapter,
1389 .nvram_config = qla2x00_nvram_config,
1390 .update_fw_options = qla2x00_update_fw_options,
1391 .load_risc = qla2x00_load_risc,
1392 .pci_info_str = qla2x00_pci_info_str,
1393 .fw_version_str = qla2x00_fw_version_str,
1394 .intr_handler = qla2300_intr_handler,
1395 .enable_intrs = qla2x00_enable_intrs,
1396 .disable_intrs = qla2x00_disable_intrs,
1397 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001398 .target_reset = qla2x00_abort_target,
1399 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001400 .fabric_login = qla2x00_login_fabric,
1401 .fabric_logout = qla2x00_fabric_logout,
1402 .calc_req_entries = qla2x00_calc_iocbs_32,
1403 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1404 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1405 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1406 .read_nvram = qla2x00_read_nvram_data,
1407 .write_nvram = qla2x00_write_nvram_data,
1408 .fw_dump = qla2300_fw_dump,
1409 .beacon_on = qla2x00_beacon_on,
1410 .beacon_off = qla2x00_beacon_off,
1411 .beacon_blink = qla2x00_beacon_blink,
1412 .read_optrom = qla2x00_read_optrom_data,
1413 .write_optrom = qla2x00_write_optrom_data,
1414 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001415 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001416};
1417
1418static struct isp_operations qla24xx_isp_ops = {
1419 .pci_config = qla24xx_pci_config,
1420 .reset_chip = qla24xx_reset_chip,
1421 .chip_diag = qla24xx_chip_diag,
1422 .config_rings = qla24xx_config_rings,
1423 .reset_adapter = qla24xx_reset_adapter,
1424 .nvram_config = qla24xx_nvram_config,
1425 .update_fw_options = qla24xx_update_fw_options,
1426 .load_risc = qla24xx_load_risc,
1427 .pci_info_str = qla24xx_pci_info_str,
1428 .fw_version_str = qla24xx_fw_version_str,
1429 .intr_handler = qla24xx_intr_handler,
1430 .enable_intrs = qla24xx_enable_intrs,
1431 .disable_intrs = qla24xx_disable_intrs,
1432 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001433 .target_reset = qla24xx_abort_target,
1434 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001435 .fabric_login = qla24xx_login_fabric,
1436 .fabric_logout = qla24xx_fabric_logout,
1437 .calc_req_entries = NULL,
1438 .build_iocbs = NULL,
1439 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1440 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1441 .read_nvram = qla24xx_read_nvram_data,
1442 .write_nvram = qla24xx_write_nvram_data,
1443 .fw_dump = qla24xx_fw_dump,
1444 .beacon_on = qla24xx_beacon_on,
1445 .beacon_off = qla24xx_beacon_off,
1446 .beacon_blink = qla24xx_beacon_blink,
1447 .read_optrom = qla24xx_read_optrom_data,
1448 .write_optrom = qla24xx_write_optrom_data,
1449 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001450 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001451};
1452
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001453static struct isp_operations qla25xx_isp_ops = {
1454 .pci_config = qla25xx_pci_config,
1455 .reset_chip = qla24xx_reset_chip,
1456 .chip_diag = qla24xx_chip_diag,
1457 .config_rings = qla24xx_config_rings,
1458 .reset_adapter = qla24xx_reset_adapter,
1459 .nvram_config = qla24xx_nvram_config,
1460 .update_fw_options = qla24xx_update_fw_options,
1461 .load_risc = qla24xx_load_risc,
1462 .pci_info_str = qla24xx_pci_info_str,
1463 .fw_version_str = qla24xx_fw_version_str,
1464 .intr_handler = qla24xx_intr_handler,
1465 .enable_intrs = qla24xx_enable_intrs,
1466 .disable_intrs = qla24xx_disable_intrs,
1467 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001468 .target_reset = qla24xx_abort_target,
1469 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001470 .fabric_login = qla24xx_login_fabric,
1471 .fabric_logout = qla24xx_fabric_logout,
1472 .calc_req_entries = NULL,
1473 .build_iocbs = NULL,
1474 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1475 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1476 .read_nvram = qla25xx_read_nvram_data,
1477 .write_nvram = qla25xx_write_nvram_data,
1478 .fw_dump = qla25xx_fw_dump,
1479 .beacon_on = qla24xx_beacon_on,
1480 .beacon_off = qla24xx_beacon_off,
1481 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001482 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001483 .write_optrom = qla24xx_write_optrom_data,
1484 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001486};
1487
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001488static struct isp_operations qla81xx_isp_ops = {
1489 .pci_config = qla25xx_pci_config,
1490 .reset_chip = qla24xx_reset_chip,
1491 .chip_diag = qla24xx_chip_diag,
1492 .config_rings = qla24xx_config_rings,
1493 .reset_adapter = qla24xx_reset_adapter,
1494 .nvram_config = qla81xx_nvram_config,
1495 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001496 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001497 .pci_info_str = qla24xx_pci_info_str,
1498 .fw_version_str = qla24xx_fw_version_str,
1499 .intr_handler = qla24xx_intr_handler,
1500 .enable_intrs = qla24xx_enable_intrs,
1501 .disable_intrs = qla24xx_disable_intrs,
1502 .abort_command = qla24xx_abort_command,
1503 .target_reset = qla24xx_abort_target,
1504 .lun_reset = qla24xx_lun_reset,
1505 .fabric_login = qla24xx_login_fabric,
1506 .fabric_logout = qla24xx_fabric_logout,
1507 .calc_req_entries = NULL,
1508 .build_iocbs = NULL,
1509 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1510 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001511 .read_nvram = NULL,
1512 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001513 .fw_dump = qla81xx_fw_dump,
1514 .beacon_on = qla24xx_beacon_on,
1515 .beacon_off = qla24xx_beacon_off,
1516 .beacon_blink = qla24xx_beacon_blink,
1517 .read_optrom = qla25xx_read_optrom_data,
1518 .write_optrom = qla24xx_write_optrom_data,
1519 .get_flash_version = qla24xx_get_flash_version,
1520 .start_scsi = qla24xx_start_scsi,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001521};
1522
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001523static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001525{
1526 ha->device_type = DT_EXTENDED_IDS;
1527 switch (ha->pdev->device) {
1528 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1529 ha->device_type |= DT_ISP2100;
1530 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001531 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001532 break;
1533 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1534 ha->device_type |= DT_ISP2200;
1535 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001536 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001537 break;
1538 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1539 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001540 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001541 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001542 break;
1543 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1544 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001545 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001546 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001547 break;
1548 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1549 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001550 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001551 if (ha->pdev->subsystem_vendor == 0x1028 &&
1552 ha->pdev->subsystem_device == 0x0170)
1553 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001554 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001555 break;
1556 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1557 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001558 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001559 break;
1560 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1561 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001562 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001563 break;
1564 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1565 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001566 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001567 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001568 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001569 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001570 break;
1571 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1572 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001573 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001574 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001575 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001576 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001577 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001578 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1579 ha->device_type |= DT_ISP8432;
1580 ha->device_type |= DT_ZIO_SUPPORTED;
1581 ha->device_type |= DT_FWI2;
1582 ha->device_type |= DT_IIDMA;
1583 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1584 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001585 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1586 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001587 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001588 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001589 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001590 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1591 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001592 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001593 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001594 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001595 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1596 ha->device_type |= DT_ISP2532;
1597 ha->device_type |= DT_ZIO_SUPPORTED;
1598 ha->device_type |= DT_FWI2;
1599 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001600 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1601 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001602 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1603 ha->device_type |= DT_ISP8001;
1604 ha->device_type |= DT_ZIO_SUPPORTED;
1605 ha->device_type |= DT_FWI2;
1606 ha->device_type |= DT_IIDMA;
1607 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1608 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001609 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001610
1611 /* Get adapter physical port no from interrupt pin register. */
1612 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1613 if (ha->port_no & 1)
1614 ha->flags.port0 = 1;
1615 else
1616 ha->flags.port0 = 0;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001617}
1618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
Andrew Vasquez37765412008-01-17 09:02:09 -08001622 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001623 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001624 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Andrew Vasquez285d0322007-10-19 15:59:17 -07001626 if (pci_request_selected_regions(ha->pdev, ha->bars,
1627 QLA2XXX_DRIVER_NAME)) {
1628 qla_printk(KERN_WARNING, ha,
1629 "Failed to reserve PIO/MMIO regions (%s)\n",
1630 pci_name(ha->pdev));
1631
1632 goto iospace_error_exit;
1633 }
1634 if (!(ha->bars & 1))
1635 goto skip_pio;
1636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1638 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001639 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1640 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 qla_printk(KERN_WARNING, ha,
1642 "Invalid PCI I/O region size (%s)...\n",
1643 pci_name(ha->pdev));
1644 pio = 0;
1645 }
1646 } else {
1647 qla_printk(KERN_WARNING, ha,
1648 "region #0 not a PIO resource (%s)...\n",
1649 pci_name(ha->pdev));
1650 pio = 0;
1651 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001652 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Andrew Vasquez285d0322007-10-19 15:59:17 -07001654skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001656 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001658 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 pci_name(ha->pdev));
1660 goto iospace_error_exit;
1661 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001662 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 qla_printk(KERN_ERR, ha,
1664 "Invalid PCI mem region size (%s), aborting\n",
1665 pci_name(ha->pdev));
1666 goto iospace_error_exit;
1667 }
1668
Andrew Vasquez37765412008-01-17 09:02:09 -08001669 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 if (!ha->iobase) {
1671 qla_printk(KERN_ERR, ha,
1672 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1673
1674 goto iospace_error_exit;
1675 }
1676
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001677 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001678 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001679 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001680 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001681 goto mqiobase_exit;
1682 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1683 pci_resource_len(ha->pdev, 3));
1684 if (ha->mqiobase) {
1685 /* Read MSIX vector size of the board */
1686 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1687 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001688 /* Max queues are bounded by available msix vectors */
1689 /* queue 0 uses two msix vectors */
1690 if (ql2xmultique_tag) {
1691 cpus = num_online_cpus();
Anirban Chakraborty27dc9c52009-06-17 10:30:28 -07001692 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001693 (cpus + 1) : (ha->msix_count - 1);
1694 ha->max_req_queues = 2;
1695 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001696 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1697 QLA_MQ_SIZE : ql2xmaxqueues;
1698 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1699 " of request queues:%d\n", ha->max_req_queues));
1700 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001701 qla_printk(KERN_INFO, ha,
1702 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001703 } else
1704 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001705
1706mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001707 ha->msix_count = ha->max_rsp_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 return (0);
1709
1710iospace_error_exit:
1711 return (-ENOMEM);
1712}
1713
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001714static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001715qla2xxx_scan_start(struct Scsi_Host *shost)
1716{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001717 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001718
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001719 if (vha->hw->flags.running_gold_fw)
1720 return;
1721
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001722 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1723 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1724 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1725 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001726}
1727
1728static int
1729qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1730{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001731 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001732
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001733 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001734 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001735 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001736 return 1;
1737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001738 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001739}
1740
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741/*
1742 * PCI driver interface
1743 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001744static int __devinit
1745qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001747 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001749 scsi_qla_host_t *base_vha = NULL;
1750 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001751 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001753 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001754 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001755 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001756 struct req_que *req = NULL;
1757 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Andrew Vasquez285d0322007-10-19 15:59:17 -07001759 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001760 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001761 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1762 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001763 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001764 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1765 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001766 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1767 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001768 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001769 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001770 }
1771
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001772 if (mem_only) {
1773 if (pci_enable_device_mem(pdev))
1774 goto probe_out;
1775 } else {
1776 if (pci_enable_device(pdev))
1777 goto probe_out;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Jesse Barnes09276782008-10-18 17:33:19 -07001780 /* This may fail but that's ok */
1781 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001783 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1784 if (!ha) {
1785 DEBUG(printk("Unable to allocate memory for ha\n"));
1786 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
1790 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001791 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001792 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001793 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001795 /* Set ISP-type information. */
1796 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08001797
1798 /* Set EEH reset type to fundamental if required by hba */
1799 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
1800 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08001801 }
1802
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 /* Configure PCI I/O space */
1804 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001805 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001806 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001809 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1810 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001813 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001814 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001815 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001817 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001820 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001822 req_length = REQUEST_ENTRY_CNT_2100;
1823 rsp_length = RESPONSE_ENTRY_CNT_2100;
1824 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001825 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001826 ha->flash_conf_off = ~0;
1827 ha->flash_data_off = ~0;
1828 ha->nvram_conf_off = ~0;
1829 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001830 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001833 req_length = REQUEST_ENTRY_CNT_2200;
1834 rsp_length = RESPONSE_ENTRY_CNT_2100;
1835 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001836 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001837 ha->flash_conf_off = ~0;
1838 ha->flash_data_off = ~0;
1839 ha->nvram_conf_off = ~0;
1840 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001841 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001842 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844 req_length = REQUEST_ENTRY_CNT_2200;
1845 rsp_length = RESPONSE_ENTRY_CNT_2300;
1846 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001847 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001848 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1849 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001850 ha->flash_conf_off = ~0;
1851 ha->flash_data_off = ~0;
1852 ha->nvram_conf_off = ~0;
1853 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001854 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001855 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001856 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 req_length = REQUEST_ENTRY_CNT_24XX;
1858 rsp_length = RESPONSE_ENTRY_CNT_2300;
1859 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001860 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001861 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001862 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001863 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001864 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001865 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1866 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1867 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1868 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001869 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001870 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 req_length = REQUEST_ENTRY_CNT_24XX;
1872 rsp_length = RESPONSE_ENTRY_CNT_2300;
1873 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001874 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001875 ha->gid_list_info_size = 8;
1876 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001877 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001878 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001879 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1880 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1881 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1882 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1883 } else if (IS_QLA81XX(ha)) {
1884 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1885 req_length = REQUEST_ENTRY_CNT_24XX;
1886 rsp_length = RESPONSE_ENTRY_CNT_2300;
1887 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1888 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1889 ha->gid_list_info_size = 8;
1890 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001891 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001892 ha->isp_ops = &qla81xx_isp_ops;
1893 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1894 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1895 ha->nvram_conf_off = ~0;
1896 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001899 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001900 init_completion(&ha->mbx_cmd_comp);
1901 complete(&ha->mbx_cmd_comp);
1902 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001904 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Andrew Vasquez53303c42009-01-22 09:45:37 -08001906 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001907 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 qla_printk(KERN_WARNING, ha,
1910 "[ERROR] Failed to allocate memory for adapter\n");
1911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912 goto probe_hw_failed;
1913 }
1914
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001915 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001917 req->max_q_depth = ql2xmaxqdepth;
1918
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919
1920 base_vha = qla2x00_create_host(sht, ha);
1921 if (!base_vha) {
1922 qla_printk(KERN_WARNING, ha,
1923 "[ERROR] Failed to allocate memory for scsi_host\n");
1924
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001925 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001926 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001927 qla2x00_free_req_que(ha, req);
1928 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 }
1931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001934 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001935 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001936 host->can_queue = req->length + 128;
1937 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001938 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001939 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1941 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 if (IS_QLA2100(ha))
1943 host->sg_tablesize = 32;
1944 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001945 host->this_id = 255;
1946 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001947 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001948 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001949 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001950 host->max_lun = MAX_LUNS;
1951 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001952 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001953
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001954 /* Set up the irqs */
1955 ret = qla2x00_request_irqs(ha, rsp);
1956 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001957 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08001958
1959 pci_save_state(pdev);
1960
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001961 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001962que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001963 if (!qla2x00_alloc_queues(ha)) {
1964 qla_printk(KERN_WARNING, ha,
1965 "[ERROR] Failed to allocate memory for queue"
1966 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001967 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001968 }
1969 ha->rsp_q_map[0] = rsp;
1970 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001971 rsp->req = req;
1972 req->rsp = rsp;
1973 set_bit(0, ha->req_qid_map);
1974 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07001975 /* FWI2-capable only. */
1976 req->req_q_in = &ha->iobase->isp24.req_q_in;
1977 req->req_q_out = &ha->iobase->isp24.req_q_out;
1978 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1979 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001980 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07001981 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1982 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1983 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1984 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001985 }
1986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001987 if (qla2x00_initialize_adapter(base_vha)) {
1988 qla_printk(KERN_WARNING, ha,
1989 "Failed to initialize adapter\n");
1990
1991 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1992 "Adapter flags %x.\n",
1993 base_vha->host_no, base_vha->device_flags));
1994
1995 ret = -ENODEV;
1996 goto probe_failed;
1997 }
1998
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001999 if (ha->mqenable) {
2000 if (qla25xx_setup_mode(base_vha)) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002001 qla_printk(KERN_WARNING, ha,
2002 "Can't create queues, falling back to single"
2003 " queue mode\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002004 goto que_init;
2005 }
2006 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002007
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002008 if (ha->flags.running_gold_fw)
2009 goto skip_dpc;
2010
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 /*
2012 * Startup the kernel thread for this host adapter
2013 */
2014 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2015 "%s_dpc", base_vha->host_str);
2016 if (IS_ERR(ha->dpc_thread)) {
2017 qla_printk(KERN_WARNING, ha,
2018 "Unable to start DPC thread!\n");
2019 ret = PTR_ERR(ha->dpc_thread);
2020 goto probe_failed;
2021 }
2022
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002023skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002024 list_add_tail(&base_vha->list, &ha->vp_list);
2025 base_vha->host->irq = ha->pdev->irq;
2026
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002033 ret = scsi_add_host(host, &pdev->dev);
2034 if (ret)
2035 goto probe_failed;
2036
Michael Reed14864002009-12-02 09:11:16 -06002037 base_vha->flags.init_done = 1;
2038 base_vha->flags.online = 1;
2039
Andrew Vasquez048feec2008-09-11 22:19:45 -07002040 ha->isp_ops->enable_intrs(ha);
2041
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002042 scsi_scan_host(host);
2043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 qla_printk(KERN_INFO, ha, "\n"
2051 " QLogic Fibre Channel HBA Driver: %s\n"
2052 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08002053 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2054 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 ha->model_desc ? ha->model_desc : "", pdev->device,
2056 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2057 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2058 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 return 0;
2061
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002062probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002063 qla2x00_free_req_que(ha, req);
2064 qla2x00_free_rsp_que(ha, rsp);
2065 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002068 if (base_vha->timer_active)
2069 qla2x00_stop_timer(base_vha);
2070 base_vha->flags.online = 0;
2071 if (ha->dpc_thread) {
2072 struct task_struct *t = ha->dpc_thread;
2073
2074 ha->dpc_thread = NULL;
2075 kthread_stop(t);
2076 }
2077
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002078 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082probe_hw_failed:
2083 if (ha->iobase)
2084 iounmap(ha->iobase);
2085
2086 pci_release_selected_regions(ha->pdev, ha->bars);
2087 kfree(ha);
2088 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002090probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002092 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Adrian Bunk4c993f72008-01-14 00:55:16 -08002095static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002096qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 scsi_qla_host_t *base_vha, *vha, *temp;
2099 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002101 base_vha = pci_get_drvdata(pdev);
2102 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2105 if (vha && vha->fc_vport)
2106 fc_vport_terminate(vha->fc_vport);
2107 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002109 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002110
Andrew Vasquezb9978762009-03-24 09:08:05 -07002111 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2112
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002116
Andrew Vasquezb9978762009-03-24 09:08:05 -07002117 /* Disable timer */
2118 if (base_vha->timer_active)
2119 qla2x00_stop_timer(base_vha);
2120
2121 base_vha->flags.online = 0;
2122
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002123 /* Flush the work queue and remove it */
2124 if (ha->wq) {
2125 flush_workqueue(ha->wq);
2126 destroy_workqueue(ha->wq);
2127 ha->wq = NULL;
2128 }
2129
Andrew Vasquezb9978762009-03-24 09:08:05 -07002130 /* Kill the kernel thread for this host */
2131 if (ha->dpc_thread) {
2132 struct task_struct *t = ha->dpc_thread;
2133
2134 /*
2135 * qla2xxx_wake_dpc checks for ->dpc_thread
2136 * so we need to zero it out.
2137 */
2138 ha->dpc_thread = NULL;
2139 kthread_stop(t);
2140 }
2141
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002142 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002144 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002145
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 scsi_host_put(base_vha->host);
2151
2152 if (ha->iobase)
2153 iounmap(ha->iobase);
2154
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002155 if (ha->mqiobase)
2156 iounmap(ha->mqiobase);
2157
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 pci_release_selected_regions(ha->pdev, ha->bars);
2159 kfree(ha);
2160 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002162 pci_disable_pcie_error_reporting(pdev);
2163
Bernhard Walle665db932007-03-28 00:49:49 +02002164 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 pci_set_drvdata(pdev, NULL);
2166}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
2168static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002169qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002171 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Andrew Vasquez85880802009-12-15 21:29:46 -08002173 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2174
2175 /* Disable timer */
2176 if (vha->timer_active)
2177 qla2x00_stop_timer(vha);
2178
2179 /* Kill the kernel thread for this host */
2180 if (ha->dpc_thread) {
2181 struct task_struct *t = ha->dpc_thread;
2182
2183 /*
2184 * qla2xxx_wake_dpc checks for ->dpc_thread
2185 * so we need to zero it out.
2186 */
2187 ha->dpc_thread = NULL;
2188 kthread_stop(t);
2189 }
2190
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002191 qla25xx_delete_queues(vha);
2192
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002193 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002195
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002196 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002197 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002198
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002199 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002200 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Andrew Vasquez85880802009-12-15 21:29:46 -08002202 vha->flags.online = 0;
2203
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002204 /* turn-off interrupts on the card */
2205 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002206 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002207
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 qla2x00_free_irqs(vha);
2209
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002210 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002211
2212 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213}
2214
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002215static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002217 int defer)
2218{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002219 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002220 scsi_qla_host_t *base_vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002221
2222 if (!fcport->rport)
2223 return;
2224
2225 rport = fcport->rport;
2226 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002227 base_vha = pci_get_drvdata(vha->hw->pdev);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002228 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002229 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002230 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002231 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2232 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002233 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002234 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002235}
2236
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2239 *
2240 * Input: ha = adapter block pointer. fcport = port structure pointer.
2241 *
2242 * Return: None.
2243 *
2244 * Context:
2245 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002247 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002249 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 vha->vp_idx == fcport->vp_idx) {
2251 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2252 qla2x00_schedule_rport_del(vha, fcport, defer);
2253 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002254 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 * We may need to retry the login, so don't change the state of the
2256 * port but do the retries.
2257 */
2258 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2259 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2260
2261 if (!do_login)
2262 return;
2263
2264 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 fcport->login_retry = vha->hw->login_retry_count;
2266 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
2268 DEBUG(printk("scsi(%ld): Port login retry: "
2269 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2270 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 fcport->port_name[0],
2273 fcport->port_name[1],
2274 fcport->port_name[2],
2275 fcport->port_name[3],
2276 fcport->port_name[4],
2277 fcport->port_name[5],
2278 fcport->port_name[6],
2279 fcport->port_name[7],
2280 fcport->loop_id,
2281 fcport->login_retry));
2282 }
2283}
2284
2285/*
2286 * qla2x00_mark_all_devices_lost
2287 * Updates fcport state when device goes offline.
2288 *
2289 * Input:
2290 * ha = adapter block pointer.
2291 * fcport = port structure pointer.
2292 *
2293 * Return:
2294 * None.
2295 *
2296 * Context:
2297 */
2298void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002299qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300{
2301 fc_port_t *fcport;
2302
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002304 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002306
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 /*
2308 * No point in marking the device as lost, if the device is
2309 * already DEAD.
2310 */
2311 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2312 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002314 if (defer)
2315 qla2x00_schedule_rport_del(vha, fcport, defer);
2316 else if (vha->vp_idx == fcport->vp_idx)
2317 qla2x00_schedule_rport_del(vha, fcport, defer);
2318 }
2319 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 }
2321}
2322
2323/*
2324* qla2x00_mem_alloc
2325* Allocates adapter memory.
2326*
2327* Returns:
2328* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002329* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002331static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002332qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2333 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
2335 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Andrew Vasqueze8711082008-01-31 12:33:48 -08002337 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002339 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002340 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2343 &ha->gid_list_dma, GFP_KERNEL);
2344 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002345 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
Andrew Vasqueze8711082008-01-31 12:33:48 -08002347 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2348 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002349 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Andrew Vasqueze8711082008-01-31 12:33:48 -08002351 /* Get memory for cached NVRAM */
2352 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2353 if (!ha->nvram)
2354 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2357 ha->pdev->device);
2358 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2359 DMA_POOL_SIZE, 8, 0);
2360 if (!ha->s_dma_pool)
2361 goto fail_free_nvram;
2362
Andrew Vasqueze8711082008-01-31 12:33:48 -08002363 /* Allocate memory for SNS commands */
2364 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002366 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002368 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002370 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002372 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002374 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002375 goto fail_dma_pool;
2376 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002377 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002379 if (!ha->ct_sns)
2380 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 }
2382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002384 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2385 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 DEBUG(printk("Unable to allocate memory for req\n"));
2387 goto fail_req;
2388 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002389 (*req)->length = req_len;
2390 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2391 ((*req)->length + 1) * sizeof(request_t),
2392 &(*req)->dma, GFP_KERNEL);
2393 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2395 goto fail_req_ring;
2396 }
2397 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002398 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2399 if (!*rsp) {
2400 qla_printk(KERN_WARNING, ha,
2401 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 goto fail_rsp;
2403 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002404 (*rsp)->hw = ha;
2405 (*rsp)->length = rsp_len;
2406 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2407 ((*rsp)->length + 1) * sizeof(response_t),
2408 &(*rsp)->dma, GFP_KERNEL);
2409 if (!(*rsp)->ring) {
2410 qla_printk(KERN_WARNING, ha,
2411 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 goto fail_rsp_ring;
2413 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002414 (*req)->rsp = *rsp;
2415 (*rsp)->req = *req;
2416 /* Allocate memory for NVRAM data for vports */
2417 if (ha->nvram_npiv_size) {
2418 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2419 ha->nvram_npiv_size, GFP_KERNEL);
2420 if (!ha->npiv_info) {
2421 qla_printk(KERN_WARNING, ha,
2422 "Unable to allocate memory for npiv info\n");
2423 goto fail_npiv_info;
2424 }
2425 } else
2426 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002428 /* Get consistent memory allocated for EX-INIT-CB. */
2429 if (IS_QLA81XX(ha)) {
2430 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2431 &ha->ex_init_cb_dma);
2432 if (!ha->ex_init_cb)
2433 goto fail_ex_init_cb;
2434 }
2435
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 INIT_LIST_HEAD(&ha->vp_list);
2437 return 1;
2438
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002439fail_ex_init_cb:
2440 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002441fail_npiv_info:
2442 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2443 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2444 (*rsp)->ring = NULL;
2445 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002447 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002449 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2450 sizeof(request_t), (*req)->ring, (*req)->dma);
2451 (*req)->ring = NULL;
2452 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002453fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002454 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002455fail_req:
2456 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2457 ha->ct_sns, ha->ct_sns_dma);
2458 ha->ct_sns = NULL;
2459 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002460fail_free_ms_iocb:
2461 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2462 ha->ms_iocb = NULL;
2463 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464fail_dma_pool:
2465 dma_pool_destroy(ha->s_dma_pool);
2466 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002467fail_free_nvram:
2468 kfree(ha->nvram);
2469 ha->nvram = NULL;
2470fail_free_srb_mempool:
2471 mempool_destroy(ha->srb_mempool);
2472 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002473fail_free_gid_list:
2474 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002476 ha->gid_list = NULL;
2477 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478fail_free_init_cb:
2479 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2480 ha->init_cb_dma);
2481 ha->init_cb = NULL;
2482 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002483fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002485 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486}
2487
2488/*
2489* qla2x00_mem_free
2490* Frees all adapter allocated memory.
2491*
2492* Input:
2493* ha = adapter block pointer.
2494*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002495static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002498 if (ha->srb_mempool)
2499 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002501 if (ha->fce)
2502 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002503 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002504
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002505 if (ha->fw_dump) {
2506 if (ha->eft)
2507 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002509 vfree(ha->fw_dump);
2510 }
2511
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07002512 if (ha->dcbx_tlv)
2513 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2514 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2515
Andrew Vasquezce0423f2009-06-03 09:55:13 -07002516 if (ha->xgmac_data)
2517 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2518 ha->xgmac_data, ha->xgmac_data_dma);
2519
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 if (ha->sns_cmd)
2521 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
2524 if (ha->ct_sns)
2525 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Andrew Vasquez88729e52006-06-23 16:10:50 -07002528 if (ha->sfp_data)
2529 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2530
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002531 if (ha->edc_data)
2532 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2533
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 if (ha->ms_iocb)
2535 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2536
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002537 if (ha->ex_init_cb)
2538 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 if (ha->s_dma_pool)
2541 dma_pool_destroy(ha->s_dma_pool);
2542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 if (ha->gid_list)
2544 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547 if (ha->init_cb)
2548 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2549 ha->init_cb, ha->init_cb_dma);
2550 vfree(ha->optrom_buffer);
2551 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002552 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
Andrew Vasqueze8711082008-01-31 12:33:48 -08002554 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002555 ha->eft = NULL;
2556 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 ha->sns_cmd = NULL;
2558 ha->sns_cmd_dma = 0;
2559 ha->ct_sns = NULL;
2560 ha->ct_sns_dma = 0;
2561 ha->ms_iocb = NULL;
2562 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 ha->init_cb = NULL;
2564 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002565 ha->ex_init_cb = NULL;
2566 ha->ex_init_cb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
2568 ha->s_dma_pool = NULL;
2569
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 ha->gid_list = NULL;
2571 ha->gid_list_dma = 0;
2572
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002574 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002576}
2577
2578struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2579 struct qla_hw_data *ha)
2580{
2581 struct Scsi_Host *host;
2582 struct scsi_qla_host *vha = NULL;
2583
2584 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2585 if (host == NULL) {
2586 printk(KERN_WARNING
2587 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2588 goto fail;
2589 }
2590
2591 /* Clear our data area */
2592 vha = shost_priv(host);
2593 memset(vha, 0, sizeof(scsi_qla_host_t));
2594
2595 vha->host = host;
2596 vha->host_no = host->host_no;
2597 vha->hw = ha;
2598
2599 INIT_LIST_HEAD(&vha->vp_fcports);
2600 INIT_LIST_HEAD(&vha->work_list);
2601 INIT_LIST_HEAD(&vha->list);
2602
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002603 spin_lock_init(&vha->work_lock);
2604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2606 return vha;
2607
2608fail:
2609 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002612static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002613qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002614{
2615 struct qla_work_evt *e;
2616
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002617 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002618 if (!e)
2619 return NULL;
2620
2621 INIT_LIST_HEAD(&e->list);
2622 e->type = type;
2623 e->flags = QLA_EVT_FLAG_FREE;
2624 return e;
2625}
2626
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002627static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002628qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002629{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002630 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002631
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002632 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002634 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002636
Andrew Vasquez0971de72008-04-03 13:13:18 -07002637 return QLA_SUCCESS;
2638}
2639
2640int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002642 u32 data)
2643{
2644 struct qla_work_evt *e;
2645
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002646 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002647 if (!e)
2648 return QLA_FUNCTION_FAILED;
2649
2650 e->u.aen.code = code;
2651 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002652 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002653}
2654
Andrew Vasquez8a659572009-02-08 20:50:12 -08002655int
2656qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2657{
2658 struct qla_work_evt *e;
2659
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002660 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08002661 if (!e)
2662 return QLA_FUNCTION_FAILED;
2663
2664 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002665 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08002666}
2667
Andrew Vasquezac280b62009-08-20 11:06:05 -07002668#define qla2x00_post_async_work(name, type) \
2669int qla2x00_post_async_##name##_work( \
2670 struct scsi_qla_host *vha, \
2671 fc_port_t *fcport, uint16_t *data) \
2672{ \
2673 struct qla_work_evt *e; \
2674 \
2675 e = qla2x00_alloc_work(vha, type); \
2676 if (!e) \
2677 return QLA_FUNCTION_FAILED; \
2678 \
2679 e->u.logio.fcport = fcport; \
2680 if (data) { \
2681 e->u.logio.data[0] = data[0]; \
2682 e->u.logio.data[1] = data[1]; \
2683 } \
2684 return qla2x00_post_work(vha, e); \
2685}
2686
2687qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2688qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2689qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2690qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2691
Andrew Vasquez3420d362009-10-13 15:16:45 -07002692int
2693qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
2694{
2695 struct qla_work_evt *e;
2696
2697 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
2698 if (!e)
2699 return QLA_FUNCTION_FAILED;
2700
2701 e->u.uevent.code = code;
2702 return qla2x00_post_work(vha, e);
2703}
2704
2705static void
2706qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
2707{
2708 char event_string[40];
2709 char *envp[] = { event_string, NULL };
2710
2711 switch (code) {
2712 case QLA_UEVENT_CODE_FW_DUMP:
2713 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2714 vha->host_no);
2715 break;
2716 default:
2717 /* do nothing */
2718 break;
2719 }
2720 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
2721}
2722
Andrew Vasquezac280b62009-08-20 11:06:05 -07002723void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002725{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002726 struct qla_work_evt *e, *tmp;
2727 unsigned long flags;
2728 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002729
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002730 spin_lock_irqsave(&vha->work_lock, flags);
2731 list_splice_init(&vha->work_list, &work);
2732 spin_unlock_irqrestore(&vha->work_lock, flags);
2733
2734 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07002735 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002736
2737 switch (e->type) {
2738 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002740 e->u.aen.code, e->u.aen.data);
2741 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08002742 case QLA_EVT_IDC_ACK:
2743 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2744 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002745 case QLA_EVT_ASYNC_LOGIN:
2746 qla2x00_async_login(vha, e->u.logio.fcport,
2747 e->u.logio.data);
2748 break;
2749 case QLA_EVT_ASYNC_LOGIN_DONE:
2750 qla2x00_async_login_done(vha, e->u.logio.fcport,
2751 e->u.logio.data);
2752 break;
2753 case QLA_EVT_ASYNC_LOGOUT:
2754 qla2x00_async_logout(vha, e->u.logio.fcport);
2755 break;
2756 case QLA_EVT_ASYNC_LOGOUT_DONE:
2757 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2758 e->u.logio.data);
2759 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07002760 case QLA_EVT_UEVENT:
2761 qla2x00_uevent_emit(vha, e->u.uevent.code);
2762 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002763 }
2764 if (e->flags & QLA_EVT_FLAG_FREE)
2765 kfree(e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002766 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002768
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002769/* Relogins all the fcports of a vport
2770 * Context: dpc thread
2771 */
2772void qla2x00_relogin(struct scsi_qla_host *vha)
2773{
2774 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08002775 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 uint16_t next_loopid = 0;
2777 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002778 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779
2780 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2781 /*
2782 * If the port is not ONLINE then try to login
2783 * to it if we haven't run out of retries.
2784 */
2785 if (atomic_read(&fcport->state) !=
2786 FCS_ONLINE && fcport->login_retry) {
2787
Andrew Vasquezac280b62009-08-20 11:06:05 -07002788 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002790 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 ha->isp_ops->fabric_logout(vha,
2792 fcport->loop_id,
2793 fcport->d_id.b.domain,
2794 fcport->d_id.b.area,
2795 fcport->d_id.b.al_pa);
2796
Andrew Vasquezac280b62009-08-20 11:06:05 -07002797 if (IS_ALOGIO_CAPABLE(ha)) {
2798 data[0] = 0;
2799 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2800 status = qla2x00_post_async_login_work(
2801 vha, fcport, data);
2802 if (status == QLA_SUCCESS)
2803 continue;
2804 /* Attempt a retry. */
2805 status = 1;
2806 } else
2807 status = qla2x00_fabric_login(vha,
2808 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809 } else
2810 status = qla2x00_local_device_login(vha,
2811 fcport);
2812
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 if (status == QLA_SUCCESS) {
2814 fcport->old_loop_id = fcport->loop_id;
2815
2816 DEBUG(printk("scsi(%ld): port login OK: logged "
2817 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2818
2819 qla2x00_update_fcport(vha, fcport);
2820
2821 } else if (status == 1) {
2822 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2823 /* retry the login again */
2824 DEBUG(printk("scsi(%ld): Retrying"
2825 " %d login again loop_id 0x%x\n",
2826 vha->host_no, fcport->login_retry,
2827 fcport->loop_id));
2828 } else {
2829 fcport->login_retry = 0;
2830 }
2831
2832 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2833 fcport->loop_id = FC_NO_LOOP_ID;
2834 }
2835 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2836 break;
2837 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002838}
2839
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840/**************************************************************************
2841* qla2x00_do_dpc
2842* This kernel thread is a task that is schedule by the interrupt handler
2843* to perform the background processing for interrupts.
2844*
2845* Notes:
2846* This task always run in the context of a kernel thread. It
2847* is kick-off by the driver's detect code and starts up
2848* up one per adapter. It immediately goes to sleep and waits for
2849* some fibre event. When either the interrupt handler or
2850* the timer routine detects a event it will one of the task
2851* bits then wake us up.
2852**************************************************************************/
2853static int
2854qla2x00_do_dpc(void *data)
2855{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002856 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 scsi_qla_host_t *base_vha;
2858 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 ha = (struct qla_hw_data *)data;
2861 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 set_user_nice(current, -20);
2864
Christoph Hellwig39a11242006-02-14 18:46:22 +01002865 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2867
Christoph Hellwig39a11242006-02-14 18:46:22 +01002868 set_current_state(TASK_INTERRUPTIBLE);
2869 schedule();
2870 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2873
2874 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 continue;
2877
Andrew Vasquez85880802009-12-15 21:29:46 -08002878 if (ha->flags.eeh_busy) {
2879 DEBUG17(qla_printk(KERN_WARNING, ha,
2880 "qla2x00_do_dpc: dpc_flags: %lx\n",
2881 base_vha->dpc_flags));
2882 continue;
2883 }
2884
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002885 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
2887 ha->dpc_active = 1;
2888
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 ha->dpc_active = 0;
2891 continue;
2892 }
2893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002896 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2897 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
2899 DEBUG(printk("scsi(%ld): dpc: sched "
2900 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 /* failed. retry later */
2907 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 clear_bit(ABORT_ISP_ACTIVE,
2911 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002912 }
2913
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 }
2917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2919 qla2x00_update_fcports(base_vha);
2920 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002921 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2924 &base_vha->dpc_flags) &&
2925 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
2927 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002928 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 qla2x00_rst_aen(base_vha);
2931 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 }
2933
2934 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 if ((test_and_clear_bit(RELOGIN_NEEDED,
2936 &base_vha->dpc_flags)) &&
2937 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2938 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939
2940 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941 base_vha->host_no));
2942 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 }
2947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2949 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
2951 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002952 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953
2954 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 clear_bit(LOOP_RESYNC_ACTIVE,
2960 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 }
2962
2963 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2968 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2969 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2970 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002971 }
2972
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002974 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2977 &base_vha->dpc_flags))
2978 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002981
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 ha->dpc_active = 0;
2983 } /* End of while(1) */
2984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986
2987 /*
2988 * Make sure that nobody tries to wake us up again.
2989 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 ha->dpc_active = 0;
2991
Andrew Vasquezac280b62009-08-20 11:06:05 -07002992 /* Cleanup any residual CTX SRBs. */
2993 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2994
Christoph Hellwig39a11242006-02-14 18:46:22 +01002995 return 0;
2996}
2997
2998void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003000{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003002 struct task_struct *t = ha->dpc_thread;
3003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003005 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006}
3007
3008/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009* qla2x00_rst_aen
3010* Processes asynchronous reset.
3011*
3012* Input:
3013* ha = adapter block pointer.
3014*/
3015static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 if (vha->flags.online && !vha->flags.reset_active &&
3019 !atomic_read(&vha->loop_down_timer) &&
3020 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
3024 /*
3025 * Issue marker command only when we are going to start
3026 * the I/O.
3027 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 vha->marker_needed = 1;
3029 } while (!atomic_read(&vha->loop_down_timer) &&
3030 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 }
3032}
3033
f4f051e2005-04-17 15:02:26 -05003034static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003035qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003036{
3037 struct scsi_cmnd *cmd = sp->cmd;
3038
3039 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003040 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003041 sp->flags &= ~SRB_DMA_VALID;
3042 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003043 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05003044}
3045
3046void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003047qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003048{
3049 struct scsi_cmnd *cmd = sp->cmd;
3050
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003051 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05003052
f4f051e2005-04-17 15:02:26 -05003053 mempool_free(sp, ha->srb_mempool);
3054
3055 cmd->scsi_done(cmd);
3056}
bdf79622005-04-17 15:06:53 -05003057
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058/**************************************************************************
3059* qla2x00_timer
3060*
3061* Description:
3062* One second timer
3063*
3064* Context: Interrupt
3065***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003066void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 unsigned long cpu_flags = 0;
3070 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 int start_dpc = 0;
3072 int index;
3073 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05003074 int t;
Andrew Vasquez85880802009-12-15 21:29:46 -08003075 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003076 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003077 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003078
3079 /* Hardware read to raise pending EEH errors during mailbox waits. */
3080 if (!pci_channel_offline(ha->pdev))
3081 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 /*
3083 * Ports - Port down timer.
3084 *
3085 * Whenever, a port is in the LOST state we start decrementing its port
3086 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003087 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 */
3089 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 if (fcport->port_type != FCT_TARGET)
3092 continue;
3093
3094 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3095
3096 if (atomic_read(&fcport->port_down_timer) == 0)
3097 continue;
3098
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003099 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003101
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07003103 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003104 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 t, atomic_read(&fcport->port_down_timer)));
3106 }
3107 t++;
3108 } /* End of for fcport */
3109
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003112 if (atomic_read(&vha->loop_down_timer) > 0 &&
3113 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3114 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 if (atomic_read(&vha->loop_down_timer) ==
3117 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118
3119 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3120 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003121 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003123 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3124 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003126 /*
3127 * Schedule an ISP abort to return any FCP2-device
3128 * commands.
3129 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003130 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003132 spin_lock_irqsave(&ha->hardware_lock,
3133 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003134 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003135 for (index = 1;
3136 index < MAX_OUTSTANDING_COMMANDS;
3137 index++) {
3138 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003139
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003140 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003141 if (!sp)
3142 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003143 if (sp->ctx)
3144 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003145 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003146 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003147 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003149 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003151 break;
3152 }
3153 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003154 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 start_dpc++;
3157 }
3158
3159 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003160 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003161 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 DEBUG(printk("scsi(%ld): Loop down - "
3163 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 qla_printk(KERN_WARNING, ha,
3166 "Loop down - aborting ISP.\n");
3167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
3170 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003171 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003172 vha->host_no,
3173 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 }
3175
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003176 /* Check if beacon LED needs to be blinked */
3177 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003178 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003179 start_dpc++;
3180 }
3181
Andrew Vasquez550bf572008-04-24 15:21:23 -07003182 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003184 start_dpc++;
3185
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3188 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3189 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003191 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3192 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3193 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3194 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3195 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198}
3199
Andrew Vasquez54333832005-11-09 15:49:04 -08003200/* Firmware interface routines. */
3201
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003202#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003203#define FW_ISP21XX 0
3204#define FW_ISP22XX 1
3205#define FW_ISP2300 2
3206#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003207#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003208#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003209#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08003210
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003211#define FW_FILE_ISP21XX "ql2100_fw.bin"
3212#define FW_FILE_ISP22XX "ql2200_fw.bin"
3213#define FW_FILE_ISP2300 "ql2300_fw.bin"
3214#define FW_FILE_ISP2322 "ql2322_fw.bin"
3215#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003216#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003217#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003218
Daniel Walkere1e82b62008-05-12 22:21:10 -07003219static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003220
3221static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003222 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3223 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3224 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3225 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3226 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003227 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003228 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003229};
3230
3231struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003232qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003233{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003235 struct fw_blob *blob;
3236
3237 blob = NULL;
3238 if (IS_QLA2100(ha)) {
3239 blob = &qla_fw_blobs[FW_ISP21XX];
3240 } else if (IS_QLA2200(ha)) {
3241 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003242 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003243 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003244 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003245 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003246 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003247 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003248 } else if (IS_QLA25XX(ha)) {
3249 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003250 } else if (IS_QLA81XX(ha)) {
3251 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003252 }
3253
Daniel Walkere1e82b62008-05-12 22:21:10 -07003254 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003255 if (blob->fw)
3256 goto out;
3257
3258 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3259 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003261 blob->fw = NULL;
3262 blob = NULL;
3263 goto out;
3264 }
3265
3266out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003267 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003268 return blob;
3269}
3270
3271static void
3272qla2x00_release_firmware(void)
3273{
3274 int idx;
3275
Daniel Walkere1e82b62008-05-12 22:21:10 -07003276 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003277 for (idx = 0; idx < FW_BLOBS; idx++)
3278 if (qla_fw_blobs[idx].fw)
3279 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003280 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003281}
3282
Seokmann Ju14e660e2007-09-20 14:07:36 -07003283static pci_ers_result_t
3284qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3285{
Andrew Vasquez85880802009-12-15 21:29:46 -08003286 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3287 struct qla_hw_data *ha = vha->hw;
3288
3289 DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
3290 state));
Seokmann Jub9b12f72009-03-24 09:08:18 -07003291
Seokmann Ju14e660e2007-09-20 14:07:36 -07003292 switch (state) {
3293 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003294 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003295 return PCI_ERS_RESULT_CAN_RECOVER;
3296 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08003297 ha->flags.eeh_busy = 1;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003298 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003299 pci_disable_device(pdev);
3300 return PCI_ERS_RESULT_NEED_RESET;
3301 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08003302 ha->flags.pci_channel_io_perm_failure = 1;
3303 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003304 return PCI_ERS_RESULT_DISCONNECT;
3305 }
3306 return PCI_ERS_RESULT_NEED_RESET;
3307}
3308
3309static pci_ers_result_t
3310qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3311{
3312 int risc_paused = 0;
3313 uint32_t stat;
3314 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3316 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003317 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3318 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3319
3320 spin_lock_irqsave(&ha->hardware_lock, flags);
3321 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3322 stat = RD_REG_DWORD(&reg->hccr);
3323 if (stat & HCCR_RISC_PAUSE)
3324 risc_paused = 1;
3325 } else if (IS_QLA23XX(ha)) {
3326 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3327 if (stat & HSR_RISC_PAUSED)
3328 risc_paused = 1;
3329 } else if (IS_FWI2_CAPABLE(ha)) {
3330 stat = RD_REG_DWORD(&reg24->host_status);
3331 if (stat & HSRX_RISC_PAUSED)
3332 risc_paused = 1;
3333 }
3334 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3335
3336 if (risc_paused) {
3337 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3338 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003339 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003340
3341 return PCI_ERS_RESULT_NEED_RESET;
3342 } else
3343 return PCI_ERS_RESULT_RECOVERED;
3344}
3345
3346static pci_ers_result_t
3347qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3348{
3349 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3351 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003352 struct rsp_que *rsp;
3353 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003354
Andrew Vasquez85880802009-12-15 21:29:46 -08003355 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3356
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003357 /* Workaround: qla2xxx driver which access hardware earlier
3358 * needs error state to be pci_channel_io_online.
3359 * Otherwise mailbox command timesout.
3360 */
3361 pdev->error_state = pci_channel_io_normal;
3362
3363 pci_restore_state(pdev);
3364
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003365 if (ha->mem_only)
3366 rc = pci_enable_device_mem(pdev);
3367 else
3368 rc = pci_enable_device(pdev);
3369
3370 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003371 qla_printk(KERN_WARNING, ha,
3372 "Can't re-enable PCI device after reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07003373 return ret;
3374 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07003375
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003376 rsp = ha->rsp_q_map[0];
3377 if (qla2x00_request_irqs(ha, rsp))
3378 return ret;
3379
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003380 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003381 return ret;
3382
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003383 while (ha->flags.mbox_busy && retries--)
3384 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08003385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3387 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003388 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003390
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003391 pci_cleanup_aer_uncorrect_error_status(pdev);
3392
Andrew Vasquez85880802009-12-15 21:29:46 -08003393 DEBUG17(qla_printk(KERN_WARNING, ha,
3394 "slot_reset-return:ret=%x\n", ret));
3395
Seokmann Ju14e660e2007-09-20 14:07:36 -07003396 return ret;
3397}
3398
3399static void
3400qla2xxx_pci_resume(struct pci_dev *pdev)
3401{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3403 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003404 int ret;
3405
Andrew Vasquez85880802009-12-15 21:29:46 -08003406 DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
3407
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003409 if (ret != QLA_SUCCESS) {
3410 qla_printk(KERN_ERR, ha,
3411 "the device failed to resume I/O "
3412 "from slot/link_reset");
3413 }
Andrew Vasquez85880802009-12-15 21:29:46 -08003414
3415 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003416}
3417
3418static struct pci_error_handlers qla2xxx_err_handler = {
3419 .error_detected = qla2xxx_pci_error_detected,
3420 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3421 .slot_reset = qla2xxx_pci_slot_reset,
3422 .resume = qla2xxx_pci_resume,
3423};
3424
Andrew Vasquez54333832005-11-09 15:49:04 -08003425static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003426 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3427 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3428 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3429 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3430 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3431 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3432 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3433 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3434 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003435 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003436 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3437 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003438 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003439 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003440 { 0 },
3441};
3442MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3443
Andrew Vasquezfca29702005-07-06 10:31:47 -07003444static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003445 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003446 .driver = {
3447 .owner = THIS_MODULE,
3448 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003449 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003450 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003451 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003452 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003453};
3454
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455/**
3456 * qla2x00_module_init - Module initialization.
3457 **/
3458static int __init
3459qla2x00_module_init(void)
3460{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003461 int ret = 0;
3462
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003464 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003465 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 if (srb_cachep == NULL) {
3467 printk(KERN_ERR
3468 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3469 return -ENOMEM;
3470 }
3471
3472 /* Derive version string. */
3473 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003474 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003475 strcat(qla2x00_version_str, "-debug");
3476
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003477 qla2xxx_transport_template =
3478 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003479 if (!qla2xxx_transport_template) {
3480 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003482 }
3483 qla2xxx_transport_vport_template =
3484 fc_attach_transport(&qla2xxx_transport_vport_functions);
3485 if (!qla2xxx_transport_vport_template) {
3486 kmem_cache_destroy(srb_cachep);
3487 fc_release_transport(qla2xxx_transport_template);
3488 return -ENODEV;
3489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003491 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3492 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003493 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003494 if (ret) {
3495 kmem_cache_destroy(srb_cachep);
3496 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003497 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003498 }
3499 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500}
3501
3502/**
3503 * qla2x00_module_exit - Module cleanup.
3504 **/
3505static void __exit
3506qla2x00_module_exit(void)
3507{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003508 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003509 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003510 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003512 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513}
3514
3515module_init(qla2x00_module_init);
3516module_exit(qla2x00_module_exit);
3517
3518MODULE_AUTHOR("QLogic Corporation");
3519MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3520MODULE_LICENSE("GPL");
3521MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003522MODULE_FIRMWARE(FW_FILE_ISP21XX);
3523MODULE_FIRMWARE(FW_FILE_ISP22XX);
3524MODULE_FIRMWARE(FW_FILE_ISP2300);
3525MODULE_FIRMWARE(FW_FILE_ISP2322);
3526MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003527MODULE_FIRMWARE(FW_FILE_ISP25XX);