blob: 413ccc152de5d3f3e8b595e0b5081db936379f44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * QLOGIC LINUX SOFTWARE
3 *
4 * QLogic ISP2x00 device driver for Linux 2.6.x
Andrew Vasquezae911932005-07-06 10:32:27 -07005 * Copyright (C) 2003-2005 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * (www.qlogic.com)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 */
19#include "qla_def.h"
20
21#include <linux/moduleparam.h>
22#include <linux/vmalloc.h>
23#include <linux/smp_lock.h>
24#include <linux/delay.h>
25
26#include <scsi/scsi_tcq.h>
27#include <scsi/scsicam.h>
28#include <scsi/scsi_transport.h>
29#include <scsi/scsi_transport_fc.h>
30
31/*
32 * Driver version
33 */
34char qla2x00_version_str[40];
35
36/*
37 * SRB allocation cache
38 */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -040039static kmem_cache_t *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/*
42 * Ioctl related information.
43 */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -040044static int num_hosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46int ql2xlogintimeout = 20;
47module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
48MODULE_PARM_DESC(ql2xlogintimeout,
49 "Login timeout value in seconds.");
50
8482e1182005-04-17 15:04:54 -050051int qlport_down_retry = 30;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
53MODULE_PARM_DESC(qlport_down_retry,
54 "Maximum number of command retries to a port that returns"
55 "a PORT-DOWN status.");
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057int ql2xplogiabsentdevice;
58module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
59MODULE_PARM_DESC(ql2xplogiabsentdevice,
60 "Option to enable PLOGI to devices that are not present after "
61 "a Fabric scan. This is needed for several broken switches."
62 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
63
64int ql2xenablezio = 0;
65module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
66MODULE_PARM_DESC(ql2xenablezio,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070067 "Option to enable ZIO:If 1 then enable it otherwise"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 " use the default set in the NVRAM."
69 " Default is 0 : disabled");
70
71int ql2xintrdelaytimer = 10;
72module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
73MODULE_PARM_DESC(ql2xintrdelaytimer,
74 "ZIO: Waiting time for Firmware before it generates an "
75 "interrupt to the host to notify completion of request.");
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077int ql2xloginretrycount = 0;
78module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
79MODULE_PARM_DESC(ql2xloginretrycount,
80 "Specify an alternate value for the NVRAM login retry count.");
81
Andrew Vasquezfca29702005-07-06 10:31:47 -070082int ql2xfwloadbin;
83module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
84MODULE_PARM_DESC(ql2xfwloadbin,
85 "Load ISP2xxx firmware image via hotplug.");
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static void qla2x00_free_device(scsi_qla_host_t *);
88
89static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
90
Andrew Vasquezcca53352005-08-26 19:08:30 -070091int ql2xfdmienable;
92module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
93MODULE_PARM_DESC(ql2xfdmienable,
94 "Enables FDMI registratons "
95 "Default is 0 - no FDMI. 1 - perfom FDMI.");
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070098 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 */
100static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500101static int qla2xxx_slave_alloc(struct scsi_device *);
102static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
104 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700105static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
106 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static int qla2xxx_eh_abort(struct scsi_cmnd *);
108static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
109static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
110static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
111static int qla2x00_loop_reset(scsi_qla_host_t *ha);
112static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
113
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700114static int qla2x00_change_queue_depth(struct scsi_device *, int);
115static int qla2x00_change_queue_type(struct scsi_device *, int);
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static struct scsi_host_template qla2x00_driver_template = {
118 .module = THIS_MODULE,
119 .name = "qla2xxx",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .queuecommand = qla2x00_queuecommand,
121
122 .eh_abort_handler = qla2xxx_eh_abort,
123 .eh_device_reset_handler = qla2xxx_eh_device_reset,
124 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
125 .eh_host_reset_handler = qla2xxx_eh_host_reset,
126
127 .slave_configure = qla2xxx_slave_configure,
128
f4f051e2005-04-17 15:02:26 -0500129 .slave_alloc = qla2xxx_slave_alloc,
130 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700131 .change_queue_depth = qla2x00_change_queue_depth,
132 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 .this_id = -1,
134 .cmd_per_lun = 3,
135 .use_clustering = ENABLE_CLUSTERING,
136 .sg_tablesize = SG_ALL,
137
138 /*
139 * The RISC allows for each command to transfer (2^32-1) bytes of data,
140 * which equates to 0x800000 sectors.
141 */
142 .max_sectors = 0xFFFF,
143};
144
Andrew Vasquezfca29702005-07-06 10:31:47 -0700145static struct scsi_host_template qla24xx_driver_template = {
146 .module = THIS_MODULE,
147 .name = "qla2xxx",
148 .queuecommand = qla24xx_queuecommand,
149
150 .eh_abort_handler = qla2xxx_eh_abort,
151 .eh_device_reset_handler = qla2xxx_eh_device_reset,
152 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
153 .eh_host_reset_handler = qla2xxx_eh_host_reset,
154
155 .slave_configure = qla2xxx_slave_configure,
156
157 .slave_alloc = qla2xxx_slave_alloc,
158 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700159 .change_queue_depth = qla2x00_change_queue_depth,
160 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700161 .this_id = -1,
162 .cmd_per_lun = 3,
163 .use_clustering = ENABLE_CLUSTERING,
164 .sg_tablesize = SG_ALL,
165
166 .max_sectors = 0xFFFF,
167};
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169static struct scsi_transport_template *qla2xxx_transport_template = NULL;
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171/* TODO Convert to inlines
172 *
173 * Timer routines
174 */
175#define WATCH_INTERVAL 1 /* number of seconds */
176
177static void qla2x00_timer(scsi_qla_host_t *);
178
179static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
180 void *, unsigned long);
181static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
182static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
183
184static inline void
185qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
186{
187 init_timer(&ha->timer);
188 ha->timer.expires = jiffies + interval * HZ;
189 ha->timer.data = (unsigned long)ha;
190 ha->timer.function = (void (*)(unsigned long))func;
191 add_timer(&ha->timer);
192 ha->timer_active = 1;
193}
194
195static inline void
196qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
197{
198 mod_timer(&ha->timer, jiffies + interval * HZ);
199}
200
201static __inline__ void
202qla2x00_stop_timer(scsi_qla_host_t *ha)
203{
204 del_timer_sync(&ha->timer);
205 ha->timer_active = 0;
206}
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208static int qla2x00_do_dpc(void *data);
209
210static void qla2x00_rst_aen(scsi_qla_host_t *);
211
212static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
213static void qla2x00_mem_free(scsi_qla_host_t *ha);
214static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
215static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500216static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
217void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/* -------------------------------------------------------------------------- */
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700222qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 static char *pci_bus_modes[] = {
225 "33", "66", "100", "133",
226 };
227 uint16_t pci_bus;
228
229 strcpy(str, "PCI");
230 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
231 if (pci_bus) {
232 strcat(str, "-X (");
233 strcat(str, pci_bus_modes[pci_bus]);
234 } else {
235 pci_bus = (ha->pci_attr & BIT_8) >> 8;
236 strcat(str, " (");
237 strcat(str, pci_bus_modes[pci_bus]);
238 }
239 strcat(str, " MHz)");
240
241 return (str);
242}
243
Andrew Vasquezfca29702005-07-06 10:31:47 -0700244static char *
245qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
246{
247 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
248 uint32_t pci_bus;
249 int pcie_reg;
250
251 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
252 if (pcie_reg) {
253 char lwstr[6];
254 uint16_t pcie_lstat, lspeed, lwidth;
255
256 pcie_reg += 0x12;
257 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
258 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
259 lwidth = (pcie_lstat &
260 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
261
262 strcpy(str, "PCIe (");
263 if (lspeed == 1)
264 strcat(str, "2.5Gb/s ");
265 else
266 strcat(str, "<unknown> ");
267 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
268 strcat(str, lwstr);
269
270 return str;
271 }
272
273 strcpy(str, "PCI");
274 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
275 if (pci_bus == 0 || pci_bus == 8) {
276 strcat(str, " (");
277 strcat(str, pci_bus_modes[pci_bus >> 3]);
278 } else {
279 strcat(str, "-X ");
280 if (pci_bus & BIT_2)
281 strcat(str, "Mode 2");
282 else
283 strcat(str, "Mode 1");
284 strcat(str, " (");
285 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
286 }
287 strcat(str, " MHz)");
288
289 return str;
290}
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700293qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
298 ha->fw_minor_version,
299 ha->fw_subminor_version);
300
301 if (ha->fw_attributes & BIT_9) {
302 strcat(str, "FLX");
303 return (str);
304 }
305
306 switch (ha->fw_attributes & 0xFF) {
307 case 0x7:
308 strcat(str, "EF");
309 break;
310 case 0x17:
311 strcat(str, "TP");
312 break;
313 case 0x37:
314 strcat(str, "IP");
315 break;
316 case 0x77:
317 strcat(str, "VI");
318 break;
319 default:
320 sprintf(un_str, "(%x)", ha->fw_attributes);
321 strcat(str, un_str);
322 break;
323 }
324 if (ha->fw_attributes & 0x100)
325 strcat(str, "X");
326
327 return (str);
328}
329
Andrew Vasquezfca29702005-07-06 10:31:47 -0700330char *
331qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
332{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700333 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
334 ha->fw_minor_version,
335 ha->fw_subminor_version);
336
Andrew Vasquezfca29702005-07-06 10:31:47 -0700337 if (ha->fw_attributes & BIT_0)
338 strcat(str, "[Class 2] ");
339 if (ha->fw_attributes & BIT_1)
340 strcat(str, "[IP] ");
341 if (ha->fw_attributes & BIT_2)
342 strcat(str, "[Multi-ID] ");
343 if (ha->fw_attributes & BIT_13)
344 strcat(str, "[Experimental]");
345 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700346}
347
348static inline srb_t *
349qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
350 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
351{
352 srb_t *sp;
353
354 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
355 if (!sp)
356 return sp;
357
358 atomic_set(&sp->ref_count, 1);
359 sp->ha = ha;
360 sp->fcport = fcport;
361 sp->cmd = cmd;
362 sp->flags = 0;
363 CMD_SP(cmd) = (void *)sp;
364 cmd->scsi_done = done;
365
366 return sp;
367}
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369static int
f4f051e2005-04-17 15:02:26 -0500370qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
f4f051e2005-04-17 15:02:26 -0500372 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500373 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500374 srb_t *sp;
375 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
bdf79622005-04-17 15:06:53 -0500377 if (!fcport) {
f4f051e2005-04-17 15:02:26 -0500378 cmd->result = DID_NO_CONNECT << 16;
379 goto qc_fail_command;
380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
f4f051e2005-04-17 15:02:26 -0500382 if (atomic_read(&fcport->state) != FCS_ONLINE) {
383 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
384 atomic_read(&ha->loop_state) == LOOP_DEAD) {
385 cmd->result = DID_NO_CONNECT << 16;
386 goto qc_fail_command;
387 }
388 goto qc_host_busy;
389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 spin_unlock_irq(ha->host->host_lock);
392
Andrew Vasquezfca29702005-07-06 10:31:47 -0700393 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
394 if (!sp)
f4f051e2005-04-17 15:02:26 -0500395 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
f4f051e2005-04-17 15:02:26 -0500397 rval = qla2x00_start_scsi(sp);
398 if (rval != QLA_SUCCESS)
399 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
f4f051e2005-04-17 15:02:26 -0500401 /* Manage unprocessed RIO/ZIO commands in response queue. */
402 if (ha->flags.online && ha->flags.process_response_queue &&
403 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
404 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
f4f051e2005-04-17 15:02:26 -0500406 spin_lock_irqsave(&ha->hardware_lock, flags);
407 qla2x00_process_response_queue(ha);
408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 spin_lock_irq(ha->host->host_lock);
412
f4f051e2005-04-17 15:02:26 -0500413 return 0;
414
415qc_host_busy_free_sp:
416 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500417 mempool_free(sp, ha->srb_mempool);
418
419qc_host_busy_lock:
420 spin_lock_irq(ha->host->host_lock);
421
422qc_host_busy:
423 return SCSI_MLQUEUE_HOST_BUSY;
424
425qc_fail_command:
426 done(cmd);
427
428 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
Andrew Vasquezfca29702005-07-06 10:31:47 -0700431
432static int
433qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
434{
435 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
436 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
437 srb_t *sp;
438 int rval;
439
440 if (!fcport) {
441 cmd->result = DID_NO_CONNECT << 16;
442 goto qc24_fail_command;
443 }
444
445 if (atomic_read(&fcport->state) != FCS_ONLINE) {
446 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
447 atomic_read(&ha->loop_state) == LOOP_DEAD) {
448 cmd->result = DID_NO_CONNECT << 16;
449 goto qc24_fail_command;
450 }
451 goto qc24_host_busy;
452 }
453
454 spin_unlock_irq(ha->host->host_lock);
455
456 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
457 if (!sp)
458 goto qc24_host_busy_lock;
459
460 rval = qla24xx_start_scsi(sp);
461 if (rval != QLA_SUCCESS)
462 goto qc24_host_busy_free_sp;
463
464 spin_lock_irq(ha->host->host_lock);
465
466 return 0;
467
468qc24_host_busy_free_sp:
469 qla2x00_sp_free_dma(ha, sp);
470 mempool_free(sp, ha->srb_mempool);
471
472qc24_host_busy_lock:
473 spin_lock_irq(ha->host->host_lock);
474
475qc24_host_busy:
476 return SCSI_MLQUEUE_HOST_BUSY;
477
478qc24_fail_command:
479 done(cmd);
480
481 return 0;
482}
483
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485/*
486 * qla2x00_eh_wait_on_command
487 * Waits for the command to be returned by the Firmware for some
488 * max time.
489 *
490 * Input:
491 * ha = actual ha whose done queue will contain the command
492 * returned by firmware.
493 * cmd = Scsi Command to wait on.
494 * flag = Abort/Reset(Bus or Device Reset)
495 *
496 * Return:
497 * Not Found : 0
498 * Found : 1
499 */
500static int
501qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
502{
503#define ABORT_POLLING_PERIOD HZ
f4f051e2005-04-17 15:02:26 -0500504#define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
505 unsigned long wait_iter = ABORT_WAIT_ITER;
506 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
f4f051e2005-04-17 15:02:26 -0500508 while (CMD_SP(cmd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 set_current_state(TASK_UNINTERRUPTIBLE);
510 schedule_timeout(ABORT_POLLING_PERIOD);
511
f4f051e2005-04-17 15:02:26 -0500512 if (--wait_iter)
513 break;
514 }
515 if (CMD_SP(cmd))
516 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
f4f051e2005-04-17 15:02:26 -0500518 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
521/*
522 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700523 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 * <= MAX_RETRIES_OF_ISP_ABORT or
525 * finally HBA is disabled ie marked offline
526 *
527 * Input:
528 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700529 *
530 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * Does context switching-Release SPIN_LOCK
532 * (if any) before calling this routine.
533 *
534 * Return:
535 * Success (Adapter is online) : 0
536 * Failed (Adapter is offline/disabled) : 1
537 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700538static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
540{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700541 int return_status;
542 unsigned long wait_online;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700544 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
546 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
547 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
548 ha->dpc_active) && time_before(jiffies, wait_online)) {
549
550 msleep(1000);
551 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700552 if (ha->flags.online)
553 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 else
555 return_status = QLA_FUNCTION_FAILED;
556
557 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
558
559 return (return_status);
560}
561
562/*
563 * qla2x00_wait_for_loop_ready
564 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700565 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 * Input:
567 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700568 *
569 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 * Does context switching-Release SPIN_LOCK
571 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700572 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 *
574 * Return:
575 * Success (LOOP_READY) : 0
576 * Failed (LOOP_NOT_READY) : 1
577 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700578static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
580{
581 int return_status = QLA_SUCCESS;
582 unsigned long loop_timeout ;
583
584 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700585 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 while ((!atomic_read(&ha->loop_down_timer) &&
588 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 atomic_read(&ha->loop_state) != LOOP_READY) {
590 msleep(1000);
591 if (time_after_eq(jiffies, loop_timeout)) {
592 return_status = QLA_FUNCTION_FAILED;
593 break;
594 }
595 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700596 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
599/**************************************************************************
600* qla2xxx_eh_abort
601*
602* Description:
603* The abort function will abort the specified command.
604*
605* Input:
606* cmd = Linux SCSI command packet to be aborted.
607*
608* Returns:
609* Either SUCCESS or FAILED.
610*
611* Note:
612**************************************************************************/
613int
614qla2xxx_eh_abort(struct scsi_cmnd *cmd)
615{
f4f051e2005-04-17 15:02:26 -0500616 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
617 srb_t *sp;
618 int ret, i;
619 unsigned int id, lun;
620 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700621 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
f4f051e2005-04-17 15:02:26 -0500623 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
f4f051e2005-04-17 15:02:26 -0500626 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
f4f051e2005-04-17 15:02:26 -0500628 id = cmd->device->id;
629 lun = cmd->device->lun;
630 serial = cmd->serial_number;
631
632 /* Check active list for command command. */
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700633 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500634 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
635 sp = ha->outstanding_cmds[i];
636
637 if (sp == NULL)
638 continue;
639
640 if (sp->cmd != cmd)
641 continue;
642
643 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
644 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
645 sp->state));
646 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
647
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700648 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700649 if (ha->isp_ops.abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500650 DEBUG2(printk("%s(%ld): abort_command "
651 "mbx failed.\n", __func__, ha->host_no));
652 } else {
653 DEBUG3(printk("%s(%ld): abort_command "
654 "mbx success.\n", __func__, ha->host_no));
655 ret = SUCCESS;
656 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700657 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500658
659 break;
660 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500662
663 /* Wait for the command to be returned. */
664 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500665 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700666 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500667 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
668 "%x.\n", ha->host_no, id, lun, serial, ret);
669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700672 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500673 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
674 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
f4f051e2005-04-17 15:02:26 -0500676 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
679/**************************************************************************
680* qla2x00_eh_wait_for_pending_target_commands
681*
682* Description:
683* Waits for all the commands to come back from the specified target.
684*
685* Input:
686* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700687* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688* Returns:
689* Either SUCCESS or FAILED.
690*
691* Note:
692**************************************************************************/
693static int
694qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
695{
696 int cnt;
697 int status;
698 srb_t *sp;
699 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700700 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 status = 0;
703
704 /*
705 * Waiting for all commands for the designated target in the active
706 * array
707 */
708 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700709 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 sp = ha->outstanding_cmds[cnt];
711 if (sp) {
712 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 if (cmd->device->id == t) {
715 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
716 status = 1;
717 break;
718 }
719 }
f4f051e2005-04-17 15:02:26 -0500720 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700721 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
723 }
724 return (status);
725}
726
727
728/**************************************************************************
729* qla2xxx_eh_device_reset
730*
731* Description:
732* The device reset function will reset the target and abort any
733* executing commands.
734*
735* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700736* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737* non-null.
738*
739* Input:
740* cmd = Linux SCSI command packet of the command that cause the
741* bus device reset.
742*
743* Returns:
744* SUCCESS/FAILURE (defined as macro in scsi.h).
745*
746**************************************************************************/
747int
748qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
749{
f4f051e2005-04-17 15:02:26 -0500750 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500751 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500752 srb_t *sp;
753 int ret;
754 unsigned int id, lun;
755 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
f4f051e2005-04-17 15:02:26 -0500757 ret = FAILED;
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
f4f051e2005-04-17 15:02:26 -0500763 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500764 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500765 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500768 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400770 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500774 if (qla2x00_device_reset(ha, fcport) == 0)
775 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500778 if (ret == SUCCESS) {
779 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700780 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
f4f051e2005-04-17 15:02:26 -0500781 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
783 }
784#endif
785 } else {
786 DEBUG2(printk(KERN_INFO
787 "%s failed: loop not ready\n",__func__);)
788 }
789
f4f051e2005-04-17 15:02:26 -0500790 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 DEBUG3(printk("%s(%ld): device reset failed\n",
792 __func__, ha->host_no));
793 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
794 __func__);
795
796 goto eh_dev_reset_done;
797 }
798
799 /*
800 * If we are coming down the EH path, wait for all commands to
801 * complete for the device.
802 */
803 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500804 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
805 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
f4f051e2005-04-17 15:02:26 -0500807 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 DEBUG3(printk("%s(%ld): failed while waiting for "
809 "commands\n", __func__, ha->host_no));
810 qla_printk(KERN_INFO, ha,
811 "%s: failed while waiting for commands\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700812 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 goto eh_dev_reset_done;
815 }
816 }
817
818 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500819 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500822 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
825/**************************************************************************
826* qla2x00_eh_wait_for_pending_commands
827*
828* Description:
829* Waits for all the commands to come back from the specified host.
830*
831* Input:
832* ha - pointer to scsi_qla_host structure.
833*
834* Returns:
835* 1 : SUCCESS
836* 0 : FAILED
837*
838* Note:
839**************************************************************************/
840static int
841qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
842{
843 int cnt;
844 int status;
845 srb_t *sp;
846 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700847 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 status = 1;
850
851 /*
852 * Waiting for all commands for the designated target in the active
853 * array
854 */
855 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700856 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 sp = ha->outstanding_cmds[cnt];
858 if (sp) {
859 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700860 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 status = qla2x00_eh_wait_on_command(ha, cmd);
862 if (status == 0)
863 break;
864 }
865 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700866 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868 }
869 return (status);
870}
871
872
873/**************************************************************************
874* qla2xxx_eh_bus_reset
875*
876* Description:
877* The bus reset function will reset the bus and abort any executing
878* commands.
879*
880* Input:
881* cmd = Linux SCSI command packet of the command that cause the
882* bus reset.
883*
884* Returns:
885* SUCCESS/FAILURE (defined as macro in scsi.h).
886*
887**************************************************************************/
888int
889qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
890{
f4f051e2005-04-17 15:02:26 -0500891 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500892 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500894 int ret;
895 unsigned int id, lun;
896 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
f4f051e2005-04-17 15:02:26 -0500898 ret = FAILED;
899
900 id = cmd->device->id;
901 lun = cmd->device->lun;
902 serial = cmd->serial_number;
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500905 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500906 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500909 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
912 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500913 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 }
915
916 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500917 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
918 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
f4f051e2005-04-17 15:02:26 -0500920 if (ret == FAILED)
921 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 /* Waiting for our command in done_queue to be returned to OS.*/
924 if (cmd->device->host->eh_active)
925 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500926 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
f4f051e2005-04-17 15:02:26 -0500928eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500930 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
f4f051e2005-04-17 15:02:26 -0500932 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
935/**************************************************************************
936* qla2xxx_eh_host_reset
937*
938* Description:
939* The reset function will reset the Adapter.
940*
941* Input:
942* cmd = Linux SCSI command packet of the command that cause the
943* adapter reset.
944*
945* Returns:
946* Either SUCCESS or FAILED.
947*
948* Note:
949**************************************************************************/
950int
951qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
952{
f4f051e2005-04-17 15:02:26 -0500953 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500954 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500955 srb_t *sp;
956 int ret;
957 unsigned int id, lun;
958 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
f4f051e2005-04-17 15:02:26 -0500960 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
f4f051e2005-04-17 15:02:26 -0500962 id = cmd->device->id;
963 lun = cmd->device->lun;
964 serial = cmd->serial_number;
965
966 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500967 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500968 return ret;
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500971 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500974 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 /*
977 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700978 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 * be completed and then issue big hammer.Otherwise
980 * it may cause I/O failure as big hammer marks the
981 * devices as lost kicking of the port_down_timer
982 * while dpc is stuck for the mailbox to complete.
983 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 qla2x00_wait_for_loop_ready(ha);
985 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
986 if (qla2x00_abort_isp(ha)) {
987 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
988 /* failed. schedule dpc to try */
989 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
990
991 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500992 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500997 if (qla2x00_eh_wait_for_pending_commands(ha))
998 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
f4f051e2005-04-17 15:02:26 -05001000eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001001 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1002 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
f4f051e2005-04-17 15:02:26 -05001004 return ret;
1005}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007/*
1008* qla2x00_loop_reset
1009* Issue loop reset.
1010*
1011* Input:
1012* ha = adapter block pointer.
1013*
1014* Returns:
1015* 0 = success
1016*/
1017static int
1018qla2x00_loop_reset(scsi_qla_host_t *ha)
1019{
1020 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -05001021 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 if (ha->flags.enable_lip_reset) {
1024 status = qla2x00_lip_reset(ha);
1025 }
1026
1027 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001028 list_for_each_entry(fcport, &ha->fcports, list) {
1029 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 continue;
1031
Andrew Vasquezc00c72a2005-08-26 19:08:50 -07001032 status = qla2x00_device_reset(ha, fcport);
bdf79622005-04-17 15:06:53 -05001033 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036 }
1037
1038 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001039 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 !ha->flags.enable_lip_reset) ||
1041 ha->flags.enable_lip_full_login)) {
1042
1043 status = qla2x00_full_login_lip(ha);
1044 }
1045
1046 /* Issue marker command only when we are going to start the I/O */
1047 ha->marker_needed = 1;
1048
1049 if (status) {
1050 /* Empty */
1051 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1052 __func__,
1053 ha->host_no);)
1054 } else {
1055 /* Empty */
1056 DEBUG3(printk("%s(%ld): exiting normally.\n",
1057 __func__,
1058 ha->host_no);)
1059 }
1060
1061 return(status);
1062}
1063
1064/*
1065 * qla2x00_device_reset
1066 * Issue bus device reset message to the target.
1067 *
1068 * Input:
1069 * ha = adapter block pointer.
1070 * t = SCSI ID.
1071 * TARGET_QUEUE_LOCK must be released.
1072 * ADAPTER_STATE_LOCK must be released.
1073 *
1074 * Context:
1075 * Kernel context.
1076 */
1077static int
1078qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1079{
1080 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001081 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
f4f051e2005-04-17 15:02:26 -05001084static int
1085qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
bdf79622005-04-17 15:06:53 -05001087 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
bdf79622005-04-17 15:06:53 -05001089 if (!rport)
f4f051e2005-04-17 15:02:26 -05001090 return -ENXIO;
1091
Andrew Vasquez77d74142005-07-08 18:00:36 -07001092 sdev->hostdata = rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001093
1094 return 0;
1095}
1096
1097static int
1098qla2xxx_slave_configure(struct scsi_device *sdev)
1099{
8482e1182005-04-17 15:04:54 -05001100 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1101 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1102
f4f051e2005-04-17 15:02:26 -05001103 if (sdev->tagged_supported)
1104 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 else
f4f051e2005-04-17 15:02:26 -05001106 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
8482e1182005-04-17 15:04:54 -05001108 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1109
f4f051e2005-04-17 15:02:26 -05001110 return 0;
1111}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
f4f051e2005-04-17 15:02:26 -05001113static void
1114qla2xxx_slave_destroy(struct scsi_device *sdev)
1115{
1116 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001119static int
1120qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1121{
1122 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1123 return sdev->queue_depth;
1124}
1125
1126static int
1127qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1128{
1129 if (sdev->tagged_supported) {
1130 scsi_set_tag_type(sdev, tag_type);
1131 if (tag_type)
1132 scsi_activate_tcq(sdev, sdev->queue_depth);
1133 else
1134 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1135 } else
1136 tag_type = 0;
1137
1138 return tag_type;
1139}
1140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141/**
1142 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1143 * @ha: HA context
1144 *
1145 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1146 * supported addressing method.
1147 */
1148static void
1149qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1150{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001151 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001154 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1155 /* Any upper-dword bits set? */
1156 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1157 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1158 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001160 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1161 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001162 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001165
1166 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1167 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
1170static int
1171qla2x00_iospace_config(scsi_qla_host_t *ha)
1172{
1173 unsigned long pio, pio_len, pio_flags;
1174 unsigned long mmio, mmio_len, mmio_flags;
1175
1176 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1177 pio = pci_resource_start(ha->pdev, 0);
1178 pio_len = pci_resource_len(ha->pdev, 0);
1179 pio_flags = pci_resource_flags(ha->pdev, 0);
1180 if (pio_flags & IORESOURCE_IO) {
1181 if (pio_len < MIN_IOBASE_LEN) {
1182 qla_printk(KERN_WARNING, ha,
1183 "Invalid PCI I/O region size (%s)...\n",
1184 pci_name(ha->pdev));
1185 pio = 0;
1186 }
1187 } else {
1188 qla_printk(KERN_WARNING, ha,
1189 "region #0 not a PIO resource (%s)...\n",
1190 pci_name(ha->pdev));
1191 pio = 0;
1192 }
1193
1194 /* Use MMIO operations for all accesses. */
1195 mmio = pci_resource_start(ha->pdev, 1);
1196 mmio_len = pci_resource_len(ha->pdev, 1);
1197 mmio_flags = pci_resource_flags(ha->pdev, 1);
1198
1199 if (!(mmio_flags & IORESOURCE_MEM)) {
1200 qla_printk(KERN_ERR, ha,
1201 "region #0 not an MMIO resource (%s), aborting\n",
1202 pci_name(ha->pdev));
1203 goto iospace_error_exit;
1204 }
1205 if (mmio_len < MIN_IOBASE_LEN) {
1206 qla_printk(KERN_ERR, ha,
1207 "Invalid PCI mem region size (%s), aborting\n",
1208 pci_name(ha->pdev));
1209 goto iospace_error_exit;
1210 }
1211
1212 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1213 qla_printk(KERN_WARNING, ha,
1214 "Failed to reserve PIO/MMIO regions (%s)\n",
1215 pci_name(ha->pdev));
1216
1217 goto iospace_error_exit;
1218 }
1219
1220 ha->pio_address = pio;
1221 ha->pio_length = pio_len;
1222 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1223 if (!ha->iobase) {
1224 qla_printk(KERN_ERR, ha,
1225 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1226
1227 goto iospace_error_exit;
1228 }
1229
1230 return (0);
1231
1232iospace_error_exit:
1233 return (-ENOMEM);
1234}
1235
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001236static void
1237qla2x00_enable_intrs(scsi_qla_host_t *ha)
1238{
1239 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001240 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001241
1242 spin_lock_irqsave(&ha->hardware_lock, flags);
1243 ha->interrupts_on = 1;
1244 /* enable risc and host interrupts */
1245 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1246 RD_REG_WORD(&reg->ictrl);
1247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1248
1249}
1250
1251static void
1252qla2x00_disable_intrs(scsi_qla_host_t *ha)
1253{
1254 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001255 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001256
1257 spin_lock_irqsave(&ha->hardware_lock, flags);
1258 ha->interrupts_on = 0;
1259 /* disable risc and host interrupts */
1260 WRT_REG_WORD(&reg->ictrl, 0);
1261 RD_REG_WORD(&reg->ictrl);
1262 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1263}
1264
Andrew Vasquezfca29702005-07-06 10:31:47 -07001265static void
1266qla24xx_enable_intrs(scsi_qla_host_t *ha)
1267{
1268 unsigned long flags = 0;
1269 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1270
1271 spin_lock_irqsave(&ha->hardware_lock, flags);
1272 ha->interrupts_on = 1;
1273 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1274 RD_REG_DWORD(&reg->ictrl);
1275 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1276}
1277
1278static void
1279qla24xx_disable_intrs(scsi_qla_host_t *ha)
1280{
1281 unsigned long flags = 0;
1282 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1283
1284 spin_lock_irqsave(&ha->hardware_lock, flags);
1285 ha->interrupts_on = 0;
1286 WRT_REG_DWORD(&reg->ictrl, 0);
1287 RD_REG_DWORD(&reg->ictrl);
1288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1289}
1290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291/*
1292 * PCI driver interface
1293 */
1294int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1295{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001296 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001297 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 struct Scsi_Host *host;
1299 scsi_qla_host_t *ha;
1300 unsigned long flags = 0;
1301 unsigned long wait_switch = 0;
1302 char pci_info[20];
1303 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001304 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
1306 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001307 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Andrew Vasquezfca29702005-07-06 10:31:47 -07001309 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1310 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 if (host == NULL) {
1312 printk(KERN_WARNING
1313 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1314 goto probe_disable_device;
1315 }
1316
1317 /* Clear our data area */
1318 ha = (scsi_qla_host_t *)host->hostdata;
1319 memset(ha, 0, sizeof(scsi_qla_host_t));
1320
1321 ha->pdev = pdev;
1322 ha->host = host;
1323 ha->host_no = host->host_no;
1324 ha->brd_info = brd_info;
1325 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1326
1327 /* Configure PCI I/O space */
1328 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001329 if (ret)
1330 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 qla_printk(KERN_INFO, ha,
1333 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001334 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
1336 spin_lock_init(&ha->hardware_lock);
1337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 ha->prev_topology = 0;
1339 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001340 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001341 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001343 /* Assign ISP specific operations. */
1344 ha->isp_ops.pci_config = qla2100_pci_config;
1345 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1346 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1347 ha->isp_ops.config_rings = qla2x00_config_rings;
1348 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1349 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1350 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001351 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001352 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1353 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1354 ha->isp_ops.intr_handler = qla2100_intr_handler;
1355 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1356 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1357 ha->isp_ops.abort_command = qla2x00_abort_command;
1358 ha->isp_ops.abort_target = qla2x00_abort_target;
1359 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1360 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1361 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1362 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1363 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001364 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001365 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1366 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001367 ha->isp_ops.fw_dump = qla2100_fw_dump;
1368 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001370 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1372 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1373 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1374 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1375 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001376 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001378 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1380 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1381 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1382 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001383 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001384 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001385 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1387 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1388 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1389 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001390 ha->isp_ops.pci_config = qla2300_pci_config;
1391 ha->isp_ops.intr_handler = qla2300_intr_handler;
1392 ha->isp_ops.fw_dump = qla2300_fw_dump;
1393 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1394 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001395 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1396 host->max_id = MAX_TARGETS_2200;
1397 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1398 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1399 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1400 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1401 ha->init_cb_size = sizeof(struct init_cb_24xx);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001402 ha->mgmt_svr_loop_id = 10;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001403 ha->isp_ops.pci_config = qla24xx_pci_config;
1404 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1405 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1406 ha->isp_ops.config_rings = qla24xx_config_rings;
1407 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1408 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1409 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1410 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1411 if (ql2xfwloadbin)
1412 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1413 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1414 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1415 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1416 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1417 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1418 ha->isp_ops.abort_command = qla24xx_abort_command;
1419 ha->isp_ops.abort_target = qla24xx_abort_target;
1420 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1421 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1422 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001423 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001424 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1425 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1426 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1427 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1428 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430 host->can_queue = ha->request_q_length + 128;
1431
1432 /* load the F/W, read paramaters, and init the H/W */
1433 ha->instance = num_hosts;
1434
1435 init_MUTEX(&ha->mbx_cmd_sem);
1436 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1437
1438 INIT_LIST_HEAD(&ha->list);
1439 INIT_LIST_HEAD(&ha->fcports);
1440 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442 /*
1443 * These locks are used to prevent more than one CPU
1444 * from modifying the queue at the same time. The
1445 * higher level "host_lock" will reduce most
1446 * contention for these locks.
1447 */
1448 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 ha->dpc_pid = -1;
1451 init_completion(&ha->dpc_inited);
1452 init_completion(&ha->dpc_exited);
1453
1454 qla2x00_config_dma_addressing(ha);
1455 if (qla2x00_mem_alloc(ha)) {
1456 qla_printk(KERN_WARNING, ha,
1457 "[ERROR] Failed to allocate memory for adapter\n");
1458
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001459 ret = -ENOMEM;
1460 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 }
1462
1463 if (qla2x00_initialize_adapter(ha) &&
1464 !(ha->device_flags & DFLG_NO_CABLE)) {
1465
1466 qla_printk(KERN_WARNING, ha,
1467 "Failed to initialize adapter\n");
1468
1469 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1470 "Adapter flags %x.\n",
1471 ha->host_no, ha->device_flags));
1472
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001473 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 goto probe_failed;
1475 }
1476
1477 /*
1478 * Startup the kernel thread for this host adapter
1479 */
1480 ha->dpc_should_die = 0;
1481 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1482 if (ha->dpc_pid < 0) {
1483 qla_printk(KERN_WARNING, ha,
1484 "Unable to start DPC thread!\n");
1485
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001486 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 goto probe_failed;
1488 }
1489 wait_for_completion(&ha->dpc_inited);
1490
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001491 host->this_id = 255;
1492 host->cmd_per_lun = 3;
1493 host->unique_id = ha->instance;
1494 host->max_cmd_len = MAX_CMDSZ;
1495 host->max_channel = ha->ports - 1;
1496 host->max_lun = MAX_LUNS;
1497 host->transportt = qla2xxx_transport_template;
1498
Andrew Vasquezfca29702005-07-06 10:31:47 -07001499 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001500 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001501 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 qla_printk(KERN_WARNING, ha,
1503 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001504 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 goto probe_failed;
1506 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001507 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 /* Initialized the timer */
1510 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1511
1512 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1513 ha->host_no, ha));
1514
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001515 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001518 reg = ha->iobase;
1519 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1520 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1521 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1522 } else {
1523 WRT_REG_WORD(&reg->isp.semaphore, 0);
1524 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1525 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Andrew Vasquezfca29702005-07-06 10:31:47 -07001527 /* Enable proper parity */
1528 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1529 if (IS_QLA2300(ha))
1530 /* SRAM parity */
1531 WRT_REG_WORD(&reg->isp.hccr,
1532 (HCCR_ENABLE_PARITY + 0x1));
1533 else
1534 /* SRAM, Instruction RAM and GP RAM parity */
1535 WRT_REG_WORD(&reg->isp.hccr,
1536 (HCCR_ENABLE_PARITY + 0x7));
1537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 }
1539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1540
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001541 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 /* v2.19.5b6 */
1544 /*
1545 * Wait around max loop_reset_delay secs for the devices to come
1546 * on-line. We don't want Linux scanning before we are ready.
1547 *
1548 */
1549 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1550 time_before(jiffies,wait_switch) &&
1551 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1552 && (ha->device_flags & SWITCH_FOUND) ;) {
1553
1554 qla2x00_check_fabric_devices(ha);
1555
1556 msleep(10);
1557 }
1558
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001559 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 ha->flags.init_done = 1;
1561 num_hosts++;
1562
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001563 ret = scsi_add_host(host, &pdev->dev);
1564 if (ret)
1565 goto probe_failed;
1566
1567 qla2x00_alloc_sysfs_attr(ha);
1568
1569 qla2x00_init_host_attr(ha);
1570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 qla_printk(KERN_INFO, ha, "\n"
1572 " QLogic Fibre Channel HBA Driver: %s\n"
1573 " QLogic %s - %s\n"
1574 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1575 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001576 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001577 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001578 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
8482e1182005-04-17 15:04:54 -05001580 /* Go with fc_rport registration. */
1581 list_for_each_entry(fcport, &ha->fcports, list)
1582 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 return 0;
1585
1586probe_failed:
bdf79622005-04-17 15:06:53 -05001587 fc_remove_host(ha->host);
1588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 qla2x00_free_device(ha);
1590
1591 scsi_host_put(host);
1592
1593probe_disable_device:
1594 pci_disable_device(pdev);
1595
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001596probe_out:
1597 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
1599EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1600
1601void qla2x00_remove_one(struct pci_dev *pdev)
1602{
1603 scsi_qla_host_t *ha;
1604
1605 ha = pci_get_drvdata(pdev);
1606
8482e1182005-04-17 15:04:54 -05001607 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
bdf79622005-04-17 15:06:53 -05001609 fc_remove_host(ha->host);
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 scsi_remove_host(ha->host);
1612
1613 qla2x00_free_device(ha);
1614
1615 scsi_host_put(ha->host);
1616
1617 pci_set_drvdata(pdev, NULL);
1618}
1619EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1620
1621static void
1622qla2x00_free_device(scsi_qla_host_t *ha)
1623{
1624 int ret;
1625
1626 /* Abort any outstanding IO descriptors. */
1627 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1628 qla2x00_cancel_io_descriptors(ha);
1629
1630 /* turn-off interrupts on the card */
1631 if (ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001632 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634 /* Disable timer */
1635 if (ha->timer_active)
1636 qla2x00_stop_timer(ha);
1637
1638 /* Kill the kernel thread for this host */
1639 if (ha->dpc_pid >= 0) {
1640 ha->dpc_should_die = 1;
1641 wmb();
1642 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1643 if (ret) {
1644 qla_printk(KERN_ERR, ha,
1645 "Unable to signal DPC thread -- (%d)\n", ret);
1646
1647 /* TODO: SOMETHING MORE??? */
1648 } else {
1649 wait_for_completion(&ha->dpc_exited);
1650 }
1651 }
1652
1653 qla2x00_mem_free(ha);
1654
1655
1656 ha->flags.online = 0;
1657
1658 /* Detach interrupts */
1659 if (ha->pdev->irq)
1660 free_irq(ha->pdev->irq, ha);
1661
1662 /* release io space registers */
1663 if (ha->iobase)
1664 iounmap(ha->iobase);
1665 pci_release_regions(ha->pdev);
1666
1667 pci_disable_device(ha->pdev);
1668}
1669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1672 *
1673 * Input: ha = adapter block pointer. fcport = port structure pointer.
1674 *
1675 * Return: None.
1676 *
1677 * Context:
1678 */
1679void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1680 int do_login)
1681{
8482e1182005-04-17 15:04:54 -05001682 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1683 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001684 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 * We may need to retry the login, so don't change the state of the
1686 * port but do the retries.
1687 */
1688 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1689 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1690
1691 if (!do_login)
1692 return;
1693
1694 if (fcport->login_retry == 0) {
1695 fcport->login_retry = ha->login_retry_count;
1696 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1697
1698 DEBUG(printk("scsi(%ld): Port login retry: "
1699 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1700 "id = 0x%04x retry cnt=%d\n",
1701 ha->host_no,
1702 fcport->port_name[0],
1703 fcport->port_name[1],
1704 fcport->port_name[2],
1705 fcport->port_name[3],
1706 fcport->port_name[4],
1707 fcport->port_name[5],
1708 fcport->port_name[6],
1709 fcport->port_name[7],
1710 fcport->loop_id,
1711 fcport->login_retry));
1712 }
1713}
1714
1715/*
1716 * qla2x00_mark_all_devices_lost
1717 * Updates fcport state when device goes offline.
1718 *
1719 * Input:
1720 * ha = adapter block pointer.
1721 * fcport = port structure pointer.
1722 *
1723 * Return:
1724 * None.
1725 *
1726 * Context:
1727 */
1728void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001729qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
1731 fc_port_t *fcport;
1732
1733 list_for_each_entry(fcport, &ha->fcports, list) {
1734 if (fcport->port_type != FCT_TARGET)
1735 continue;
1736
1737 /*
1738 * No point in marking the device as lost, if the device is
1739 * already DEAD.
1740 */
1741 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1742 continue;
8482e1182005-04-17 15:04:54 -05001743 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1744 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1746 }
1747}
1748
1749/*
1750* qla2x00_mem_alloc
1751* Allocates adapter memory.
1752*
1753* Returns:
1754* 0 = success.
1755* 1 = failure.
1756*/
1757static uint8_t
1758qla2x00_mem_alloc(scsi_qla_host_t *ha)
1759{
1760 char name[16];
1761 uint8_t status = 1;
1762 int retry= 10;
1763
1764 do {
1765 /*
1766 * This will loop only once if everything goes well, else some
1767 * number of retries will be performed to get around a kernel
1768 * bug where available mem is not allocated until after a
1769 * little delay and a retry.
1770 */
1771 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1772 (ha->request_q_length + 1) * sizeof(request_t),
1773 &ha->request_dma, GFP_KERNEL);
1774 if (ha->request_ring == NULL) {
1775 qla_printk(KERN_WARNING, ha,
1776 "Memory Allocation failed - request_ring\n");
1777
1778 qla2x00_mem_free(ha);
1779 msleep(100);
1780
1781 continue;
1782 }
1783
1784 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1785 (ha->response_q_length + 1) * sizeof(response_t),
1786 &ha->response_dma, GFP_KERNEL);
1787 if (ha->response_ring == NULL) {
1788 qla_printk(KERN_WARNING, ha,
1789 "Memory Allocation failed - response_ring\n");
1790
1791 qla2x00_mem_free(ha);
1792 msleep(100);
1793
1794 continue;
1795 }
1796
1797 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1798 &ha->gid_list_dma, GFP_KERNEL);
1799 if (ha->gid_list == NULL) {
1800 qla_printk(KERN_WARNING, ha,
1801 "Memory Allocation failed - gid_list\n");
1802
1803 qla2x00_mem_free(ha);
1804 msleep(100);
1805
1806 continue;
1807 }
1808
1809 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1810 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1811 if (ha->rlc_rsp == NULL) {
1812 qla_printk(KERN_WARNING, ha,
1813 "Memory Allocation failed - rlc");
1814
1815 qla2x00_mem_free(ha);
1816 msleep(100);
1817
1818 continue;
1819 }
1820
1821 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1822 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1823 DMA_POOL_SIZE, 8, 0);
1824 if (ha->s_dma_pool == NULL) {
1825 qla_printk(KERN_WARNING, ha,
1826 "Memory Allocation failed - s_dma_pool\n");
1827
1828 qla2x00_mem_free(ha);
1829 msleep(100);
1830
1831 continue;
1832 }
1833
1834 /* get consistent memory allocated for init control block */
1835 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1836 &ha->init_cb_dma);
1837 if (ha->init_cb == NULL) {
1838 qla_printk(KERN_WARNING, ha,
1839 "Memory Allocation failed - init_cb\n");
1840
1841 qla2x00_mem_free(ha);
1842 msleep(100);
1843
1844 continue;
1845 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001846 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 /* Get consistent memory allocated for Get Port Database cmd */
1849 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1850 &ha->iodesc_pd_dma);
1851 if (ha->iodesc_pd == NULL) {
1852 /* error */
1853 qla_printk(KERN_WARNING, ha,
1854 "Memory Allocation failed - iodesc_pd\n");
1855
1856 qla2x00_mem_free(ha);
1857 msleep(100);
1858
1859 continue;
1860 }
1861 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1862
1863 /* Allocate ioctl related memory. */
1864 if (qla2x00_alloc_ioctl_mem(ha)) {
1865 qla_printk(KERN_WARNING, ha,
1866 "Memory Allocation failed - ioctl_mem\n");
1867
1868 qla2x00_mem_free(ha);
1869 msleep(100);
1870
1871 continue;
1872 }
1873
1874 if (qla2x00_allocate_sp_pool(ha)) {
1875 qla_printk(KERN_WARNING, ha,
1876 "Memory Allocation failed - "
1877 "qla2x00_allocate_sp_pool()\n");
1878
1879 qla2x00_mem_free(ha);
1880 msleep(100);
1881
1882 continue;
1883 }
1884
1885 /* Allocate memory for SNS commands */
1886 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1887 /* Get consistent memory allocated for SNS commands */
1888 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1889 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1890 GFP_KERNEL);
1891 if (ha->sns_cmd == NULL) {
1892 /* error */
1893 qla_printk(KERN_WARNING, ha,
1894 "Memory Allocation failed - sns_cmd\n");
1895
1896 qla2x00_mem_free(ha);
1897 msleep(100);
1898
1899 continue;
1900 }
1901 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1902 } else {
1903 /* Get consistent memory allocated for MS IOCB */
1904 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1905 &ha->ms_iocb_dma);
1906 if (ha->ms_iocb == NULL) {
1907 /* error */
1908 qla_printk(KERN_WARNING, ha,
1909 "Memory Allocation failed - ms_iocb\n");
1910
1911 qla2x00_mem_free(ha);
1912 msleep(100);
1913
1914 continue;
1915 }
1916 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1917
1918 /*
1919 * Get consistent memory allocated for CT SNS
1920 * commands
1921 */
1922 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1923 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1924 GFP_KERNEL);
1925 if (ha->ct_sns == NULL) {
1926 /* error */
1927 qla_printk(KERN_WARNING, ha,
1928 "Memory Allocation failed - ct_sns\n");
1929
1930 qla2x00_mem_free(ha);
1931 msleep(100);
1932
1933 continue;
1934 }
1935 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1936 }
1937
1938 /* Done all allocations without any error. */
1939 status = 0;
1940
1941 } while (retry-- && status != 0);
1942
1943 if (status) {
1944 printk(KERN_WARNING
1945 "%s(): **** FAILED ****\n", __func__);
1946 }
1947
1948 return(status);
1949}
1950
1951/*
1952* qla2x00_mem_free
1953* Frees all adapter allocated memory.
1954*
1955* Input:
1956* ha = adapter block pointer.
1957*/
1958static void
1959qla2x00_mem_free(scsi_qla_host_t *ha)
1960{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 struct list_head *fcpl, *fcptemp;
1962 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 unsigned long wtime;/* max wait time if mbx cmd is busy. */
1964
1965 if (ha == NULL) {
1966 /* error */
1967 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1968 return;
1969 }
1970
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 /* Make sure all other threads are stopped. */
1972 wtime = 60 * HZ;
1973 while (ha->dpc_wait && wtime) {
1974 set_current_state(TASK_INTERRUPTIBLE);
1975 wtime = schedule_timeout(wtime);
1976 }
1977
1978 /* free ioctl memory */
1979 qla2x00_free_ioctl_mem(ha);
1980
1981 /* free sp pool */
1982 qla2x00_free_sp_pool(ha);
1983
1984 if (ha->sns_cmd)
1985 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1986 ha->sns_cmd, ha->sns_cmd_dma);
1987
1988 if (ha->ct_sns)
1989 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1990 ha->ct_sns, ha->ct_sns_dma);
1991
1992 if (ha->ms_iocb)
1993 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1994
1995 if (ha->iodesc_pd)
1996 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1997
1998 if (ha->init_cb)
1999 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
2000
2001 if (ha->s_dma_pool)
2002 dma_pool_destroy(ha->s_dma_pool);
2003
2004 if (ha->rlc_rsp)
2005 dma_free_coherent(&ha->pdev->dev,
2006 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2007 ha->rlc_rsp_dma);
2008
2009 if (ha->gid_list)
2010 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2011 ha->gid_list_dma);
2012
2013 if (ha->response_ring)
2014 dma_free_coherent(&ha->pdev->dev,
2015 (ha->response_q_length + 1) * sizeof(response_t),
2016 ha->response_ring, ha->response_dma);
2017
2018 if (ha->request_ring)
2019 dma_free_coherent(&ha->pdev->dev,
2020 (ha->request_q_length + 1) * sizeof(request_t),
2021 ha->request_ring, ha->request_dma);
2022
2023 ha->sns_cmd = NULL;
2024 ha->sns_cmd_dma = 0;
2025 ha->ct_sns = NULL;
2026 ha->ct_sns_dma = 0;
2027 ha->ms_iocb = NULL;
2028 ha->ms_iocb_dma = 0;
2029 ha->iodesc_pd = NULL;
2030 ha->iodesc_pd_dma = 0;
2031 ha->init_cb = NULL;
2032 ha->init_cb_dma = 0;
2033
2034 ha->s_dma_pool = NULL;
2035
2036 ha->rlc_rsp = NULL;
2037 ha->rlc_rsp_dma = 0;
2038 ha->gid_list = NULL;
2039 ha->gid_list_dma = 0;
2040
2041 ha->response_ring = NULL;
2042 ha->response_dma = 0;
2043 ha->request_ring = NULL;
2044 ha->request_dma = 0;
2045
2046 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2047 fcport = list_entry(fcpl, fc_port_t, list);
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 /* fc ports */
2050 list_del_init(&fcport->list);
2051 kfree(fcport);
2052 }
2053 INIT_LIST_HEAD(&ha->fcports);
2054
2055 if (ha->fw_dump)
2056 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2057
Andrew Vasquezfca29702005-07-06 10:31:47 -07002058 vfree(ha->fw_dump24);
2059
2060 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002063 ha->fw_dump24 = NULL;
2064 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 ha->fw_dump_reading = 0;
2066 ha->fw_dump_buffer = NULL;
2067}
2068
2069/*
2070 * qla2x00_allocate_sp_pool
2071 * This routine is called during initialization to allocate
2072 * memory for local srb_t.
2073 *
2074 * Input:
2075 * ha = adapter block pointer.
2076 *
2077 * Context:
2078 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002079 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 * Note: Sets the ref_count for non Null sp to one.
2081 */
2082static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002083qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084{
2085 int rval;
2086
2087 rval = QLA_SUCCESS;
2088 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2089 mempool_free_slab, srb_cachep);
2090 if (ha->srb_mempool == NULL) {
2091 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2092 rval = QLA_FUNCTION_FAILED;
2093 }
2094 return (rval);
2095}
2096
2097/*
2098 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002099 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 */
2101static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002102qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
2104 if (ha->srb_mempool) {
2105 mempool_destroy(ha->srb_mempool);
2106 ha->srb_mempool = NULL;
2107 }
2108}
2109
2110/**************************************************************************
2111* qla2x00_do_dpc
2112* This kernel thread is a task that is schedule by the interrupt handler
2113* to perform the background processing for interrupts.
2114*
2115* Notes:
2116* This task always run in the context of a kernel thread. It
2117* is kick-off by the driver's detect code and starts up
2118* up one per adapter. It immediately goes to sleep and waits for
2119* some fibre event. When either the interrupt handler or
2120* the timer routine detects a event it will one of the task
2121* bits then wake us up.
2122**************************************************************************/
2123static int
2124qla2x00_do_dpc(void *data)
2125{
2126 DECLARE_MUTEX_LOCKED(sem);
2127 scsi_qla_host_t *ha;
2128 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
2132 ha = (scsi_qla_host_t *)data;
2133
2134 lock_kernel();
2135
2136 daemonize("%s_dpc", ha->host_str);
2137 allow_signal(SIGHUP);
2138
2139 ha->dpc_wait = &sem;
2140
2141 set_user_nice(current, -20);
2142
2143 unlock_kernel();
2144
2145 complete(&ha->dpc_inited);
2146
2147 while (1) {
2148 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2149
2150 if (down_interruptible(&sem))
2151 break;
2152
2153 if (ha->dpc_should_die)
2154 break;
2155
2156 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2157
2158 /* Initialization not yet finished. Don't do anything yet. */
2159 if (!ha->flags.init_done || ha->dpc_active)
2160 continue;
2161
2162 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2163
2164 ha->dpc_active = 1;
2165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 ha->dpc_active = 0;
2168 continue;
2169 }
2170
2171 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2172
2173 DEBUG(printk("scsi(%ld): dpc: sched "
2174 "qla2x00_abort_isp ha = %p\n",
2175 ha->host_no, ha));
2176 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2177 &ha->dpc_flags))) {
2178
2179 if (qla2x00_abort_isp(ha)) {
2180 /* failed. retry later */
2181 set_bit(ISP_ABORT_NEEDED,
2182 &ha->dpc_flags);
2183 }
2184 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2185 }
2186 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2187 ha->host_no));
2188 }
2189
2190 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2191 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2192
2193 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2194 ha->host_no));
2195
2196 qla2x00_rst_aen(ha);
2197 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2198 }
2199
2200 /* Retry each device up to login retry count */
2201 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2202 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2203 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2204
2205 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2206 ha->host_no));
2207
2208 next_loopid = 0;
2209 list_for_each_entry(fcport, &ha->fcports, list) {
2210 if (fcport->port_type != FCT_TARGET)
2211 continue;
2212
2213 /*
2214 * If the port is not ONLINE then try to login
2215 * to it if we haven't run out of retries.
2216 */
2217 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2218 fcport->login_retry) {
2219
2220 fcport->login_retry--;
2221 if (fcport->flags & FCF_FABRIC_DEVICE) {
2222 if (fcport->flags &
2223 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002224 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002225 ha, fcport->loop_id,
2226 fcport->d_id.b.domain,
2227 fcport->d_id.b.area,
2228 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 status = qla2x00_fabric_login(
2230 ha, fcport, &next_loopid);
2231 } else
2232 status =
2233 qla2x00_local_device_login(
2234 ha, fcport->loop_id);
2235
2236 if (status == QLA_SUCCESS) {
2237 fcport->old_loop_id = fcport->loop_id;
2238
2239 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2240 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 fcport->port_login_retry_count =
2243 ha->port_down_retry_count * PORT_RETRY_TIME;
2244 atomic_set(&fcport->state, FCS_ONLINE);
2245 atomic_set(&fcport->port_down_timer,
2246 ha->port_down_retry_count * PORT_RETRY_TIME);
2247
2248 fcport->login_retry = 0;
2249 } else if (status == 1) {
2250 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2251 /* retry the login again */
2252 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2253 ha->host_no,
2254 fcport->login_retry, fcport->loop_id));
2255 } else {
2256 fcport->login_retry = 0;
2257 }
2258 }
2259 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2260 break;
2261 }
2262 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2263 ha->host_no));
2264 }
2265
2266 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2267 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2268
2269 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2270 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2271 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2274
2275 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2276 ha->host_no));
2277 }
2278
2279 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2280
2281 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2282 ha->host_no));
2283
2284 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2285 &ha->dpc_flags))) {
2286
2287 qla2x00_loop_resync(ha);
2288
2289 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2290 }
2291
2292 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2293 ha->host_no));
2294 }
2295
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2297
2298 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2299 ha->host_no));
2300
2301 qla2x00_rescan_fcports(ha);
2302
2303 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2304 "end.\n",
2305 ha->host_no));
2306 }
2307
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002309 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 ha->dpc_active = 0;
2312 } /* End of while(1) */
2313
2314 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2315
2316 /*
2317 * Make sure that nobody tries to wake us up again.
2318 */
2319 ha->dpc_wait = NULL;
2320 ha->dpc_active = 0;
2321
2322 complete_and_exit(&ha->dpc_exited, 0);
2323}
2324
2325/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326* qla2x00_rst_aen
2327* Processes asynchronous reset.
2328*
2329* Input:
2330* ha = adapter block pointer.
2331*/
2332static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002333qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
2335 if (ha->flags.online && !ha->flags.reset_active &&
2336 !atomic_read(&ha->loop_down_timer) &&
2337 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2338 do {
2339 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2340
2341 /*
2342 * Issue marker command only when we are going to start
2343 * the I/O.
2344 */
2345 ha->marker_needed = 1;
2346 } while (!atomic_read(&ha->loop_down_timer) &&
2347 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2348 }
2349}
2350
f4f051e2005-04-17 15:02:26 -05002351static void
2352qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2353{
2354 struct scsi_cmnd *cmd = sp->cmd;
2355
2356 if (sp->flags & SRB_DMA_VALID) {
2357 if (cmd->use_sg) {
2358 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2359 cmd->use_sg, cmd->sc_data_direction);
2360 } else if (cmd->request_bufflen) {
2361 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2362 cmd->request_bufflen, cmd->sc_data_direction);
2363 }
2364 sp->flags &= ~SRB_DMA_VALID;
2365 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002366 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002367}
2368
2369void
2370qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2371{
2372 struct scsi_cmnd *cmd = sp->cmd;
2373
2374 qla2x00_sp_free_dma(ha, sp);
2375
f4f051e2005-04-17 15:02:26 -05002376 mempool_free(sp, ha->srb_mempool);
2377
2378 cmd->scsi_done(cmd);
2379}
bdf79622005-04-17 15:06:53 -05002380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381/**************************************************************************
2382* qla2x00_timer
2383*
2384* Description:
2385* One second timer
2386*
2387* Context: Interrupt
2388***************************************************************************/
2389static void
2390qla2x00_timer(scsi_qla_host_t *ha)
2391{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 unsigned long cpu_flags = 0;
2393 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 int start_dpc = 0;
2395 int index;
2396 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002397 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
2399 /*
2400 * Ports - Port down timer.
2401 *
2402 * Whenever, a port is in the LOST state we start decrementing its port
2403 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002404 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 */
2406 t = 0;
2407 list_for_each_entry(fcport, &ha->fcports, list) {
2408 if (fcport->port_type != FCT_TARGET)
2409 continue;
2410
2411 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2412
2413 if (atomic_read(&fcport->port_down_timer) == 0)
2414 continue;
2415
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002416 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002420 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 ha->host_no,
2422 t, atomic_read(&fcport->port_down_timer)));
2423 }
2424 t++;
2425 } /* End of for fcport */
2426
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 /* Loop down handler. */
2429 if (atomic_read(&ha->loop_down_timer) > 0 &&
2430 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2431
2432 if (atomic_read(&ha->loop_down_timer) ==
2433 ha->loop_down_abort_time) {
2434
2435 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2436 "queues before time expire\n",
2437 ha->host_no));
2438
2439 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002440 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
2442 /* Schedule an ISP abort to return any tape commands. */
2443 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2444 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2445 index++) {
bdf79622005-04-17 15:06:53 -05002446 fc_port_t *sfcp;
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 sp = ha->outstanding_cmds[index];
2449 if (!sp)
2450 continue;
bdf79622005-04-17 15:06:53 -05002451 sfcp = sp->fcport;
2452 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 continue;
2454
2455 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2456 break;
2457 }
2458 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2459
2460 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2461 start_dpc++;
2462 }
2463
2464 /* if the loop has been down for 4 minutes, reinit adapter */
2465 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2466 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2467 "restarting queues.\n",
2468 ha->host_no));
2469
2470 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2471 start_dpc++;
2472
2473 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2474 DEBUG(printk("scsi(%ld): Loop down - "
2475 "aborting ISP.\n",
2476 ha->host_no));
2477 qla_printk(KERN_WARNING, ha,
2478 "Loop down - aborting ISP.\n");
2479
2480 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2481 }
2482 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002483 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 ha->host_no,
2485 atomic_read(&ha->loop_down_timer)));
2486 }
2487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 /* Schedule the DPC routine if needed */
2489 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2490 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2491 start_dpc ||
2492 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002493 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2495 ha->dpc_wait && !ha->dpc_active) {
2496
2497 up(ha->dpc_wait);
2498 }
2499
2500 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2501}
2502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503/* XXX(hch): crude hack to emulate a down_timeout() */
2504int
2505qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2506{
2507 const unsigned int step = HZ/10;
2508
2509 do {
2510 if (!down_trylock(sema))
2511 return 0;
2512 set_current_state(TASK_INTERRUPTIBLE);
2513 if (schedule_timeout(step))
2514 break;
2515 } while ((timeout -= step) > 0);
2516
2517 return -ETIMEDOUT;
2518}
2519
Andrew Vasquezfca29702005-07-06 10:31:47 -07002520static struct qla_board_info qla_board_tbl[] = {
2521 {
2522 .drv_name = "qla2400",
2523 .isp_name = "ISP2422",
2524 .fw_fname = "ql2400_fw.bin",
2525 .sht = &qla24xx_driver_template,
2526 },
2527 {
2528 .drv_name = "qla2400",
2529 .isp_name = "ISP2432",
2530 .fw_fname = "ql2400_fw.bin",
2531 .sht = &qla24xx_driver_template,
2532 },
2533};
2534
2535static struct pci_device_id qla2xxx_pci_tbl[] = {
2536 {
2537 .vendor = PCI_VENDOR_ID_QLOGIC,
2538 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2539 .subvendor = PCI_ANY_ID,
2540 .subdevice = PCI_ANY_ID,
2541 .driver_data = (unsigned long)&qla_board_tbl[0],
2542 },
2543 {
2544 .vendor = PCI_VENDOR_ID_QLOGIC,
2545 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2546 .subvendor = PCI_ANY_ID,
2547 .subdevice = PCI_ANY_ID,
2548 .driver_data = (unsigned long)&qla_board_tbl[1],
2549 },
2550 {0, 0},
2551};
2552MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2553
2554static int __devinit
2555qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2556{
2557 return qla2x00_probe_one(pdev,
2558 (struct qla_board_info *)id->driver_data);
2559}
2560
2561static void __devexit
2562qla2xxx_remove_one(struct pci_dev *pdev)
2563{
2564 qla2x00_remove_one(pdev);
2565}
2566
2567static struct pci_driver qla2xxx_pci_driver = {
2568 .name = "qla2xxx",
2569 .id_table = qla2xxx_pci_tbl,
2570 .probe = qla2xxx_probe_one,
2571 .remove = __devexit_p(qla2xxx_remove_one),
2572};
2573
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574/**
2575 * qla2x00_module_init - Module initialization.
2576 **/
2577static int __init
2578qla2x00_module_init(void)
2579{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002580 int ret = 0;
2581
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002583 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 SLAB_HWCACHE_ALIGN, NULL, NULL);
2585 if (srb_cachep == NULL) {
2586 printk(KERN_ERR
2587 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2588 return -ENOMEM;
2589 }
2590
2591 /* Derive version string. */
2592 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2593#if DEBUG_QLA2100
2594 strcat(qla2x00_version_str, "-debug");
2595#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002596 qla2xxx_transport_template =
2597 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 if (!qla2xxx_transport_template)
2599 return -ENODEV;
2600
2601 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002602 ret = pci_module_init(&qla2xxx_pci_driver);
2603 if (ret) {
2604 kmem_cache_destroy(srb_cachep);
2605 fc_release_transport(qla2xxx_transport_template);
2606 }
2607 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/**
2611 * qla2x00_module_exit - Module cleanup.
2612 **/
2613static void __exit
2614qla2x00_module_exit(void)
2615{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002616 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002617 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 fc_release_transport(qla2xxx_transport_template);
2619}
2620
2621module_init(qla2x00_module_init);
2622module_exit(qla2x00_module_exit);
2623
2624MODULE_AUTHOR("QLogic Corporation");
2625MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2626MODULE_LICENSE("GPL");
2627MODULE_VERSION(QLA2XXX_VERSION);