blob: 14f2f9077c81c4e27707490001f5c5e9d124bbf5 [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,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700143 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
Andrew Vasquezfca29702005-07-06 10:31:47 -0700146static struct scsi_host_template qla24xx_driver_template = {
147 .module = THIS_MODULE,
148 .name = "qla2xxx",
149 .queuecommand = qla24xx_queuecommand,
150
151 .eh_abort_handler = qla2xxx_eh_abort,
152 .eh_device_reset_handler = qla2xxx_eh_device_reset,
153 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
154 .eh_host_reset_handler = qla2xxx_eh_host_reset,
155
156 .slave_configure = qla2xxx_slave_configure,
157
158 .slave_alloc = qla2xxx_slave_alloc,
159 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700160 .change_queue_depth = qla2x00_change_queue_depth,
161 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700162 .this_id = -1,
163 .cmd_per_lun = 3,
164 .use_clustering = ENABLE_CLUSTERING,
165 .sg_tablesize = SG_ALL,
166
167 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700168 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700169};
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171static struct scsi_transport_template *qla2xxx_transport_template = NULL;
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* TODO Convert to inlines
174 *
175 * Timer routines
176 */
177#define WATCH_INTERVAL 1 /* number of seconds */
178
179static void qla2x00_timer(scsi_qla_host_t *);
180
181static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
182 void *, unsigned long);
183static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
184static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
185
186static inline void
187qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
188{
189 init_timer(&ha->timer);
190 ha->timer.expires = jiffies + interval * HZ;
191 ha->timer.data = (unsigned long)ha;
192 ha->timer.function = (void (*)(unsigned long))func;
193 add_timer(&ha->timer);
194 ha->timer_active = 1;
195}
196
197static inline void
198qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
199{
200 mod_timer(&ha->timer, jiffies + interval * HZ);
201}
202
203static __inline__ void
204qla2x00_stop_timer(scsi_qla_host_t *ha)
205{
206 del_timer_sync(&ha->timer);
207 ha->timer_active = 0;
208}
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static int qla2x00_do_dpc(void *data);
211
212static void qla2x00_rst_aen(scsi_qla_host_t *);
213
214static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
215static void qla2x00_mem_free(scsi_qla_host_t *ha);
216static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
217static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500218static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
219void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/* -------------------------------------------------------------------------- */
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700224qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
226 static char *pci_bus_modes[] = {
227 "33", "66", "100", "133",
228 };
229 uint16_t pci_bus;
230
231 strcpy(str, "PCI");
232 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
233 if (pci_bus) {
234 strcat(str, "-X (");
235 strcat(str, pci_bus_modes[pci_bus]);
236 } else {
237 pci_bus = (ha->pci_attr & BIT_8) >> 8;
238 strcat(str, " (");
239 strcat(str, pci_bus_modes[pci_bus]);
240 }
241 strcat(str, " MHz)");
242
243 return (str);
244}
245
Andrew Vasquezfca29702005-07-06 10:31:47 -0700246static char *
247qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
248{
249 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
250 uint32_t pci_bus;
251 int pcie_reg;
252
253 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
254 if (pcie_reg) {
255 char lwstr[6];
256 uint16_t pcie_lstat, lspeed, lwidth;
257
258 pcie_reg += 0x12;
259 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
260 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
261 lwidth = (pcie_lstat &
262 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
263
264 strcpy(str, "PCIe (");
265 if (lspeed == 1)
266 strcat(str, "2.5Gb/s ");
267 else
268 strcat(str, "<unknown> ");
269 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
270 strcat(str, lwstr);
271
272 return str;
273 }
274
275 strcpy(str, "PCI");
276 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
277 if (pci_bus == 0 || pci_bus == 8) {
278 strcat(str, " (");
279 strcat(str, pci_bus_modes[pci_bus >> 3]);
280 } else {
281 strcat(str, "-X ");
282 if (pci_bus & BIT_2)
283 strcat(str, "Mode 2");
284 else
285 strcat(str, "Mode 1");
286 strcat(str, " (");
287 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
288 }
289 strcat(str, " MHz)");
290
291 return str;
292}
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700295qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
297 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
300 ha->fw_minor_version,
301 ha->fw_subminor_version);
302
303 if (ha->fw_attributes & BIT_9) {
304 strcat(str, "FLX");
305 return (str);
306 }
307
308 switch (ha->fw_attributes & 0xFF) {
309 case 0x7:
310 strcat(str, "EF");
311 break;
312 case 0x17:
313 strcat(str, "TP");
314 break;
315 case 0x37:
316 strcat(str, "IP");
317 break;
318 case 0x77:
319 strcat(str, "VI");
320 break;
321 default:
322 sprintf(un_str, "(%x)", ha->fw_attributes);
323 strcat(str, un_str);
324 break;
325 }
326 if (ha->fw_attributes & 0x100)
327 strcat(str, "X");
328
329 return (str);
330}
331
Andrew Vasquezfca29702005-07-06 10:31:47 -0700332char *
333qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
334{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700335 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
336 ha->fw_minor_version,
337 ha->fw_subminor_version);
338
Andrew Vasquezfca29702005-07-06 10:31:47 -0700339 if (ha->fw_attributes & BIT_0)
340 strcat(str, "[Class 2] ");
341 if (ha->fw_attributes & BIT_1)
342 strcat(str, "[IP] ");
343 if (ha->fw_attributes & BIT_2)
344 strcat(str, "[Multi-ID] ");
345 if (ha->fw_attributes & BIT_13)
346 strcat(str, "[Experimental]");
347 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700348}
349
350static inline srb_t *
351qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
352 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
353{
354 srb_t *sp;
355
356 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
357 if (!sp)
358 return sp;
359
360 atomic_set(&sp->ref_count, 1);
361 sp->ha = ha;
362 sp->fcport = fcport;
363 sp->cmd = cmd;
364 sp->flags = 0;
365 CMD_SP(cmd) = (void *)sp;
366 cmd->scsi_done = done;
367
368 return sp;
369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371static int
f4f051e2005-04-17 15:02:26 -0500372qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
f4f051e2005-04-17 15:02:26 -0500374 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500375 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500376 srb_t *sp;
377 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
bdf79622005-04-17 15:06:53 -0500379 if (!fcport) {
f4f051e2005-04-17 15:02:26 -0500380 cmd->result = DID_NO_CONNECT << 16;
381 goto qc_fail_command;
382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
f4f051e2005-04-17 15:02:26 -0500384 if (atomic_read(&fcport->state) != FCS_ONLINE) {
385 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
386 atomic_read(&ha->loop_state) == LOOP_DEAD) {
387 cmd->result = DID_NO_CONNECT << 16;
388 goto qc_fail_command;
389 }
390 goto qc_host_busy;
391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 spin_unlock_irq(ha->host->host_lock);
394
Andrew Vasquezfca29702005-07-06 10:31:47 -0700395 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
396 if (!sp)
f4f051e2005-04-17 15:02:26 -0500397 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
f4f051e2005-04-17 15:02:26 -0500399 rval = qla2x00_start_scsi(sp);
400 if (rval != QLA_SUCCESS)
401 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
f4f051e2005-04-17 15:02:26 -0500403 /* Manage unprocessed RIO/ZIO commands in response queue. */
404 if (ha->flags.online && ha->flags.process_response_queue &&
405 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
406 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
f4f051e2005-04-17 15:02:26 -0500408 spin_lock_irqsave(&ha->hardware_lock, flags);
409 qla2x00_process_response_queue(ha);
410 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 spin_lock_irq(ha->host->host_lock);
414
f4f051e2005-04-17 15:02:26 -0500415 return 0;
416
417qc_host_busy_free_sp:
418 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500419 mempool_free(sp, ha->srb_mempool);
420
421qc_host_busy_lock:
422 spin_lock_irq(ha->host->host_lock);
423
424qc_host_busy:
425 return SCSI_MLQUEUE_HOST_BUSY;
426
427qc_fail_command:
428 done(cmd);
429
430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Andrew Vasquezfca29702005-07-06 10:31:47 -0700433
434static int
435qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
436{
437 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
438 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
439 srb_t *sp;
440 int rval;
441
442 if (!fcport) {
443 cmd->result = DID_NO_CONNECT << 16;
444 goto qc24_fail_command;
445 }
446
447 if (atomic_read(&fcport->state) != FCS_ONLINE) {
448 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
449 atomic_read(&ha->loop_state) == LOOP_DEAD) {
450 cmd->result = DID_NO_CONNECT << 16;
451 goto qc24_fail_command;
452 }
453 goto qc24_host_busy;
454 }
455
456 spin_unlock_irq(ha->host->host_lock);
457
458 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
459 if (!sp)
460 goto qc24_host_busy_lock;
461
462 rval = qla24xx_start_scsi(sp);
463 if (rval != QLA_SUCCESS)
464 goto qc24_host_busy_free_sp;
465
466 spin_lock_irq(ha->host->host_lock);
467
468 return 0;
469
470qc24_host_busy_free_sp:
471 qla2x00_sp_free_dma(ha, sp);
472 mempool_free(sp, ha->srb_mempool);
473
474qc24_host_busy_lock:
475 spin_lock_irq(ha->host->host_lock);
476
477qc24_host_busy:
478 return SCSI_MLQUEUE_HOST_BUSY;
479
480qc24_fail_command:
481 done(cmd);
482
483 return 0;
484}
485
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487/*
488 * qla2x00_eh_wait_on_command
489 * Waits for the command to be returned by the Firmware for some
490 * max time.
491 *
492 * Input:
493 * ha = actual ha whose done queue will contain the command
494 * returned by firmware.
495 * cmd = Scsi Command to wait on.
496 * flag = Abort/Reset(Bus or Device Reset)
497 *
498 * Return:
499 * Not Found : 0
500 * Found : 1
501 */
502static int
503qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
504{
505#define ABORT_POLLING_PERIOD HZ
f4f051e2005-04-17 15:02:26 -0500506#define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
507 unsigned long wait_iter = ABORT_WAIT_ITER;
508 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
f4f051e2005-04-17 15:02:26 -0500510 while (CMD_SP(cmd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 set_current_state(TASK_UNINTERRUPTIBLE);
512 schedule_timeout(ABORT_POLLING_PERIOD);
513
f4f051e2005-04-17 15:02:26 -0500514 if (--wait_iter)
515 break;
516 }
517 if (CMD_SP(cmd))
518 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
f4f051e2005-04-17 15:02:26 -0500520 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
523/*
524 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700525 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 * <= MAX_RETRIES_OF_ISP_ABORT or
527 * finally HBA is disabled ie marked offline
528 *
529 * Input:
530 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700531 *
532 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * Does context switching-Release SPIN_LOCK
534 * (if any) before calling this routine.
535 *
536 * Return:
537 * Success (Adapter is online) : 0
538 * Failed (Adapter is offline/disabled) : 1
539 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700540static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
542{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700543 int return_status;
544 unsigned long wait_online;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700546 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
548 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
549 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
550 ha->dpc_active) && time_before(jiffies, wait_online)) {
551
552 msleep(1000);
553 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700554 if (ha->flags.online)
555 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 else
557 return_status = QLA_FUNCTION_FAILED;
558
559 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
560
561 return (return_status);
562}
563
564/*
565 * qla2x00_wait_for_loop_ready
566 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700567 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 * Input:
569 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700570 *
571 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 * Does context switching-Release SPIN_LOCK
573 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700574 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 *
576 * Return:
577 * Success (LOOP_READY) : 0
578 * Failed (LOOP_NOT_READY) : 1
579 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700580static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
582{
583 int return_status = QLA_SUCCESS;
584 unsigned long loop_timeout ;
585
586 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700587 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 while ((!atomic_read(&ha->loop_down_timer) &&
590 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 atomic_read(&ha->loop_state) != LOOP_READY) {
592 msleep(1000);
593 if (time_after_eq(jiffies, loop_timeout)) {
594 return_status = QLA_FUNCTION_FAILED;
595 break;
596 }
597 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700598 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601/**************************************************************************
602* qla2xxx_eh_abort
603*
604* Description:
605* The abort function will abort the specified command.
606*
607* Input:
608* cmd = Linux SCSI command packet to be aborted.
609*
610* Returns:
611* Either SUCCESS or FAILED.
612*
613* Note:
614**************************************************************************/
615int
616qla2xxx_eh_abort(struct scsi_cmnd *cmd)
617{
f4f051e2005-04-17 15:02:26 -0500618 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
619 srb_t *sp;
620 int ret, i;
621 unsigned int id, lun;
622 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700623 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
f4f051e2005-04-17 15:02:26 -0500625 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
f4f051e2005-04-17 15:02:26 -0500628 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
f4f051e2005-04-17 15:02:26 -0500630 id = cmd->device->id;
631 lun = cmd->device->lun;
632 serial = cmd->serial_number;
633
634 /* Check active list for command command. */
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700635 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500636 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
637 sp = ha->outstanding_cmds[i];
638
639 if (sp == NULL)
640 continue;
641
642 if (sp->cmd != cmd)
643 continue;
644
645 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
646 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
647 sp->state));
648 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
649
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700650 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700651 if (ha->isp_ops.abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500652 DEBUG2(printk("%s(%ld): abort_command "
653 "mbx failed.\n", __func__, ha->host_no));
654 } else {
655 DEBUG3(printk("%s(%ld): abort_command "
656 "mbx success.\n", __func__, ha->host_no));
657 ret = SUCCESS;
658 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700659 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500660
661 break;
662 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700663 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500664
665 /* Wait for the command to be returned. */
666 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500667 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700668 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500669 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
670 "%x.\n", ha->host_no, id, lun, serial, ret);
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700674 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500675 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
676 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
f4f051e2005-04-17 15:02:26 -0500678 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
681/**************************************************************************
682* qla2x00_eh_wait_for_pending_target_commands
683*
684* Description:
685* Waits for all the commands to come back from the specified target.
686*
687* Input:
688* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700689* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690* Returns:
691* Either SUCCESS or FAILED.
692*
693* Note:
694**************************************************************************/
695static int
696qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
697{
698 int cnt;
699 int status;
700 srb_t *sp;
701 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700702 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 status = 0;
705
706 /*
707 * Waiting for all commands for the designated target in the active
708 * array
709 */
710 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700711 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 sp = ha->outstanding_cmds[cnt];
713 if (sp) {
714 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (cmd->device->id == t) {
717 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
718 status = 1;
719 break;
720 }
721 }
f4f051e2005-04-17 15:02:26 -0500722 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 }
725 }
726 return (status);
727}
728
729
730/**************************************************************************
731* qla2xxx_eh_device_reset
732*
733* Description:
734* The device reset function will reset the target and abort any
735* executing commands.
736*
737* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700738* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739* non-null.
740*
741* Input:
742* cmd = Linux SCSI command packet of the command that cause the
743* bus device reset.
744*
745* Returns:
746* SUCCESS/FAILURE (defined as macro in scsi.h).
747*
748**************************************************************************/
749int
750qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
751{
f4f051e2005-04-17 15:02:26 -0500752 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500753 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500754 srb_t *sp;
755 int ret;
756 unsigned int id, lun;
757 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
f4f051e2005-04-17 15:02:26 -0500759 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
f4f051e2005-04-17 15:02:26 -0500761 id = cmd->device->id;
762 lun = cmd->device->lun;
763 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
f4f051e2005-04-17 15:02:26 -0500765 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500766 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500767 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500770 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400772 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500776 if (qla2x00_device_reset(ha, fcport) == 0)
777 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500780 if (ret == SUCCESS) {
781 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700782 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
f4f051e2005-04-17 15:02:26 -0500783 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
785 }
786#endif
787 } else {
788 DEBUG2(printk(KERN_INFO
789 "%s failed: loop not ready\n",__func__);)
790 }
791
f4f051e2005-04-17 15:02:26 -0500792 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 DEBUG3(printk("%s(%ld): device reset failed\n",
794 __func__, ha->host_no));
795 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
796 __func__);
797
798 goto eh_dev_reset_done;
799 }
800
801 /*
802 * If we are coming down the EH path, wait for all commands to
803 * complete for the device.
804 */
805 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500806 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
807 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
f4f051e2005-04-17 15:02:26 -0500809 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 DEBUG3(printk("%s(%ld): failed while waiting for "
811 "commands\n", __func__, ha->host_no));
812 qla_printk(KERN_INFO, ha,
813 "%s: failed while waiting for commands\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700814 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 goto eh_dev_reset_done;
817 }
818 }
819
820 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500821 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500824 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
827/**************************************************************************
828* qla2x00_eh_wait_for_pending_commands
829*
830* Description:
831* Waits for all the commands to come back from the specified host.
832*
833* Input:
834* ha - pointer to scsi_qla_host structure.
835*
836* Returns:
837* 1 : SUCCESS
838* 0 : FAILED
839*
840* Note:
841**************************************************************************/
842static int
843qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
844{
845 int cnt;
846 int status;
847 srb_t *sp;
848 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700849 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 status = 1;
852
853 /*
854 * Waiting for all commands for the designated target in the active
855 * array
856 */
857 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700858 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 sp = ha->outstanding_cmds[cnt];
860 if (sp) {
861 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700862 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 status = qla2x00_eh_wait_on_command(ha, cmd);
864 if (status == 0)
865 break;
866 }
867 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700868 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870 }
871 return (status);
872}
873
874
875/**************************************************************************
876* qla2xxx_eh_bus_reset
877*
878* Description:
879* The bus reset function will reset the bus and abort any executing
880* commands.
881*
882* Input:
883* cmd = Linux SCSI command packet of the command that cause the
884* bus reset.
885*
886* Returns:
887* SUCCESS/FAILURE (defined as macro in scsi.h).
888*
889**************************************************************************/
890int
891qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
892{
f4f051e2005-04-17 15:02:26 -0500893 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500894 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500896 int ret;
897 unsigned int id, lun;
898 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
f4f051e2005-04-17 15:02:26 -0500900 ret = FAILED;
901
902 id = cmd->device->id;
903 lun = cmd->device->lun;
904 serial = cmd->serial_number;
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500907 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500908 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500911 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
914 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500915 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
917
918 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500919 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
920 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
f4f051e2005-04-17 15:02:26 -0500922 if (ret == FAILED)
923 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 /* Waiting for our command in done_queue to be returned to OS.*/
926 if (cmd->device->host->eh_active)
927 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500928 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
f4f051e2005-04-17 15:02:26 -0500930eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500932 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
f4f051e2005-04-17 15:02:26 -0500934 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
937/**************************************************************************
938* qla2xxx_eh_host_reset
939*
940* Description:
941* The reset function will reset the Adapter.
942*
943* Input:
944* cmd = Linux SCSI command packet of the command that cause the
945* adapter reset.
946*
947* Returns:
948* Either SUCCESS or FAILED.
949*
950* Note:
951**************************************************************************/
952int
953qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
954{
f4f051e2005-04-17 15:02:26 -0500955 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500956 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500957 srb_t *sp;
958 int ret;
959 unsigned int id, lun;
960 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
f4f051e2005-04-17 15:02:26 -0500962 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
f4f051e2005-04-17 15:02:26 -0500964 id = cmd->device->id;
965 lun = cmd->device->lun;
966 serial = cmd->serial_number;
967
968 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500969 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500970 return ret;
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500973 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500976 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 /*
979 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700980 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 * be completed and then issue big hammer.Otherwise
982 * it may cause I/O failure as big hammer marks the
983 * devices as lost kicking of the port_down_timer
984 * while dpc is stuck for the mailbox to complete.
985 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 qla2x00_wait_for_loop_ready(ha);
987 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
988 if (qla2x00_abort_isp(ha)) {
989 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
990 /* failed. schedule dpc to try */
991 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
992
993 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500994 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700995 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500999 if (qla2x00_eh_wait_for_pending_commands(ha))
1000 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
f4f051e2005-04-17 15:02:26 -05001002eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001003 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1004 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
f4f051e2005-04-17 15:02:26 -05001006 return ret;
1007}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009/*
1010* qla2x00_loop_reset
1011* Issue loop reset.
1012*
1013* Input:
1014* ha = adapter block pointer.
1015*
1016* Returns:
1017* 0 = success
1018*/
1019static int
1020qla2x00_loop_reset(scsi_qla_host_t *ha)
1021{
1022 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -05001023 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 if (ha->flags.enable_lip_reset) {
1026 status = qla2x00_lip_reset(ha);
1027 }
1028
1029 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001030 list_for_each_entry(fcport, &ha->fcports, list) {
1031 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 continue;
1033
Andrew Vasquezc00c72a2005-08-26 19:08:50 -07001034 status = qla2x00_device_reset(ha, fcport);
bdf79622005-04-17 15:06:53 -05001035 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038 }
1039
1040 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001041 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 !ha->flags.enable_lip_reset) ||
1043 ha->flags.enable_lip_full_login)) {
1044
1045 status = qla2x00_full_login_lip(ha);
1046 }
1047
1048 /* Issue marker command only when we are going to start the I/O */
1049 ha->marker_needed = 1;
1050
1051 if (status) {
1052 /* Empty */
1053 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1054 __func__,
1055 ha->host_no);)
1056 } else {
1057 /* Empty */
1058 DEBUG3(printk("%s(%ld): exiting normally.\n",
1059 __func__,
1060 ha->host_no);)
1061 }
1062
1063 return(status);
1064}
1065
1066/*
1067 * qla2x00_device_reset
1068 * Issue bus device reset message to the target.
1069 *
1070 * Input:
1071 * ha = adapter block pointer.
1072 * t = SCSI ID.
1073 * TARGET_QUEUE_LOCK must be released.
1074 * ADAPTER_STATE_LOCK must be released.
1075 *
1076 * Context:
1077 * Kernel context.
1078 */
1079static int
1080qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1081{
1082 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001083 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
f4f051e2005-04-17 15:02:26 -05001086static int
1087qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
bdf79622005-04-17 15:06:53 -05001089 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
bdf79622005-04-17 15:06:53 -05001091 if (!rport)
f4f051e2005-04-17 15:02:26 -05001092 return -ENXIO;
1093
Andrew Vasquez77d74142005-07-08 18:00:36 -07001094 sdev->hostdata = rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001095
1096 return 0;
1097}
1098
1099static int
1100qla2xxx_slave_configure(struct scsi_device *sdev)
1101{
8482e1182005-04-17 15:04:54 -05001102 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1103 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1104
f4f051e2005-04-17 15:02:26 -05001105 if (sdev->tagged_supported)
1106 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 else
f4f051e2005-04-17 15:02:26 -05001108 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
8482e1182005-04-17 15:04:54 -05001110 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1111
f4f051e2005-04-17 15:02:26 -05001112 return 0;
1113}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
f4f051e2005-04-17 15:02:26 -05001115static void
1116qla2xxx_slave_destroy(struct scsi_device *sdev)
1117{
1118 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
1120
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001121static int
1122qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1123{
1124 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1125 return sdev->queue_depth;
1126}
1127
1128static int
1129qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1130{
1131 if (sdev->tagged_supported) {
1132 scsi_set_tag_type(sdev, tag_type);
1133 if (tag_type)
1134 scsi_activate_tcq(sdev, sdev->queue_depth);
1135 else
1136 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1137 } else
1138 tag_type = 0;
1139
1140 return tag_type;
1141}
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143/**
1144 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1145 * @ha: HA context
1146 *
1147 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1148 * supported addressing method.
1149 */
1150static void
1151qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1152{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001153 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001156 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1157 /* Any upper-dword bits set? */
1158 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1159 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1160 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001162 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1163 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001164 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001167
1168 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1169 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
1172static int
1173qla2x00_iospace_config(scsi_qla_host_t *ha)
1174{
1175 unsigned long pio, pio_len, pio_flags;
1176 unsigned long mmio, mmio_len, mmio_flags;
1177
1178 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1179 pio = pci_resource_start(ha->pdev, 0);
1180 pio_len = pci_resource_len(ha->pdev, 0);
1181 pio_flags = pci_resource_flags(ha->pdev, 0);
1182 if (pio_flags & IORESOURCE_IO) {
1183 if (pio_len < MIN_IOBASE_LEN) {
1184 qla_printk(KERN_WARNING, ha,
1185 "Invalid PCI I/O region size (%s)...\n",
1186 pci_name(ha->pdev));
1187 pio = 0;
1188 }
1189 } else {
1190 qla_printk(KERN_WARNING, ha,
1191 "region #0 not a PIO resource (%s)...\n",
1192 pci_name(ha->pdev));
1193 pio = 0;
1194 }
1195
1196 /* Use MMIO operations for all accesses. */
1197 mmio = pci_resource_start(ha->pdev, 1);
1198 mmio_len = pci_resource_len(ha->pdev, 1);
1199 mmio_flags = pci_resource_flags(ha->pdev, 1);
1200
1201 if (!(mmio_flags & IORESOURCE_MEM)) {
1202 qla_printk(KERN_ERR, ha,
1203 "region #0 not an MMIO resource (%s), aborting\n",
1204 pci_name(ha->pdev));
1205 goto iospace_error_exit;
1206 }
1207 if (mmio_len < MIN_IOBASE_LEN) {
1208 qla_printk(KERN_ERR, ha,
1209 "Invalid PCI mem region size (%s), aborting\n",
1210 pci_name(ha->pdev));
1211 goto iospace_error_exit;
1212 }
1213
1214 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1215 qla_printk(KERN_WARNING, ha,
1216 "Failed to reserve PIO/MMIO regions (%s)\n",
1217 pci_name(ha->pdev));
1218
1219 goto iospace_error_exit;
1220 }
1221
1222 ha->pio_address = pio;
1223 ha->pio_length = pio_len;
1224 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1225 if (!ha->iobase) {
1226 qla_printk(KERN_ERR, ha,
1227 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1228
1229 goto iospace_error_exit;
1230 }
1231
1232 return (0);
1233
1234iospace_error_exit:
1235 return (-ENOMEM);
1236}
1237
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001238static void
1239qla2x00_enable_intrs(scsi_qla_host_t *ha)
1240{
1241 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001243
1244 spin_lock_irqsave(&ha->hardware_lock, flags);
1245 ha->interrupts_on = 1;
1246 /* enable risc and host interrupts */
1247 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1248 RD_REG_WORD(&reg->ictrl);
1249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1250
1251}
1252
1253static void
1254qla2x00_disable_intrs(scsi_qla_host_t *ha)
1255{
1256 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001257 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001258
1259 spin_lock_irqsave(&ha->hardware_lock, flags);
1260 ha->interrupts_on = 0;
1261 /* disable risc and host interrupts */
1262 WRT_REG_WORD(&reg->ictrl, 0);
1263 RD_REG_WORD(&reg->ictrl);
1264 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1265}
1266
Andrew Vasquezfca29702005-07-06 10:31:47 -07001267static void
1268qla24xx_enable_intrs(scsi_qla_host_t *ha)
1269{
1270 unsigned long flags = 0;
1271 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1272
1273 spin_lock_irqsave(&ha->hardware_lock, flags);
1274 ha->interrupts_on = 1;
1275 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1276 RD_REG_DWORD(&reg->ictrl);
1277 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1278}
1279
1280static void
1281qla24xx_disable_intrs(scsi_qla_host_t *ha)
1282{
1283 unsigned long flags = 0;
1284 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1285
1286 spin_lock_irqsave(&ha->hardware_lock, flags);
1287 ha->interrupts_on = 0;
1288 WRT_REG_DWORD(&reg->ictrl, 0);
1289 RD_REG_DWORD(&reg->ictrl);
1290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1291}
1292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293/*
1294 * PCI driver interface
1295 */
1296int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1297{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001298 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001299 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 struct Scsi_Host *host;
1301 scsi_qla_host_t *ha;
1302 unsigned long flags = 0;
1303 unsigned long wait_switch = 0;
1304 char pci_info[20];
1305 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001306 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001309 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Andrew Vasquezfca29702005-07-06 10:31:47 -07001311 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1312 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 if (host == NULL) {
1314 printk(KERN_WARNING
1315 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1316 goto probe_disable_device;
1317 }
1318
1319 /* Clear our data area */
1320 ha = (scsi_qla_host_t *)host->hostdata;
1321 memset(ha, 0, sizeof(scsi_qla_host_t));
1322
1323 ha->pdev = pdev;
1324 ha->host = host;
1325 ha->host_no = host->host_no;
1326 ha->brd_info = brd_info;
1327 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1328
1329 /* Configure PCI I/O space */
1330 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001331 if (ret)
1332 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 qla_printk(KERN_INFO, ha,
1335 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001336 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 spin_lock_init(&ha->hardware_lock);
1339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 ha->prev_topology = 0;
1341 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001342 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001343 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001345 /* Assign ISP specific operations. */
1346 ha->isp_ops.pci_config = qla2100_pci_config;
1347 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1348 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1349 ha->isp_ops.config_rings = qla2x00_config_rings;
1350 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1351 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1352 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001353 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001354 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1355 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1356 ha->isp_ops.intr_handler = qla2100_intr_handler;
1357 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1358 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1359 ha->isp_ops.abort_command = qla2x00_abort_command;
1360 ha->isp_ops.abort_target = qla2x00_abort_target;
1361 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1362 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1363 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1364 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1365 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001366 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001367 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1368 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001369 ha->isp_ops.fw_dump = qla2100_fw_dump;
1370 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001372 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1374 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1375 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1376 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1377 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001378 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001380 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1382 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1383 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1384 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001385 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001386 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001387 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1389 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1390 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1391 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001392 ha->isp_ops.pci_config = qla2300_pci_config;
1393 ha->isp_ops.intr_handler = qla2300_intr_handler;
1394 ha->isp_ops.fw_dump = qla2300_fw_dump;
1395 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1396 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001397 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1398 host->max_id = MAX_TARGETS_2200;
1399 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1400 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1401 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1402 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1403 ha->init_cb_size = sizeof(struct init_cb_24xx);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001404 ha->mgmt_svr_loop_id = 10;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001405 ha->isp_ops.pci_config = qla24xx_pci_config;
1406 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1407 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1408 ha->isp_ops.config_rings = qla24xx_config_rings;
1409 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1410 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1411 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1412 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1413 if (ql2xfwloadbin)
1414 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1415 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1416 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1417 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1418 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1419 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1420 ha->isp_ops.abort_command = qla24xx_abort_command;
1421 ha->isp_ops.abort_target = qla24xx_abort_target;
1422 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1423 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1424 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001425 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001426 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1427 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1428 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1429 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1430 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432 host->can_queue = ha->request_q_length + 128;
1433
1434 /* load the F/W, read paramaters, and init the H/W */
1435 ha->instance = num_hosts;
1436
1437 init_MUTEX(&ha->mbx_cmd_sem);
1438 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1439
1440 INIT_LIST_HEAD(&ha->list);
1441 INIT_LIST_HEAD(&ha->fcports);
1442 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
1444 /*
1445 * These locks are used to prevent more than one CPU
1446 * from modifying the queue at the same time. The
1447 * higher level "host_lock" will reduce most
1448 * contention for these locks.
1449 */
1450 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
1452 ha->dpc_pid = -1;
1453 init_completion(&ha->dpc_inited);
1454 init_completion(&ha->dpc_exited);
1455
1456 qla2x00_config_dma_addressing(ha);
1457 if (qla2x00_mem_alloc(ha)) {
1458 qla_printk(KERN_WARNING, ha,
1459 "[ERROR] Failed to allocate memory for adapter\n");
1460
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001461 ret = -ENOMEM;
1462 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
1464
1465 if (qla2x00_initialize_adapter(ha) &&
1466 !(ha->device_flags & DFLG_NO_CABLE)) {
1467
1468 qla_printk(KERN_WARNING, ha,
1469 "Failed to initialize adapter\n");
1470
1471 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1472 "Adapter flags %x.\n",
1473 ha->host_no, ha->device_flags));
1474
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001475 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 goto probe_failed;
1477 }
1478
1479 /*
1480 * Startup the kernel thread for this host adapter
1481 */
1482 ha->dpc_should_die = 0;
1483 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1484 if (ha->dpc_pid < 0) {
1485 qla_printk(KERN_WARNING, ha,
1486 "Unable to start DPC thread!\n");
1487
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001488 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 goto probe_failed;
1490 }
1491 wait_for_completion(&ha->dpc_inited);
1492
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001493 host->this_id = 255;
1494 host->cmd_per_lun = 3;
1495 host->unique_id = ha->instance;
1496 host->max_cmd_len = MAX_CMDSZ;
1497 host->max_channel = ha->ports - 1;
1498 host->max_lun = MAX_LUNS;
1499 host->transportt = qla2xxx_transport_template;
1500
Andrew Vasquezfca29702005-07-06 10:31:47 -07001501 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001502 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001503 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 qla_printk(KERN_WARNING, ha,
1505 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001506 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 goto probe_failed;
1508 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001509 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511 /* Initialized the timer */
1512 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1513
1514 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1515 ha->host_no, ha));
1516
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001517 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001520 reg = ha->iobase;
1521 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1522 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1523 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1524 } else {
1525 WRT_REG_WORD(&reg->isp.semaphore, 0);
1526 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1527 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Andrew Vasquezfca29702005-07-06 10:31:47 -07001529 /* Enable proper parity */
1530 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1531 if (IS_QLA2300(ha))
1532 /* SRAM parity */
1533 WRT_REG_WORD(&reg->isp.hccr,
1534 (HCCR_ENABLE_PARITY + 0x1));
1535 else
1536 /* SRAM, Instruction RAM and GP RAM parity */
1537 WRT_REG_WORD(&reg->isp.hccr,
1538 (HCCR_ENABLE_PARITY + 0x7));
1539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
1541 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1542
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001543 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
1545 /* v2.19.5b6 */
1546 /*
1547 * Wait around max loop_reset_delay secs for the devices to come
1548 * on-line. We don't want Linux scanning before we are ready.
1549 *
1550 */
1551 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1552 time_before(jiffies,wait_switch) &&
1553 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1554 && (ha->device_flags & SWITCH_FOUND) ;) {
1555
1556 qla2x00_check_fabric_devices(ha);
1557
1558 msleep(10);
1559 }
1560
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001561 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 ha->flags.init_done = 1;
1563 num_hosts++;
1564
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001565 ret = scsi_add_host(host, &pdev->dev);
1566 if (ret)
1567 goto probe_failed;
1568
1569 qla2x00_alloc_sysfs_attr(ha);
1570
1571 qla2x00_init_host_attr(ha);
1572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 qla_printk(KERN_INFO, ha, "\n"
1574 " QLogic Fibre Channel HBA Driver: %s\n"
1575 " QLogic %s - %s\n"
1576 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1577 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001578 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001579 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001580 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
8482e1182005-04-17 15:04:54 -05001582 /* Go with fc_rport registration. */
1583 list_for_each_entry(fcport, &ha->fcports, list)
1584 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
1586 return 0;
1587
1588probe_failed:
bdf79622005-04-17 15:06:53 -05001589 fc_remove_host(ha->host);
1590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 qla2x00_free_device(ha);
1592
1593 scsi_host_put(host);
1594
1595probe_disable_device:
1596 pci_disable_device(pdev);
1597
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001598probe_out:
1599 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1602
1603void qla2x00_remove_one(struct pci_dev *pdev)
1604{
1605 scsi_qla_host_t *ha;
1606
1607 ha = pci_get_drvdata(pdev);
1608
8482e1182005-04-17 15:04:54 -05001609 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
bdf79622005-04-17 15:06:53 -05001611 fc_remove_host(ha->host);
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 scsi_remove_host(ha->host);
1614
1615 qla2x00_free_device(ha);
1616
1617 scsi_host_put(ha->host);
1618
1619 pci_set_drvdata(pdev, NULL);
1620}
1621EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1622
1623static void
1624qla2x00_free_device(scsi_qla_host_t *ha)
1625{
1626 int ret;
1627
1628 /* Abort any outstanding IO descriptors. */
1629 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1630 qla2x00_cancel_io_descriptors(ha);
1631
1632 /* turn-off interrupts on the card */
1633 if (ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001634 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
1636 /* Disable timer */
1637 if (ha->timer_active)
1638 qla2x00_stop_timer(ha);
1639
1640 /* Kill the kernel thread for this host */
1641 if (ha->dpc_pid >= 0) {
1642 ha->dpc_should_die = 1;
1643 wmb();
1644 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1645 if (ret) {
1646 qla_printk(KERN_ERR, ha,
1647 "Unable to signal DPC thread -- (%d)\n", ret);
1648
1649 /* TODO: SOMETHING MORE??? */
1650 } else {
1651 wait_for_completion(&ha->dpc_exited);
1652 }
1653 }
1654
1655 qla2x00_mem_free(ha);
1656
1657
1658 ha->flags.online = 0;
1659
1660 /* Detach interrupts */
1661 if (ha->pdev->irq)
1662 free_irq(ha->pdev->irq, ha);
1663
1664 /* release io space registers */
1665 if (ha->iobase)
1666 iounmap(ha->iobase);
1667 pci_release_regions(ha->pdev);
1668
1669 pci_disable_device(ha->pdev);
1670}
1671
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1674 *
1675 * Input: ha = adapter block pointer. fcport = port structure pointer.
1676 *
1677 * Return: None.
1678 *
1679 * Context:
1680 */
1681void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1682 int do_login)
1683{
8482e1182005-04-17 15:04:54 -05001684 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1685 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001686 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 * We may need to retry the login, so don't change the state of the
1688 * port but do the retries.
1689 */
1690 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1691 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1692
1693 if (!do_login)
1694 return;
1695
1696 if (fcport->login_retry == 0) {
1697 fcport->login_retry = ha->login_retry_count;
1698 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1699
1700 DEBUG(printk("scsi(%ld): Port login retry: "
1701 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1702 "id = 0x%04x retry cnt=%d\n",
1703 ha->host_no,
1704 fcport->port_name[0],
1705 fcport->port_name[1],
1706 fcport->port_name[2],
1707 fcport->port_name[3],
1708 fcport->port_name[4],
1709 fcport->port_name[5],
1710 fcport->port_name[6],
1711 fcport->port_name[7],
1712 fcport->loop_id,
1713 fcport->login_retry));
1714 }
1715}
1716
1717/*
1718 * qla2x00_mark_all_devices_lost
1719 * Updates fcport state when device goes offline.
1720 *
1721 * Input:
1722 * ha = adapter block pointer.
1723 * fcport = port structure pointer.
1724 *
1725 * Return:
1726 * None.
1727 *
1728 * Context:
1729 */
1730void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001731qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
1733 fc_port_t *fcport;
1734
1735 list_for_each_entry(fcport, &ha->fcports, list) {
1736 if (fcport->port_type != FCT_TARGET)
1737 continue;
1738
1739 /*
1740 * No point in marking the device as lost, if the device is
1741 * already DEAD.
1742 */
1743 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1744 continue;
8482e1182005-04-17 15:04:54 -05001745 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1746 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1748 }
1749}
1750
1751/*
1752* qla2x00_mem_alloc
1753* Allocates adapter memory.
1754*
1755* Returns:
1756* 0 = success.
1757* 1 = failure.
1758*/
1759static uint8_t
1760qla2x00_mem_alloc(scsi_qla_host_t *ha)
1761{
1762 char name[16];
1763 uint8_t status = 1;
1764 int retry= 10;
1765
1766 do {
1767 /*
1768 * This will loop only once if everything goes well, else some
1769 * number of retries will be performed to get around a kernel
1770 * bug where available mem is not allocated until after a
1771 * little delay and a retry.
1772 */
1773 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1774 (ha->request_q_length + 1) * sizeof(request_t),
1775 &ha->request_dma, GFP_KERNEL);
1776 if (ha->request_ring == NULL) {
1777 qla_printk(KERN_WARNING, ha,
1778 "Memory Allocation failed - request_ring\n");
1779
1780 qla2x00_mem_free(ha);
1781 msleep(100);
1782
1783 continue;
1784 }
1785
1786 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1787 (ha->response_q_length + 1) * sizeof(response_t),
1788 &ha->response_dma, GFP_KERNEL);
1789 if (ha->response_ring == NULL) {
1790 qla_printk(KERN_WARNING, ha,
1791 "Memory Allocation failed - response_ring\n");
1792
1793 qla2x00_mem_free(ha);
1794 msleep(100);
1795
1796 continue;
1797 }
1798
1799 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1800 &ha->gid_list_dma, GFP_KERNEL);
1801 if (ha->gid_list == NULL) {
1802 qla_printk(KERN_WARNING, ha,
1803 "Memory Allocation failed - gid_list\n");
1804
1805 qla2x00_mem_free(ha);
1806 msleep(100);
1807
1808 continue;
1809 }
1810
1811 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1812 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1813 if (ha->rlc_rsp == NULL) {
1814 qla_printk(KERN_WARNING, ha,
1815 "Memory Allocation failed - rlc");
1816
1817 qla2x00_mem_free(ha);
1818 msleep(100);
1819
1820 continue;
1821 }
1822
1823 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1824 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1825 DMA_POOL_SIZE, 8, 0);
1826 if (ha->s_dma_pool == NULL) {
1827 qla_printk(KERN_WARNING, ha,
1828 "Memory Allocation failed - s_dma_pool\n");
1829
1830 qla2x00_mem_free(ha);
1831 msleep(100);
1832
1833 continue;
1834 }
1835
1836 /* get consistent memory allocated for init control block */
1837 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1838 &ha->init_cb_dma);
1839 if (ha->init_cb == NULL) {
1840 qla_printk(KERN_WARNING, ha,
1841 "Memory Allocation failed - init_cb\n");
1842
1843 qla2x00_mem_free(ha);
1844 msleep(100);
1845
1846 continue;
1847 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001848 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850 /* Get consistent memory allocated for Get Port Database cmd */
1851 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1852 &ha->iodesc_pd_dma);
1853 if (ha->iodesc_pd == NULL) {
1854 /* error */
1855 qla_printk(KERN_WARNING, ha,
1856 "Memory Allocation failed - iodesc_pd\n");
1857
1858 qla2x00_mem_free(ha);
1859 msleep(100);
1860
1861 continue;
1862 }
1863 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1864
1865 /* Allocate ioctl related memory. */
1866 if (qla2x00_alloc_ioctl_mem(ha)) {
1867 qla_printk(KERN_WARNING, ha,
1868 "Memory Allocation failed - ioctl_mem\n");
1869
1870 qla2x00_mem_free(ha);
1871 msleep(100);
1872
1873 continue;
1874 }
1875
1876 if (qla2x00_allocate_sp_pool(ha)) {
1877 qla_printk(KERN_WARNING, ha,
1878 "Memory Allocation failed - "
1879 "qla2x00_allocate_sp_pool()\n");
1880
1881 qla2x00_mem_free(ha);
1882 msleep(100);
1883
1884 continue;
1885 }
1886
1887 /* Allocate memory for SNS commands */
1888 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1889 /* Get consistent memory allocated for SNS commands */
1890 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1891 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1892 GFP_KERNEL);
1893 if (ha->sns_cmd == NULL) {
1894 /* error */
1895 qla_printk(KERN_WARNING, ha,
1896 "Memory Allocation failed - sns_cmd\n");
1897
1898 qla2x00_mem_free(ha);
1899 msleep(100);
1900
1901 continue;
1902 }
1903 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1904 } else {
1905 /* Get consistent memory allocated for MS IOCB */
1906 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1907 &ha->ms_iocb_dma);
1908 if (ha->ms_iocb == NULL) {
1909 /* error */
1910 qla_printk(KERN_WARNING, ha,
1911 "Memory Allocation failed - ms_iocb\n");
1912
1913 qla2x00_mem_free(ha);
1914 msleep(100);
1915
1916 continue;
1917 }
1918 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1919
1920 /*
1921 * Get consistent memory allocated for CT SNS
1922 * commands
1923 */
1924 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1925 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1926 GFP_KERNEL);
1927 if (ha->ct_sns == NULL) {
1928 /* error */
1929 qla_printk(KERN_WARNING, ha,
1930 "Memory Allocation failed - ct_sns\n");
1931
1932 qla2x00_mem_free(ha);
1933 msleep(100);
1934
1935 continue;
1936 }
1937 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1938 }
1939
1940 /* Done all allocations without any error. */
1941 status = 0;
1942
1943 } while (retry-- && status != 0);
1944
1945 if (status) {
1946 printk(KERN_WARNING
1947 "%s(): **** FAILED ****\n", __func__);
1948 }
1949
1950 return(status);
1951}
1952
1953/*
1954* qla2x00_mem_free
1955* Frees all adapter allocated memory.
1956*
1957* Input:
1958* ha = adapter block pointer.
1959*/
1960static void
1961qla2x00_mem_free(scsi_qla_host_t *ha)
1962{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 struct list_head *fcpl, *fcptemp;
1964 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 unsigned long wtime;/* max wait time if mbx cmd is busy. */
1966
1967 if (ha == NULL) {
1968 /* error */
1969 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1970 return;
1971 }
1972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 /* Make sure all other threads are stopped. */
1974 wtime = 60 * HZ;
1975 while (ha->dpc_wait && wtime) {
1976 set_current_state(TASK_INTERRUPTIBLE);
1977 wtime = schedule_timeout(wtime);
1978 }
1979
1980 /* free ioctl memory */
1981 qla2x00_free_ioctl_mem(ha);
1982
1983 /* free sp pool */
1984 qla2x00_free_sp_pool(ha);
1985
1986 if (ha->sns_cmd)
1987 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1988 ha->sns_cmd, ha->sns_cmd_dma);
1989
1990 if (ha->ct_sns)
1991 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1992 ha->ct_sns, ha->ct_sns_dma);
1993
1994 if (ha->ms_iocb)
1995 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1996
1997 if (ha->iodesc_pd)
1998 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1999
2000 if (ha->init_cb)
2001 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
2002
2003 if (ha->s_dma_pool)
2004 dma_pool_destroy(ha->s_dma_pool);
2005
2006 if (ha->rlc_rsp)
2007 dma_free_coherent(&ha->pdev->dev,
2008 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2009 ha->rlc_rsp_dma);
2010
2011 if (ha->gid_list)
2012 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2013 ha->gid_list_dma);
2014
2015 if (ha->response_ring)
2016 dma_free_coherent(&ha->pdev->dev,
2017 (ha->response_q_length + 1) * sizeof(response_t),
2018 ha->response_ring, ha->response_dma);
2019
2020 if (ha->request_ring)
2021 dma_free_coherent(&ha->pdev->dev,
2022 (ha->request_q_length + 1) * sizeof(request_t),
2023 ha->request_ring, ha->request_dma);
2024
2025 ha->sns_cmd = NULL;
2026 ha->sns_cmd_dma = 0;
2027 ha->ct_sns = NULL;
2028 ha->ct_sns_dma = 0;
2029 ha->ms_iocb = NULL;
2030 ha->ms_iocb_dma = 0;
2031 ha->iodesc_pd = NULL;
2032 ha->iodesc_pd_dma = 0;
2033 ha->init_cb = NULL;
2034 ha->init_cb_dma = 0;
2035
2036 ha->s_dma_pool = NULL;
2037
2038 ha->rlc_rsp = NULL;
2039 ha->rlc_rsp_dma = 0;
2040 ha->gid_list = NULL;
2041 ha->gid_list_dma = 0;
2042
2043 ha->response_ring = NULL;
2044 ha->response_dma = 0;
2045 ha->request_ring = NULL;
2046 ha->request_dma = 0;
2047
2048 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2049 fcport = list_entry(fcpl, fc_port_t, list);
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 /* fc ports */
2052 list_del_init(&fcport->list);
2053 kfree(fcport);
2054 }
2055 INIT_LIST_HEAD(&ha->fcports);
2056
2057 if (ha->fw_dump)
2058 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2059
Andrew Vasquezfca29702005-07-06 10:31:47 -07002060 vfree(ha->fw_dump24);
2061
2062 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
2064 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002065 ha->fw_dump24 = NULL;
2066 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 ha->fw_dump_reading = 0;
2068 ha->fw_dump_buffer = NULL;
2069}
2070
2071/*
2072 * qla2x00_allocate_sp_pool
2073 * This routine is called during initialization to allocate
2074 * memory for local srb_t.
2075 *
2076 * Input:
2077 * ha = adapter block pointer.
2078 *
2079 * Context:
2080 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002081 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 * Note: Sets the ref_count for non Null sp to one.
2083 */
2084static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002085qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
2087 int rval;
2088
2089 rval = QLA_SUCCESS;
2090 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2091 mempool_free_slab, srb_cachep);
2092 if (ha->srb_mempool == NULL) {
2093 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2094 rval = QLA_FUNCTION_FAILED;
2095 }
2096 return (rval);
2097}
2098
2099/*
2100 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002101 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 */
2103static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002104qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
2106 if (ha->srb_mempool) {
2107 mempool_destroy(ha->srb_mempool);
2108 ha->srb_mempool = NULL;
2109 }
2110}
2111
2112/**************************************************************************
2113* qla2x00_do_dpc
2114* This kernel thread is a task that is schedule by the interrupt handler
2115* to perform the background processing for interrupts.
2116*
2117* Notes:
2118* This task always run in the context of a kernel thread. It
2119* is kick-off by the driver's detect code and starts up
2120* up one per adapter. It immediately goes to sleep and waits for
2121* some fibre event. When either the interrupt handler or
2122* the timer routine detects a event it will one of the task
2123* bits then wake us up.
2124**************************************************************************/
2125static int
2126qla2x00_do_dpc(void *data)
2127{
2128 DECLARE_MUTEX_LOCKED(sem);
2129 scsi_qla_host_t *ha;
2130 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
2134 ha = (scsi_qla_host_t *)data;
2135
2136 lock_kernel();
2137
2138 daemonize("%s_dpc", ha->host_str);
2139 allow_signal(SIGHUP);
2140
2141 ha->dpc_wait = &sem;
2142
2143 set_user_nice(current, -20);
2144
2145 unlock_kernel();
2146
2147 complete(&ha->dpc_inited);
2148
2149 while (1) {
2150 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2151
2152 if (down_interruptible(&sem))
2153 break;
2154
2155 if (ha->dpc_should_die)
2156 break;
2157
2158 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2159
2160 /* Initialization not yet finished. Don't do anything yet. */
2161 if (!ha->flags.init_done || ha->dpc_active)
2162 continue;
2163
2164 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2165
2166 ha->dpc_active = 1;
2167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 ha->dpc_active = 0;
2170 continue;
2171 }
2172
2173 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2174
2175 DEBUG(printk("scsi(%ld): dpc: sched "
2176 "qla2x00_abort_isp ha = %p\n",
2177 ha->host_no, ha));
2178 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2179 &ha->dpc_flags))) {
2180
2181 if (qla2x00_abort_isp(ha)) {
2182 /* failed. retry later */
2183 set_bit(ISP_ABORT_NEEDED,
2184 &ha->dpc_flags);
2185 }
2186 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2187 }
2188 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2189 ha->host_no));
2190 }
2191
2192 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2193 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2194
2195 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2196 ha->host_no));
2197
2198 qla2x00_rst_aen(ha);
2199 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2200 }
2201
2202 /* Retry each device up to login retry count */
2203 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2204 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2205 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2206
2207 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2208 ha->host_no));
2209
2210 next_loopid = 0;
2211 list_for_each_entry(fcport, &ha->fcports, list) {
2212 if (fcport->port_type != FCT_TARGET)
2213 continue;
2214
2215 /*
2216 * If the port is not ONLINE then try to login
2217 * to it if we haven't run out of retries.
2218 */
2219 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2220 fcport->login_retry) {
2221
2222 fcport->login_retry--;
2223 if (fcport->flags & FCF_FABRIC_DEVICE) {
2224 if (fcport->flags &
2225 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002226 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002227 ha, fcport->loop_id,
2228 fcport->d_id.b.domain,
2229 fcport->d_id.b.area,
2230 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 status = qla2x00_fabric_login(
2232 ha, fcport, &next_loopid);
2233 } else
2234 status =
2235 qla2x00_local_device_login(
2236 ha, fcport->loop_id);
2237
2238 if (status == QLA_SUCCESS) {
2239 fcport->old_loop_id = fcport->loop_id;
2240
2241 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2242 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002243
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 fcport->port_login_retry_count =
2245 ha->port_down_retry_count * PORT_RETRY_TIME;
2246 atomic_set(&fcport->state, FCS_ONLINE);
2247 atomic_set(&fcport->port_down_timer,
2248 ha->port_down_retry_count * PORT_RETRY_TIME);
2249
2250 fcport->login_retry = 0;
2251 } else if (status == 1) {
2252 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2253 /* retry the login again */
2254 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2255 ha->host_no,
2256 fcport->login_retry, fcport->loop_id));
2257 } else {
2258 fcport->login_retry = 0;
2259 }
2260 }
2261 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2262 break;
2263 }
2264 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2265 ha->host_no));
2266 }
2267
2268 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2269 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2270
2271 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2272 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2273 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2276
2277 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2278 ha->host_no));
2279 }
2280
2281 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2282
2283 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2284 ha->host_no));
2285
2286 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2287 &ha->dpc_flags))) {
2288
2289 qla2x00_loop_resync(ha);
2290
2291 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2292 }
2293
2294 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2295 ha->host_no));
2296 }
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2299
2300 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2301 ha->host_no));
2302
2303 qla2x00_rescan_fcports(ha);
2304
2305 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2306 "end.\n",
2307 ha->host_no));
2308 }
2309
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002311 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 ha->dpc_active = 0;
2314 } /* End of while(1) */
2315
2316 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2317
2318 /*
2319 * Make sure that nobody tries to wake us up again.
2320 */
2321 ha->dpc_wait = NULL;
2322 ha->dpc_active = 0;
2323
2324 complete_and_exit(&ha->dpc_exited, 0);
2325}
2326
2327/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328* qla2x00_rst_aen
2329* Processes asynchronous reset.
2330*
2331* Input:
2332* ha = adapter block pointer.
2333*/
2334static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002335qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336{
2337 if (ha->flags.online && !ha->flags.reset_active &&
2338 !atomic_read(&ha->loop_down_timer) &&
2339 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2340 do {
2341 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2342
2343 /*
2344 * Issue marker command only when we are going to start
2345 * the I/O.
2346 */
2347 ha->marker_needed = 1;
2348 } while (!atomic_read(&ha->loop_down_timer) &&
2349 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2350 }
2351}
2352
f4f051e2005-04-17 15:02:26 -05002353static void
2354qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2355{
2356 struct scsi_cmnd *cmd = sp->cmd;
2357
2358 if (sp->flags & SRB_DMA_VALID) {
2359 if (cmd->use_sg) {
2360 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2361 cmd->use_sg, cmd->sc_data_direction);
2362 } else if (cmd->request_bufflen) {
2363 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2364 cmd->request_bufflen, cmd->sc_data_direction);
2365 }
2366 sp->flags &= ~SRB_DMA_VALID;
2367 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002368 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002369}
2370
2371void
2372qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2373{
2374 struct scsi_cmnd *cmd = sp->cmd;
2375
2376 qla2x00_sp_free_dma(ha, sp);
2377
f4f051e2005-04-17 15:02:26 -05002378 mempool_free(sp, ha->srb_mempool);
2379
2380 cmd->scsi_done(cmd);
2381}
bdf79622005-04-17 15:06:53 -05002382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383/**************************************************************************
2384* qla2x00_timer
2385*
2386* Description:
2387* One second timer
2388*
2389* Context: Interrupt
2390***************************************************************************/
2391static void
2392qla2x00_timer(scsi_qla_host_t *ha)
2393{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 unsigned long cpu_flags = 0;
2395 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 int start_dpc = 0;
2397 int index;
2398 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002399 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401 /*
2402 * Ports - Port down timer.
2403 *
2404 * Whenever, a port is in the LOST state we start decrementing its port
2405 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002406 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 */
2408 t = 0;
2409 list_for_each_entry(fcport, &ha->fcports, list) {
2410 if (fcport->port_type != FCT_TARGET)
2411 continue;
2412
2413 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2414
2415 if (atomic_read(&fcport->port_down_timer) == 0)
2416 continue;
2417
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002418 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002422 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 ha->host_no,
2424 t, atomic_read(&fcport->port_down_timer)));
2425 }
2426 t++;
2427 } /* End of for fcport */
2428
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
2430 /* Loop down handler. */
2431 if (atomic_read(&ha->loop_down_timer) > 0 &&
2432 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2433
2434 if (atomic_read(&ha->loop_down_timer) ==
2435 ha->loop_down_abort_time) {
2436
2437 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2438 "queues before time expire\n",
2439 ha->host_no));
2440
2441 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002442 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
2444 /* Schedule an ISP abort to return any tape commands. */
2445 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2446 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2447 index++) {
bdf79622005-04-17 15:06:53 -05002448 fc_port_t *sfcp;
2449
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 sp = ha->outstanding_cmds[index];
2451 if (!sp)
2452 continue;
bdf79622005-04-17 15:06:53 -05002453 sfcp = sp->fcport;
2454 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 continue;
2456
2457 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2458 break;
2459 }
2460 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2461
2462 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2463 start_dpc++;
2464 }
2465
2466 /* if the loop has been down for 4 minutes, reinit adapter */
2467 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2468 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2469 "restarting queues.\n",
2470 ha->host_no));
2471
2472 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2473 start_dpc++;
2474
2475 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2476 DEBUG(printk("scsi(%ld): Loop down - "
2477 "aborting ISP.\n",
2478 ha->host_no));
2479 qla_printk(KERN_WARNING, ha,
2480 "Loop down - aborting ISP.\n");
2481
2482 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2483 }
2484 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002485 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 ha->host_no,
2487 atomic_read(&ha->loop_down_timer)));
2488 }
2489
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 /* Schedule the DPC routine if needed */
2491 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2492 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2493 start_dpc ||
2494 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002495 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2497 ha->dpc_wait && !ha->dpc_active) {
2498
2499 up(ha->dpc_wait);
2500 }
2501
2502 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2503}
2504
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505/* XXX(hch): crude hack to emulate a down_timeout() */
2506int
2507qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2508{
2509 const unsigned int step = HZ/10;
2510
2511 do {
2512 if (!down_trylock(sema))
2513 return 0;
2514 set_current_state(TASK_INTERRUPTIBLE);
2515 if (schedule_timeout(step))
2516 break;
2517 } while ((timeout -= step) > 0);
2518
2519 return -ETIMEDOUT;
2520}
2521
Andrew Vasquezfca29702005-07-06 10:31:47 -07002522static struct qla_board_info qla_board_tbl[] = {
2523 {
2524 .drv_name = "qla2400",
2525 .isp_name = "ISP2422",
2526 .fw_fname = "ql2400_fw.bin",
2527 .sht = &qla24xx_driver_template,
2528 },
2529 {
2530 .drv_name = "qla2400",
2531 .isp_name = "ISP2432",
2532 .fw_fname = "ql2400_fw.bin",
2533 .sht = &qla24xx_driver_template,
2534 },
2535};
2536
2537static struct pci_device_id qla2xxx_pci_tbl[] = {
2538 {
2539 .vendor = PCI_VENDOR_ID_QLOGIC,
2540 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2541 .subvendor = PCI_ANY_ID,
2542 .subdevice = PCI_ANY_ID,
2543 .driver_data = (unsigned long)&qla_board_tbl[0],
2544 },
2545 {
2546 .vendor = PCI_VENDOR_ID_QLOGIC,
2547 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2548 .subvendor = PCI_ANY_ID,
2549 .subdevice = PCI_ANY_ID,
2550 .driver_data = (unsigned long)&qla_board_tbl[1],
2551 },
2552 {0, 0},
2553};
2554MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2555
2556static int __devinit
2557qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2558{
2559 return qla2x00_probe_one(pdev,
2560 (struct qla_board_info *)id->driver_data);
2561}
2562
2563static void __devexit
2564qla2xxx_remove_one(struct pci_dev *pdev)
2565{
2566 qla2x00_remove_one(pdev);
2567}
2568
2569static struct pci_driver qla2xxx_pci_driver = {
2570 .name = "qla2xxx",
2571 .id_table = qla2xxx_pci_tbl,
2572 .probe = qla2xxx_probe_one,
2573 .remove = __devexit_p(qla2xxx_remove_one),
2574};
2575
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576/**
2577 * qla2x00_module_init - Module initialization.
2578 **/
2579static int __init
2580qla2x00_module_init(void)
2581{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002582 int ret = 0;
2583
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002585 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 SLAB_HWCACHE_ALIGN, NULL, NULL);
2587 if (srb_cachep == NULL) {
2588 printk(KERN_ERR
2589 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2590 return -ENOMEM;
2591 }
2592
2593 /* Derive version string. */
2594 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2595#if DEBUG_QLA2100
2596 strcat(qla2x00_version_str, "-debug");
2597#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002598 qla2xxx_transport_template =
2599 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 if (!qla2xxx_transport_template)
2601 return -ENODEV;
2602
2603 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002604 ret = pci_module_init(&qla2xxx_pci_driver);
2605 if (ret) {
2606 kmem_cache_destroy(srb_cachep);
2607 fc_release_transport(qla2xxx_transport_template);
2608 }
2609 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/**
2613 * qla2x00_module_exit - Module cleanup.
2614 **/
2615static void __exit
2616qla2x00_module_exit(void)
2617{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002618 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002619 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 fc_release_transport(qla2xxx_transport_template);
2621}
2622
2623module_init(qla2x00_module_init);
2624module_exit(qla2x00_module_exit);
2625
2626MODULE_AUTHOR("QLogic Corporation");
2627MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2628MODULE_LICENSE("GPL");
2629MODULE_VERSION(QLA2XXX_VERSION);