blob: d726f48728ec2ef807637c0ad4957dcd9544dc7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * QLOGIC LINUX SOFTWARE
3 *
4 * QLogic ISP2x00 device driver for Linux 2.6.x
Andrew Vasquezae911932005-07-06 10:32:27 -07005 * Copyright (C) 2003-2005 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * (www.qlogic.com)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 */
19#include "qla_def.h"
20
21#include <linux/moduleparam.h>
22#include <linux/vmalloc.h>
23#include <linux/smp_lock.h>
24#include <linux/delay.h>
25
26#include <scsi/scsi_tcq.h>
27#include <scsi/scsicam.h>
28#include <scsi/scsi_transport.h>
29#include <scsi/scsi_transport_fc.h>
30
31/*
32 * Driver version
33 */
34char qla2x00_version_str[40];
35
36/*
37 * SRB allocation cache
38 */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -040039static kmem_cache_t *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/*
42 * Ioctl related information.
43 */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -040044static int num_hosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46int ql2xlogintimeout = 20;
47module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
48MODULE_PARM_DESC(ql2xlogintimeout,
49 "Login timeout value in seconds.");
50
8482e1182005-04-17 15:04:54 -050051int qlport_down_retry = 30;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
53MODULE_PARM_DESC(qlport_down_retry,
54 "Maximum number of command retries to a port that returns"
55 "a PORT-DOWN status.");
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057int ql2xplogiabsentdevice;
58module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
59MODULE_PARM_DESC(ql2xplogiabsentdevice,
60 "Option to enable PLOGI to devices that are not present after "
61 "a Fabric scan. This is needed for several broken switches."
62 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
63
64int ql2xenablezio = 0;
65module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
66MODULE_PARM_DESC(ql2xenablezio,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070067 "Option to enable ZIO:If 1 then enable it otherwise"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 " use the default set in the NVRAM."
69 " Default is 0 : disabled");
70
71int ql2xintrdelaytimer = 10;
72module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
73MODULE_PARM_DESC(ql2xintrdelaytimer,
74 "ZIO: Waiting time for Firmware before it generates an "
75 "interrupt to the host to notify completion of request.");
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077int ql2xloginretrycount = 0;
78module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
79MODULE_PARM_DESC(ql2xloginretrycount,
80 "Specify an alternate value for the NVRAM login retry count.");
81
Andrew Vasquezfca29702005-07-06 10:31:47 -070082int ql2xfwloadbin;
83module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
84MODULE_PARM_DESC(ql2xfwloadbin,
85 "Load ISP2xxx firmware image via hotplug.");
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static void qla2x00_free_device(scsi_qla_host_t *);
88
89static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
90
91/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070092 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 */
94static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -050095static int qla2xxx_slave_alloc(struct scsi_device *);
96static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
98 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -070099static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
100 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static int qla2xxx_eh_abort(struct scsi_cmnd *);
102static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
103static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
104static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
105static int qla2x00_loop_reset(scsi_qla_host_t *ha);
106static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static struct scsi_host_template qla2x00_driver_template = {
109 .module = THIS_MODULE,
110 .name = "qla2xxx",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 .queuecommand = qla2x00_queuecommand,
112
113 .eh_abort_handler = qla2xxx_eh_abort,
114 .eh_device_reset_handler = qla2xxx_eh_device_reset,
115 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
116 .eh_host_reset_handler = qla2xxx_eh_host_reset,
117
118 .slave_configure = qla2xxx_slave_configure,
119
f4f051e2005-04-17 15:02:26 -0500120 .slave_alloc = qla2xxx_slave_alloc,
121 .slave_destroy = qla2xxx_slave_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .this_id = -1,
123 .cmd_per_lun = 3,
124 .use_clustering = ENABLE_CLUSTERING,
125 .sg_tablesize = SG_ALL,
126
127 /*
128 * The RISC allows for each command to transfer (2^32-1) bytes of data,
129 * which equates to 0x800000 sectors.
130 */
131 .max_sectors = 0xFFFF,
132};
133
Andrew Vasquezfca29702005-07-06 10:31:47 -0700134static struct scsi_host_template qla24xx_driver_template = {
135 .module = THIS_MODULE,
136 .name = "qla2xxx",
137 .queuecommand = qla24xx_queuecommand,
138
139 .eh_abort_handler = qla2xxx_eh_abort,
140 .eh_device_reset_handler = qla2xxx_eh_device_reset,
141 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
142 .eh_host_reset_handler = qla2xxx_eh_host_reset,
143
144 .slave_configure = qla2xxx_slave_configure,
145
146 .slave_alloc = qla2xxx_slave_alloc,
147 .slave_destroy = qla2xxx_slave_destroy,
148 .this_id = -1,
149 .cmd_per_lun = 3,
150 .use_clustering = ENABLE_CLUSTERING,
151 .sg_tablesize = SG_ALL,
152
153 .max_sectors = 0xFFFF,
154};
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static struct scsi_transport_template *qla2xxx_transport_template = NULL;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/* TODO Convert to inlines
159 *
160 * Timer routines
161 */
162#define WATCH_INTERVAL 1 /* number of seconds */
163
164static void qla2x00_timer(scsi_qla_host_t *);
165
166static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
167 void *, unsigned long);
168static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
169static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
170
171static inline void
172qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
173{
174 init_timer(&ha->timer);
175 ha->timer.expires = jiffies + interval * HZ;
176 ha->timer.data = (unsigned long)ha;
177 ha->timer.function = (void (*)(unsigned long))func;
178 add_timer(&ha->timer);
179 ha->timer_active = 1;
180}
181
182static inline void
183qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
184{
185 mod_timer(&ha->timer, jiffies + interval * HZ);
186}
187
188static __inline__ void
189qla2x00_stop_timer(scsi_qla_host_t *ha)
190{
191 del_timer_sync(&ha->timer);
192 ha->timer_active = 0;
193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195static int qla2x00_do_dpc(void *data);
196
197static void qla2x00_rst_aen(scsi_qla_host_t *);
198
199static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
200static void qla2x00_mem_free(scsi_qla_host_t *ha);
201static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
202static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500203static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
204void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* -------------------------------------------------------------------------- */
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700209qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
211 static char *pci_bus_modes[] = {
212 "33", "66", "100", "133",
213 };
214 uint16_t pci_bus;
215
216 strcpy(str, "PCI");
217 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
218 if (pci_bus) {
219 strcat(str, "-X (");
220 strcat(str, pci_bus_modes[pci_bus]);
221 } else {
222 pci_bus = (ha->pci_attr & BIT_8) >> 8;
223 strcat(str, " (");
224 strcat(str, pci_bus_modes[pci_bus]);
225 }
226 strcat(str, " MHz)");
227
228 return (str);
229}
230
Andrew Vasquezfca29702005-07-06 10:31:47 -0700231static char *
232qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
233{
234 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
235 uint32_t pci_bus;
236 int pcie_reg;
237
238 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
239 if (pcie_reg) {
240 char lwstr[6];
241 uint16_t pcie_lstat, lspeed, lwidth;
242
243 pcie_reg += 0x12;
244 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
245 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
246 lwidth = (pcie_lstat &
247 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
248
249 strcpy(str, "PCIe (");
250 if (lspeed == 1)
251 strcat(str, "2.5Gb/s ");
252 else
253 strcat(str, "<unknown> ");
254 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
255 strcat(str, lwstr);
256
257 return str;
258 }
259
260 strcpy(str, "PCI");
261 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
262 if (pci_bus == 0 || pci_bus == 8) {
263 strcat(str, " (");
264 strcat(str, pci_bus_modes[pci_bus >> 3]);
265 } else {
266 strcat(str, "-X ");
267 if (pci_bus & BIT_2)
268 strcat(str, "Mode 2");
269 else
270 strcat(str, "Mode 1");
271 strcat(str, " (");
272 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
273 }
274 strcat(str, " MHz)");
275
276 return str;
277}
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700280qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
285 ha->fw_minor_version,
286 ha->fw_subminor_version);
287
288 if (ha->fw_attributes & BIT_9) {
289 strcat(str, "FLX");
290 return (str);
291 }
292
293 switch (ha->fw_attributes & 0xFF) {
294 case 0x7:
295 strcat(str, "EF");
296 break;
297 case 0x17:
298 strcat(str, "TP");
299 break;
300 case 0x37:
301 strcat(str, "IP");
302 break;
303 case 0x77:
304 strcat(str, "VI");
305 break;
306 default:
307 sprintf(un_str, "(%x)", ha->fw_attributes);
308 strcat(str, un_str);
309 break;
310 }
311 if (ha->fw_attributes & 0x100)
312 strcat(str, "X");
313
314 return (str);
315}
316
Andrew Vasquezfca29702005-07-06 10:31:47 -0700317char *
318qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
319{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700320 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
321 ha->fw_minor_version,
322 ha->fw_subminor_version);
323
Andrew Vasquezfca29702005-07-06 10:31:47 -0700324 if (ha->fw_attributes & BIT_0)
325 strcat(str, "[Class 2] ");
326 if (ha->fw_attributes & BIT_1)
327 strcat(str, "[IP] ");
328 if (ha->fw_attributes & BIT_2)
329 strcat(str, "[Multi-ID] ");
330 if (ha->fw_attributes & BIT_13)
331 strcat(str, "[Experimental]");
332 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700333}
334
335static inline srb_t *
336qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
337 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
338{
339 srb_t *sp;
340
341 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
342 if (!sp)
343 return sp;
344
345 atomic_set(&sp->ref_count, 1);
346 sp->ha = ha;
347 sp->fcport = fcport;
348 sp->cmd = cmd;
349 sp->flags = 0;
350 CMD_SP(cmd) = (void *)sp;
351 cmd->scsi_done = done;
352
353 return sp;
354}
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356static int
f4f051e2005-04-17 15:02:26 -0500357qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
f4f051e2005-04-17 15:02:26 -0500359 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500360 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500361 srb_t *sp;
362 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
bdf79622005-04-17 15:06:53 -0500364 if (!fcport) {
f4f051e2005-04-17 15:02:26 -0500365 cmd->result = DID_NO_CONNECT << 16;
366 goto qc_fail_command;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
f4f051e2005-04-17 15:02:26 -0500369 if (atomic_read(&fcport->state) != FCS_ONLINE) {
370 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
371 atomic_read(&ha->loop_state) == LOOP_DEAD) {
372 cmd->result = DID_NO_CONNECT << 16;
373 goto qc_fail_command;
374 }
375 goto qc_host_busy;
376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 spin_unlock_irq(ha->host->host_lock);
379
Andrew Vasquezfca29702005-07-06 10:31:47 -0700380 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
381 if (!sp)
f4f051e2005-04-17 15:02:26 -0500382 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
f4f051e2005-04-17 15:02:26 -0500384 rval = qla2x00_start_scsi(sp);
385 if (rval != QLA_SUCCESS)
386 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
f4f051e2005-04-17 15:02:26 -0500388 /* Manage unprocessed RIO/ZIO commands in response queue. */
389 if (ha->flags.online && ha->flags.process_response_queue &&
390 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
391 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
f4f051e2005-04-17 15:02:26 -0500393 spin_lock_irqsave(&ha->hardware_lock, flags);
394 qla2x00_process_response_queue(ha);
395 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 spin_lock_irq(ha->host->host_lock);
399
f4f051e2005-04-17 15:02:26 -0500400 return 0;
401
402qc_host_busy_free_sp:
403 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500404 mempool_free(sp, ha->srb_mempool);
405
406qc_host_busy_lock:
407 spin_lock_irq(ha->host->host_lock);
408
409qc_host_busy:
410 return SCSI_MLQUEUE_HOST_BUSY;
411
412qc_fail_command:
413 done(cmd);
414
415 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
Andrew Vasquezfca29702005-07-06 10:31:47 -0700418
419static int
420qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
421{
422 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
423 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
424 srb_t *sp;
425 int rval;
426
427 if (!fcport) {
428 cmd->result = DID_NO_CONNECT << 16;
429 goto qc24_fail_command;
430 }
431
432 if (atomic_read(&fcport->state) != FCS_ONLINE) {
433 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
434 atomic_read(&ha->loop_state) == LOOP_DEAD) {
435 cmd->result = DID_NO_CONNECT << 16;
436 goto qc24_fail_command;
437 }
438 goto qc24_host_busy;
439 }
440
441 spin_unlock_irq(ha->host->host_lock);
442
443 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
444 if (!sp)
445 goto qc24_host_busy_lock;
446
447 rval = qla24xx_start_scsi(sp);
448 if (rval != QLA_SUCCESS)
449 goto qc24_host_busy_free_sp;
450
451 spin_lock_irq(ha->host->host_lock);
452
453 return 0;
454
455qc24_host_busy_free_sp:
456 qla2x00_sp_free_dma(ha, sp);
457 mempool_free(sp, ha->srb_mempool);
458
459qc24_host_busy_lock:
460 spin_lock_irq(ha->host->host_lock);
461
462qc24_host_busy:
463 return SCSI_MLQUEUE_HOST_BUSY;
464
465qc24_fail_command:
466 done(cmd);
467
468 return 0;
469}
470
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472/*
473 * qla2x00_eh_wait_on_command
474 * Waits for the command to be returned by the Firmware for some
475 * max time.
476 *
477 * Input:
478 * ha = actual ha whose done queue will contain the command
479 * returned by firmware.
480 * cmd = Scsi Command to wait on.
481 * flag = Abort/Reset(Bus or Device Reset)
482 *
483 * Return:
484 * Not Found : 0
485 * Found : 1
486 */
487static int
488qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
489{
490#define ABORT_POLLING_PERIOD HZ
f4f051e2005-04-17 15:02:26 -0500491#define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
492 unsigned long wait_iter = ABORT_WAIT_ITER;
493 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
f4f051e2005-04-17 15:02:26 -0500495 while (CMD_SP(cmd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 set_current_state(TASK_UNINTERRUPTIBLE);
497 schedule_timeout(ABORT_POLLING_PERIOD);
498
f4f051e2005-04-17 15:02:26 -0500499 if (--wait_iter)
500 break;
501 }
502 if (CMD_SP(cmd))
503 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
f4f051e2005-04-17 15:02:26 -0500505 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
507
508/*
509 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700510 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 * <= MAX_RETRIES_OF_ISP_ABORT or
512 * finally HBA is disabled ie marked offline
513 *
514 * Input:
515 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700516 *
517 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 * Does context switching-Release SPIN_LOCK
519 * (if any) before calling this routine.
520 *
521 * Return:
522 * Success (Adapter is online) : 0
523 * Failed (Adapter is offline/disabled) : 1
524 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700525static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
527{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700528 int return_status;
529 unsigned long wait_online;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700531 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
533 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
534 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
535 ha->dpc_active) && time_before(jiffies, wait_online)) {
536
537 msleep(1000);
538 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700539 if (ha->flags.online)
540 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 else
542 return_status = QLA_FUNCTION_FAILED;
543
544 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
545
546 return (return_status);
547}
548
549/*
550 * qla2x00_wait_for_loop_ready
551 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700552 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 * Input:
554 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700555 *
556 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 * Does context switching-Release SPIN_LOCK
558 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700559 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 *
561 * Return:
562 * Success (LOOP_READY) : 0
563 * Failed (LOOP_NOT_READY) : 1
564 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700565static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
567{
568 int return_status = QLA_SUCCESS;
569 unsigned long loop_timeout ;
570
571 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700572 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 while ((!atomic_read(&ha->loop_down_timer) &&
575 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 atomic_read(&ha->loop_state) != LOOP_READY) {
577 msleep(1000);
578 if (time_after_eq(jiffies, loop_timeout)) {
579 return_status = QLA_FUNCTION_FAILED;
580 break;
581 }
582 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700583 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
586/**************************************************************************
587* qla2xxx_eh_abort
588*
589* Description:
590* The abort function will abort the specified command.
591*
592* Input:
593* cmd = Linux SCSI command packet to be aborted.
594*
595* Returns:
596* Either SUCCESS or FAILED.
597*
598* Note:
599**************************************************************************/
600int
601qla2xxx_eh_abort(struct scsi_cmnd *cmd)
602{
f4f051e2005-04-17 15:02:26 -0500603 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
604 srb_t *sp;
605 int ret, i;
606 unsigned int id, lun;
607 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700608 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
f4f051e2005-04-17 15:02:26 -0500610 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
f4f051e2005-04-17 15:02:26 -0500613 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
f4f051e2005-04-17 15:02:26 -0500615 id = cmd->device->id;
616 lun = cmd->device->lun;
617 serial = cmd->serial_number;
618
619 /* Check active list for command command. */
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700620 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500621 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
622 sp = ha->outstanding_cmds[i];
623
624 if (sp == NULL)
625 continue;
626
627 if (sp->cmd != cmd)
628 continue;
629
630 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
631 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
632 sp->state));
633 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
634
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700635 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700636 if (ha->isp_ops.abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500637 DEBUG2(printk("%s(%ld): abort_command "
638 "mbx failed.\n", __func__, ha->host_no));
639 } else {
640 DEBUG3(printk("%s(%ld): abort_command "
641 "mbx success.\n", __func__, ha->host_no));
642 ret = SUCCESS;
643 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700644 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500645
646 break;
647 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700648 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500649
650 /* Wait for the command to be returned. */
651 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500652 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700653 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500654 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
655 "%x.\n", ha->host_no, id, lun, serial, ret);
656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700659 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500660 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
661 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
f4f051e2005-04-17 15:02:26 -0500663 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
665
666/**************************************************************************
667* qla2x00_eh_wait_for_pending_target_commands
668*
669* Description:
670* Waits for all the commands to come back from the specified target.
671*
672* Input:
673* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700674* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675* Returns:
676* Either SUCCESS or FAILED.
677*
678* Note:
679**************************************************************************/
680static int
681qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
682{
683 int cnt;
684 int status;
685 srb_t *sp;
686 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700687 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
689 status = 0;
690
691 /*
692 * Waiting for all commands for the designated target in the active
693 * array
694 */
695 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700696 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 sp = ha->outstanding_cmds[cnt];
698 if (sp) {
699 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700700 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 if (cmd->device->id == t) {
702 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
703 status = 1;
704 break;
705 }
706 }
f4f051e2005-04-17 15:02:26 -0500707 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700708 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
710 }
711 return (status);
712}
713
714
715/**************************************************************************
716* qla2xxx_eh_device_reset
717*
718* Description:
719* The device reset function will reset the target and abort any
720* executing commands.
721*
722* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700723* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724* non-null.
725*
726* Input:
727* cmd = Linux SCSI command packet of the command that cause the
728* bus device reset.
729*
730* Returns:
731* SUCCESS/FAILURE (defined as macro in scsi.h).
732*
733**************************************************************************/
734int
735qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
736{
f4f051e2005-04-17 15:02:26 -0500737 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500738 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500739 srb_t *sp;
740 int ret;
741 unsigned int id, lun;
742 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
f4f051e2005-04-17 15:02:26 -0500744 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
f4f051e2005-04-17 15:02:26 -0500746 id = cmd->device->id;
747 lun = cmd->device->lun;
748 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
f4f051e2005-04-17 15:02:26 -0500750 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500751 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500752 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500755 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400757 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500761 if (qla2x00_device_reset(ha, fcport) == 0)
762 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500765 if (ret == SUCCESS) {
766 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700767 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
f4f051e2005-04-17 15:02:26 -0500768 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 }
770 }
771#endif
772 } else {
773 DEBUG2(printk(KERN_INFO
774 "%s failed: loop not ready\n",__func__);)
775 }
776
f4f051e2005-04-17 15:02:26 -0500777 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 DEBUG3(printk("%s(%ld): device reset failed\n",
779 __func__, ha->host_no));
780 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
781 __func__);
782
783 goto eh_dev_reset_done;
784 }
785
786 /*
787 * If we are coming down the EH path, wait for all commands to
788 * complete for the device.
789 */
790 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500791 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
792 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
f4f051e2005-04-17 15:02:26 -0500794 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 DEBUG3(printk("%s(%ld): failed while waiting for "
796 "commands\n", __func__, ha->host_no));
797 qla_printk(KERN_INFO, ha,
798 "%s: failed while waiting for commands\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700799 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 goto eh_dev_reset_done;
802 }
803 }
804
805 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500806 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500809 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
812/**************************************************************************
813* qla2x00_eh_wait_for_pending_commands
814*
815* Description:
816* Waits for all the commands to come back from the specified host.
817*
818* Input:
819* ha - pointer to scsi_qla_host structure.
820*
821* Returns:
822* 1 : SUCCESS
823* 0 : FAILED
824*
825* Note:
826**************************************************************************/
827static int
828qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
829{
830 int cnt;
831 int status;
832 srb_t *sp;
833 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700834 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 status = 1;
837
838 /*
839 * Waiting for all commands for the designated target in the active
840 * array
841 */
842 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700843 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 sp = ha->outstanding_cmds[cnt];
845 if (sp) {
846 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700847 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 status = qla2x00_eh_wait_on_command(ha, cmd);
849 if (status == 0)
850 break;
851 }
852 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700853 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
855 }
856 return (status);
857}
858
859
860/**************************************************************************
861* qla2xxx_eh_bus_reset
862*
863* Description:
864* The bus reset function will reset the bus and abort any executing
865* commands.
866*
867* Input:
868* cmd = Linux SCSI command packet of the command that cause the
869* bus reset.
870*
871* Returns:
872* SUCCESS/FAILURE (defined as macro in scsi.h).
873*
874**************************************************************************/
875int
876qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
877{
f4f051e2005-04-17 15:02:26 -0500878 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500879 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500881 int ret;
882 unsigned int id, lun;
883 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
f4f051e2005-04-17 15:02:26 -0500885 ret = FAILED;
886
887 id = cmd->device->id;
888 lun = cmd->device->lun;
889 serial = cmd->serial_number;
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500892 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500893 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500896 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
899 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500900 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902
903 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500904 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
905 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 }
f4f051e2005-04-17 15:02:26 -0500907 if (ret == FAILED)
908 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 /* Waiting for our command in done_queue to be returned to OS.*/
911 if (cmd->device->host->eh_active)
912 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500913 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
f4f051e2005-04-17 15:02:26 -0500915eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500917 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
f4f051e2005-04-17 15:02:26 -0500919 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
922/**************************************************************************
923* qla2xxx_eh_host_reset
924*
925* Description:
926* The reset function will reset the Adapter.
927*
928* Input:
929* cmd = Linux SCSI command packet of the command that cause the
930* adapter reset.
931*
932* Returns:
933* Either SUCCESS or FAILED.
934*
935* Note:
936**************************************************************************/
937int
938qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
939{
f4f051e2005-04-17 15:02:26 -0500940 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500941 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500942 srb_t *sp;
943 int ret;
944 unsigned int id, lun;
945 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
f4f051e2005-04-17 15:02:26 -0500947 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
f4f051e2005-04-17 15:02:26 -0500949 id = cmd->device->id;
950 lun = cmd->device->lun;
951 serial = cmd->serial_number;
952
953 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500954 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500955 return ret;
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500958 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500961 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 /*
964 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700965 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 * be completed and then issue big hammer.Otherwise
967 * it may cause I/O failure as big hammer marks the
968 * devices as lost kicking of the port_down_timer
969 * while dpc is stuck for the mailbox to complete.
970 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 qla2x00_wait_for_loop_ready(ha);
972 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
973 if (qla2x00_abort_isp(ha)) {
974 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
975 /* failed. schedule dpc to try */
976 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
977
978 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500979 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500984 if (qla2x00_eh_wait_for_pending_commands(ha))
985 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
f4f051e2005-04-17 15:02:26 -0500987eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -0500988 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
989 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
f4f051e2005-04-17 15:02:26 -0500991 return ret;
992}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994/*
995* qla2x00_loop_reset
996* Issue loop reset.
997*
998* Input:
999* ha = adapter block pointer.
1000*
1001* Returns:
1002* 0 = success
1003*/
1004static int
1005qla2x00_loop_reset(scsi_qla_host_t *ha)
1006{
1007 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -05001008 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 if (ha->flags.enable_lip_reset) {
1011 status = qla2x00_lip_reset(ha);
1012 }
1013
1014 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001015 list_for_each_entry(fcport, &ha->fcports, list) {
1016 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 continue;
1018
bdf79622005-04-17 15:06:53 -05001019 status = qla2x00_target_reset(ha, fcport);
1020 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 }
1024
1025 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001026 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 !ha->flags.enable_lip_reset) ||
1028 ha->flags.enable_lip_full_login)) {
1029
1030 status = qla2x00_full_login_lip(ha);
1031 }
1032
1033 /* Issue marker command only when we are going to start the I/O */
1034 ha->marker_needed = 1;
1035
1036 if (status) {
1037 /* Empty */
1038 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1039 __func__,
1040 ha->host_no);)
1041 } else {
1042 /* Empty */
1043 DEBUG3(printk("%s(%ld): exiting normally.\n",
1044 __func__,
1045 ha->host_no);)
1046 }
1047
1048 return(status);
1049}
1050
1051/*
1052 * qla2x00_device_reset
1053 * Issue bus device reset message to the target.
1054 *
1055 * Input:
1056 * ha = adapter block pointer.
1057 * t = SCSI ID.
1058 * TARGET_QUEUE_LOCK must be released.
1059 * ADAPTER_STATE_LOCK must be released.
1060 *
1061 * Context:
1062 * Kernel context.
1063 */
1064static int
1065qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1066{
1067 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001068 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069}
1070
f4f051e2005-04-17 15:02:26 -05001071static int
1072qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
1074 scsi_qla_host_t *ha = to_qla_host(sdev->host);
bdf79622005-04-17 15:06:53 -05001075 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1076 fc_port_t *fcport;
1077 int found;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
bdf79622005-04-17 15:06:53 -05001079 if (!rport)
f4f051e2005-04-17 15:02:26 -05001080 return -ENXIO;
1081
bdf79622005-04-17 15:06:53 -05001082 found = 0;
1083 list_for_each_entry(fcport, &ha->fcports, list) {
1084 if (rport->port_name ==
1085 be64_to_cpu(*(uint64_t *)fcport->port_name)) {
1086 found++;
1087 break;
1088 }
bdf79622005-04-17 15:06:53 -05001089 }
1090 if (!found)
1091 return -ENXIO;
1092
1093 sdev->hostdata = fcport;
f4f051e2005-04-17 15:02:26 -05001094
1095 return 0;
1096}
1097
1098static int
1099qla2xxx_slave_configure(struct scsi_device *sdev)
1100{
8482e1182005-04-17 15:04:54 -05001101 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1102 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1103
f4f051e2005-04-17 15:02:26 -05001104 if (sdev->tagged_supported)
1105 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 else
f4f051e2005-04-17 15:02:26 -05001107 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
8482e1182005-04-17 15:04:54 -05001109 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1110
f4f051e2005-04-17 15:02:26 -05001111 return 0;
1112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
f4f051e2005-04-17 15:02:26 -05001114static void
1115qla2xxx_slave_destroy(struct scsi_device *sdev)
1116{
1117 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
1120/**
1121 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1122 * @ha: HA context
1123 *
1124 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1125 * supported addressing method.
1126 */
1127static void
1128qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1129{
1130 /* Assume 32bit DMA address */
1131 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 /*
1134 * Given the two variants pci_set_dma_mask(), allow the compiler to
1135 * assist in setting the proper dma mask.
1136 */
1137 if (sizeof(dma_addr_t) > 4) {
1138 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1139 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001140 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1141 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 if (pci_set_consistent_dma_mask(ha->pdev,
1144 DMA_64BIT_MASK)) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001145 qla_printk(KERN_DEBUG, ha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 "Failed to set 64 bit PCI consistent mask; "
1147 "using 32 bit.\n");
1148 pci_set_consistent_dma_mask(ha->pdev,
1149 DMA_32BIT_MASK);
1150 }
1151 } else {
1152 qla_printk(KERN_DEBUG, ha,
1153 "Failed to set 64 bit PCI DMA mask, falling back "
1154 "to 32 bit MASK.\n");
1155 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1156 }
1157 } else {
1158 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1159 }
1160}
1161
1162static int
1163qla2x00_iospace_config(scsi_qla_host_t *ha)
1164{
1165 unsigned long pio, pio_len, pio_flags;
1166 unsigned long mmio, mmio_len, mmio_flags;
1167
1168 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1169 pio = pci_resource_start(ha->pdev, 0);
1170 pio_len = pci_resource_len(ha->pdev, 0);
1171 pio_flags = pci_resource_flags(ha->pdev, 0);
1172 if (pio_flags & IORESOURCE_IO) {
1173 if (pio_len < MIN_IOBASE_LEN) {
1174 qla_printk(KERN_WARNING, ha,
1175 "Invalid PCI I/O region size (%s)...\n",
1176 pci_name(ha->pdev));
1177 pio = 0;
1178 }
1179 } else {
1180 qla_printk(KERN_WARNING, ha,
1181 "region #0 not a PIO resource (%s)...\n",
1182 pci_name(ha->pdev));
1183 pio = 0;
1184 }
1185
1186 /* Use MMIO operations for all accesses. */
1187 mmio = pci_resource_start(ha->pdev, 1);
1188 mmio_len = pci_resource_len(ha->pdev, 1);
1189 mmio_flags = pci_resource_flags(ha->pdev, 1);
1190
1191 if (!(mmio_flags & IORESOURCE_MEM)) {
1192 qla_printk(KERN_ERR, ha,
1193 "region #0 not an MMIO resource (%s), aborting\n",
1194 pci_name(ha->pdev));
1195 goto iospace_error_exit;
1196 }
1197 if (mmio_len < MIN_IOBASE_LEN) {
1198 qla_printk(KERN_ERR, ha,
1199 "Invalid PCI mem region size (%s), aborting\n",
1200 pci_name(ha->pdev));
1201 goto iospace_error_exit;
1202 }
1203
1204 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1205 qla_printk(KERN_WARNING, ha,
1206 "Failed to reserve PIO/MMIO regions (%s)\n",
1207 pci_name(ha->pdev));
1208
1209 goto iospace_error_exit;
1210 }
1211
1212 ha->pio_address = pio;
1213 ha->pio_length = pio_len;
1214 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1215 if (!ha->iobase) {
1216 qla_printk(KERN_ERR, ha,
1217 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1218
1219 goto iospace_error_exit;
1220 }
1221
1222 return (0);
1223
1224iospace_error_exit:
1225 return (-ENOMEM);
1226}
1227
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001228static void
1229qla2x00_enable_intrs(scsi_qla_host_t *ha)
1230{
1231 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001232 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001233
1234 spin_lock_irqsave(&ha->hardware_lock, flags);
1235 ha->interrupts_on = 1;
1236 /* enable risc and host interrupts */
1237 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1238 RD_REG_WORD(&reg->ictrl);
1239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1240
1241}
1242
1243static void
1244qla2x00_disable_intrs(scsi_qla_host_t *ha)
1245{
1246 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001247 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001248
1249 spin_lock_irqsave(&ha->hardware_lock, flags);
1250 ha->interrupts_on = 0;
1251 /* disable risc and host interrupts */
1252 WRT_REG_WORD(&reg->ictrl, 0);
1253 RD_REG_WORD(&reg->ictrl);
1254 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1255}
1256
Andrew Vasquezfca29702005-07-06 10:31:47 -07001257static void
1258qla24xx_enable_intrs(scsi_qla_host_t *ha)
1259{
1260 unsigned long flags = 0;
1261 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1262
1263 spin_lock_irqsave(&ha->hardware_lock, flags);
1264 ha->interrupts_on = 1;
1265 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1266 RD_REG_DWORD(&reg->ictrl);
1267 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1268}
1269
1270static void
1271qla24xx_disable_intrs(scsi_qla_host_t *ha)
1272{
1273 unsigned long flags = 0;
1274 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1275
1276 spin_lock_irqsave(&ha->hardware_lock, flags);
1277 ha->interrupts_on = 0;
1278 WRT_REG_DWORD(&reg->ictrl, 0);
1279 RD_REG_DWORD(&reg->ictrl);
1280 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1281}
1282
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283/*
1284 * PCI driver interface
1285 */
1286int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1287{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001288 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001289 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 struct Scsi_Host *host;
1291 scsi_qla_host_t *ha;
1292 unsigned long flags = 0;
1293 unsigned long wait_switch = 0;
1294 char pci_info[20];
1295 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001296 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001299 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Andrew Vasquezfca29702005-07-06 10:31:47 -07001301 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1302 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 if (host == NULL) {
1304 printk(KERN_WARNING
1305 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1306 goto probe_disable_device;
1307 }
1308
1309 /* Clear our data area */
1310 ha = (scsi_qla_host_t *)host->hostdata;
1311 memset(ha, 0, sizeof(scsi_qla_host_t));
1312
1313 ha->pdev = pdev;
1314 ha->host = host;
1315 ha->host_no = host->host_no;
1316 ha->brd_info = brd_info;
1317 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1318
1319 /* Configure PCI I/O space */
1320 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001321 if (ret)
1322 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 qla_printk(KERN_INFO, ha,
1325 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001326 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 spin_lock_init(&ha->hardware_lock);
1329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 ha->prev_topology = 0;
1331 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001332 ha->init_cb_size = sizeof(init_cb_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001334 /* Assign ISP specific operations. */
1335 ha->isp_ops.pci_config = qla2100_pci_config;
1336 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1337 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1338 ha->isp_ops.config_rings = qla2x00_config_rings;
1339 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1340 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1341 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001342 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001343 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1344 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1345 ha->isp_ops.intr_handler = qla2100_intr_handler;
1346 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1347 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1348 ha->isp_ops.abort_command = qla2x00_abort_command;
1349 ha->isp_ops.abort_target = qla2x00_abort_target;
1350 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1351 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1352 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1353 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1354 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001355 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1356 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001357 ha->isp_ops.fw_dump = qla2100_fw_dump;
1358 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001360 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1362 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1363 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1364 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1365 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001366 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001368 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1370 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1371 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1372 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001373 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001374 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001375 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1377 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1378 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1379 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001380 ha->isp_ops.pci_config = qla2300_pci_config;
1381 ha->isp_ops.intr_handler = qla2300_intr_handler;
1382 ha->isp_ops.fw_dump = qla2300_fw_dump;
1383 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1384 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001385 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1386 host->max_id = MAX_TARGETS_2200;
1387 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1388 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1389 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1390 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1391 ha->init_cb_size = sizeof(struct init_cb_24xx);
1392 ha->isp_ops.pci_config = qla24xx_pci_config;
1393 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1394 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1395 ha->isp_ops.config_rings = qla24xx_config_rings;
1396 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1397 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1398 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1399 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1400 if (ql2xfwloadbin)
1401 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1402 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1403 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1404 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1405 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1406 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1407 ha->isp_ops.abort_command = qla24xx_abort_command;
1408 ha->isp_ops.abort_target = qla24xx_abort_target;
1409 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1410 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1411 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
1412 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1413 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1414 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1415 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1416 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
1418 host->can_queue = ha->request_q_length + 128;
1419
1420 /* load the F/W, read paramaters, and init the H/W */
1421 ha->instance = num_hosts;
1422
1423 init_MUTEX(&ha->mbx_cmd_sem);
1424 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1425
1426 INIT_LIST_HEAD(&ha->list);
1427 INIT_LIST_HEAD(&ha->fcports);
1428 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 /*
1431 * These locks are used to prevent more than one CPU
1432 * from modifying the queue at the same time. The
1433 * higher level "host_lock" will reduce most
1434 * contention for these locks.
1435 */
1436 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 ha->dpc_pid = -1;
1439 init_completion(&ha->dpc_inited);
1440 init_completion(&ha->dpc_exited);
1441
1442 qla2x00_config_dma_addressing(ha);
1443 if (qla2x00_mem_alloc(ha)) {
1444 qla_printk(KERN_WARNING, ha,
1445 "[ERROR] Failed to allocate memory for adapter\n");
1446
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001447 ret = -ENOMEM;
1448 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450
1451 if (qla2x00_initialize_adapter(ha) &&
1452 !(ha->device_flags & DFLG_NO_CABLE)) {
1453
1454 qla_printk(KERN_WARNING, ha,
1455 "Failed to initialize adapter\n");
1456
1457 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1458 "Adapter flags %x.\n",
1459 ha->host_no, ha->device_flags));
1460
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001461 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 goto probe_failed;
1463 }
1464
1465 /*
1466 * Startup the kernel thread for this host adapter
1467 */
1468 ha->dpc_should_die = 0;
1469 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1470 if (ha->dpc_pid < 0) {
1471 qla_printk(KERN_WARNING, ha,
1472 "Unable to start DPC thread!\n");
1473
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001474 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 goto probe_failed;
1476 }
1477 wait_for_completion(&ha->dpc_inited);
1478
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001479 host->this_id = 255;
1480 host->cmd_per_lun = 3;
1481 host->unique_id = ha->instance;
1482 host->max_cmd_len = MAX_CMDSZ;
1483 host->max_channel = ha->ports - 1;
1484 host->max_lun = MAX_LUNS;
1485 host->transportt = qla2xxx_transport_template;
1486
Andrew Vasquezfca29702005-07-06 10:31:47 -07001487 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001488 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001489 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 qla_printk(KERN_WARNING, ha,
1491 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001492 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 goto probe_failed;
1494 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001495 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497 /* Initialized the timer */
1498 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1499
1500 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1501 ha->host_no, ha));
1502
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001503 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001506 reg = ha->iobase;
1507 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1508 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1509 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1510 } else {
1511 WRT_REG_WORD(&reg->isp.semaphore, 0);
1512 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1513 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Andrew Vasquezfca29702005-07-06 10:31:47 -07001515 /* Enable proper parity */
1516 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1517 if (IS_QLA2300(ha))
1518 /* SRAM parity */
1519 WRT_REG_WORD(&reg->isp.hccr,
1520 (HCCR_ENABLE_PARITY + 0x1));
1521 else
1522 /* SRAM, Instruction RAM and GP RAM parity */
1523 WRT_REG_WORD(&reg->isp.hccr,
1524 (HCCR_ENABLE_PARITY + 0x7));
1525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 }
1527 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1528
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001529 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 /* v2.19.5b6 */
1532 /*
1533 * Wait around max loop_reset_delay secs for the devices to come
1534 * on-line. We don't want Linux scanning before we are ready.
1535 *
1536 */
1537 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1538 time_before(jiffies,wait_switch) &&
1539 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1540 && (ha->device_flags & SWITCH_FOUND) ;) {
1541
1542 qla2x00_check_fabric_devices(ha);
1543
1544 msleep(10);
1545 }
1546
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001547 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 ha->flags.init_done = 1;
1549 num_hosts++;
1550
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001551 ret = scsi_add_host(host, &pdev->dev);
1552 if (ret)
1553 goto probe_failed;
1554
1555 qla2x00_alloc_sysfs_attr(ha);
1556
1557 qla2x00_init_host_attr(ha);
1558
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 qla_printk(KERN_INFO, ha, "\n"
1560 " QLogic Fibre Channel HBA Driver: %s\n"
1561 " QLogic %s - %s\n"
1562 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1563 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001564 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001565 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001566 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
8482e1182005-04-17 15:04:54 -05001568 /* Go with fc_rport registration. */
1569 list_for_each_entry(fcport, &ha->fcports, list)
1570 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 return 0;
1573
1574probe_failed:
bdf79622005-04-17 15:06:53 -05001575 fc_remove_host(ha->host);
1576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 qla2x00_free_device(ha);
1578
1579 scsi_host_put(host);
1580
1581probe_disable_device:
1582 pci_disable_device(pdev);
1583
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001584probe_out:
1585 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
1587EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1588
1589void qla2x00_remove_one(struct pci_dev *pdev)
1590{
1591 scsi_qla_host_t *ha;
1592
1593 ha = pci_get_drvdata(pdev);
1594
8482e1182005-04-17 15:04:54 -05001595 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
bdf79622005-04-17 15:06:53 -05001597 fc_remove_host(ha->host);
1598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 scsi_remove_host(ha->host);
1600
1601 qla2x00_free_device(ha);
1602
1603 scsi_host_put(ha->host);
1604
1605 pci_set_drvdata(pdev, NULL);
1606}
1607EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1608
1609static void
1610qla2x00_free_device(scsi_qla_host_t *ha)
1611{
1612 int ret;
1613
1614 /* Abort any outstanding IO descriptors. */
1615 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1616 qla2x00_cancel_io_descriptors(ha);
1617
1618 /* turn-off interrupts on the card */
1619 if (ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001620 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
1622 /* Disable timer */
1623 if (ha->timer_active)
1624 qla2x00_stop_timer(ha);
1625
1626 /* Kill the kernel thread for this host */
1627 if (ha->dpc_pid >= 0) {
1628 ha->dpc_should_die = 1;
1629 wmb();
1630 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1631 if (ret) {
1632 qla_printk(KERN_ERR, ha,
1633 "Unable to signal DPC thread -- (%d)\n", ret);
1634
1635 /* TODO: SOMETHING MORE??? */
1636 } else {
1637 wait_for_completion(&ha->dpc_exited);
1638 }
1639 }
1640
1641 qla2x00_mem_free(ha);
1642
1643
1644 ha->flags.online = 0;
1645
1646 /* Detach interrupts */
1647 if (ha->pdev->irq)
1648 free_irq(ha->pdev->irq, ha);
1649
1650 /* release io space registers */
1651 if (ha->iobase)
1652 iounmap(ha->iobase);
1653 pci_release_regions(ha->pdev);
1654
1655 pci_disable_device(ha->pdev);
1656}
1657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1660 *
1661 * Input: ha = adapter block pointer. fcport = port structure pointer.
1662 *
1663 * Return: None.
1664 *
1665 * Context:
1666 */
1667void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1668 int do_login)
1669{
8482e1182005-04-17 15:04:54 -05001670 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1671 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001672 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 * We may need to retry the login, so don't change the state of the
1674 * port but do the retries.
1675 */
1676 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1677 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1678
1679 if (!do_login)
1680 return;
1681
1682 if (fcport->login_retry == 0) {
1683 fcport->login_retry = ha->login_retry_count;
1684 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1685
1686 DEBUG(printk("scsi(%ld): Port login retry: "
1687 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1688 "id = 0x%04x retry cnt=%d\n",
1689 ha->host_no,
1690 fcport->port_name[0],
1691 fcport->port_name[1],
1692 fcport->port_name[2],
1693 fcport->port_name[3],
1694 fcport->port_name[4],
1695 fcport->port_name[5],
1696 fcport->port_name[6],
1697 fcport->port_name[7],
1698 fcport->loop_id,
1699 fcport->login_retry));
1700 }
1701}
1702
1703/*
1704 * qla2x00_mark_all_devices_lost
1705 * Updates fcport state when device goes offline.
1706 *
1707 * Input:
1708 * ha = adapter block pointer.
1709 * fcport = port structure pointer.
1710 *
1711 * Return:
1712 * None.
1713 *
1714 * Context:
1715 */
1716void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001717qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
1719 fc_port_t *fcport;
1720
1721 list_for_each_entry(fcport, &ha->fcports, list) {
1722 if (fcport->port_type != FCT_TARGET)
1723 continue;
1724
1725 /*
1726 * No point in marking the device as lost, if the device is
1727 * already DEAD.
1728 */
1729 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1730 continue;
8482e1182005-04-17 15:04:54 -05001731 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1732 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1734 }
1735}
1736
1737/*
1738* qla2x00_mem_alloc
1739* Allocates adapter memory.
1740*
1741* Returns:
1742* 0 = success.
1743* 1 = failure.
1744*/
1745static uint8_t
1746qla2x00_mem_alloc(scsi_qla_host_t *ha)
1747{
1748 char name[16];
1749 uint8_t status = 1;
1750 int retry= 10;
1751
1752 do {
1753 /*
1754 * This will loop only once if everything goes well, else some
1755 * number of retries will be performed to get around a kernel
1756 * bug where available mem is not allocated until after a
1757 * little delay and a retry.
1758 */
1759 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1760 (ha->request_q_length + 1) * sizeof(request_t),
1761 &ha->request_dma, GFP_KERNEL);
1762 if (ha->request_ring == NULL) {
1763 qla_printk(KERN_WARNING, ha,
1764 "Memory Allocation failed - request_ring\n");
1765
1766 qla2x00_mem_free(ha);
1767 msleep(100);
1768
1769 continue;
1770 }
1771
1772 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1773 (ha->response_q_length + 1) * sizeof(response_t),
1774 &ha->response_dma, GFP_KERNEL);
1775 if (ha->response_ring == NULL) {
1776 qla_printk(KERN_WARNING, ha,
1777 "Memory Allocation failed - response_ring\n");
1778
1779 qla2x00_mem_free(ha);
1780 msleep(100);
1781
1782 continue;
1783 }
1784
1785 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1786 &ha->gid_list_dma, GFP_KERNEL);
1787 if (ha->gid_list == NULL) {
1788 qla_printk(KERN_WARNING, ha,
1789 "Memory Allocation failed - gid_list\n");
1790
1791 qla2x00_mem_free(ha);
1792 msleep(100);
1793
1794 continue;
1795 }
1796
1797 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1798 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1799 if (ha->rlc_rsp == NULL) {
1800 qla_printk(KERN_WARNING, ha,
1801 "Memory Allocation failed - rlc");
1802
1803 qla2x00_mem_free(ha);
1804 msleep(100);
1805
1806 continue;
1807 }
1808
1809 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1810 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1811 DMA_POOL_SIZE, 8, 0);
1812 if (ha->s_dma_pool == NULL) {
1813 qla_printk(KERN_WARNING, ha,
1814 "Memory Allocation failed - s_dma_pool\n");
1815
1816 qla2x00_mem_free(ha);
1817 msleep(100);
1818
1819 continue;
1820 }
1821
1822 /* get consistent memory allocated for init control block */
1823 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1824 &ha->init_cb_dma);
1825 if (ha->init_cb == NULL) {
1826 qla_printk(KERN_WARNING, ha,
1827 "Memory Allocation failed - init_cb\n");
1828
1829 qla2x00_mem_free(ha);
1830 msleep(100);
1831
1832 continue;
1833 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001834 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 /* Get consistent memory allocated for Get Port Database cmd */
1837 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1838 &ha->iodesc_pd_dma);
1839 if (ha->iodesc_pd == NULL) {
1840 /* error */
1841 qla_printk(KERN_WARNING, ha,
1842 "Memory Allocation failed - iodesc_pd\n");
1843
1844 qla2x00_mem_free(ha);
1845 msleep(100);
1846
1847 continue;
1848 }
1849 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1850
1851 /* Allocate ioctl related memory. */
1852 if (qla2x00_alloc_ioctl_mem(ha)) {
1853 qla_printk(KERN_WARNING, ha,
1854 "Memory Allocation failed - ioctl_mem\n");
1855
1856 qla2x00_mem_free(ha);
1857 msleep(100);
1858
1859 continue;
1860 }
1861
1862 if (qla2x00_allocate_sp_pool(ha)) {
1863 qla_printk(KERN_WARNING, ha,
1864 "Memory Allocation failed - "
1865 "qla2x00_allocate_sp_pool()\n");
1866
1867 qla2x00_mem_free(ha);
1868 msleep(100);
1869
1870 continue;
1871 }
1872
1873 /* Allocate memory for SNS commands */
1874 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1875 /* Get consistent memory allocated for SNS commands */
1876 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1877 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1878 GFP_KERNEL);
1879 if (ha->sns_cmd == NULL) {
1880 /* error */
1881 qla_printk(KERN_WARNING, ha,
1882 "Memory Allocation failed - sns_cmd\n");
1883
1884 qla2x00_mem_free(ha);
1885 msleep(100);
1886
1887 continue;
1888 }
1889 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1890 } else {
1891 /* Get consistent memory allocated for MS IOCB */
1892 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1893 &ha->ms_iocb_dma);
1894 if (ha->ms_iocb == NULL) {
1895 /* error */
1896 qla_printk(KERN_WARNING, ha,
1897 "Memory Allocation failed - ms_iocb\n");
1898
1899 qla2x00_mem_free(ha);
1900 msleep(100);
1901
1902 continue;
1903 }
1904 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1905
1906 /*
1907 * Get consistent memory allocated for CT SNS
1908 * commands
1909 */
1910 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1911 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1912 GFP_KERNEL);
1913 if (ha->ct_sns == NULL) {
1914 /* error */
1915 qla_printk(KERN_WARNING, ha,
1916 "Memory Allocation failed - ct_sns\n");
1917
1918 qla2x00_mem_free(ha);
1919 msleep(100);
1920
1921 continue;
1922 }
1923 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1924 }
1925
1926 /* Done all allocations without any error. */
1927 status = 0;
1928
1929 } while (retry-- && status != 0);
1930
1931 if (status) {
1932 printk(KERN_WARNING
1933 "%s(): **** FAILED ****\n", __func__);
1934 }
1935
1936 return(status);
1937}
1938
1939/*
1940* qla2x00_mem_free
1941* Frees all adapter allocated memory.
1942*
1943* Input:
1944* ha = adapter block pointer.
1945*/
1946static void
1947qla2x00_mem_free(scsi_qla_host_t *ha)
1948{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 struct list_head *fcpl, *fcptemp;
1950 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 unsigned long wtime;/* max wait time if mbx cmd is busy. */
1952
1953 if (ha == NULL) {
1954 /* error */
1955 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1956 return;
1957 }
1958
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 /* Make sure all other threads are stopped. */
1960 wtime = 60 * HZ;
1961 while (ha->dpc_wait && wtime) {
1962 set_current_state(TASK_INTERRUPTIBLE);
1963 wtime = schedule_timeout(wtime);
1964 }
1965
1966 /* free ioctl memory */
1967 qla2x00_free_ioctl_mem(ha);
1968
1969 /* free sp pool */
1970 qla2x00_free_sp_pool(ha);
1971
1972 if (ha->sns_cmd)
1973 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1974 ha->sns_cmd, ha->sns_cmd_dma);
1975
1976 if (ha->ct_sns)
1977 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1978 ha->ct_sns, ha->ct_sns_dma);
1979
1980 if (ha->ms_iocb)
1981 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1982
1983 if (ha->iodesc_pd)
1984 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1985
1986 if (ha->init_cb)
1987 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1988
1989 if (ha->s_dma_pool)
1990 dma_pool_destroy(ha->s_dma_pool);
1991
1992 if (ha->rlc_rsp)
1993 dma_free_coherent(&ha->pdev->dev,
1994 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
1995 ha->rlc_rsp_dma);
1996
1997 if (ha->gid_list)
1998 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
1999 ha->gid_list_dma);
2000
2001 if (ha->response_ring)
2002 dma_free_coherent(&ha->pdev->dev,
2003 (ha->response_q_length + 1) * sizeof(response_t),
2004 ha->response_ring, ha->response_dma);
2005
2006 if (ha->request_ring)
2007 dma_free_coherent(&ha->pdev->dev,
2008 (ha->request_q_length + 1) * sizeof(request_t),
2009 ha->request_ring, ha->request_dma);
2010
2011 ha->sns_cmd = NULL;
2012 ha->sns_cmd_dma = 0;
2013 ha->ct_sns = NULL;
2014 ha->ct_sns_dma = 0;
2015 ha->ms_iocb = NULL;
2016 ha->ms_iocb_dma = 0;
2017 ha->iodesc_pd = NULL;
2018 ha->iodesc_pd_dma = 0;
2019 ha->init_cb = NULL;
2020 ha->init_cb_dma = 0;
2021
2022 ha->s_dma_pool = NULL;
2023
2024 ha->rlc_rsp = NULL;
2025 ha->rlc_rsp_dma = 0;
2026 ha->gid_list = NULL;
2027 ha->gid_list_dma = 0;
2028
2029 ha->response_ring = NULL;
2030 ha->response_dma = 0;
2031 ha->request_ring = NULL;
2032 ha->request_dma = 0;
2033
2034 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2035 fcport = list_entry(fcpl, fc_port_t, list);
2036
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 /* fc ports */
2038 list_del_init(&fcport->list);
2039 kfree(fcport);
2040 }
2041 INIT_LIST_HEAD(&ha->fcports);
2042
2043 if (ha->fw_dump)
2044 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2045
Andrew Vasquezfca29702005-07-06 10:31:47 -07002046 vfree(ha->fw_dump24);
2047
2048 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002051 ha->fw_dump24 = NULL;
2052 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 ha->fw_dump_reading = 0;
2054 ha->fw_dump_buffer = NULL;
2055}
2056
2057/*
2058 * qla2x00_allocate_sp_pool
2059 * This routine is called during initialization to allocate
2060 * memory for local srb_t.
2061 *
2062 * Input:
2063 * ha = adapter block pointer.
2064 *
2065 * Context:
2066 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002067 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 * Note: Sets the ref_count for non Null sp to one.
2069 */
2070static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002071qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072{
2073 int rval;
2074
2075 rval = QLA_SUCCESS;
2076 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2077 mempool_free_slab, srb_cachep);
2078 if (ha->srb_mempool == NULL) {
2079 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2080 rval = QLA_FUNCTION_FAILED;
2081 }
2082 return (rval);
2083}
2084
2085/*
2086 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002087 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 */
2089static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002090qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
2092 if (ha->srb_mempool) {
2093 mempool_destroy(ha->srb_mempool);
2094 ha->srb_mempool = NULL;
2095 }
2096}
2097
2098/**************************************************************************
2099* qla2x00_do_dpc
2100* This kernel thread is a task that is schedule by the interrupt handler
2101* to perform the background processing for interrupts.
2102*
2103* Notes:
2104* This task always run in the context of a kernel thread. It
2105* is kick-off by the driver's detect code and starts up
2106* up one per adapter. It immediately goes to sleep and waits for
2107* some fibre event. When either the interrupt handler or
2108* the timer routine detects a event it will one of the task
2109* bits then wake us up.
2110**************************************************************************/
2111static int
2112qla2x00_do_dpc(void *data)
2113{
2114 DECLARE_MUTEX_LOCKED(sem);
2115 scsi_qla_host_t *ha;
2116 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
2120 ha = (scsi_qla_host_t *)data;
2121
2122 lock_kernel();
2123
2124 daemonize("%s_dpc", ha->host_str);
2125 allow_signal(SIGHUP);
2126
2127 ha->dpc_wait = &sem;
2128
2129 set_user_nice(current, -20);
2130
2131 unlock_kernel();
2132
2133 complete(&ha->dpc_inited);
2134
2135 while (1) {
2136 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2137
2138 if (down_interruptible(&sem))
2139 break;
2140
2141 if (ha->dpc_should_die)
2142 break;
2143
2144 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2145
2146 /* Initialization not yet finished. Don't do anything yet. */
2147 if (!ha->flags.init_done || ha->dpc_active)
2148 continue;
2149
2150 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2151
2152 ha->dpc_active = 1;
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 ha->dpc_active = 0;
2156 continue;
2157 }
2158
2159 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2160
2161 DEBUG(printk("scsi(%ld): dpc: sched "
2162 "qla2x00_abort_isp ha = %p\n",
2163 ha->host_no, ha));
2164 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2165 &ha->dpc_flags))) {
2166
2167 if (qla2x00_abort_isp(ha)) {
2168 /* failed. retry later */
2169 set_bit(ISP_ABORT_NEEDED,
2170 &ha->dpc_flags);
2171 }
2172 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2173 }
2174 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2175 ha->host_no));
2176 }
2177
2178 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2179 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2180
2181 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2182 ha->host_no));
2183
2184 qla2x00_rst_aen(ha);
2185 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2186 }
2187
2188 /* Retry each device up to login retry count */
2189 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2190 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2191 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2192
2193 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2194 ha->host_no));
2195
2196 next_loopid = 0;
2197 list_for_each_entry(fcport, &ha->fcports, list) {
2198 if (fcport->port_type != FCT_TARGET)
2199 continue;
2200
2201 /*
2202 * If the port is not ONLINE then try to login
2203 * to it if we haven't run out of retries.
2204 */
2205 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2206 fcport->login_retry) {
2207
2208 fcport->login_retry--;
2209 if (fcport->flags & FCF_FABRIC_DEVICE) {
2210 if (fcport->flags &
2211 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002212 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002213 ha, fcport->loop_id,
2214 fcport->d_id.b.domain,
2215 fcport->d_id.b.area,
2216 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 status = qla2x00_fabric_login(
2218 ha, fcport, &next_loopid);
2219 } else
2220 status =
2221 qla2x00_local_device_login(
2222 ha, fcport->loop_id);
2223
2224 if (status == QLA_SUCCESS) {
2225 fcport->old_loop_id = fcport->loop_id;
2226
2227 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2228 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002229
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 fcport->port_login_retry_count =
2231 ha->port_down_retry_count * PORT_RETRY_TIME;
2232 atomic_set(&fcport->state, FCS_ONLINE);
2233 atomic_set(&fcport->port_down_timer,
2234 ha->port_down_retry_count * PORT_RETRY_TIME);
2235
2236 fcport->login_retry = 0;
2237 } else if (status == 1) {
2238 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2239 /* retry the login again */
2240 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2241 ha->host_no,
2242 fcport->login_retry, fcport->loop_id));
2243 } else {
2244 fcport->login_retry = 0;
2245 }
2246 }
2247 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2248 break;
2249 }
2250 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2251 ha->host_no));
2252 }
2253
2254 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2255 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2256
2257 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2258 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2259 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2262
2263 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2264 ha->host_no));
2265 }
2266
2267 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2268
2269 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2270 ha->host_no));
2271
2272 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2273 &ha->dpc_flags))) {
2274
2275 qla2x00_loop_resync(ha);
2276
2277 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2278 }
2279
2280 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2281 ha->host_no));
2282 }
2283
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2285
2286 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2287 ha->host_no));
2288
2289 qla2x00_rescan_fcports(ha);
2290
2291 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2292 "end.\n",
2293 ha->host_no));
2294 }
2295
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002297 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 ha->dpc_active = 0;
2300 } /* End of while(1) */
2301
2302 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2303
2304 /*
2305 * Make sure that nobody tries to wake us up again.
2306 */
2307 ha->dpc_wait = NULL;
2308 ha->dpc_active = 0;
2309
2310 complete_and_exit(&ha->dpc_exited, 0);
2311}
2312
2313/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314* qla2x00_rst_aen
2315* Processes asynchronous reset.
2316*
2317* Input:
2318* ha = adapter block pointer.
2319*/
2320static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002321qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
2323 if (ha->flags.online && !ha->flags.reset_active &&
2324 !atomic_read(&ha->loop_down_timer) &&
2325 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2326 do {
2327 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2328
2329 /*
2330 * Issue marker command only when we are going to start
2331 * the I/O.
2332 */
2333 ha->marker_needed = 1;
2334 } while (!atomic_read(&ha->loop_down_timer) &&
2335 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2336 }
2337}
2338
f4f051e2005-04-17 15:02:26 -05002339static void
2340qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2341{
2342 struct scsi_cmnd *cmd = sp->cmd;
2343
2344 if (sp->flags & SRB_DMA_VALID) {
2345 if (cmd->use_sg) {
2346 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2347 cmd->use_sg, cmd->sc_data_direction);
2348 } else if (cmd->request_bufflen) {
2349 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2350 cmd->request_bufflen, cmd->sc_data_direction);
2351 }
2352 sp->flags &= ~SRB_DMA_VALID;
2353 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002354 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002355}
2356
2357void
2358qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2359{
2360 struct scsi_cmnd *cmd = sp->cmd;
2361
2362 qla2x00_sp_free_dma(ha, sp);
2363
f4f051e2005-04-17 15:02:26 -05002364 mempool_free(sp, ha->srb_mempool);
2365
2366 cmd->scsi_done(cmd);
2367}
bdf79622005-04-17 15:06:53 -05002368
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369/**************************************************************************
2370* qla2x00_timer
2371*
2372* Description:
2373* One second timer
2374*
2375* Context: Interrupt
2376***************************************************************************/
2377static void
2378qla2x00_timer(scsi_qla_host_t *ha)
2379{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 unsigned long cpu_flags = 0;
2381 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 int start_dpc = 0;
2383 int index;
2384 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002385 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
2387 /*
2388 * Ports - Port down timer.
2389 *
2390 * Whenever, a port is in the LOST state we start decrementing its port
2391 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002392 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 */
2394 t = 0;
2395 list_for_each_entry(fcport, &ha->fcports, list) {
2396 if (fcport->port_type != FCT_TARGET)
2397 continue;
2398
2399 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2400
2401 if (atomic_read(&fcport->port_down_timer) == 0)
2402 continue;
2403
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002404 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002406
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002408 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 ha->host_no,
2410 t, atomic_read(&fcport->port_down_timer)));
2411 }
2412 t++;
2413 } /* End of for fcport */
2414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
2416 /* Loop down handler. */
2417 if (atomic_read(&ha->loop_down_timer) > 0 &&
2418 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2419
2420 if (atomic_read(&ha->loop_down_timer) ==
2421 ha->loop_down_abort_time) {
2422
2423 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2424 "queues before time expire\n",
2425 ha->host_no));
2426
2427 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002428 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
2430 /* Schedule an ISP abort to return any tape commands. */
2431 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2432 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2433 index++) {
bdf79622005-04-17 15:06:53 -05002434 fc_port_t *sfcp;
2435
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 sp = ha->outstanding_cmds[index];
2437 if (!sp)
2438 continue;
bdf79622005-04-17 15:06:53 -05002439 sfcp = sp->fcport;
2440 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 continue;
2442
2443 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2444 break;
2445 }
2446 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2447
2448 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2449 start_dpc++;
2450 }
2451
2452 /* if the loop has been down for 4 minutes, reinit adapter */
2453 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2454 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2455 "restarting queues.\n",
2456 ha->host_no));
2457
2458 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2459 start_dpc++;
2460
2461 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2462 DEBUG(printk("scsi(%ld): Loop down - "
2463 "aborting ISP.\n",
2464 ha->host_no));
2465 qla_printk(KERN_WARNING, ha,
2466 "Loop down - aborting ISP.\n");
2467
2468 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2469 }
2470 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002471 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 ha->host_no,
2473 atomic_read(&ha->loop_down_timer)));
2474 }
2475
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 /* Schedule the DPC routine if needed */
2477 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2478 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2479 start_dpc ||
2480 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002481 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2483 ha->dpc_wait && !ha->dpc_active) {
2484
2485 up(ha->dpc_wait);
2486 }
2487
2488 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2489}
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491/* XXX(hch): crude hack to emulate a down_timeout() */
2492int
2493qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2494{
2495 const unsigned int step = HZ/10;
2496
2497 do {
2498 if (!down_trylock(sema))
2499 return 0;
2500 set_current_state(TASK_INTERRUPTIBLE);
2501 if (schedule_timeout(step))
2502 break;
2503 } while ((timeout -= step) > 0);
2504
2505 return -ETIMEDOUT;
2506}
2507
Andrew Vasquezfca29702005-07-06 10:31:47 -07002508static struct qla_board_info qla_board_tbl[] = {
2509 {
2510 .drv_name = "qla2400",
2511 .isp_name = "ISP2422",
2512 .fw_fname = "ql2400_fw.bin",
2513 .sht = &qla24xx_driver_template,
2514 },
2515 {
2516 .drv_name = "qla2400",
2517 .isp_name = "ISP2432",
2518 .fw_fname = "ql2400_fw.bin",
2519 .sht = &qla24xx_driver_template,
2520 },
2521};
2522
2523static struct pci_device_id qla2xxx_pci_tbl[] = {
2524 {
2525 .vendor = PCI_VENDOR_ID_QLOGIC,
2526 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2527 .subvendor = PCI_ANY_ID,
2528 .subdevice = PCI_ANY_ID,
2529 .driver_data = (unsigned long)&qla_board_tbl[0],
2530 },
2531 {
2532 .vendor = PCI_VENDOR_ID_QLOGIC,
2533 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2534 .subvendor = PCI_ANY_ID,
2535 .subdevice = PCI_ANY_ID,
2536 .driver_data = (unsigned long)&qla_board_tbl[1],
2537 },
2538 {0, 0},
2539};
2540MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2541
2542static int __devinit
2543qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2544{
2545 return qla2x00_probe_one(pdev,
2546 (struct qla_board_info *)id->driver_data);
2547}
2548
2549static void __devexit
2550qla2xxx_remove_one(struct pci_dev *pdev)
2551{
2552 qla2x00_remove_one(pdev);
2553}
2554
2555static struct pci_driver qla2xxx_pci_driver = {
2556 .name = "qla2xxx",
2557 .id_table = qla2xxx_pci_tbl,
2558 .probe = qla2xxx_probe_one,
2559 .remove = __devexit_p(qla2xxx_remove_one),
2560};
2561
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562/**
2563 * qla2x00_module_init - Module initialization.
2564 **/
2565static int __init
2566qla2x00_module_init(void)
2567{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002568 int ret = 0;
2569
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002571 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 SLAB_HWCACHE_ALIGN, NULL, NULL);
2573 if (srb_cachep == NULL) {
2574 printk(KERN_ERR
2575 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2576 return -ENOMEM;
2577 }
2578
2579 /* Derive version string. */
2580 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2581#if DEBUG_QLA2100
2582 strcat(qla2x00_version_str, "-debug");
2583#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002584 qla2xxx_transport_template =
2585 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 if (!qla2xxx_transport_template)
2587 return -ENODEV;
2588
2589 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002590 ret = pci_module_init(&qla2xxx_pci_driver);
2591 if (ret) {
2592 kmem_cache_destroy(srb_cachep);
2593 fc_release_transport(qla2xxx_transport_template);
2594 }
2595 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
2598/**
2599 * qla2x00_module_exit - Module cleanup.
2600 **/
2601static void __exit
2602qla2x00_module_exit(void)
2603{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002604 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002605 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 fc_release_transport(qla2xxx_transport_template);
2607}
2608
2609module_init(qla2x00_module_init);
2610module_exit(qla2x00_module_exit);
2611
2612MODULE_AUTHOR("QLogic Corporation");
2613MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2614MODULE_LICENSE("GPL");
2615MODULE_VERSION(QLA2XXX_VERSION);