blob: 8982978c42fdfa4f780bf454bac3e8f8d4de0507 [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 Vasquezf6ef3b12005-08-26 19:10:20 -070082int ql2xfwloadbin=1;
Andrew Vasquezfca29702005-07-06 10:31:47 -070083module_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{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700505#define ABORT_POLLING_PERIOD 1000
506#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500507 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)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700511 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
f4f051e2005-04-17 15:02:26 -0500513 if (--wait_iter)
514 break;
515 }
516 if (CMD_SP(cmd))
517 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
f4f051e2005-04-17 15:02:26 -0500519 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
522/*
523 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700524 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * <= MAX_RETRIES_OF_ISP_ABORT or
526 * finally HBA is disabled ie marked offline
527 *
528 * Input:
529 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700530 *
531 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 * Does context switching-Release SPIN_LOCK
533 * (if any) before calling this routine.
534 *
535 * Return:
536 * Success (Adapter is online) : 0
537 * Failed (Adapter is offline/disabled) : 1
538 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700539static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
541{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700542 int return_status;
543 unsigned long wait_online;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700545 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
547 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
548 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
549 ha->dpc_active) && time_before(jiffies, wait_online)) {
550
551 msleep(1000);
552 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700553 if (ha->flags.online)
554 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 else
556 return_status = QLA_FUNCTION_FAILED;
557
558 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
559
560 return (return_status);
561}
562
563/*
564 * qla2x00_wait_for_loop_ready
565 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700566 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 * Input:
568 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700569 *
570 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * Does context switching-Release SPIN_LOCK
572 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700573 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 *
575 * Return:
576 * Success (LOOP_READY) : 0
577 * Failed (LOOP_NOT_READY) : 1
578 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700579static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
581{
582 int return_status = QLA_SUCCESS;
583 unsigned long loop_timeout ;
584
585 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700586 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 while ((!atomic_read(&ha->loop_down_timer) &&
589 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 atomic_read(&ha->loop_state) != LOOP_READY) {
591 msleep(1000);
592 if (time_after_eq(jiffies, loop_timeout)) {
593 return_status = QLA_FUNCTION_FAILED;
594 break;
595 }
596 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700597 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
600/**************************************************************************
601* qla2xxx_eh_abort
602*
603* Description:
604* The abort function will abort the specified command.
605*
606* Input:
607* cmd = Linux SCSI command packet to be aborted.
608*
609* Returns:
610* Either SUCCESS or FAILED.
611*
612* Note:
613**************************************************************************/
614int
615qla2xxx_eh_abort(struct scsi_cmnd *cmd)
616{
f4f051e2005-04-17 15:02:26 -0500617 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
618 srb_t *sp;
619 int ret, i;
620 unsigned int id, lun;
621 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700622 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
f4f051e2005-04-17 15:02:26 -0500624 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
f4f051e2005-04-17 15:02:26 -0500627 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
f4f051e2005-04-17 15:02:26 -0500629 id = cmd->device->id;
630 lun = cmd->device->lun;
631 serial = cmd->serial_number;
632
633 /* Check active list for command command. */
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700634 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500635 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
636 sp = ha->outstanding_cmds[i];
637
638 if (sp == NULL)
639 continue;
640
641 if (sp->cmd != cmd)
642 continue;
643
644 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
645 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
646 sp->state));
647 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
648
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700649 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700650 if (ha->isp_ops.abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500651 DEBUG2(printk("%s(%ld): abort_command "
652 "mbx failed.\n", __func__, ha->host_no));
653 } else {
654 DEBUG3(printk("%s(%ld): abort_command "
655 "mbx success.\n", __func__, ha->host_no));
656 ret = SUCCESS;
657 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700658 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500659
660 break;
661 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700662 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500663
664 /* Wait for the command to be returned. */
665 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500666 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700667 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500668 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
669 "%x.\n", ha->host_no, id, lun, serial, ret);
670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700673 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500674 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
675 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
f4f051e2005-04-17 15:02:26 -0500677 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
680/**************************************************************************
681* qla2x00_eh_wait_for_pending_target_commands
682*
683* Description:
684* Waits for all the commands to come back from the specified target.
685*
686* Input:
687* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700688* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689* Returns:
690* Either SUCCESS or FAILED.
691*
692* Note:
693**************************************************************************/
694static int
695qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
696{
697 int cnt;
698 int status;
699 srb_t *sp;
700 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700701 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 status = 0;
704
705 /*
706 * Waiting for all commands for the designated target in the active
707 * array
708 */
709 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700710 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 sp = ha->outstanding_cmds[cnt];
712 if (sp) {
713 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700714 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if (cmd->device->id == t) {
716 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
717 status = 1;
718 break;
719 }
720 }
f4f051e2005-04-17 15:02:26 -0500721 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700722 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724 }
725 return (status);
726}
727
728
729/**************************************************************************
730* qla2xxx_eh_device_reset
731*
732* Description:
733* The device reset function will reset the target and abort any
734* executing commands.
735*
736* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700737* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738* non-null.
739*
740* Input:
741* cmd = Linux SCSI command packet of the command that cause the
742* bus device reset.
743*
744* Returns:
745* SUCCESS/FAILURE (defined as macro in scsi.h).
746*
747**************************************************************************/
748int
749qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
750{
f4f051e2005-04-17 15:02:26 -0500751 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500752 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500753 srb_t *sp;
754 int ret;
755 unsigned int id, lun;
756 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
f4f051e2005-04-17 15:02:26 -0500758 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
f4f051e2005-04-17 15:02:26 -0500760 id = cmd->device->id;
761 lun = cmd->device->lun;
762 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
f4f051e2005-04-17 15:02:26 -0500764 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500765 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500766 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500769 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400771 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500775 if (qla2x00_device_reset(ha, fcport) == 0)
776 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500779 if (ret == SUCCESS) {
780 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700781 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
f4f051e2005-04-17 15:02:26 -0500782 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 }
784 }
785#endif
786 } else {
787 DEBUG2(printk(KERN_INFO
788 "%s failed: loop not ready\n",__func__);)
789 }
790
f4f051e2005-04-17 15:02:26 -0500791 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 DEBUG3(printk("%s(%ld): device reset failed\n",
793 __func__, ha->host_no));
794 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
795 __func__);
796
797 goto eh_dev_reset_done;
798 }
799
800 /*
801 * If we are coming down the EH path, wait for all commands to
802 * complete for the device.
803 */
804 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500805 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
806 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
f4f051e2005-04-17 15:02:26 -0500808 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 DEBUG3(printk("%s(%ld): failed while waiting for "
810 "commands\n", __func__, ha->host_no));
811 qla_printk(KERN_INFO, ha,
812 "%s: failed while waiting for commands\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700813 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 goto eh_dev_reset_done;
816 }
817 }
818
819 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500820 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500823 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
826/**************************************************************************
827* qla2x00_eh_wait_for_pending_commands
828*
829* Description:
830* Waits for all the commands to come back from the specified host.
831*
832* Input:
833* ha - pointer to scsi_qla_host structure.
834*
835* Returns:
836* 1 : SUCCESS
837* 0 : FAILED
838*
839* Note:
840**************************************************************************/
841static int
842qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
843{
844 int cnt;
845 int status;
846 srb_t *sp;
847 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700848 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 status = 1;
851
852 /*
853 * Waiting for all commands for the designated target in the active
854 * array
855 */
856 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700857 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 sp = ha->outstanding_cmds[cnt];
859 if (sp) {
860 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700861 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 status = qla2x00_eh_wait_on_command(ha, cmd);
863 if (status == 0)
864 break;
865 }
866 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700867 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 }
869 }
870 return (status);
871}
872
873
874/**************************************************************************
875* qla2xxx_eh_bus_reset
876*
877* Description:
878* The bus reset function will reset the bus and abort any executing
879* commands.
880*
881* Input:
882* cmd = Linux SCSI command packet of the command that cause the
883* bus reset.
884*
885* Returns:
886* SUCCESS/FAILURE (defined as macro in scsi.h).
887*
888**************************************************************************/
889int
890qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
891{
f4f051e2005-04-17 15:02:26 -0500892 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500893 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500895 int ret;
896 unsigned int id, lun;
897 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
f4f051e2005-04-17 15:02:26 -0500899 ret = FAILED;
900
901 id = cmd->device->id;
902 lun = cmd->device->lun;
903 serial = cmd->serial_number;
904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500906 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500907 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500910 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
913 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500914 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916
917 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500918 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
919 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
f4f051e2005-04-17 15:02:26 -0500921 if (ret == FAILED)
922 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /* Waiting for our command in done_queue to be returned to OS.*/
925 if (cmd->device->host->eh_active)
926 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500927 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
f4f051e2005-04-17 15:02:26 -0500929eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500931 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
f4f051e2005-04-17 15:02:26 -0500933 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
936/**************************************************************************
937* qla2xxx_eh_host_reset
938*
939* Description:
940* The reset function will reset the Adapter.
941*
942* Input:
943* cmd = Linux SCSI command packet of the command that cause the
944* adapter reset.
945*
946* Returns:
947* Either SUCCESS or FAILED.
948*
949* Note:
950**************************************************************************/
951int
952qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
953{
f4f051e2005-04-17 15:02:26 -0500954 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500955 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500956 srb_t *sp;
957 int ret;
958 unsigned int id, lun;
959 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
f4f051e2005-04-17 15:02:26 -0500961 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
f4f051e2005-04-17 15:02:26 -0500963 id = cmd->device->id;
964 lun = cmd->device->lun;
965 serial = cmd->serial_number;
966
967 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500968 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500969 return ret;
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500972 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500975 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /*
978 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700979 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 * be completed and then issue big hammer.Otherwise
981 * it may cause I/O failure as big hammer marks the
982 * devices as lost kicking of the port_down_timer
983 * while dpc is stuck for the mailbox to complete.
984 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 qla2x00_wait_for_loop_ready(ha);
986 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
987 if (qla2x00_abort_isp(ha)) {
988 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
989 /* failed. schedule dpc to try */
990 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
991
992 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500993 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500998 if (qla2x00_eh_wait_for_pending_commands(ha))
999 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
f4f051e2005-04-17 15:02:26 -05001001eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001002 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1003 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
f4f051e2005-04-17 15:02:26 -05001005 return ret;
1006}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008/*
1009* qla2x00_loop_reset
1010* Issue loop reset.
1011*
1012* Input:
1013* ha = adapter block pointer.
1014*
1015* Returns:
1016* 0 = success
1017*/
1018static int
1019qla2x00_loop_reset(scsi_qla_host_t *ha)
1020{
1021 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -05001022 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 if (ha->flags.enable_lip_reset) {
1025 status = qla2x00_lip_reset(ha);
1026 }
1027
1028 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001029 list_for_each_entry(fcport, &ha->fcports, list) {
1030 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 continue;
1032
Andrew Vasquezc00c72a2005-08-26 19:08:50 -07001033 status = qla2x00_device_reset(ha, fcport);
bdf79622005-04-17 15:06:53 -05001034 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037 }
1038
1039 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001040 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 !ha->flags.enable_lip_reset) ||
1042 ha->flags.enable_lip_full_login)) {
1043
1044 status = qla2x00_full_login_lip(ha);
1045 }
1046
1047 /* Issue marker command only when we are going to start the I/O */
1048 ha->marker_needed = 1;
1049
1050 if (status) {
1051 /* Empty */
1052 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1053 __func__,
1054 ha->host_no);)
1055 } else {
1056 /* Empty */
1057 DEBUG3(printk("%s(%ld): exiting normally.\n",
1058 __func__,
1059 ha->host_no);)
1060 }
1061
1062 return(status);
1063}
1064
1065/*
1066 * qla2x00_device_reset
1067 * Issue bus device reset message to the target.
1068 *
1069 * Input:
1070 * ha = adapter block pointer.
1071 * t = SCSI ID.
1072 * TARGET_QUEUE_LOCK must be released.
1073 * ADAPTER_STATE_LOCK must be released.
1074 *
1075 * Context:
1076 * Kernel context.
1077 */
1078static int
1079qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1080{
1081 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001082 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
f4f051e2005-04-17 15:02:26 -05001085static int
1086qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
bdf79622005-04-17 15:06:53 -05001088 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
bdf79622005-04-17 15:06:53 -05001090 if (!rport)
f4f051e2005-04-17 15:02:26 -05001091 return -ENXIO;
1092
Andrew Vasquez77d74142005-07-08 18:00:36 -07001093 sdev->hostdata = rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001094
1095 return 0;
1096}
1097
1098static int
1099qla2xxx_slave_configure(struct scsi_device *sdev)
1100{
8482e1182005-04-17 15:04:54 -05001101 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1102 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1103
f4f051e2005-04-17 15:02:26 -05001104 if (sdev->tagged_supported)
1105 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 else
f4f051e2005-04-17 15:02:26 -05001107 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
8482e1182005-04-17 15:04:54 -05001109 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1110
f4f051e2005-04-17 15:02:26 -05001111 return 0;
1112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
f4f051e2005-04-17 15:02:26 -05001114static void
1115qla2xxx_slave_destroy(struct scsi_device *sdev)
1116{
1117 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001120static int
1121qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1122{
1123 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1124 return sdev->queue_depth;
1125}
1126
1127static int
1128qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1129{
1130 if (sdev->tagged_supported) {
1131 scsi_set_tag_type(sdev, tag_type);
1132 if (tag_type)
1133 scsi_activate_tcq(sdev, sdev->queue_depth);
1134 else
1135 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1136 } else
1137 tag_type = 0;
1138
1139 return tag_type;
1140}
1141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142/**
1143 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1144 * @ha: HA context
1145 *
1146 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1147 * supported addressing method.
1148 */
1149static void
1150qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1151{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001152 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001155 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1156 /* Any upper-dword bits set? */
1157 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1158 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1159 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001161 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1162 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001163 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001166
1167 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1168 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
1171static int
1172qla2x00_iospace_config(scsi_qla_host_t *ha)
1173{
1174 unsigned long pio, pio_len, pio_flags;
1175 unsigned long mmio, mmio_len, mmio_flags;
1176
1177 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1178 pio = pci_resource_start(ha->pdev, 0);
1179 pio_len = pci_resource_len(ha->pdev, 0);
1180 pio_flags = pci_resource_flags(ha->pdev, 0);
1181 if (pio_flags & IORESOURCE_IO) {
1182 if (pio_len < MIN_IOBASE_LEN) {
1183 qla_printk(KERN_WARNING, ha,
1184 "Invalid PCI I/O region size (%s)...\n",
1185 pci_name(ha->pdev));
1186 pio = 0;
1187 }
1188 } else {
1189 qla_printk(KERN_WARNING, ha,
1190 "region #0 not a PIO resource (%s)...\n",
1191 pci_name(ha->pdev));
1192 pio = 0;
1193 }
1194
1195 /* Use MMIO operations for all accesses. */
1196 mmio = pci_resource_start(ha->pdev, 1);
1197 mmio_len = pci_resource_len(ha->pdev, 1);
1198 mmio_flags = pci_resource_flags(ha->pdev, 1);
1199
1200 if (!(mmio_flags & IORESOURCE_MEM)) {
1201 qla_printk(KERN_ERR, ha,
1202 "region #0 not an MMIO resource (%s), aborting\n",
1203 pci_name(ha->pdev));
1204 goto iospace_error_exit;
1205 }
1206 if (mmio_len < MIN_IOBASE_LEN) {
1207 qla_printk(KERN_ERR, ha,
1208 "Invalid PCI mem region size (%s), aborting\n",
1209 pci_name(ha->pdev));
1210 goto iospace_error_exit;
1211 }
1212
1213 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1214 qla_printk(KERN_WARNING, ha,
1215 "Failed to reserve PIO/MMIO regions (%s)\n",
1216 pci_name(ha->pdev));
1217
1218 goto iospace_error_exit;
1219 }
1220
1221 ha->pio_address = pio;
1222 ha->pio_length = pio_len;
1223 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1224 if (!ha->iobase) {
1225 qla_printk(KERN_ERR, ha,
1226 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1227
1228 goto iospace_error_exit;
1229 }
1230
1231 return (0);
1232
1233iospace_error_exit:
1234 return (-ENOMEM);
1235}
1236
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001237static void
1238qla2x00_enable_intrs(scsi_qla_host_t *ha)
1239{
1240 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001241 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001242
1243 spin_lock_irqsave(&ha->hardware_lock, flags);
1244 ha->interrupts_on = 1;
1245 /* enable risc and host interrupts */
1246 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1247 RD_REG_WORD(&reg->ictrl);
1248 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1249
1250}
1251
1252static void
1253qla2x00_disable_intrs(scsi_qla_host_t *ha)
1254{
1255 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001256 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001257
1258 spin_lock_irqsave(&ha->hardware_lock, flags);
1259 ha->interrupts_on = 0;
1260 /* disable risc and host interrupts */
1261 WRT_REG_WORD(&reg->ictrl, 0);
1262 RD_REG_WORD(&reg->ictrl);
1263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1264}
1265
Andrew Vasquezfca29702005-07-06 10:31:47 -07001266static void
1267qla24xx_enable_intrs(scsi_qla_host_t *ha)
1268{
1269 unsigned long flags = 0;
1270 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1271
1272 spin_lock_irqsave(&ha->hardware_lock, flags);
1273 ha->interrupts_on = 1;
1274 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1275 RD_REG_DWORD(&reg->ictrl);
1276 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1277}
1278
1279static void
1280qla24xx_disable_intrs(scsi_qla_host_t *ha)
1281{
1282 unsigned long flags = 0;
1283 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1284
1285 spin_lock_irqsave(&ha->hardware_lock, flags);
1286 ha->interrupts_on = 0;
1287 WRT_REG_DWORD(&reg->ictrl, 0);
1288 RD_REG_DWORD(&reg->ictrl);
1289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1290}
1291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292/*
1293 * PCI driver interface
1294 */
1295int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1296{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001297 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001298 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 struct Scsi_Host *host;
1300 scsi_qla_host_t *ha;
1301 unsigned long flags = 0;
1302 unsigned long wait_switch = 0;
1303 char pci_info[20];
1304 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001305 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001308 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Andrew Vasquezfca29702005-07-06 10:31:47 -07001310 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1311 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (host == NULL) {
1313 printk(KERN_WARNING
1314 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1315 goto probe_disable_device;
1316 }
1317
1318 /* Clear our data area */
1319 ha = (scsi_qla_host_t *)host->hostdata;
1320 memset(ha, 0, sizeof(scsi_qla_host_t));
1321
1322 ha->pdev = pdev;
1323 ha->host = host;
1324 ha->host_no = host->host_no;
1325 ha->brd_info = brd_info;
1326 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1327
1328 /* Configure PCI I/O space */
1329 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001330 if (ret)
1331 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 qla_printk(KERN_INFO, ha,
1334 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001335 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 spin_lock_init(&ha->hardware_lock);
1338
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 ha->prev_topology = 0;
1340 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001341 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001342 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001344 /* Assign ISP specific operations. */
1345 ha->isp_ops.pci_config = qla2100_pci_config;
1346 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1347 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1348 ha->isp_ops.config_rings = qla2x00_config_rings;
1349 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1350 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1351 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001352 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001353 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1354 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1355 ha->isp_ops.intr_handler = qla2100_intr_handler;
1356 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1357 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1358 ha->isp_ops.abort_command = qla2x00_abort_command;
1359 ha->isp_ops.abort_target = qla2x00_abort_target;
1360 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1361 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1362 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1363 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1364 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001365 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001366 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1367 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001368 ha->isp_ops.fw_dump = qla2100_fw_dump;
1369 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001371 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1373 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1374 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1375 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1376 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001377 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001379 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1381 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1382 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1383 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001384 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001385 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001386 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1388 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1389 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1390 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001391 ha->isp_ops.pci_config = qla2300_pci_config;
1392 ha->isp_ops.intr_handler = qla2300_intr_handler;
1393 ha->isp_ops.fw_dump = qla2300_fw_dump;
1394 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1395 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001396 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1397 host->max_id = MAX_TARGETS_2200;
1398 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1399 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1400 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1401 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1402 ha->init_cb_size = sizeof(struct init_cb_24xx);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001403 ha->mgmt_svr_loop_id = 10;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001404 ha->isp_ops.pci_config = qla24xx_pci_config;
1405 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1406 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1407 ha->isp_ops.config_rings = qla24xx_config_rings;
1408 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1409 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1410 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1411 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1412 if (ql2xfwloadbin)
1413 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1414 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1415 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1416 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1417 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1418 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1419 ha->isp_ops.abort_command = qla24xx_abort_command;
1420 ha->isp_ops.abort_target = qla24xx_abort_target;
1421 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1422 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1423 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001424 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001425 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1426 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1427 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1428 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1429 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431 host->can_queue = ha->request_q_length + 128;
1432
1433 /* load the F/W, read paramaters, and init the H/W */
1434 ha->instance = num_hosts;
1435
1436 init_MUTEX(&ha->mbx_cmd_sem);
1437 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1438
1439 INIT_LIST_HEAD(&ha->list);
1440 INIT_LIST_HEAD(&ha->fcports);
1441 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
1443 /*
1444 * These locks are used to prevent more than one CPU
1445 * from modifying the queue at the same time. The
1446 * higher level "host_lock" will reduce most
1447 * contention for these locks.
1448 */
1449 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 ha->dpc_pid = -1;
1452 init_completion(&ha->dpc_inited);
1453 init_completion(&ha->dpc_exited);
1454
1455 qla2x00_config_dma_addressing(ha);
1456 if (qla2x00_mem_alloc(ha)) {
1457 qla_printk(KERN_WARNING, ha,
1458 "[ERROR] Failed to allocate memory for adapter\n");
1459
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001460 ret = -ENOMEM;
1461 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
1463
1464 if (qla2x00_initialize_adapter(ha) &&
1465 !(ha->device_flags & DFLG_NO_CABLE)) {
1466
1467 qla_printk(KERN_WARNING, ha,
1468 "Failed to initialize adapter\n");
1469
1470 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1471 "Adapter flags %x.\n",
1472 ha->host_no, ha->device_flags));
1473
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001474 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 goto probe_failed;
1476 }
1477
1478 /*
1479 * Startup the kernel thread for this host adapter
1480 */
1481 ha->dpc_should_die = 0;
1482 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1483 if (ha->dpc_pid < 0) {
1484 qla_printk(KERN_WARNING, ha,
1485 "Unable to start DPC thread!\n");
1486
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001487 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 goto probe_failed;
1489 }
1490 wait_for_completion(&ha->dpc_inited);
1491
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001492 host->this_id = 255;
1493 host->cmd_per_lun = 3;
1494 host->unique_id = ha->instance;
1495 host->max_cmd_len = MAX_CMDSZ;
1496 host->max_channel = ha->ports - 1;
1497 host->max_lun = MAX_LUNS;
1498 host->transportt = qla2xxx_transport_template;
1499
Andrew Vasquezfca29702005-07-06 10:31:47 -07001500 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001501 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001502 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 qla_printk(KERN_WARNING, ha,
1504 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001505 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 goto probe_failed;
1507 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001508 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 /* Initialized the timer */
1511 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1512
1513 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1514 ha->host_no, ha));
1515
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001516 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001519 reg = ha->iobase;
1520 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1521 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1522 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1523 } else {
1524 WRT_REG_WORD(&reg->isp.semaphore, 0);
1525 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1526 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Andrew Vasquezfca29702005-07-06 10:31:47 -07001528 /* Enable proper parity */
1529 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1530 if (IS_QLA2300(ha))
1531 /* SRAM parity */
1532 WRT_REG_WORD(&reg->isp.hccr,
1533 (HCCR_ENABLE_PARITY + 0x1));
1534 else
1535 /* SRAM, Instruction RAM and GP RAM parity */
1536 WRT_REG_WORD(&reg->isp.hccr,
1537 (HCCR_ENABLE_PARITY + 0x7));
1538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 }
1540 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1541
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001542 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 /* v2.19.5b6 */
1545 /*
1546 * Wait around max loop_reset_delay secs for the devices to come
1547 * on-line. We don't want Linux scanning before we are ready.
1548 *
1549 */
1550 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1551 time_before(jiffies,wait_switch) &&
1552 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1553 && (ha->device_flags & SWITCH_FOUND) ;) {
1554
1555 qla2x00_check_fabric_devices(ha);
1556
1557 msleep(10);
1558 }
1559
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001560 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 ha->flags.init_done = 1;
1562 num_hosts++;
1563
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001564 ret = scsi_add_host(host, &pdev->dev);
1565 if (ret)
1566 goto probe_failed;
1567
1568 qla2x00_alloc_sysfs_attr(ha);
1569
1570 qla2x00_init_host_attr(ha);
1571
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 qla_printk(KERN_INFO, ha, "\n"
1573 " QLogic Fibre Channel HBA Driver: %s\n"
1574 " QLogic %s - %s\n"
1575 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1576 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001577 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001578 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001579 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
8482e1182005-04-17 15:04:54 -05001581 /* Go with fc_rport registration. */
1582 list_for_each_entry(fcport, &ha->fcports, list)
1583 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 return 0;
1586
1587probe_failed:
1588 qla2x00_free_device(ha);
1589
1590 scsi_host_put(host);
1591
1592probe_disable_device:
1593 pci_disable_device(pdev);
1594
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001595probe_out:
1596 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597}
1598EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1599
1600void qla2x00_remove_one(struct pci_dev *pdev)
1601{
1602 scsi_qla_host_t *ha;
1603
1604 ha = pci_get_drvdata(pdev);
1605
8482e1182005-04-17 15:04:54 -05001606 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
bdf79622005-04-17 15:06:53 -05001608 fc_remove_host(ha->host);
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 scsi_remove_host(ha->host);
1611
1612 qla2x00_free_device(ha);
1613
1614 scsi_host_put(ha->host);
1615
1616 pci_set_drvdata(pdev, NULL);
1617}
1618EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1619
1620static void
1621qla2x00_free_device(scsi_qla_host_t *ha)
1622{
1623 int ret;
1624
1625 /* Abort any outstanding IO descriptors. */
1626 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1627 qla2x00_cancel_io_descriptors(ha);
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 /* Disable timer */
1630 if (ha->timer_active)
1631 qla2x00_stop_timer(ha);
1632
1633 /* Kill the kernel thread for this host */
1634 if (ha->dpc_pid >= 0) {
1635 ha->dpc_should_die = 1;
1636 wmb();
1637 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1638 if (ret) {
1639 qla_printk(KERN_ERR, ha,
1640 "Unable to signal DPC thread -- (%d)\n", ret);
1641
1642 /* TODO: SOMETHING MORE??? */
1643 } else {
1644 wait_for_completion(&ha->dpc_exited);
1645 }
1646 }
1647
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001648 /* Stop currently executing firmware. */
1649 qla2x00_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001651 /* turn-off interrupts on the card */
1652 if (ha->interrupts_on)
1653 ha->isp_ops.disable_intrs(ha);
1654
1655 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 ha->flags.online = 0;
1658
1659 /* Detach interrupts */
1660 if (ha->pdev->irq)
1661 free_irq(ha->pdev->irq, ha);
1662
1663 /* release io space registers */
1664 if (ha->iobase)
1665 iounmap(ha->iobase);
1666 pci_release_regions(ha->pdev);
1667
1668 pci_disable_device(ha->pdev);
1669}
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1673 *
1674 * Input: ha = adapter block pointer. fcport = port structure pointer.
1675 *
1676 * Return: None.
1677 *
1678 * Context:
1679 */
1680void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1681 int do_login)
1682{
8482e1182005-04-17 15:04:54 -05001683 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1684 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001685 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 * We may need to retry the login, so don't change the state of the
1687 * port but do the retries.
1688 */
1689 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1690 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1691
1692 if (!do_login)
1693 return;
1694
1695 if (fcport->login_retry == 0) {
1696 fcport->login_retry = ha->login_retry_count;
1697 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1698
1699 DEBUG(printk("scsi(%ld): Port login retry: "
1700 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1701 "id = 0x%04x retry cnt=%d\n",
1702 ha->host_no,
1703 fcport->port_name[0],
1704 fcport->port_name[1],
1705 fcport->port_name[2],
1706 fcport->port_name[3],
1707 fcport->port_name[4],
1708 fcport->port_name[5],
1709 fcport->port_name[6],
1710 fcport->port_name[7],
1711 fcport->loop_id,
1712 fcport->login_retry));
1713 }
1714}
1715
1716/*
1717 * qla2x00_mark_all_devices_lost
1718 * Updates fcport state when device goes offline.
1719 *
1720 * Input:
1721 * ha = adapter block pointer.
1722 * fcport = port structure pointer.
1723 *
1724 * Return:
1725 * None.
1726 *
1727 * Context:
1728 */
1729void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001730qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
1732 fc_port_t *fcport;
1733
1734 list_for_each_entry(fcport, &ha->fcports, list) {
1735 if (fcport->port_type != FCT_TARGET)
1736 continue;
1737
1738 /*
1739 * No point in marking the device as lost, if the device is
1740 * already DEAD.
1741 */
1742 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1743 continue;
8482e1182005-04-17 15:04:54 -05001744 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1745 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1747 }
1748}
1749
1750/*
1751* qla2x00_mem_alloc
1752* Allocates adapter memory.
1753*
1754* Returns:
1755* 0 = success.
1756* 1 = failure.
1757*/
1758static uint8_t
1759qla2x00_mem_alloc(scsi_qla_host_t *ha)
1760{
1761 char name[16];
1762 uint8_t status = 1;
1763 int retry= 10;
1764
1765 do {
1766 /*
1767 * This will loop only once if everything goes well, else some
1768 * number of retries will be performed to get around a kernel
1769 * bug where available mem is not allocated until after a
1770 * little delay and a retry.
1771 */
1772 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1773 (ha->request_q_length + 1) * sizeof(request_t),
1774 &ha->request_dma, GFP_KERNEL);
1775 if (ha->request_ring == NULL) {
1776 qla_printk(KERN_WARNING, ha,
1777 "Memory Allocation failed - request_ring\n");
1778
1779 qla2x00_mem_free(ha);
1780 msleep(100);
1781
1782 continue;
1783 }
1784
1785 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1786 (ha->response_q_length + 1) * sizeof(response_t),
1787 &ha->response_dma, GFP_KERNEL);
1788 if (ha->response_ring == NULL) {
1789 qla_printk(KERN_WARNING, ha,
1790 "Memory Allocation failed - response_ring\n");
1791
1792 qla2x00_mem_free(ha);
1793 msleep(100);
1794
1795 continue;
1796 }
1797
1798 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1799 &ha->gid_list_dma, GFP_KERNEL);
1800 if (ha->gid_list == NULL) {
1801 qla_printk(KERN_WARNING, ha,
1802 "Memory Allocation failed - gid_list\n");
1803
1804 qla2x00_mem_free(ha);
1805 msleep(100);
1806
1807 continue;
1808 }
1809
1810 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1811 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1812 if (ha->rlc_rsp == NULL) {
1813 qla_printk(KERN_WARNING, ha,
1814 "Memory Allocation failed - rlc");
1815
1816 qla2x00_mem_free(ha);
1817 msleep(100);
1818
1819 continue;
1820 }
1821
1822 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1823 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1824 DMA_POOL_SIZE, 8, 0);
1825 if (ha->s_dma_pool == NULL) {
1826 qla_printk(KERN_WARNING, ha,
1827 "Memory Allocation failed - s_dma_pool\n");
1828
1829 qla2x00_mem_free(ha);
1830 msleep(100);
1831
1832 continue;
1833 }
1834
1835 /* get consistent memory allocated for init control block */
1836 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1837 &ha->init_cb_dma);
1838 if (ha->init_cb == NULL) {
1839 qla_printk(KERN_WARNING, ha,
1840 "Memory Allocation failed - init_cb\n");
1841
1842 qla2x00_mem_free(ha);
1843 msleep(100);
1844
1845 continue;
1846 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001847 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
1849 /* Get consistent memory allocated for Get Port Database cmd */
1850 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1851 &ha->iodesc_pd_dma);
1852 if (ha->iodesc_pd == NULL) {
1853 /* error */
1854 qla_printk(KERN_WARNING, ha,
1855 "Memory Allocation failed - iodesc_pd\n");
1856
1857 qla2x00_mem_free(ha);
1858 msleep(100);
1859
1860 continue;
1861 }
1862 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1863
1864 /* Allocate ioctl related memory. */
1865 if (qla2x00_alloc_ioctl_mem(ha)) {
1866 qla_printk(KERN_WARNING, ha,
1867 "Memory Allocation failed - ioctl_mem\n");
1868
1869 qla2x00_mem_free(ha);
1870 msleep(100);
1871
1872 continue;
1873 }
1874
1875 if (qla2x00_allocate_sp_pool(ha)) {
1876 qla_printk(KERN_WARNING, ha,
1877 "Memory Allocation failed - "
1878 "qla2x00_allocate_sp_pool()\n");
1879
1880 qla2x00_mem_free(ha);
1881 msleep(100);
1882
1883 continue;
1884 }
1885
1886 /* Allocate memory for SNS commands */
1887 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1888 /* Get consistent memory allocated for SNS commands */
1889 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1890 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1891 GFP_KERNEL);
1892 if (ha->sns_cmd == NULL) {
1893 /* error */
1894 qla_printk(KERN_WARNING, ha,
1895 "Memory Allocation failed - sns_cmd\n");
1896
1897 qla2x00_mem_free(ha);
1898 msleep(100);
1899
1900 continue;
1901 }
1902 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1903 } else {
1904 /* Get consistent memory allocated for MS IOCB */
1905 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1906 &ha->ms_iocb_dma);
1907 if (ha->ms_iocb == NULL) {
1908 /* error */
1909 qla_printk(KERN_WARNING, ha,
1910 "Memory Allocation failed - ms_iocb\n");
1911
1912 qla2x00_mem_free(ha);
1913 msleep(100);
1914
1915 continue;
1916 }
1917 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1918
1919 /*
1920 * Get consistent memory allocated for CT SNS
1921 * commands
1922 */
1923 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1924 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1925 GFP_KERNEL);
1926 if (ha->ct_sns == NULL) {
1927 /* error */
1928 qla_printk(KERN_WARNING, ha,
1929 "Memory Allocation failed - ct_sns\n");
1930
1931 qla2x00_mem_free(ha);
1932 msleep(100);
1933
1934 continue;
1935 }
1936 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1937 }
1938
1939 /* Done all allocations without any error. */
1940 status = 0;
1941
1942 } while (retry-- && status != 0);
1943
1944 if (status) {
1945 printk(KERN_WARNING
1946 "%s(): **** FAILED ****\n", __func__);
1947 }
1948
1949 return(status);
1950}
1951
1952/*
1953* qla2x00_mem_free
1954* Frees all adapter allocated memory.
1955*
1956* Input:
1957* ha = adapter block pointer.
1958*/
1959static void
1960qla2x00_mem_free(scsi_qla_host_t *ha)
1961{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 struct list_head *fcpl, *fcptemp;
1963 fc_port_t *fcport;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001964 unsigned int wtime;/* max wait time if mbx cmd is busy. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
1966 if (ha == NULL) {
1967 /* error */
1968 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1969 return;
1970 }
1971
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 /* Make sure all other threads are stopped. */
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001973 wtime = 60 * 1000;
1974 while (ha->dpc_wait && wtime)
1975 wtime = msleep_interruptible(wtime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977 /* free ioctl memory */
1978 qla2x00_free_ioctl_mem(ha);
1979
1980 /* free sp pool */
1981 qla2x00_free_sp_pool(ha);
1982
1983 if (ha->sns_cmd)
1984 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1985 ha->sns_cmd, ha->sns_cmd_dma);
1986
1987 if (ha->ct_sns)
1988 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1989 ha->ct_sns, ha->ct_sns_dma);
1990
1991 if (ha->ms_iocb)
1992 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1993
1994 if (ha->iodesc_pd)
1995 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1996
1997 if (ha->init_cb)
1998 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1999
2000 if (ha->s_dma_pool)
2001 dma_pool_destroy(ha->s_dma_pool);
2002
2003 if (ha->rlc_rsp)
2004 dma_free_coherent(&ha->pdev->dev,
2005 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2006 ha->rlc_rsp_dma);
2007
2008 if (ha->gid_list)
2009 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2010 ha->gid_list_dma);
2011
2012 if (ha->response_ring)
2013 dma_free_coherent(&ha->pdev->dev,
2014 (ha->response_q_length + 1) * sizeof(response_t),
2015 ha->response_ring, ha->response_dma);
2016
2017 if (ha->request_ring)
2018 dma_free_coherent(&ha->pdev->dev,
2019 (ha->request_q_length + 1) * sizeof(request_t),
2020 ha->request_ring, ha->request_dma);
2021
2022 ha->sns_cmd = NULL;
2023 ha->sns_cmd_dma = 0;
2024 ha->ct_sns = NULL;
2025 ha->ct_sns_dma = 0;
2026 ha->ms_iocb = NULL;
2027 ha->ms_iocb_dma = 0;
2028 ha->iodesc_pd = NULL;
2029 ha->iodesc_pd_dma = 0;
2030 ha->init_cb = NULL;
2031 ha->init_cb_dma = 0;
2032
2033 ha->s_dma_pool = NULL;
2034
2035 ha->rlc_rsp = NULL;
2036 ha->rlc_rsp_dma = 0;
2037 ha->gid_list = NULL;
2038 ha->gid_list_dma = 0;
2039
2040 ha->response_ring = NULL;
2041 ha->response_dma = 0;
2042 ha->request_ring = NULL;
2043 ha->request_dma = 0;
2044
2045 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2046 fcport = list_entry(fcpl, fc_port_t, list);
2047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 /* fc ports */
2049 list_del_init(&fcport->list);
2050 kfree(fcport);
2051 }
2052 INIT_LIST_HEAD(&ha->fcports);
2053
2054 if (ha->fw_dump)
2055 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2056
Andrew Vasquezfca29702005-07-06 10:31:47 -07002057 vfree(ha->fw_dump24);
2058
2059 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002062 ha->fw_dump24 = NULL;
2063 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 ha->fw_dump_reading = 0;
2065 ha->fw_dump_buffer = NULL;
2066}
2067
2068/*
2069 * qla2x00_allocate_sp_pool
2070 * This routine is called during initialization to allocate
2071 * memory for local srb_t.
2072 *
2073 * Input:
2074 * ha = adapter block pointer.
2075 *
2076 * Context:
2077 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002078 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 * Note: Sets the ref_count for non Null sp to one.
2080 */
2081static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002082qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083{
2084 int rval;
2085
2086 rval = QLA_SUCCESS;
2087 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2088 mempool_free_slab, srb_cachep);
2089 if (ha->srb_mempool == NULL) {
2090 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2091 rval = QLA_FUNCTION_FAILED;
2092 }
2093 return (rval);
2094}
2095
2096/*
2097 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002098 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 */
2100static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002101qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
2103 if (ha->srb_mempool) {
2104 mempool_destroy(ha->srb_mempool);
2105 ha->srb_mempool = NULL;
2106 }
2107}
2108
2109/**************************************************************************
2110* qla2x00_do_dpc
2111* This kernel thread is a task that is schedule by the interrupt handler
2112* to perform the background processing for interrupts.
2113*
2114* Notes:
2115* This task always run in the context of a kernel thread. It
2116* is kick-off by the driver's detect code and starts up
2117* up one per adapter. It immediately goes to sleep and waits for
2118* some fibre event. When either the interrupt handler or
2119* the timer routine detects a event it will one of the task
2120* bits then wake us up.
2121**************************************************************************/
2122static int
2123qla2x00_do_dpc(void *data)
2124{
2125 DECLARE_MUTEX_LOCKED(sem);
2126 scsi_qla_host_t *ha;
2127 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
2131 ha = (scsi_qla_host_t *)data;
2132
2133 lock_kernel();
2134
2135 daemonize("%s_dpc", ha->host_str);
2136 allow_signal(SIGHUP);
2137
2138 ha->dpc_wait = &sem;
2139
2140 set_user_nice(current, -20);
2141
2142 unlock_kernel();
2143
2144 complete(&ha->dpc_inited);
2145
2146 while (1) {
2147 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2148
2149 if (down_interruptible(&sem))
2150 break;
2151
2152 if (ha->dpc_should_die)
2153 break;
2154
2155 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2156
2157 /* Initialization not yet finished. Don't do anything yet. */
2158 if (!ha->flags.init_done || ha->dpc_active)
2159 continue;
2160
2161 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2162
2163 ha->dpc_active = 1;
2164
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 ha->dpc_active = 0;
2167 continue;
2168 }
2169
2170 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2171
2172 DEBUG(printk("scsi(%ld): dpc: sched "
2173 "qla2x00_abort_isp ha = %p\n",
2174 ha->host_no, ha));
2175 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2176 &ha->dpc_flags))) {
2177
2178 if (qla2x00_abort_isp(ha)) {
2179 /* failed. retry later */
2180 set_bit(ISP_ABORT_NEEDED,
2181 &ha->dpc_flags);
2182 }
2183 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2184 }
2185 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2186 ha->host_no));
2187 }
2188
2189 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2190 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2191
2192 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2193 ha->host_no));
2194
2195 qla2x00_rst_aen(ha);
2196 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2197 }
2198
2199 /* Retry each device up to login retry count */
2200 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2201 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2202 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2203
2204 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2205 ha->host_no));
2206
2207 next_loopid = 0;
2208 list_for_each_entry(fcport, &ha->fcports, list) {
2209 if (fcport->port_type != FCT_TARGET)
2210 continue;
2211
2212 /*
2213 * If the port is not ONLINE then try to login
2214 * to it if we haven't run out of retries.
2215 */
2216 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2217 fcport->login_retry) {
2218
2219 fcport->login_retry--;
2220 if (fcport->flags & FCF_FABRIC_DEVICE) {
2221 if (fcport->flags &
2222 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002223 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002224 ha, fcport->loop_id,
2225 fcport->d_id.b.domain,
2226 fcport->d_id.b.area,
2227 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 status = qla2x00_fabric_login(
2229 ha, fcport, &next_loopid);
2230 } else
2231 status =
2232 qla2x00_local_device_login(
2233 ha, fcport->loop_id);
2234
2235 if (status == QLA_SUCCESS) {
2236 fcport->old_loop_id = fcport->loop_id;
2237
2238 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2239 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002240
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 fcport->port_login_retry_count =
2242 ha->port_down_retry_count * PORT_RETRY_TIME;
2243 atomic_set(&fcport->state, FCS_ONLINE);
2244 atomic_set(&fcport->port_down_timer,
2245 ha->port_down_retry_count * PORT_RETRY_TIME);
2246
2247 fcport->login_retry = 0;
2248 } else if (status == 1) {
2249 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2250 /* retry the login again */
2251 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2252 ha->host_no,
2253 fcport->login_retry, fcport->loop_id));
2254 } else {
2255 fcport->login_retry = 0;
2256 }
2257 }
2258 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2259 break;
2260 }
2261 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2262 ha->host_no));
2263 }
2264
2265 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2266 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2267
2268 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2269 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2270 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002271
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2273
2274 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2275 ha->host_no));
2276 }
2277
2278 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2279
2280 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2281 ha->host_no));
2282
2283 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2284 &ha->dpc_flags))) {
2285
2286 qla2x00_loop_resync(ha);
2287
2288 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2289 }
2290
2291 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2292 ha->host_no));
2293 }
2294
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2296
2297 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2298 ha->host_no));
2299
2300 qla2x00_rescan_fcports(ha);
2301
2302 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2303 "end.\n",
2304 ha->host_no));
2305 }
2306
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002308 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 ha->dpc_active = 0;
2311 } /* End of while(1) */
2312
2313 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2314
2315 /*
2316 * Make sure that nobody tries to wake us up again.
2317 */
2318 ha->dpc_wait = NULL;
2319 ha->dpc_active = 0;
2320
2321 complete_and_exit(&ha->dpc_exited, 0);
2322}
2323
2324/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325* qla2x00_rst_aen
2326* Processes asynchronous reset.
2327*
2328* Input:
2329* ha = adapter block pointer.
2330*/
2331static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002332qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
2334 if (ha->flags.online && !ha->flags.reset_active &&
2335 !atomic_read(&ha->loop_down_timer) &&
2336 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2337 do {
2338 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2339
2340 /*
2341 * Issue marker command only when we are going to start
2342 * the I/O.
2343 */
2344 ha->marker_needed = 1;
2345 } while (!atomic_read(&ha->loop_down_timer) &&
2346 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2347 }
2348}
2349
f4f051e2005-04-17 15:02:26 -05002350static void
2351qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2352{
2353 struct scsi_cmnd *cmd = sp->cmd;
2354
2355 if (sp->flags & SRB_DMA_VALID) {
2356 if (cmd->use_sg) {
2357 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2358 cmd->use_sg, cmd->sc_data_direction);
2359 } else if (cmd->request_bufflen) {
2360 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2361 cmd->request_bufflen, cmd->sc_data_direction);
2362 }
2363 sp->flags &= ~SRB_DMA_VALID;
2364 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002365 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002366}
2367
2368void
2369qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2370{
2371 struct scsi_cmnd *cmd = sp->cmd;
2372
2373 qla2x00_sp_free_dma(ha, sp);
2374
f4f051e2005-04-17 15:02:26 -05002375 mempool_free(sp, ha->srb_mempool);
2376
2377 cmd->scsi_done(cmd);
2378}
bdf79622005-04-17 15:06:53 -05002379
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380/**************************************************************************
2381* qla2x00_timer
2382*
2383* Description:
2384* One second timer
2385*
2386* Context: Interrupt
2387***************************************************************************/
2388static void
2389qla2x00_timer(scsi_qla_host_t *ha)
2390{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 unsigned long cpu_flags = 0;
2392 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 int start_dpc = 0;
2394 int index;
2395 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002396 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
2398 /*
2399 * Ports - Port down timer.
2400 *
2401 * Whenever, a port is in the LOST state we start decrementing its port
2402 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002403 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 */
2405 t = 0;
2406 list_for_each_entry(fcport, &ha->fcports, list) {
2407 if (fcport->port_type != FCT_TARGET)
2408 continue;
2409
2410 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2411
2412 if (atomic_read(&fcport->port_down_timer) == 0)
2413 continue;
2414
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002415 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002419 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 ha->host_no,
2421 t, atomic_read(&fcport->port_down_timer)));
2422 }
2423 t++;
2424 } /* End of for fcport */
2425
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
2427 /* Loop down handler. */
2428 if (atomic_read(&ha->loop_down_timer) > 0 &&
2429 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2430
2431 if (atomic_read(&ha->loop_down_timer) ==
2432 ha->loop_down_abort_time) {
2433
2434 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2435 "queues before time expire\n",
2436 ha->host_no));
2437
2438 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002439 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
2441 /* Schedule an ISP abort to return any tape commands. */
2442 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2443 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2444 index++) {
bdf79622005-04-17 15:06:53 -05002445 fc_port_t *sfcp;
2446
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 sp = ha->outstanding_cmds[index];
2448 if (!sp)
2449 continue;
bdf79622005-04-17 15:06:53 -05002450 sfcp = sp->fcport;
2451 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 continue;
2453
2454 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2455 break;
2456 }
2457 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2458
2459 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2460 start_dpc++;
2461 }
2462
2463 /* if the loop has been down for 4 minutes, reinit adapter */
2464 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2465 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2466 "restarting queues.\n",
2467 ha->host_no));
2468
2469 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2470 start_dpc++;
2471
2472 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2473 DEBUG(printk("scsi(%ld): Loop down - "
2474 "aborting ISP.\n",
2475 ha->host_no));
2476 qla_printk(KERN_WARNING, ha,
2477 "Loop down - aborting ISP.\n");
2478
2479 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2480 }
2481 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002482 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 ha->host_no,
2484 atomic_read(&ha->loop_down_timer)));
2485 }
2486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 /* Schedule the DPC routine if needed */
2488 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2489 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2490 start_dpc ||
2491 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002492 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2494 ha->dpc_wait && !ha->dpc_active) {
2495
2496 up(ha->dpc_wait);
2497 }
2498
2499 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2500}
2501
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502/* XXX(hch): crude hack to emulate a down_timeout() */
2503int
2504qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2505{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002506 const unsigned int step = 100; /* msecs */
2507 unsigned int iterations = jiffies_to_msecs(timeout)/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509 do {
2510 if (!down_trylock(sema))
2511 return 0;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002512 if (msleep_interruptible(step))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 break;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002514 } while (--iterations >= 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
2516 return -ETIMEDOUT;
2517}
2518
Andrew Vasquezfca29702005-07-06 10:31:47 -07002519static struct qla_board_info qla_board_tbl[] = {
2520 {
2521 .drv_name = "qla2400",
2522 .isp_name = "ISP2422",
2523 .fw_fname = "ql2400_fw.bin",
2524 .sht = &qla24xx_driver_template,
2525 },
2526 {
2527 .drv_name = "qla2400",
2528 .isp_name = "ISP2432",
2529 .fw_fname = "ql2400_fw.bin",
2530 .sht = &qla24xx_driver_template,
2531 },
2532};
2533
2534static struct pci_device_id qla2xxx_pci_tbl[] = {
2535 {
2536 .vendor = PCI_VENDOR_ID_QLOGIC,
2537 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2538 .subvendor = PCI_ANY_ID,
2539 .subdevice = PCI_ANY_ID,
2540 .driver_data = (unsigned long)&qla_board_tbl[0],
2541 },
2542 {
2543 .vendor = PCI_VENDOR_ID_QLOGIC,
2544 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2545 .subvendor = PCI_ANY_ID,
2546 .subdevice = PCI_ANY_ID,
2547 .driver_data = (unsigned long)&qla_board_tbl[1],
2548 },
2549 {0, 0},
2550};
2551MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2552
2553static int __devinit
2554qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2555{
2556 return qla2x00_probe_one(pdev,
2557 (struct qla_board_info *)id->driver_data);
2558}
2559
2560static void __devexit
2561qla2xxx_remove_one(struct pci_dev *pdev)
2562{
2563 qla2x00_remove_one(pdev);
2564}
2565
2566static struct pci_driver qla2xxx_pci_driver = {
2567 .name = "qla2xxx",
2568 .id_table = qla2xxx_pci_tbl,
2569 .probe = qla2xxx_probe_one,
2570 .remove = __devexit_p(qla2xxx_remove_one),
2571};
2572
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573/**
2574 * qla2x00_module_init - Module initialization.
2575 **/
2576static int __init
2577qla2x00_module_init(void)
2578{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002579 int ret = 0;
2580
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002582 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 SLAB_HWCACHE_ALIGN, NULL, NULL);
2584 if (srb_cachep == NULL) {
2585 printk(KERN_ERR
2586 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2587 return -ENOMEM;
2588 }
2589
2590 /* Derive version string. */
2591 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2592#if DEBUG_QLA2100
2593 strcat(qla2x00_version_str, "-debug");
2594#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002595 qla2xxx_transport_template =
2596 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 if (!qla2xxx_transport_template)
2598 return -ENODEV;
2599
2600 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002601 ret = pci_module_init(&qla2xxx_pci_driver);
2602 if (ret) {
2603 kmem_cache_destroy(srb_cachep);
2604 fc_release_transport(qla2xxx_transport_template);
2605 }
2606 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607}
2608
2609/**
2610 * qla2x00_module_exit - Module cleanup.
2611 **/
2612static void __exit
2613qla2x00_module_exit(void)
2614{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002615 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002616 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 fc_release_transport(qla2xxx_transport_template);
2618}
2619
2620module_init(qla2x00_module_init);
2621module_exit(qla2x00_module_exit);
2622
2623MODULE_AUTHOR("QLogic Corporation");
2624MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2625MODULE_LICENSE("GPL");
2626MODULE_VERSION(QLA2XXX_VERSION);