blob: d960637fd56a391b7d742586cd36bbafa48f0505 [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
5 * Copyright (C) 2003-2004 QLogic Corporation
6 * (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 */
39char srb_cachep_name[16];
40kmem_cache_t *srb_cachep;
41
42/*
43 * Stats for all adpaters.
44 */
45struct _qla2x00stats qla2x00_stats;
46
47/*
48 * Ioctl related information.
49 */
50int num_hosts;
51int apiHBAInstance;
52
53/*
54 * Module parameter information and variables
55 */
56int ql2xmaxqdepth;
57module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
58MODULE_PARM_DESC(ql2xmaxqdepth,
59 "Maximum queue depth to report for target devices.");
60
61int ql2xlogintimeout = 20;
62module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
63MODULE_PARM_DESC(ql2xlogintimeout,
64 "Login timeout value in seconds.");
65
8482e1182005-04-17 15:04:54 -050066int qlport_down_retry = 30;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
68MODULE_PARM_DESC(qlport_down_retry,
69 "Maximum number of command retries to a port that returns"
70 "a PORT-DOWN status.");
71
72int ql2xretrycount = 20;
73module_param(ql2xretrycount, int, S_IRUGO|S_IWUSR);
74MODULE_PARM_DESC(ql2xretrycount,
75 "Maximum number of mid-layer retries allowed for a command. "
76 "Default value is 20, ");
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078int ql2xplogiabsentdevice;
79module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
80MODULE_PARM_DESC(ql2xplogiabsentdevice,
81 "Option to enable PLOGI to devices that are not present after "
82 "a Fabric scan. This is needed for several broken switches."
83 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
84
85int ql2xenablezio = 0;
86module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
87MODULE_PARM_DESC(ql2xenablezio,
88 "Option to enable ZIO:If 1 then enable it otherwise"
89 " use the default set in the NVRAM."
90 " Default is 0 : disabled");
91
92int ql2xintrdelaytimer = 10;
93module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
94MODULE_PARM_DESC(ql2xintrdelaytimer,
95 "ZIO: Waiting time for Firmware before it generates an "
96 "interrupt to the host to notify completion of request.");
97
98int ConfigRequired;
99module_param(ConfigRequired, int, S_IRUGO|S_IRUSR);
100MODULE_PARM_DESC(ConfigRequired,
101 "If 1, then only configured devices passed in through the"
102 "ql2xopts parameter will be presented to the OS");
103
104int Bind = BIND_BY_PORT_NAME;
105module_param(Bind, int, S_IRUGO|S_IRUSR);
106MODULE_PARM_DESC(Bind,
107 "Target persistent binding method: "
108 "0 by Portname (default); 1 by PortID; 2 by Nodename. ");
109
110int ql2xsuspendcount = SUSPEND_COUNT;
111module_param(ql2xsuspendcount, int, S_IRUGO|S_IWUSR);
112MODULE_PARM_DESC(ql2xsuspendcount,
113 "Number of 6-second suspend iterations to perform while a "
114 "target returns a <NOT READY> status. Default is 10 "
115 "iterations.");
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117int ql2xloginretrycount = 0;
118module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
119MODULE_PARM_DESC(ql2xloginretrycount,
120 "Specify an alternate value for the NVRAM login retry count.");
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static void qla2x00_free_device(scsi_qla_host_t *);
123
124static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
125
126/*
127 * SCSI host template entry points
128 */
129static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500130static int qla2xxx_slave_alloc(struct scsi_device *);
131static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
133 void (*fn)(struct scsi_cmnd *));
134static int qla2xxx_eh_abort(struct scsi_cmnd *);
135static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
136static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
137static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
138static int qla2x00_loop_reset(scsi_qla_host_t *ha);
139static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141static struct scsi_host_template qla2x00_driver_template = {
142 .module = THIS_MODULE,
143 .name = "qla2xxx",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .queuecommand = qla2x00_queuecommand,
145
146 .eh_abort_handler = qla2xxx_eh_abort,
147 .eh_device_reset_handler = qla2xxx_eh_device_reset,
148 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
149 .eh_host_reset_handler = qla2xxx_eh_host_reset,
150
151 .slave_configure = qla2xxx_slave_configure,
152
f4f051e2005-04-17 15:02:26 -0500153 .slave_alloc = qla2xxx_slave_alloc,
154 .slave_destroy = qla2xxx_slave_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 .this_id = -1,
156 .cmd_per_lun = 3,
157 .use_clustering = ENABLE_CLUSTERING,
158 .sg_tablesize = SG_ALL,
159
160 /*
161 * The RISC allows for each command to transfer (2^32-1) bytes of data,
162 * which equates to 0x800000 sectors.
163 */
164 .max_sectors = 0xFFFF,
165};
166
167static struct scsi_transport_template *qla2xxx_transport_template = NULL;
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/* TODO Convert to inlines
170 *
171 * Timer routines
172 */
173#define WATCH_INTERVAL 1 /* number of seconds */
174
175static void qla2x00_timer(scsi_qla_host_t *);
176
177static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
178 void *, unsigned long);
179static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
180static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
181
182static inline void
183qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
184{
185 init_timer(&ha->timer);
186 ha->timer.expires = jiffies + interval * HZ;
187 ha->timer.data = (unsigned long)ha;
188 ha->timer.function = (void (*)(unsigned long))func;
189 add_timer(&ha->timer);
190 ha->timer_active = 1;
191}
192
193static inline void
194qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
195{
196 mod_timer(&ha->timer, jiffies + interval * HZ);
197}
198
199static __inline__ void
200qla2x00_stop_timer(scsi_qla_host_t *ha)
201{
202 del_timer_sync(&ha->timer);
203 ha->timer_active = 0;
204}
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static int qla2x00_do_dpc(void *data);
207
208static void qla2x00_rst_aen(scsi_qla_host_t *);
209
210static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
211static void qla2x00_mem_free(scsi_qla_host_t *ha);
212static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
213static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500214static srb_t *qla2x00_get_new_sp(scsi_qla_host_t *);
215static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
216void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218/* -------------------------------------------------------------------------- */
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220static char *
221qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
222{
223 static char *pci_bus_modes[] = {
224 "33", "66", "100", "133",
225 };
226 uint16_t pci_bus;
227
228 strcpy(str, "PCI");
229 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
230 if (pci_bus) {
231 strcat(str, "-X (");
232 strcat(str, pci_bus_modes[pci_bus]);
233 } else {
234 pci_bus = (ha->pci_attr & BIT_8) >> 8;
235 strcat(str, " (");
236 strcat(str, pci_bus_modes[pci_bus]);
237 }
238 strcat(str, " MHz)");
239
240 return (str);
241}
242
243char *
244qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
245{
246 char un_str[10];
247
248 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
249 ha->fw_minor_version,
250 ha->fw_subminor_version);
251
252 if (ha->fw_attributes & BIT_9) {
253 strcat(str, "FLX");
254 return (str);
255 }
256
257 switch (ha->fw_attributes & 0xFF) {
258 case 0x7:
259 strcat(str, "EF");
260 break;
261 case 0x17:
262 strcat(str, "TP");
263 break;
264 case 0x37:
265 strcat(str, "IP");
266 break;
267 case 0x77:
268 strcat(str, "VI");
269 break;
270 default:
271 sprintf(un_str, "(%x)", ha->fw_attributes);
272 strcat(str, un_str);
273 break;
274 }
275 if (ha->fw_attributes & 0x100)
276 strcat(str, "X");
277
278 return (str);
279}
280
281/**************************************************************************
282* qla2x00_queuecommand
283*
284* Description:
285* Queue a command to the controller.
286*
287* Input:
288* cmd - pointer to Scsi cmd structure
289* fn - pointer to Scsi done function
290*
291* Returns:
292* 0 - Always
293*
294* Note:
295* The mid-level driver tries to ensures that queuecommand never gets invoked
296* concurrently with itself or the interrupt handler (although the
297* interrupt handler may call this routine as part of request-completion
298* handling).
299**************************************************************************/
300static int
f4f051e2005-04-17 15:02:26 -0500301qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
f4f051e2005-04-17 15:02:26 -0500303 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500304 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500305 srb_t *sp;
306 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
bdf79622005-04-17 15:06:53 -0500308 if (!fcport) {
f4f051e2005-04-17 15:02:26 -0500309 cmd->result = DID_NO_CONNECT << 16;
310 goto qc_fail_command;
311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
f4f051e2005-04-17 15:02:26 -0500313 if (atomic_read(&fcport->state) != FCS_ONLINE) {
314 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
315 atomic_read(&ha->loop_state) == LOOP_DEAD) {
316 cmd->result = DID_NO_CONNECT << 16;
317 goto qc_fail_command;
318 }
319 goto qc_host_busy;
320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 spin_unlock_irq(ha->host->host_lock);
323
f4f051e2005-04-17 15:02:26 -0500324 /* Allocate a command packet from the "sp" pool. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
f4f051e2005-04-17 15:02:26 -0500326 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328
f4f051e2005-04-17 15:02:26 -0500329 sp->ha = ha;
bdf79622005-04-17 15:06:53 -0500330 sp->fcport = fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 sp->cmd = cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 sp->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 sp->err_id = 0;
334
f4f051e2005-04-17 15:02:26 -0500335 CMD_SP(cmd) = (void *)sp;
336 cmd->scsi_done = done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
f4f051e2005-04-17 15:02:26 -0500338 rval = qla2x00_start_scsi(sp);
339 if (rval != QLA_SUCCESS)
340 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
f4f051e2005-04-17 15:02:26 -0500342 /* Manage unprocessed RIO/ZIO commands in response queue. */
343 if (ha->flags.online && ha->flags.process_response_queue &&
344 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
345 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
f4f051e2005-04-17 15:02:26 -0500347 spin_lock_irqsave(&ha->hardware_lock, flags);
348 qla2x00_process_response_queue(ha);
349 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 spin_lock_irq(ha->host->host_lock);
353
f4f051e2005-04-17 15:02:26 -0500354 return 0;
355
356qc_host_busy_free_sp:
357 qla2x00_sp_free_dma(ha, sp);
358 CMD_SP(cmd) = NULL;
359 mempool_free(sp, ha->srb_mempool);
360
361qc_host_busy_lock:
362 spin_lock_irq(ha->host->host_lock);
363
364qc_host_busy:
365 return SCSI_MLQUEUE_HOST_BUSY;
366
367qc_fail_command:
368 done(cmd);
369
370 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
373/*
374 * qla2x00_eh_wait_on_command
375 * Waits for the command to be returned by the Firmware for some
376 * max time.
377 *
378 * Input:
379 * ha = actual ha whose done queue will contain the command
380 * returned by firmware.
381 * cmd = Scsi Command to wait on.
382 * flag = Abort/Reset(Bus or Device Reset)
383 *
384 * Return:
385 * Not Found : 0
386 * Found : 1
387 */
388static int
389qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
390{
391#define ABORT_POLLING_PERIOD HZ
f4f051e2005-04-17 15:02:26 -0500392#define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
393 unsigned long wait_iter = ABORT_WAIT_ITER;
394 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
f4f051e2005-04-17 15:02:26 -0500396 while (CMD_SP(cmd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 set_current_state(TASK_UNINTERRUPTIBLE);
398 schedule_timeout(ABORT_POLLING_PERIOD);
399
f4f051e2005-04-17 15:02:26 -0500400 if (--wait_iter)
401 break;
402 }
403 if (CMD_SP(cmd))
404 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
f4f051e2005-04-17 15:02:26 -0500406 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
409/*
410 * qla2x00_wait_for_hba_online
411 * Wait till the HBA is online after going through
412 * <= MAX_RETRIES_OF_ISP_ABORT or
413 * finally HBA is disabled ie marked offline
414 *
415 * Input:
416 * ha - pointer to host adapter structure
417 *
418 * Note:
419 * Does context switching-Release SPIN_LOCK
420 * (if any) before calling this routine.
421 *
422 * Return:
423 * Success (Adapter is online) : 0
424 * Failed (Adapter is offline/disabled) : 1
425 */
426static int
427qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
428{
429 int return_status;
430 unsigned long wait_online;
431
432 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
433 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
434 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
435 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
436 ha->dpc_active) && time_before(jiffies, wait_online)) {
437
438 msleep(1000);
439 }
440 if (ha->flags.online)
441 return_status = QLA_SUCCESS;
442 else
443 return_status = QLA_FUNCTION_FAILED;
444
445 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
446
447 return (return_status);
448}
449
450/*
451 * qla2x00_wait_for_loop_ready
452 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
453 * to be in LOOP_READY state.
454 * Input:
455 * ha - pointer to host adapter structure
456 *
457 * Note:
458 * Does context switching-Release SPIN_LOCK
459 * (if any) before calling this routine.
460 *
461 *
462 * Return:
463 * Success (LOOP_READY) : 0
464 * Failed (LOOP_NOT_READY) : 1
465 */
466static inline int
467qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
468{
469 int return_status = QLA_SUCCESS;
470 unsigned long loop_timeout ;
471
472 /* wait for 5 min at the max for loop to be ready */
473 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
474
475 while ((!atomic_read(&ha->loop_down_timer) &&
476 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
477 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
478 atomic_read(&ha->loop_state) != LOOP_READY) {
479 msleep(1000);
480 if (time_after_eq(jiffies, loop_timeout)) {
481 return_status = QLA_FUNCTION_FAILED;
482 break;
483 }
484 }
485 return (return_status);
486}
487
488/**************************************************************************
489* qla2xxx_eh_abort
490*
491* Description:
492* The abort function will abort the specified command.
493*
494* Input:
495* cmd = Linux SCSI command packet to be aborted.
496*
497* Returns:
498* Either SUCCESS or FAILED.
499*
500* Note:
501**************************************************************************/
502int
503qla2xxx_eh_abort(struct scsi_cmnd *cmd)
504{
f4f051e2005-04-17 15:02:26 -0500505 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
506 srb_t *sp;
507 int ret, i;
508 unsigned int id, lun;
509 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700510 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
f4f051e2005-04-17 15:02:26 -0500512 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
f4f051e2005-04-17 15:02:26 -0500515 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
f4f051e2005-04-17 15:02:26 -0500517 id = cmd->device->id;
518 lun = cmd->device->lun;
519 serial = cmd->serial_number;
520
521 /* Check active list for command command. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 spin_unlock_irq(ha->host->host_lock);
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700523 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500524 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
525 sp = ha->outstanding_cmds[i];
526
527 if (sp == NULL)
528 continue;
529
530 if (sp->cmd != cmd)
531 continue;
532
533 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
534 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
535 sp->state));
536 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
537
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700538 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500539 if (qla2x00_abort_command(ha, sp)) {
540 DEBUG2(printk("%s(%ld): abort_command "
541 "mbx failed.\n", __func__, ha->host_no));
542 } else {
543 DEBUG3(printk("%s(%ld): abort_command "
544 "mbx success.\n", __func__, ha->host_no));
545 ret = SUCCESS;
546 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700547 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500548
549 break;
550 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700551 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500552
553 /* Wait for the command to be returned. */
554 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500555 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
556 qla_printk(KERN_ERR, ha,
557 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
558 "%x.\n", ha->host_no, id, lun, serial, ret);
559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561 spin_lock_irq(ha->host->host_lock);
562
f4f051e2005-04-17 15:02:26 -0500563 qla_printk(KERN_INFO, ha,
564 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
565 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
f4f051e2005-04-17 15:02:26 -0500567 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
569
570/**************************************************************************
571* qla2x00_eh_wait_for_pending_target_commands
572*
573* Description:
574* Waits for all the commands to come back from the specified target.
575*
576* Input:
577* ha - pointer to scsi_qla_host structure.
578* t - target
579* Returns:
580* Either SUCCESS or FAILED.
581*
582* Note:
583**************************************************************************/
584static int
585qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
586{
587 int cnt;
588 int status;
589 srb_t *sp;
590 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700591 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 status = 0;
594
595 /*
596 * Waiting for all commands for the designated target in the active
597 * array
598 */
599 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700600 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 sp = ha->outstanding_cmds[cnt];
602 if (sp) {
603 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (cmd->device->id == t) {
606 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
607 status = 1;
608 break;
609 }
610 }
f4f051e2005-04-17 15:02:26 -0500611 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614 }
615 return (status);
616}
617
618
619/**************************************************************************
620* qla2xxx_eh_device_reset
621*
622* Description:
623* The device reset function will reset the target and abort any
624* executing commands.
625*
626* NOTE: The use of SP is undefined within this context. Do *NOT*
627* attempt to use this value, even if you determine it is
628* non-null.
629*
630* Input:
631* cmd = Linux SCSI command packet of the command that cause the
632* bus device reset.
633*
634* Returns:
635* SUCCESS/FAILURE (defined as macro in scsi.h).
636*
637**************************************************************************/
638int
639qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
640{
f4f051e2005-04-17 15:02:26 -0500641 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500642 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500643 srb_t *sp;
644 int ret;
645 unsigned int id, lun;
646 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
f4f051e2005-04-17 15:02:26 -0500648 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
f4f051e2005-04-17 15:02:26 -0500650 id = cmd->device->id;
651 lun = cmd->device->lun;
652 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
f4f051e2005-04-17 15:02:26 -0500654 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500655 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500656 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500659 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 spin_unlock_irq(ha->host->host_lock);
662
663 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 spin_lock_irq(ha->host->host_lock);
665 goto eh_dev_reset_done;
666 }
667
668 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500669 if (qla2x00_device_reset(ha, fcport) == 0)
670 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500673 if (ret == SUCCESS) {
674 if (fcport->flags & FC_FABRIC_DEVICE) {
675 qla2x00_fabric_logout(ha, fcport->loop_id);
676 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
678 }
679#endif
680 } else {
681 DEBUG2(printk(KERN_INFO
682 "%s failed: loop not ready\n",__func__);)
683 }
684
f4f051e2005-04-17 15:02:26 -0500685 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 DEBUG3(printk("%s(%ld): device reset failed\n",
687 __func__, ha->host_no));
688 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
689 __func__);
690
691 goto eh_dev_reset_done;
692 }
693
694 /*
695 * If we are coming down the EH path, wait for all commands to
696 * complete for the device.
697 */
698 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500699 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
700 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
f4f051e2005-04-17 15:02:26 -0500702 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 DEBUG3(printk("%s(%ld): failed while waiting for "
704 "commands\n", __func__, ha->host_no));
705 qla_printk(KERN_INFO, ha,
706 "%s: failed while waiting for commands\n",
707 __func__);
708
709 goto eh_dev_reset_done;
710 }
711 }
712
713 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500714 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500717 spin_lock_irq(ha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
f4f051e2005-04-17 15:02:26 -0500719 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
721
722/**************************************************************************
723* qla2x00_eh_wait_for_pending_commands
724*
725* Description:
726* Waits for all the commands to come back from the specified host.
727*
728* Input:
729* ha - pointer to scsi_qla_host structure.
730*
731* Returns:
732* 1 : SUCCESS
733* 0 : FAILED
734*
735* Note:
736**************************************************************************/
737static int
738qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
739{
740 int cnt;
741 int status;
742 srb_t *sp;
743 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700744 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 status = 1;
747
748 /*
749 * Waiting for all commands for the designated target in the active
750 * array
751 */
752 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700753 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 sp = ha->outstanding_cmds[cnt];
755 if (sp) {
756 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 status = qla2x00_eh_wait_on_command(ha, cmd);
759 if (status == 0)
760 break;
761 }
762 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765 }
766 return (status);
767}
768
769
770/**************************************************************************
771* qla2xxx_eh_bus_reset
772*
773* Description:
774* The bus reset function will reset the bus and abort any executing
775* commands.
776*
777* Input:
778* cmd = Linux SCSI command packet of the command that cause the
779* bus reset.
780*
781* Returns:
782* SUCCESS/FAILURE (defined as macro in scsi.h).
783*
784**************************************************************************/
785int
786qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
787{
f4f051e2005-04-17 15:02:26 -0500788 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500789 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500791 int ret;
792 unsigned int id, lun;
793 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
f4f051e2005-04-17 15:02:26 -0500795 ret = FAILED;
796
797 id = cmd->device->id;
798 lun = cmd->device->lun;
799 serial = cmd->serial_number;
800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500802 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500803 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500806 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 spin_unlock_irq(ha->host->host_lock);
809
810 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
811 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500812 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814
815 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500816 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
817 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
f4f051e2005-04-17 15:02:26 -0500819 if (ret == FAILED)
820 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 /* Waiting for our command in done_queue to be returned to OS.*/
823 if (cmd->device->host->eh_active)
824 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500825 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
f4f051e2005-04-17 15:02:26 -0500827eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500829 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
f4f051e2005-04-17 15:02:26 -0500831 spin_lock_irq(ha->host->host_lock);
832
833 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
836/**************************************************************************
837* qla2xxx_eh_host_reset
838*
839* Description:
840* The reset function will reset the Adapter.
841*
842* Input:
843* cmd = Linux SCSI command packet of the command that cause the
844* adapter reset.
845*
846* Returns:
847* Either SUCCESS or FAILED.
848*
849* Note:
850**************************************************************************/
851int
852qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
853{
f4f051e2005-04-17 15:02:26 -0500854 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500855 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500856 srb_t *sp;
857 int ret;
858 unsigned int id, lun;
859 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
f4f051e2005-04-17 15:02:26 -0500861 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
f4f051e2005-04-17 15:02:26 -0500863 id = cmd->device->id;
864 lun = cmd->device->lun;
865 serial = cmd->serial_number;
866
867 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500868 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500869 return ret;
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500872 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 spin_unlock_irq(ha->host->host_lock);
875
876 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500877 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 /*
880 * Fixme-may be dpc thread is active and processing
881 * loop_resync,so wait a while for it to
882 * be completed and then issue big hammer.Otherwise
883 * it may cause I/O failure as big hammer marks the
884 * devices as lost kicking of the port_down_timer
885 * while dpc is stuck for the mailbox to complete.
886 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 qla2x00_wait_for_loop_ready(ha);
888 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
889 if (qla2x00_abort_isp(ha)) {
890 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
891 /* failed. schedule dpc to try */
892 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
893
894 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500895 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500900 if (qla2x00_eh_wait_for_pending_commands(ha))
901 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
f4f051e2005-04-17 15:02:26 -0500903eh_host_reset_lock:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 spin_lock_irq(ha->host->host_lock);
905
f4f051e2005-04-17 15:02:26 -0500906 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
907 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
f4f051e2005-04-17 15:02:26 -0500909 return ret;
910}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912/*
913* qla2x00_loop_reset
914* Issue loop reset.
915*
916* Input:
917* ha = adapter block pointer.
918*
919* Returns:
920* 0 = success
921*/
922static int
923qla2x00_loop_reset(scsi_qla_host_t *ha)
924{
925 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -0500926 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 if (ha->flags.enable_lip_reset) {
929 status = qla2x00_lip_reset(ha);
930 }
931
932 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -0500933 list_for_each_entry(fcport, &ha->fcports, list) {
934 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 continue;
936
bdf79622005-04-17 15:06:53 -0500937 status = qla2x00_target_reset(ha, fcport);
938 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 }
941 }
942
943 if (status == QLA_SUCCESS &&
944 ((!ha->flags.enable_target_reset &&
945 !ha->flags.enable_lip_reset) ||
946 ha->flags.enable_lip_full_login)) {
947
948 status = qla2x00_full_login_lip(ha);
949 }
950
951 /* Issue marker command only when we are going to start the I/O */
952 ha->marker_needed = 1;
953
954 if (status) {
955 /* Empty */
956 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
957 __func__,
958 ha->host_no);)
959 } else {
960 /* Empty */
961 DEBUG3(printk("%s(%ld): exiting normally.\n",
962 __func__,
963 ha->host_no);)
964 }
965
966 return(status);
967}
968
969/*
970 * qla2x00_device_reset
971 * Issue bus device reset message to the target.
972 *
973 * Input:
974 * ha = adapter block pointer.
975 * t = SCSI ID.
976 * TARGET_QUEUE_LOCK must be released.
977 * ADAPTER_STATE_LOCK must be released.
978 *
979 * Context:
980 * Kernel context.
981 */
982static int
983qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
984{
985 /* Abort Target command will clear Reservation */
986 return qla2x00_abort_target(reset_fcport);
987}
988
f4f051e2005-04-17 15:02:26 -0500989static int
990qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991{
992 scsi_qla_host_t *ha = to_qla_host(sdev->host);
bdf79622005-04-17 15:06:53 -0500993 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
994 fc_port_t *fcport;
995 int found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
bdf79622005-04-17 15:06:53 -0500997 if (!rport)
f4f051e2005-04-17 15:02:26 -0500998 return -ENXIO;
999
bdf79622005-04-17 15:06:53 -05001000 found = 0;
1001 list_for_each_entry(fcport, &ha->fcports, list) {
1002 if (rport->port_name ==
1003 be64_to_cpu(*(uint64_t *)fcport->port_name)) {
1004 found++;
1005 break;
1006 }
bdf79622005-04-17 15:06:53 -05001007 }
1008 if (!found)
1009 return -ENXIO;
1010
1011 sdev->hostdata = fcport;
f4f051e2005-04-17 15:02:26 -05001012
1013 return 0;
1014}
1015
1016static int
1017qla2xxx_slave_configure(struct scsi_device *sdev)
1018{
8482e1182005-04-17 15:04:54 -05001019 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1020 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1021
f4f051e2005-04-17 15:02:26 -05001022 if (sdev->tagged_supported)
1023 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 else
f4f051e2005-04-17 15:02:26 -05001025 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
8482e1182005-04-17 15:04:54 -05001027 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1028
f4f051e2005-04-17 15:02:26 -05001029 return 0;
1030}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
f4f051e2005-04-17 15:02:26 -05001032static void
1033qla2xxx_slave_destroy(struct scsi_device *sdev)
1034{
1035 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
1038/**
1039 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1040 * @ha: HA context
1041 *
1042 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1043 * supported addressing method.
1044 */
1045static void
1046qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1047{
1048 /* Assume 32bit DMA address */
1049 ha->flags.enable_64bit_addressing = 0;
1050 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1051 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1052
1053 /*
1054 * Given the two variants pci_set_dma_mask(), allow the compiler to
1055 * assist in setting the proper dma mask.
1056 */
1057 if (sizeof(dma_addr_t) > 4) {
1058 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1059 ha->flags.enable_64bit_addressing = 1;
1060 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1061 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1062
1063 if (pci_set_consistent_dma_mask(ha->pdev,
1064 DMA_64BIT_MASK)) {
1065 qla_printk(KERN_DEBUG, ha,
1066 "Failed to set 64 bit PCI consistent mask; "
1067 "using 32 bit.\n");
1068 pci_set_consistent_dma_mask(ha->pdev,
1069 DMA_32BIT_MASK);
1070 }
1071 } else {
1072 qla_printk(KERN_DEBUG, ha,
1073 "Failed to set 64 bit PCI DMA mask, falling back "
1074 "to 32 bit MASK.\n");
1075 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1076 }
1077 } else {
1078 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1079 }
1080}
1081
1082static int
1083qla2x00_iospace_config(scsi_qla_host_t *ha)
1084{
1085 unsigned long pio, pio_len, pio_flags;
1086 unsigned long mmio, mmio_len, mmio_flags;
1087
1088 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1089 pio = pci_resource_start(ha->pdev, 0);
1090 pio_len = pci_resource_len(ha->pdev, 0);
1091 pio_flags = pci_resource_flags(ha->pdev, 0);
1092 if (pio_flags & IORESOURCE_IO) {
1093 if (pio_len < MIN_IOBASE_LEN) {
1094 qla_printk(KERN_WARNING, ha,
1095 "Invalid PCI I/O region size (%s)...\n",
1096 pci_name(ha->pdev));
1097 pio = 0;
1098 }
1099 } else {
1100 qla_printk(KERN_WARNING, ha,
1101 "region #0 not a PIO resource (%s)...\n",
1102 pci_name(ha->pdev));
1103 pio = 0;
1104 }
1105
1106 /* Use MMIO operations for all accesses. */
1107 mmio = pci_resource_start(ha->pdev, 1);
1108 mmio_len = pci_resource_len(ha->pdev, 1);
1109 mmio_flags = pci_resource_flags(ha->pdev, 1);
1110
1111 if (!(mmio_flags & IORESOURCE_MEM)) {
1112 qla_printk(KERN_ERR, ha,
1113 "region #0 not an MMIO resource (%s), aborting\n",
1114 pci_name(ha->pdev));
1115 goto iospace_error_exit;
1116 }
1117 if (mmio_len < MIN_IOBASE_LEN) {
1118 qla_printk(KERN_ERR, ha,
1119 "Invalid PCI mem region size (%s), aborting\n",
1120 pci_name(ha->pdev));
1121 goto iospace_error_exit;
1122 }
1123
1124 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1125 qla_printk(KERN_WARNING, ha,
1126 "Failed to reserve PIO/MMIO regions (%s)\n",
1127 pci_name(ha->pdev));
1128
1129 goto iospace_error_exit;
1130 }
1131
1132 ha->pio_address = pio;
1133 ha->pio_length = pio_len;
1134 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1135 if (!ha->iobase) {
1136 qla_printk(KERN_ERR, ha,
1137 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1138
1139 goto iospace_error_exit;
1140 }
1141
1142 return (0);
1143
1144iospace_error_exit:
1145 return (-ENOMEM);
1146}
1147
1148/*
1149 * PCI driver interface
1150 */
1151int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1152{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001153 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 device_reg_t __iomem *reg;
1155 struct Scsi_Host *host;
1156 scsi_qla_host_t *ha;
1157 unsigned long flags = 0;
1158 unsigned long wait_switch = 0;
1159 char pci_info[20];
1160 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001161 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001164 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 host = scsi_host_alloc(&qla2x00_driver_template,
1167 sizeof(scsi_qla_host_t));
1168 if (host == NULL) {
1169 printk(KERN_WARNING
1170 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1171 goto probe_disable_device;
1172 }
1173
1174 /* Clear our data area */
1175 ha = (scsi_qla_host_t *)host->hostdata;
1176 memset(ha, 0, sizeof(scsi_qla_host_t));
1177
1178 ha->pdev = pdev;
1179 ha->host = host;
1180 ha->host_no = host->host_no;
1181 ha->brd_info = brd_info;
1182 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1183
1184 /* Configure PCI I/O space */
1185 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001186 if (ret)
1187 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 /* Sanitize the information from PCI BIOS. */
1190 host->irq = pdev->irq;
1191
1192 qla_printk(KERN_INFO, ha,
1193 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1194 host->irq, ha->iobase);
1195
1196 spin_lock_init(&ha->hardware_lock);
1197
1198 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1199 ha->actthreads = 0;
1200 ha->qthreads = 0;
1201 ha->total_isr_cnt = 0;
1202 ha->total_isp_aborts = 0;
1203 ha->total_lip_cnt = 0;
1204 ha->total_dev_errs = 0;
1205 ha->total_ios = 0;
1206 ha->total_bytes = 0;
1207
1208 ha->prev_topology = 0;
1209 ha->ports = MAX_BUSES;
1210
1211 if (IS_QLA2100(ha)) {
1212 ha->max_targets = MAX_TARGETS_2100;
1213 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1214 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1215 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1216 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1217 host->sg_tablesize = 32;
1218 } else if (IS_QLA2200(ha)) {
1219 ha->max_targets = MAX_TARGETS_2200;
1220 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1221 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1222 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1223 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1224 } else /*if (IS_QLA2300(ha))*/ {
1225 ha->max_targets = MAX_TARGETS_2200;
1226 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1227 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1228 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1229 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1230 }
1231 host->can_queue = ha->request_q_length + 128;
1232
1233 /* load the F/W, read paramaters, and init the H/W */
1234 ha->instance = num_hosts;
1235
1236 init_MUTEX(&ha->mbx_cmd_sem);
1237 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1238
1239 INIT_LIST_HEAD(&ha->list);
1240 INIT_LIST_HEAD(&ha->fcports);
1241 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 /*
1244 * These locks are used to prevent more than one CPU
1245 * from modifying the queue at the same time. The
1246 * higher level "host_lock" will reduce most
1247 * contention for these locks.
1248 */
1249 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251 ha->dpc_pid = -1;
1252 init_completion(&ha->dpc_inited);
1253 init_completion(&ha->dpc_exited);
1254
1255 qla2x00_config_dma_addressing(ha);
1256 if (qla2x00_mem_alloc(ha)) {
1257 qla_printk(KERN_WARNING, ha,
1258 "[ERROR] Failed to allocate memory for adapter\n");
1259
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001260 ret = -ENOMEM;
1261 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 }
1263
1264 if (qla2x00_initialize_adapter(ha) &&
1265 !(ha->device_flags & DFLG_NO_CABLE)) {
1266
1267 qla_printk(KERN_WARNING, ha,
1268 "Failed to initialize adapter\n");
1269
1270 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1271 "Adapter flags %x.\n",
1272 ha->host_no, ha->device_flags));
1273
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001274 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 goto probe_failed;
1276 }
1277
1278 /*
1279 * Startup the kernel thread for this host adapter
1280 */
1281 ha->dpc_should_die = 0;
1282 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1283 if (ha->dpc_pid < 0) {
1284 qla_printk(KERN_WARNING, ha,
1285 "Unable to start DPC thread!\n");
1286
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001287 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 goto probe_failed;
1289 }
1290 wait_for_completion(&ha->dpc_inited);
1291
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001292 host->this_id = 255;
1293 host->cmd_per_lun = 3;
1294 host->unique_id = ha->instance;
1295 host->max_cmd_len = MAX_CMDSZ;
1296 host->max_channel = ha->ports - 1;
1297 host->max_lun = MAX_LUNS;
1298 host->transportt = qla2xxx_transport_template;
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1301 ret = request_irq(host->irq, qla2100_intr_handler,
1302 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1303 else
1304 ret = request_irq(host->irq, qla2300_intr_handler,
1305 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001306 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 qla_printk(KERN_WARNING, ha,
1308 "Failed to reserve interrupt %d already in use.\n",
1309 host->irq);
1310 goto probe_failed;
1311 }
1312
1313 /* Initialized the timer */
1314 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1315
1316 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1317 ha->host_no, ha));
1318
1319 reg = ha->iobase;
1320
1321 /* Disable ISP interrupts. */
1322 qla2x00_disable_intrs(ha);
1323
1324 /* Ensure mailbox registers are free. */
1325 spin_lock_irqsave(&ha->hardware_lock, flags);
1326 WRT_REG_WORD(&reg->semaphore, 0);
1327 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1328 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1329
1330 /* Enable proper parity */
1331 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1332 if (IS_QLA2300(ha))
1333 /* SRAM parity */
1334 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x1));
1335 else
1336 /* SRAM, Instruction RAM and GP RAM parity */
1337 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x7));
1338 }
1339 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1340
1341 /* Enable chip interrupts. */
1342 qla2x00_enable_intrs(ha);
1343
1344 /* v2.19.5b6 */
1345 /*
1346 * Wait around max loop_reset_delay secs for the devices to come
1347 * on-line. We don't want Linux scanning before we are ready.
1348 *
1349 */
1350 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1351 time_before(jiffies,wait_switch) &&
1352 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1353 && (ha->device_flags & SWITCH_FOUND) ;) {
1354
1355 qla2x00_check_fabric_devices(ha);
1356
1357 msleep(10);
1358 }
1359
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001360 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 ha->flags.init_done = 1;
1362 num_hosts++;
1363
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001364 ret = scsi_add_host(host, &pdev->dev);
1365 if (ret)
1366 goto probe_failed;
1367
1368 qla2x00_alloc_sysfs_attr(ha);
1369
1370 qla2x00_init_host_attr(ha);
1371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 qla_printk(KERN_INFO, ha, "\n"
1373 " QLogic Fibre Channel HBA Driver: %s\n"
1374 " QLogic %s - %s\n"
1375 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1376 ha->model_number, ha->model_desc ? ha->model_desc: "",
1377 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
1378 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
1379 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
1380
8482e1182005-04-17 15:04:54 -05001381 /* Go with fc_rport registration. */
1382 list_for_each_entry(fcport, &ha->fcports, list)
1383 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 return 0;
1386
1387probe_failed:
bdf79622005-04-17 15:06:53 -05001388 fc_remove_host(ha->host);
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 qla2x00_free_device(ha);
1391
1392 scsi_host_put(host);
1393
1394probe_disable_device:
1395 pci_disable_device(pdev);
1396
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001397probe_out:
1398 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399}
1400EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1401
1402void qla2x00_remove_one(struct pci_dev *pdev)
1403{
1404 scsi_qla_host_t *ha;
1405
1406 ha = pci_get_drvdata(pdev);
1407
8482e1182005-04-17 15:04:54 -05001408 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
bdf79622005-04-17 15:06:53 -05001410 fc_remove_host(ha->host);
1411
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 scsi_remove_host(ha->host);
1413
1414 qla2x00_free_device(ha);
1415
1416 scsi_host_put(ha->host);
1417
1418 pci_set_drvdata(pdev, NULL);
1419}
1420EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1421
1422static void
1423qla2x00_free_device(scsi_qla_host_t *ha)
1424{
1425 int ret;
1426
1427 /* Abort any outstanding IO descriptors. */
1428 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1429 qla2x00_cancel_io_descriptors(ha);
1430
1431 /* turn-off interrupts on the card */
1432 if (ha->interrupts_on)
1433 qla2x00_disable_intrs(ha);
1434
1435 /* Disable timer */
1436 if (ha->timer_active)
1437 qla2x00_stop_timer(ha);
1438
1439 /* Kill the kernel thread for this host */
1440 if (ha->dpc_pid >= 0) {
1441 ha->dpc_should_die = 1;
1442 wmb();
1443 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1444 if (ret) {
1445 qla_printk(KERN_ERR, ha,
1446 "Unable to signal DPC thread -- (%d)\n", ret);
1447
1448 /* TODO: SOMETHING MORE??? */
1449 } else {
1450 wait_for_completion(&ha->dpc_exited);
1451 }
1452 }
1453
1454 qla2x00_mem_free(ha);
1455
1456
1457 ha->flags.online = 0;
1458
1459 /* Detach interrupts */
1460 if (ha->pdev->irq)
1461 free_irq(ha->pdev->irq, ha);
1462
1463 /* release io space registers */
1464 if (ha->iobase)
1465 iounmap(ha->iobase);
1466 pci_release_regions(ha->pdev);
1467
1468 pci_disable_device(ha->pdev);
1469}
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1473 *
1474 * Input: ha = adapter block pointer. fcport = port structure pointer.
1475 *
1476 * Return: None.
1477 *
1478 * Context:
1479 */
1480void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1481 int do_login)
1482{
8482e1182005-04-17 15:04:54 -05001483 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1484 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 /*
1486 * We may need to retry the login, so don't change the state of the
1487 * port but do the retries.
1488 */
1489 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1490 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1491
1492 if (!do_login)
1493 return;
1494
1495 if (fcport->login_retry == 0) {
1496 fcport->login_retry = ha->login_retry_count;
1497 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1498
1499 DEBUG(printk("scsi(%ld): Port login retry: "
1500 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1501 "id = 0x%04x retry cnt=%d\n",
1502 ha->host_no,
1503 fcport->port_name[0],
1504 fcport->port_name[1],
1505 fcport->port_name[2],
1506 fcport->port_name[3],
1507 fcport->port_name[4],
1508 fcport->port_name[5],
1509 fcport->port_name[6],
1510 fcport->port_name[7],
1511 fcport->loop_id,
1512 fcport->login_retry));
1513 }
1514}
1515
1516/*
1517 * qla2x00_mark_all_devices_lost
1518 * Updates fcport state when device goes offline.
1519 *
1520 * Input:
1521 * ha = adapter block pointer.
1522 * fcport = port structure pointer.
1523 *
1524 * Return:
1525 * None.
1526 *
1527 * Context:
1528 */
1529void
1530qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
1531{
1532 fc_port_t *fcport;
1533
1534 list_for_each_entry(fcport, &ha->fcports, list) {
1535 if (fcport->port_type != FCT_TARGET)
1536 continue;
1537
1538 /*
1539 * No point in marking the device as lost, if the device is
1540 * already DEAD.
1541 */
1542 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1543 continue;
8482e1182005-04-17 15:04:54 -05001544 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1545 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1547 }
1548}
1549
1550/*
1551* qla2x00_mem_alloc
1552* Allocates adapter memory.
1553*
1554* Returns:
1555* 0 = success.
1556* 1 = failure.
1557*/
1558static uint8_t
1559qla2x00_mem_alloc(scsi_qla_host_t *ha)
1560{
1561 char name[16];
1562 uint8_t status = 1;
1563 int retry= 10;
1564
1565 do {
1566 /*
1567 * This will loop only once if everything goes well, else some
1568 * number of retries will be performed to get around a kernel
1569 * bug where available mem is not allocated until after a
1570 * little delay and a retry.
1571 */
1572 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1573 (ha->request_q_length + 1) * sizeof(request_t),
1574 &ha->request_dma, GFP_KERNEL);
1575 if (ha->request_ring == NULL) {
1576 qla_printk(KERN_WARNING, ha,
1577 "Memory Allocation failed - request_ring\n");
1578
1579 qla2x00_mem_free(ha);
1580 msleep(100);
1581
1582 continue;
1583 }
1584
1585 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1586 (ha->response_q_length + 1) * sizeof(response_t),
1587 &ha->response_dma, GFP_KERNEL);
1588 if (ha->response_ring == NULL) {
1589 qla_printk(KERN_WARNING, ha,
1590 "Memory Allocation failed - response_ring\n");
1591
1592 qla2x00_mem_free(ha);
1593 msleep(100);
1594
1595 continue;
1596 }
1597
1598 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1599 &ha->gid_list_dma, GFP_KERNEL);
1600 if (ha->gid_list == NULL) {
1601 qla_printk(KERN_WARNING, ha,
1602 "Memory Allocation failed - gid_list\n");
1603
1604 qla2x00_mem_free(ha);
1605 msleep(100);
1606
1607 continue;
1608 }
1609
1610 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1611 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1612 if (ha->rlc_rsp == NULL) {
1613 qla_printk(KERN_WARNING, ha,
1614 "Memory Allocation failed - rlc");
1615
1616 qla2x00_mem_free(ha);
1617 msleep(100);
1618
1619 continue;
1620 }
1621
1622 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1623 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1624 DMA_POOL_SIZE, 8, 0);
1625 if (ha->s_dma_pool == NULL) {
1626 qla_printk(KERN_WARNING, ha,
1627 "Memory Allocation failed - s_dma_pool\n");
1628
1629 qla2x00_mem_free(ha);
1630 msleep(100);
1631
1632 continue;
1633 }
1634
1635 /* get consistent memory allocated for init control block */
1636 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1637 &ha->init_cb_dma);
1638 if (ha->init_cb == NULL) {
1639 qla_printk(KERN_WARNING, ha,
1640 "Memory Allocation failed - init_cb\n");
1641
1642 qla2x00_mem_free(ha);
1643 msleep(100);
1644
1645 continue;
1646 }
1647 memset(ha->init_cb, 0, sizeof(init_cb_t));
1648
1649 /* Get consistent memory allocated for Get Port Database cmd */
1650 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1651 &ha->iodesc_pd_dma);
1652 if (ha->iodesc_pd == NULL) {
1653 /* error */
1654 qla_printk(KERN_WARNING, ha,
1655 "Memory Allocation failed - iodesc_pd\n");
1656
1657 qla2x00_mem_free(ha);
1658 msleep(100);
1659
1660 continue;
1661 }
1662 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1663
1664 /* Allocate ioctl related memory. */
1665 if (qla2x00_alloc_ioctl_mem(ha)) {
1666 qla_printk(KERN_WARNING, ha,
1667 "Memory Allocation failed - ioctl_mem\n");
1668
1669 qla2x00_mem_free(ha);
1670 msleep(100);
1671
1672 continue;
1673 }
1674
1675 if (qla2x00_allocate_sp_pool(ha)) {
1676 qla_printk(KERN_WARNING, ha,
1677 "Memory Allocation failed - "
1678 "qla2x00_allocate_sp_pool()\n");
1679
1680 qla2x00_mem_free(ha);
1681 msleep(100);
1682
1683 continue;
1684 }
1685
1686 /* Allocate memory for SNS commands */
1687 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1688 /* Get consistent memory allocated for SNS commands */
1689 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1690 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1691 GFP_KERNEL);
1692 if (ha->sns_cmd == NULL) {
1693 /* error */
1694 qla_printk(KERN_WARNING, ha,
1695 "Memory Allocation failed - sns_cmd\n");
1696
1697 qla2x00_mem_free(ha);
1698 msleep(100);
1699
1700 continue;
1701 }
1702 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1703 } else {
1704 /* Get consistent memory allocated for MS IOCB */
1705 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1706 &ha->ms_iocb_dma);
1707 if (ha->ms_iocb == NULL) {
1708 /* error */
1709 qla_printk(KERN_WARNING, ha,
1710 "Memory Allocation failed - ms_iocb\n");
1711
1712 qla2x00_mem_free(ha);
1713 msleep(100);
1714
1715 continue;
1716 }
1717 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1718
1719 /*
1720 * Get consistent memory allocated for CT SNS
1721 * commands
1722 */
1723 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1724 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1725 GFP_KERNEL);
1726 if (ha->ct_sns == NULL) {
1727 /* error */
1728 qla_printk(KERN_WARNING, ha,
1729 "Memory Allocation failed - ct_sns\n");
1730
1731 qla2x00_mem_free(ha);
1732 msleep(100);
1733
1734 continue;
1735 }
1736 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1737 }
1738
1739 /* Done all allocations without any error. */
1740 status = 0;
1741
1742 } while (retry-- && status != 0);
1743
1744 if (status) {
1745 printk(KERN_WARNING
1746 "%s(): **** FAILED ****\n", __func__);
1747 }
1748
1749 return(status);
1750}
1751
1752/*
1753* qla2x00_mem_free
1754* Frees all adapter allocated memory.
1755*
1756* Input:
1757* ha = adapter block pointer.
1758*/
1759static void
1760qla2x00_mem_free(scsi_qla_host_t *ha)
1761{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 struct list_head *fcpl, *fcptemp;
1763 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 unsigned long wtime;/* max wait time if mbx cmd is busy. */
1765
1766 if (ha == NULL) {
1767 /* error */
1768 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1769 return;
1770 }
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 /* Make sure all other threads are stopped. */
1773 wtime = 60 * HZ;
1774 while (ha->dpc_wait && wtime) {
1775 set_current_state(TASK_INTERRUPTIBLE);
1776 wtime = schedule_timeout(wtime);
1777 }
1778
1779 /* free ioctl memory */
1780 qla2x00_free_ioctl_mem(ha);
1781
1782 /* free sp pool */
1783 qla2x00_free_sp_pool(ha);
1784
1785 if (ha->sns_cmd)
1786 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1787 ha->sns_cmd, ha->sns_cmd_dma);
1788
1789 if (ha->ct_sns)
1790 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1791 ha->ct_sns, ha->ct_sns_dma);
1792
1793 if (ha->ms_iocb)
1794 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1795
1796 if (ha->iodesc_pd)
1797 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1798
1799 if (ha->init_cb)
1800 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1801
1802 if (ha->s_dma_pool)
1803 dma_pool_destroy(ha->s_dma_pool);
1804
1805 if (ha->rlc_rsp)
1806 dma_free_coherent(&ha->pdev->dev,
1807 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
1808 ha->rlc_rsp_dma);
1809
1810 if (ha->gid_list)
1811 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
1812 ha->gid_list_dma);
1813
1814 if (ha->response_ring)
1815 dma_free_coherent(&ha->pdev->dev,
1816 (ha->response_q_length + 1) * sizeof(response_t),
1817 ha->response_ring, ha->response_dma);
1818
1819 if (ha->request_ring)
1820 dma_free_coherent(&ha->pdev->dev,
1821 (ha->request_q_length + 1) * sizeof(request_t),
1822 ha->request_ring, ha->request_dma);
1823
1824 ha->sns_cmd = NULL;
1825 ha->sns_cmd_dma = 0;
1826 ha->ct_sns = NULL;
1827 ha->ct_sns_dma = 0;
1828 ha->ms_iocb = NULL;
1829 ha->ms_iocb_dma = 0;
1830 ha->iodesc_pd = NULL;
1831 ha->iodesc_pd_dma = 0;
1832 ha->init_cb = NULL;
1833 ha->init_cb_dma = 0;
1834
1835 ha->s_dma_pool = NULL;
1836
1837 ha->rlc_rsp = NULL;
1838 ha->rlc_rsp_dma = 0;
1839 ha->gid_list = NULL;
1840 ha->gid_list_dma = 0;
1841
1842 ha->response_ring = NULL;
1843 ha->response_dma = 0;
1844 ha->request_ring = NULL;
1845 ha->request_dma = 0;
1846
1847 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
1848 fcport = list_entry(fcpl, fc_port_t, list);
1849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 /* fc ports */
1851 list_del_init(&fcport->list);
1852 kfree(fcport);
1853 }
1854 INIT_LIST_HEAD(&ha->fcports);
1855
1856 if (ha->fw_dump)
1857 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
1858
1859 if (ha->fw_dump_buffer)
1860 vfree(ha->fw_dump_buffer);
1861
1862 ha->fw_dump = NULL;
1863 ha->fw_dump_reading = 0;
1864 ha->fw_dump_buffer = NULL;
1865}
1866
1867/*
1868 * qla2x00_allocate_sp_pool
1869 * This routine is called during initialization to allocate
1870 * memory for local srb_t.
1871 *
1872 * Input:
1873 * ha = adapter block pointer.
1874 *
1875 * Context:
1876 * Kernel context.
1877 *
1878 * Note: Sets the ref_count for non Null sp to one.
1879 */
1880static int
1881qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
1882{
1883 int rval;
1884
1885 rval = QLA_SUCCESS;
1886 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1887 mempool_free_slab, srb_cachep);
1888 if (ha->srb_mempool == NULL) {
1889 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
1890 rval = QLA_FUNCTION_FAILED;
1891 }
1892 return (rval);
1893}
1894
1895/*
1896 * This routine frees all adapter allocated memory.
1897 *
1898 */
1899static void
1900qla2x00_free_sp_pool( scsi_qla_host_t *ha)
1901{
1902 if (ha->srb_mempool) {
1903 mempool_destroy(ha->srb_mempool);
1904 ha->srb_mempool = NULL;
1905 }
1906}
1907
1908/**************************************************************************
1909* qla2x00_do_dpc
1910* This kernel thread is a task that is schedule by the interrupt handler
1911* to perform the background processing for interrupts.
1912*
1913* Notes:
1914* This task always run in the context of a kernel thread. It
1915* is kick-off by the driver's detect code and starts up
1916* up one per adapter. It immediately goes to sleep and waits for
1917* some fibre event. When either the interrupt handler or
1918* the timer routine detects a event it will one of the task
1919* bits then wake us up.
1920**************************************************************************/
1921static int
1922qla2x00_do_dpc(void *data)
1923{
1924 DECLARE_MUTEX_LOCKED(sem);
1925 scsi_qla_host_t *ha;
1926 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
1930 ha = (scsi_qla_host_t *)data;
1931
1932 lock_kernel();
1933
1934 daemonize("%s_dpc", ha->host_str);
1935 allow_signal(SIGHUP);
1936
1937 ha->dpc_wait = &sem;
1938
1939 set_user_nice(current, -20);
1940
1941 unlock_kernel();
1942
1943 complete(&ha->dpc_inited);
1944
1945 while (1) {
1946 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
1947
1948 if (down_interruptible(&sem))
1949 break;
1950
1951 if (ha->dpc_should_die)
1952 break;
1953
1954 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
1955
1956 /* Initialization not yet finished. Don't do anything yet. */
1957 if (!ha->flags.init_done || ha->dpc_active)
1958 continue;
1959
1960 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
1961
1962 ha->dpc_active = 1;
1963
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 ha->dpc_active = 0;
1966 continue;
1967 }
1968
1969 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
1970
1971 DEBUG(printk("scsi(%ld): dpc: sched "
1972 "qla2x00_abort_isp ha = %p\n",
1973 ha->host_no, ha));
1974 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
1975 &ha->dpc_flags))) {
1976
1977 if (qla2x00_abort_isp(ha)) {
1978 /* failed. retry later */
1979 set_bit(ISP_ABORT_NEEDED,
1980 &ha->dpc_flags);
1981 }
1982 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1983 }
1984 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
1985 ha->host_no));
1986 }
1987
1988 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
1989 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
1990
1991 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
1992 ha->host_no));
1993
1994 qla2x00_rst_aen(ha);
1995 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
1996 }
1997
1998 /* Retry each device up to login retry count */
1999 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2000 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2001 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2002
2003 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2004 ha->host_no));
2005
2006 next_loopid = 0;
2007 list_for_each_entry(fcport, &ha->fcports, list) {
2008 if (fcport->port_type != FCT_TARGET)
2009 continue;
2010
2011 /*
2012 * If the port is not ONLINE then try to login
2013 * to it if we haven't run out of retries.
2014 */
2015 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2016 fcport->login_retry) {
2017
2018 fcport->login_retry--;
2019 if (fcport->flags & FCF_FABRIC_DEVICE) {
2020 if (fcport->flags &
2021 FCF_TAPE_PRESENT)
2022 qla2x00_fabric_logout(
2023 ha,
2024 fcport->loop_id);
2025 status = qla2x00_fabric_login(
2026 ha, fcport, &next_loopid);
2027 } else
2028 status =
2029 qla2x00_local_device_login(
2030 ha, fcport->loop_id);
2031
2032 if (status == QLA_SUCCESS) {
2033 fcport->old_loop_id = fcport->loop_id;
2034
2035 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2036 ha->host_no, fcport->loop_id));
2037
2038 fcport->port_login_retry_count =
2039 ha->port_down_retry_count * PORT_RETRY_TIME;
2040 atomic_set(&fcport->state, FCS_ONLINE);
2041 atomic_set(&fcport->port_down_timer,
2042 ha->port_down_retry_count * PORT_RETRY_TIME);
2043
2044 fcport->login_retry = 0;
2045 } else if (status == 1) {
2046 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2047 /* retry the login again */
2048 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2049 ha->host_no,
2050 fcport->login_retry, fcport->loop_id));
2051 } else {
2052 fcport->login_retry = 0;
2053 }
2054 }
2055 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2056 break;
2057 }
2058 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2059 ha->host_no));
2060 }
2061
2062 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2063 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2064
2065 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2066 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2067 ha->host_no));
2068
2069 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2070
2071 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2072 ha->host_no));
2073 }
2074
2075 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2076
2077 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2078 ha->host_no));
2079
2080 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2081 &ha->dpc_flags))) {
2082
2083 qla2x00_loop_resync(ha);
2084
2085 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2086 }
2087
2088 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2089 ha->host_no));
2090 }
2091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2093
2094 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2095 ha->host_no));
2096
2097 qla2x00_rescan_fcports(ha);
2098
2099 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2100 "end.\n",
2101 ha->host_no));
2102 }
2103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 if (!ha->interrupts_on)
2105 qla2x00_enable_intrs(ha);
2106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 ha->dpc_active = 0;
2108 } /* End of while(1) */
2109
2110 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2111
2112 /*
2113 * Make sure that nobody tries to wake us up again.
2114 */
2115 ha->dpc_wait = NULL;
2116 ha->dpc_active = 0;
2117
2118 complete_and_exit(&ha->dpc_exited, 0);
2119}
2120
2121/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122* qla2x00_rst_aen
2123* Processes asynchronous reset.
2124*
2125* Input:
2126* ha = adapter block pointer.
2127*/
2128static void
2129qla2x00_rst_aen(scsi_qla_host_t *ha)
2130{
2131 if (ha->flags.online && !ha->flags.reset_active &&
2132 !atomic_read(&ha->loop_down_timer) &&
2133 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2134 do {
2135 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2136
2137 /*
2138 * Issue marker command only when we are going to start
2139 * the I/O.
2140 */
2141 ha->marker_needed = 1;
2142 } while (!atomic_read(&ha->loop_down_timer) &&
2143 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2144 }
2145}
2146
2147
2148/*
2149 * This routine will allocate SP from the free queue
2150 * input:
2151 * scsi_qla_host_t *
2152 * output:
2153 * srb_t * or NULL
2154 */
2155static srb_t *
2156qla2x00_get_new_sp(scsi_qla_host_t *ha)
2157{
2158 srb_t *sp;
2159
2160 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2161 if (sp)
2162 atomic_set(&sp->ref_count, 1);
2163 return (sp);
2164}
2165
f4f051e2005-04-17 15:02:26 -05002166static void
2167qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2168{
2169 struct scsi_cmnd *cmd = sp->cmd;
2170
2171 if (sp->flags & SRB_DMA_VALID) {
2172 if (cmd->use_sg) {
2173 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2174 cmd->use_sg, cmd->sc_data_direction);
2175 } else if (cmd->request_bufflen) {
2176 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2177 cmd->request_bufflen, cmd->sc_data_direction);
2178 }
2179 sp->flags &= ~SRB_DMA_VALID;
2180 }
2181}
2182
2183void
2184qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2185{
2186 struct scsi_cmnd *cmd = sp->cmd;
2187
2188 qla2x00_sp_free_dma(ha, sp);
2189
2190 CMD_SP(cmd) = NULL;
2191 mempool_free(sp, ha->srb_mempool);
2192
2193 cmd->scsi_done(cmd);
2194}
bdf79622005-04-17 15:06:53 -05002195
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196/**************************************************************************
2197* qla2x00_timer
2198*
2199* Description:
2200* One second timer
2201*
2202* Context: Interrupt
2203***************************************************************************/
2204static void
2205qla2x00_timer(scsi_qla_host_t *ha)
2206{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 unsigned long cpu_flags = 0;
2208 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 int start_dpc = 0;
2210 int index;
2211 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002212 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
2214 /*
2215 * Ports - Port down timer.
2216 *
2217 * Whenever, a port is in the LOST state we start decrementing its port
2218 * down timer every second until it reaches zero. Once it reaches zero
2219 * the port it marked DEAD.
2220 */
2221 t = 0;
2222 list_for_each_entry(fcport, &ha->fcports, list) {
2223 if (fcport->port_type != FCT_TARGET)
2224 continue;
2225
2226 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2227
2228 if (atomic_read(&fcport->port_down_timer) == 0)
2229 continue;
2230
2231 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2232 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2233
2234 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2235 "%d remainning\n",
2236 ha->host_no,
2237 t, atomic_read(&fcport->port_down_timer)));
2238 }
2239 t++;
2240 } /* End of for fcport */
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243 /* Loop down handler. */
2244 if (atomic_read(&ha->loop_down_timer) > 0 &&
2245 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2246
2247 if (atomic_read(&ha->loop_down_timer) ==
2248 ha->loop_down_abort_time) {
2249
2250 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2251 "queues before time expire\n",
2252 ha->host_no));
2253
2254 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2255 atomic_set(&ha->loop_state, LOOP_DEAD);
2256
2257 /* Schedule an ISP abort to return any tape commands. */
2258 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2259 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2260 index++) {
bdf79622005-04-17 15:06:53 -05002261 fc_port_t *sfcp;
2262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 sp = ha->outstanding_cmds[index];
2264 if (!sp)
2265 continue;
bdf79622005-04-17 15:06:53 -05002266 sfcp = sp->fcport;
2267 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 continue;
2269
2270 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2271 break;
2272 }
2273 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2274
2275 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2276 start_dpc++;
2277 }
2278
2279 /* if the loop has been down for 4 minutes, reinit adapter */
2280 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2281 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2282 "restarting queues.\n",
2283 ha->host_no));
2284
2285 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2286 start_dpc++;
2287
2288 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2289 DEBUG(printk("scsi(%ld): Loop down - "
2290 "aborting ISP.\n",
2291 ha->host_no));
2292 qla_printk(KERN_WARNING, ha,
2293 "Loop down - aborting ISP.\n");
2294
2295 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2296 }
2297 }
2298 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
2299 ha->host_no,
2300 atomic_read(&ha->loop_down_timer)));
2301 }
2302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 /* Schedule the DPC routine if needed */
2304 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2305 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2306 start_dpc ||
2307 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002308 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2310 ha->dpc_wait && !ha->dpc_active) {
2311
2312 up(ha->dpc_wait);
2313 }
2314
2315 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2316}
2317
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318/* XXX(hch): crude hack to emulate a down_timeout() */
2319int
2320qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2321{
2322 const unsigned int step = HZ/10;
2323
2324 do {
2325 if (!down_trylock(sema))
2326 return 0;
2327 set_current_state(TASK_INTERRUPTIBLE);
2328 if (schedule_timeout(step))
2329 break;
2330 } while ((timeout -= step) > 0);
2331
2332 return -ETIMEDOUT;
2333}
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/**
2336 * qla2x00_module_init - Module initialization.
2337 **/
2338static int __init
2339qla2x00_module_init(void)
2340{
2341 /* Allocate cache for SRBs. */
2342 sprintf(srb_cachep_name, "qla2xxx_srbs");
2343 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
2344 SLAB_HWCACHE_ALIGN, NULL, NULL);
2345 if (srb_cachep == NULL) {
2346 printk(KERN_ERR
2347 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2348 return -ENOMEM;
2349 }
2350
2351 /* Derive version string. */
2352 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2353#if DEBUG_QLA2100
2354 strcat(qla2x00_version_str, "-debug");
2355#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002356 qla2xxx_transport_template =
2357 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 if (!qla2xxx_transport_template)
2359 return -ENODEV;
2360
2361 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
2362 return 0;
2363}
2364
2365/**
2366 * qla2x00_module_exit - Module cleanup.
2367 **/
2368static void __exit
2369qla2x00_module_exit(void)
2370{
2371 /* Free SRBs cache. */
2372 if (srb_cachep != NULL) {
2373 if (kmem_cache_destroy(srb_cachep) != 0) {
2374 printk(KERN_ERR
2375 "qla2xxx: Unable to free SRB cache...Memory pools "
2376 "still active?\n");
2377 }
2378 srb_cachep = NULL;
2379 }
2380
2381 fc_release_transport(qla2xxx_transport_template);
2382}
2383
2384module_init(qla2x00_module_init);
2385module_exit(qla2x00_module_exit);
2386
2387MODULE_AUTHOR("QLogic Corporation");
2388MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2389MODULE_LICENSE("GPL");
2390MODULE_VERSION(QLA2XXX_VERSION);