1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
40 /* AlpaArray for assignment of scsid for scan-down and bind_method */
41 static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
57 static void lpfc_disc_timeout_handler(struct lpfc_hba *);
60 lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
62 uint8_t *name = (uint8_t *)&ndlp->nlp_portname;
65 spin_lock_irq(phba->host->host_lock);
66 if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
67 spin_unlock_irq(phba->host->host_lock);
72 * If a discovery event readded nodev_timer after timer
73 * firing and before processing the timer, cancel the
76 spin_unlock_irq(phba->host->host_lock);
77 del_timer_sync(&ndlp->nlp_tmofunc);
78 spin_lock_irq(phba->host->host_lock);
80 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
82 if (ndlp->nlp_sid != NLP_NO_SID) {
84 /* flush the target */
85 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
86 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
88 spin_unlock_irq(phba->host->host_lock);
91 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
92 "%d:0203 Nodev timeout on "
93 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
94 "NPort x%x Data: x%x x%x x%x\n",
96 *name, *(name+1), *(name+2), *(name+3),
97 *(name+4), *(name+5), *(name+6), *(name+7),
98 ndlp->nlp_DID, ndlp->nlp_flag,
99 ndlp->nlp_state, ndlp->nlp_rpi);
101 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
102 "%d:0204 Nodev timeout on "
103 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
104 "NPort x%x Data: x%x x%x x%x\n",
106 *name, *(name+1), *(name+2), *(name+3),
107 *(name+4), *(name+5), *(name+6), *(name+7),
108 ndlp->nlp_DID, ndlp->nlp_flag,
109 ndlp->nlp_state, ndlp->nlp_rpi);
112 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
117 lpfc_work_list_done(struct lpfc_hba * phba)
119 struct lpfc_work_evt *evtp = NULL;
120 struct lpfc_nodelist *ndlp;
123 spin_lock_irq(phba->host->host_lock);
124 while(!list_empty(&phba->work_list)) {
125 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
127 spin_unlock_irq(phba->host->host_lock);
130 case LPFC_EVT_NODEV_TMO:
131 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
132 lpfc_process_nodev_timeout(phba, ndlp);
135 case LPFC_EVT_ELS_RETRY:
136 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
137 lpfc_els_retry_delay_handler(ndlp);
140 case LPFC_EVT_ONLINE:
141 if (phba->hba_state < LPFC_LINK_DOWN)
142 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
144 *(int *)(evtp->evt_arg1) = 0;
145 complete((struct completion *)(evtp->evt_arg2));
147 case LPFC_EVT_OFFLINE:
148 if (phba->hba_state >= LPFC_LINK_DOWN)
150 lpfc_sli_brdrestart(phba);
151 *(int *)(evtp->evt_arg1) =
152 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
153 complete((struct completion *)(evtp->evt_arg2));
155 case LPFC_EVT_WARM_START:
156 if (phba->hba_state >= LPFC_LINK_DOWN)
158 lpfc_reset_barrier(phba);
159 lpfc_sli_brdreset(phba);
160 lpfc_hba_down_post(phba);
161 *(int *)(evtp->evt_arg1) =
162 lpfc_sli_brdready(phba, HS_MBRDY);
163 complete((struct completion *)(evtp->evt_arg2));
166 if (phba->hba_state >= LPFC_LINK_DOWN)
168 *(int *)(evtp->evt_arg1)
169 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
170 complete((struct completion *)(evtp->evt_arg2));
175 spin_lock_irq(phba->host->host_lock);
177 spin_unlock_irq(phba->host->host_lock);
182 lpfc_work_done(struct lpfc_hba * phba)
184 struct lpfc_sli_ring *pring;
188 uint32_t work_hba_events;
190 spin_lock_irq(phba->host->host_lock);
191 ha_copy = phba->work_ha;
193 work_hba_events=phba->work_hba_events;
194 spin_unlock_irq(phba->host->host_lock);
196 if (ha_copy & HA_ERATT)
197 lpfc_handle_eratt(phba);
199 if (ha_copy & HA_MBATT)
200 lpfc_sli_handle_mb_event(phba);
202 if (ha_copy & HA_LATT)
203 lpfc_handle_latt(phba);
205 if (work_hba_events & WORKER_DISC_TMO)
206 lpfc_disc_timeout_handler(phba);
208 if (work_hba_events & WORKER_ELS_TMO)
209 lpfc_els_timeout_handler(phba);
211 if (work_hba_events & WORKER_MBOX_TMO)
212 lpfc_mbox_timeout_handler(phba);
214 if (work_hba_events & WORKER_FDMI_TMO)
215 lpfc_fdmi_tmo_handler(phba);
217 spin_lock_irq(phba->host->host_lock);
218 phba->work_hba_events &= ~work_hba_events;
219 spin_unlock_irq(phba->host->host_lock);
221 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
222 pring = &phba->sli.ring[i];
223 if ((ha_copy & HA_RXATT)
224 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
225 if (pring->flag & LPFC_STOP_IOCB_MASK) {
226 pring->flag |= LPFC_DEFERRED_RING_EVENT;
228 lpfc_sli_handle_slow_ring_event(phba, pring,
231 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
234 * Turn on Ring interrupts
236 spin_lock_irq(phba->host->host_lock);
237 control = readl(phba->HCregaddr);
238 control |= (HC_R0INT_ENA << i);
239 writel(control, phba->HCregaddr);
240 readl(phba->HCregaddr); /* flush */
241 spin_unlock_irq(phba->host->host_lock);
245 lpfc_work_list_done (phba);
250 check_work_wait_done(struct lpfc_hba *phba) {
252 spin_lock_irq(phba->host->host_lock);
254 phba->work_hba_events ||
255 (!list_empty(&phba->work_list)) ||
256 kthread_should_stop()) {
257 spin_unlock_irq(phba->host->host_lock);
260 spin_unlock_irq(phba->host->host_lock);
266 lpfc_do_work(void *p)
268 struct lpfc_hba *phba = p;
270 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
272 set_user_nice(current, -20);
273 phba->work_wait = &work_waitq;
277 rc = wait_event_interruptible(work_waitq,
278 check_work_wait_done(phba));
281 if (kthread_should_stop())
284 lpfc_work_done(phba);
287 phba->work_wait = NULL;
292 * This is only called to handle FC worker events. Since this a rare
293 * occurance, we allocate a struct lpfc_work_evt structure here instead of
294 * embedding it in the IOCB.
297 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
300 struct lpfc_work_evt *evtp;
303 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
304 * be queued to worker thread for processing
306 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
310 evtp->evt_arg1 = arg1;
311 evtp->evt_arg2 = arg2;
314 spin_lock_irq(phba->host->host_lock);
315 list_add_tail(&evtp->evt_listp, &phba->work_list);
317 wake_up(phba->work_wait);
318 spin_unlock_irq(phba->host->host_lock);
324 lpfc_linkdown(struct lpfc_hba * phba)
326 struct lpfc_sli *psli;
327 struct lpfc_nodelist *ndlp, *next_ndlp;
328 struct list_head *listp, *node_list[7];
333 /* sysfs or selective reset may call this routine to clean up */
334 if (phba->hba_state >= LPFC_LINK_DOWN) {
335 if (phba->hba_state == LPFC_LINK_DOWN)
338 spin_lock_irq(phba->host->host_lock);
339 phba->hba_state = LPFC_LINK_DOWN;
340 spin_unlock_irq(phba->host->host_lock);
343 fc_host_post_event(phba->host, fc_get_event_number(),
344 FCH_EVT_LINKDOWN, 0);
346 /* Clean up any firmware default rpi's */
347 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
348 lpfc_unreg_did(phba, 0xffffffff, mb);
349 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
350 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
351 == MBX_NOT_FINISHED) {
352 mempool_free( mb, phba->mbox_mem_pool);
356 /* Cleanup any outstanding RSCN activity */
357 lpfc_els_flush_rscn(phba);
359 /* Cleanup any outstanding ELS commands */
360 lpfc_els_flush_cmd(phba);
362 /* Issue a LINK DOWN event to all nodes */
363 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
364 node_list[1] = &phba->fc_nlpmap_list;
365 node_list[2] = &phba->fc_nlpunmap_list;
366 node_list[3] = &phba->fc_prli_list;
367 node_list[4] = &phba->fc_reglogin_list;
368 node_list[5] = &phba->fc_adisc_list;
369 node_list[6] = &phba->fc_plogi_list;
370 for (i = 0; i < 7; i++) {
371 listp = node_list[i];
372 if (list_empty(listp))
375 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
377 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
378 NLP_EVT_DEVICE_RECOVERY);
380 /* Check config parameter use-adisc or FCP-2 */
381 if ((rc != NLP_STE_FREED_NODE) &&
382 (phba->cfg_use_adisc == 0) &&
383 !(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) {
384 /* We know we will have to relogin, so
385 * unreglogin the rpi right now to fail
386 * any outstanding I/Os quickly.
388 lpfc_unreg_rpi(phba, ndlp);
393 /* free any ndlp's on unused list */
394 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
396 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
399 /* Setup myDID for link up if we are in pt2pt mode */
400 if (phba->fc_flag & FC_PT2PT) {
402 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
403 lpfc_config_link(phba, mb);
404 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
405 if (lpfc_sli_issue_mbox
406 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
407 == MBX_NOT_FINISHED) {
408 mempool_free( mb, phba->mbox_mem_pool);
411 spin_lock_irq(phba->host->host_lock);
412 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
413 spin_unlock_irq(phba->host->host_lock);
415 spin_lock_irq(phba->host->host_lock);
416 phba->fc_flag &= ~FC_LBIT;
417 spin_unlock_irq(phba->host->host_lock);
419 /* Turn off discovery timer if its running */
420 lpfc_can_disctmo(phba);
422 /* Must process IOCBs on all rings to handle ABORTed I/Os */
427 lpfc_linkup(struct lpfc_hba * phba)
429 struct lpfc_nodelist *ndlp, *next_ndlp;
430 struct list_head *listp, *node_list[7];
433 fc_host_post_event(phba->host, fc_get_event_number(),
436 spin_lock_irq(phba->host->host_lock);
437 phba->hba_state = LPFC_LINK_UP;
438 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
439 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
440 phba->fc_flag |= FC_NDISC_ACTIVE;
441 phba->fc_ns_retry = 0;
442 spin_unlock_irq(phba->host->host_lock);
445 node_list[0] = &phba->fc_plogi_list;
446 node_list[1] = &phba->fc_adisc_list;
447 node_list[2] = &phba->fc_reglogin_list;
448 node_list[3] = &phba->fc_prli_list;
449 node_list[4] = &phba->fc_nlpunmap_list;
450 node_list[5] = &phba->fc_nlpmap_list;
451 node_list[6] = &phba->fc_npr_list;
452 for (i = 0; i < 7; i++) {
453 listp = node_list[i];
454 if (list_empty(listp))
457 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
458 if (phba->fc_flag & FC_LBIT) {
459 if (ndlp->nlp_type & NLP_FABRIC) {
460 /* On Linkup its safe to clean up the
461 * ndlp from Fabric connections.
463 lpfc_nlp_list(phba, ndlp,
465 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
466 /* Fail outstanding IO now since device
467 * is marked for PLOGI.
469 lpfc_unreg_rpi(phba, ndlp);
475 /* free any ndlp's on unused list */
476 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
478 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
485 * This routine handles processing a CLEAR_LA mailbox
486 * command upon completion. It is setup in the LPFC_MBOXQ
487 * as the completion routine when the command is
488 * handed off to the SLI layer.
491 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
493 struct lpfc_sli *psli;
499 /* Since we don't do discovery right now, turn these off here */
500 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
501 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
502 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
504 /* Check for error */
505 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
506 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
507 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
508 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
510 phba->brd_no, mb->mbxStatus, phba->hba_state);
512 phba->hba_state = LPFC_HBA_ERROR;
516 if (phba->fc_flag & FC_ABORT_DISCOVERY)
519 phba->num_disc_nodes = 0;
520 /* go thru NPR list and issue ELS PLOGIs */
521 if (phba->fc_npr_cnt) {
522 lpfc_els_disc_plogi(phba);
525 if (!phba->num_disc_nodes) {
526 spin_lock_irq(phba->host->host_lock);
527 phba->fc_flag &= ~FC_NDISC_ACTIVE;
528 spin_unlock_irq(phba->host->host_lock);
531 phba->hba_state = LPFC_HBA_READY;
534 /* Device Discovery completes */
535 lpfc_printf_log(phba,
538 "%d:0225 Device Discovery completes\n",
541 mempool_free( pmb, phba->mbox_mem_pool);
543 spin_lock_irq(phba->host->host_lock);
544 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
545 if (phba->fc_flag & FC_ESTABLISH_LINK) {
546 phba->fc_flag &= ~FC_ESTABLISH_LINK;
548 spin_unlock_irq(phba->host->host_lock);
550 del_timer_sync(&phba->fc_estabtmo);
552 lpfc_can_disctmo(phba);
554 /* turn on Link Attention interrupts */
555 spin_lock_irq(phba->host->host_lock);
556 psli->sli_flag |= LPFC_PROCESS_LA;
557 control = readl(phba->HCregaddr);
558 control |= HC_LAINT_ENA;
559 writel(control, phba->HCregaddr);
560 readl(phba->HCregaddr); /* flush */
561 spin_unlock_irq(phba->host->host_lock);
567 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
569 struct lpfc_sli *psli = &phba->sli;
572 if (pmb->mb.mbxStatus)
575 mempool_free(pmb, phba->mbox_mem_pool);
577 if (phba->fc_topology == TOPOLOGY_LOOP &&
578 phba->fc_flag & FC_PUBLIC_LOOP &&
579 !(phba->fc_flag & FC_LBIT)) {
580 /* Need to wait for FAN - use discovery timer
581 * for timeout. hba_state is identically
582 * LPFC_LOCAL_CFG_LINK while waiting for FAN
584 lpfc_set_disctmo(phba);
588 /* Start discovery by sending a FLOGI. hba_state is identically
589 * LPFC_FLOGI while waiting for FLOGI cmpl
591 phba->hba_state = LPFC_FLOGI;
592 lpfc_set_disctmo(phba);
593 lpfc_initial_flogi(phba);
597 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
598 "%d:0306 CONFIG_LINK mbxStatus error x%x "
600 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
604 phba->hba_state = LPFC_HBA_ERROR;
606 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
607 "%d:0200 CONFIG_LINK bad hba state x%x\n",
608 phba->brd_no, phba->hba_state);
610 lpfc_clear_la(phba, pmb);
611 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
612 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
613 if (rc == MBX_NOT_FINISHED) {
614 mempool_free(pmb, phba->mbox_mem_pool);
615 lpfc_disc_flush_list(phba);
616 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
617 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
618 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
619 phba->hba_state = LPFC_HBA_READY;
625 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
627 struct lpfc_sli *psli = &phba->sli;
628 MAILBOX_t *mb = &pmb->mb;
629 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
632 /* Check for error */
634 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
635 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
636 "%d:0319 READ_SPARAM mbxStatus error x%x "
638 phba->brd_no, mb->mbxStatus, phba->hba_state);
641 phba->hba_state = LPFC_HBA_ERROR;
645 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
646 sizeof (struct serv_parm));
647 memcpy((uint8_t *) & phba->fc_nodename,
648 (uint8_t *) & phba->fc_sparam.nodeName,
649 sizeof (struct lpfc_name));
650 memcpy((uint8_t *) & phba->fc_portname,
651 (uint8_t *) & phba->fc_sparam.portName,
652 sizeof (struct lpfc_name));
653 lpfc_mbuf_free(phba, mp->virt, mp->phys);
655 mempool_free( pmb, phba->mbox_mem_pool);
659 pmb->context1 = NULL;
660 lpfc_mbuf_free(phba, mp->virt, mp->phys);
662 if (phba->hba_state != LPFC_CLEAR_LA) {
663 lpfc_clear_la(phba, pmb);
664 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
665 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
666 == MBX_NOT_FINISHED) {
667 mempool_free( pmb, phba->mbox_mem_pool);
668 lpfc_disc_flush_list(phba);
669 psli->ring[(psli->ip_ring)].flag &=
670 ~LPFC_STOP_IOCB_EVENT;
671 psli->ring[(psli->fcp_ring)].flag &=
672 ~LPFC_STOP_IOCB_EVENT;
673 psli->ring[(psli->next_ring)].flag &=
674 ~LPFC_STOP_IOCB_EVENT;
675 phba->hba_state = LPFC_HBA_READY;
678 mempool_free( pmb, phba->mbox_mem_pool);
684 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
687 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
688 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
689 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
691 spin_lock_irq(phba->host->host_lock);
692 switch (la->UlnkSpeed) {
694 phba->fc_linkspeed = LA_1GHZ_LINK;
697 phba->fc_linkspeed = LA_2GHZ_LINK;
700 phba->fc_linkspeed = LA_4GHZ_LINK;
703 phba->fc_linkspeed = LA_UNKNW_LINK;
707 phba->fc_topology = la->topology;
709 if (phba->fc_topology == TOPOLOGY_LOOP) {
710 /* Get Loop Map information */
713 phba->fc_flag |= FC_LBIT;
715 phba->fc_myDID = la->granted_AL_PA;
716 i = la->un.lilpBde64.tus.f.bdeSize;
719 phba->alpa_map[0] = 0;
721 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
732 numalpa = phba->alpa_map[0];
734 while (j < numalpa) {
735 memset(un.pamap, 0, 16);
736 for (k = 1; j < numalpa; k++) {
738 phba->alpa_map[j + 1];
743 /* Link Up Event ALPA map */
744 lpfc_printf_log(phba,
747 "%d:1304 Link Up Event "
748 "ALPA map Data: x%x "
751 un.pa.wd1, un.pa.wd2,
752 un.pa.wd3, un.pa.wd4);
757 phba->fc_myDID = phba->fc_pref_DID;
758 phba->fc_flag |= FC_LBIT;
760 spin_unlock_irq(phba->host->host_lock);
764 lpfc_read_sparam(phba, sparam_mbox);
765 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
766 lpfc_sli_issue_mbox(phba, sparam_mbox,
767 (MBX_NOWAIT | MBX_STOP_IOCB));
771 phba->hba_state = LPFC_LOCAL_CFG_LINK;
772 lpfc_config_link(phba, cfglink_mbox);
773 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
774 lpfc_sli_issue_mbox(phba, cfglink_mbox,
775 (MBX_NOWAIT | MBX_STOP_IOCB));
780 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
782 struct lpfc_sli *psli = &phba->sli;
786 /* turn on Link Attention interrupts - no CLEAR_LA needed */
787 spin_lock_irq(phba->host->host_lock);
788 psli->sli_flag |= LPFC_PROCESS_LA;
789 control = readl(phba->HCregaddr);
790 control |= HC_LAINT_ENA;
791 writel(control, phba->HCregaddr);
792 readl(phba->HCregaddr); /* flush */
793 spin_unlock_irq(phba->host->host_lock);
797 * This routine handles processing a READ_LA mailbox
798 * command upon completion. It is setup in the LPFC_MBOXQ
799 * as the completion routine when the command is
800 * handed off to the SLI layer.
803 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
806 MAILBOX_t *mb = &pmb->mb;
807 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
809 /* Check for error */
811 lpfc_printf_log(phba,
814 "%d:1307 READ_LA mbox error x%x state x%x\n",
816 mb->mbxStatus, phba->hba_state);
817 lpfc_mbx_issue_link_down(phba);
818 phba->hba_state = LPFC_HBA_ERROR;
819 goto lpfc_mbx_cmpl_read_la_free_mbuf;
822 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
824 memcpy(&phba->alpa_map[0], mp->virt, 128);
826 spin_lock_irq(phba->host->host_lock);
828 phba->fc_flag |= FC_BYPASSED_MODE;
830 phba->fc_flag &= ~FC_BYPASSED_MODE;
831 spin_unlock_irq(phba->host->host_lock);
833 if (((phba->fc_eventTag + 1) < la->eventTag) ||
834 (phba->fc_eventTag == la->eventTag)) {
835 phba->fc_stat.LinkMultiEvent++;
836 if (la->attType == AT_LINK_UP) {
837 if (phba->fc_eventTag != 0)
842 phba->fc_eventTag = la->eventTag;
844 if (la->attType == AT_LINK_UP) {
845 phba->fc_stat.LinkUp++;
846 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
847 "%d:1303 Link Up Event x%x received "
848 "Data: x%x x%x x%x x%x\n",
849 phba->brd_no, la->eventTag, phba->fc_eventTag,
850 la->granted_AL_PA, la->UlnkSpeed,
852 lpfc_mbx_process_link_up(phba, la);
854 phba->fc_stat.LinkDown++;
855 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
856 "%d:1305 Link Down Event x%x received "
857 "Data: x%x x%x x%x\n",
858 phba->brd_no, la->eventTag, phba->fc_eventTag,
859 phba->hba_state, phba->fc_flag);
860 lpfc_mbx_issue_link_down(phba);
863 lpfc_mbx_cmpl_read_la_free_mbuf:
864 lpfc_mbuf_free(phba, mp->virt, mp->phys);
866 mempool_free(pmb, phba->mbox_mem_pool);
871 * This routine handles processing a REG_LOGIN mailbox
872 * command upon completion. It is setup in the LPFC_MBOXQ
873 * as the completion routine when the command is
874 * handed off to the SLI layer.
877 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
879 struct lpfc_sli *psli;
881 struct lpfc_dmabuf *mp;
882 struct lpfc_nodelist *ndlp;
887 ndlp = (struct lpfc_nodelist *) pmb->context2;
888 mp = (struct lpfc_dmabuf *) (pmb->context1);
890 pmb->context1 = NULL;
892 /* Good status, call state machine */
893 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
894 lpfc_mbuf_free(phba, mp->virt, mp->phys);
896 mempool_free( pmb, phba->mbox_mem_pool);
902 * This routine handles processing a Fabric REG_LOGIN mailbox
903 * command upon completion. It is setup in the LPFC_MBOXQ
904 * as the completion routine when the command is
905 * handed off to the SLI layer.
908 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
910 struct lpfc_sli *psli;
912 struct lpfc_dmabuf *mp;
913 struct lpfc_nodelist *ndlp;
914 struct lpfc_nodelist *ndlp_fdmi;
920 ndlp = (struct lpfc_nodelist *) pmb->context2;
921 mp = (struct lpfc_dmabuf *) (pmb->context1);
924 lpfc_mbuf_free(phba, mp->virt, mp->phys);
926 mempool_free( pmb, phba->mbox_mem_pool);
927 mempool_free( ndlp, phba->nlp_mem_pool);
929 /* FLOGI failed, so just use loop map to make discovery list */
930 lpfc_disc_list_loopmap(phba);
932 /* Start discovery */
933 lpfc_disc_start(phba);
937 pmb->context1 = NULL;
939 ndlp->nlp_rpi = mb->un.varWords[0];
940 ndlp->nlp_type |= NLP_FABRIC;
941 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
942 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
944 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
945 /* This NPort has been assigned an NPort_ID by the fabric as a
946 * result of the completed fabric login. Issue a State Change
947 * Registration (SCR) ELS request to the fabric controller
948 * (SCR_DID) so that this NPort gets RSCN events from the
951 lpfc_issue_els_scr(phba, SCR_DID, 0);
953 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
955 /* Allocate a new node instance. If the pool is empty,
956 * start the discovery process and skip the Nameserver
957 * login process. This is attempted again later on.
958 * Otherwise, issue a Port Login (PLOGI) to NameServer.
960 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
962 lpfc_disc_start(phba);
963 lpfc_mbuf_free(phba, mp->virt, mp->phys);
965 mempool_free( pmb, phba->mbox_mem_pool);
968 lpfc_nlp_init(phba, ndlp, NameServer_DID);
969 ndlp->nlp_type |= NLP_FABRIC;
972 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
973 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
974 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
975 if (phba->cfg_fdmi_on) {
976 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
979 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
980 ndlp_fdmi->nlp_type |= NLP_FABRIC;
981 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
982 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
987 lpfc_mbuf_free(phba, mp->virt, mp->phys);
989 mempool_free( pmb, phba->mbox_mem_pool);
994 * This routine handles processing a NameServer REG_LOGIN mailbox
995 * command upon completion. It is setup in the LPFC_MBOXQ
996 * as the completion routine when the command is
997 * handed off to the SLI layer.
1000 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1002 struct lpfc_sli *psli;
1004 struct lpfc_dmabuf *mp;
1005 struct lpfc_nodelist *ndlp;
1010 ndlp = (struct lpfc_nodelist *) pmb->context2;
1011 mp = (struct lpfc_dmabuf *) (pmb->context1);
1013 if (mb->mbxStatus) {
1014 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1016 mempool_free( pmb, phba->mbox_mem_pool);
1017 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1019 /* RegLogin failed, so just use loop map to make discovery
1021 lpfc_disc_list_loopmap(phba);
1023 /* Start discovery */
1024 lpfc_disc_start(phba);
1028 pmb->context1 = NULL;
1030 ndlp->nlp_rpi = mb->un.varWords[0];
1031 ndlp->nlp_type |= NLP_FABRIC;
1032 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1033 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1035 if (phba->hba_state < LPFC_HBA_READY) {
1036 /* Link up discovery requires Fabrib registration. */
1037 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1038 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1039 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1042 phba->fc_ns_retry = 0;
1043 /* Good status, issue CT Request to NameServer */
1044 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1045 /* Cannot issue NameServer Query, so finish up discovery */
1046 lpfc_disc_start(phba);
1049 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1051 mempool_free( pmb, phba->mbox_mem_pool);
1057 lpfc_register_remote_port(struct lpfc_hba * phba,
1058 struct lpfc_nodelist * ndlp)
1060 struct fc_rport *rport;
1061 struct lpfc_rport_data *rdata;
1062 struct fc_rport_identifiers rport_ids;
1064 /* Remote port has reappeared. Re-register w/ FC transport */
1065 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1066 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1067 rport_ids.port_id = ndlp->nlp_DID;
1068 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1070 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1072 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1073 "Warning: fc_remote_port_add failed\n");
1077 /* initialize static port data */
1078 rport->maxframe_size = ndlp->nlp_maxframe;
1079 rport->supported_classes = ndlp->nlp_class_sup;
1080 rdata = rport->dd_data;
1081 rdata->pnode = ndlp;
1083 if (ndlp->nlp_type & NLP_FCP_TARGET)
1084 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1085 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1086 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1089 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1090 fc_remote_port_rolechg(rport, rport_ids.roles);
1092 if ((rport->scsi_target_id != -1) &&
1093 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1094 ndlp->nlp_sid = rport->scsi_target_id;
1101 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1102 struct lpfc_nodelist * ndlp)
1104 struct fc_rport *rport = ndlp->rport;
1105 struct lpfc_rport_data *rdata = rport->dd_data;
1108 rdata->pnode = NULL;
1109 fc_remote_port_delete(rport);
1115 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1117 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1118 struct lpfc_sli *psli;
1121 /* Sanity check to ensure we are not moving to / from the same list */
1122 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1123 if (list != NLP_NO_LIST)
1126 spin_lock_irq(phba->host->host_lock);
1127 switch (nlp->nlp_flag & NLP_LIST_MASK) {
1128 case NLP_NO_LIST: /* Not on any list */
1130 case NLP_UNUSED_LIST:
1131 phba->fc_unused_cnt--;
1132 list_del(&nlp->nlp_listp);
1134 case NLP_PLOGI_LIST:
1135 phba->fc_plogi_cnt--;
1136 list_del(&nlp->nlp_listp);
1138 case NLP_ADISC_LIST:
1139 phba->fc_adisc_cnt--;
1140 list_del(&nlp->nlp_listp);
1142 case NLP_REGLOGIN_LIST:
1143 phba->fc_reglogin_cnt--;
1144 list_del(&nlp->nlp_listp);
1147 phba->fc_prli_cnt--;
1148 list_del(&nlp->nlp_listp);
1150 case NLP_UNMAPPED_LIST:
1151 phba->fc_unmap_cnt--;
1152 list_del(&nlp->nlp_listp);
1153 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1154 nlp->nlp_type &= ~NLP_FC_NODE;
1155 phba->nport_event_cnt++;
1157 rport_del = unmapped;
1159 case NLP_MAPPED_LIST:
1161 list_del(&nlp->nlp_listp);
1162 phba->nport_event_cnt++;
1168 list_del(&nlp->nlp_listp);
1169 /* Stop delay tmo if taking node off NPR list */
1170 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1171 (list != NLP_NPR_LIST)) {
1172 spin_unlock_irq(phba->host->host_lock);
1173 lpfc_cancel_retry_delay_tmo(phba, nlp);
1174 spin_lock_irq(phba->host->host_lock);
1179 nlp->nlp_flag &= ~NLP_LIST_MASK;
1181 /* Add NPort <did> to <num> list */
1182 lpfc_printf_log(phba,
1185 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1187 nlp->nlp_DID, list, nlp->nlp_flag);
1190 case NLP_NO_LIST: /* No list, just remove it */
1191 spin_unlock_irq(phba->host->host_lock);
1192 lpfc_nlp_remove(phba, nlp);
1193 spin_lock_irq(phba->host->host_lock);
1194 /* as node removed - stop further transport calls */
1197 case NLP_UNUSED_LIST:
1198 nlp->nlp_flag |= list;
1199 /* Put it at the end of the unused list */
1200 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1201 phba->fc_unused_cnt++;
1203 case NLP_PLOGI_LIST:
1204 nlp->nlp_flag |= list;
1205 /* Put it at the end of the plogi list */
1206 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1207 phba->fc_plogi_cnt++;
1209 case NLP_ADISC_LIST:
1210 nlp->nlp_flag |= list;
1211 /* Put it at the end of the adisc list */
1212 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1213 phba->fc_adisc_cnt++;
1215 case NLP_REGLOGIN_LIST:
1216 nlp->nlp_flag |= list;
1217 /* Put it at the end of the reglogin list */
1218 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1219 phba->fc_reglogin_cnt++;
1222 nlp->nlp_flag |= list;
1223 /* Put it at the end of the prli list */
1224 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1225 phba->fc_prli_cnt++;
1227 case NLP_UNMAPPED_LIST:
1228 rport_add = unmapped;
1229 /* ensure all vestiges of "mapped" significance are gone */
1230 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1231 nlp->nlp_flag |= list;
1232 /* Put it at the end of the unmap list */
1233 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1234 phba->fc_unmap_cnt++;
1235 phba->nport_event_cnt++;
1236 /* stop nodev tmo if running */
1237 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1238 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1239 spin_unlock_irq(phba->host->host_lock);
1240 del_timer_sync(&nlp->nlp_tmofunc);
1241 spin_lock_irq(phba->host->host_lock);
1242 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1243 list_del_init(&nlp->nodev_timeout_evt.
1247 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1248 nlp->nlp_type |= NLP_FC_NODE;
1250 case NLP_MAPPED_LIST:
1252 nlp->nlp_flag |= list;
1253 /* Put it at the end of the map list */
1254 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1256 phba->nport_event_cnt++;
1257 /* stop nodev tmo if running */
1258 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1259 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1260 spin_unlock_irq(phba->host->host_lock);
1261 del_timer_sync(&nlp->nlp_tmofunc);
1262 spin_lock_irq(phba->host->host_lock);
1263 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1264 list_del_init(&nlp->nodev_timeout_evt.
1268 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1271 nlp->nlp_flag |= list;
1272 /* Put it at the end of the npr list */
1273 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1276 if (!(nlp->nlp_flag & NLP_NODEV_TMO))
1277 mod_timer(&nlp->nlp_tmofunc,
1278 jiffies + HZ * phba->cfg_nodev_tmo);
1280 nlp->nlp_flag |= NLP_NODEV_TMO;
1281 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1287 spin_unlock_irq(phba->host->host_lock);
1290 * We make all the calls into the transport after we have
1291 * moved the node between lists. This so that we don't
1292 * release the lock while in-between lists.
1295 /* Don't upcall midlayer if we're unloading */
1296 if (!(phba->fc_flag & FC_UNLOADING)) {
1298 * We revalidate the rport pointer as the "add" function
1299 * may have removed the remote port.
1301 if ((rport_del != none) && nlp->rport)
1302 lpfc_unregister_remote_port(phba, nlp);
1304 if (rport_add != none) {
1306 * Tell the fc transport about the port, if we haven't
1307 * already. If we have, and it's a scsi entity, be
1308 * sure to unblock any attached scsi devices
1311 lpfc_register_remote_port(phba, nlp);
1314 * if we added to Mapped list, but the remote port
1315 * registration failed or assigned a target id outside
1316 * our presentable range - move the node to the
1319 if ((rport_add == mapped) &&
1321 (nlp->rport->scsi_target_id == -1) ||
1322 (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) {
1323 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1324 spin_lock_irq(phba->host->host_lock);
1325 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1326 spin_unlock_irq(phba->host->host_lock);
1327 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1335 * Start / ReStart rescue timer for Discovery / RSCN handling
1338 lpfc_set_disctmo(struct lpfc_hba * phba)
1342 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1343 /* For FAN, timeout should be greater then edtov */
1344 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1346 /* Normal discovery timeout should be > then ELS/CT timeout
1347 * FC spec states we need 3 * ratov for CT requests
1349 tmo = ((phba->fc_ratov * 3) + 3);
1352 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1353 spin_lock_irq(phba->host->host_lock);
1354 phba->fc_flag |= FC_DISC_TMO;
1355 spin_unlock_irq(phba->host->host_lock);
1357 /* Start Discovery Timer state <hba_state> */
1358 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1359 "%d:0247 Start Discovery Timer state x%x "
1360 "Data: x%x x%lx x%x x%x\n",
1362 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1363 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1369 * Cancel rescue timer for Discovery / RSCN handling
1372 lpfc_can_disctmo(struct lpfc_hba * phba)
1374 /* Turn off discovery timer if its running */
1375 if (phba->fc_flag & FC_DISC_TMO) {
1376 spin_lock_irq(phba->host->host_lock);
1377 phba->fc_flag &= ~FC_DISC_TMO;
1378 spin_unlock_irq(phba->host->host_lock);
1379 del_timer_sync(&phba->fc_disctmo);
1380 phba->work_hba_events &= ~WORKER_DISC_TMO;
1383 /* Cancel Discovery Timer state <hba_state> */
1384 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1385 "%d:0248 Cancel Discovery Timer state x%x "
1386 "Data: x%x x%x x%x\n",
1387 phba->brd_no, phba->hba_state, phba->fc_flag,
1388 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1394 * Check specified ring for outstanding IOCB on the SLI queue
1395 * Return true if iocb matches the specified nport
1398 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1399 struct lpfc_sli_ring * pring,
1400 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1402 struct lpfc_sli *psli;
1407 if (pring->ringno == LPFC_ELS_RING) {
1408 switch (icmd->ulpCommand) {
1409 case CMD_GEN_REQUEST64_CR:
1410 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1412 case CMD_ELS_REQUEST64_CR:
1413 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1415 case CMD_XMIT_ELS_RSP64_CX:
1416 if (iocb->context1 == (uint8_t *) ndlp)
1419 } else if (pring->ringno == psli->ip_ring) {
1421 } else if (pring->ringno == psli->fcp_ring) {
1422 /* Skip match check if waiting to relogin to FCP target */
1423 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1424 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1427 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1430 } else if (pring->ringno == psli->next_ring) {
1437 * Free resources / clean up outstanding I/Os
1438 * associated with nlp_rpi in the LPFC_NODELIST entry.
1441 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1443 struct lpfc_sli *psli;
1444 struct lpfc_sli_ring *pring;
1445 struct lpfc_iocbq *iocb, *next_iocb;
1450 * Everything that matches on txcmplq will be returned
1451 * by firmware with a no rpi error.
1454 rpi = ndlp->nlp_rpi;
1456 /* Now process each ring */
1457 for (i = 0; i < psli->num_rings; i++) {
1458 pring = &psli->ring[i];
1460 spin_lock_irq(phba->host->host_lock);
1461 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1464 * Check to see if iocb matches the nport we are
1467 if ((lpfc_check_sli_ndlp
1468 (phba, pring, iocb, ndlp))) {
1469 /* It matches, so deque and call compl
1471 list_del(&iocb->list);
1473 if (iocb->iocb_cmpl) {
1476 IOSTAT_LOCAL_REJECT;
1477 icmd->un.ulpWord[4] =
1479 spin_unlock_irq(phba->host->
1481 (iocb->iocb_cmpl) (phba,
1483 spin_lock_irq(phba->host->
1486 lpfc_sli_release_iocbq(phba,
1490 spin_unlock_irq(phba->host->host_lock);
1498 * Free rpi associated with LPFC_NODELIST entry.
1499 * This routine is called from lpfc_freenode(), when we are removing
1500 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1501 * LOGO that completes successfully, and we are waiting to PLOGI back
1502 * to the remote NPort. In addition, it is called after we receive
1503 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1504 * we are waiting to PLOGI back to the remote NPort.
1507 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1512 if (ndlp->nlp_rpi) {
1513 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1514 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1515 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1516 rc = lpfc_sli_issue_mbox
1517 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1518 if (rc == MBX_NOT_FINISHED)
1519 mempool_free( mbox, phba->mbox_mem_pool);
1521 lpfc_no_rpi(phba, ndlp);
1529 * Free resources associated with LPFC_NODELIST entry
1530 * so it can be freed.
1533 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1536 LPFC_MBOXQ_t *nextmb;
1537 struct lpfc_dmabuf *mp;
1539 /* Cleanup node for NPort <nlp_DID> */
1540 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1541 "%d:0900 Cleanup node for NPort x%x "
1542 "Data: x%x x%x x%x\n",
1543 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1544 ndlp->nlp_state, ndlp->nlp_rpi);
1546 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1549 * if unloading the driver - just leave the remote port in place.
1550 * The driver unload will force the attached devices to detach
1551 * and flush cache's w/o generating flush errors.
1553 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1554 lpfc_unregister_remote_port(phba, ndlp);
1555 ndlp->nlp_sid = NLP_NO_SID;
1558 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1559 if ((mb = phba->sli.mbox_active)) {
1560 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1561 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1562 mb->context2 = NULL;
1563 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1567 spin_lock_irq(phba->host->host_lock);
1568 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1569 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1570 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1571 mp = (struct lpfc_dmabuf *) (mb->context1);
1573 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1576 list_del(&mb->list);
1577 mempool_free(mb, phba->mbox_mem_pool);
1580 spin_unlock_irq(phba->host->host_lock);
1582 lpfc_els_abort(phba,ndlp,0);
1583 spin_lock_irq(phba->host->host_lock);
1584 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1585 spin_unlock_irq(phba->host->host_lock);
1586 del_timer_sync(&ndlp->nlp_tmofunc);
1588 ndlp->nlp_last_elscmd = 0;
1589 del_timer_sync(&ndlp->nlp_delayfunc);
1591 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1592 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1593 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1594 list_del_init(&ndlp->els_retry_evt.evt_listp);
1596 lpfc_unreg_rpi(phba, ndlp);
1602 * Check to see if we can free the nlp back to the freelist.
1603 * If we are in the middle of using the nlp in the discovery state
1604 * machine, defer the free till we reach the end of the state machine.
1607 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1609 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1610 spin_lock_irq(phba->host->host_lock);
1611 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1612 spin_unlock_irq(phba->host->host_lock);
1613 del_timer_sync(&ndlp->nlp_tmofunc);
1614 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1615 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1620 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1621 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1624 if (ndlp->nlp_disc_refcnt) {
1625 spin_lock_irq(phba->host->host_lock);
1626 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1627 spin_unlock_irq(phba->host->host_lock);
1629 lpfc_freenode(phba, ndlp);
1630 mempool_free( ndlp, phba->nlp_mem_pool);
1636 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1642 if (did == Bcast_DID)
1645 if (ndlp->nlp_DID == 0) {
1649 /* First check for Direct match */
1650 if (ndlp->nlp_DID == did)
1653 /* Next check for area/domain identically equals 0 match */
1654 mydid.un.word = phba->fc_myDID;
1655 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1659 matchdid.un.word = did;
1660 ndlpdid.un.word = ndlp->nlp_DID;
1661 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1662 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1663 (mydid.un.b.area == matchdid.un.b.area)) {
1664 if ((ndlpdid.un.b.domain == 0) &&
1665 (ndlpdid.un.b.area == 0)) {
1666 if (ndlpdid.un.b.id)
1672 matchdid.un.word = ndlp->nlp_DID;
1673 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1674 (mydid.un.b.area == ndlpdid.un.b.area)) {
1675 if ((matchdid.un.b.domain == 0) &&
1676 (matchdid.un.b.area == 0)) {
1677 if (matchdid.un.b.id)
1685 /* Search for a nodelist entry on a specific list */
1686 struct lpfc_nodelist *
1687 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1689 struct lpfc_nodelist *ndlp, *next_ndlp;
1692 spin_lock_irq(phba->host->host_lock);
1693 if (order & NLP_SEARCH_UNMAPPED) {
1694 list_for_each_entry_safe(ndlp, next_ndlp,
1695 &phba->fc_nlpunmap_list, nlp_listp) {
1696 if (lpfc_matchdid(phba, ndlp, did)) {
1697 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1698 ((uint32_t) ndlp->nlp_xri << 16) |
1699 ((uint32_t) ndlp->nlp_type << 8) |
1700 ((uint32_t) ndlp->nlp_rpi & 0xff));
1701 /* FIND node DID unmapped */
1702 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1703 "%d:0929 FIND node DID unmapped"
1704 " Data: x%p x%x x%x x%x\n",
1706 ndlp, ndlp->nlp_DID,
1707 ndlp->nlp_flag, data1);
1708 spin_unlock_irq(phba->host->host_lock);
1714 if (order & NLP_SEARCH_MAPPED) {
1715 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1717 if (lpfc_matchdid(phba, ndlp, did)) {
1719 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1720 ((uint32_t) ndlp->nlp_xri << 16) |
1721 ((uint32_t) ndlp->nlp_type << 8) |
1722 ((uint32_t) ndlp->nlp_rpi & 0xff));
1723 /* FIND node DID mapped */
1724 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1725 "%d:0930 FIND node DID mapped "
1726 "Data: x%p x%x x%x x%x\n",
1728 ndlp, ndlp->nlp_DID,
1729 ndlp->nlp_flag, data1);
1730 spin_unlock_irq(phba->host->host_lock);
1736 if (order & NLP_SEARCH_PLOGI) {
1737 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1739 if (lpfc_matchdid(phba, ndlp, did)) {
1741 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1742 ((uint32_t) ndlp->nlp_xri << 16) |
1743 ((uint32_t) ndlp->nlp_type << 8) |
1744 ((uint32_t) ndlp->nlp_rpi & 0xff));
1745 /* LOG change to PLOGI */
1746 /* FIND node DID plogi */
1747 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1748 "%d:0908 FIND node DID plogi "
1749 "Data: x%p x%x x%x x%x\n",
1751 ndlp, ndlp->nlp_DID,
1752 ndlp->nlp_flag, data1);
1753 spin_unlock_irq(phba->host->host_lock);
1759 if (order & NLP_SEARCH_ADISC) {
1760 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1762 if (lpfc_matchdid(phba, ndlp, did)) {
1764 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1765 ((uint32_t) ndlp->nlp_xri << 16) |
1766 ((uint32_t) ndlp->nlp_type << 8) |
1767 ((uint32_t) ndlp->nlp_rpi & 0xff));
1768 /* LOG change to ADISC */
1769 /* FIND node DID adisc */
1770 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1771 "%d:0931 FIND node DID adisc "
1772 "Data: x%p x%x x%x x%x\n",
1774 ndlp, ndlp->nlp_DID,
1775 ndlp->nlp_flag, data1);
1776 spin_unlock_irq(phba->host->host_lock);
1782 if (order & NLP_SEARCH_REGLOGIN) {
1783 list_for_each_entry_safe(ndlp, next_ndlp,
1784 &phba->fc_reglogin_list, nlp_listp) {
1785 if (lpfc_matchdid(phba, ndlp, did)) {
1787 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1788 ((uint32_t) ndlp->nlp_xri << 16) |
1789 ((uint32_t) ndlp->nlp_type << 8) |
1790 ((uint32_t) ndlp->nlp_rpi & 0xff));
1791 /* LOG change to REGLOGIN */
1792 /* FIND node DID reglogin */
1793 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1794 "%d:0901 FIND node DID reglogin"
1795 " Data: x%p x%x x%x x%x\n",
1797 ndlp, ndlp->nlp_DID,
1798 ndlp->nlp_flag, data1);
1799 spin_unlock_irq(phba->host->host_lock);
1805 if (order & NLP_SEARCH_PRLI) {
1806 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1808 if (lpfc_matchdid(phba, ndlp, did)) {
1810 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1811 ((uint32_t) ndlp->nlp_xri << 16) |
1812 ((uint32_t) ndlp->nlp_type << 8) |
1813 ((uint32_t) ndlp->nlp_rpi & 0xff));
1814 /* LOG change to PRLI */
1815 /* FIND node DID prli */
1816 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1817 "%d:0902 FIND node DID prli "
1818 "Data: x%p x%x x%x x%x\n",
1820 ndlp, ndlp->nlp_DID,
1821 ndlp->nlp_flag, data1);
1822 spin_unlock_irq(phba->host->host_lock);
1828 if (order & NLP_SEARCH_NPR) {
1829 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1831 if (lpfc_matchdid(phba, ndlp, did)) {
1833 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1834 ((uint32_t) ndlp->nlp_xri << 16) |
1835 ((uint32_t) ndlp->nlp_type << 8) |
1836 ((uint32_t) ndlp->nlp_rpi & 0xff));
1837 /* LOG change to NPR */
1838 /* FIND node DID npr */
1839 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1840 "%d:0903 FIND node DID npr "
1841 "Data: x%p x%x x%x x%x\n",
1843 ndlp, ndlp->nlp_DID,
1844 ndlp->nlp_flag, data1);
1845 spin_unlock_irq(phba->host->host_lock);
1851 if (order & NLP_SEARCH_UNUSED) {
1852 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1854 if (lpfc_matchdid(phba, ndlp, did)) {
1856 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1857 ((uint32_t) ndlp->nlp_xri << 16) |
1858 ((uint32_t) ndlp->nlp_type << 8) |
1859 ((uint32_t) ndlp->nlp_rpi & 0xff));
1860 /* LOG change to UNUSED */
1861 /* FIND node DID unused */
1862 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1863 "%d:0905 FIND node DID unused "
1864 "Data: x%p x%x x%x x%x\n",
1866 ndlp, ndlp->nlp_DID,
1867 ndlp->nlp_flag, data1);
1868 spin_unlock_irq(phba->host->host_lock);
1874 spin_unlock_irq(phba->host->host_lock);
1876 /* FIND node did <did> NOT FOUND */
1877 lpfc_printf_log(phba,
1880 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1881 phba->brd_no, did, order);
1883 /* no match found */
1887 struct lpfc_nodelist *
1888 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1890 struct lpfc_nodelist *ndlp;
1893 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1895 if ((phba->fc_flag & FC_RSCN_MODE) &&
1896 ((lpfc_rscn_payload_check(phba, did) == 0)))
1898 ndlp = (struct lpfc_nodelist *)
1899 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1902 lpfc_nlp_init(phba, ndlp, did);
1903 ndlp->nlp_state = NLP_STE_NPR_NODE;
1904 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1905 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1908 if (phba->fc_flag & FC_RSCN_MODE) {
1909 if (lpfc_rscn_payload_check(phba, did)) {
1910 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1912 /* Since this node is marked for discovery,
1913 * delay timeout is not needed.
1915 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1916 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1920 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1921 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1923 ndlp->nlp_state = NLP_STE_NPR_NODE;
1924 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1925 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1930 /* Build a list of nodes to discover based on the loopmap */
1932 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1935 uint32_t alpa, index;
1937 if (phba->hba_state <= LPFC_LINK_DOWN) {
1940 if (phba->fc_topology != TOPOLOGY_LOOP) {
1944 /* Check for loop map present or not */
1945 if (phba->alpa_map[0]) {
1946 for (j = 1; j <= phba->alpa_map[0]; j++) {
1947 alpa = phba->alpa_map[j];
1949 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1952 lpfc_setup_disc_node(phba, alpa);
1955 /* No alpamap, so try all alpa's */
1956 for (j = 0; j < FC_MAXLOOP; j++) {
1957 /* If cfg_scan_down is set, start from highest
1958 * ALPA (0xef) to lowest (0x1).
1960 if (phba->cfg_scan_down)
1963 index = FC_MAXLOOP - j - 1;
1964 alpa = lpfcAlpaArray[index];
1965 if ((phba->fc_myDID & 0xff) == alpa) {
1969 lpfc_setup_disc_node(phba, alpa);
1975 /* Start Link up / RSCN discovery on NPR list */
1977 lpfc_disc_start(struct lpfc_hba * phba)
1979 struct lpfc_sli *psli;
1981 struct lpfc_nodelist *ndlp, *next_ndlp;
1982 uint32_t did_changed, num_sent;
1983 uint32_t clear_la_pending;
1988 if (phba->hba_state <= LPFC_LINK_DOWN) {
1991 if (phba->hba_state == LPFC_CLEAR_LA)
1992 clear_la_pending = 1;
1994 clear_la_pending = 0;
1996 if (phba->hba_state < LPFC_HBA_READY) {
1997 phba->hba_state = LPFC_DISC_AUTH;
1999 lpfc_set_disctmo(phba);
2001 if (phba->fc_prevDID == phba->fc_myDID) {
2006 phba->fc_prevDID = phba->fc_myDID;
2007 phba->num_disc_nodes = 0;
2009 /* Start Discovery state <hba_state> */
2010 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2011 "%d:0202 Start Discovery hba state x%x "
2012 "Data: x%x x%x x%x\n",
2013 phba->brd_no, phba->hba_state, phba->fc_flag,
2014 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2016 /* If our did changed, we MUST do PLOGI */
2017 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2019 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2021 spin_lock_irq(phba->host->host_lock);
2022 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2023 spin_unlock_irq(phba->host->host_lock);
2028 /* First do ADISCs - if any */
2029 num_sent = lpfc_els_disc_adisc(phba);
2034 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2035 /* If we get here, there is nothing to ADISC */
2036 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2037 phba->hba_state = LPFC_CLEAR_LA;
2038 lpfc_clear_la(phba, mbox);
2039 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2040 rc = lpfc_sli_issue_mbox(phba, mbox,
2041 (MBX_NOWAIT | MBX_STOP_IOCB));
2042 if (rc == MBX_NOT_FINISHED) {
2043 mempool_free( mbox, phba->mbox_mem_pool);
2044 lpfc_disc_flush_list(phba);
2045 psli->ring[(psli->ip_ring)].flag &=
2046 ~LPFC_STOP_IOCB_EVENT;
2047 psli->ring[(psli->fcp_ring)].flag &=
2048 ~LPFC_STOP_IOCB_EVENT;
2049 psli->ring[(psli->next_ring)].flag &=
2050 ~LPFC_STOP_IOCB_EVENT;
2051 phba->hba_state = LPFC_HBA_READY;
2055 /* Next do PLOGIs - if any */
2056 num_sent = lpfc_els_disc_plogi(phba);
2061 if (phba->fc_flag & FC_RSCN_MODE) {
2062 /* Check to see if more RSCNs came in while we
2063 * were processing this one.
2065 if ((phba->fc_rscn_id_cnt == 0) &&
2066 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2067 spin_lock_irq(phba->host->host_lock);
2068 phba->fc_flag &= ~FC_RSCN_MODE;
2069 spin_unlock_irq(phba->host->host_lock);
2071 lpfc_els_handle_rscn(phba);
2078 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2079 * ring the match the sppecified nodelist.
2082 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2084 struct lpfc_sli *psli;
2086 struct lpfc_iocbq *iocb, *next_iocb;
2087 struct lpfc_sli_ring *pring;
2088 struct lpfc_dmabuf *mp;
2091 pring = &psli->ring[LPFC_ELS_RING];
2093 /* Error matching iocb on txq or txcmplq
2094 * First check the txq.
2096 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2097 if (iocb->context1 != ndlp) {
2101 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2102 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2104 list_del(&iocb->list);
2106 lpfc_els_free_iocb(phba, iocb);
2110 /* Next check the txcmplq */
2111 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2112 if (iocb->context1 != ndlp) {
2116 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2117 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2119 iocb->iocb_cmpl = NULL;
2120 /* context2 = cmd, context2->next = rsp, context3 =
2122 if (iocb->context2) {
2123 /* Free the response IOCB before handling the
2126 mp = (struct lpfc_dmabuf *) (iocb->context2);
2127 mp = list_get_first(&mp->list,
2131 /* Delay before releasing rsp buffer to
2132 * give UNREG mbox a chance to take
2136 &phba->freebufList);
2138 lpfc_mbuf_free(phba,
2139 ((struct lpfc_dmabuf *)
2140 iocb->context2)->virt,
2141 ((struct lpfc_dmabuf *)
2142 iocb->context2)->phys);
2143 kfree(iocb->context2);
2146 if (iocb->context3) {
2147 lpfc_mbuf_free(phba,
2148 ((struct lpfc_dmabuf *)
2149 iocb->context3)->virt,
2150 ((struct lpfc_dmabuf *)
2151 iocb->context3)->phys);
2152 kfree(iocb->context3);
2161 lpfc_disc_flush_list(struct lpfc_hba * phba)
2163 struct lpfc_nodelist *ndlp, *next_ndlp;
2165 if (phba->fc_plogi_cnt) {
2166 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2168 lpfc_free_tx(phba, ndlp);
2169 lpfc_nlp_remove(phba, ndlp);
2172 if (phba->fc_adisc_cnt) {
2173 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2175 lpfc_free_tx(phba, ndlp);
2176 lpfc_nlp_remove(phba, ndlp);
2182 /*****************************************************************************/
2184 * NAME: lpfc_disc_timeout
2186 * FUNCTION: Fibre Channel driver discovery timeout routine.
2188 * EXECUTION ENVIRONMENT: interrupt only
2196 /*****************************************************************************/
2198 lpfc_disc_timeout(unsigned long ptr)
2200 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2201 unsigned long flags = 0;
2203 if (unlikely(!phba))
2206 spin_lock_irqsave(phba->host->host_lock, flags);
2207 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2208 phba->work_hba_events |= WORKER_DISC_TMO;
2209 if (phba->work_wait)
2210 wake_up(phba->work_wait);
2212 spin_unlock_irqrestore(phba->host->host_lock, flags);
2217 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2219 struct lpfc_sli *psli;
2220 struct lpfc_nodelist *ndlp, *next_ndlp;
2221 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2222 int rc, clrlaerr = 0;
2224 if (unlikely(!phba))
2227 if (!(phba->fc_flag & FC_DISC_TMO))
2232 spin_lock_irq(phba->host->host_lock);
2233 phba->fc_flag &= ~FC_DISC_TMO;
2234 spin_unlock_irq(phba->host->host_lock);
2236 switch (phba->hba_state) {
2238 case LPFC_LOCAL_CFG_LINK:
2239 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2241 lpfc_printf_log(phba,
2244 "%d:0221 FAN timeout\n",
2247 /* Start discovery by sending FLOGI, clean up old rpis */
2248 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2250 if (ndlp->nlp_type & NLP_FABRIC) {
2251 /* Clean up the ndlp on Fabric connections */
2252 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2253 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2254 /* Fail outstanding IO now since device
2255 * is marked for PLOGI.
2257 lpfc_unreg_rpi(phba, ndlp);
2260 phba->hba_state = LPFC_FLOGI;
2261 lpfc_set_disctmo(phba);
2262 lpfc_initial_flogi(phba);
2266 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2267 /* Initial FLOGI timeout */
2268 lpfc_printf_log(phba,
2271 "%d:0222 Initial FLOGI timeout\n",
2274 /* Assume no Fabric and go on with discovery.
2275 * Check for outstanding ELS FLOGI to abort.
2278 /* FLOGI failed, so just use loop map to make discovery list */
2279 lpfc_disc_list_loopmap(phba);
2281 /* Start discovery */
2282 lpfc_disc_start(phba);
2285 case LPFC_FABRIC_CFG_LINK:
2286 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2288 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2289 "%d:0223 Timeout while waiting for NameServer "
2290 "login\n", phba->brd_no);
2292 /* Next look for NameServer ndlp */
2293 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2295 lpfc_nlp_remove(phba, ndlp);
2296 /* Start discovery */
2297 lpfc_disc_start(phba);
2301 /* Check for wait for NameServer Rsp timeout */
2302 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2303 "%d:0224 NameServer Query timeout "
2306 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2308 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2311 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2312 /* Try it one more time */
2313 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2317 phba->fc_ns_retry = 0;
2320 /* Nothing to authenticate, so CLEAR_LA right now */
2321 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2324 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2325 "%d:0226 Device Discovery "
2326 "completion error\n",
2328 phba->hba_state = LPFC_HBA_ERROR;
2332 phba->hba_state = LPFC_CLEAR_LA;
2333 lpfc_clear_la(phba, clearlambox);
2334 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2335 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2336 (MBX_NOWAIT | MBX_STOP_IOCB));
2337 if (rc == MBX_NOT_FINISHED) {
2338 mempool_free(clearlambox, phba->mbox_mem_pool);
2343 /* Setup and issue mailbox INITIALIZE LINK command */
2344 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2345 if (!initlinkmbox) {
2346 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2347 "%d:0206 Device Discovery "
2348 "completion error\n",
2350 phba->hba_state = LPFC_HBA_ERROR;
2354 lpfc_linkdown(phba);
2355 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2356 phba->cfg_link_speed);
2357 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2358 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2359 (MBX_NOWAIT | MBX_STOP_IOCB));
2360 if (rc == MBX_NOT_FINISHED)
2361 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2365 case LPFC_DISC_AUTH:
2366 /* Node Authentication timeout */
2367 lpfc_printf_log(phba,
2370 "%d:0227 Node Authentication timeout\n",
2372 lpfc_disc_flush_list(phba);
2373 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2376 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2377 "%d:0207 Device Discovery "
2378 "completion error\n",
2380 phba->hba_state = LPFC_HBA_ERROR;
2383 phba->hba_state = LPFC_CLEAR_LA;
2384 lpfc_clear_la(phba, clearlambox);
2385 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2386 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2387 (MBX_NOWAIT | MBX_STOP_IOCB));
2388 if (rc == MBX_NOT_FINISHED) {
2389 mempool_free(clearlambox, phba->mbox_mem_pool);
2395 /* CLEAR LA timeout */
2396 lpfc_printf_log(phba,
2399 "%d:0228 CLEAR LA timeout\n",
2404 case LPFC_HBA_READY:
2405 if (phba->fc_flag & FC_RSCN_MODE) {
2406 lpfc_printf_log(phba,
2409 "%d:0231 RSCN timeout Data: x%x x%x\n",
2411 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2413 /* Cleanup any outstanding ELS commands */
2414 lpfc_els_flush_cmd(phba);
2416 lpfc_els_flush_rscn(phba);
2417 lpfc_disc_flush_list(phba);
2423 lpfc_disc_flush_list(phba);
2424 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2425 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2426 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2427 phba->hba_state = LPFC_HBA_READY;
2434 lpfc_nodev_timeout(unsigned long ptr)
2436 struct lpfc_hba *phba;
2437 struct lpfc_nodelist *ndlp;
2438 unsigned long iflag;
2439 struct lpfc_work_evt *evtp;
2441 ndlp = (struct lpfc_nodelist *)ptr;
2442 phba = ndlp->nlp_phba;
2443 evtp = &ndlp->nodev_timeout_evt;
2444 spin_lock_irqsave(phba->host->host_lock, iflag);
2446 if (!list_empty(&evtp->evt_listp)) {
2447 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2450 evtp->evt_arg1 = ndlp;
2451 evtp->evt = LPFC_EVT_NODEV_TMO;
2452 list_add_tail(&evtp->evt_listp, &phba->work_list);
2453 if (phba->work_wait)
2454 wake_up(phba->work_wait);
2456 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2462 * This routine handles processing a NameServer REG_LOGIN mailbox
2463 * command upon completion. It is setup in the LPFC_MBOXQ
2464 * as the completion routine when the command is
2465 * handed off to the SLI layer.
2468 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2470 struct lpfc_sli *psli;
2472 struct lpfc_dmabuf *mp;
2473 struct lpfc_nodelist *ndlp;
2478 ndlp = (struct lpfc_nodelist *) pmb->context2;
2479 mp = (struct lpfc_dmabuf *) (pmb->context1);
2481 pmb->context1 = NULL;
2483 ndlp->nlp_rpi = mb->un.varWords[0];
2484 ndlp->nlp_type |= NLP_FABRIC;
2485 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2486 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2488 /* Start issuing Fabric-Device Management Interface (FDMI)
2489 * command to 0xfffffa (FDMI well known port)
2491 if (phba->cfg_fdmi_on == 1) {
2492 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2495 * Delay issuing FDMI command if fdmi-on=2
2496 * (supporting RPA/hostnmae)
2498 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2501 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2503 mempool_free( pmb, phba->mbox_mem_pool);
2509 * This routine looks up the ndlp lists
2510 * for the given RPI. If rpi found
2511 * it return the node list pointer
2514 struct lpfc_nodelist *
2515 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2517 struct lpfc_nodelist *ndlp;
2518 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2519 &phba->fc_nlpmap_list,
2520 &phba->fc_plogi_list,
2521 &phba->fc_adisc_list,
2522 &phba->fc_reglogin_list};
2525 spin_lock_irq(phba->host->host_lock);
2526 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2527 list_for_each_entry(ndlp, lists[i], nlp_listp)
2528 if (ndlp->nlp_rpi == rpi) {
2529 spin_unlock_irq(phba->host->host_lock);
2532 spin_unlock_irq(phba->host->host_lock);
2537 * This routine looks up the ndlp lists
2538 * for the given WWPN. If WWPN found
2539 * it return the node list pointer
2542 struct lpfc_nodelist *
2543 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2544 struct lpfc_name * wwpn)
2546 struct lpfc_nodelist *ndlp;
2547 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2548 &phba->fc_nlpmap_list,
2550 &phba->fc_plogi_list,
2551 &phba->fc_adisc_list,
2552 &phba->fc_reglogin_list,
2553 &phba->fc_prli_list};
2554 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2559 NLP_SEARCH_REGLOGIN,
2563 spin_lock_irq(phba->host->host_lock);
2564 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2565 if (!(order & search[i]))
2567 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2568 if (memcmp(&ndlp->nlp_portname, wwpn,
2569 sizeof(struct lpfc_name)) == 0) {
2570 spin_unlock_irq(phba->host->host_lock);
2575 spin_unlock_irq(phba->host->host_lock);
2580 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2583 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2584 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2585 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2586 init_timer(&ndlp->nlp_tmofunc);
2587 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2588 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2589 init_timer(&ndlp->nlp_delayfunc);
2590 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2591 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2592 ndlp->nlp_DID = did;
2593 ndlp->nlp_phba = phba;
2594 ndlp->nlp_sid = NLP_NO_SID;