blob: 77054d7692c484e1c926db2118e5b12faf748fda [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070064int ql2xloginretrycount = 0;
65module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
66MODULE_PARM_DESC(ql2xloginretrycount,
67 "Specify an alternate value for the NVRAM login retry count.");
68
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -070069int ql2xfwloadbin=1;
Andrew Vasquezfca29702005-07-06 10:31:47 -070070module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
71MODULE_PARM_DESC(ql2xfwloadbin,
72 "Load ISP2xxx firmware image via hotplug.");
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static void qla2x00_free_device(scsi_qla_host_t *);
75
76static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
77
Andrew Vasquezcca53352005-08-26 19:08:30 -070078int ql2xfdmienable;
79module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
80MODULE_PARM_DESC(ql2xfdmienable,
81 "Enables FDMI registratons "
82 "Default is 0 - no FDMI. 1 - perfom FDMI.");
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070085 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
87static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -050088static int qla2xxx_slave_alloc(struct scsi_device *);
89static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
91 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -070092static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
93 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static int qla2xxx_eh_abort(struct scsi_cmnd *);
95static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
96static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
97static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
98static int qla2x00_loop_reset(scsi_qla_host_t *ha);
99static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
100
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700101static int qla2x00_change_queue_depth(struct scsi_device *, int);
102static int qla2x00_change_queue_type(struct scsi_device *, int);
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static struct scsi_host_template qla2x00_driver_template = {
105 .module = THIS_MODULE,
106 .name = "qla2xxx",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 .queuecommand = qla2x00_queuecommand,
108
109 .eh_abort_handler = qla2xxx_eh_abort,
110 .eh_device_reset_handler = qla2xxx_eh_device_reset,
111 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
112 .eh_host_reset_handler = qla2xxx_eh_host_reset,
113
114 .slave_configure = qla2xxx_slave_configure,
115
f4f051e2005-04-17 15:02:26 -0500116 .slave_alloc = qla2xxx_slave_alloc,
117 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700118 .change_queue_depth = qla2x00_change_queue_depth,
119 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .this_id = -1,
121 .cmd_per_lun = 3,
122 .use_clustering = ENABLE_CLUSTERING,
123 .sg_tablesize = SG_ALL,
124
125 /*
126 * The RISC allows for each command to transfer (2^32-1) bytes of data,
127 * which equates to 0x800000 sectors.
128 */
129 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700130 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Andrew Vasquezfca29702005-07-06 10:31:47 -0700133static struct scsi_host_template qla24xx_driver_template = {
134 .module = THIS_MODULE,
135 .name = "qla2xxx",
136 .queuecommand = qla24xx_queuecommand,
137
138 .eh_abort_handler = qla2xxx_eh_abort,
139 .eh_device_reset_handler = qla2xxx_eh_device_reset,
140 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
141 .eh_host_reset_handler = qla2xxx_eh_host_reset,
142
143 .slave_configure = qla2xxx_slave_configure,
144
145 .slave_alloc = qla2xxx_slave_alloc,
146 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700147 .change_queue_depth = qla2x00_change_queue_depth,
148 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700149 .this_id = -1,
150 .cmd_per_lun = 3,
151 .use_clustering = ENABLE_CLUSTERING,
152 .sg_tablesize = SG_ALL,
153
154 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700155 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700156};
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158static struct scsi_transport_template *qla2xxx_transport_template = NULL;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/* TODO Convert to inlines
161 *
162 * Timer routines
163 */
164#define WATCH_INTERVAL 1 /* number of seconds */
165
166static void qla2x00_timer(scsi_qla_host_t *);
167
168static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
169 void *, unsigned long);
170static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
171static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
172
173static inline void
174qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
175{
176 init_timer(&ha->timer);
177 ha->timer.expires = jiffies + interval * HZ;
178 ha->timer.data = (unsigned long)ha;
179 ha->timer.function = (void (*)(unsigned long))func;
180 add_timer(&ha->timer);
181 ha->timer_active = 1;
182}
183
184static inline void
185qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
186{
187 mod_timer(&ha->timer, jiffies + interval * HZ);
188}
189
190static __inline__ void
191qla2x00_stop_timer(scsi_qla_host_t *ha)
192{
193 del_timer_sync(&ha->timer);
194 ha->timer_active = 0;
195}
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197static int qla2x00_do_dpc(void *data);
198
199static void qla2x00_rst_aen(scsi_qla_host_t *);
200
201static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
202static void qla2x00_mem_free(scsi_qla_host_t *ha);
203static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
204static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500205static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
206void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208/* -------------------------------------------------------------------------- */
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700211qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 static char *pci_bus_modes[] = {
214 "33", "66", "100", "133",
215 };
216 uint16_t pci_bus;
217
218 strcpy(str, "PCI");
219 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
220 if (pci_bus) {
221 strcat(str, "-X (");
222 strcat(str, pci_bus_modes[pci_bus]);
223 } else {
224 pci_bus = (ha->pci_attr & BIT_8) >> 8;
225 strcat(str, " (");
226 strcat(str, pci_bus_modes[pci_bus]);
227 }
228 strcat(str, " MHz)");
229
230 return (str);
231}
232
Andrew Vasquezfca29702005-07-06 10:31:47 -0700233static char *
234qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
235{
236 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
237 uint32_t pci_bus;
238 int pcie_reg;
239
240 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
241 if (pcie_reg) {
242 char lwstr[6];
243 uint16_t pcie_lstat, lspeed, lwidth;
244
245 pcie_reg += 0x12;
246 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
247 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
248 lwidth = (pcie_lstat &
249 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
250
251 strcpy(str, "PCIe (");
252 if (lspeed == 1)
253 strcat(str, "2.5Gb/s ");
254 else
255 strcat(str, "<unknown> ");
256 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
257 strcat(str, lwstr);
258
259 return str;
260 }
261
262 strcpy(str, "PCI");
263 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
264 if (pci_bus == 0 || pci_bus == 8) {
265 strcat(str, " (");
266 strcat(str, pci_bus_modes[pci_bus >> 3]);
267 } else {
268 strcat(str, "-X ");
269 if (pci_bus & BIT_2)
270 strcat(str, "Mode 2");
271 else
272 strcat(str, "Mode 1");
273 strcat(str, " (");
274 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
275 }
276 strcat(str, " MHz)");
277
278 return str;
279}
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700282qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
287 ha->fw_minor_version,
288 ha->fw_subminor_version);
289
290 if (ha->fw_attributes & BIT_9) {
291 strcat(str, "FLX");
292 return (str);
293 }
294
295 switch (ha->fw_attributes & 0xFF) {
296 case 0x7:
297 strcat(str, "EF");
298 break;
299 case 0x17:
300 strcat(str, "TP");
301 break;
302 case 0x37:
303 strcat(str, "IP");
304 break;
305 case 0x77:
306 strcat(str, "VI");
307 break;
308 default:
309 sprintf(un_str, "(%x)", ha->fw_attributes);
310 strcat(str, un_str);
311 break;
312 }
313 if (ha->fw_attributes & 0x100)
314 strcat(str, "X");
315
316 return (str);
317}
318
Andrew Vasquezfca29702005-07-06 10:31:47 -0700319char *
320qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
321{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700322 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
323 ha->fw_minor_version,
324 ha->fw_subminor_version);
325
Andrew Vasquezfca29702005-07-06 10:31:47 -0700326 if (ha->fw_attributes & BIT_0)
327 strcat(str, "[Class 2] ");
328 if (ha->fw_attributes & BIT_1)
329 strcat(str, "[IP] ");
330 if (ha->fw_attributes & BIT_2)
331 strcat(str, "[Multi-ID] ");
332 if (ha->fw_attributes & BIT_13)
333 strcat(str, "[Experimental]");
334 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700335}
336
337static inline srb_t *
338qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
339 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
340{
341 srb_t *sp;
342
343 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
344 if (!sp)
345 return sp;
346
347 atomic_set(&sp->ref_count, 1);
348 sp->ha = ha;
349 sp->fcport = fcport;
350 sp->cmd = cmd;
351 sp->flags = 0;
352 CMD_SP(cmd) = (void *)sp;
353 cmd->scsi_done = done;
354
355 return sp;
356}
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358static int
f4f051e2005-04-17 15:02:26 -0500359qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
f4f051e2005-04-17 15:02:26 -0500361 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500362 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500363 srb_t *sp;
364 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
bdf79622005-04-17 15:06:53 -0500366 if (!fcport) {
f4f051e2005-04-17 15:02:26 -0500367 cmd->result = DID_NO_CONNECT << 16;
368 goto qc_fail_command;
369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
f4f051e2005-04-17 15:02:26 -0500371 if (atomic_read(&fcport->state) != FCS_ONLINE) {
372 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
373 atomic_read(&ha->loop_state) == LOOP_DEAD) {
374 cmd->result = DID_NO_CONNECT << 16;
375 goto qc_fail_command;
376 }
377 goto qc_host_busy;
378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 spin_unlock_irq(ha->host->host_lock);
381
Andrew Vasquezfca29702005-07-06 10:31:47 -0700382 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
383 if (!sp)
f4f051e2005-04-17 15:02:26 -0500384 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
f4f051e2005-04-17 15:02:26 -0500386 rval = qla2x00_start_scsi(sp);
387 if (rval != QLA_SUCCESS)
388 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 spin_lock_irq(ha->host->host_lock);
391
f4f051e2005-04-17 15:02:26 -0500392 return 0;
393
394qc_host_busy_free_sp:
395 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500396 mempool_free(sp, ha->srb_mempool);
397
398qc_host_busy_lock:
399 spin_lock_irq(ha->host->host_lock);
400
401qc_host_busy:
402 return SCSI_MLQUEUE_HOST_BUSY;
403
404qc_fail_command:
405 done(cmd);
406
407 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Andrew Vasquezfca29702005-07-06 10:31:47 -0700410
411static int
412qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
413{
414 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
415 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
416 srb_t *sp;
417 int rval;
418
419 if (!fcport) {
420 cmd->result = DID_NO_CONNECT << 16;
421 goto qc24_fail_command;
422 }
423
424 if (atomic_read(&fcport->state) != FCS_ONLINE) {
425 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
426 atomic_read(&ha->loop_state) == LOOP_DEAD) {
427 cmd->result = DID_NO_CONNECT << 16;
428 goto qc24_fail_command;
429 }
430 goto qc24_host_busy;
431 }
432
433 spin_unlock_irq(ha->host->host_lock);
434
435 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
436 if (!sp)
437 goto qc24_host_busy_lock;
438
439 rval = qla24xx_start_scsi(sp);
440 if (rval != QLA_SUCCESS)
441 goto qc24_host_busy_free_sp;
442
443 spin_lock_irq(ha->host->host_lock);
444
445 return 0;
446
447qc24_host_busy_free_sp:
448 qla2x00_sp_free_dma(ha, sp);
449 mempool_free(sp, ha->srb_mempool);
450
451qc24_host_busy_lock:
452 spin_lock_irq(ha->host->host_lock);
453
454qc24_host_busy:
455 return SCSI_MLQUEUE_HOST_BUSY;
456
457qc24_fail_command:
458 done(cmd);
459
460 return 0;
461}
462
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/*
465 * qla2x00_eh_wait_on_command
466 * Waits for the command to be returned by the Firmware for some
467 * max time.
468 *
469 * Input:
470 * ha = actual ha whose done queue will contain the command
471 * returned by firmware.
472 * cmd = Scsi Command to wait on.
473 * flag = Abort/Reset(Bus or Device Reset)
474 *
475 * Return:
476 * Not Found : 0
477 * Found : 1
478 */
479static int
480qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
481{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700482#define ABORT_POLLING_PERIOD 1000
483#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500484 unsigned long wait_iter = ABORT_WAIT_ITER;
485 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
f4f051e2005-04-17 15:02:26 -0500487 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700488 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
f4f051e2005-04-17 15:02:26 -0500490 if (--wait_iter)
491 break;
492 }
493 if (CMD_SP(cmd))
494 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
f4f051e2005-04-17 15:02:26 -0500496 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499/*
500 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700501 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 * <= MAX_RETRIES_OF_ISP_ABORT or
503 * finally HBA is disabled ie marked offline
504 *
505 * Input:
506 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700507 *
508 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 * Does context switching-Release SPIN_LOCK
510 * (if any) before calling this routine.
511 *
512 * Return:
513 * Success (Adapter is online) : 0
514 * Failed (Adapter is offline/disabled) : 1
515 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700516static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
518{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700519 int return_status;
520 unsigned long wait_online;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700522 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
524 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
525 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
526 ha->dpc_active) && time_before(jiffies, wait_online)) {
527
528 msleep(1000);
529 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700530 if (ha->flags.online)
531 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 else
533 return_status = QLA_FUNCTION_FAILED;
534
535 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
536
537 return (return_status);
538}
539
540/*
541 * qla2x00_wait_for_loop_ready
542 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700543 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 * Input:
545 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700546 *
547 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 * Does context switching-Release SPIN_LOCK
549 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700550 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 *
552 * Return:
553 * Success (LOOP_READY) : 0
554 * Failed (LOOP_NOT_READY) : 1
555 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700556static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
558{
559 int return_status = QLA_SUCCESS;
560 unsigned long loop_timeout ;
561
562 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700563 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 while ((!atomic_read(&ha->loop_down_timer) &&
566 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 atomic_read(&ha->loop_state) != LOOP_READY) {
568 msleep(1000);
569 if (time_after_eq(jiffies, loop_timeout)) {
570 return_status = QLA_FUNCTION_FAILED;
571 break;
572 }
573 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700574 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
577/**************************************************************************
578* qla2xxx_eh_abort
579*
580* Description:
581* The abort function will abort the specified command.
582*
583* Input:
584* cmd = Linux SCSI command packet to be aborted.
585*
586* Returns:
587* Either SUCCESS or FAILED.
588*
589* Note:
590**************************************************************************/
591int
592qla2xxx_eh_abort(struct scsi_cmnd *cmd)
593{
f4f051e2005-04-17 15:02:26 -0500594 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
595 srb_t *sp;
596 int ret, i;
597 unsigned int id, lun;
598 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700599 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
f4f051e2005-04-17 15:02:26 -0500601 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
f4f051e2005-04-17 15:02:26 -0500604 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
f4f051e2005-04-17 15:02:26 -0500606 id = cmd->device->id;
607 lun = cmd->device->lun;
608 serial = cmd->serial_number;
609
610 /* Check active list for command command. */
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700611 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500612 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
613 sp = ha->outstanding_cmds[i];
614
615 if (sp == NULL)
616 continue;
617
618 if (sp->cmd != cmd)
619 continue;
620
621 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
622 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
623 sp->state));
624 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
625
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700626 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700627 if (ha->isp_ops.abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500628 DEBUG2(printk("%s(%ld): abort_command "
629 "mbx failed.\n", __func__, ha->host_no));
630 } else {
631 DEBUG3(printk("%s(%ld): abort_command "
632 "mbx success.\n", __func__, ha->host_no));
633 ret = SUCCESS;
634 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700635 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500636
637 break;
638 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700639 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500640
641 /* Wait for the command to be returned. */
642 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500643 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700644 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500645 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
646 "%x.\n", ha->host_no, id, lun, serial, ret);
647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700650 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500651 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
652 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
f4f051e2005-04-17 15:02:26 -0500654 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657/**************************************************************************
658* qla2x00_eh_wait_for_pending_target_commands
659*
660* Description:
661* Waits for all the commands to come back from the specified target.
662*
663* Input:
664* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700665* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666* Returns:
667* Either SUCCESS or FAILED.
668*
669* Note:
670**************************************************************************/
671static int
672qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
673{
674 int cnt;
675 int status;
676 srb_t *sp;
677 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700678 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 status = 0;
681
682 /*
683 * Waiting for all commands for the designated target in the active
684 * array
685 */
686 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700687 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 sp = ha->outstanding_cmds[cnt];
689 if (sp) {
690 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700691 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (cmd->device->id == t) {
693 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
694 status = 1;
695 break;
696 }
697 }
f4f051e2005-04-17 15:02:26 -0500698 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700699 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 }
702 return (status);
703}
704
705
706/**************************************************************************
707* qla2xxx_eh_device_reset
708*
709* Description:
710* The device reset function will reset the target and abort any
711* executing commands.
712*
713* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700714* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715* non-null.
716*
717* Input:
718* cmd = Linux SCSI command packet of the command that cause the
719* bus device reset.
720*
721* Returns:
722* SUCCESS/FAILURE (defined as macro in scsi.h).
723*
724**************************************************************************/
725int
726qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
727{
f4f051e2005-04-17 15:02:26 -0500728 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500729 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500730 srb_t *sp;
731 int ret;
732 unsigned int id, lun;
733 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
f4f051e2005-04-17 15:02:26 -0500735 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
f4f051e2005-04-17 15:02:26 -0500737 id = cmd->device->id;
738 lun = cmd->device->lun;
739 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
f4f051e2005-04-17 15:02:26 -0500741 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500742 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500743 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500746 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400748 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500752 if (qla2x00_device_reset(ha, fcport) == 0)
753 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500756 if (ret == SUCCESS) {
757 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700758 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
f4f051e2005-04-17 15:02:26 -0500759 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761 }
762#endif
763 } else {
764 DEBUG2(printk(KERN_INFO
765 "%s failed: loop not ready\n",__func__);)
766 }
767
f4f051e2005-04-17 15:02:26 -0500768 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 DEBUG3(printk("%s(%ld): device reset failed\n",
770 __func__, ha->host_no));
771 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
772 __func__);
773
774 goto eh_dev_reset_done;
775 }
776
777 /*
778 * If we are coming down the EH path, wait for all commands to
779 * complete for the device.
780 */
781 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500782 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
783 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
f4f051e2005-04-17 15:02:26 -0500785 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 DEBUG3(printk("%s(%ld): failed while waiting for "
787 "commands\n", __func__, ha->host_no));
788 qla_printk(KERN_INFO, ha,
789 "%s: failed while waiting for commands\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700790 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 goto eh_dev_reset_done;
793 }
794 }
795
796 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500797 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500800 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
803/**************************************************************************
804* qla2x00_eh_wait_for_pending_commands
805*
806* Description:
807* Waits for all the commands to come back from the specified host.
808*
809* Input:
810* ha - pointer to scsi_qla_host structure.
811*
812* Returns:
813* 1 : SUCCESS
814* 0 : FAILED
815*
816* Note:
817**************************************************************************/
818static int
819qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
820{
821 int cnt;
822 int status;
823 srb_t *sp;
824 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700825 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 status = 1;
828
829 /*
830 * Waiting for all commands for the designated target in the active
831 * array
832 */
833 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700834 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 sp = ha->outstanding_cmds[cnt];
836 if (sp) {
837 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700838 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 status = qla2x00_eh_wait_on_command(ha, cmd);
840 if (status == 0)
841 break;
842 }
843 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700844 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
846 }
847 return (status);
848}
849
850
851/**************************************************************************
852* qla2xxx_eh_bus_reset
853*
854* Description:
855* The bus reset function will reset the bus and abort any executing
856* commands.
857*
858* Input:
859* cmd = Linux SCSI command packet of the command that cause the
860* bus reset.
861*
862* Returns:
863* SUCCESS/FAILURE (defined as macro in scsi.h).
864*
865**************************************************************************/
866int
867qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
868{
f4f051e2005-04-17 15:02:26 -0500869 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500870 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500872 int ret;
873 unsigned int id, lun;
874 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
f4f051e2005-04-17 15:02:26 -0500876 ret = FAILED;
877
878 id = cmd->device->id;
879 lun = cmd->device->lun;
880 serial = cmd->serial_number;
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500883 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500884 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500887 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
890 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500891 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893
894 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500895 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
896 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
f4f051e2005-04-17 15:02:26 -0500898 if (ret == FAILED)
899 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 /* Waiting for our command in done_queue to be returned to OS.*/
902 if (cmd->device->host->eh_active)
903 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500904 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
f4f051e2005-04-17 15:02:26 -0500906eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500908 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
f4f051e2005-04-17 15:02:26 -0500910 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911}
912
913/**************************************************************************
914* qla2xxx_eh_host_reset
915*
916* Description:
917* The reset function will reset the Adapter.
918*
919* Input:
920* cmd = Linux SCSI command packet of the command that cause the
921* adapter reset.
922*
923* Returns:
924* Either SUCCESS or FAILED.
925*
926* Note:
927**************************************************************************/
928int
929qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
930{
f4f051e2005-04-17 15:02:26 -0500931 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500932 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500933 srb_t *sp;
934 int ret;
935 unsigned int id, lun;
936 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
f4f051e2005-04-17 15:02:26 -0500938 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
f4f051e2005-04-17 15:02:26 -0500940 id = cmd->device->id;
941 lun = cmd->device->lun;
942 serial = cmd->serial_number;
943
944 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500945 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500946 return ret;
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500949 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500952 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 /*
955 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700956 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 * be completed and then issue big hammer.Otherwise
958 * it may cause I/O failure as big hammer marks the
959 * devices as lost kicking of the port_down_timer
960 * while dpc is stuck for the mailbox to complete.
961 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 qla2x00_wait_for_loop_ready(ha);
963 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
964 if (qla2x00_abort_isp(ha)) {
965 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
966 /* failed. schedule dpc to try */
967 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
968
969 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500970 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500975 if (qla2x00_eh_wait_for_pending_commands(ha))
976 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
f4f051e2005-04-17 15:02:26 -0500978eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -0500979 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
980 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
f4f051e2005-04-17 15:02:26 -0500982 return ret;
983}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985/*
986* qla2x00_loop_reset
987* Issue loop reset.
988*
989* Input:
990* ha = adapter block pointer.
991*
992* Returns:
993* 0 = success
994*/
995static int
996qla2x00_loop_reset(scsi_qla_host_t *ha)
997{
998 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -0500999 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 if (ha->flags.enable_lip_reset) {
1002 status = qla2x00_lip_reset(ha);
1003 }
1004
1005 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001006 list_for_each_entry(fcport, &ha->fcports, list) {
1007 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 continue;
1009
Andrew Vasquezc00c72a2005-08-26 19:08:50 -07001010 status = qla2x00_device_reset(ha, fcport);
bdf79622005-04-17 15:06:53 -05001011 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 }
1014 }
1015
1016 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001017 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 !ha->flags.enable_lip_reset) ||
1019 ha->flags.enable_lip_full_login)) {
1020
1021 status = qla2x00_full_login_lip(ha);
1022 }
1023
1024 /* Issue marker command only when we are going to start the I/O */
1025 ha->marker_needed = 1;
1026
1027 if (status) {
1028 /* Empty */
1029 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1030 __func__,
1031 ha->host_no);)
1032 } else {
1033 /* Empty */
1034 DEBUG3(printk("%s(%ld): exiting normally.\n",
1035 __func__,
1036 ha->host_no);)
1037 }
1038
1039 return(status);
1040}
1041
1042/*
1043 * qla2x00_device_reset
1044 * Issue bus device reset message to the target.
1045 *
1046 * Input:
1047 * ha = adapter block pointer.
1048 * t = SCSI ID.
1049 * TARGET_QUEUE_LOCK must be released.
1050 * ADAPTER_STATE_LOCK must be released.
1051 *
1052 * Context:
1053 * Kernel context.
1054 */
1055static int
1056qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1057{
1058 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001059 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
f4f051e2005-04-17 15:02:26 -05001062static int
1063qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
bdf79622005-04-17 15:06:53 -05001065 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
bdf79622005-04-17 15:06:53 -05001067 if (!rport)
f4f051e2005-04-17 15:02:26 -05001068 return -ENXIO;
1069
Andrew Vasquez77d74142005-07-08 18:00:36 -07001070 sdev->hostdata = rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001071
1072 return 0;
1073}
1074
1075static int
1076qla2xxx_slave_configure(struct scsi_device *sdev)
1077{
8482e1182005-04-17 15:04:54 -05001078 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1079 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1080
f4f051e2005-04-17 15:02:26 -05001081 if (sdev->tagged_supported)
1082 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 else
f4f051e2005-04-17 15:02:26 -05001084 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
8482e1182005-04-17 15:04:54 -05001086 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1087
f4f051e2005-04-17 15:02:26 -05001088 return 0;
1089}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
f4f051e2005-04-17 15:02:26 -05001091static void
1092qla2xxx_slave_destroy(struct scsi_device *sdev)
1093{
1094 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001097static int
1098qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1099{
1100 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1101 return sdev->queue_depth;
1102}
1103
1104static int
1105qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1106{
1107 if (sdev->tagged_supported) {
1108 scsi_set_tag_type(sdev, tag_type);
1109 if (tag_type)
1110 scsi_activate_tcq(sdev, sdev->queue_depth);
1111 else
1112 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1113 } else
1114 tag_type = 0;
1115
1116 return tag_type;
1117}
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119/**
1120 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1121 * @ha: HA context
1122 *
1123 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1124 * supported addressing method.
1125 */
1126static void
1127qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1128{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001129 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001132 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1133 /* Any upper-dword bits set? */
1134 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1135 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1136 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001138 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1139 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001140 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001143
1144 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1145 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
1148static int
1149qla2x00_iospace_config(scsi_qla_host_t *ha)
1150{
1151 unsigned long pio, pio_len, pio_flags;
1152 unsigned long mmio, mmio_len, mmio_flags;
1153
1154 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1155 pio = pci_resource_start(ha->pdev, 0);
1156 pio_len = pci_resource_len(ha->pdev, 0);
1157 pio_flags = pci_resource_flags(ha->pdev, 0);
1158 if (pio_flags & IORESOURCE_IO) {
1159 if (pio_len < MIN_IOBASE_LEN) {
1160 qla_printk(KERN_WARNING, ha,
1161 "Invalid PCI I/O region size (%s)...\n",
1162 pci_name(ha->pdev));
1163 pio = 0;
1164 }
1165 } else {
1166 qla_printk(KERN_WARNING, ha,
1167 "region #0 not a PIO resource (%s)...\n",
1168 pci_name(ha->pdev));
1169 pio = 0;
1170 }
1171
1172 /* Use MMIO operations for all accesses. */
1173 mmio = pci_resource_start(ha->pdev, 1);
1174 mmio_len = pci_resource_len(ha->pdev, 1);
1175 mmio_flags = pci_resource_flags(ha->pdev, 1);
1176
1177 if (!(mmio_flags & IORESOURCE_MEM)) {
1178 qla_printk(KERN_ERR, ha,
1179 "region #0 not an MMIO resource (%s), aborting\n",
1180 pci_name(ha->pdev));
1181 goto iospace_error_exit;
1182 }
1183 if (mmio_len < MIN_IOBASE_LEN) {
1184 qla_printk(KERN_ERR, ha,
1185 "Invalid PCI mem region size (%s), aborting\n",
1186 pci_name(ha->pdev));
1187 goto iospace_error_exit;
1188 }
1189
1190 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1191 qla_printk(KERN_WARNING, ha,
1192 "Failed to reserve PIO/MMIO regions (%s)\n",
1193 pci_name(ha->pdev));
1194
1195 goto iospace_error_exit;
1196 }
1197
1198 ha->pio_address = pio;
1199 ha->pio_length = pio_len;
1200 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1201 if (!ha->iobase) {
1202 qla_printk(KERN_ERR, ha,
1203 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1204
1205 goto iospace_error_exit;
1206 }
1207
1208 return (0);
1209
1210iospace_error_exit:
1211 return (-ENOMEM);
1212}
1213
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001214static void
1215qla2x00_enable_intrs(scsi_qla_host_t *ha)
1216{
1217 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001218 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001219
1220 spin_lock_irqsave(&ha->hardware_lock, flags);
1221 ha->interrupts_on = 1;
1222 /* enable risc and host interrupts */
1223 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1224 RD_REG_WORD(&reg->ictrl);
1225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1226
1227}
1228
1229static void
1230qla2x00_disable_intrs(scsi_qla_host_t *ha)
1231{
1232 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001233 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001234
1235 spin_lock_irqsave(&ha->hardware_lock, flags);
1236 ha->interrupts_on = 0;
1237 /* disable risc and host interrupts */
1238 WRT_REG_WORD(&reg->ictrl, 0);
1239 RD_REG_WORD(&reg->ictrl);
1240 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1241}
1242
Andrew Vasquezfca29702005-07-06 10:31:47 -07001243static void
1244qla24xx_enable_intrs(scsi_qla_host_t *ha)
1245{
1246 unsigned long flags = 0;
1247 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1248
1249 spin_lock_irqsave(&ha->hardware_lock, flags);
1250 ha->interrupts_on = 1;
1251 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1252 RD_REG_DWORD(&reg->ictrl);
1253 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1254}
1255
1256static void
1257qla24xx_disable_intrs(scsi_qla_host_t *ha)
1258{
1259 unsigned long flags = 0;
1260 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1261
1262 spin_lock_irqsave(&ha->hardware_lock, flags);
1263 ha->interrupts_on = 0;
1264 WRT_REG_DWORD(&reg->ictrl, 0);
1265 RD_REG_DWORD(&reg->ictrl);
1266 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1267}
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269/*
1270 * PCI driver interface
1271 */
1272int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1273{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001274 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001275 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 struct Scsi_Host *host;
1277 scsi_qla_host_t *ha;
1278 unsigned long flags = 0;
1279 unsigned long wait_switch = 0;
1280 char pci_info[20];
1281 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001282 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001285 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Andrew Vasquezfca29702005-07-06 10:31:47 -07001287 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1288 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 if (host == NULL) {
1290 printk(KERN_WARNING
1291 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1292 goto probe_disable_device;
1293 }
1294
1295 /* Clear our data area */
1296 ha = (scsi_qla_host_t *)host->hostdata;
1297 memset(ha, 0, sizeof(scsi_qla_host_t));
1298
1299 ha->pdev = pdev;
1300 ha->host = host;
1301 ha->host_no = host->host_no;
1302 ha->brd_info = brd_info;
1303 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1304
Andrew Morton444d1d92005-10-25 11:00:56 -07001305 ha->dpc_pid = -1;
1306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 /* Configure PCI I/O space */
1308 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001309 if (ret)
1310 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 qla_printk(KERN_INFO, ha,
1313 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001314 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 spin_lock_init(&ha->hardware_lock);
1317
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 ha->prev_topology = 0;
1319 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001320 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001321 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001323 /* Assign ISP specific operations. */
1324 ha->isp_ops.pci_config = qla2100_pci_config;
1325 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1326 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1327 ha->isp_ops.config_rings = qla2x00_config_rings;
1328 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1329 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1330 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001331 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001332 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1333 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1334 ha->isp_ops.intr_handler = qla2100_intr_handler;
1335 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1336 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1337 ha->isp_ops.abort_command = qla2x00_abort_command;
1338 ha->isp_ops.abort_target = qla2x00_abort_target;
1339 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1340 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1341 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1342 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1343 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001344 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001345 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1346 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001347 ha->isp_ops.fw_dump = qla2100_fw_dump;
1348 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001350 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1352 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1353 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1354 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1355 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001356 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001358 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1360 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1361 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1362 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001363 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001364 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001365 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1367 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1368 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1369 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001370 ha->isp_ops.pci_config = qla2300_pci_config;
1371 ha->isp_ops.intr_handler = qla2300_intr_handler;
1372 ha->isp_ops.fw_dump = qla2300_fw_dump;
1373 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1374 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001375 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1376 host->max_id = MAX_TARGETS_2200;
1377 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1378 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1379 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1380 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1381 ha->init_cb_size = sizeof(struct init_cb_24xx);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001382 ha->mgmt_svr_loop_id = 10;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001383 ha->isp_ops.pci_config = qla24xx_pci_config;
1384 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1385 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1386 ha->isp_ops.config_rings = qla24xx_config_rings;
1387 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1388 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1389 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1390 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1391 if (ql2xfwloadbin)
1392 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1393 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1394 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1395 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1396 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1397 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1398 ha->isp_ops.abort_command = qla24xx_abort_command;
1399 ha->isp_ops.abort_target = qla24xx_abort_target;
1400 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1401 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1402 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001403 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001404 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1405 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1406 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1407 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1408 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 }
1410 host->can_queue = ha->request_q_length + 128;
1411
1412 /* load the F/W, read paramaters, and init the H/W */
1413 ha->instance = num_hosts;
1414
1415 init_MUTEX(&ha->mbx_cmd_sem);
1416 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1417
1418 INIT_LIST_HEAD(&ha->list);
1419 INIT_LIST_HEAD(&ha->fcports);
1420 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 /*
1423 * These locks are used to prevent more than one CPU
1424 * from modifying the queue at the same time. The
1425 * higher level "host_lock" will reduce most
1426 * contention for these locks.
1427 */
1428 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 init_completion(&ha->dpc_inited);
1431 init_completion(&ha->dpc_exited);
1432
1433 qla2x00_config_dma_addressing(ha);
1434 if (qla2x00_mem_alloc(ha)) {
1435 qla_printk(KERN_WARNING, ha,
1436 "[ERROR] Failed to allocate memory for adapter\n");
1437
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001438 ret = -ENOMEM;
1439 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441
1442 if (qla2x00_initialize_adapter(ha) &&
1443 !(ha->device_flags & DFLG_NO_CABLE)) {
1444
1445 qla_printk(KERN_WARNING, ha,
1446 "Failed to initialize adapter\n");
1447
1448 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1449 "Adapter flags %x.\n",
1450 ha->host_no, ha->device_flags));
1451
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001452 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 goto probe_failed;
1454 }
1455
1456 /*
1457 * Startup the kernel thread for this host adapter
1458 */
1459 ha->dpc_should_die = 0;
1460 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1461 if (ha->dpc_pid < 0) {
1462 qla_printk(KERN_WARNING, ha,
1463 "Unable to start DPC thread!\n");
1464
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001465 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 goto probe_failed;
1467 }
1468 wait_for_completion(&ha->dpc_inited);
1469
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001470 host->this_id = 255;
1471 host->cmd_per_lun = 3;
1472 host->unique_id = ha->instance;
1473 host->max_cmd_len = MAX_CMDSZ;
1474 host->max_channel = ha->ports - 1;
1475 host->max_lun = MAX_LUNS;
1476 host->transportt = qla2xxx_transport_template;
1477
Andrew Vasquezfca29702005-07-06 10:31:47 -07001478 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001479 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001480 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 qla_printk(KERN_WARNING, ha,
1482 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001483 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 goto probe_failed;
1485 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001486 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 /* Initialized the timer */
1489 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1490
1491 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1492 ha->host_no, ha));
1493
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001494 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001497 reg = ha->iobase;
1498 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1499 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1500 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1501 } else {
1502 WRT_REG_WORD(&reg->isp.semaphore, 0);
1503 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1504 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Andrew Vasquezfca29702005-07-06 10:31:47 -07001506 /* Enable proper parity */
1507 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1508 if (IS_QLA2300(ha))
1509 /* SRAM parity */
1510 WRT_REG_WORD(&reg->isp.hccr,
1511 (HCCR_ENABLE_PARITY + 0x1));
1512 else
1513 /* SRAM, Instruction RAM and GP RAM parity */
1514 WRT_REG_WORD(&reg->isp.hccr,
1515 (HCCR_ENABLE_PARITY + 0x7));
1516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 }
1518 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1519
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001520 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522 /* v2.19.5b6 */
1523 /*
1524 * Wait around max loop_reset_delay secs for the devices to come
1525 * on-line. We don't want Linux scanning before we are ready.
1526 *
1527 */
1528 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1529 time_before(jiffies,wait_switch) &&
1530 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1531 && (ha->device_flags & SWITCH_FOUND) ;) {
1532
1533 qla2x00_check_fabric_devices(ha);
1534
1535 msleep(10);
1536 }
1537
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001538 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 ha->flags.init_done = 1;
1540 num_hosts++;
1541
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001542 ret = scsi_add_host(host, &pdev->dev);
1543 if (ret)
1544 goto probe_failed;
1545
1546 qla2x00_alloc_sysfs_attr(ha);
1547
1548 qla2x00_init_host_attr(ha);
1549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 qla_printk(KERN_INFO, ha, "\n"
1551 " QLogic Fibre Channel HBA Driver: %s\n"
1552 " QLogic %s - %s\n"
1553 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1554 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001555 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001556 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001557 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
8482e1182005-04-17 15:04:54 -05001559 /* Go with fc_rport registration. */
1560 list_for_each_entry(fcport, &ha->fcports, list)
1561 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 return 0;
1564
1565probe_failed:
1566 qla2x00_free_device(ha);
1567
1568 scsi_host_put(host);
1569
1570probe_disable_device:
1571 pci_disable_device(pdev);
1572
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001573probe_out:
1574 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1577
1578void qla2x00_remove_one(struct pci_dev *pdev)
1579{
1580 scsi_qla_host_t *ha;
1581
1582 ha = pci_get_drvdata(pdev);
1583
8482e1182005-04-17 15:04:54 -05001584 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
bdf79622005-04-17 15:06:53 -05001586 fc_remove_host(ha->host);
1587
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 scsi_remove_host(ha->host);
1589
1590 qla2x00_free_device(ha);
1591
1592 scsi_host_put(ha->host);
1593
1594 pci_set_drvdata(pdev, NULL);
1595}
1596EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1597
1598static void
1599qla2x00_free_device(scsi_qla_host_t *ha)
1600{
1601 int ret;
1602
1603 /* Abort any outstanding IO descriptors. */
1604 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1605 qla2x00_cancel_io_descriptors(ha);
1606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 /* Disable timer */
1608 if (ha->timer_active)
1609 qla2x00_stop_timer(ha);
1610
1611 /* Kill the kernel thread for this host */
1612 if (ha->dpc_pid >= 0) {
1613 ha->dpc_should_die = 1;
1614 wmb();
1615 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1616 if (ret) {
1617 qla_printk(KERN_ERR, ha,
1618 "Unable to signal DPC thread -- (%d)\n", ret);
1619
1620 /* TODO: SOMETHING MORE??? */
1621 } else {
1622 wait_for_completion(&ha->dpc_exited);
1623 }
1624 }
1625
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001626 /* Stop currently executing firmware. */
1627 qla2x00_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001629 /* turn-off interrupts on the card */
1630 if (ha->interrupts_on)
1631 ha->isp_ops.disable_intrs(ha);
1632
1633 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635 ha->flags.online = 0;
1636
1637 /* Detach interrupts */
1638 if (ha->pdev->irq)
1639 free_irq(ha->pdev->irq, ha);
1640
1641 /* release io space registers */
1642 if (ha->iobase)
1643 iounmap(ha->iobase);
1644 pci_release_regions(ha->pdev);
1645
1646 pci_disable_device(ha->pdev);
1647}
1648
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1651 *
1652 * Input: ha = adapter block pointer. fcport = port structure pointer.
1653 *
1654 * Return: None.
1655 *
1656 * Context:
1657 */
1658void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1659 int do_login)
1660{
8482e1182005-04-17 15:04:54 -05001661 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1662 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001663 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 * We may need to retry the login, so don't change the state of the
1665 * port but do the retries.
1666 */
1667 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1668 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1669
1670 if (!do_login)
1671 return;
1672
1673 if (fcport->login_retry == 0) {
1674 fcport->login_retry = ha->login_retry_count;
1675 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1676
1677 DEBUG(printk("scsi(%ld): Port login retry: "
1678 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1679 "id = 0x%04x retry cnt=%d\n",
1680 ha->host_no,
1681 fcport->port_name[0],
1682 fcport->port_name[1],
1683 fcport->port_name[2],
1684 fcport->port_name[3],
1685 fcport->port_name[4],
1686 fcport->port_name[5],
1687 fcport->port_name[6],
1688 fcport->port_name[7],
1689 fcport->loop_id,
1690 fcport->login_retry));
1691 }
1692}
1693
1694/*
1695 * qla2x00_mark_all_devices_lost
1696 * Updates fcport state when device goes offline.
1697 *
1698 * Input:
1699 * ha = adapter block pointer.
1700 * fcport = port structure pointer.
1701 *
1702 * Return:
1703 * None.
1704 *
1705 * Context:
1706 */
1707void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001708qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
1710 fc_port_t *fcport;
1711
1712 list_for_each_entry(fcport, &ha->fcports, list) {
1713 if (fcport->port_type != FCT_TARGET)
1714 continue;
1715
1716 /*
1717 * No point in marking the device as lost, if the device is
1718 * already DEAD.
1719 */
1720 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1721 continue;
8482e1182005-04-17 15:04:54 -05001722 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1723 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1725 }
1726}
1727
1728/*
1729* qla2x00_mem_alloc
1730* Allocates adapter memory.
1731*
1732* Returns:
1733* 0 = success.
1734* 1 = failure.
1735*/
1736static uint8_t
1737qla2x00_mem_alloc(scsi_qla_host_t *ha)
1738{
1739 char name[16];
1740 uint8_t status = 1;
1741 int retry= 10;
1742
1743 do {
1744 /*
1745 * This will loop only once if everything goes well, else some
1746 * number of retries will be performed to get around a kernel
1747 * bug where available mem is not allocated until after a
1748 * little delay and a retry.
1749 */
1750 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1751 (ha->request_q_length + 1) * sizeof(request_t),
1752 &ha->request_dma, GFP_KERNEL);
1753 if (ha->request_ring == NULL) {
1754 qla_printk(KERN_WARNING, ha,
1755 "Memory Allocation failed - request_ring\n");
1756
1757 qla2x00_mem_free(ha);
1758 msleep(100);
1759
1760 continue;
1761 }
1762
1763 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1764 (ha->response_q_length + 1) * sizeof(response_t),
1765 &ha->response_dma, GFP_KERNEL);
1766 if (ha->response_ring == NULL) {
1767 qla_printk(KERN_WARNING, ha,
1768 "Memory Allocation failed - response_ring\n");
1769
1770 qla2x00_mem_free(ha);
1771 msleep(100);
1772
1773 continue;
1774 }
1775
1776 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1777 &ha->gid_list_dma, GFP_KERNEL);
1778 if (ha->gid_list == NULL) {
1779 qla_printk(KERN_WARNING, ha,
1780 "Memory Allocation failed - gid_list\n");
1781
1782 qla2x00_mem_free(ha);
1783 msleep(100);
1784
1785 continue;
1786 }
1787
1788 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1789 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1790 if (ha->rlc_rsp == NULL) {
1791 qla_printk(KERN_WARNING, ha,
1792 "Memory Allocation failed - rlc");
1793
1794 qla2x00_mem_free(ha);
1795 msleep(100);
1796
1797 continue;
1798 }
1799
1800 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1801 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1802 DMA_POOL_SIZE, 8, 0);
1803 if (ha->s_dma_pool == NULL) {
1804 qla_printk(KERN_WARNING, ha,
1805 "Memory Allocation failed - s_dma_pool\n");
1806
1807 qla2x00_mem_free(ha);
1808 msleep(100);
1809
1810 continue;
1811 }
1812
1813 /* get consistent memory allocated for init control block */
1814 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1815 &ha->init_cb_dma);
1816 if (ha->init_cb == NULL) {
1817 qla_printk(KERN_WARNING, ha,
1818 "Memory Allocation failed - init_cb\n");
1819
1820 qla2x00_mem_free(ha);
1821 msleep(100);
1822
1823 continue;
1824 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001825 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 /* Get consistent memory allocated for Get Port Database cmd */
1828 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1829 &ha->iodesc_pd_dma);
1830 if (ha->iodesc_pd == NULL) {
1831 /* error */
1832 qla_printk(KERN_WARNING, ha,
1833 "Memory Allocation failed - iodesc_pd\n");
1834
1835 qla2x00_mem_free(ha);
1836 msleep(100);
1837
1838 continue;
1839 }
1840 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1841
1842 /* Allocate ioctl related memory. */
1843 if (qla2x00_alloc_ioctl_mem(ha)) {
1844 qla_printk(KERN_WARNING, ha,
1845 "Memory Allocation failed - ioctl_mem\n");
1846
1847 qla2x00_mem_free(ha);
1848 msleep(100);
1849
1850 continue;
1851 }
1852
1853 if (qla2x00_allocate_sp_pool(ha)) {
1854 qla_printk(KERN_WARNING, ha,
1855 "Memory Allocation failed - "
1856 "qla2x00_allocate_sp_pool()\n");
1857
1858 qla2x00_mem_free(ha);
1859 msleep(100);
1860
1861 continue;
1862 }
1863
1864 /* Allocate memory for SNS commands */
1865 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1866 /* Get consistent memory allocated for SNS commands */
1867 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1868 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1869 GFP_KERNEL);
1870 if (ha->sns_cmd == NULL) {
1871 /* error */
1872 qla_printk(KERN_WARNING, ha,
1873 "Memory Allocation failed - sns_cmd\n");
1874
1875 qla2x00_mem_free(ha);
1876 msleep(100);
1877
1878 continue;
1879 }
1880 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1881 } else {
1882 /* Get consistent memory allocated for MS IOCB */
1883 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1884 &ha->ms_iocb_dma);
1885 if (ha->ms_iocb == NULL) {
1886 /* error */
1887 qla_printk(KERN_WARNING, ha,
1888 "Memory Allocation failed - ms_iocb\n");
1889
1890 qla2x00_mem_free(ha);
1891 msleep(100);
1892
1893 continue;
1894 }
1895 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1896
1897 /*
1898 * Get consistent memory allocated for CT SNS
1899 * commands
1900 */
1901 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1902 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1903 GFP_KERNEL);
1904 if (ha->ct_sns == NULL) {
1905 /* error */
1906 qla_printk(KERN_WARNING, ha,
1907 "Memory Allocation failed - ct_sns\n");
1908
1909 qla2x00_mem_free(ha);
1910 msleep(100);
1911
1912 continue;
1913 }
1914 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1915 }
1916
1917 /* Done all allocations without any error. */
1918 status = 0;
1919
1920 } while (retry-- && status != 0);
1921
1922 if (status) {
1923 printk(KERN_WARNING
1924 "%s(): **** FAILED ****\n", __func__);
1925 }
1926
1927 return(status);
1928}
1929
1930/*
1931* qla2x00_mem_free
1932* Frees all adapter allocated memory.
1933*
1934* Input:
1935* ha = adapter block pointer.
1936*/
1937static void
1938qla2x00_mem_free(scsi_qla_host_t *ha)
1939{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 struct list_head *fcpl, *fcptemp;
1941 fc_port_t *fcport;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001942 unsigned int wtime;/* max wait time if mbx cmd is busy. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
1944 if (ha == NULL) {
1945 /* error */
1946 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1947 return;
1948 }
1949
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 /* Make sure all other threads are stopped. */
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001951 wtime = 60 * 1000;
1952 while (ha->dpc_wait && wtime)
1953 wtime = msleep_interruptible(wtime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
1955 /* free ioctl memory */
1956 qla2x00_free_ioctl_mem(ha);
1957
1958 /* free sp pool */
1959 qla2x00_free_sp_pool(ha);
1960
1961 if (ha->sns_cmd)
1962 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1963 ha->sns_cmd, ha->sns_cmd_dma);
1964
1965 if (ha->ct_sns)
1966 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1967 ha->ct_sns, ha->ct_sns_dma);
1968
1969 if (ha->ms_iocb)
1970 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1971
1972 if (ha->iodesc_pd)
1973 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1974
1975 if (ha->init_cb)
1976 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1977
1978 if (ha->s_dma_pool)
1979 dma_pool_destroy(ha->s_dma_pool);
1980
1981 if (ha->rlc_rsp)
1982 dma_free_coherent(&ha->pdev->dev,
1983 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
1984 ha->rlc_rsp_dma);
1985
1986 if (ha->gid_list)
1987 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
1988 ha->gid_list_dma);
1989
1990 if (ha->response_ring)
1991 dma_free_coherent(&ha->pdev->dev,
1992 (ha->response_q_length + 1) * sizeof(response_t),
1993 ha->response_ring, ha->response_dma);
1994
1995 if (ha->request_ring)
1996 dma_free_coherent(&ha->pdev->dev,
1997 (ha->request_q_length + 1) * sizeof(request_t),
1998 ha->request_ring, ha->request_dma);
1999
2000 ha->sns_cmd = NULL;
2001 ha->sns_cmd_dma = 0;
2002 ha->ct_sns = NULL;
2003 ha->ct_sns_dma = 0;
2004 ha->ms_iocb = NULL;
2005 ha->ms_iocb_dma = 0;
2006 ha->iodesc_pd = NULL;
2007 ha->iodesc_pd_dma = 0;
2008 ha->init_cb = NULL;
2009 ha->init_cb_dma = 0;
2010
2011 ha->s_dma_pool = NULL;
2012
2013 ha->rlc_rsp = NULL;
2014 ha->rlc_rsp_dma = 0;
2015 ha->gid_list = NULL;
2016 ha->gid_list_dma = 0;
2017
2018 ha->response_ring = NULL;
2019 ha->response_dma = 0;
2020 ha->request_ring = NULL;
2021 ha->request_dma = 0;
2022
2023 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2024 fcport = list_entry(fcpl, fc_port_t, list);
2025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 /* fc ports */
2027 list_del_init(&fcport->list);
2028 kfree(fcport);
2029 }
2030 INIT_LIST_HEAD(&ha->fcports);
2031
2032 if (ha->fw_dump)
2033 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2034
Andrew Vasquezfca29702005-07-06 10:31:47 -07002035 vfree(ha->fw_dump24);
2036
2037 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
2039 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002040 ha->fw_dump24 = NULL;
2041 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 ha->fw_dump_reading = 0;
2043 ha->fw_dump_buffer = NULL;
2044}
2045
2046/*
2047 * qla2x00_allocate_sp_pool
2048 * This routine is called during initialization to allocate
2049 * memory for local srb_t.
2050 *
2051 * Input:
2052 * ha = adapter block pointer.
2053 *
2054 * Context:
2055 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002056 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 * Note: Sets the ref_count for non Null sp to one.
2058 */
2059static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002060qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
2062 int rval;
2063
2064 rval = QLA_SUCCESS;
2065 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2066 mempool_free_slab, srb_cachep);
2067 if (ha->srb_mempool == NULL) {
2068 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2069 rval = QLA_FUNCTION_FAILED;
2070 }
2071 return (rval);
2072}
2073
2074/*
2075 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002076 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 */
2078static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002079qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
2081 if (ha->srb_mempool) {
2082 mempool_destroy(ha->srb_mempool);
2083 ha->srb_mempool = NULL;
2084 }
2085}
2086
2087/**************************************************************************
2088* qla2x00_do_dpc
2089* This kernel thread is a task that is schedule by the interrupt handler
2090* to perform the background processing for interrupts.
2091*
2092* Notes:
2093* This task always run in the context of a kernel thread. It
2094* is kick-off by the driver's detect code and starts up
2095* up one per adapter. It immediately goes to sleep and waits for
2096* some fibre event. When either the interrupt handler or
2097* the timer routine detects a event it will one of the task
2098* bits then wake us up.
2099**************************************************************************/
2100static int
2101qla2x00_do_dpc(void *data)
2102{
2103 DECLARE_MUTEX_LOCKED(sem);
2104 scsi_qla_host_t *ha;
2105 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 ha = (scsi_qla_host_t *)data;
2110
2111 lock_kernel();
2112
2113 daemonize("%s_dpc", ha->host_str);
2114 allow_signal(SIGHUP);
2115
2116 ha->dpc_wait = &sem;
2117
2118 set_user_nice(current, -20);
2119
2120 unlock_kernel();
2121
2122 complete(&ha->dpc_inited);
2123
2124 while (1) {
2125 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2126
2127 if (down_interruptible(&sem))
2128 break;
2129
2130 if (ha->dpc_should_die)
2131 break;
2132
2133 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2134
2135 /* Initialization not yet finished. Don't do anything yet. */
2136 if (!ha->flags.init_done || ha->dpc_active)
2137 continue;
2138
2139 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2140
2141 ha->dpc_active = 1;
2142
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 ha->dpc_active = 0;
2145 continue;
2146 }
2147
2148 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2149
2150 DEBUG(printk("scsi(%ld): dpc: sched "
2151 "qla2x00_abort_isp ha = %p\n",
2152 ha->host_no, ha));
2153 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2154 &ha->dpc_flags))) {
2155
2156 if (qla2x00_abort_isp(ha)) {
2157 /* failed. retry later */
2158 set_bit(ISP_ABORT_NEEDED,
2159 &ha->dpc_flags);
2160 }
2161 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2162 }
2163 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2164 ha->host_no));
2165 }
2166
2167 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2168 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2169
2170 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2171 ha->host_no));
2172
2173 qla2x00_rst_aen(ha);
2174 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2175 }
2176
2177 /* Retry each device up to login retry count */
2178 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2179 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2180 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2181
2182 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2183 ha->host_no));
2184
2185 next_loopid = 0;
2186 list_for_each_entry(fcport, &ha->fcports, list) {
2187 if (fcport->port_type != FCT_TARGET)
2188 continue;
2189
2190 /*
2191 * If the port is not ONLINE then try to login
2192 * to it if we haven't run out of retries.
2193 */
2194 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2195 fcport->login_retry) {
2196
2197 fcport->login_retry--;
2198 if (fcport->flags & FCF_FABRIC_DEVICE) {
2199 if (fcport->flags &
2200 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002201 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002202 ha, fcport->loop_id,
2203 fcport->d_id.b.domain,
2204 fcport->d_id.b.area,
2205 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 status = qla2x00_fabric_login(
2207 ha, fcport, &next_loopid);
2208 } else
2209 status =
2210 qla2x00_local_device_login(
2211 ha, fcport->loop_id);
2212
2213 if (status == QLA_SUCCESS) {
2214 fcport->old_loop_id = fcport->loop_id;
2215
2216 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2217 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002218
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 fcport->port_login_retry_count =
2220 ha->port_down_retry_count * PORT_RETRY_TIME;
2221 atomic_set(&fcport->state, FCS_ONLINE);
2222 atomic_set(&fcport->port_down_timer,
2223 ha->port_down_retry_count * PORT_RETRY_TIME);
2224
2225 fcport->login_retry = 0;
2226 } else if (status == 1) {
2227 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2228 /* retry the login again */
2229 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2230 ha->host_no,
2231 fcport->login_retry, fcport->loop_id));
2232 } else {
2233 fcport->login_retry = 0;
2234 }
2235 }
2236 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2237 break;
2238 }
2239 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2240 ha->host_no));
2241 }
2242
2243 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2244 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2245
2246 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2247 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2248 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2251
2252 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2253 ha->host_no));
2254 }
2255
2256 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2257
2258 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2259 ha->host_no));
2260
2261 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2262 &ha->dpc_flags))) {
2263
2264 qla2x00_loop_resync(ha);
2265
2266 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2267 }
2268
2269 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2270 ha->host_no));
2271 }
2272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2274
2275 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2276 ha->host_no));
2277
2278 qla2x00_rescan_fcports(ha);
2279
2280 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2281 "end.\n",
2282 ha->host_no));
2283 }
2284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002286 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 ha->dpc_active = 0;
2289 } /* End of while(1) */
2290
2291 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2292
2293 /*
2294 * Make sure that nobody tries to wake us up again.
2295 */
2296 ha->dpc_wait = NULL;
2297 ha->dpc_active = 0;
2298
2299 complete_and_exit(&ha->dpc_exited, 0);
2300}
2301
2302/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303* qla2x00_rst_aen
2304* Processes asynchronous reset.
2305*
2306* Input:
2307* ha = adapter block pointer.
2308*/
2309static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002310qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
2312 if (ha->flags.online && !ha->flags.reset_active &&
2313 !atomic_read(&ha->loop_down_timer) &&
2314 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2315 do {
2316 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2317
2318 /*
2319 * Issue marker command only when we are going to start
2320 * the I/O.
2321 */
2322 ha->marker_needed = 1;
2323 } while (!atomic_read(&ha->loop_down_timer) &&
2324 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2325 }
2326}
2327
f4f051e2005-04-17 15:02:26 -05002328static void
2329qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2330{
2331 struct scsi_cmnd *cmd = sp->cmd;
2332
2333 if (sp->flags & SRB_DMA_VALID) {
2334 if (cmd->use_sg) {
2335 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2336 cmd->use_sg, cmd->sc_data_direction);
2337 } else if (cmd->request_bufflen) {
2338 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2339 cmd->request_bufflen, cmd->sc_data_direction);
2340 }
2341 sp->flags &= ~SRB_DMA_VALID;
2342 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002343 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002344}
2345
2346void
2347qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2348{
2349 struct scsi_cmnd *cmd = sp->cmd;
2350
2351 qla2x00_sp_free_dma(ha, sp);
2352
f4f051e2005-04-17 15:02:26 -05002353 mempool_free(sp, ha->srb_mempool);
2354
2355 cmd->scsi_done(cmd);
2356}
bdf79622005-04-17 15:06:53 -05002357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358/**************************************************************************
2359* qla2x00_timer
2360*
2361* Description:
2362* One second timer
2363*
2364* Context: Interrupt
2365***************************************************************************/
2366static void
2367qla2x00_timer(scsi_qla_host_t *ha)
2368{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 unsigned long cpu_flags = 0;
2370 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 int start_dpc = 0;
2372 int index;
2373 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002374 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
2376 /*
2377 * Ports - Port down timer.
2378 *
2379 * Whenever, a port is in the LOST state we start decrementing its port
2380 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002381 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 */
2383 t = 0;
2384 list_for_each_entry(fcport, &ha->fcports, list) {
2385 if (fcport->port_type != FCT_TARGET)
2386 continue;
2387
2388 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2389
2390 if (atomic_read(&fcport->port_down_timer) == 0)
2391 continue;
2392
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002393 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002395
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002397 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 ha->host_no,
2399 t, atomic_read(&fcport->port_down_timer)));
2400 }
2401 t++;
2402 } /* End of for fcport */
2403
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
2405 /* Loop down handler. */
2406 if (atomic_read(&ha->loop_down_timer) > 0 &&
2407 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2408
2409 if (atomic_read(&ha->loop_down_timer) ==
2410 ha->loop_down_abort_time) {
2411
2412 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2413 "queues before time expire\n",
2414 ha->host_no));
2415
2416 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002417 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
2419 /* Schedule an ISP abort to return any tape commands. */
2420 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2421 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2422 index++) {
bdf79622005-04-17 15:06:53 -05002423 fc_port_t *sfcp;
2424
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 sp = ha->outstanding_cmds[index];
2426 if (!sp)
2427 continue;
bdf79622005-04-17 15:06:53 -05002428 sfcp = sp->fcport;
2429 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 continue;
2431
2432 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2433 break;
2434 }
2435 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2436
2437 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2438 start_dpc++;
2439 }
2440
2441 /* if the loop has been down for 4 minutes, reinit adapter */
2442 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2443 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2444 "restarting queues.\n",
2445 ha->host_no));
2446
2447 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2448 start_dpc++;
2449
2450 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2451 DEBUG(printk("scsi(%ld): Loop down - "
2452 "aborting ISP.\n",
2453 ha->host_no));
2454 qla_printk(KERN_WARNING, ha,
2455 "Loop down - aborting ISP.\n");
2456
2457 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2458 }
2459 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002460 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 ha->host_no,
2462 atomic_read(&ha->loop_down_timer)));
2463 }
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 /* Schedule the DPC routine if needed */
2466 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2467 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2468 start_dpc ||
2469 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002470 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2472 ha->dpc_wait && !ha->dpc_active) {
2473
2474 up(ha->dpc_wait);
2475 }
2476
2477 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2478}
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/* XXX(hch): crude hack to emulate a down_timeout() */
2481int
2482qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2483{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002484 const unsigned int step = 100; /* msecs */
2485 unsigned int iterations = jiffies_to_msecs(timeout)/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
2487 do {
2488 if (!down_trylock(sema))
2489 return 0;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002490 if (msleep_interruptible(step))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 break;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002492 } while (--iterations >= 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
2494 return -ETIMEDOUT;
2495}
2496
Andrew Vasquezfca29702005-07-06 10:31:47 -07002497static struct qla_board_info qla_board_tbl[] = {
2498 {
2499 .drv_name = "qla2400",
2500 .isp_name = "ISP2422",
2501 .fw_fname = "ql2400_fw.bin",
2502 .sht = &qla24xx_driver_template,
2503 },
2504 {
2505 .drv_name = "qla2400",
2506 .isp_name = "ISP2432",
2507 .fw_fname = "ql2400_fw.bin",
2508 .sht = &qla24xx_driver_template,
2509 },
2510};
2511
2512static struct pci_device_id qla2xxx_pci_tbl[] = {
2513 {
2514 .vendor = PCI_VENDOR_ID_QLOGIC,
2515 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2516 .subvendor = PCI_ANY_ID,
2517 .subdevice = PCI_ANY_ID,
2518 .driver_data = (unsigned long)&qla_board_tbl[0],
2519 },
2520 {
2521 .vendor = PCI_VENDOR_ID_QLOGIC,
2522 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2523 .subvendor = PCI_ANY_ID,
2524 .subdevice = PCI_ANY_ID,
2525 .driver_data = (unsigned long)&qla_board_tbl[1],
2526 },
2527 {0, 0},
2528};
2529MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2530
2531static int __devinit
2532qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2533{
2534 return qla2x00_probe_one(pdev,
2535 (struct qla_board_info *)id->driver_data);
2536}
2537
2538static void __devexit
2539qla2xxx_remove_one(struct pci_dev *pdev)
2540{
2541 qla2x00_remove_one(pdev);
2542}
2543
2544static struct pci_driver qla2xxx_pci_driver = {
2545 .name = "qla2xxx",
2546 .id_table = qla2xxx_pci_tbl,
2547 .probe = qla2xxx_probe_one,
2548 .remove = __devexit_p(qla2xxx_remove_one),
2549};
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551/**
2552 * qla2x00_module_init - Module initialization.
2553 **/
2554static int __init
2555qla2x00_module_init(void)
2556{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002557 int ret = 0;
2558
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002560 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 SLAB_HWCACHE_ALIGN, NULL, NULL);
2562 if (srb_cachep == NULL) {
2563 printk(KERN_ERR
2564 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2565 return -ENOMEM;
2566 }
2567
2568 /* Derive version string. */
2569 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2570#if DEBUG_QLA2100
2571 strcat(qla2x00_version_str, "-debug");
2572#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002573 qla2xxx_transport_template =
2574 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 if (!qla2xxx_transport_template)
2576 return -ENODEV;
2577
2578 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002579 ret = pci_module_init(&qla2xxx_pci_driver);
2580 if (ret) {
2581 kmem_cache_destroy(srb_cachep);
2582 fc_release_transport(qla2xxx_transport_template);
2583 }
2584 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585}
2586
2587/**
2588 * qla2x00_module_exit - Module cleanup.
2589 **/
2590static void __exit
2591qla2x00_module_exit(void)
2592{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002593 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002594 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 fc_release_transport(qla2xxx_transport_template);
2596}
2597
2598module_init(qla2x00_module_init);
2599module_exit(qla2x00_module_exit);
2600
2601MODULE_AUTHOR("QLogic Corporation");
2602MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2603MODULE_LICENSE("GPL");
2604MODULE_VERSION(QLA2XXX_VERSION);