blob: 82e57d778428d79ea2b0930f22827e15733436d0 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700111 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
113static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500114static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800115static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
116static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500117static void qla2xxx_slave_destroy(struct scsi_device *);
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700118static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700119 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120static int qla2xxx_eh_abort(struct scsi_cmnd *);
121static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700122static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
124static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Mike Christiee881a172009-10-15 17:46:39 -0700126static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700127static int qla2x00_change_queue_type(struct scsi_device *, int);
128
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700129struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700131 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700132 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700133
134 .eh_abort_handler = qla2xxx_eh_abort,
135 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700136 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700137 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
138 .eh_host_reset_handler = qla2xxx_eh_host_reset,
139
140 .slave_configure = qla2xxx_slave_configure,
141
142 .slave_alloc = qla2xxx_slave_alloc,
143 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700144 .scan_finished = qla2xxx_scan_finished,
145 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700146 .change_queue_depth = qla2x00_change_queue_depth,
147 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700148 .this_id = -1,
149 .cmd_per_lun = 3,
150 .use_clustering = ENABLE_CLUSTERING,
151 .sg_tablesize = SG_ALL,
152
153 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700154 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700155};
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700158struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/* TODO Convert to inlines
161 *
162 * Timer routines
163 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700165__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800166qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800168 init_timer(&vha->timer);
169 vha->timer.expires = jiffies + interval * HZ;
170 vha->timer.data = (unsigned long)vha;
171 vha->timer.function = (void (*)(unsigned long))func;
172 add_timer(&vha->timer);
173 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
176static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800177qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800179 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
Adrian Bunka824ebb2008-01-17 09:02:15 -0800182static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800183qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800185 del_timer_sync(&vha->timer);
186 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189static int qla2x00_do_dpc(void *data);
190
191static void qla2x00_rst_aen(scsi_qla_host_t *);
192
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800193static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
194 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800195static void qla2x00_mem_free(struct qla_hw_data *);
196static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800199static int qla2x00_alloc_queues(struct qla_hw_data *ha)
200{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700201 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800202 GFP_KERNEL);
203 if (!ha->req_q_map) {
204 qla_printk(KERN_WARNING, ha,
205 "Unable to allocate memory for request queue ptrs\n");
206 goto fail_req_map;
207 }
208
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700209 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800210 GFP_KERNEL);
211 if (!ha->rsp_q_map) {
212 qla_printk(KERN_WARNING, ha,
213 "Unable to allocate memory for response queue ptrs\n");
214 goto fail_rsp_map;
215 }
216 set_bit(0, ha->rsp_qid_map);
217 set_bit(0, ha->req_qid_map);
218 return 1;
219
220fail_rsp_map:
221 kfree(ha->req_q_map);
222 ha->req_q_map = NULL;
223fail_req_map:
224 return -ENOMEM;
225}
226
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700227static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800228{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800229 if (req && req->ring)
230 dma_free_coherent(&ha->pdev->dev,
231 (req->length + 1) * sizeof(request_t),
232 req->ring, req->dma);
233
234 kfree(req);
235 req = NULL;
236}
237
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700238static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
239{
240 if (rsp && rsp->ring)
241 dma_free_coherent(&ha->pdev->dev,
242 (rsp->length + 1) * sizeof(response_t),
243 rsp->ring, rsp->dma);
244
245 kfree(rsp);
246 rsp = NULL;
247}
248
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800249static void qla2x00_free_queues(struct qla_hw_data *ha)
250{
251 struct req_que *req;
252 struct rsp_que *rsp;
253 int cnt;
254
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700255 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800256 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700257 qla2x00_free_req_que(ha, req);
258 }
259 kfree(ha->req_q_map);
260 ha->req_q_map = NULL;
261
262 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
263 rsp = ha->rsp_q_map[cnt];
264 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800265 }
266 kfree(ha->rsp_q_map);
267 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800268}
269
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700270static int qla25xx_setup_mode(struct scsi_qla_host *vha)
271{
272 uint16_t options = 0;
273 int ques, req, ret;
274 struct qla_hw_data *ha = vha->hw;
275
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700276 if (!(ha->fw_attributes & BIT_6)) {
277 qla_printk(KERN_INFO, ha,
278 "Firmware is not multi-queue capable\n");
279 goto fail;
280 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700281 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700282 /* create a request queue for IO */
283 options |= BIT_7;
284 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
285 QLA_DEFAULT_QUE_QOS);
286 if (!req) {
287 qla_printk(KERN_WARNING, ha,
288 "Can't create request queue\n");
289 goto fail;
290 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700291 ha->wq = create_workqueue("qla2xxx_wq");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700292 vha->req = ha->req_q_map[req];
293 options |= BIT_1;
294 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
295 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
296 if (!ret) {
297 qla_printk(KERN_WARNING, ha,
298 "Response Queue create failed\n");
299 goto fail2;
300 }
301 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700302 ha->flags.cpu_affinity_enabled = 1;
303
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700304 DEBUG2(qla_printk(KERN_INFO, ha,
305 "CPU affinity mode enabled, no. of response"
306 " queues:%d, no. of request queues:%d\n",
307 ha->max_rsp_queues, ha->max_req_queues));
308 }
309 return 0;
310fail2:
311 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700312 destroy_workqueue(ha->wq);
313 ha->wq = NULL;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700314fail:
315 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700316 kfree(ha->req_q_map);
317 kfree(ha->rsp_q_map);
318 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700319 return 1;
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800323qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800325 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 static char *pci_bus_modes[] = {
327 "33", "66", "100", "133",
328 };
329 uint16_t pci_bus;
330
331 strcpy(str, "PCI");
332 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
333 if (pci_bus) {
334 strcat(str, "-X (");
335 strcat(str, pci_bus_modes[pci_bus]);
336 } else {
337 pci_bus = (ha->pci_attr & BIT_8) >> 8;
338 strcat(str, " (");
339 strcat(str, pci_bus_modes[pci_bus]);
340 }
341 strcat(str, " MHz)");
342
343 return (str);
344}
345
Andrew Vasquezfca29702005-07-06 10:31:47 -0700346static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800347qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700348{
349 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700351 uint32_t pci_bus;
352 int pcie_reg;
353
354 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
355 if (pcie_reg) {
356 char lwstr[6];
357 uint16_t pcie_lstat, lspeed, lwidth;
358
359 pcie_reg += 0x12;
360 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
361 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
362 lwidth = (pcie_lstat &
363 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
364
365 strcpy(str, "PCIe (");
366 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700367 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700368 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700369 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700370 else
371 strcat(str, "<unknown> ");
372 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
373 strcat(str, lwstr);
374
375 return str;
376 }
377
378 strcpy(str, "PCI");
379 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
380 if (pci_bus == 0 || pci_bus == 8) {
381 strcat(str, " (");
382 strcat(str, pci_bus_modes[pci_bus >> 3]);
383 } else {
384 strcat(str, "-X ");
385 if (pci_bus & BIT_2)
386 strcat(str, "Mode 2");
387 else
388 strcat(str, "Mode 1");
389 strcat(str, " (");
390 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
391 }
392 strcat(str, " MHz)");
393
394 return str;
395}
396
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800397static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800398qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800401 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
404 ha->fw_minor_version,
405 ha->fw_subminor_version);
406
407 if (ha->fw_attributes & BIT_9) {
408 strcat(str, "FLX");
409 return (str);
410 }
411
412 switch (ha->fw_attributes & 0xFF) {
413 case 0x7:
414 strcat(str, "EF");
415 break;
416 case 0x17:
417 strcat(str, "TP");
418 break;
419 case 0x37:
420 strcat(str, "IP");
421 break;
422 case 0x77:
423 strcat(str, "VI");
424 break;
425 default:
426 sprintf(un_str, "(%x)", ha->fw_attributes);
427 strcat(str, un_str);
428 break;
429 }
430 if (ha->fw_attributes & 0x100)
431 strcat(str, "X");
432
433 return (str);
434}
435
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800436static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800437qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700438{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800439 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700440
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800441 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
442 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700443 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700444}
445
446static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800447qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700448 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
449{
450 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800451 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700452
453 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
454 if (!sp)
455 return sp;
456
Andrew Vasquezfca29702005-07-06 10:31:47 -0700457 sp->fcport = fcport;
458 sp->cmd = cmd;
459 sp->flags = 0;
460 CMD_SP(cmd) = (void *)sp;
461 cmd->scsi_done = done;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700462 sp->ctx = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700463
464 return sp;
465}
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700468qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700469{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800470 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700471 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400472 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800473 struct qla_hw_data *ha = vha->hw;
474 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700475 srb_t *sp;
476 int rval;
477
Andrew Vasquez85880802009-12-15 21:29:46 -0800478 if (ha->flags.eeh_busy) {
479 if (ha->flags.pci_channel_io_perm_failure)
Seokmann Jub9b12f72009-03-24 09:08:18 -0700480 cmd->result = DID_NO_CONNECT << 16;
Andrew Vasquez85880802009-12-15 21:29:46 -0800481 else
482 cmd->result = DID_REQUEUE << 16;
Seokmann Ju14e660e2007-09-20 14:07:36 -0700483 goto qc24_fail_command;
484 }
485
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400486 rval = fc_remote_port_chkready(rport);
487 if (rval) {
488 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700489 goto qc24_fail_command;
490 }
491
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800492 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500493 if (fcport->drport)
494 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800495
Andrew Vasquezfca29702005-07-06 10:31:47 -0700496 if (atomic_read(&fcport->state) != FCS_ONLINE) {
497 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800498 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700499 cmd->result = DID_NO_CONNECT << 16;
500 goto qc24_fail_command;
501 }
Mike Christie7b594132008-08-17 15:24:40 -0500502 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700503 }
504
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800505 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700508 if (!sp)
509 goto qc24_host_busy_lock;
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700512 if (rval != QLA_SUCCESS)
513 goto qc24_host_busy_free_sp;
514
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700516
517 return 0;
518
519qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800520 qla2x00_sp_free_dma(sp);
521 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522
523qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700525 return SCSI_MLQUEUE_HOST_BUSY;
526
Mike Christie7b594132008-08-17 15:24:40 -0500527qc24_target_busy:
528 return SCSI_MLQUEUE_TARGET_BUSY;
529
Andrew Vasquezfca29702005-07-06 10:31:47 -0700530qc24_fail_command:
531 done(cmd);
532
533 return 0;
534}
535
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537/*
538 * qla2x00_eh_wait_on_command
539 * Waits for the command to be returned by the Firmware for some
540 * max time.
541 *
542 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 *
545 * Return:
546 * Not Found : 0
547 * Found : 1
548 */
549static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700552#define ABORT_POLLING_PERIOD 1000
553#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500554 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800555 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
556 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500557 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Andrew Vasquez85880802009-12-15 21:29:46 -0800559 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
560 DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
561 return ret;
562 }
563
Lalit Chandivaded9704322009-08-25 11:36:18 -0700564 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700565 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500566 }
567 if (CMD_SP(cmd))
568 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
f4f051e2005-04-17 15:02:26 -0500570 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
573/*
574 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700575 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 * <= MAX_RETRIES_OF_ISP_ABORT or
577 * finally HBA is disabled ie marked offline
578 *
579 * Input:
580 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700581 *
582 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 * Does context switching-Release SPIN_LOCK
584 * (if any) before calling this routine.
585 *
586 * Return:
587 * Success (Adapter is online) : 0
588 * Failed (Adapter is offline/disabled) : 1
589 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800590int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700593 int return_status;
594 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800595 struct qla_hw_data *ha = vha->hw;
596 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700598 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
600 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
601 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
602 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 msleep(1000);
605 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800606 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700607 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 else
609 return_status = QLA_FUNCTION_FAILED;
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 return (return_status);
612}
613
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700614int
615qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
616{
617 int return_status;
618 unsigned long wait_reset;
619 struct qla_hw_data *ha = vha->hw;
620 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
621
622 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
623 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
624 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
625 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
626 ha->dpc_active) && time_before(jiffies, wait_reset)) {
627
628 msleep(1000);
629
630 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
631 ha->flags.chip_reset_done)
632 break;
633 }
634 if (ha->flags.chip_reset_done)
635 return_status = QLA_SUCCESS;
636 else
637 return_status = QLA_FUNCTION_FAILED;
638
639 return return_status;
640}
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642/*
643 * qla2x00_wait_for_loop_ready
644 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700645 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 * Input:
647 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700648 *
649 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 * Does context switching-Release SPIN_LOCK
651 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700652 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 *
654 * Return:
655 * Success (LOOP_READY) : 0
656 * Failed (LOOP_NOT_READY) : 1
657 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700658static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800659qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
661 int return_status = QLA_SUCCESS;
662 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663 struct qla_hw_data *ha = vha->hw;
664 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700667 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800669 while ((!atomic_read(&base_vha->loop_down_timer) &&
670 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
671 atomic_read(&base_vha->loop_state) != LOOP_READY) {
672 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700673 return_status = QLA_FUNCTION_FAILED;
674 break;
675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 msleep(1000);
677 if (time_after_eq(jiffies, loop_timeout)) {
678 return_status = QLA_FUNCTION_FAILED;
679 break;
680 }
681 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700682 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700685void
686qla2x00_abort_fcport_cmds(fc_port_t *fcport)
687{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700688 int cnt;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700689 unsigned long flags;
690 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800691 scsi_qla_host_t *vha = fcport->vha;
692 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800693 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800695 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700696 req = vha->req;
697 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
698 sp = req->outstanding_cmds[cnt];
699 if (!sp)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700700 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700701 if (sp->fcport != fcport)
702 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700703 if (sp->ctx)
704 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700705
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
707 if (ha->isp_ops->abort_command(sp)) {
708 DEBUG2(qla_printk(KERN_WARNING, ha,
709 "Abort failed -- %lx\n",
710 sp->cmd->serial_number));
711 } else {
712 if (qla2x00_eh_wait_on_command(sp->cmd) !=
713 QLA_SUCCESS)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700714 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700715 "Abort failed while waiting -- %lx\n",
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800716 sp->cmd->serial_number));
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700717 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700718 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700719 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800720 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700721}
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723/**************************************************************************
724* qla2xxx_eh_abort
725*
726* Description:
727* The abort function will abort the specified command.
728*
729* Input:
730* cmd = Linux SCSI command packet to be aborted.
731*
732* Returns:
733* Either SUCCESS or FAILED.
734*
735* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700736* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800738static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739qla2xxx_eh_abort(struct scsi_cmnd *cmd)
740{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500742 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800743 int ret, i;
f4f051e2005-04-17 15:02:26 -0500744 unsigned int id, lun;
745 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700746 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700747 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800748 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700749 struct req_que *req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800750 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Christof Schmitt65d430f2009-10-30 17:59:29 +0100752 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -0700753
f4f051e2005-04-17 15:02:26 -0500754 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700755 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Michael Reed2ea00202006-04-27 16:25:30 -0700757 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
f4f051e2005-04-17 15:02:26 -0500759 id = cmd->device->id;
760 lun = cmd->device->lun;
761 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800762 spt = (srb_t *) CMD_SP(cmd);
763 if (!spt)
764 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500765
766 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800767 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800768 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
769 sp = req->outstanding_cmds[i];
770
771 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500772 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700773 if (sp->ctx)
774 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800775 if (sp->cmd != cmd)
776 continue;
f4f051e2005-04-17 15:02:26 -0500777
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800778 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
779 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500780
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700782 if (ha->isp_ops->abort_command(sp)) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800783 DEBUG2(printk("%s(%ld): abort_command "
784 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800785 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800786 } else {
787 DEBUG3(printk("%s(%ld): abort_command "
788 "mbx success.\n", __func__, vha->host_no));
789 wait = 1;
f4f051e2005-04-17 15:02:26 -0500790 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800791 spin_lock_irqsave(&ha->hardware_lock, flags);
792 break;
f4f051e2005-04-17 15:02:26 -0500793 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500795
796 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700797 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800798 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700799 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500800 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800801 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700802 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700806 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700807 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800808 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
f4f051e2005-04-17 15:02:26 -0500810 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
Andrew Vasquez523ec772008-04-03 13:13:24 -0700813enum nexus_wait_type {
814 WAIT_HOST = 0,
815 WAIT_TARGET,
816 WAIT_LUN,
817};
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800821 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800823 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700824 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800825 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800826 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Andrew Vasquez523ec772008-04-03 13:13:24 -0700828 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800829 if (!sp)
830 return status;
831
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700833 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800834 for (cnt = 1; status == QLA_SUCCESS &&
835 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
836 sp = req->outstanding_cmds[cnt];
837 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700838 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700839 if (sp->ctx)
840 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800841 if (vha->vp_idx != sp->fcport->vha->vp_idx)
842 continue;
843 match = 0;
844 switch (type) {
845 case WAIT_HOST:
846 match = 1;
847 break;
848 case WAIT_TARGET:
849 match = sp->cmd->device->id == t;
850 break;
851 case WAIT_LUN:
852 match = (sp->cmd->device->id == t &&
853 sp->cmd->device->lun == l);
854 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800856 if (!match)
857 continue;
858
859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
860 status = qla2x00_eh_wait_on_command(sp->cmd);
861 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800863 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700864
865 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
867
Andrew Vasquez523ec772008-04-03 13:13:24 -0700868static char *reset_errors[] = {
869 "HBA not online",
870 "HBA not ready",
871 "Task management failed",
872 "Waiting for command completions",
873};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Andrew Vasquez523ec772008-04-03 13:13:24 -0700875static int
876__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700877 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700878{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800879 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700880 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
881 int err;
882
Christof Schmitt65d430f2009-10-30 17:59:29 +0100883 fc_block_scsi_eh(cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700884
885 if (!fcport)
886 return FAILED;
887
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800888 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
889 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700890
891 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800892 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700893 goto eh_reset_failed;
894 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800895 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700896 goto eh_reset_failed;
897 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700898 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
899 != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700900 goto eh_reset_failed;
901 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800902 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800903 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700904 goto eh_reset_failed;
905
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800906 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
907 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700908
909 return SUCCESS;
910
911 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800912 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
913 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700914 reset_errors[err]);
915 return FAILED;
916}
917
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800918static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
920{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800921 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
922 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Andrew Vasquez523ec772008-04-03 13:13:24 -0700924 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
925 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700929qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
932 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Andrew Vasquez523ec772008-04-03 13:13:24 -0700934 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
935 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938/**************************************************************************
939* qla2xxx_eh_bus_reset
940*
941* Description:
942* The bus reset function will reset the bus and abort any executing
943* commands.
944*
945* Input:
946* cmd = Linux SCSI command packet of the command that cause the
947* bus reset.
948*
949* Returns:
950* SUCCESS/FAILURE (defined as macro in scsi.h).
951*
952**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800953static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
955{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800956 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500957 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700958 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500959 unsigned int id, lun;
960 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800961 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Christof Schmitt65d430f2009-10-30 17:59:29 +0100963 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -0700964
f4f051e2005-04-17 15:02:26 -0500965 id = cmd->device->id;
966 lun = cmd->device->lun;
967 serial = cmd->serial_number;
968
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700969 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500970 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800972 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800973 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800975 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500977 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 }
979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
981 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500982 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
f4f051e2005-04-17 15:02:26 -0500984 if (ret == FAILED)
985 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700987 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800988 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -0700989 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700990 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
f4f051e2005-04-17 15:02:26 -0500992eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800993 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500994 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
f4f051e2005-04-17 15:02:26 -0500996 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
999/**************************************************************************
1000* qla2xxx_eh_host_reset
1001*
1002* Description:
1003* The reset function will reset the Adapter.
1004*
1005* Input:
1006* cmd = Linux SCSI command packet of the command that cause the
1007* adapter reset.
1008*
1009* Returns:
1010* Either SUCCESS or FAILED.
1011*
1012* Note:
1013**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001014static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1016{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001017 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001018 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001019 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001020 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001021 unsigned int id, lun;
1022 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001023 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001024 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Christof Schmitt65d430f2009-10-30 17:59:29 +01001026 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -07001027
f4f051e2005-04-17 15:02:26 -05001028 id = cmd->device->id;
1029 lun = cmd->device->lun;
1030 serial = cmd->serial_number;
1031
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001032 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001033 return ret;
1034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001036 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001038 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001039 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041 /*
1042 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001043 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 * be completed and then issue big hammer.Otherwise
1045 * it may cause I/O failure as big hammer marks the
1046 * devices as lost kicking of the port_down_timer
1047 * while dpc is stuck for the mailbox to complete.
1048 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001049 qla2x00_wait_for_loop_ready(vha);
1050 if (vha != base_vha) {
1051 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001052 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001053 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001054 if (ha->wq)
1055 flush_workqueue(ha->wq);
1056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1058 if (qla2x00_abort_isp(base_vha)) {
1059 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1060 /* failed. schedule dpc to try */
1061 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1062
1063 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1064 goto eh_host_reset_lock;
1065 }
1066 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001070 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001071 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001072 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
f4f051e2005-04-17 15:02:26 -05001074eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001075 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1076 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
f4f051e2005-04-17 15:02:26 -05001078 return ret;
1079}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081/*
1082* qla2x00_loop_reset
1083* Issue loop reset.
1084*
1085* Input:
1086* ha = adapter block pointer.
1087*
1088* Returns:
1089* 0 = success
1090*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001091int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001092qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001094 int ret;
bdf79622005-04-17 15:06:53 -05001095 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001096 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001098 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001099 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001100 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001101 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001102 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001103 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001104 }
1105 atomic_set(&vha->loop_state, LOOP_DOWN);
1106 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1107 qla2x00_mark_all_devices_lost(vha, 0);
1108 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
1110
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001111 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001113 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001114 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1116 } else
1117 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001118 }
1119
1120 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001121 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001122 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 continue;
1124
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001125 ret = ha->isp_ops->target_reset(fcport, 0, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001126 if (ret != QLA_SUCCESS) {
1127 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1128 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001129 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 }
1132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001134 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001136 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001139void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001140qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001141{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001142 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001143 unsigned long flags;
1144 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001145 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001146 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001147 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001148
1149 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001150 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001151 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001152 if (!req)
1153 continue;
1154 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1155 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001156 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001157 req->outstanding_cmds[cnt] = NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001158 if (!sp->ctx) {
1159 sp->cmd->result = res;
1160 qla2x00_sp_compl(ha, sp);
1161 } else {
1162 ctx = sp->ctx;
1163 del_timer_sync(&ctx->timer);
1164 ctx->free(sp);
1165 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001166 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001167 }
1168 }
1169 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1170}
1171
f4f051e2005-04-17 15:02:26 -05001172static int
1173qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
bdf79622005-04-17 15:06:53 -05001175 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001177 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001178 return -ENXIO;
1179
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001180 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001181
1182 return 0;
1183}
1184
1185static int
1186qla2xxx_slave_configure(struct scsi_device *sdev)
1187{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001188 scsi_qla_host_t *vha = shost_priv(sdev->host);
1189 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001190 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001191 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001192
f4f051e2005-04-17 15:02:26 -05001193 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001194 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Andrew Vasquez85821c92008-07-10 16:55:48 -07001198 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001199
f4f051e2005-04-17 15:02:26 -05001200 return 0;
1201}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
f4f051e2005-04-17 15:02:26 -05001203static void
1204qla2xxx_slave_destroy(struct scsi_device *sdev)
1205{
1206 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001209static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1210{
1211 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1212
1213 if (!scsi_track_queue_full(sdev, qdepth))
1214 return;
1215
1216 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1217 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1218 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1219 sdev->queue_depth));
1220}
1221
1222static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1223{
1224 fc_port_t *fcport = sdev->hostdata;
1225 struct scsi_qla_host *vha = fcport->vha;
1226 struct qla_hw_data *ha = vha->hw;
1227 struct req_que *req = NULL;
1228
1229 req = vha->req;
1230 if (!req)
1231 return;
1232
1233 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1234 return;
1235
1236 if (sdev->ordered_tags)
1237 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1238 else
1239 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1240
1241 DEBUG2(qla_printk(KERN_INFO, ha,
1242 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1243 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1244 sdev->queue_depth));
1245}
1246
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001247static int
Mike Christiee881a172009-10-15 17:46:39 -07001248qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001249{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001250 switch (reason) {
1251 case SCSI_QDEPTH_DEFAULT:
1252 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1253 break;
1254 case SCSI_QDEPTH_QFULL:
1255 qla2x00_handle_queue_full(sdev, qdepth);
1256 break;
1257 case SCSI_QDEPTH_RAMP_UP:
1258 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1259 break;
1260 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001261 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001262 }
Mike Christiee881a172009-10-15 17:46:39 -07001263
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001264 return sdev->queue_depth;
1265}
1266
1267static int
1268qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1269{
1270 if (sdev->tagged_supported) {
1271 scsi_set_tag_type(sdev, tag_type);
1272 if (tag_type)
1273 scsi_activate_tcq(sdev, sdev->queue_depth);
1274 else
1275 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1276 } else
1277 tag_type = 0;
1278
1279 return tag_type;
1280}
1281
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282/**
1283 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1284 * @ha: HA context
1285 *
1286 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1287 * supported addressing method.
1288 */
1289static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001290qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001292 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Yang Hongyang6a355282009-04-06 19:01:13 -07001295 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001296 /* Any upper-dword bits set? */
1297 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001298 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001299 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001301 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1302 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001303 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001306
Yang Hongyang284901a2009-04-06 19:01:15 -07001307 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1308 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309}
1310
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001311static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001313{
1314 unsigned long flags = 0;
1315 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1316
1317 spin_lock_irqsave(&ha->hardware_lock, flags);
1318 ha->interrupts_on = 1;
1319 /* enable risc and host interrupts */
1320 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1321 RD_REG_WORD(&reg->ictrl);
1322 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1323
1324}
1325
1326static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001328{
1329 unsigned long flags = 0;
1330 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1331
1332 spin_lock_irqsave(&ha->hardware_lock, flags);
1333 ha->interrupts_on = 0;
1334 /* disable risc and host interrupts */
1335 WRT_REG_WORD(&reg->ictrl, 0);
1336 RD_REG_WORD(&reg->ictrl);
1337 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1338}
1339
1340static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001341qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001342{
1343 unsigned long flags = 0;
1344 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1345
1346 spin_lock_irqsave(&ha->hardware_lock, flags);
1347 ha->interrupts_on = 1;
1348 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1349 RD_REG_DWORD(&reg->ictrl);
1350 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1351}
1352
1353static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001354qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001355{
1356 unsigned long flags = 0;
1357 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1358
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001359 if (IS_NOPOLLING_TYPE(ha))
1360 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001361 spin_lock_irqsave(&ha->hardware_lock, flags);
1362 ha->interrupts_on = 0;
1363 WRT_REG_DWORD(&reg->ictrl, 0);
1364 RD_REG_DWORD(&reg->ictrl);
1365 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1366}
1367
1368static struct isp_operations qla2100_isp_ops = {
1369 .pci_config = qla2100_pci_config,
1370 .reset_chip = qla2x00_reset_chip,
1371 .chip_diag = qla2x00_chip_diag,
1372 .config_rings = qla2x00_config_rings,
1373 .reset_adapter = qla2x00_reset_adapter,
1374 .nvram_config = qla2x00_nvram_config,
1375 .update_fw_options = qla2x00_update_fw_options,
1376 .load_risc = qla2x00_load_risc,
1377 .pci_info_str = qla2x00_pci_info_str,
1378 .fw_version_str = qla2x00_fw_version_str,
1379 .intr_handler = qla2100_intr_handler,
1380 .enable_intrs = qla2x00_enable_intrs,
1381 .disable_intrs = qla2x00_disable_intrs,
1382 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001383 .target_reset = qla2x00_abort_target,
1384 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001385 .fabric_login = qla2x00_login_fabric,
1386 .fabric_logout = qla2x00_fabric_logout,
1387 .calc_req_entries = qla2x00_calc_iocbs_32,
1388 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1389 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1390 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1391 .read_nvram = qla2x00_read_nvram_data,
1392 .write_nvram = qla2x00_write_nvram_data,
1393 .fw_dump = qla2100_fw_dump,
1394 .beacon_on = NULL,
1395 .beacon_off = NULL,
1396 .beacon_blink = NULL,
1397 .read_optrom = qla2x00_read_optrom_data,
1398 .write_optrom = qla2x00_write_optrom_data,
1399 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001400 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001401};
1402
1403static struct isp_operations qla2300_isp_ops = {
1404 .pci_config = qla2300_pci_config,
1405 .reset_chip = qla2x00_reset_chip,
1406 .chip_diag = qla2x00_chip_diag,
1407 .config_rings = qla2x00_config_rings,
1408 .reset_adapter = qla2x00_reset_adapter,
1409 .nvram_config = qla2x00_nvram_config,
1410 .update_fw_options = qla2x00_update_fw_options,
1411 .load_risc = qla2x00_load_risc,
1412 .pci_info_str = qla2x00_pci_info_str,
1413 .fw_version_str = qla2x00_fw_version_str,
1414 .intr_handler = qla2300_intr_handler,
1415 .enable_intrs = qla2x00_enable_intrs,
1416 .disable_intrs = qla2x00_disable_intrs,
1417 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001418 .target_reset = qla2x00_abort_target,
1419 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001420 .fabric_login = qla2x00_login_fabric,
1421 .fabric_logout = qla2x00_fabric_logout,
1422 .calc_req_entries = qla2x00_calc_iocbs_32,
1423 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1424 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1425 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1426 .read_nvram = qla2x00_read_nvram_data,
1427 .write_nvram = qla2x00_write_nvram_data,
1428 .fw_dump = qla2300_fw_dump,
1429 .beacon_on = qla2x00_beacon_on,
1430 .beacon_off = qla2x00_beacon_off,
1431 .beacon_blink = qla2x00_beacon_blink,
1432 .read_optrom = qla2x00_read_optrom_data,
1433 .write_optrom = qla2x00_write_optrom_data,
1434 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001435 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001436};
1437
1438static struct isp_operations qla24xx_isp_ops = {
1439 .pci_config = qla24xx_pci_config,
1440 .reset_chip = qla24xx_reset_chip,
1441 .chip_diag = qla24xx_chip_diag,
1442 .config_rings = qla24xx_config_rings,
1443 .reset_adapter = qla24xx_reset_adapter,
1444 .nvram_config = qla24xx_nvram_config,
1445 .update_fw_options = qla24xx_update_fw_options,
1446 .load_risc = qla24xx_load_risc,
1447 .pci_info_str = qla24xx_pci_info_str,
1448 .fw_version_str = qla24xx_fw_version_str,
1449 .intr_handler = qla24xx_intr_handler,
1450 .enable_intrs = qla24xx_enable_intrs,
1451 .disable_intrs = qla24xx_disable_intrs,
1452 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001453 .target_reset = qla24xx_abort_target,
1454 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001455 .fabric_login = qla24xx_login_fabric,
1456 .fabric_logout = qla24xx_fabric_logout,
1457 .calc_req_entries = NULL,
1458 .build_iocbs = NULL,
1459 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1460 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1461 .read_nvram = qla24xx_read_nvram_data,
1462 .write_nvram = qla24xx_write_nvram_data,
1463 .fw_dump = qla24xx_fw_dump,
1464 .beacon_on = qla24xx_beacon_on,
1465 .beacon_off = qla24xx_beacon_off,
1466 .beacon_blink = qla24xx_beacon_blink,
1467 .read_optrom = qla24xx_read_optrom_data,
1468 .write_optrom = qla24xx_write_optrom_data,
1469 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001471};
1472
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001473static struct isp_operations qla25xx_isp_ops = {
1474 .pci_config = qla25xx_pci_config,
1475 .reset_chip = qla24xx_reset_chip,
1476 .chip_diag = qla24xx_chip_diag,
1477 .config_rings = qla24xx_config_rings,
1478 .reset_adapter = qla24xx_reset_adapter,
1479 .nvram_config = qla24xx_nvram_config,
1480 .update_fw_options = qla24xx_update_fw_options,
1481 .load_risc = qla24xx_load_risc,
1482 .pci_info_str = qla24xx_pci_info_str,
1483 .fw_version_str = qla24xx_fw_version_str,
1484 .intr_handler = qla24xx_intr_handler,
1485 .enable_intrs = qla24xx_enable_intrs,
1486 .disable_intrs = qla24xx_disable_intrs,
1487 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001488 .target_reset = qla24xx_abort_target,
1489 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001490 .fabric_login = qla24xx_login_fabric,
1491 .fabric_logout = qla24xx_fabric_logout,
1492 .calc_req_entries = NULL,
1493 .build_iocbs = NULL,
1494 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1495 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1496 .read_nvram = qla25xx_read_nvram_data,
1497 .write_nvram = qla25xx_write_nvram_data,
1498 .fw_dump = qla25xx_fw_dump,
1499 .beacon_on = qla24xx_beacon_on,
1500 .beacon_off = qla24xx_beacon_off,
1501 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001502 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001503 .write_optrom = qla24xx_write_optrom_data,
1504 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001505 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001506};
1507
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001508static struct isp_operations qla81xx_isp_ops = {
1509 .pci_config = qla25xx_pci_config,
1510 .reset_chip = qla24xx_reset_chip,
1511 .chip_diag = qla24xx_chip_diag,
1512 .config_rings = qla24xx_config_rings,
1513 .reset_adapter = qla24xx_reset_adapter,
1514 .nvram_config = qla81xx_nvram_config,
1515 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001516 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001517 .pci_info_str = qla24xx_pci_info_str,
1518 .fw_version_str = qla24xx_fw_version_str,
1519 .intr_handler = qla24xx_intr_handler,
1520 .enable_intrs = qla24xx_enable_intrs,
1521 .disable_intrs = qla24xx_disable_intrs,
1522 .abort_command = qla24xx_abort_command,
1523 .target_reset = qla24xx_abort_target,
1524 .lun_reset = qla24xx_lun_reset,
1525 .fabric_login = qla24xx_login_fabric,
1526 .fabric_logout = qla24xx_fabric_logout,
1527 .calc_req_entries = NULL,
1528 .build_iocbs = NULL,
1529 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1530 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001531 .read_nvram = NULL,
1532 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001533 .fw_dump = qla81xx_fw_dump,
1534 .beacon_on = qla24xx_beacon_on,
1535 .beacon_off = qla24xx_beacon_off,
1536 .beacon_blink = qla24xx_beacon_blink,
1537 .read_optrom = qla25xx_read_optrom_data,
1538 .write_optrom = qla24xx_write_optrom_data,
1539 .get_flash_version = qla24xx_get_flash_version,
1540 .start_scsi = qla24xx_start_scsi,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001541};
1542
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001543static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001545{
1546 ha->device_type = DT_EXTENDED_IDS;
1547 switch (ha->pdev->device) {
1548 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1549 ha->device_type |= DT_ISP2100;
1550 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001551 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001552 break;
1553 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1554 ha->device_type |= DT_ISP2200;
1555 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001556 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001557 break;
1558 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1559 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001560 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001561 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001562 break;
1563 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1564 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001565 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001566 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001567 break;
1568 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1569 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001570 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001571 if (ha->pdev->subsystem_vendor == 0x1028 &&
1572 ha->pdev->subsystem_device == 0x0170)
1573 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001574 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001575 break;
1576 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1577 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001578 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001579 break;
1580 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1581 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001582 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001583 break;
1584 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1585 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001586 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001587 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001588 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001589 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001590 break;
1591 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1592 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001593 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001594 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001595 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001596 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001597 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001598 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1599 ha->device_type |= DT_ISP8432;
1600 ha->device_type |= DT_ZIO_SUPPORTED;
1601 ha->device_type |= DT_FWI2;
1602 ha->device_type |= DT_IIDMA;
1603 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1604 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001605 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1606 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001607 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001608 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001609 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001610 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1611 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001612 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001613 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001614 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001615 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1616 ha->device_type |= DT_ISP2532;
1617 ha->device_type |= DT_ZIO_SUPPORTED;
1618 ha->device_type |= DT_FWI2;
1619 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001620 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1621 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001622 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1623 ha->device_type |= DT_ISP8001;
1624 ha->device_type |= DT_ZIO_SUPPORTED;
1625 ha->device_type |= DT_FWI2;
1626 ha->device_type |= DT_IIDMA;
1627 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1628 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001629 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001630
1631 /* Get adapter physical port no from interrupt pin register. */
1632 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1633 if (ha->port_no & 1)
1634 ha->flags.port0 = 1;
1635 else
1636 ha->flags.port0 = 0;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001637}
1638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Andrew Vasquez37765412008-01-17 09:02:09 -08001642 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001643 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001644 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Andrew Vasquez285d0322007-10-19 15:59:17 -07001646 if (pci_request_selected_regions(ha->pdev, ha->bars,
1647 QLA2XXX_DRIVER_NAME)) {
1648 qla_printk(KERN_WARNING, ha,
1649 "Failed to reserve PIO/MMIO regions (%s)\n",
1650 pci_name(ha->pdev));
1651
1652 goto iospace_error_exit;
1653 }
1654 if (!(ha->bars & 1))
1655 goto skip_pio;
1656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1658 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001659 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1660 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 qla_printk(KERN_WARNING, ha,
1662 "Invalid PCI I/O region size (%s)...\n",
1663 pci_name(ha->pdev));
1664 pio = 0;
1665 }
1666 } else {
1667 qla_printk(KERN_WARNING, ha,
1668 "region #0 not a PIO resource (%s)...\n",
1669 pci_name(ha->pdev));
1670 pio = 0;
1671 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001672 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Andrew Vasquez285d0322007-10-19 15:59:17 -07001674skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001676 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001678 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 pci_name(ha->pdev));
1680 goto iospace_error_exit;
1681 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001682 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 qla_printk(KERN_ERR, ha,
1684 "Invalid PCI mem region size (%s), aborting\n",
1685 pci_name(ha->pdev));
1686 goto iospace_error_exit;
1687 }
1688
Andrew Vasquez37765412008-01-17 09:02:09 -08001689 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 if (!ha->iobase) {
1691 qla_printk(KERN_ERR, ha,
1692 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1693
1694 goto iospace_error_exit;
1695 }
1696
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001697 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001698 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001699 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001700 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001701 goto mqiobase_exit;
1702 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1703 pci_resource_len(ha->pdev, 3));
1704 if (ha->mqiobase) {
1705 /* Read MSIX vector size of the board */
1706 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1707 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001708 /* Max queues are bounded by available msix vectors */
1709 /* queue 0 uses two msix vectors */
1710 if (ql2xmultique_tag) {
1711 cpus = num_online_cpus();
Anirban Chakraborty27dc9c52009-06-17 10:30:28 -07001712 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001713 (cpus + 1) : (ha->msix_count - 1);
1714 ha->max_req_queues = 2;
1715 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001716 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1717 QLA_MQ_SIZE : ql2xmaxqueues;
1718 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1719 " of request queues:%d\n", ha->max_req_queues));
1720 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001721 qla_printk(KERN_INFO, ha,
1722 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001723 } else
1724 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001725
1726mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001727 ha->msix_count = ha->max_rsp_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 return (0);
1729
1730iospace_error_exit:
1731 return (-ENOMEM);
1732}
1733
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001734static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001735qla2xxx_scan_start(struct Scsi_Host *shost)
1736{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001737 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001738
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001739 if (vha->hw->flags.running_gold_fw)
1740 return;
1741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001742 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1743 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1744 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1745 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001746}
1747
1748static int
1749qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1750{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001751 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001752
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001753 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001754 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001755 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001756 return 1;
1757
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001758 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001759}
1760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761/*
1762 * PCI driver interface
1763 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001764static int __devinit
1765qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001767 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769 scsi_qla_host_t *base_vha = NULL;
1770 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001771 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001773 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001774 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001775 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001776 struct req_que *req = NULL;
1777 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Andrew Vasquez285d0322007-10-19 15:59:17 -07001779 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001780 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001781 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1782 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001783 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001784 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1785 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001786 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1787 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001788 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001789 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001790 }
1791
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001792 if (mem_only) {
1793 if (pci_enable_device_mem(pdev))
1794 goto probe_out;
1795 } else {
1796 if (pci_enable_device(pdev))
1797 goto probe_out;
1798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
Jesse Barnes09276782008-10-18 17:33:19 -07001800 /* This may fail but that's ok */
1801 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001802
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001803 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1804 if (!ha) {
1805 DEBUG(printk("Unable to allocate memory for ha\n"));
1806 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001808 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001811 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001812 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001813 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001815 /* Set ISP-type information. */
1816 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08001817
1818 /* Set EEH reset type to fundamental if required by hba */
1819 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
1820 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08001821 }
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 /* Configure PCI I/O space */
1824 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001825 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001826 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001829 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1830 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001833 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001834 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001835 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001837 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001838 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001842 req_length = REQUEST_ENTRY_CNT_2100;
1843 rsp_length = RESPONSE_ENTRY_CNT_2100;
1844 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001845 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001846 ha->flash_conf_off = ~0;
1847 ha->flash_data_off = ~0;
1848 ha->nvram_conf_off = ~0;
1849 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001850 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001853 req_length = REQUEST_ENTRY_CNT_2200;
1854 rsp_length = RESPONSE_ENTRY_CNT_2100;
1855 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001856 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001857 ha->flash_conf_off = ~0;
1858 ha->flash_data_off = ~0;
1859 ha->nvram_conf_off = ~0;
1860 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001861 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001862 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001864 req_length = REQUEST_ENTRY_CNT_2200;
1865 rsp_length = RESPONSE_ENTRY_CNT_2300;
1866 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001867 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001868 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1869 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001870 ha->flash_conf_off = ~0;
1871 ha->flash_data_off = ~0;
1872 ha->nvram_conf_off = ~0;
1873 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001874 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001875 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001876 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001877 req_length = REQUEST_ENTRY_CNT_24XX;
1878 rsp_length = RESPONSE_ENTRY_CNT_2300;
1879 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001880 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001881 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001882 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001883 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001884 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001885 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1886 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1887 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1888 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001889 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001890 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001891 req_length = REQUEST_ENTRY_CNT_24XX;
1892 rsp_length = RESPONSE_ENTRY_CNT_2300;
1893 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001894 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001895 ha->gid_list_info_size = 8;
1896 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001897 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001898 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001899 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1900 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1901 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1902 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1903 } else if (IS_QLA81XX(ha)) {
1904 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1905 req_length = REQUEST_ENTRY_CNT_24XX;
1906 rsp_length = RESPONSE_ENTRY_CNT_2300;
1907 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1908 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1909 ha->gid_list_info_size = 8;
1910 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001911 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001912 ha->isp_ops = &qla81xx_isp_ops;
1913 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1914 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1915 ha->nvram_conf_off = ~0;
1916 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001919 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001920 init_completion(&ha->mbx_cmd_comp);
1921 complete(&ha->mbx_cmd_comp);
1922 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001924 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Andrew Vasquez53303c42009-01-22 09:45:37 -08001926 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001927 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 qla_printk(KERN_WARNING, ha,
1930 "[ERROR] Failed to allocate memory for adapter\n");
1931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 goto probe_hw_failed;
1933 }
1934
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001935 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001936 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001937 req->max_q_depth = ql2xmaxqdepth;
1938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001939
1940 base_vha = qla2x00_create_host(sht, ha);
1941 if (!base_vha) {
1942 qla_printk(KERN_WARNING, ha,
1943 "[ERROR] Failed to allocate memory for scsi_host\n");
1944
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001945 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001946 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001947 qla2x00_free_req_que(ha, req);
1948 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 }
1951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001955 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001956 host->can_queue = req->length + 128;
1957 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001958 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001959 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1961 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 if (IS_QLA2100(ha))
1963 host->sg_tablesize = 32;
1964 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001965 host->this_id = 255;
1966 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001967 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001968 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001969 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001970 host->max_lun = MAX_LUNS;
1971 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001972 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001973
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001974 /* Set up the irqs */
1975 ret = qla2x00_request_irqs(ha, rsp);
1976 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001977 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08001978
1979 pci_save_state(pdev);
1980
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001981 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001982que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001983 if (!qla2x00_alloc_queues(ha)) {
1984 qla_printk(KERN_WARNING, ha,
1985 "[ERROR] Failed to allocate memory for queue"
1986 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001987 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001988 }
1989 ha->rsp_q_map[0] = rsp;
1990 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001991 rsp->req = req;
1992 req->rsp = rsp;
1993 set_bit(0, ha->req_qid_map);
1994 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07001995 /* FWI2-capable only. */
1996 req->req_q_in = &ha->iobase->isp24.req_q_in;
1997 req->req_q_out = &ha->iobase->isp24.req_q_out;
1998 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1999 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002000 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002001 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2002 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2003 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2004 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002005 }
2006
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 if (qla2x00_initialize_adapter(base_vha)) {
2008 qla_printk(KERN_WARNING, ha,
2009 "Failed to initialize adapter\n");
2010
2011 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2012 "Adapter flags %x.\n",
2013 base_vha->host_no, base_vha->device_flags));
2014
2015 ret = -ENODEV;
2016 goto probe_failed;
2017 }
2018
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002019 if (ha->mqenable) {
2020 if (qla25xx_setup_mode(base_vha)) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002021 qla_printk(KERN_WARNING, ha,
2022 "Can't create queues, falling back to single"
2023 " queue mode\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002024 goto que_init;
2025 }
2026 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002027
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002028 if (ha->flags.running_gold_fw)
2029 goto skip_dpc;
2030
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 /*
2032 * Startup the kernel thread for this host adapter
2033 */
2034 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2035 "%s_dpc", base_vha->host_str);
2036 if (IS_ERR(ha->dpc_thread)) {
2037 qla_printk(KERN_WARNING, ha,
2038 "Unable to start DPC thread!\n");
2039 ret = PTR_ERR(ha->dpc_thread);
2040 goto probe_failed;
2041 }
2042
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002043skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 list_add_tail(&base_vha->list, &ha->vp_list);
2045 base_vha->host->irq = ha->pdev->irq;
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002051 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002053 ret = scsi_add_host(host, &pdev->dev);
2054 if (ret)
2055 goto probe_failed;
2056
Michael Reed14864002009-12-02 09:11:16 -06002057 base_vha->flags.init_done = 1;
2058 base_vha->flags.online = 1;
2059
Andrew Vasquez048feec2008-09-11 22:19:45 -07002060 ha->isp_ops->enable_intrs(ha);
2061
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002062 scsi_scan_host(host);
2063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002065
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002067
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002068 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 qla_printk(KERN_INFO, ha, "\n"
2071 " QLogic Fibre Channel HBA Driver: %s\n"
2072 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08002073 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2074 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 ha->model_desc ? ha->model_desc : "", pdev->device,
2076 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2077 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2078 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 return 0;
2081
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002082probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002083 qla2x00_free_req_que(ha, req);
2084 qla2x00_free_rsp_que(ha, rsp);
2085 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002088 if (base_vha->timer_active)
2089 qla2x00_stop_timer(base_vha);
2090 base_vha->flags.online = 0;
2091 if (ha->dpc_thread) {
2092 struct task_struct *t = ha->dpc_thread;
2093
2094 ha->dpc_thread = NULL;
2095 kthread_stop(t);
2096 }
2097
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102probe_hw_failed:
2103 if (ha->iobase)
2104 iounmap(ha->iobase);
2105
2106 pci_release_selected_regions(ha->pdev, ha->bars);
2107 kfree(ha);
2108 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002110probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002111 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002112 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Adrian Bunk4c993f72008-01-14 00:55:16 -08002115static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002116qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 scsi_qla_host_t *base_vha, *vha, *temp;
2119 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002121 base_vha = pci_get_drvdata(pdev);
2122 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002124 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2125 if (vha && vha->fc_vport)
2126 fc_vport_terminate(vha->fc_vport);
2127 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002128
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002129 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002130
Andrew Vasquezb9978762009-03-24 09:08:05 -07002131 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2132
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002136
Andrew Vasquezb9978762009-03-24 09:08:05 -07002137 /* Disable timer */
2138 if (base_vha->timer_active)
2139 qla2x00_stop_timer(base_vha);
2140
2141 base_vha->flags.online = 0;
2142
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002143 /* Flush the work queue and remove it */
2144 if (ha->wq) {
2145 flush_workqueue(ha->wq);
2146 destroy_workqueue(ha->wq);
2147 ha->wq = NULL;
2148 }
2149
Andrew Vasquezb9978762009-03-24 09:08:05 -07002150 /* Kill the kernel thread for this host */
2151 if (ha->dpc_thread) {
2152 struct task_struct *t = ha->dpc_thread;
2153
2154 /*
2155 * qla2xxx_wake_dpc checks for ->dpc_thread
2156 * so we need to zero it out.
2157 */
2158 ha->dpc_thread = NULL;
2159 kthread_stop(t);
2160 }
2161
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 scsi_host_put(base_vha->host);
2171
2172 if (ha->iobase)
2173 iounmap(ha->iobase);
2174
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002175 if (ha->mqiobase)
2176 iounmap(ha->mqiobase);
2177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002178 pci_release_selected_regions(ha->pdev, ha->bars);
2179 kfree(ha);
2180 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002182 pci_disable_pcie_error_reporting(pdev);
2183
Bernhard Walle665db932007-03-28 00:49:49 +02002184 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 pci_set_drvdata(pdev, NULL);
2186}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
2188static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002189qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002191 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Andrew Vasquez85880802009-12-15 21:29:46 -08002193 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2194
2195 /* Disable timer */
2196 if (vha->timer_active)
2197 qla2x00_stop_timer(vha);
2198
2199 /* Kill the kernel thread for this host */
2200 if (ha->dpc_thread) {
2201 struct task_struct *t = ha->dpc_thread;
2202
2203 /*
2204 * qla2xxx_wake_dpc checks for ->dpc_thread
2205 * so we need to zero it out.
2206 */
2207 ha->dpc_thread = NULL;
2208 kthread_stop(t);
2209 }
2210
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002211 qla25xx_delete_queues(vha);
2212
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002213 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002215
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002216 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002217 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002218
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002219 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002220 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Andrew Vasquez85880802009-12-15 21:29:46 -08002222 vha->flags.online = 0;
2223
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002224 /* turn-off interrupts on the card */
2225 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002226 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002227
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002228 qla2x00_free_irqs(vha);
2229
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002230 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002231
2232 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233}
2234
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002235static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002237 int defer)
2238{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002239 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002240 scsi_qla_host_t *base_vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002241
2242 if (!fcport->rport)
2243 return;
2244
2245 rport = fcport->rport;
2246 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002247 base_vha = pci_get_drvdata(vha->hw->pdev);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002248 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002249 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002251 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2252 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002253 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002254 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002255}
2256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2259 *
2260 * Input: ha = adapter block pointer. fcport = port structure pointer.
2261 *
2262 * Return: None.
2263 *
2264 * Context:
2265 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002267 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002269 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270 vha->vp_idx == fcport->vp_idx) {
2271 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2272 qla2x00_schedule_rport_del(vha, fcport, defer);
2273 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002274 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 * We may need to retry the login, so don't change the state of the
2276 * port but do the retries.
2277 */
2278 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2279 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2280
2281 if (!do_login)
2282 return;
2283
2284 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 fcport->login_retry = vha->hw->login_retry_count;
2286 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
2288 DEBUG(printk("scsi(%ld): Port login retry: "
2289 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2290 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 fcport->port_name[0],
2293 fcport->port_name[1],
2294 fcport->port_name[2],
2295 fcport->port_name[3],
2296 fcport->port_name[4],
2297 fcport->port_name[5],
2298 fcport->port_name[6],
2299 fcport->port_name[7],
2300 fcport->loop_id,
2301 fcport->login_retry));
2302 }
2303}
2304
2305/*
2306 * qla2x00_mark_all_devices_lost
2307 * Updates fcport state when device goes offline.
2308 *
2309 * Input:
2310 * ha = adapter block pointer.
2311 * fcport = port structure pointer.
2312 *
2313 * Return:
2314 * None.
2315 *
2316 * Context:
2317 */
2318void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
2321 fc_port_t *fcport;
2322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002324 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002326
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 /*
2328 * No point in marking the device as lost, if the device is
2329 * already DEAD.
2330 */
2331 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2332 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002334 if (defer)
2335 qla2x00_schedule_rport_del(vha, fcport, defer);
2336 else if (vha->vp_idx == fcport->vp_idx)
2337 qla2x00_schedule_rport_del(vha, fcport, defer);
2338 }
2339 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 }
2341}
2342
2343/*
2344* qla2x00_mem_alloc
2345* Allocates adapter memory.
2346*
2347* Returns:
2348* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002349* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002351static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002352qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2353 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
2355 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Andrew Vasqueze8711082008-01-31 12:33:48 -08002357 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002359 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002362 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2363 &ha->gid_list_dma, GFP_KERNEL);
2364 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002365 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Andrew Vasqueze8711082008-01-31 12:33:48 -08002367 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2368 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
Andrew Vasqueze8711082008-01-31 12:33:48 -08002371 /* Get memory for cached NVRAM */
2372 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2373 if (!ha->nvram)
2374 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2377 ha->pdev->device);
2378 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2379 DMA_POOL_SIZE, 8, 0);
2380 if (!ha->s_dma_pool)
2381 goto fail_free_nvram;
2382
Andrew Vasqueze8711082008-01-31 12:33:48 -08002383 /* Allocate memory for SNS commands */
2384 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002386 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002388 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002390 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002392 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002394 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002395 goto fail_dma_pool;
2396 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002397 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002399 if (!ha->ct_sns)
2400 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 }
2402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002404 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2405 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 DEBUG(printk("Unable to allocate memory for req\n"));
2407 goto fail_req;
2408 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002409 (*req)->length = req_len;
2410 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2411 ((*req)->length + 1) * sizeof(request_t),
2412 &(*req)->dma, GFP_KERNEL);
2413 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2415 goto fail_req_ring;
2416 }
2417 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002418 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2419 if (!*rsp) {
2420 qla_printk(KERN_WARNING, ha,
2421 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 goto fail_rsp;
2423 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002424 (*rsp)->hw = ha;
2425 (*rsp)->length = rsp_len;
2426 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2427 ((*rsp)->length + 1) * sizeof(response_t),
2428 &(*rsp)->dma, GFP_KERNEL);
2429 if (!(*rsp)->ring) {
2430 qla_printk(KERN_WARNING, ha,
2431 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 goto fail_rsp_ring;
2433 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002434 (*req)->rsp = *rsp;
2435 (*rsp)->req = *req;
2436 /* Allocate memory for NVRAM data for vports */
2437 if (ha->nvram_npiv_size) {
2438 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2439 ha->nvram_npiv_size, GFP_KERNEL);
2440 if (!ha->npiv_info) {
2441 qla_printk(KERN_WARNING, ha,
2442 "Unable to allocate memory for npiv info\n");
2443 goto fail_npiv_info;
2444 }
2445 } else
2446 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002448 /* Get consistent memory allocated for EX-INIT-CB. */
2449 if (IS_QLA81XX(ha)) {
2450 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2451 &ha->ex_init_cb_dma);
2452 if (!ha->ex_init_cb)
2453 goto fail_ex_init_cb;
2454 }
2455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 INIT_LIST_HEAD(&ha->vp_list);
2457 return 1;
2458
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002459fail_ex_init_cb:
2460 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002461fail_npiv_info:
2462 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2463 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2464 (*rsp)->ring = NULL;
2465 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002467 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002469 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2470 sizeof(request_t), (*req)->ring, (*req)->dma);
2471 (*req)->ring = NULL;
2472 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002474 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475fail_req:
2476 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2477 ha->ct_sns, ha->ct_sns_dma);
2478 ha->ct_sns = NULL;
2479 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002480fail_free_ms_iocb:
2481 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2482 ha->ms_iocb = NULL;
2483 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484fail_dma_pool:
2485 dma_pool_destroy(ha->s_dma_pool);
2486 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002487fail_free_nvram:
2488 kfree(ha->nvram);
2489 ha->nvram = NULL;
2490fail_free_srb_mempool:
2491 mempool_destroy(ha->srb_mempool);
2492 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002493fail_free_gid_list:
2494 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002496 ha->gid_list = NULL;
2497 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498fail_free_init_cb:
2499 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2500 ha->init_cb_dma);
2501 ha->init_cb = NULL;
2502 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002503fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002505 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509* qla2x00_mem_free
2510* Frees all adapter allocated memory.
2511*
2512* Input:
2513* ha = adapter block pointer.
2514*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002515static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002518 if (ha->srb_mempool)
2519 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002521 if (ha->fce)
2522 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002524
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002525 if (ha->fw_dump) {
2526 if (ha->eft)
2527 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002529 vfree(ha->fw_dump);
2530 }
2531
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07002532 if (ha->dcbx_tlv)
2533 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2534 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2535
Andrew Vasquezce0423f2009-06-03 09:55:13 -07002536 if (ha->xgmac_data)
2537 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2538 ha->xgmac_data, ha->xgmac_data_dma);
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 if (ha->sns_cmd)
2541 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002542 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
2544 if (ha->ct_sns)
2545 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002546 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
Andrew Vasquez88729e52006-06-23 16:10:50 -07002548 if (ha->sfp_data)
2549 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2550
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002551 if (ha->edc_data)
2552 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2553
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 if (ha->ms_iocb)
2555 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2556
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002557 if (ha->ex_init_cb)
2558 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2559
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 if (ha->s_dma_pool)
2561 dma_pool_destroy(ha->s_dma_pool);
2562
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 if (ha->gid_list)
2564 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 if (ha->init_cb)
2568 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2569 ha->init_cb, ha->init_cb_dma);
2570 vfree(ha->optrom_buffer);
2571 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002572 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573
Andrew Vasqueze8711082008-01-31 12:33:48 -08002574 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002575 ha->eft = NULL;
2576 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 ha->sns_cmd = NULL;
2578 ha->sns_cmd_dma = 0;
2579 ha->ct_sns = NULL;
2580 ha->ct_sns_dma = 0;
2581 ha->ms_iocb = NULL;
2582 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 ha->init_cb = NULL;
2584 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002585 ha->ex_init_cb = NULL;
2586 ha->ex_init_cb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
2588 ha->s_dma_pool = NULL;
2589
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 ha->gid_list = NULL;
2591 ha->gid_list_dma = 0;
2592
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002594 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596}
2597
2598struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2599 struct qla_hw_data *ha)
2600{
2601 struct Scsi_Host *host;
2602 struct scsi_qla_host *vha = NULL;
2603
2604 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2605 if (host == NULL) {
2606 printk(KERN_WARNING
2607 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2608 goto fail;
2609 }
2610
2611 /* Clear our data area */
2612 vha = shost_priv(host);
2613 memset(vha, 0, sizeof(scsi_qla_host_t));
2614
2615 vha->host = host;
2616 vha->host_no = host->host_no;
2617 vha->hw = ha;
2618
2619 INIT_LIST_HEAD(&vha->vp_fcports);
2620 INIT_LIST_HEAD(&vha->work_list);
2621 INIT_LIST_HEAD(&vha->list);
2622
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002623 spin_lock_init(&vha->work_lock);
2624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2626 return vha;
2627
2628fail:
2629 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630}
2631
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002632static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002633qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002634{
2635 struct qla_work_evt *e;
2636
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002637 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002638 if (!e)
2639 return NULL;
2640
2641 INIT_LIST_HEAD(&e->list);
2642 e->type = type;
2643 e->flags = QLA_EVT_FLAG_FREE;
2644 return e;
2645}
2646
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002647static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002648qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002649{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002650 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002651
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002652 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002654 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002655 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002656
Andrew Vasquez0971de72008-04-03 13:13:18 -07002657 return QLA_SUCCESS;
2658}
2659
2660int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002662 u32 data)
2663{
2664 struct qla_work_evt *e;
2665
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002666 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002667 if (!e)
2668 return QLA_FUNCTION_FAILED;
2669
2670 e->u.aen.code = code;
2671 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002672 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002673}
2674
Andrew Vasquez8a659572009-02-08 20:50:12 -08002675int
2676qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2677{
2678 struct qla_work_evt *e;
2679
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002680 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08002681 if (!e)
2682 return QLA_FUNCTION_FAILED;
2683
2684 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002685 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08002686}
2687
Andrew Vasquezac280b62009-08-20 11:06:05 -07002688#define qla2x00_post_async_work(name, type) \
2689int qla2x00_post_async_##name##_work( \
2690 struct scsi_qla_host *vha, \
2691 fc_port_t *fcport, uint16_t *data) \
2692{ \
2693 struct qla_work_evt *e; \
2694 \
2695 e = qla2x00_alloc_work(vha, type); \
2696 if (!e) \
2697 return QLA_FUNCTION_FAILED; \
2698 \
2699 e->u.logio.fcport = fcport; \
2700 if (data) { \
2701 e->u.logio.data[0] = data[0]; \
2702 e->u.logio.data[1] = data[1]; \
2703 } \
2704 return qla2x00_post_work(vha, e); \
2705}
2706
2707qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2708qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2709qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2710qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2711
Andrew Vasquez3420d362009-10-13 15:16:45 -07002712int
2713qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
2714{
2715 struct qla_work_evt *e;
2716
2717 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
2718 if (!e)
2719 return QLA_FUNCTION_FAILED;
2720
2721 e->u.uevent.code = code;
2722 return qla2x00_post_work(vha, e);
2723}
2724
2725static void
2726qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
2727{
2728 char event_string[40];
2729 char *envp[] = { event_string, NULL };
2730
2731 switch (code) {
2732 case QLA_UEVENT_CODE_FW_DUMP:
2733 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2734 vha->host_no);
2735 break;
2736 default:
2737 /* do nothing */
2738 break;
2739 }
2740 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
2741}
2742
Andrew Vasquezac280b62009-08-20 11:06:05 -07002743void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002744qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002745{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002746 struct qla_work_evt *e, *tmp;
2747 unsigned long flags;
2748 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002749
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002750 spin_lock_irqsave(&vha->work_lock, flags);
2751 list_splice_init(&vha->work_list, &work);
2752 spin_unlock_irqrestore(&vha->work_lock, flags);
2753
2754 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07002755 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002756
2757 switch (e->type) {
2758 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002760 e->u.aen.code, e->u.aen.data);
2761 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08002762 case QLA_EVT_IDC_ACK:
2763 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2764 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002765 case QLA_EVT_ASYNC_LOGIN:
2766 qla2x00_async_login(vha, e->u.logio.fcport,
2767 e->u.logio.data);
2768 break;
2769 case QLA_EVT_ASYNC_LOGIN_DONE:
2770 qla2x00_async_login_done(vha, e->u.logio.fcport,
2771 e->u.logio.data);
2772 break;
2773 case QLA_EVT_ASYNC_LOGOUT:
2774 qla2x00_async_logout(vha, e->u.logio.fcport);
2775 break;
2776 case QLA_EVT_ASYNC_LOGOUT_DONE:
2777 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2778 e->u.logio.data);
2779 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07002780 case QLA_EVT_UEVENT:
2781 qla2x00_uevent_emit(vha, e->u.uevent.code);
2782 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002783 }
2784 if (e->flags & QLA_EVT_FLAG_FREE)
2785 kfree(e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002786 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789/* Relogins all the fcports of a vport
2790 * Context: dpc thread
2791 */
2792void qla2x00_relogin(struct scsi_qla_host *vha)
2793{
2794 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08002795 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796 uint16_t next_loopid = 0;
2797 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002798 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799
2800 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2801 /*
2802 * If the port is not ONLINE then try to login
2803 * to it if we haven't run out of retries.
2804 */
2805 if (atomic_read(&fcport->state) !=
2806 FCS_ONLINE && fcport->login_retry) {
2807
Andrew Vasquezac280b62009-08-20 11:06:05 -07002808 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002810 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 ha->isp_ops->fabric_logout(vha,
2812 fcport->loop_id,
2813 fcport->d_id.b.domain,
2814 fcport->d_id.b.area,
2815 fcport->d_id.b.al_pa);
2816
Andrew Vasquezac280b62009-08-20 11:06:05 -07002817 if (IS_ALOGIO_CAPABLE(ha)) {
2818 data[0] = 0;
2819 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2820 status = qla2x00_post_async_login_work(
2821 vha, fcport, data);
2822 if (status == QLA_SUCCESS)
2823 continue;
2824 /* Attempt a retry. */
2825 status = 1;
2826 } else
2827 status = qla2x00_fabric_login(vha,
2828 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 } else
2830 status = qla2x00_local_device_login(vha,
2831 fcport);
2832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 if (status == QLA_SUCCESS) {
2834 fcport->old_loop_id = fcport->loop_id;
2835
2836 DEBUG(printk("scsi(%ld): port login OK: logged "
2837 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2838
2839 qla2x00_update_fcport(vha, fcport);
2840
2841 } else if (status == 1) {
2842 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2843 /* retry the login again */
2844 DEBUG(printk("scsi(%ld): Retrying"
2845 " %d login again loop_id 0x%x\n",
2846 vha->host_no, fcport->login_retry,
2847 fcport->loop_id));
2848 } else {
2849 fcport->login_retry = 0;
2850 }
2851
2852 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2853 fcport->loop_id = FC_NO_LOOP_ID;
2854 }
2855 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2856 break;
2857 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002858}
2859
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860/**************************************************************************
2861* qla2x00_do_dpc
2862* This kernel thread is a task that is schedule by the interrupt handler
2863* to perform the background processing for interrupts.
2864*
2865* Notes:
2866* This task always run in the context of a kernel thread. It
2867* is kick-off by the driver's detect code and starts up
2868* up one per adapter. It immediately goes to sleep and waits for
2869* some fibre event. When either the interrupt handler or
2870* the timer routine detects a event it will one of the task
2871* bits then wake us up.
2872**************************************************************************/
2873static int
2874qla2x00_do_dpc(void *data)
2875{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002876 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002877 scsi_qla_host_t *base_vha;
2878 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002879
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 ha = (struct qla_hw_data *)data;
2881 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 set_user_nice(current, -20);
2884
Christoph Hellwig39a11242006-02-14 18:46:22 +01002885 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2887
Christoph Hellwig39a11242006-02-14 18:46:22 +01002888 set_current_state(TASK_INTERRUPTIBLE);
2889 schedule();
2890 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
2892 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2893
2894 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 continue;
2897
Andrew Vasquez85880802009-12-15 21:29:46 -08002898 if (ha->flags.eeh_busy) {
2899 DEBUG17(qla_printk(KERN_WARNING, ha,
2900 "qla2x00_do_dpc: dpc_flags: %lx\n",
2901 base_vha->dpc_flags));
2902 continue;
2903 }
2904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
2907 ha->dpc_active = 1;
2908
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 ha->dpc_active = 0;
2911 continue;
2912 }
2913
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002915
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2917 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
2919 DEBUG(printk("scsi(%ld): dpc: sched "
2920 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 /* failed. retry later */
2927 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002928 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 clear_bit(ABORT_ISP_ACTIVE,
2931 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002932 }
2933
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
2937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2939 qla2x00_update_fcports(base_vha);
2940 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002941 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2944 &base_vha->dpc_flags) &&
2945 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946
2947 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 qla2x00_rst_aen(base_vha);
2951 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 }
2953
2954 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 if ((test_and_clear_bit(RELOGIN_NEEDED,
2956 &base_vha->dpc_flags)) &&
2957 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2958 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
2960 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 base_vha->host_no));
2962 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2969 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
2971 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
2974 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979 clear_bit(LOOP_RESYNC_ACTIVE,
2980 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 }
2982
2983 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 }
2986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2988 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2989 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2990 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002991 }
2992
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002994 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2997 &base_vha->dpc_flags))
2998 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003000 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003001
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 ha->dpc_active = 0;
3003 } /* End of while(1) */
3004
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006
3007 /*
3008 * Make sure that nobody tries to wake us up again.
3009 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 ha->dpc_active = 0;
3011
Andrew Vasquezac280b62009-08-20 11:06:05 -07003012 /* Cleanup any residual CTX SRBs. */
3013 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3014
Christoph Hellwig39a11242006-02-14 18:46:22 +01003015 return 0;
3016}
3017
3018void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003020{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003021 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003022 struct task_struct *t = ha->dpc_thread;
3023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003025 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026}
3027
3028/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029* qla2x00_rst_aen
3030* Processes asynchronous reset.
3031*
3032* Input:
3033* ha = adapter block pointer.
3034*/
3035static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 if (vha->flags.online && !vha->flags.reset_active &&
3039 !atomic_read(&vha->loop_down_timer) &&
3040 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
3044 /*
3045 * Issue marker command only when we are going to start
3046 * the I/O.
3047 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 vha->marker_needed = 1;
3049 } while (!atomic_read(&vha->loop_down_timer) &&
3050 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 }
3052}
3053
f4f051e2005-04-17 15:02:26 -05003054static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003056{
3057 struct scsi_cmnd *cmd = sp->cmd;
3058
3059 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003060 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003061 sp->flags &= ~SRB_DMA_VALID;
3062 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003063 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05003064}
3065
3066void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003067qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003068{
3069 struct scsi_cmnd *cmd = sp->cmd;
3070
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003071 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05003072
f4f051e2005-04-17 15:02:26 -05003073 mempool_free(sp, ha->srb_mempool);
3074
3075 cmd->scsi_done(cmd);
3076}
bdf79622005-04-17 15:06:53 -05003077
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078/**************************************************************************
3079* qla2x00_timer
3080*
3081* Description:
3082* One second timer
3083*
3084* Context: Interrupt
3085***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003086void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003087qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 unsigned long cpu_flags = 0;
3090 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 int start_dpc = 0;
3092 int index;
3093 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05003094 int t;
Andrew Vasquez85880802009-12-15 21:29:46 -08003095 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003097 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003098
3099 /* Hardware read to raise pending EEH errors during mailbox waits. */
3100 if (!pci_channel_offline(ha->pdev))
3101 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 /*
3103 * Ports - Port down timer.
3104 *
3105 * Whenever, a port is in the LOST state we start decrementing its port
3106 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003107 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 */
3109 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003110 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (fcport->port_type != FCT_TARGET)
3112 continue;
3113
3114 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3115
3116 if (atomic_read(&fcport->port_down_timer) == 0)
3117 continue;
3118
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003119 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003121
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07003123 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003124 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 t, atomic_read(&fcport->port_down_timer)));
3126 }
3127 t++;
3128 } /* End of for fcport */
3129
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
3131 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003132 if (atomic_read(&vha->loop_down_timer) > 0 &&
3133 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3134 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 if (atomic_read(&vha->loop_down_timer) ==
3137 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3140 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3144 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003146 /*
3147 * Schedule an ISP abort to return any FCP2-device
3148 * commands.
3149 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003150 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003152 spin_lock_irqsave(&ha->hardware_lock,
3153 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003154 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003155 for (index = 1;
3156 index < MAX_OUTSTANDING_COMMANDS;
3157 index++) {
3158 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003159
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003160 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003161 if (!sp)
3162 continue;
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003163 if (sp->ctx)
3164 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003165 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003166 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003167 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003169 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003171 break;
3172 }
3173 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 start_dpc++;
3177 }
3178
3179 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003181 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 DEBUG(printk("scsi(%ld): Loop down - "
3183 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 qla_printk(KERN_WARNING, ha,
3186 "Loop down - aborting ISP.\n");
3187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 }
3190 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003191 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 vha->host_no,
3193 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 }
3195
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003196 /* Check if beacon LED needs to be blinked */
3197 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003199 start_dpc++;
3200 }
3201
Andrew Vasquez550bf572008-04-24 15:21:23 -07003202 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003203 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003204 start_dpc++;
3205
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3208 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3209 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003211 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3212 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3213 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3214 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3215 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
Andrew Vasquez54333832005-11-09 15:49:04 -08003220/* Firmware interface routines. */
3221
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003222#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003223#define FW_ISP21XX 0
3224#define FW_ISP22XX 1
3225#define FW_ISP2300 2
3226#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003227#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003228#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003229#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08003230
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003231#define FW_FILE_ISP21XX "ql2100_fw.bin"
3232#define FW_FILE_ISP22XX "ql2200_fw.bin"
3233#define FW_FILE_ISP2300 "ql2300_fw.bin"
3234#define FW_FILE_ISP2322 "ql2322_fw.bin"
3235#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003236#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003237#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003238
Daniel Walkere1e82b62008-05-12 22:21:10 -07003239static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003240
3241static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003242 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3243 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3244 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3245 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3246 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003247 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003248 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003249};
3250
3251struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003253{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003254 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003255 struct fw_blob *blob;
3256
3257 blob = NULL;
3258 if (IS_QLA2100(ha)) {
3259 blob = &qla_fw_blobs[FW_ISP21XX];
3260 } else if (IS_QLA2200(ha)) {
3261 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003262 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003263 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003264 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003265 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003266 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003267 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003268 } else if (IS_QLA25XX(ha)) {
3269 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003270 } else if (IS_QLA81XX(ha)) {
3271 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003272 }
3273
Daniel Walkere1e82b62008-05-12 22:21:10 -07003274 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003275 if (blob->fw)
3276 goto out;
3277
3278 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3279 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003281 blob->fw = NULL;
3282 blob = NULL;
3283 goto out;
3284 }
3285
3286out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003287 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003288 return blob;
3289}
3290
3291static void
3292qla2x00_release_firmware(void)
3293{
3294 int idx;
3295
Daniel Walkere1e82b62008-05-12 22:21:10 -07003296 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003297 for (idx = 0; idx < FW_BLOBS; idx++)
3298 if (qla_fw_blobs[idx].fw)
3299 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003300 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003301}
3302
Seokmann Ju14e660e2007-09-20 14:07:36 -07003303static pci_ers_result_t
3304qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3305{
Andrew Vasquez85880802009-12-15 21:29:46 -08003306 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3307 struct qla_hw_data *ha = vha->hw;
3308
3309 DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
3310 state));
Seokmann Jub9b12f72009-03-24 09:08:18 -07003311
Seokmann Ju14e660e2007-09-20 14:07:36 -07003312 switch (state) {
3313 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003314 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003315 return PCI_ERS_RESULT_CAN_RECOVER;
3316 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08003317 ha->flags.eeh_busy = 1;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003318 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003319 pci_disable_device(pdev);
3320 return PCI_ERS_RESULT_NEED_RESET;
3321 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08003322 ha->flags.pci_channel_io_perm_failure = 1;
3323 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003324 return PCI_ERS_RESULT_DISCONNECT;
3325 }
3326 return PCI_ERS_RESULT_NEED_RESET;
3327}
3328
3329static pci_ers_result_t
3330qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3331{
3332 int risc_paused = 0;
3333 uint32_t stat;
3334 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3336 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003337 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3338 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3339
3340 spin_lock_irqsave(&ha->hardware_lock, flags);
3341 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3342 stat = RD_REG_DWORD(&reg->hccr);
3343 if (stat & HCCR_RISC_PAUSE)
3344 risc_paused = 1;
3345 } else if (IS_QLA23XX(ha)) {
3346 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3347 if (stat & HSR_RISC_PAUSED)
3348 risc_paused = 1;
3349 } else if (IS_FWI2_CAPABLE(ha)) {
3350 stat = RD_REG_DWORD(&reg24->host_status);
3351 if (stat & HSRX_RISC_PAUSED)
3352 risc_paused = 1;
3353 }
3354 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3355
3356 if (risc_paused) {
3357 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3358 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003359 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003360
3361 return PCI_ERS_RESULT_NEED_RESET;
3362 } else
3363 return PCI_ERS_RESULT_RECOVERED;
3364}
3365
3366static pci_ers_result_t
3367qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3368{
3369 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3371 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003372 struct rsp_que *rsp;
3373 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003374
Andrew Vasquez85880802009-12-15 21:29:46 -08003375 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3376
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003377 /* Workaround: qla2xxx driver which access hardware earlier
3378 * needs error state to be pci_channel_io_online.
3379 * Otherwise mailbox command timesout.
3380 */
3381 pdev->error_state = pci_channel_io_normal;
3382
3383 pci_restore_state(pdev);
3384
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003385 if (ha->mem_only)
3386 rc = pci_enable_device_mem(pdev);
3387 else
3388 rc = pci_enable_device(pdev);
3389
3390 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003391 qla_printk(KERN_WARNING, ha,
3392 "Can't re-enable PCI device after reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07003393 return ret;
3394 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07003395
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003396 rsp = ha->rsp_q_map[0];
3397 if (qla2x00_request_irqs(ha, rsp))
3398 return ret;
3399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003400 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003401 return ret;
3402
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003403 while (ha->flags.mbox_busy && retries--)
3404 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08003405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003406 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3407 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003408 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003409 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003410
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003411 pci_cleanup_aer_uncorrect_error_status(pdev);
3412
Andrew Vasquez85880802009-12-15 21:29:46 -08003413 DEBUG17(qla_printk(KERN_WARNING, ha,
3414 "slot_reset-return:ret=%x\n", ret));
3415
Seokmann Ju14e660e2007-09-20 14:07:36 -07003416 return ret;
3417}
3418
3419static void
3420qla2xxx_pci_resume(struct pci_dev *pdev)
3421{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3423 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003424 int ret;
3425
Andrew Vasquez85880802009-12-15 21:29:46 -08003426 DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
3427
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003429 if (ret != QLA_SUCCESS) {
3430 qla_printk(KERN_ERR, ha,
3431 "the device failed to resume I/O "
3432 "from slot/link_reset");
3433 }
Andrew Vasquez85880802009-12-15 21:29:46 -08003434
3435 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003436}
3437
3438static struct pci_error_handlers qla2xxx_err_handler = {
3439 .error_detected = qla2xxx_pci_error_detected,
3440 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3441 .slot_reset = qla2xxx_pci_slot_reset,
3442 .resume = qla2xxx_pci_resume,
3443};
3444
Andrew Vasquez54333832005-11-09 15:49:04 -08003445static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003446 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3447 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3448 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3449 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3450 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3451 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3452 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3453 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3454 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003455 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003456 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3457 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003458 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003459 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003460 { 0 },
3461};
3462MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3463
Andrew Vasquezfca29702005-07-06 10:31:47 -07003464static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003465 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003466 .driver = {
3467 .owner = THIS_MODULE,
3468 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003469 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003470 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003471 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003472 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003473};
3474
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475/**
3476 * qla2x00_module_init - Module initialization.
3477 **/
3478static int __init
3479qla2x00_module_init(void)
3480{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003481 int ret = 0;
3482
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003484 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003485 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 if (srb_cachep == NULL) {
3487 printk(KERN_ERR
3488 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3489 return -ENOMEM;
3490 }
3491
3492 /* Derive version string. */
3493 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003494 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003495 strcat(qla2x00_version_str, "-debug");
3496
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003497 qla2xxx_transport_template =
3498 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003499 if (!qla2xxx_transport_template) {
3500 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003502 }
3503 qla2xxx_transport_vport_template =
3504 fc_attach_transport(&qla2xxx_transport_vport_functions);
3505 if (!qla2xxx_transport_vport_template) {
3506 kmem_cache_destroy(srb_cachep);
3507 fc_release_transport(qla2xxx_transport_template);
3508 return -ENODEV;
3509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003511 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3512 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003513 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003514 if (ret) {
3515 kmem_cache_destroy(srb_cachep);
3516 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003517 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003518 }
3519 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520}
3521
3522/**
3523 * qla2x00_module_exit - Module cleanup.
3524 **/
3525static void __exit
3526qla2x00_module_exit(void)
3527{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003528 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003529 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003530 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003532 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533}
3534
3535module_init(qla2x00_module_init);
3536module_exit(qla2x00_module_exit);
3537
3538MODULE_AUTHOR("QLogic Corporation");
3539MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3540MODULE_LICENSE("GPL");
3541MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003542MODULE_FIRMWARE(FW_FILE_ISP21XX);
3543MODULE_FIRMWARE(FW_FILE_ISP22XX);
3544MODULE_FIRMWARE(FW_FILE_ISP2300);
3545MODULE_FIRMWARE(FW_FILE_ISP2322);
3546MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003547MODULE_FIRMWARE(FW_FILE_ISP25XX);