[PATCH] qla2xxx: remove internal queuing...
[linux-2.6/mini2440.git] / drivers / scsi / qla2xxx / qla_os.c
blob0e7e51db470caccdc7ecf6eb43f8e7195831c74b
1 /*
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
6 * (www.qlogic.com)
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.
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.
19 #include "qla_def.h"
21 #include <linux/moduleparam.h>
22 #include <linux/vmalloc.h>
23 #include <linux/smp_lock.h>
24 #include <linux/delay.h>
26 #include <scsi/scsi_tcq.h>
27 #include <scsi/scsicam.h>
28 #include <scsi/scsi_transport.h>
29 #include <scsi/scsi_transport_fc.h>
32 * Driver version
34 char qla2x00_version_str[40];
37 * SRB allocation cache
39 char srb_cachep_name[16];
40 kmem_cache_t *srb_cachep;
43 * Stats for all adpaters.
45 struct _qla2x00stats qla2x00_stats;
48 * Ioctl related information.
50 int num_hosts;
51 int apiHBAInstance;
54 * Module parameter information and variables
56 int ql2xmaxqdepth;
57 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql2xmaxqdepth,
59 "Maximum queue depth to report for target devices.");
61 int ql2xlogintimeout = 20;
62 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
63 MODULE_PARM_DESC(ql2xlogintimeout,
64 "Login timeout value in seconds.");
66 int qlport_down_retry;
67 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
68 MODULE_PARM_DESC(qlport_down_retry,
69 "Maximum number of command retries to a port that returns"
70 "a PORT-DOWN status.");
72 int ql2xretrycount = 20;
73 module_param(ql2xretrycount, int, S_IRUGO|S_IWUSR);
74 MODULE_PARM_DESC(ql2xretrycount,
75 "Maximum number of mid-layer retries allowed for a command. "
76 "Default value is 20, ");
78 int displayConfig;
79 module_param(displayConfig, int, S_IRUGO|S_IWUSR);
80 MODULE_PARM_DESC(displayConfig,
81 "If 1 then display the configuration used in /etc/modprobe.conf.");
83 int ql2xplogiabsentdevice;
84 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
85 MODULE_PARM_DESC(ql2xplogiabsentdevice,
86 "Option to enable PLOGI to devices that are not present after "
87 "a Fabric scan. This is needed for several broken switches."
88 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
90 int ql2xenablezio = 0;
91 module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
92 MODULE_PARM_DESC(ql2xenablezio,
93 "Option to enable ZIO:If 1 then enable it otherwise"
94 " use the default set in the NVRAM."
95 " Default is 0 : disabled");
97 int ql2xintrdelaytimer = 10;
98 module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
99 MODULE_PARM_DESC(ql2xintrdelaytimer,
100 "ZIO: Waiting time for Firmware before it generates an "
101 "interrupt to the host to notify completion of request.");
103 int ConfigRequired;
104 module_param(ConfigRequired, int, S_IRUGO|S_IRUSR);
105 MODULE_PARM_DESC(ConfigRequired,
106 "If 1, then only configured devices passed in through the"
107 "ql2xopts parameter will be presented to the OS");
109 int Bind = BIND_BY_PORT_NAME;
110 module_param(Bind, int, S_IRUGO|S_IRUSR);
111 MODULE_PARM_DESC(Bind,
112 "Target persistent binding method: "
113 "0 by Portname (default); 1 by PortID; 2 by Nodename. ");
115 int ql2xsuspendcount = SUSPEND_COUNT;
116 module_param(ql2xsuspendcount, int, S_IRUGO|S_IWUSR);
117 MODULE_PARM_DESC(ql2xsuspendcount,
118 "Number of 6-second suspend iterations to perform while a "
119 "target returns a <NOT READY> status. Default is 10 "
120 "iterations.");
122 int ql2xdoinitscan = 1;
123 module_param(ql2xdoinitscan, int, S_IRUGO|S_IWUSR);
124 MODULE_PARM_DESC(ql2xdoinitscan,
125 "Signal mid-layer to perform scan after driver load: 0 -- no "
126 "signal sent to mid-layer.");
128 int ql2xloginretrycount = 0;
129 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
130 MODULE_PARM_DESC(ql2xloginretrycount,
131 "Specify an alternate value for the NVRAM login retry count.");
134 * Proc structures and functions
136 struct info_str {
137 char *buffer;
138 int length;
139 off_t offset;
140 int pos;
143 static void copy_mem_info(struct info_str *, char *, int);
144 static int copy_info(struct info_str *, char *, ...);
146 static void qla2x00_free_device(scsi_qla_host_t *);
148 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
151 * SCSI host template entry points
153 static int qla2xxx_slave_configure(struct scsi_device * device);
154 static int qla2xxx_slave_alloc(struct scsi_device *);
155 static void qla2xxx_slave_destroy(struct scsi_device *);
156 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
157 void (*fn)(struct scsi_cmnd *));
158 static int qla2xxx_eh_abort(struct scsi_cmnd *);
159 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
160 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
161 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
162 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
163 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
165 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
166 off_t, int, int);
168 static struct scsi_host_template qla2x00_driver_template = {
169 .module = THIS_MODULE,
170 .name = "qla2xxx",
171 .proc_name = "qla2xxx",
172 .proc_info = qla2x00_proc_info,
173 .queuecommand = qla2x00_queuecommand,
175 .eh_abort_handler = qla2xxx_eh_abort,
176 .eh_device_reset_handler = qla2xxx_eh_device_reset,
177 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
178 .eh_host_reset_handler = qla2xxx_eh_host_reset,
180 .slave_configure = qla2xxx_slave_configure,
182 .slave_alloc = qla2xxx_slave_alloc,
183 .slave_destroy = qla2xxx_slave_destroy,
184 .this_id = -1,
185 .cmd_per_lun = 3,
186 .use_clustering = ENABLE_CLUSTERING,
187 .sg_tablesize = SG_ALL,
190 * The RISC allows for each command to transfer (2^32-1) bytes of data,
191 * which equates to 0x800000 sectors.
193 .max_sectors = 0xFFFF,
196 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
198 static void qla2x00_display_fc_names(scsi_qla_host_t *);
200 /* TODO Convert to inlines
202 * Timer routines
204 #define WATCH_INTERVAL 1 /* number of seconds */
206 static void qla2x00_timer(scsi_qla_host_t *);
208 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
209 void *, unsigned long);
210 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
211 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
213 static inline void
214 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
216 init_timer(&ha->timer);
217 ha->timer.expires = jiffies + interval * HZ;
218 ha->timer.data = (unsigned long)ha;
219 ha->timer.function = (void (*)(unsigned long))func;
220 add_timer(&ha->timer);
221 ha->timer_active = 1;
224 static inline void
225 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
227 mod_timer(&ha->timer, jiffies + interval * HZ);
230 static __inline__ void
231 qla2x00_stop_timer(scsi_qla_host_t *ha)
233 del_timer_sync(&ha->timer);
234 ha->timer_active = 0;
237 static int qla2x00_do_dpc(void *data);
239 static void qla2x00_rst_aen(scsi_qla_host_t *);
241 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
242 static void qla2x00_mem_free(scsi_qla_host_t *ha);
243 static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
244 static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
245 static srb_t *qla2x00_get_new_sp(scsi_qla_host_t *);
246 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
247 void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
249 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t,
250 size_t);
251 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t,
252 size_t);
253 static struct bin_attribute sysfs_fw_dump_attr = {
254 .attr = {
255 .name = "fw_dump",
256 .mode = S_IRUSR | S_IWUSR,
257 .owner = THIS_MODULE,
259 .size = 0,
260 .read = qla2x00_sysfs_read_fw_dump,
261 .write = qla2x00_sysfs_write_fw_dump,
263 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t,
264 size_t);
265 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t,
266 size_t);
267 static struct bin_attribute sysfs_nvram_attr = {
268 .attr = {
269 .name = "nvram",
270 .mode = S_IRUSR | S_IWUSR,
271 .owner = THIS_MODULE,
273 .size = sizeof(nvram_t),
274 .read = qla2x00_sysfs_read_nvram,
275 .write = qla2x00_sysfs_write_nvram,
278 /* -------------------------------------------------------------------------- */
281 /* SysFS attributes. */
282 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf,
283 loff_t off, size_t count)
285 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
286 struct device, kobj)));
288 if (ha->fw_dump_reading == 0)
289 return 0;
290 if (off > ha->fw_dump_buffer_len)
291 return 0;
292 if (off + count > ha->fw_dump_buffer_len)
293 count = ha->fw_dump_buffer_len - off;
295 memcpy(buf, &ha->fw_dump_buffer[off], count);
297 return (count);
300 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf,
301 loff_t off, size_t count)
303 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
304 struct device, kobj)));
305 int reading;
306 uint32_t dump_size;
308 if (off != 0)
309 return (0);
311 reading = simple_strtol(buf, NULL, 10);
312 switch (reading) {
313 case 0:
314 if (ha->fw_dump_reading == 1) {
315 qla_printk(KERN_INFO, ha,
316 "Firmware dump cleared on (%ld).\n",
317 ha->host_no);
319 vfree(ha->fw_dump_buffer);
320 free_pages((unsigned long)ha->fw_dump,
321 ha->fw_dump_order);
323 ha->fw_dump_reading = 0;
324 ha->fw_dump_buffer = NULL;
325 ha->fw_dump = NULL;
327 break;
328 case 1:
329 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
330 ha->fw_dump_reading = 1;
332 dump_size = FW_DUMP_SIZE_1M;
333 if (ha->fw_memory_size < 0x20000)
334 dump_size = FW_DUMP_SIZE_128K;
335 else if (ha->fw_memory_size < 0x80000)
336 dump_size = FW_DUMP_SIZE_512K;
337 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
338 if (ha->fw_dump_buffer == NULL) {
339 qla_printk(KERN_WARNING, ha,
340 "Unable to allocate memory for firmware "
341 "dump buffer (%d).\n", dump_size);
343 ha->fw_dump_reading = 0;
344 return (count);
346 qla_printk(KERN_INFO, ha,
347 "Firmware dump ready for read on (%ld).\n",
348 ha->host_no);
349 memset(ha->fw_dump_buffer, 0, dump_size);
350 if (IS_QLA2100(ha) || IS_QLA2200(ha))
351 qla2100_ascii_fw_dump(ha);
352 else
353 qla2300_ascii_fw_dump(ha);
354 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
356 break;
358 return (count);
361 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf,
362 loff_t off, size_t count)
364 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
365 struct device, kobj)));
366 uint16_t *witer;
367 unsigned long flags;
368 uint16_t cnt;
370 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
371 return 0;
373 /* Read NVRAM. */
374 spin_lock_irqsave(&ha->hardware_lock, flags);
375 qla2x00_lock_nvram_access(ha);
376 witer = (uint16_t *)buf;
377 for (cnt = 0; cnt < count / 2; cnt++) {
378 *witer = cpu_to_le16(qla2x00_get_nvram_word(ha,
379 cnt+ha->nvram_base));
380 witer++;
382 qla2x00_unlock_nvram_access(ha);
383 spin_unlock_irqrestore(&ha->hardware_lock, flags);
385 return (count);
388 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf,
389 loff_t off, size_t count)
391 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
392 struct device, kobj)));
393 uint8_t *iter;
394 uint16_t *witer;
395 unsigned long flags;
396 uint16_t cnt;
397 uint8_t chksum;
399 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
400 return 0;
402 /* Checksum NVRAM. */
403 iter = (uint8_t *)buf;
404 chksum = 0;
405 for (cnt = 0; cnt < count - 1; cnt++)
406 chksum += *iter++;
407 chksum = ~chksum + 1;
408 *iter = chksum;
410 /* Write NVRAM. */
411 spin_lock_irqsave(&ha->hardware_lock, flags);
412 qla2x00_lock_nvram_access(ha);
413 qla2x00_release_nvram_protection(ha);
414 witer = (uint16_t *)buf;
415 for (cnt = 0; cnt < count / 2; cnt++) {
416 qla2x00_write_nvram_word(ha, cnt+ha->nvram_base,
417 cpu_to_le16(*witer));
418 witer++;
420 qla2x00_unlock_nvram_access(ha);
421 spin_unlock_irqrestore(&ha->hardware_lock, flags);
423 return (count);
426 /* -------------------------------------------------------------------------- */
427 static char *
428 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
430 static char *pci_bus_modes[] = {
431 "33", "66", "100", "133",
433 uint16_t pci_bus;
435 strcpy(str, "PCI");
436 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
437 if (pci_bus) {
438 strcat(str, "-X (");
439 strcat(str, pci_bus_modes[pci_bus]);
440 } else {
441 pci_bus = (ha->pci_attr & BIT_8) >> 8;
442 strcat(str, " (");
443 strcat(str, pci_bus_modes[pci_bus]);
445 strcat(str, " MHz)");
447 return (str);
450 char *
451 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
453 char un_str[10];
455 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
456 ha->fw_minor_version,
457 ha->fw_subminor_version);
459 if (ha->fw_attributes & BIT_9) {
460 strcat(str, "FLX");
461 return (str);
464 switch (ha->fw_attributes & 0xFF) {
465 case 0x7:
466 strcat(str, "EF");
467 break;
468 case 0x17:
469 strcat(str, "TP");
470 break;
471 case 0x37:
472 strcat(str, "IP");
473 break;
474 case 0x77:
475 strcat(str, "VI");
476 break;
477 default:
478 sprintf(un_str, "(%x)", ha->fw_attributes);
479 strcat(str, un_str);
480 break;
482 if (ha->fw_attributes & 0x100)
483 strcat(str, "X");
485 return (str);
488 /**************************************************************************
489 * qla2x00_queuecommand
491 * Description:
492 * Queue a command to the controller.
494 * Input:
495 * cmd - pointer to Scsi cmd structure
496 * fn - pointer to Scsi done function
498 * Returns:
499 * 0 - Always
501 * Note:
502 * The mid-level driver tries to ensures that queuecommand never gets invoked
503 * concurrently with itself or the interrupt handler (although the
504 * interrupt handler may call this routine as part of request-completion
505 * handling).
506 **************************************************************************/
507 static int
508 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
510 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
511 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
512 fc_port_t *fcport = tq->fcport;
513 os_lun_t *lq;
514 srb_t *sp;
515 int rval;
517 lq = GET_LU_Q(ha, cmd->device->id, cmd->device->lun);
518 if (!fcport || !lq) {
519 cmd->result = DID_NO_CONNECT << 16;
520 goto qc_fail_command;
523 if (atomic_read(&fcport->state) != FCS_ONLINE) {
524 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
525 atomic_read(&ha->loop_state) == LOOP_DEAD) {
526 cmd->result = DID_NO_CONNECT << 16;
527 goto qc_fail_command;
529 goto qc_host_busy;
532 spin_unlock_irq(ha->host->host_lock);
534 /* Allocate a command packet from the "sp" pool. */
535 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
536 goto qc_host_busy_lock;
539 sp->ha = ha;
540 sp->cmd = cmd;
541 sp->tgt_queue = tq;
543 sp->lun_queue = lq;
544 lq->io_cnt++;
545 sp->fclun = lq->fclun;
547 sp->flags = 0;
548 sp->err_id = 0;
550 CMD_SP(cmd) = (void *)sp;
551 cmd->scsi_done = done;
553 rval = qla2x00_start_scsi(sp);
554 if (rval != QLA_SUCCESS)
555 goto qc_host_busy_free_sp;
557 /* Manage unprocessed RIO/ZIO commands in response queue. */
558 if (ha->flags.online && ha->flags.process_response_queue &&
559 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
560 unsigned long flags;
562 spin_lock_irqsave(&ha->hardware_lock, flags);
563 qla2x00_process_response_queue(ha);
564 spin_unlock_irqrestore(&ha->hardware_lock, flags);
567 spin_lock_irq(ha->host->host_lock);
569 return 0;
571 qc_host_busy_free_sp:
572 qla2x00_sp_free_dma(ha, sp);
573 CMD_SP(cmd) = NULL;
574 mempool_free(sp, ha->srb_mempool);
576 qc_host_busy_lock:
577 spin_lock_irq(ha->host->host_lock);
579 qc_host_busy:
580 return SCSI_MLQUEUE_HOST_BUSY;
582 qc_fail_command:
583 done(cmd);
585 return 0;
589 * qla2x00_eh_wait_on_command
590 * Waits for the command to be returned by the Firmware for some
591 * max time.
593 * Input:
594 * ha = actual ha whose done queue will contain the command
595 * returned by firmware.
596 * cmd = Scsi Command to wait on.
597 * flag = Abort/Reset(Bus or Device Reset)
599 * Return:
600 * Not Found : 0
601 * Found : 1
603 static int
604 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
606 #define ABORT_POLLING_PERIOD HZ
607 #define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
608 unsigned long wait_iter = ABORT_WAIT_ITER;
609 int ret = QLA_SUCCESS;
611 while (CMD_SP(cmd)) {
612 set_current_state(TASK_UNINTERRUPTIBLE);
613 schedule_timeout(ABORT_POLLING_PERIOD);
615 if (--wait_iter)
616 break;
618 if (CMD_SP(cmd))
619 ret = QLA_FUNCTION_FAILED;
621 return ret;
625 * qla2x00_wait_for_hba_online
626 * Wait till the HBA is online after going through
627 * <= MAX_RETRIES_OF_ISP_ABORT or
628 * finally HBA is disabled ie marked offline
630 * Input:
631 * ha - pointer to host adapter structure
633 * Note:
634 * Does context switching-Release SPIN_LOCK
635 * (if any) before calling this routine.
637 * Return:
638 * Success (Adapter is online) : 0
639 * Failed (Adapter is offline/disabled) : 1
641 static int
642 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
644 int return_status;
645 unsigned long wait_online;
647 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
648 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
649 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
650 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
651 ha->dpc_active) && time_before(jiffies, wait_online)) {
653 msleep(1000);
655 if (ha->flags.online)
656 return_status = QLA_SUCCESS;
657 else
658 return_status = QLA_FUNCTION_FAILED;
660 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
662 return (return_status);
666 * qla2x00_wait_for_loop_ready
667 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
668 * to be in LOOP_READY state.
669 * Input:
670 * ha - pointer to host adapter structure
672 * Note:
673 * Does context switching-Release SPIN_LOCK
674 * (if any) before calling this routine.
677 * Return:
678 * Success (LOOP_READY) : 0
679 * Failed (LOOP_NOT_READY) : 1
681 static inline int
682 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
684 int return_status = QLA_SUCCESS;
685 unsigned long loop_timeout ;
687 /* wait for 5 min at the max for loop to be ready */
688 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
690 while ((!atomic_read(&ha->loop_down_timer) &&
691 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
692 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
693 atomic_read(&ha->loop_state) != LOOP_READY) {
694 msleep(1000);
695 if (time_after_eq(jiffies, loop_timeout)) {
696 return_status = QLA_FUNCTION_FAILED;
697 break;
700 return (return_status);
703 /**************************************************************************
704 * qla2xxx_eh_abort
706 * Description:
707 * The abort function will abort the specified command.
709 * Input:
710 * cmd = Linux SCSI command packet to be aborted.
712 * Returns:
713 * Either SUCCESS or FAILED.
715 * Note:
716 **************************************************************************/
718 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
720 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
721 srb_t *sp;
722 int ret, i;
723 unsigned int id, lun;
724 unsigned long serial;
726 if (!CMD_SP(cmd))
727 return FAILED;
729 ret = FAILED;
731 id = cmd->device->id;
732 lun = cmd->device->lun;
733 serial = cmd->serial_number;
735 /* Check active list for command command. */
736 spin_unlock_irq(ha->host->host_lock);
737 spin_lock(&ha->hardware_lock);
738 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
739 sp = ha->outstanding_cmds[i];
741 if (sp == NULL)
742 continue;
744 if (sp->cmd != cmd)
745 continue;
747 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
748 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
749 sp->state));
750 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
752 spin_unlock(&ha->hardware_lock);
753 if (qla2x00_abort_command(ha, sp)) {
754 DEBUG2(printk("%s(%ld): abort_command "
755 "mbx failed.\n", __func__, ha->host_no));
756 } else {
757 DEBUG3(printk("%s(%ld): abort_command "
758 "mbx success.\n", __func__, ha->host_no));
759 ret = SUCCESS;
761 spin_lock(&ha->hardware_lock);
763 break;
766 /* Wait for the command to be returned. */
767 if (ret == SUCCESS) {
768 spin_unlock(&ha->hardware_lock);
769 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
770 qla_printk(KERN_ERR, ha,
771 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
772 "%x.\n", ha->host_no, id, lun, serial, ret);
774 spin_lock(&ha->hardware_lock);
776 spin_lock_irq(ha->host->host_lock);
778 qla_printk(KERN_INFO, ha,
779 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
780 id, lun, serial, ret);
782 return ret;
785 /**************************************************************************
786 * qla2x00_eh_wait_for_pending_target_commands
788 * Description:
789 * Waits for all the commands to come back from the specified target.
791 * Input:
792 * ha - pointer to scsi_qla_host structure.
793 * t - target
794 * Returns:
795 * Either SUCCESS or FAILED.
797 * Note:
798 **************************************************************************/
799 static int
800 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
802 int cnt;
803 int status;
804 srb_t *sp;
805 struct scsi_cmnd *cmd;
807 status = 0;
810 * Waiting for all commands for the designated target in the active
811 * array
813 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
814 spin_lock(&ha->hardware_lock);
815 sp = ha->outstanding_cmds[cnt];
816 if (sp) {
817 cmd = sp->cmd;
818 spin_unlock(&ha->hardware_lock);
819 if (cmd->device->id == t) {
820 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
821 status = 1;
822 break;
825 } else {
826 spin_unlock(&ha->hardware_lock);
829 return (status);
833 /**************************************************************************
834 * qla2xxx_eh_device_reset
836 * Description:
837 * The device reset function will reset the target and abort any
838 * executing commands.
840 * NOTE: The use of SP is undefined within this context. Do *NOT*
841 * attempt to use this value, even if you determine it is
842 * non-null.
844 * Input:
845 * cmd = Linux SCSI command packet of the command that cause the
846 * bus device reset.
848 * Returns:
849 * SUCCESS/FAILURE (defined as macro in scsi.h).
851 **************************************************************************/
853 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
855 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
856 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
857 fc_port_t *fcport = tq->fcport;
858 os_lun_t *lq;
859 srb_t *sp;
860 int ret;
861 unsigned int id, lun;
862 unsigned long serial;
864 ret = FAILED;
866 id = cmd->device->id;
867 lun = cmd->device->lun;
868 serial = cmd->serial_number;
870 sp = (srb_t *) CMD_SP(cmd);
871 lq = GET_LU_Q(ha, id, lun);
872 if (!sp || !fcport || !lq)
873 return ret;
875 qla_printk(KERN_INFO, ha,
876 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
878 spin_unlock_irq(ha->host->host_lock);
880 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
881 spin_lock_irq(ha->host->host_lock);
882 goto eh_dev_reset_done;
885 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
886 if (qla2x00_device_reset(ha, fcport) == 0)
887 ret = SUCCESS;
889 #if defined(LOGOUT_AFTER_DEVICE_RESET)
890 if (ret == SUCCESS) {
891 if (fcport->flags & FC_FABRIC_DEVICE) {
892 qla2x00_fabric_logout(ha, fcport->loop_id);
893 qla2x00_mark_device_lost(ha, fcport);
896 #endif
897 } else {
898 DEBUG2(printk(KERN_INFO
899 "%s failed: loop not ready\n",__func__);)
902 if (ret == FAILED) {
903 DEBUG3(printk("%s(%ld): device reset failed\n",
904 __func__, ha->host_no));
905 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
906 __func__);
908 goto eh_dev_reset_done;
912 * If we are coming down the EH path, wait for all commands to
913 * complete for the device.
915 if (cmd->device->host->eh_active) {
916 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
917 ret = FAILED;
919 if (ret == FAILED) {
920 DEBUG3(printk("%s(%ld): failed while waiting for "
921 "commands\n", __func__, ha->host_no));
922 qla_printk(KERN_INFO, ha,
923 "%s: failed while waiting for commands\n",
924 __func__);
926 goto eh_dev_reset_done;
930 qla_printk(KERN_INFO, ha,
931 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
933 eh_dev_reset_done:
934 spin_lock_irq(ha->host->host_lock);
936 return ret;
939 /**************************************************************************
940 * qla2x00_eh_wait_for_pending_commands
942 * Description:
943 * Waits for all the commands to come back from the specified host.
945 * Input:
946 * ha - pointer to scsi_qla_host structure.
948 * Returns:
949 * 1 : SUCCESS
950 * 0 : FAILED
952 * Note:
953 **************************************************************************/
954 static int
955 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
957 int cnt;
958 int status;
959 srb_t *sp;
960 struct scsi_cmnd *cmd;
962 status = 1;
965 * Waiting for all commands for the designated target in the active
966 * array
968 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
969 spin_lock(&ha->hardware_lock);
970 sp = ha->outstanding_cmds[cnt];
971 if (sp) {
972 cmd = sp->cmd;
973 spin_unlock(&ha->hardware_lock);
974 status = qla2x00_eh_wait_on_command(ha, cmd);
975 if (status == 0)
976 break;
978 else {
979 spin_unlock(&ha->hardware_lock);
982 return (status);
986 /**************************************************************************
987 * qla2xxx_eh_bus_reset
989 * Description:
990 * The bus reset function will reset the bus and abort any executing
991 * commands.
993 * Input:
994 * cmd = Linux SCSI command packet of the command that cause the
995 * bus reset.
997 * Returns:
998 * SUCCESS/FAILURE (defined as macro in scsi.h).
1000 **************************************************************************/
1002 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1004 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
1005 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
1006 fc_port_t *fcport = tq->fcport;
1007 os_lun_t *lq;
1008 srb_t *sp;
1009 int ret;
1010 unsigned int id, lun;
1011 unsigned long serial;
1013 ret = FAILED;
1015 id = cmd->device->id;
1016 lun = cmd->device->lun;
1017 serial = cmd->serial_number;
1019 sp = (srb_t *) CMD_SP(cmd);
1020 lq = GET_LU_Q(ha, id, lun);
1021 if (!sp || !fcport || !lq)
1022 return ret;
1024 qla_printk(KERN_INFO, ha,
1025 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
1027 spin_unlock_irq(ha->host->host_lock);
1029 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1030 DEBUG2(printk("%s failed:board disabled\n",__func__));
1031 goto eh_bus_reset_done;
1034 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1035 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
1036 ret = SUCCESS;
1038 if (ret == FAILED)
1039 goto eh_bus_reset_done;
1041 /* Waiting for our command in done_queue to be returned to OS.*/
1042 if (cmd->device->host->eh_active)
1043 if (!qla2x00_eh_wait_for_pending_commands(ha))
1044 ret = FAILED;
1046 eh_bus_reset_done:
1047 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1048 (ret == FAILED) ? "failed" : "succeded");
1050 spin_lock_irq(ha->host->host_lock);
1052 return ret;
1055 /**************************************************************************
1056 * qla2xxx_eh_host_reset
1058 * Description:
1059 * The reset function will reset the Adapter.
1061 * Input:
1062 * cmd = Linux SCSI command packet of the command that cause the
1063 * adapter reset.
1065 * Returns:
1066 * Either SUCCESS or FAILED.
1068 * Note:
1069 **************************************************************************/
1071 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1073 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
1074 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
1075 fc_port_t *fcport = tq->fcport;
1076 os_lun_t *lq;
1077 srb_t *sp;
1078 int ret;
1079 unsigned int id, lun;
1080 unsigned long serial;
1082 ret = FAILED;
1084 id = cmd->device->id;
1085 lun = cmd->device->lun;
1086 serial = cmd->serial_number;
1088 sp = (srb_t *) CMD_SP(cmd);
1089 lq = GET_LU_Q(ha, id, lun);
1090 if (!sp || !fcport || !lq)
1091 return ret;
1093 qla_printk(KERN_INFO, ha,
1094 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
1096 spin_unlock_irq(ha->host->host_lock);
1098 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1099 goto eh_host_reset_lock;
1102 * Fixme-may be dpc thread is active and processing
1103 * loop_resync,so wait a while for it to
1104 * be completed and then issue big hammer.Otherwise
1105 * it may cause I/O failure as big hammer marks the
1106 * devices as lost kicking of the port_down_timer
1107 * while dpc is stuck for the mailbox to complete.
1109 qla2x00_wait_for_loop_ready(ha);
1110 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1111 if (qla2x00_abort_isp(ha)) {
1112 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1113 /* failed. schedule dpc to try */
1114 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1116 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1117 goto eh_host_reset_lock;
1119 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1121 /* Waiting for our command in done_queue to be returned to OS.*/
1122 if (qla2x00_eh_wait_for_pending_commands(ha))
1123 ret = SUCCESS;
1125 eh_host_reset_lock:
1126 spin_lock_irq(ha->host->host_lock);
1128 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1129 (ret == FAILED) ? "failed" : "succeded");
1131 return ret;
1135 * qla2x00_loop_reset
1136 * Issue loop reset.
1138 * Input:
1139 * ha = adapter block pointer.
1141 * Returns:
1142 * 0 = success
1144 static int
1145 qla2x00_loop_reset(scsi_qla_host_t *ha)
1147 int status = QLA_SUCCESS;
1148 uint16_t t;
1149 os_tgt_t *tq;
1151 if (ha->flags.enable_lip_reset) {
1152 status = qla2x00_lip_reset(ha);
1155 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1156 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1157 if ((tq = TGT_Q(ha, t)) == NULL)
1158 continue;
1160 if (tq->fcport == NULL)
1161 continue;
1163 status = qla2x00_target_reset(ha, 0, t);
1164 if (status != QLA_SUCCESS) {
1165 break;
1170 if (status == QLA_SUCCESS &&
1171 ((!ha->flags.enable_target_reset &&
1172 !ha->flags.enable_lip_reset) ||
1173 ha->flags.enable_lip_full_login)) {
1175 status = qla2x00_full_login_lip(ha);
1178 /* Issue marker command only when we are going to start the I/O */
1179 ha->marker_needed = 1;
1181 if (status) {
1182 /* Empty */
1183 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1184 __func__,
1185 ha->host_no);)
1186 } else {
1187 /* Empty */
1188 DEBUG3(printk("%s(%ld): exiting normally.\n",
1189 __func__,
1190 ha->host_no);)
1193 return(status);
1197 * qla2x00_device_reset
1198 * Issue bus device reset message to the target.
1200 * Input:
1201 * ha = adapter block pointer.
1202 * t = SCSI ID.
1203 * TARGET_QUEUE_LOCK must be released.
1204 * ADAPTER_STATE_LOCK must be released.
1206 * Context:
1207 * Kernel context.
1209 static int
1210 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1212 /* Abort Target command will clear Reservation */
1213 return qla2x00_abort_target(reset_fcport);
1216 static int
1217 qla2xxx_slave_alloc(struct scsi_device *sdev)
1219 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1220 os_tgt_t *tq;
1222 tq = (os_tgt_t *) TGT_Q(ha, sdev->id);
1223 if (!tq)
1224 return -ENXIO;
1225 if (!tq->fcport)
1226 return -ENXIO;
1228 sdev->hostdata = tq;
1230 return 0;
1233 static int
1234 qla2xxx_slave_configure(struct scsi_device *sdev)
1236 if (sdev->tagged_supported)
1237 scsi_activate_tcq(sdev, 32);
1238 else
1239 scsi_deactivate_tcq(sdev, 32);
1241 return 0;
1244 static void
1245 qla2xxx_slave_destroy(struct scsi_device *sdev)
1247 sdev->hostdata = NULL;
1251 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1252 * @ha: HA context
1254 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1255 * supported addressing method.
1257 static void
1258 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1260 /* Assume 32bit DMA address */
1261 ha->flags.enable_64bit_addressing = 0;
1262 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1263 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1266 * Given the two variants pci_set_dma_mask(), allow the compiler to
1267 * assist in setting the proper dma mask.
1269 if (sizeof(dma_addr_t) > 4) {
1270 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1271 ha->flags.enable_64bit_addressing = 1;
1272 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1273 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1275 if (pci_set_consistent_dma_mask(ha->pdev,
1276 DMA_64BIT_MASK)) {
1277 qla_printk(KERN_DEBUG, ha,
1278 "Failed to set 64 bit PCI consistent mask; "
1279 "using 32 bit.\n");
1280 pci_set_consistent_dma_mask(ha->pdev,
1281 DMA_32BIT_MASK);
1283 } else {
1284 qla_printk(KERN_DEBUG, ha,
1285 "Failed to set 64 bit PCI DMA mask, falling back "
1286 "to 32 bit MASK.\n");
1287 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1289 } else {
1290 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1294 static int
1295 qla2x00_iospace_config(scsi_qla_host_t *ha)
1297 unsigned long pio, pio_len, pio_flags;
1298 unsigned long mmio, mmio_len, mmio_flags;
1300 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1301 pio = pci_resource_start(ha->pdev, 0);
1302 pio_len = pci_resource_len(ha->pdev, 0);
1303 pio_flags = pci_resource_flags(ha->pdev, 0);
1304 if (pio_flags & IORESOURCE_IO) {
1305 if (pio_len < MIN_IOBASE_LEN) {
1306 qla_printk(KERN_WARNING, ha,
1307 "Invalid PCI I/O region size (%s)...\n",
1308 pci_name(ha->pdev));
1309 pio = 0;
1311 } else {
1312 qla_printk(KERN_WARNING, ha,
1313 "region #0 not a PIO resource (%s)...\n",
1314 pci_name(ha->pdev));
1315 pio = 0;
1318 /* Use MMIO operations for all accesses. */
1319 mmio = pci_resource_start(ha->pdev, 1);
1320 mmio_len = pci_resource_len(ha->pdev, 1);
1321 mmio_flags = pci_resource_flags(ha->pdev, 1);
1323 if (!(mmio_flags & IORESOURCE_MEM)) {
1324 qla_printk(KERN_ERR, ha,
1325 "region #0 not an MMIO resource (%s), aborting\n",
1326 pci_name(ha->pdev));
1327 goto iospace_error_exit;
1329 if (mmio_len < MIN_IOBASE_LEN) {
1330 qla_printk(KERN_ERR, ha,
1331 "Invalid PCI mem region size (%s), aborting\n",
1332 pci_name(ha->pdev));
1333 goto iospace_error_exit;
1336 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1337 qla_printk(KERN_WARNING, ha,
1338 "Failed to reserve PIO/MMIO regions (%s)\n",
1339 pci_name(ha->pdev));
1341 goto iospace_error_exit;
1344 ha->pio_address = pio;
1345 ha->pio_length = pio_len;
1346 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1347 if (!ha->iobase) {
1348 qla_printk(KERN_ERR, ha,
1349 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1351 goto iospace_error_exit;
1354 return (0);
1356 iospace_error_exit:
1357 return (-ENOMEM);
1361 * PCI driver interface
1363 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1365 int ret;
1366 device_reg_t __iomem *reg;
1367 struct Scsi_Host *host;
1368 scsi_qla_host_t *ha;
1369 unsigned long flags = 0;
1370 unsigned long wait_switch = 0;
1371 char pci_info[20];
1372 char fw_str[30];
1374 if (pci_enable_device(pdev))
1375 return -1;
1377 host = scsi_host_alloc(&qla2x00_driver_template,
1378 sizeof(scsi_qla_host_t));
1379 if (host == NULL) {
1380 printk(KERN_WARNING
1381 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1382 goto probe_disable_device;
1385 /* Clear our data area */
1386 ha = (scsi_qla_host_t *)host->hostdata;
1387 memset(ha, 0, sizeof(scsi_qla_host_t));
1389 ha->pdev = pdev;
1390 ha->host = host;
1391 ha->host_no = host->host_no;
1392 ha->brd_info = brd_info;
1393 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1395 /* Configure PCI I/O space */
1396 ret = qla2x00_iospace_config(ha);
1397 if (ret != 0) {
1398 goto probe_failed;
1401 /* Sanitize the information from PCI BIOS. */
1402 host->irq = pdev->irq;
1404 qla_printk(KERN_INFO, ha,
1405 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1406 host->irq, ha->iobase);
1408 spin_lock_init(&ha->hardware_lock);
1410 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1411 ha->actthreads = 0;
1412 ha->qthreads = 0;
1413 ha->total_isr_cnt = 0;
1414 ha->total_isp_aborts = 0;
1415 ha->total_lip_cnt = 0;
1416 ha->total_dev_errs = 0;
1417 ha->total_ios = 0;
1418 ha->total_bytes = 0;
1420 ha->prev_topology = 0;
1421 ha->ports = MAX_BUSES;
1423 if (IS_QLA2100(ha)) {
1424 ha->max_targets = MAX_TARGETS_2100;
1425 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1426 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1427 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1428 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1429 host->sg_tablesize = 32;
1430 } else if (IS_QLA2200(ha)) {
1431 ha->max_targets = MAX_TARGETS_2200;
1432 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1433 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1434 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1435 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1436 } else /*if (IS_QLA2300(ha))*/ {
1437 ha->max_targets = MAX_TARGETS_2200;
1438 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1439 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1440 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1441 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1443 host->can_queue = ha->request_q_length + 128;
1445 /* load the F/W, read paramaters, and init the H/W */
1446 ha->instance = num_hosts;
1448 init_MUTEX(&ha->mbx_cmd_sem);
1449 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1451 INIT_LIST_HEAD(&ha->list);
1452 INIT_LIST_HEAD(&ha->fcports);
1453 INIT_LIST_HEAD(&ha->rscn_fcports);
1456 * These locks are used to prevent more than one CPU
1457 * from modifying the queue at the same time. The
1458 * higher level "host_lock" will reduce most
1459 * contention for these locks.
1461 spin_lock_init(&ha->mbx_reg_lock);
1463 ha->dpc_pid = -1;
1464 init_completion(&ha->dpc_inited);
1465 init_completion(&ha->dpc_exited);
1467 qla2x00_config_dma_addressing(ha);
1468 if (qla2x00_mem_alloc(ha)) {
1469 qla_printk(KERN_WARNING, ha,
1470 "[ERROR] Failed to allocate memory for adapter\n");
1472 goto probe_failed;
1475 if (qla2x00_initialize_adapter(ha) &&
1476 !(ha->device_flags & DFLG_NO_CABLE)) {
1478 qla_printk(KERN_WARNING, ha,
1479 "Failed to initialize adapter\n");
1481 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1482 "Adapter flags %x.\n",
1483 ha->host_no, ha->device_flags));
1485 goto probe_failed;
1489 * Startup the kernel thread for this host adapter
1491 ha->dpc_should_die = 0;
1492 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1493 if (ha->dpc_pid < 0) {
1494 qla_printk(KERN_WARNING, ha,
1495 "Unable to start DPC thread!\n");
1497 goto probe_failed;
1499 wait_for_completion(&ha->dpc_inited);
1501 host->this_id = 255;
1502 host->cmd_per_lun = 3;
1503 host->max_cmd_len = MAX_CMDSZ;
1504 host->max_channel = ha->ports - 1;
1505 host->max_lun = ha->max_luns;
1506 BUG_ON(qla2xxx_transport_template == NULL);
1507 host->transportt = qla2xxx_transport_template;
1508 host->unique_id = ha->instance;
1509 host->max_id = ha->max_targets;
1511 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1512 ret = request_irq(host->irq, qla2100_intr_handler,
1513 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1514 else
1515 ret = request_irq(host->irq, qla2300_intr_handler,
1516 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1517 if (ret != 0) {
1518 qla_printk(KERN_WARNING, ha,
1519 "Failed to reserve interrupt %d already in use.\n",
1520 host->irq);
1521 goto probe_failed;
1524 /* Initialized the timer */
1525 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1527 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1528 ha->host_no, ha));
1530 reg = ha->iobase;
1532 /* Disable ISP interrupts. */
1533 qla2x00_disable_intrs(ha);
1535 /* Ensure mailbox registers are free. */
1536 spin_lock_irqsave(&ha->hardware_lock, flags);
1537 WRT_REG_WORD(&reg->semaphore, 0);
1538 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1539 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1541 /* Enable proper parity */
1542 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1543 if (IS_QLA2300(ha))
1544 /* SRAM parity */
1545 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x1));
1546 else
1547 /* SRAM, Instruction RAM and GP RAM parity */
1548 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x7));
1550 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1552 /* Enable chip interrupts. */
1553 qla2x00_enable_intrs(ha);
1555 /* v2.19.5b6 */
1557 * Wait around max loop_reset_delay secs for the devices to come
1558 * on-line. We don't want Linux scanning before we are ready.
1561 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1562 time_before(jiffies,wait_switch) &&
1563 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1564 && (ha->device_flags & SWITCH_FOUND) ;) {
1566 qla2x00_check_fabric_devices(ha);
1568 msleep(10);
1571 pci_set_drvdata(pdev, ha);
1572 ha->flags.init_done = 1;
1573 num_hosts++;
1575 /* List the target we have found */
1576 if (displayConfig) {
1577 qla2x00_display_fc_names(ha);
1580 if (scsi_add_host(host, &pdev->dev))
1581 goto probe_failed;
1583 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
1584 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
1586 qla_printk(KERN_INFO, ha, "\n"
1587 " QLogic Fibre Channel HBA Driver: %s\n"
1588 " QLogic %s - %s\n"
1589 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1590 ha->model_number, ha->model_desc ? ha->model_desc: "",
1591 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
1592 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
1593 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
1595 if (ql2xdoinitscan)
1596 scsi_scan_host(host);
1598 return 0;
1600 probe_failed:
1601 qla2x00_free_device(ha);
1603 scsi_host_put(host);
1605 probe_disable_device:
1606 pci_disable_device(pdev);
1608 return -1;
1610 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1612 void qla2x00_remove_one(struct pci_dev *pdev)
1614 scsi_qla_host_t *ha;
1616 ha = pci_get_drvdata(pdev);
1618 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj,
1619 &sysfs_fw_dump_attr);
1620 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr);
1622 scsi_remove_host(ha->host);
1624 qla2x00_free_device(ha);
1626 scsi_host_put(ha->host);
1628 pci_set_drvdata(pdev, NULL);
1630 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1632 static void
1633 qla2x00_free_device(scsi_qla_host_t *ha)
1635 int ret;
1637 /* Abort any outstanding IO descriptors. */
1638 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1639 qla2x00_cancel_io_descriptors(ha);
1641 /* turn-off interrupts on the card */
1642 if (ha->interrupts_on)
1643 qla2x00_disable_intrs(ha);
1645 /* Disable timer */
1646 if (ha->timer_active)
1647 qla2x00_stop_timer(ha);
1649 /* Kill the kernel thread for this host */
1650 if (ha->dpc_pid >= 0) {
1651 ha->dpc_should_die = 1;
1652 wmb();
1653 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1654 if (ret) {
1655 qla_printk(KERN_ERR, ha,
1656 "Unable to signal DPC thread -- (%d)\n", ret);
1658 /* TODO: SOMETHING MORE??? */
1659 } else {
1660 wait_for_completion(&ha->dpc_exited);
1664 qla2x00_mem_free(ha);
1667 ha->flags.online = 0;
1669 /* Detach interrupts */
1670 if (ha->pdev->irq)
1671 free_irq(ha->pdev->irq, ha);
1673 /* release io space registers */
1674 if (ha->iobase)
1675 iounmap(ha->iobase);
1676 pci_release_regions(ha->pdev);
1678 pci_disable_device(ha->pdev);
1683 * The following support functions are adopted to handle
1684 * the re-entrant qla2x00_proc_info correctly.
1686 static void
1687 copy_mem_info(struct info_str *info, char *data, int len)
1689 if (info->pos + len > info->offset + info->length)
1690 len = info->offset + info->length - info->pos;
1692 if (info->pos + len < info->offset) {
1693 info->pos += len;
1694 return;
1697 if (info->pos < info->offset) {
1698 off_t partial;
1700 partial = info->offset - info->pos;
1701 data += partial;
1702 info->pos += partial;
1703 len -= partial;
1706 if (len > 0) {
1707 memcpy(info->buffer, data, len);
1708 info->pos += len;
1709 info->buffer += len;
1713 static int
1714 copy_info(struct info_str *info, char *fmt, ...)
1716 va_list args;
1717 char buf[256];
1718 int len;
1720 va_start(args, fmt);
1721 len = vsprintf(buf, fmt, args);
1722 va_end(args);
1724 copy_mem_info(info, buf, len);
1726 return (len);
1729 /*************************************************************************
1730 * qla2x00_proc_info
1732 * Description:
1733 * Return information to handle /proc support for the driver.
1735 * inout : decides the direction of the dataflow and the meaning of the
1736 * variables
1737 * buffer: If inout==0 data is being written to it else read from it
1738 * (ptr to a page buffer)
1739 * *start: If inout==0 start of the valid data in the buffer
1740 * offset: If inout==0 starting offset from the beginning of all
1741 * possible data to return.
1742 * length: If inout==0 max number of bytes to be written into the buffer
1743 * else number of bytes in "buffer"
1744 * Returns:
1745 * < 0: error. errno value.
1746 * >= 0: sizeof data returned.
1747 *************************************************************************/
1749 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
1750 char **start, off_t offset, int length, int inout)
1752 struct info_str info;
1753 int retval = -EINVAL;
1754 os_lun_t *up;
1755 os_tgt_t *tq;
1756 unsigned int t, l;
1757 uint32_t tmp_sn;
1758 uint32_t *flags;
1759 uint8_t *loop_state;
1760 scsi_qla_host_t *ha;
1761 char fw_info[30];
1763 DEBUG3(printk(KERN_INFO
1764 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
1765 buffer, offset, length);)
1767 ha = (scsi_qla_host_t *) shost->hostdata;
1769 if (inout) {
1770 /* Has data been written to the file? */
1771 DEBUG3(printk(
1772 "%s: has data been written to the file. \n",
1773 __func__);)
1775 return -ENOSYS;
1778 if (start) {
1779 *start = buffer;
1782 info.buffer = buffer;
1783 info.length = length;
1784 info.offset = offset;
1785 info.pos = 0;
1787 /* start building the print buffer */
1788 copy_info(&info,
1789 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
1790 " Firmware version %s, ",
1791 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
1793 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
1795 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
1796 ha->serial1;
1797 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
1798 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
1800 copy_info(&info,
1801 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
1802 (unsigned long long)ha->request_dma,
1803 (unsigned long long)ha->response_dma);
1805 copy_info(&info,
1806 "Request Queue count = %d, Response Queue count = %d\n",
1807 ha->request_q_length, ha->response_q_length);
1809 copy_info(&info,
1810 "Total number of active commands = %ld\n",
1811 ha->actthreads);
1813 copy_info(&info,
1814 "Total number of interrupts = %ld\n",
1815 (long)ha->total_isr_cnt);
1817 copy_info(&info,
1818 " Device queue depth = 0x%x\n",
1819 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
1821 copy_info(&info,
1822 "Number of free request entries = %d\n", ha->req_q_cnt);
1824 copy_info(&info,
1825 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
1827 copy_info(&info,
1828 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
1830 copy_info(&info,
1831 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
1833 copy_info(&info,
1834 "Number of retries for empty slots = %ld\n",
1835 qla2x00_stats.outarray_full);
1837 flags = (uint32_t *) &ha->flags;
1839 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
1840 loop_state = "DOWN";
1841 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
1842 loop_state = "UP";
1843 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
1844 loop_state = "READY";
1845 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
1846 loop_state = "TIMEOUT";
1847 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
1848 loop_state = "UPDATE";
1849 } else {
1850 loop_state = "UNKNOWN";
1853 copy_info(&info,
1854 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
1855 loop_state , *flags);
1857 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
1859 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
1861 copy_info(&info, "Link down Timeout = %3.3d\n",
1862 ha->link_down_timeout);
1864 copy_info(&info, "Port down retry = %3.3d\n",
1865 ha->port_down_retry_count);
1867 copy_info(&info, "Login retry count = %3.3d\n",
1868 ha->login_retry_count);
1870 copy_info(&info,
1871 "Commands retried with dropped frame(s) = %d\n",
1872 ha->dropped_frame_error_cnt);
1874 copy_info(&info,
1875 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
1876 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
1878 copy_info(&info, "\n");
1880 /* 2.25 node/port display to proc */
1881 /* Display the node name for adapter */
1882 copy_info(&info, "\nSCSI Device Information:\n");
1883 copy_info(&info,
1884 "scsi-qla%d-adapter-node="
1885 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1886 (int)ha->instance,
1887 ha->init_cb->node_name[0],
1888 ha->init_cb->node_name[1],
1889 ha->init_cb->node_name[2],
1890 ha->init_cb->node_name[3],
1891 ha->init_cb->node_name[4],
1892 ha->init_cb->node_name[5],
1893 ha->init_cb->node_name[6],
1894 ha->init_cb->node_name[7]);
1896 /* display the port name for adapter */
1897 copy_info(&info,
1898 "scsi-qla%d-adapter-port="
1899 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1900 (int)ha->instance,
1901 ha->init_cb->port_name[0],
1902 ha->init_cb->port_name[1],
1903 ha->init_cb->port_name[2],
1904 ha->init_cb->port_name[3],
1905 ha->init_cb->port_name[4],
1906 ha->init_cb->port_name[5],
1907 ha->init_cb->port_name[6],
1908 ha->init_cb->port_name[7]);
1910 /* Print out device port names */
1911 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1912 if ((tq = TGT_Q(ha, t)) == NULL)
1913 continue;
1915 copy_info(&info,
1916 "scsi-qla%d-target-%d="
1917 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1918 (int)ha->instance, t,
1919 tq->port_name[0], tq->port_name[1],
1920 tq->port_name[2], tq->port_name[3],
1921 tq->port_name[4], tq->port_name[5],
1922 tq->port_name[6], tq->port_name[7]);
1925 copy_info(&info, "\nSCSI LUN Information:\n");
1926 copy_info(&info,
1927 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
1929 /* scan for all equipment stats */
1930 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1931 /* scan all luns */
1932 for (l = 0; l < ha->max_luns; l++) {
1933 up = (os_lun_t *) GET_LU_Q(ha, t, l);
1935 if (up == NULL) {
1936 continue;
1938 if (up->fclun == NULL) {
1939 continue;
1942 copy_info(&info,
1943 "(%2d:%2d): Total reqs %ld,",
1944 t,l,up->io_cnt);
1946 copy_info(&info,
1947 " Pending reqs %ld,",
1948 up->out_cnt);
1950 if (up->io_cnt < 4) {
1951 copy_info(&info,
1952 " flags 0x%x*,",
1953 (int)up->q_flag);
1954 } else {
1955 copy_info(&info,
1956 " flags 0x%x,",
1957 (int)up->q_flag);
1960 copy_info(&info,
1961 " %ld:%d:%02x %02x",
1962 up->fclun->fcport->ha->instance,
1963 up->fclun->fcport->cur_path,
1964 up->fclun->fcport->loop_id,
1965 up->fclun->device_type);
1967 copy_info(&info, "\n");
1969 if (info.pos >= info.offset + info.length) {
1970 /* No need to continue */
1971 goto profile_stop;
1975 if (info.pos >= info.offset + info.length) {
1976 /* No need to continue */
1977 break;
1981 profile_stop:
1983 retval = info.pos > info.offset ? info.pos - info.offset : 0;
1985 DEBUG3(printk(KERN_INFO
1986 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
1987 "length=0x%x\n", info.pos, offset, length);)
1989 return (retval);
1993 * qla2x00_display_fc_names
1994 * This routine will the node names of the different devices found
1995 * after port inquiry.
1997 * Input:
1998 * cmd = SCSI command structure
2000 * Returns:
2001 * None.
2003 static void
2004 qla2x00_display_fc_names(scsi_qla_host_t *ha)
2006 uint16_t tgt;
2007 os_tgt_t *tq;
2009 /* Display the node name for adapter */
2010 qla_printk(KERN_INFO, ha,
2011 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2012 (int)ha->instance,
2013 ha->init_cb->node_name[0],
2014 ha->init_cb->node_name[1],
2015 ha->init_cb->node_name[2],
2016 ha->init_cb->node_name[3],
2017 ha->init_cb->node_name[4],
2018 ha->init_cb->node_name[5],
2019 ha->init_cb->node_name[6],
2020 ha->init_cb->node_name[7]);
2022 /* display the port name for adapter */
2023 qla_printk(KERN_INFO, ha,
2024 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2025 (int)ha->instance,
2026 ha->init_cb->port_name[0],
2027 ha->init_cb->port_name[1],
2028 ha->init_cb->port_name[2],
2029 ha->init_cb->port_name[3],
2030 ha->init_cb->port_name[4],
2031 ha->init_cb->port_name[5],
2032 ha->init_cb->port_name[6],
2033 ha->init_cb->port_name[7]);
2035 /* Print out device port names */
2036 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
2037 if ((tq = ha->otgt[tgt]) == NULL)
2038 continue;
2040 if (tq->fcport == NULL)
2041 continue;
2043 switch (ha->binding_type) {
2044 case BIND_BY_PORT_NAME:
2045 qla_printk(KERN_INFO, ha,
2046 "scsi-qla%d-tgt-%d-di-0-port="
2047 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2048 (int)ha->instance,
2049 tgt,
2050 tq->port_name[0],
2051 tq->port_name[1],
2052 tq->port_name[2],
2053 tq->port_name[3],
2054 tq->port_name[4],
2055 tq->port_name[5],
2056 tq->port_name[6],
2057 tq->port_name[7]);
2059 break;
2061 case BIND_BY_PORT_ID:
2062 qla_printk(KERN_INFO, ha,
2063 "scsi-qla%d-tgt-%d-di-0-pid="
2064 "%02x%02x%02x\\;\n",
2065 (int)ha->instance,
2066 tgt,
2067 tq->d_id.b.domain,
2068 tq->d_id.b.area,
2069 tq->d_id.b.al_pa);
2070 break;
2073 #if VSA
2074 qla_printk(KERN_INFO, ha,
2075 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
2076 #endif
2082 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2084 * Input: ha = adapter block pointer. fcport = port structure pointer.
2086 * Return: None.
2088 * Context:
2090 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
2091 int do_login)
2094 * We may need to retry the login, so don't change the state of the
2095 * port but do the retries.
2097 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2098 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2100 if (!do_login)
2101 return;
2103 if (fcport->login_retry == 0) {
2104 fcport->login_retry = ha->login_retry_count;
2105 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2107 DEBUG(printk("scsi(%ld): Port login retry: "
2108 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2109 "id = 0x%04x retry cnt=%d\n",
2110 ha->host_no,
2111 fcport->port_name[0],
2112 fcport->port_name[1],
2113 fcport->port_name[2],
2114 fcport->port_name[3],
2115 fcport->port_name[4],
2116 fcport->port_name[5],
2117 fcport->port_name[6],
2118 fcport->port_name[7],
2119 fcport->loop_id,
2120 fcport->login_retry));
2125 * qla2x00_mark_all_devices_lost
2126 * Updates fcport state when device goes offline.
2128 * Input:
2129 * ha = adapter block pointer.
2130 * fcport = port structure pointer.
2132 * Return:
2133 * None.
2135 * Context:
2137 void
2138 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
2140 fc_port_t *fcport;
2142 list_for_each_entry(fcport, &ha->fcports, list) {
2143 if (fcport->port_type != FCT_TARGET)
2144 continue;
2147 * No point in marking the device as lost, if the device is
2148 * already DEAD.
2150 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2151 continue;
2153 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2158 * qla2x00_mem_alloc
2159 * Allocates adapter memory.
2161 * Returns:
2162 * 0 = success.
2163 * 1 = failure.
2165 static uint8_t
2166 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2168 char name[16];
2169 uint8_t status = 1;
2170 int retry= 10;
2172 do {
2174 * This will loop only once if everything goes well, else some
2175 * number of retries will be performed to get around a kernel
2176 * bug where available mem is not allocated until after a
2177 * little delay and a retry.
2179 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2180 (ha->request_q_length + 1) * sizeof(request_t),
2181 &ha->request_dma, GFP_KERNEL);
2182 if (ha->request_ring == NULL) {
2183 qla_printk(KERN_WARNING, ha,
2184 "Memory Allocation failed - request_ring\n");
2186 qla2x00_mem_free(ha);
2187 msleep(100);
2189 continue;
2192 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2193 (ha->response_q_length + 1) * sizeof(response_t),
2194 &ha->response_dma, GFP_KERNEL);
2195 if (ha->response_ring == NULL) {
2196 qla_printk(KERN_WARNING, ha,
2197 "Memory Allocation failed - response_ring\n");
2199 qla2x00_mem_free(ha);
2200 msleep(100);
2202 continue;
2205 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2206 &ha->gid_list_dma, GFP_KERNEL);
2207 if (ha->gid_list == NULL) {
2208 qla_printk(KERN_WARNING, ha,
2209 "Memory Allocation failed - gid_list\n");
2211 qla2x00_mem_free(ha);
2212 msleep(100);
2214 continue;
2217 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
2218 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
2219 if (ha->rlc_rsp == NULL) {
2220 qla_printk(KERN_WARNING, ha,
2221 "Memory Allocation failed - rlc");
2223 qla2x00_mem_free(ha);
2224 msleep(100);
2226 continue;
2229 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
2230 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2231 DMA_POOL_SIZE, 8, 0);
2232 if (ha->s_dma_pool == NULL) {
2233 qla_printk(KERN_WARNING, ha,
2234 "Memory Allocation failed - s_dma_pool\n");
2236 qla2x00_mem_free(ha);
2237 msleep(100);
2239 continue;
2242 /* get consistent memory allocated for init control block */
2243 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2244 &ha->init_cb_dma);
2245 if (ha->init_cb == NULL) {
2246 qla_printk(KERN_WARNING, ha,
2247 "Memory Allocation failed - init_cb\n");
2249 qla2x00_mem_free(ha);
2250 msleep(100);
2252 continue;
2254 memset(ha->init_cb, 0, sizeof(init_cb_t));
2256 /* Get consistent memory allocated for Get Port Database cmd */
2257 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2258 &ha->iodesc_pd_dma);
2259 if (ha->iodesc_pd == NULL) {
2260 /* error */
2261 qla_printk(KERN_WARNING, ha,
2262 "Memory Allocation failed - iodesc_pd\n");
2264 qla2x00_mem_free(ha);
2265 msleep(100);
2267 continue;
2269 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
2271 /* Allocate ioctl related memory. */
2272 if (qla2x00_alloc_ioctl_mem(ha)) {
2273 qla_printk(KERN_WARNING, ha,
2274 "Memory Allocation failed - ioctl_mem\n");
2276 qla2x00_mem_free(ha);
2277 msleep(100);
2279 continue;
2282 if (qla2x00_allocate_sp_pool(ha)) {
2283 qla_printk(KERN_WARNING, ha,
2284 "Memory Allocation failed - "
2285 "qla2x00_allocate_sp_pool()\n");
2287 qla2x00_mem_free(ha);
2288 msleep(100);
2290 continue;
2293 /* Allocate memory for SNS commands */
2294 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2295 /* Get consistent memory allocated for SNS commands */
2296 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2297 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
2298 GFP_KERNEL);
2299 if (ha->sns_cmd == NULL) {
2300 /* error */
2301 qla_printk(KERN_WARNING, ha,
2302 "Memory Allocation failed - sns_cmd\n");
2304 qla2x00_mem_free(ha);
2305 msleep(100);
2307 continue;
2309 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2310 } else {
2311 /* Get consistent memory allocated for MS IOCB */
2312 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2313 &ha->ms_iocb_dma);
2314 if (ha->ms_iocb == NULL) {
2315 /* error */
2316 qla_printk(KERN_WARNING, ha,
2317 "Memory Allocation failed - ms_iocb\n");
2319 qla2x00_mem_free(ha);
2320 msleep(100);
2322 continue;
2324 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2327 * Get consistent memory allocated for CT SNS
2328 * commands
2330 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2331 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2332 GFP_KERNEL);
2333 if (ha->ct_sns == NULL) {
2334 /* error */
2335 qla_printk(KERN_WARNING, ha,
2336 "Memory Allocation failed - ct_sns\n");
2338 qla2x00_mem_free(ha);
2339 msleep(100);
2341 continue;
2343 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2346 /* Done all allocations without any error. */
2347 status = 0;
2349 } while (retry-- && status != 0);
2351 if (status) {
2352 printk(KERN_WARNING
2353 "%s(): **** FAILED ****\n", __func__);
2356 return(status);
2360 * qla2x00_mem_free
2361 * Frees all adapter allocated memory.
2363 * Input:
2364 * ha = adapter block pointer.
2366 static void
2367 qla2x00_mem_free(scsi_qla_host_t *ha)
2369 uint32_t t;
2370 struct list_head *fcpl, *fcptemp;
2371 fc_port_t *fcport;
2372 struct list_head *fcll, *fcltemp;
2373 fc_lun_t *fclun;
2374 unsigned long wtime;/* max wait time if mbx cmd is busy. */
2376 if (ha == NULL) {
2377 /* error */
2378 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
2379 return;
2382 /* Free the target queues */
2383 for (t = 0; t < MAX_TARGETS; t++) {
2384 qla2x00_tgt_free(ha, t);
2387 /* Make sure all other threads are stopped. */
2388 wtime = 60 * HZ;
2389 while (ha->dpc_wait && wtime) {
2390 set_current_state(TASK_INTERRUPTIBLE);
2391 wtime = schedule_timeout(wtime);
2394 /* free ioctl memory */
2395 qla2x00_free_ioctl_mem(ha);
2397 /* free sp pool */
2398 qla2x00_free_sp_pool(ha);
2400 if (ha->sns_cmd)
2401 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2402 ha->sns_cmd, ha->sns_cmd_dma);
2404 if (ha->ct_sns)
2405 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2406 ha->ct_sns, ha->ct_sns_dma);
2408 if (ha->ms_iocb)
2409 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2411 if (ha->iodesc_pd)
2412 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
2414 if (ha->init_cb)
2415 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
2417 if (ha->s_dma_pool)
2418 dma_pool_destroy(ha->s_dma_pool);
2420 if (ha->rlc_rsp)
2421 dma_free_coherent(&ha->pdev->dev,
2422 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2423 ha->rlc_rsp_dma);
2425 if (ha->gid_list)
2426 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2427 ha->gid_list_dma);
2429 if (ha->response_ring)
2430 dma_free_coherent(&ha->pdev->dev,
2431 (ha->response_q_length + 1) * sizeof(response_t),
2432 ha->response_ring, ha->response_dma);
2434 if (ha->request_ring)
2435 dma_free_coherent(&ha->pdev->dev,
2436 (ha->request_q_length + 1) * sizeof(request_t),
2437 ha->request_ring, ha->request_dma);
2439 ha->sns_cmd = NULL;
2440 ha->sns_cmd_dma = 0;
2441 ha->ct_sns = NULL;
2442 ha->ct_sns_dma = 0;
2443 ha->ms_iocb = NULL;
2444 ha->ms_iocb_dma = 0;
2445 ha->iodesc_pd = NULL;
2446 ha->iodesc_pd_dma = 0;
2447 ha->init_cb = NULL;
2448 ha->init_cb_dma = 0;
2450 ha->s_dma_pool = NULL;
2452 ha->rlc_rsp = NULL;
2453 ha->rlc_rsp_dma = 0;
2454 ha->gid_list = NULL;
2455 ha->gid_list_dma = 0;
2457 ha->response_ring = NULL;
2458 ha->response_dma = 0;
2459 ha->request_ring = NULL;
2460 ha->request_dma = 0;
2462 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2463 fcport = list_entry(fcpl, fc_port_t, list);
2465 /* fc luns */
2466 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
2467 fclun = list_entry(fcll, fc_lun_t, list);
2469 list_del_init(&fclun->list);
2470 kfree(fclun);
2473 /* fc ports */
2474 list_del_init(&fcport->list);
2475 kfree(fcport);
2477 INIT_LIST_HEAD(&ha->fcports);
2479 if (ha->fw_dump)
2480 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2482 if (ha->fw_dump_buffer)
2483 vfree(ha->fw_dump_buffer);
2485 ha->fw_dump = NULL;
2486 ha->fw_dump_reading = 0;
2487 ha->fw_dump_buffer = NULL;
2491 * qla2x00_allocate_sp_pool
2492 * This routine is called during initialization to allocate
2493 * memory for local srb_t.
2495 * Input:
2496 * ha = adapter block pointer.
2498 * Context:
2499 * Kernel context.
2501 * Note: Sets the ref_count for non Null sp to one.
2503 static int
2504 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
2506 int rval;
2508 rval = QLA_SUCCESS;
2509 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2510 mempool_free_slab, srb_cachep);
2511 if (ha->srb_mempool == NULL) {
2512 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2513 rval = QLA_FUNCTION_FAILED;
2515 return (rval);
2519 * This routine frees all adapter allocated memory.
2522 static void
2523 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
2525 if (ha->srb_mempool) {
2526 mempool_destroy(ha->srb_mempool);
2527 ha->srb_mempool = NULL;
2531 /**************************************************************************
2532 * qla2x00_do_dpc
2533 * This kernel thread is a task that is schedule by the interrupt handler
2534 * to perform the background processing for interrupts.
2536 * Notes:
2537 * This task always run in the context of a kernel thread. It
2538 * is kick-off by the driver's detect code and starts up
2539 * up one per adapter. It immediately goes to sleep and waits for
2540 * some fibre event. When either the interrupt handler or
2541 * the timer routine detects a event it will one of the task
2542 * bits then wake us up.
2543 **************************************************************************/
2544 static int
2545 qla2x00_do_dpc(void *data)
2547 DECLARE_MUTEX_LOCKED(sem);
2548 scsi_qla_host_t *ha;
2549 fc_port_t *fcport;
2550 uint8_t status;
2551 uint16_t next_loopid;
2553 ha = (scsi_qla_host_t *)data;
2555 lock_kernel();
2557 daemonize("%s_dpc", ha->host_str);
2558 allow_signal(SIGHUP);
2560 ha->dpc_wait = &sem;
2562 set_user_nice(current, -20);
2564 unlock_kernel();
2566 complete(&ha->dpc_inited);
2568 while (1) {
2569 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2571 if (down_interruptible(&sem))
2572 break;
2574 if (ha->dpc_should_die)
2575 break;
2577 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2579 /* Initialization not yet finished. Don't do anything yet. */
2580 if (!ha->flags.init_done || ha->dpc_active)
2581 continue;
2583 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2585 ha->dpc_active = 1;
2587 if (ha->flags.mbox_busy) {
2588 ha->dpc_active = 0;
2589 continue;
2592 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2594 DEBUG(printk("scsi(%ld): dpc: sched "
2595 "qla2x00_abort_isp ha = %p\n",
2596 ha->host_no, ha));
2597 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2598 &ha->dpc_flags))) {
2600 if (qla2x00_abort_isp(ha)) {
2601 /* failed. retry later */
2602 set_bit(ISP_ABORT_NEEDED,
2603 &ha->dpc_flags);
2605 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2607 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2608 ha->host_no));
2611 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2612 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2614 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2615 ha->host_no));
2617 qla2x00_rst_aen(ha);
2618 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2621 /* Retry each device up to login retry count */
2622 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2623 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2624 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2626 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2627 ha->host_no));
2629 next_loopid = 0;
2630 list_for_each_entry(fcport, &ha->fcports, list) {
2631 if (fcport->port_type != FCT_TARGET)
2632 continue;
2635 * If the port is not ONLINE then try to login
2636 * to it if we haven't run out of retries.
2638 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2639 fcport->login_retry) {
2641 fcport->login_retry--;
2642 if (fcport->flags & FCF_FABRIC_DEVICE) {
2643 if (fcport->flags &
2644 FCF_TAPE_PRESENT)
2645 qla2x00_fabric_logout(
2647 fcport->loop_id);
2648 status = qla2x00_fabric_login(
2649 ha, fcport, &next_loopid);
2650 } else
2651 status =
2652 qla2x00_local_device_login(
2653 ha, fcport->loop_id);
2655 if (status == QLA_SUCCESS) {
2656 fcport->old_loop_id = fcport->loop_id;
2658 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2659 ha->host_no, fcport->loop_id));
2661 fcport->port_login_retry_count =
2662 ha->port_down_retry_count * PORT_RETRY_TIME;
2663 atomic_set(&fcport->state, FCS_ONLINE);
2664 atomic_set(&fcport->port_down_timer,
2665 ha->port_down_retry_count * PORT_RETRY_TIME);
2667 fcport->login_retry = 0;
2668 } else if (status == 1) {
2669 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2670 /* retry the login again */
2671 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2672 ha->host_no,
2673 fcport->login_retry, fcport->loop_id));
2674 } else {
2675 fcport->login_retry = 0;
2678 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2679 break;
2681 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2682 ha->host_no));
2685 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2686 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2688 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2689 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2690 ha->host_no));
2692 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2694 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2695 ha->host_no));
2698 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2700 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2701 ha->host_no));
2703 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2704 &ha->dpc_flags))) {
2706 qla2x00_loop_resync(ha);
2708 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2711 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2712 ha->host_no));
2715 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2717 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2718 ha->host_no));
2720 qla2x00_rescan_fcports(ha);
2722 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2723 "end.\n",
2724 ha->host_no));
2727 if (!ha->interrupts_on)
2728 qla2x00_enable_intrs(ha);
2730 ha->dpc_active = 0;
2731 } /* End of while(1) */
2733 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2736 * Make sure that nobody tries to wake us up again.
2738 ha->dpc_wait = NULL;
2739 ha->dpc_active = 0;
2741 complete_and_exit(&ha->dpc_exited, 0);
2745 * qla2x00_rst_aen
2746 * Processes asynchronous reset.
2748 * Input:
2749 * ha = adapter block pointer.
2751 static void
2752 qla2x00_rst_aen(scsi_qla_host_t *ha)
2754 if (ha->flags.online && !ha->flags.reset_active &&
2755 !atomic_read(&ha->loop_down_timer) &&
2756 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2757 do {
2758 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2761 * Issue marker command only when we are going to start
2762 * the I/O.
2764 ha->marker_needed = 1;
2765 } while (!atomic_read(&ha->loop_down_timer) &&
2766 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2772 * This routine will allocate SP from the free queue
2773 * input:
2774 * scsi_qla_host_t *
2775 * output:
2776 * srb_t * or NULL
2778 static srb_t *
2779 qla2x00_get_new_sp(scsi_qla_host_t *ha)
2781 srb_t *sp;
2783 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2784 if (sp)
2785 atomic_set(&sp->ref_count, 1);
2786 return (sp);
2789 static void
2790 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2792 struct scsi_cmnd *cmd = sp->cmd;
2794 if (sp->flags & SRB_DMA_VALID) {
2795 if (cmd->use_sg) {
2796 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2797 cmd->use_sg, cmd->sc_data_direction);
2798 } else if (cmd->request_bufflen) {
2799 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2800 cmd->request_bufflen, cmd->sc_data_direction);
2802 sp->flags &= ~SRB_DMA_VALID;
2806 void
2807 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2809 struct scsi_cmnd *cmd = sp->cmd;
2811 qla2x00_sp_free_dma(ha, sp);
2813 CMD_SP(cmd) = NULL;
2814 mempool_free(sp, ha->srb_mempool);
2816 cmd->scsi_done(cmd);
2819 /**************************************************************************
2820 * qla2x00_timer
2822 * Description:
2823 * One second timer
2825 * Context: Interrupt
2826 ***************************************************************************/
2827 static void
2828 qla2x00_timer(scsi_qla_host_t *ha)
2830 unsigned long cpu_flags = 0;
2831 fc_port_t *fcport;
2832 int start_dpc = 0;
2833 int index;
2834 srb_t *sp;
2835 int t;
2838 * Ports - Port down timer.
2840 * Whenever, a port is in the LOST state we start decrementing its port
2841 * down timer every second until it reaches zero. Once it reaches zero
2842 * the port it marked DEAD.
2844 t = 0;
2845 list_for_each_entry(fcport, &ha->fcports, list) {
2846 if (fcport->port_type != FCT_TARGET)
2847 continue;
2849 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2851 if (atomic_read(&fcport->port_down_timer) == 0)
2852 continue;
2854 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2855 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2857 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2858 "%d remainning\n",
2859 ha->host_no,
2860 t, atomic_read(&fcport->port_down_timer)));
2862 t++;
2863 } /* End of for fcport */
2866 /* Loop down handler. */
2867 if (atomic_read(&ha->loop_down_timer) > 0 &&
2868 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2870 if (atomic_read(&ha->loop_down_timer) ==
2871 ha->loop_down_abort_time) {
2873 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2874 "queues before time expire\n",
2875 ha->host_no));
2877 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2878 atomic_set(&ha->loop_state, LOOP_DEAD);
2880 /* Schedule an ISP abort to return any tape commands. */
2881 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2882 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2883 index++) {
2884 sp = ha->outstanding_cmds[index];
2885 if (!sp)
2886 continue;
2887 if (!(sp->fclun->fcport->flags &
2888 FCF_TAPE_PRESENT))
2889 continue;
2891 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2892 break;
2894 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2896 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2897 start_dpc++;
2900 /* if the loop has been down for 4 minutes, reinit adapter */
2901 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2902 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2903 "restarting queues.\n",
2904 ha->host_no));
2906 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2907 start_dpc++;
2909 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2910 DEBUG(printk("scsi(%ld): Loop down - "
2911 "aborting ISP.\n",
2912 ha->host_no));
2913 qla_printk(KERN_WARNING, ha,
2914 "Loop down - aborting ISP.\n");
2916 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2919 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
2920 ha->host_no,
2921 atomic_read(&ha->loop_down_timer)));
2924 /* Schedule the DPC routine if needed */
2925 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2926 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2927 start_dpc ||
2928 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
2929 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2930 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2931 ha->dpc_wait && !ha->dpc_active) {
2933 up(ha->dpc_wait);
2936 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2939 /* XXX(hch): crude hack to emulate a down_timeout() */
2941 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2943 const unsigned int step = HZ/10;
2945 do {
2946 if (!down_trylock(sema))
2947 return 0;
2948 set_current_state(TASK_INTERRUPTIBLE);
2949 if (schedule_timeout(step))
2950 break;
2951 } while ((timeout -= step) > 0);
2953 return -ETIMEDOUT;
2956 static void
2957 qla2xxx_get_port_id(struct scsi_target *starget)
2959 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2960 scsi_qla_host_t *ha = to_qla_host(shost);
2961 struct fc_port *fc;
2963 list_for_each_entry(fc, &ha->fcports, list) {
2964 if (fc->os_target_id == starget->id) {
2965 fc_starget_port_id(starget) = fc->d_id.b.domain << 16 |
2966 fc->d_id.b.area << 8 |
2967 fc->d_id.b.al_pa;
2968 return;
2971 fc_starget_port_id(starget) = -1;
2974 static void
2975 qla2xxx_get_port_name(struct scsi_target *starget)
2977 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2978 scsi_qla_host_t *ha = to_qla_host(shost);
2979 struct fc_port *fc;
2981 list_for_each_entry(fc, &ha->fcports, list) {
2982 if (fc->os_target_id == starget->id) {
2983 fc_starget_port_name(starget) =
2984 __be64_to_cpu(*(uint64_t *)fc->port_name);
2985 return;
2988 fc_starget_port_name(starget) = -1;
2991 static void
2992 qla2xxx_get_node_name(struct scsi_target *starget)
2994 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2995 scsi_qla_host_t *ha = to_qla_host(shost);
2996 struct fc_port *fc;
2998 list_for_each_entry(fc, &ha->fcports, list) {
2999 if (fc->os_target_id == starget->id) {
3000 fc_starget_node_name(starget) =
3001 __be64_to_cpu(*(uint64_t *)fc->node_name);
3002 return;
3005 fc_starget_node_name(starget) = -1;
3008 static struct fc_function_template qla2xxx_transport_functions = {
3009 .get_starget_port_id = qla2xxx_get_port_id,
3010 .show_starget_port_id = 1,
3011 .get_starget_port_name = qla2xxx_get_port_name,
3012 .show_starget_port_name = 1,
3013 .get_starget_node_name = qla2xxx_get_node_name,
3014 .show_starget_node_name = 1,
3018 * qla2x00_module_init - Module initialization.
3020 static int __init
3021 qla2x00_module_init(void)
3023 /* Allocate cache for SRBs. */
3024 sprintf(srb_cachep_name, "qla2xxx_srbs");
3025 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
3026 SLAB_HWCACHE_ALIGN, NULL, NULL);
3027 if (srb_cachep == NULL) {
3028 printk(KERN_ERR
3029 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3030 return -ENOMEM;
3033 /* Derive version string. */
3034 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3035 #if DEBUG_QLA2100
3036 strcat(qla2x00_version_str, "-debug");
3037 #endif
3039 qla2xxx_transport_template = fc_attach_transport(&qla2xxx_transport_functions);
3040 if (!qla2xxx_transport_template)
3041 return -ENODEV;
3043 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
3044 return 0;
3048 * qla2x00_module_exit - Module cleanup.
3050 static void __exit
3051 qla2x00_module_exit(void)
3053 /* Free SRBs cache. */
3054 if (srb_cachep != NULL) {
3055 if (kmem_cache_destroy(srb_cachep) != 0) {
3056 printk(KERN_ERR
3057 "qla2xxx: Unable to free SRB cache...Memory pools "
3058 "still active?\n");
3060 srb_cachep = NULL;
3063 fc_release_transport(qla2xxx_transport_template);
3066 module_init(qla2x00_module_init);
3067 module_exit(qla2x00_module_exit);
3069 MODULE_AUTHOR("QLogic Corporation");
3070 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3071 MODULE_LICENSE("GPL");
3072 MODULE_VERSION(QLA2XXX_VERSION);