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_terminate_rport_io(struct fc_rport *rport)
62 struct lpfc_rport_data *rdata;
63 struct lpfc_nodelist * ndlp;
64 struct lpfc_hba *phba;
66 rdata = rport->dd_data;
70 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
71 printk(KERN_ERR "Cannot find remote node"
72 " to terminate I/O Data x%x\n",
77 phba = ndlp->nlp_phba;
79 spin_lock_irq(phba->host->host_lock);
80 if (ndlp->nlp_sid != NLP_NO_SID) {
81 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
82 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
84 spin_unlock_irq(phba->host->host_lock);
90 * This function will be called when dev_loss_tmo fire.
93 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist * ndlp;
99 struct lpfc_hba *phba;
101 rdata = rport->dd_data;
105 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
106 printk(KERN_ERR "Cannot find remote node"
107 " for rport in dev_loss_tmo_callbk x%x\n",
112 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
115 name = (uint8_t *)&ndlp->nlp_portname;
116 phba = ndlp->nlp_phba;
118 spin_lock_irq(phba->host->host_lock);
120 if (ndlp->nlp_sid != NLP_NO_SID) {
122 /* flush the target */
123 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
124 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
126 if (phba->fc_flag & FC_UNLOADING)
129 spin_unlock_irq(phba->host->host_lock);
132 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
133 "%d:0203 Devloss timeout on "
134 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
135 "NPort x%x Data: x%x x%x x%x\n",
137 *name, *(name+1), *(name+2), *(name+3),
138 *(name+4), *(name+5), *(name+6), *(name+7),
139 ndlp->nlp_DID, ndlp->nlp_flag,
140 ndlp->nlp_state, ndlp->nlp_rpi);
142 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
143 "%d:0204 Devloss timeout on "
144 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
145 "NPort x%x Data: x%x x%x x%x\n",
147 *name, *(name+1), *(name+2), *(name+3),
148 *(name+4), *(name+5), *(name+6), *(name+7),
149 ndlp->nlp_DID, ndlp->nlp_flag,
150 ndlp->nlp_state, ndlp->nlp_rpi);
153 if (!(phba->fc_flag & FC_UNLOADING) &&
154 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
155 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
156 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
157 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
162 put_device(&rport->dev);
169 lpfc_work_list_done(struct lpfc_hba * phba)
171 struct lpfc_work_evt *evtp = NULL;
172 struct lpfc_nodelist *ndlp;
175 spin_lock_irq(phba->host->host_lock);
176 while(!list_empty(&phba->work_list)) {
177 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
179 spin_unlock_irq(phba->host->host_lock);
182 case LPFC_EVT_ELS_RETRY:
183 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
184 lpfc_els_retry_delay_handler(ndlp);
187 case LPFC_EVT_ONLINE:
188 if (phba->hba_state < LPFC_LINK_DOWN)
189 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
191 *(int *)(evtp->evt_arg1) = 0;
192 complete((struct completion *)(evtp->evt_arg2));
194 case LPFC_EVT_OFFLINE_PREP:
195 if (phba->hba_state >= LPFC_LINK_DOWN)
196 lpfc_offline_prep(phba);
197 *(int *)(evtp->evt_arg1) = 0;
198 complete((struct completion *)(evtp->evt_arg2));
200 case LPFC_EVT_OFFLINE:
202 lpfc_sli_brdrestart(phba);
203 *(int *)(evtp->evt_arg1) =
204 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
205 lpfc_unblock_mgmt_io(phba);
206 complete((struct completion *)(evtp->evt_arg2));
208 case LPFC_EVT_WARM_START:
210 lpfc_reset_barrier(phba);
211 lpfc_sli_brdreset(phba);
212 lpfc_hba_down_post(phba);
213 *(int *)(evtp->evt_arg1) =
214 lpfc_sli_brdready(phba, HS_MBRDY);
215 lpfc_unblock_mgmt_io(phba);
216 complete((struct completion *)(evtp->evt_arg2));
220 *(int *)(evtp->evt_arg1)
221 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
222 lpfc_unblock_mgmt_io(phba);
223 complete((struct completion *)(evtp->evt_arg2));
228 spin_lock_irq(phba->host->host_lock);
230 spin_unlock_irq(phba->host->host_lock);
235 lpfc_work_done(struct lpfc_hba * phba)
237 struct lpfc_sli_ring *pring;
241 uint32_t work_hba_events;
243 spin_lock_irq(phba->host->host_lock);
244 ha_copy = phba->work_ha;
246 work_hba_events=phba->work_hba_events;
247 spin_unlock_irq(phba->host->host_lock);
249 if (ha_copy & HA_ERATT)
250 lpfc_handle_eratt(phba);
252 if (ha_copy & HA_MBATT)
253 lpfc_sli_handle_mb_event(phba);
255 if (ha_copy & HA_LATT)
256 lpfc_handle_latt(phba);
258 if (work_hba_events & WORKER_DISC_TMO)
259 lpfc_disc_timeout_handler(phba);
261 if (work_hba_events & WORKER_ELS_TMO)
262 lpfc_els_timeout_handler(phba);
264 if (work_hba_events & WORKER_MBOX_TMO)
265 lpfc_mbox_timeout_handler(phba);
267 if (work_hba_events & WORKER_FDMI_TMO)
268 lpfc_fdmi_tmo_handler(phba);
270 spin_lock_irq(phba->host->host_lock);
271 phba->work_hba_events &= ~work_hba_events;
272 spin_unlock_irq(phba->host->host_lock);
274 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
275 pring = &phba->sli.ring[i];
276 if ((ha_copy & HA_RXATT)
277 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
278 if (pring->flag & LPFC_STOP_IOCB_MASK) {
279 pring->flag |= LPFC_DEFERRED_RING_EVENT;
281 lpfc_sli_handle_slow_ring_event(phba, pring,
284 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
287 * Turn on Ring interrupts
289 spin_lock_irq(phba->host->host_lock);
290 control = readl(phba->HCregaddr);
291 control |= (HC_R0INT_ENA << i);
292 writel(control, phba->HCregaddr);
293 readl(phba->HCregaddr); /* flush */
294 spin_unlock_irq(phba->host->host_lock);
298 lpfc_work_list_done (phba);
303 check_work_wait_done(struct lpfc_hba *phba) {
305 spin_lock_irq(phba->host->host_lock);
307 phba->work_hba_events ||
308 (!list_empty(&phba->work_list)) ||
309 kthread_should_stop()) {
310 spin_unlock_irq(phba->host->host_lock);
313 spin_unlock_irq(phba->host->host_lock);
319 lpfc_do_work(void *p)
321 struct lpfc_hba *phba = p;
323 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
325 set_user_nice(current, -20);
326 phba->work_wait = &work_waitq;
330 rc = wait_event_interruptible(work_waitq,
331 check_work_wait_done(phba));
334 if (kthread_should_stop())
337 lpfc_work_done(phba);
340 phba->work_wait = NULL;
345 * This is only called to handle FC worker events. Since this a rare
346 * occurance, we allocate a struct lpfc_work_evt structure here instead of
347 * embedding it in the IOCB.
350 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
353 struct lpfc_work_evt *evtp;
356 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
357 * be queued to worker thread for processing
359 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
363 evtp->evt_arg1 = arg1;
364 evtp->evt_arg2 = arg2;
367 spin_lock_irq(phba->host->host_lock);
368 list_add_tail(&evtp->evt_listp, &phba->work_list);
370 wake_up(phba->work_wait);
371 spin_unlock_irq(phba->host->host_lock);
377 lpfc_linkdown(struct lpfc_hba * phba)
379 struct lpfc_sli *psli;
380 struct lpfc_nodelist *ndlp, *next_ndlp;
381 struct list_head *listp, *node_list[7];
386 /* sysfs or selective reset may call this routine to clean up */
387 if (phba->hba_state >= LPFC_LINK_DOWN) {
388 if (phba->hba_state == LPFC_LINK_DOWN)
391 spin_lock_irq(phba->host->host_lock);
392 phba->hba_state = LPFC_LINK_DOWN;
393 spin_unlock_irq(phba->host->host_lock);
396 fc_host_post_event(phba->host, fc_get_event_number(),
397 FCH_EVT_LINKDOWN, 0);
399 /* Clean up any firmware default rpi's */
400 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
401 lpfc_unreg_did(phba, 0xffffffff, mb);
402 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
403 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
404 == MBX_NOT_FINISHED) {
405 mempool_free( mb, phba->mbox_mem_pool);
409 /* Cleanup any outstanding RSCN activity */
410 lpfc_els_flush_rscn(phba);
412 /* Cleanup any outstanding ELS commands */
413 lpfc_els_flush_cmd(phba);
415 /* Issue a LINK DOWN event to all nodes */
416 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
417 node_list[1] = &phba->fc_nlpmap_list;
418 node_list[2] = &phba->fc_nlpunmap_list;
419 node_list[3] = &phba->fc_prli_list;
420 node_list[4] = &phba->fc_reglogin_list;
421 node_list[5] = &phba->fc_adisc_list;
422 node_list[6] = &phba->fc_plogi_list;
423 for (i = 0; i < 7; i++) {
424 listp = node_list[i];
425 if (list_empty(listp))
428 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
430 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
431 NLP_EVT_DEVICE_RECOVERY);
436 /* free any ndlp's on unused list */
437 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
439 lpfc_drop_node(phba, ndlp);
441 /* Setup myDID for link up if we are in pt2pt mode */
442 if (phba->fc_flag & FC_PT2PT) {
444 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
445 lpfc_config_link(phba, mb);
446 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
447 if (lpfc_sli_issue_mbox
448 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
449 == MBX_NOT_FINISHED) {
450 mempool_free( mb, phba->mbox_mem_pool);
453 spin_lock_irq(phba->host->host_lock);
454 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
455 spin_unlock_irq(phba->host->host_lock);
457 spin_lock_irq(phba->host->host_lock);
458 phba->fc_flag &= ~FC_LBIT;
459 spin_unlock_irq(phba->host->host_lock);
461 /* Turn off discovery timer if its running */
462 lpfc_can_disctmo(phba);
464 /* Must process IOCBs on all rings to handle ABORTed I/Os */
469 lpfc_linkup(struct lpfc_hba * phba)
471 struct lpfc_nodelist *ndlp, *next_ndlp;
472 struct list_head *listp, *node_list[7];
475 fc_host_post_event(phba->host, fc_get_event_number(),
478 spin_lock_irq(phba->host->host_lock);
479 phba->hba_state = LPFC_LINK_UP;
480 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
481 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
482 phba->fc_flag |= FC_NDISC_ACTIVE;
483 phba->fc_ns_retry = 0;
484 spin_unlock_irq(phba->host->host_lock);
487 node_list[0] = &phba->fc_plogi_list;
488 node_list[1] = &phba->fc_adisc_list;
489 node_list[2] = &phba->fc_reglogin_list;
490 node_list[3] = &phba->fc_prli_list;
491 node_list[4] = &phba->fc_nlpunmap_list;
492 node_list[5] = &phba->fc_nlpmap_list;
493 node_list[6] = &phba->fc_npr_list;
494 for (i = 0; i < 7; i++) {
495 listp = node_list[i];
496 if (list_empty(listp))
499 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
500 if (phba->fc_flag & FC_LBIT) {
501 if (ndlp->nlp_type & NLP_FABRIC) {
502 /* On Linkup its safe to clean up the
503 * ndlp from Fabric connections.
505 lpfc_nlp_set_state(phba, ndlp,
506 NLP_STE_UNUSED_NODE);
507 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
508 /* Fail outstanding IO now since device
509 * is marked for PLOGI.
511 lpfc_unreg_rpi(phba, ndlp);
517 /* free any ndlp's on unused list */
518 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
520 lpfc_drop_node(phba, ndlp);
526 * This routine handles processing a CLEAR_LA mailbox
527 * command upon completion. It is setup in the LPFC_MBOXQ
528 * as the completion routine when the command is
529 * handed off to the SLI layer.
532 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
534 struct lpfc_sli *psli;
540 /* Since we don't do discovery right now, turn these off here */
541 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
542 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
543 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
545 /* Check for error */
546 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
547 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
548 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
549 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
551 phba->brd_no, mb->mbxStatus, phba->hba_state);
553 phba->hba_state = LPFC_HBA_ERROR;
557 if (phba->fc_flag & FC_ABORT_DISCOVERY)
560 phba->num_disc_nodes = 0;
561 /* go thru NPR list and issue ELS PLOGIs */
562 if (phba->fc_npr_cnt) {
563 lpfc_els_disc_plogi(phba);
566 if (!phba->num_disc_nodes) {
567 spin_lock_irq(phba->host->host_lock);
568 phba->fc_flag &= ~FC_NDISC_ACTIVE;
569 spin_unlock_irq(phba->host->host_lock);
572 phba->hba_state = LPFC_HBA_READY;
575 /* Device Discovery completes */
576 lpfc_printf_log(phba,
579 "%d:0225 Device Discovery completes\n",
582 mempool_free( pmb, phba->mbox_mem_pool);
584 spin_lock_irq(phba->host->host_lock);
585 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
586 if (phba->fc_flag & FC_ESTABLISH_LINK) {
587 phba->fc_flag &= ~FC_ESTABLISH_LINK;
589 spin_unlock_irq(phba->host->host_lock);
591 del_timer_sync(&phba->fc_estabtmo);
593 lpfc_can_disctmo(phba);
595 /* turn on Link Attention interrupts */
596 spin_lock_irq(phba->host->host_lock);
597 psli->sli_flag |= LPFC_PROCESS_LA;
598 control = readl(phba->HCregaddr);
599 control |= HC_LAINT_ENA;
600 writel(control, phba->HCregaddr);
601 readl(phba->HCregaddr); /* flush */
602 spin_unlock_irq(phba->host->host_lock);
608 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
610 struct lpfc_sli *psli = &phba->sli;
613 if (pmb->mb.mbxStatus)
616 mempool_free(pmb, phba->mbox_mem_pool);
618 if (phba->fc_topology == TOPOLOGY_LOOP &&
619 phba->fc_flag & FC_PUBLIC_LOOP &&
620 !(phba->fc_flag & FC_LBIT)) {
621 /* Need to wait for FAN - use discovery timer
622 * for timeout. hba_state is identically
623 * LPFC_LOCAL_CFG_LINK while waiting for FAN
625 lpfc_set_disctmo(phba);
629 /* Start discovery by sending a FLOGI. hba_state is identically
630 * LPFC_FLOGI while waiting for FLOGI cmpl
632 phba->hba_state = LPFC_FLOGI;
633 lpfc_set_disctmo(phba);
634 lpfc_initial_flogi(phba);
638 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
639 "%d:0306 CONFIG_LINK mbxStatus error x%x "
641 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
645 phba->hba_state = LPFC_HBA_ERROR;
647 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
648 "%d:0200 CONFIG_LINK bad hba state x%x\n",
649 phba->brd_no, phba->hba_state);
651 lpfc_clear_la(phba, pmb);
652 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
653 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
654 if (rc == MBX_NOT_FINISHED) {
655 mempool_free(pmb, phba->mbox_mem_pool);
656 lpfc_disc_flush_list(phba);
657 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
658 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
659 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
660 phba->hba_state = LPFC_HBA_READY;
666 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
668 struct lpfc_sli *psli = &phba->sli;
669 MAILBOX_t *mb = &pmb->mb;
670 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
673 /* Check for error */
675 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
676 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
677 "%d:0319 READ_SPARAM mbxStatus error x%x "
679 phba->brd_no, mb->mbxStatus, phba->hba_state);
682 phba->hba_state = LPFC_HBA_ERROR;
686 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
687 sizeof (struct serv_parm));
688 if (phba->cfg_soft_wwnn)
689 u64_to_wwn(phba->cfg_soft_wwnn, phba->fc_sparam.nodeName.u.wwn);
690 if (phba->cfg_soft_wwpn)
691 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
692 memcpy((uint8_t *) & phba->fc_nodename,
693 (uint8_t *) & phba->fc_sparam.nodeName,
694 sizeof (struct lpfc_name));
695 memcpy((uint8_t *) & phba->fc_portname,
696 (uint8_t *) & phba->fc_sparam.portName,
697 sizeof (struct lpfc_name));
698 lpfc_mbuf_free(phba, mp->virt, mp->phys);
700 mempool_free( pmb, phba->mbox_mem_pool);
704 pmb->context1 = NULL;
705 lpfc_mbuf_free(phba, mp->virt, mp->phys);
707 if (phba->hba_state != LPFC_CLEAR_LA) {
708 lpfc_clear_la(phba, pmb);
709 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
710 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
711 == MBX_NOT_FINISHED) {
712 mempool_free( pmb, phba->mbox_mem_pool);
713 lpfc_disc_flush_list(phba);
714 psli->ring[(psli->extra_ring)].flag &=
715 ~LPFC_STOP_IOCB_EVENT;
716 psli->ring[(psli->fcp_ring)].flag &=
717 ~LPFC_STOP_IOCB_EVENT;
718 psli->ring[(psli->next_ring)].flag &=
719 ~LPFC_STOP_IOCB_EVENT;
720 phba->hba_state = LPFC_HBA_READY;
723 mempool_free( pmb, phba->mbox_mem_pool);
729 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
732 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
733 struct lpfc_dmabuf *mp;
736 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
737 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
739 spin_lock_irq(phba->host->host_lock);
740 switch (la->UlnkSpeed) {
742 phba->fc_linkspeed = LA_1GHZ_LINK;
745 phba->fc_linkspeed = LA_2GHZ_LINK;
748 phba->fc_linkspeed = LA_4GHZ_LINK;
751 phba->fc_linkspeed = LA_UNKNW_LINK;
755 phba->fc_topology = la->topology;
757 if (phba->fc_topology == TOPOLOGY_LOOP) {
758 /* Get Loop Map information */
761 phba->fc_flag |= FC_LBIT;
763 phba->fc_myDID = la->granted_AL_PA;
764 i = la->un.lilpBde64.tus.f.bdeSize;
767 phba->alpa_map[0] = 0;
769 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
780 numalpa = phba->alpa_map[0];
782 while (j < numalpa) {
783 memset(un.pamap, 0, 16);
784 for (k = 1; j < numalpa; k++) {
786 phba->alpa_map[j + 1];
791 /* Link Up Event ALPA map */
792 lpfc_printf_log(phba,
795 "%d:1304 Link Up Event "
796 "ALPA map Data: x%x "
799 un.pa.wd1, un.pa.wd2,
800 un.pa.wd3, un.pa.wd4);
805 phba->fc_myDID = phba->fc_pref_DID;
806 phba->fc_flag |= FC_LBIT;
808 spin_unlock_irq(phba->host->host_lock);
812 lpfc_read_sparam(phba, sparam_mbox);
813 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
814 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
815 (MBX_NOWAIT | MBX_STOP_IOCB));
816 if (rc == MBX_NOT_FINISHED) {
817 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
818 lpfc_mbuf_free(phba, mp->virt, mp->phys);
820 mempool_free(sparam_mbox, phba->mbox_mem_pool);
822 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
828 phba->hba_state = LPFC_LOCAL_CFG_LINK;
829 lpfc_config_link(phba, cfglink_mbox);
830 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
831 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
832 (MBX_NOWAIT | MBX_STOP_IOCB));
833 if (rc == MBX_NOT_FINISHED)
834 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
839 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
841 struct lpfc_sli *psli = &phba->sli;
845 /* turn on Link Attention interrupts - no CLEAR_LA needed */
846 spin_lock_irq(phba->host->host_lock);
847 psli->sli_flag |= LPFC_PROCESS_LA;
848 control = readl(phba->HCregaddr);
849 control |= HC_LAINT_ENA;
850 writel(control, phba->HCregaddr);
851 readl(phba->HCregaddr); /* flush */
852 spin_unlock_irq(phba->host->host_lock);
856 * This routine handles processing a READ_LA mailbox
857 * command upon completion. It is setup in the LPFC_MBOXQ
858 * as the completion routine when the command is
859 * handed off to the SLI layer.
862 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
865 MAILBOX_t *mb = &pmb->mb;
866 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
868 /* Check for error */
870 lpfc_printf_log(phba,
873 "%d:1307 READ_LA mbox error x%x state x%x\n",
875 mb->mbxStatus, phba->hba_state);
876 lpfc_mbx_issue_link_down(phba);
877 phba->hba_state = LPFC_HBA_ERROR;
878 goto lpfc_mbx_cmpl_read_la_free_mbuf;
881 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
883 memcpy(&phba->alpa_map[0], mp->virt, 128);
885 spin_lock_irq(phba->host->host_lock);
887 phba->fc_flag |= FC_BYPASSED_MODE;
889 phba->fc_flag &= ~FC_BYPASSED_MODE;
890 spin_unlock_irq(phba->host->host_lock);
892 if (((phba->fc_eventTag + 1) < la->eventTag) ||
893 (phba->fc_eventTag == la->eventTag)) {
894 phba->fc_stat.LinkMultiEvent++;
895 if (la->attType == AT_LINK_UP) {
896 if (phba->fc_eventTag != 0)
901 phba->fc_eventTag = la->eventTag;
903 if (la->attType == AT_LINK_UP) {
904 phba->fc_stat.LinkUp++;
905 if (phba->fc_flag & FC_LOOPBACK_MODE) {
906 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
907 "%d:1306 Link Up Event in loop back mode "
908 "x%x received Data: x%x x%x x%x x%x\n",
909 phba->brd_no, la->eventTag, phba->fc_eventTag,
910 la->granted_AL_PA, la->UlnkSpeed,
913 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
914 "%d:1303 Link Up Event x%x received "
915 "Data: x%x x%x x%x x%x\n",
916 phba->brd_no, la->eventTag, phba->fc_eventTag,
917 la->granted_AL_PA, la->UlnkSpeed,
920 lpfc_mbx_process_link_up(phba, la);
922 phba->fc_stat.LinkDown++;
923 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
924 "%d:1305 Link Down Event x%x received "
925 "Data: x%x x%x x%x\n",
926 phba->brd_no, la->eventTag, phba->fc_eventTag,
927 phba->hba_state, phba->fc_flag);
928 lpfc_mbx_issue_link_down(phba);
931 lpfc_mbx_cmpl_read_la_free_mbuf:
932 lpfc_mbuf_free(phba, mp->virt, mp->phys);
934 mempool_free(pmb, phba->mbox_mem_pool);
939 * This routine handles processing a REG_LOGIN mailbox
940 * command upon completion. It is setup in the LPFC_MBOXQ
941 * as the completion routine when the command is
942 * handed off to the SLI layer.
945 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
947 struct lpfc_sli *psli;
949 struct lpfc_dmabuf *mp;
950 struct lpfc_nodelist *ndlp;
955 ndlp = (struct lpfc_nodelist *) pmb->context2;
956 mp = (struct lpfc_dmabuf *) (pmb->context1);
958 pmb->context1 = NULL;
960 /* Good status, call state machine */
961 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
962 lpfc_mbuf_free(phba, mp->virt, mp->phys);
964 mempool_free( pmb, phba->mbox_mem_pool);
971 * This routine handles processing a Fabric REG_LOGIN mailbox
972 * command upon completion. It is setup in the LPFC_MBOXQ
973 * as the completion routine when the command is
974 * handed off to the SLI layer.
977 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
979 struct lpfc_sli *psli;
981 struct lpfc_dmabuf *mp;
982 struct lpfc_nodelist *ndlp;
983 struct lpfc_nodelist *ndlp_fdmi;
989 ndlp = (struct lpfc_nodelist *) pmb->context2;
990 mp = (struct lpfc_dmabuf *) (pmb->context1);
992 pmb->context1 = NULL;
993 pmb->context2 = NULL;
996 lpfc_mbuf_free(phba, mp->virt, mp->phys);
998 mempool_free(pmb, phba->mbox_mem_pool);
1001 /* FLOGI failed, so just use loop map to make discovery list */
1002 lpfc_disc_list_loopmap(phba);
1004 /* Start discovery */
1005 lpfc_disc_start(phba);
1009 ndlp->nlp_rpi = mb->un.varWords[0];
1010 ndlp->nlp_type |= NLP_FABRIC;
1011 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1013 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
1015 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
1016 /* This NPort has been assigned an NPort_ID by the fabric as a
1017 * result of the completed fabric login. Issue a State Change
1018 * Registration (SCR) ELS request to the fabric controller
1019 * (SCR_DID) so that this NPort gets RSCN events from the
1022 lpfc_issue_els_scr(phba, SCR_DID, 0);
1024 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
1026 /* Allocate a new node instance. If the pool is empty,
1027 * start the discovery process and skip the Nameserver
1028 * login process. This is attempted again later on.
1029 * Otherwise, issue a Port Login (PLOGI) to NameServer.
1031 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1033 lpfc_disc_start(phba);
1034 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1036 mempool_free(pmb, phba->mbox_mem_pool);
1039 lpfc_nlp_init(phba, ndlp, NameServer_DID);
1040 ndlp->nlp_type |= NLP_FABRIC;
1043 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1044 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
1045 if (phba->cfg_fdmi_on) {
1046 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1049 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
1050 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1051 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
1052 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
1057 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1059 mempool_free(pmb, phba->mbox_mem_pool);
1064 * This routine handles processing a NameServer REG_LOGIN mailbox
1065 * command upon completion. It is setup in the LPFC_MBOXQ
1066 * as the completion routine when the command is
1067 * handed off to the SLI layer.
1070 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1072 struct lpfc_sli *psli;
1074 struct lpfc_dmabuf *mp;
1075 struct lpfc_nodelist *ndlp;
1080 ndlp = (struct lpfc_nodelist *) pmb->context2;
1081 mp = (struct lpfc_dmabuf *) (pmb->context1);
1083 if (mb->mbxStatus) {
1085 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1087 mempool_free(pmb, phba->mbox_mem_pool);
1088 lpfc_drop_node(phba, ndlp);
1090 /* RegLogin failed, so just use loop map to make discovery
1092 lpfc_disc_list_loopmap(phba);
1094 /* Start discovery */
1095 lpfc_disc_start(phba);
1099 pmb->context1 = NULL;
1101 ndlp->nlp_rpi = mb->un.varWords[0];
1102 ndlp->nlp_type |= NLP_FABRIC;
1103 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1105 if (phba->hba_state < LPFC_HBA_READY) {
1106 /* Link up discovery requires Fabrib registration. */
1107 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1108 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1109 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1110 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFF_ID);
1113 phba->fc_ns_retry = 0;
1114 /* Good status, issue CT Request to NameServer */
1115 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1116 /* Cannot issue NameServer Query, so finish up discovery */
1117 lpfc_disc_start(phba);
1121 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1123 mempool_free( pmb, phba->mbox_mem_pool);
1129 lpfc_register_remote_port(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1131 struct fc_rport *rport;
1132 struct lpfc_rport_data *rdata;
1133 struct fc_rport_identifiers rport_ids;
1135 /* Remote port has reappeared. Re-register w/ FC transport */
1136 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1137 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1138 rport_ids.port_id = ndlp->nlp_DID;
1139 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1142 * We leave our node pointer in rport->dd_data when we unregister a
1143 * FCP target port. But fc_remote_port_add zeros the space to which
1144 * rport->dd_data points. So, if we're reusing a previously
1145 * registered port, drop the reference that we took the last time we
1146 * registered the port.
1148 if (ndlp->rport && ndlp->rport->dd_data &&
1149 *(struct lpfc_rport_data **) ndlp->rport->dd_data) {
1152 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1153 if (!rport || !get_device(&rport->dev)) {
1154 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1155 "Warning: fc_remote_port_add failed\n");
1159 /* initialize static port data */
1160 rport->maxframe_size = ndlp->nlp_maxframe;
1161 rport->supported_classes = ndlp->nlp_class_sup;
1162 rdata = rport->dd_data;
1163 rdata->pnode = lpfc_nlp_get(ndlp);
1165 if (ndlp->nlp_type & NLP_FCP_TARGET)
1166 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1167 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1168 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1171 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1172 fc_remote_port_rolechg(rport, rport_ids.roles);
1174 if ((rport->scsi_target_id != -1) &&
1175 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1176 ndlp->nlp_sid = rport->scsi_target_id;
1183 lpfc_unregister_remote_port(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1185 struct fc_rport *rport = ndlp->rport;
1186 struct lpfc_rport_data *rdata = rport->dd_data;
1188 if (rport->scsi_target_id == -1) {
1190 rdata->pnode = NULL;
1192 put_device(&rport->dev);
1195 fc_remote_port_delete(rport);
1201 lpfc_nlp_counters(struct lpfc_hba *phba, int state, int count)
1204 case NLP_STE_UNUSED_NODE:
1205 phba->fc_unused_cnt += count;
1207 case NLP_STE_PLOGI_ISSUE:
1208 phba->fc_plogi_cnt += count;
1210 case NLP_STE_ADISC_ISSUE:
1211 phba->fc_adisc_cnt += count;
1213 case NLP_STE_REG_LOGIN_ISSUE:
1214 phba->fc_reglogin_cnt += count;
1216 case NLP_STE_PRLI_ISSUE:
1217 phba->fc_prli_cnt += count;
1219 case NLP_STE_UNMAPPED_NODE:
1220 phba->fc_unmap_cnt += count;
1222 case NLP_STE_MAPPED_NODE:
1223 phba->fc_map_cnt += count;
1225 case NLP_STE_NPR_NODE:
1226 phba->fc_npr_cnt += count;
1232 lpfc_delink_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1234 switch (ndlp->nlp_flag & NLP_LIST_MASK) {
1235 case NLP_UNUSED_LIST:
1236 list_del_init(&ndlp->nlp_listp);
1238 case NLP_PLOGI_LIST:
1239 list_del_init(&ndlp->nlp_listp);
1241 case NLP_ADISC_LIST:
1242 list_del_init(&ndlp->nlp_listp);
1244 case NLP_REGLOGIN_LIST:
1245 list_del_init(&ndlp->nlp_listp);
1248 list_del_init(&ndlp->nlp_listp);
1250 case NLP_UNMAPPED_LIST:
1251 list_del_init(&ndlp->nlp_listp);
1253 case NLP_MAPPED_LIST:
1254 list_del_init(&ndlp->nlp_listp);
1257 list_del_init(&ndlp->nlp_listp);
1261 ndlp->nlp_flag &= ~NLP_LIST_MASK;
1265 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1267 struct lpfc_sli *psli;
1270 /* Sanity check to ensure we are not moving to / from the same list */
1271 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1274 spin_lock_irq(phba->host->host_lock);
1275 lpfc_delink_node(phba, nlp);
1277 /* Add NPort <did> to <num> list */
1278 lpfc_printf_log(phba,
1281 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1283 nlp->nlp_DID, list, nlp->nlp_flag);
1286 case NLP_UNUSED_LIST:
1287 nlp->nlp_flag |= list;
1288 /* Put it at the end of the unused list */
1289 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1291 case NLP_PLOGI_LIST:
1292 nlp->nlp_flag |= list;
1293 /* Put it at the end of the plogi list */
1294 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1296 case NLP_ADISC_LIST:
1297 nlp->nlp_flag |= list;
1298 /* Put it at the end of the adisc list */
1299 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1301 case NLP_REGLOGIN_LIST:
1302 nlp->nlp_flag |= list;
1303 /* Put it at the end of the reglogin list */
1304 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1307 nlp->nlp_flag |= list;
1308 /* Put it at the end of the prli list */
1309 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1311 case NLP_UNMAPPED_LIST:
1312 nlp->nlp_flag |= list;
1313 /* Put it at the end of the unmap list */
1314 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1316 case NLP_MAPPED_LIST:
1317 nlp->nlp_flag |= list;
1318 /* Put it at the end of the map list */
1319 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1322 nlp->nlp_flag |= list;
1323 /* Put it at the end of the npr list */
1324 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1328 spin_unlock_irq(phba->host->host_lock);
1333 lpfc_nlp_state_cleanup(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1334 int old_state, int new_state)
1336 if (new_state == NLP_STE_UNMAPPED_NODE) {
1337 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1338 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1339 ndlp->nlp_type |= NLP_FC_NODE;
1341 if (new_state == NLP_STE_MAPPED_NODE)
1342 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1343 if (new_state == NLP_STE_NPR_NODE)
1344 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1346 /* Transport interface */
1347 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1348 old_state == NLP_STE_UNMAPPED_NODE)) {
1349 phba->nport_event_cnt++;
1350 lpfc_unregister_remote_port(phba, ndlp);
1353 if (new_state == NLP_STE_MAPPED_NODE ||
1354 new_state == NLP_STE_UNMAPPED_NODE) {
1355 phba->nport_event_cnt++;
1357 * Tell the fc transport about the port, if we haven't
1358 * already. If we have, and it's a scsi entity, be
1359 * sure to unblock any attached scsi devices
1361 lpfc_register_remote_port(phba, ndlp);
1365 * if we added to Mapped list, but the remote port
1366 * registration failed or assigned a target id outside
1367 * our presentable range - move the node to the
1370 if (new_state == NLP_STE_MAPPED_NODE &&
1372 ndlp->rport->scsi_target_id == -1 ||
1373 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1374 spin_lock_irq(phba->host->host_lock);
1375 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1376 spin_unlock_irq(phba->host->host_lock);
1377 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1382 lpfc_nlp_set_state(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int state)
1384 int old_state = ndlp->nlp_state;
1385 static int list_id[] = {
1386 [NLP_STE_UNUSED_NODE] = NLP_UNUSED_LIST,
1387 [NLP_STE_PLOGI_ISSUE] = NLP_PLOGI_LIST,
1388 [NLP_STE_ADISC_ISSUE] = NLP_ADISC_LIST,
1389 [NLP_STE_REG_LOGIN_ISSUE] = NLP_REGLOGIN_LIST,
1390 [NLP_STE_PRLI_ISSUE] = NLP_PRLI_LIST,
1391 [NLP_STE_UNMAPPED_NODE] = NLP_UNMAPPED_LIST,
1392 [NLP_STE_MAPPED_NODE] = NLP_MAPPED_LIST,
1393 [NLP_STE_NPR_NODE] = NLP_NPR_LIST,
1396 if (old_state == NLP_STE_NPR_NODE &&
1397 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1398 state != NLP_STE_NPR_NODE)
1399 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1400 if (old_state == NLP_STE_UNMAPPED_NODE) {
1401 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1402 ndlp->nlp_type &= ~NLP_FC_NODE;
1405 if (old_state && !list_empty(&ndlp->nlp_listp))
1406 lpfc_nlp_counters(phba, old_state, -1);
1408 ndlp->nlp_state = state;
1409 lpfc_nlp_list(phba, ndlp, list_id[state]);
1410 lpfc_nlp_counters(phba, state, 1);
1412 lpfc_nlp_state_cleanup(phba, ndlp, old_state, state);
1416 lpfc_dequeue_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1418 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1419 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1420 spin_lock_irq(phba->host->host_lock);
1421 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1422 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1423 lpfc_delink_node(phba, ndlp);
1424 spin_unlock_irq(phba->host->host_lock);
1425 lpfc_nlp_state_cleanup(phba, ndlp, ndlp->nlp_state, 0);
1429 lpfc_drop_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1431 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1432 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1433 spin_lock_irq(phba->host->host_lock);
1434 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1435 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1436 lpfc_delink_node(phba, ndlp);
1437 spin_unlock_irq(phba->host->host_lock);
1442 * Start / ReStart rescue timer for Discovery / RSCN handling
1445 lpfc_set_disctmo(struct lpfc_hba * phba)
1449 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1450 /* For FAN, timeout should be greater then edtov */
1451 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1453 /* Normal discovery timeout should be > then ELS/CT timeout
1454 * FC spec states we need 3 * ratov for CT requests
1456 tmo = ((phba->fc_ratov * 3) + 3);
1459 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1460 spin_lock_irq(phba->host->host_lock);
1461 phba->fc_flag |= FC_DISC_TMO;
1462 spin_unlock_irq(phba->host->host_lock);
1464 /* Start Discovery Timer state <hba_state> */
1465 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1466 "%d:0247 Start Discovery Timer state x%x "
1467 "Data: x%x x%lx x%x x%x\n",
1469 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1470 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1476 * Cancel rescue timer for Discovery / RSCN handling
1479 lpfc_can_disctmo(struct lpfc_hba * phba)
1481 /* Turn off discovery timer if its running */
1482 if (phba->fc_flag & FC_DISC_TMO) {
1483 spin_lock_irq(phba->host->host_lock);
1484 phba->fc_flag &= ~FC_DISC_TMO;
1485 spin_unlock_irq(phba->host->host_lock);
1486 del_timer_sync(&phba->fc_disctmo);
1487 phba->work_hba_events &= ~WORKER_DISC_TMO;
1490 /* Cancel Discovery Timer state <hba_state> */
1491 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1492 "%d:0248 Cancel Discovery Timer state x%x "
1493 "Data: x%x x%x x%x\n",
1494 phba->brd_no, phba->hba_state, phba->fc_flag,
1495 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1501 * Check specified ring for outstanding IOCB on the SLI queue
1502 * Return true if iocb matches the specified nport
1505 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1506 struct lpfc_sli_ring * pring,
1507 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1509 struct lpfc_sli *psli;
1514 if (pring->ringno == LPFC_ELS_RING) {
1515 switch (icmd->ulpCommand) {
1516 case CMD_GEN_REQUEST64_CR:
1517 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1519 case CMD_ELS_REQUEST64_CR:
1520 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1522 case CMD_XMIT_ELS_RSP64_CX:
1523 if (iocb->context1 == (uint8_t *) ndlp)
1526 } else if (pring->ringno == psli->extra_ring) {
1528 } else if (pring->ringno == psli->fcp_ring) {
1529 /* Skip match check if waiting to relogin to FCP target */
1530 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1531 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1534 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1537 } else if (pring->ringno == psli->next_ring) {
1544 * Free resources / clean up outstanding I/Os
1545 * associated with nlp_rpi in the LPFC_NODELIST entry.
1548 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1550 LIST_HEAD(completions);
1551 struct lpfc_sli *psli;
1552 struct lpfc_sli_ring *pring;
1553 struct lpfc_iocbq *iocb, *next_iocb;
1558 * Everything that matches on txcmplq will be returned
1559 * by firmware with a no rpi error.
1562 rpi = ndlp->nlp_rpi;
1564 /* Now process each ring */
1565 for (i = 0; i < psli->num_rings; i++) {
1566 pring = &psli->ring[i];
1568 spin_lock_irq(phba->host->host_lock);
1569 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1572 * Check to see if iocb matches the nport we are
1575 if ((lpfc_check_sli_ndlp
1576 (phba, pring, iocb, ndlp))) {
1577 /* It matches, so deque and call compl
1579 list_move_tail(&iocb->list,
1584 spin_unlock_irq(phba->host->host_lock);
1589 while (!list_empty(&completions)) {
1590 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1591 list_del(&iocb->list);
1593 if (iocb->iocb_cmpl) {
1595 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1596 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1597 (iocb->iocb_cmpl) (phba, iocb, iocb);
1599 lpfc_sli_release_iocbq(phba, iocb);
1606 * Free rpi associated with LPFC_NODELIST entry.
1607 * This routine is called from lpfc_freenode(), when we are removing
1608 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1609 * LOGO that completes successfully, and we are waiting to PLOGI back
1610 * to the remote NPort. In addition, it is called after we receive
1611 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1612 * we are waiting to PLOGI back to the remote NPort.
1615 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1620 if (ndlp->nlp_rpi) {
1621 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1622 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1623 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1624 rc = lpfc_sli_issue_mbox
1625 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1626 if (rc == MBX_NOT_FINISHED)
1627 mempool_free( mbox, phba->mbox_mem_pool);
1629 lpfc_no_rpi(phba, ndlp);
1637 * Free resources associated with LPFC_NODELIST entry
1638 * so it can be freed.
1641 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1644 LPFC_MBOXQ_t *nextmb;
1645 struct lpfc_dmabuf *mp;
1647 /* Cleanup node for NPort <nlp_DID> */
1648 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1649 "%d:0900 Cleanup node for NPort x%x "
1650 "Data: x%x x%x x%x\n",
1651 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1652 ndlp->nlp_state, ndlp->nlp_rpi);
1654 lpfc_dequeue_node(phba, ndlp);
1656 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1657 if ((mb = phba->sli.mbox_active)) {
1658 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1659 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1660 mb->context2 = NULL;
1661 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1665 spin_lock_irq(phba->host->host_lock);
1666 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1667 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1668 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1669 mp = (struct lpfc_dmabuf *) (mb->context1);
1671 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1674 list_del(&mb->list);
1675 mempool_free(mb, phba->mbox_mem_pool);
1679 spin_unlock_irq(phba->host->host_lock);
1681 lpfc_els_abort(phba,ndlp);
1682 spin_lock_irq(phba->host->host_lock);
1683 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1684 spin_unlock_irq(phba->host->host_lock);
1686 ndlp->nlp_last_elscmd = 0;
1687 del_timer_sync(&ndlp->nlp_delayfunc);
1689 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1690 list_del_init(&ndlp->els_retry_evt.evt_listp);
1692 lpfc_unreg_rpi(phba, ndlp);
1698 * Check to see if we can free the nlp back to the freelist.
1699 * If we are in the middle of using the nlp in the discovery state
1700 * machine, defer the free till we reach the end of the state machine.
1703 lpfc_nlp_remove(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1705 struct lpfc_rport_data *rdata;
1707 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1708 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1711 lpfc_freenode(phba, ndlp);
1713 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1714 put_device(&ndlp->rport->dev);
1715 rdata = ndlp->rport->dd_data;
1716 rdata->pnode = NULL;
1722 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1728 if (did == Bcast_DID)
1731 if (ndlp->nlp_DID == 0) {
1735 /* First check for Direct match */
1736 if (ndlp->nlp_DID == did)
1739 /* Next check for area/domain identically equals 0 match */
1740 mydid.un.word = phba->fc_myDID;
1741 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1745 matchdid.un.word = did;
1746 ndlpdid.un.word = ndlp->nlp_DID;
1747 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1748 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1749 (mydid.un.b.area == matchdid.un.b.area)) {
1750 if ((ndlpdid.un.b.domain == 0) &&
1751 (ndlpdid.un.b.area == 0)) {
1752 if (ndlpdid.un.b.id)
1758 matchdid.un.word = ndlp->nlp_DID;
1759 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1760 (mydid.un.b.area == ndlpdid.un.b.area)) {
1761 if ((matchdid.un.b.domain == 0) &&
1762 (matchdid.un.b.area == 0)) {
1763 if (matchdid.un.b.id)
1771 /* Search for a nodelist entry on a specific list */
1772 struct lpfc_nodelist *
1773 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1775 struct lpfc_nodelist *ndlp;
1776 struct list_head *lists[]={&phba->fc_nlpunmap_list,
1777 &phba->fc_nlpmap_list,
1778 &phba->fc_plogi_list,
1779 &phba->fc_adisc_list,
1780 &phba->fc_reglogin_list,
1781 &phba->fc_prli_list,
1783 &phba->fc_unused_list};
1784 uint32_t search[]={NLP_SEARCH_UNMAPPED,
1788 NLP_SEARCH_REGLOGIN,
1795 spin_lock_irq(phba->host->host_lock);
1796 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
1797 if (!(order & search[i]))
1799 list_for_each_entry(ndlp, lists[i], nlp_listp) {
1800 if (lpfc_matchdid(phba, ndlp, did)) {
1801 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1802 ((uint32_t) ndlp->nlp_xri << 16) |
1803 ((uint32_t) ndlp->nlp_type << 8) |
1804 ((uint32_t) ndlp->nlp_rpi & 0xff));
1805 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1806 "%d:0929 FIND node DID "
1807 " Data: x%p x%x x%x x%x\n",
1809 ndlp, ndlp->nlp_DID,
1810 ndlp->nlp_flag, data1);
1811 spin_unlock_irq(phba->host->host_lock);
1816 spin_unlock_irq(phba->host->host_lock);
1818 /* FIND node did <did> NOT FOUND */
1819 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1820 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1821 phba->brd_no, did, order);
1825 struct lpfc_nodelist *
1826 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1828 struct lpfc_nodelist *ndlp;
1831 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1833 if ((phba->fc_flag & FC_RSCN_MODE) &&
1834 ((lpfc_rscn_payload_check(phba, did) == 0)))
1836 ndlp = (struct lpfc_nodelist *)
1837 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1840 lpfc_nlp_init(phba, ndlp, did);
1841 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1842 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1845 if (phba->fc_flag & FC_RSCN_MODE) {
1846 if (lpfc_rscn_payload_check(phba, did)) {
1847 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1849 /* Since this node is marked for discovery,
1850 * delay timeout is not needed.
1852 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1853 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1857 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1858 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1860 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1861 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1866 /* Build a list of nodes to discover based on the loopmap */
1868 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1871 uint32_t alpa, index;
1873 if (phba->hba_state <= LPFC_LINK_DOWN) {
1876 if (phba->fc_topology != TOPOLOGY_LOOP) {
1880 /* Check for loop map present or not */
1881 if (phba->alpa_map[0]) {
1882 for (j = 1; j <= phba->alpa_map[0]; j++) {
1883 alpa = phba->alpa_map[j];
1885 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1888 lpfc_setup_disc_node(phba, alpa);
1891 /* No alpamap, so try all alpa's */
1892 for (j = 0; j < FC_MAXLOOP; j++) {
1893 /* If cfg_scan_down is set, start from highest
1894 * ALPA (0xef) to lowest (0x1).
1896 if (phba->cfg_scan_down)
1899 index = FC_MAXLOOP - j - 1;
1900 alpa = lpfcAlpaArray[index];
1901 if ((phba->fc_myDID & 0xff) == alpa) {
1905 lpfc_setup_disc_node(phba, alpa);
1911 /* Start Link up / RSCN discovery on NPR list */
1913 lpfc_disc_start(struct lpfc_hba * phba)
1915 struct lpfc_sli *psli;
1917 struct lpfc_nodelist *ndlp, *next_ndlp;
1918 uint32_t did_changed, num_sent;
1919 uint32_t clear_la_pending;
1924 if (phba->hba_state <= LPFC_LINK_DOWN) {
1927 if (phba->hba_state == LPFC_CLEAR_LA)
1928 clear_la_pending = 1;
1930 clear_la_pending = 0;
1932 if (phba->hba_state < LPFC_HBA_READY) {
1933 phba->hba_state = LPFC_DISC_AUTH;
1935 lpfc_set_disctmo(phba);
1937 if (phba->fc_prevDID == phba->fc_myDID) {
1942 phba->fc_prevDID = phba->fc_myDID;
1943 phba->num_disc_nodes = 0;
1945 /* Start Discovery state <hba_state> */
1946 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1947 "%d:0202 Start Discovery hba state x%x "
1948 "Data: x%x x%x x%x\n",
1949 phba->brd_no, phba->hba_state, phba->fc_flag,
1950 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1952 /* If our did changed, we MUST do PLOGI */
1953 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1955 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1957 spin_lock_irq(phba->host->host_lock);
1958 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1959 spin_unlock_irq(phba->host->host_lock);
1964 /* First do ADISCs - if any */
1965 num_sent = lpfc_els_disc_adisc(phba);
1970 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
1971 /* If we get here, there is nothing to ADISC */
1972 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1973 phba->hba_state = LPFC_CLEAR_LA;
1974 lpfc_clear_la(phba, mbox);
1975 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1976 rc = lpfc_sli_issue_mbox(phba, mbox,
1977 (MBX_NOWAIT | MBX_STOP_IOCB));
1978 if (rc == MBX_NOT_FINISHED) {
1979 mempool_free( mbox, phba->mbox_mem_pool);
1980 lpfc_disc_flush_list(phba);
1981 psli->ring[(psli->extra_ring)].flag &=
1982 ~LPFC_STOP_IOCB_EVENT;
1983 psli->ring[(psli->fcp_ring)].flag &=
1984 ~LPFC_STOP_IOCB_EVENT;
1985 psli->ring[(psli->next_ring)].flag &=
1986 ~LPFC_STOP_IOCB_EVENT;
1987 phba->hba_state = LPFC_HBA_READY;
1991 /* Next do PLOGIs - if any */
1992 num_sent = lpfc_els_disc_plogi(phba);
1997 if (phba->fc_flag & FC_RSCN_MODE) {
1998 /* Check to see if more RSCNs came in while we
1999 * were processing this one.
2001 if ((phba->fc_rscn_id_cnt == 0) &&
2002 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2003 spin_lock_irq(phba->host->host_lock);
2004 phba->fc_flag &= ~FC_RSCN_MODE;
2005 spin_unlock_irq(phba->host->host_lock);
2007 lpfc_els_handle_rscn(phba);
2014 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2015 * ring the match the sppecified nodelist.
2018 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2020 LIST_HEAD(completions);
2021 struct lpfc_sli *psli;
2023 struct lpfc_iocbq *iocb, *next_iocb;
2024 struct lpfc_sli_ring *pring;
2027 pring = &psli->ring[LPFC_ELS_RING];
2029 /* Error matching iocb on txq or txcmplq
2030 * First check the txq.
2032 spin_lock_irq(phba->host->host_lock);
2033 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2034 if (iocb->context1 != ndlp) {
2038 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2039 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2041 list_move_tail(&iocb->list, &completions);
2046 /* Next check the txcmplq */
2047 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2048 if (iocb->context1 != ndlp) {
2052 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2053 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2054 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2057 spin_unlock_irq(phba->host->host_lock);
2059 while (!list_empty(&completions)) {
2060 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2061 list_del(&iocb->list);
2063 if (iocb->iocb_cmpl) {
2065 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2066 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2067 (iocb->iocb_cmpl) (phba, iocb, iocb);
2069 lpfc_sli_release_iocbq(phba, iocb);
2076 lpfc_disc_flush_list(struct lpfc_hba * phba)
2078 struct lpfc_nodelist *ndlp, *next_ndlp;
2080 if (phba->fc_plogi_cnt) {
2081 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2083 lpfc_free_tx(phba, ndlp);
2087 if (phba->fc_adisc_cnt) {
2088 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2090 lpfc_free_tx(phba, ndlp);
2097 /*****************************************************************************/
2099 * NAME: lpfc_disc_timeout
2101 * FUNCTION: Fibre Channel driver discovery timeout routine.
2103 * EXECUTION ENVIRONMENT: interrupt only
2111 /*****************************************************************************/
2113 lpfc_disc_timeout(unsigned long ptr)
2115 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2116 unsigned long flags = 0;
2118 if (unlikely(!phba))
2121 spin_lock_irqsave(phba->host->host_lock, flags);
2122 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2123 phba->work_hba_events |= WORKER_DISC_TMO;
2124 if (phba->work_wait)
2125 wake_up(phba->work_wait);
2127 spin_unlock_irqrestore(phba->host->host_lock, flags);
2132 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2134 struct lpfc_sli *psli;
2135 struct lpfc_nodelist *ndlp, *next_ndlp;
2136 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2137 int rc, clrlaerr = 0;
2139 if (unlikely(!phba))
2142 if (!(phba->fc_flag & FC_DISC_TMO))
2147 spin_lock_irq(phba->host->host_lock);
2148 phba->fc_flag &= ~FC_DISC_TMO;
2149 spin_unlock_irq(phba->host->host_lock);
2151 switch (phba->hba_state) {
2153 case LPFC_LOCAL_CFG_LINK:
2154 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2156 lpfc_printf_log(phba,
2159 "%d:0221 FAN timeout\n",
2162 /* Start discovery by sending FLOGI, clean up old rpis */
2163 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2165 if (ndlp->nlp_type & NLP_FABRIC) {
2166 /* Clean up the ndlp on Fabric connections */
2167 lpfc_drop_node(phba, ndlp);
2168 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2169 /* Fail outstanding IO now since device
2170 * is marked for PLOGI.
2172 lpfc_unreg_rpi(phba, ndlp);
2175 phba->hba_state = LPFC_FLOGI;
2176 lpfc_set_disctmo(phba);
2177 lpfc_initial_flogi(phba);
2181 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2182 /* Initial FLOGI timeout */
2183 lpfc_printf_log(phba,
2186 "%d:0222 Initial FLOGI timeout\n",
2189 /* Assume no Fabric and go on with discovery.
2190 * Check for outstanding ELS FLOGI to abort.
2193 /* FLOGI failed, so just use loop map to make discovery list */
2194 lpfc_disc_list_loopmap(phba);
2196 /* Start discovery */
2197 lpfc_disc_start(phba);
2200 case LPFC_FABRIC_CFG_LINK:
2201 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2203 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2204 "%d:0223 Timeout while waiting for NameServer "
2205 "login\n", phba->brd_no);
2207 /* Next look for NameServer ndlp */
2208 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2211 /* Start discovery */
2212 lpfc_disc_start(phba);
2216 /* Check for wait for NameServer Rsp timeout */
2217 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2218 "%d:0224 NameServer Query timeout "
2221 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2223 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2226 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2227 /* Try it one more time */
2228 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2232 phba->fc_ns_retry = 0;
2235 /* Nothing to authenticate, so CLEAR_LA right now */
2236 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2239 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2240 "%d:0226 Device Discovery "
2241 "completion error\n",
2243 phba->hba_state = LPFC_HBA_ERROR;
2247 phba->hba_state = LPFC_CLEAR_LA;
2248 lpfc_clear_la(phba, clearlambox);
2249 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2250 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2251 (MBX_NOWAIT | MBX_STOP_IOCB));
2252 if (rc == MBX_NOT_FINISHED) {
2253 mempool_free(clearlambox, phba->mbox_mem_pool);
2258 /* Setup and issue mailbox INITIALIZE LINK command */
2259 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2260 if (!initlinkmbox) {
2261 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2262 "%d:0206 Device Discovery "
2263 "completion error\n",
2265 phba->hba_state = LPFC_HBA_ERROR;
2269 lpfc_linkdown(phba);
2270 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2271 phba->cfg_link_speed);
2272 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2273 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2274 (MBX_NOWAIT | MBX_STOP_IOCB));
2275 lpfc_set_loopback_flag(phba);
2276 if (rc == MBX_NOT_FINISHED)
2277 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2281 case LPFC_DISC_AUTH:
2282 /* Node Authentication timeout */
2283 lpfc_printf_log(phba,
2286 "%d:0227 Node Authentication timeout\n",
2288 lpfc_disc_flush_list(phba);
2289 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2292 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2293 "%d:0207 Device Discovery "
2294 "completion error\n",
2296 phba->hba_state = LPFC_HBA_ERROR;
2299 phba->hba_state = LPFC_CLEAR_LA;
2300 lpfc_clear_la(phba, clearlambox);
2301 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2302 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2303 (MBX_NOWAIT | MBX_STOP_IOCB));
2304 if (rc == MBX_NOT_FINISHED) {
2305 mempool_free(clearlambox, phba->mbox_mem_pool);
2311 /* CLEAR LA timeout */
2312 lpfc_printf_log(phba,
2315 "%d:0228 CLEAR LA timeout\n",
2320 case LPFC_HBA_READY:
2321 if (phba->fc_flag & FC_RSCN_MODE) {
2322 lpfc_printf_log(phba,
2325 "%d:0231 RSCN timeout Data: x%x x%x\n",
2327 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2329 /* Cleanup any outstanding ELS commands */
2330 lpfc_els_flush_cmd(phba);
2332 lpfc_els_flush_rscn(phba);
2333 lpfc_disc_flush_list(phba);
2339 lpfc_disc_flush_list(phba);
2340 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2341 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2342 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2343 phba->hba_state = LPFC_HBA_READY;
2350 * This routine handles processing a NameServer REG_LOGIN mailbox
2351 * command upon completion. It is setup in the LPFC_MBOXQ
2352 * as the completion routine when the command is
2353 * handed off to the SLI layer.
2356 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2358 struct lpfc_sli *psli;
2360 struct lpfc_dmabuf *mp;
2361 struct lpfc_nodelist *ndlp;
2366 ndlp = (struct lpfc_nodelist *) pmb->context2;
2367 mp = (struct lpfc_dmabuf *) (pmb->context1);
2369 pmb->context1 = NULL;
2371 ndlp->nlp_rpi = mb->un.varWords[0];
2372 ndlp->nlp_type |= NLP_FABRIC;
2373 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
2375 /* Start issuing Fabric-Device Management Interface (FDMI)
2376 * command to 0xfffffa (FDMI well known port)
2378 if (phba->cfg_fdmi_on == 1) {
2379 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2382 * Delay issuing FDMI command if fdmi-on=2
2383 * (supporting RPA/hostnmae)
2385 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2388 /* Mailbox took a reference to the node */
2390 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2392 mempool_free(pmb, phba->mbox_mem_pool);
2398 * This routine looks up the ndlp lists
2399 * for the given RPI. If rpi found
2400 * it return the node list pointer
2403 struct lpfc_nodelist *
2404 __lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2406 struct lpfc_nodelist *ndlp;
2407 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2408 &phba->fc_nlpmap_list,
2409 &phba->fc_plogi_list,
2410 &phba->fc_adisc_list,
2411 &phba->fc_reglogin_list};
2414 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2415 list_for_each_entry(ndlp, lists[i], nlp_listp)
2416 if (ndlp->nlp_rpi == rpi) {
2422 struct lpfc_nodelist *
2423 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2425 struct lpfc_nodelist *ndlp;
2427 spin_lock_irq(phba->host->host_lock);
2428 ndlp = __lpfc_findnode_rpi(phba, rpi);
2429 spin_unlock_irq(phba->host->host_lock);
2434 * This routine looks up the ndlp lists
2435 * for the given WWPN. If WWPN found
2436 * it return the node list pointer
2439 struct lpfc_nodelist *
2440 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2441 struct lpfc_name * wwpn)
2443 struct lpfc_nodelist *ndlp;
2444 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2445 &phba->fc_nlpmap_list,
2447 &phba->fc_plogi_list,
2448 &phba->fc_adisc_list,
2449 &phba->fc_reglogin_list,
2450 &phba->fc_prli_list};
2451 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2456 NLP_SEARCH_REGLOGIN,
2460 spin_lock_irq(phba->host->host_lock);
2461 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2462 if (!(order & search[i]))
2464 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2465 if (memcmp(&ndlp->nlp_portname, wwpn,
2466 sizeof(struct lpfc_name)) == 0) {
2467 spin_unlock_irq(phba->host->host_lock);
2472 spin_unlock_irq(phba->host->host_lock);
2477 lpfc_nlp_init(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, uint32_t did)
2479 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2480 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2481 init_timer(&ndlp->nlp_delayfunc);
2482 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2483 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2484 ndlp->nlp_DID = did;
2485 ndlp->nlp_phba = phba;
2486 ndlp->nlp_sid = NLP_NO_SID;
2487 kref_init(&ndlp->kref);
2492 lpfc_nlp_release(struct kref *kref)
2494 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2496 lpfc_nlp_remove(ndlp->nlp_phba, ndlp);
2497 mempool_free(ndlp, ndlp->nlp_phba->nlp_mem_pool);
2500 struct lpfc_nodelist *
2501 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2504 kref_get(&ndlp->kref);
2509 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2511 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;