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);
167 lpfc_work_list_done(struct lpfc_hba * phba)
169 struct lpfc_work_evt *evtp = NULL;
170 struct lpfc_nodelist *ndlp;
173 spin_lock_irq(phba->host->host_lock);
174 while(!list_empty(&phba->work_list)) {
175 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
177 spin_unlock_irq(phba->host->host_lock);
180 case LPFC_EVT_ELS_RETRY:
181 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
182 lpfc_els_retry_delay_handler(ndlp);
185 case LPFC_EVT_ONLINE:
186 if (phba->hba_state < LPFC_LINK_DOWN)
187 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
189 *(int *)(evtp->evt_arg1) = 0;
190 complete((struct completion *)(evtp->evt_arg2));
192 case LPFC_EVT_OFFLINE_PREP:
193 if (phba->hba_state >= LPFC_LINK_DOWN)
194 lpfc_offline_prep(phba);
195 *(int *)(evtp->evt_arg1) = 0;
196 complete((struct completion *)(evtp->evt_arg2));
198 case LPFC_EVT_OFFLINE:
200 lpfc_sli_brdrestart(phba);
201 *(int *)(evtp->evt_arg1) =
202 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
203 lpfc_unblock_mgmt_io(phba);
204 complete((struct completion *)(evtp->evt_arg2));
206 case LPFC_EVT_WARM_START:
208 lpfc_reset_barrier(phba);
209 lpfc_sli_brdreset(phba);
210 lpfc_hba_down_post(phba);
211 *(int *)(evtp->evt_arg1) =
212 lpfc_sli_brdready(phba, HS_MBRDY);
213 lpfc_unblock_mgmt_io(phba);
214 complete((struct completion *)(evtp->evt_arg2));
218 *(int *)(evtp->evt_arg1)
219 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
220 lpfc_unblock_mgmt_io(phba);
221 complete((struct completion *)(evtp->evt_arg2));
226 spin_lock_irq(phba->host->host_lock);
228 spin_unlock_irq(phba->host->host_lock);
233 lpfc_work_done(struct lpfc_hba * phba)
235 struct lpfc_sli_ring *pring;
239 uint32_t work_hba_events;
241 spin_lock_irq(phba->host->host_lock);
242 ha_copy = phba->work_ha;
244 work_hba_events=phba->work_hba_events;
245 spin_unlock_irq(phba->host->host_lock);
247 if (ha_copy & HA_ERATT)
248 lpfc_handle_eratt(phba);
250 if (ha_copy & HA_MBATT)
251 lpfc_sli_handle_mb_event(phba);
253 if (ha_copy & HA_LATT)
254 lpfc_handle_latt(phba);
256 if (work_hba_events & WORKER_DISC_TMO)
257 lpfc_disc_timeout_handler(phba);
259 if (work_hba_events & WORKER_ELS_TMO)
260 lpfc_els_timeout_handler(phba);
262 if (work_hba_events & WORKER_MBOX_TMO)
263 lpfc_mbox_timeout_handler(phba);
265 if (work_hba_events & WORKER_FDMI_TMO)
266 lpfc_fdmi_tmo_handler(phba);
268 spin_lock_irq(phba->host->host_lock);
269 phba->work_hba_events &= ~work_hba_events;
270 spin_unlock_irq(phba->host->host_lock);
272 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
273 pring = &phba->sli.ring[i];
274 if ((ha_copy & HA_RXATT)
275 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
276 if (pring->flag & LPFC_STOP_IOCB_MASK) {
277 pring->flag |= LPFC_DEFERRED_RING_EVENT;
279 lpfc_sli_handle_slow_ring_event(phba, pring,
282 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
285 * Turn on Ring interrupts
287 spin_lock_irq(phba->host->host_lock);
288 control = readl(phba->HCregaddr);
289 control |= (HC_R0INT_ENA << i);
290 writel(control, phba->HCregaddr);
291 readl(phba->HCregaddr); /* flush */
292 spin_unlock_irq(phba->host->host_lock);
296 lpfc_work_list_done (phba);
301 check_work_wait_done(struct lpfc_hba *phba) {
303 spin_lock_irq(phba->host->host_lock);
305 phba->work_hba_events ||
306 (!list_empty(&phba->work_list)) ||
307 kthread_should_stop()) {
308 spin_unlock_irq(phba->host->host_lock);
311 spin_unlock_irq(phba->host->host_lock);
317 lpfc_do_work(void *p)
319 struct lpfc_hba *phba = p;
321 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
323 set_user_nice(current, -20);
324 phba->work_wait = &work_waitq;
328 rc = wait_event_interruptible(work_waitq,
329 check_work_wait_done(phba));
332 if (kthread_should_stop())
335 lpfc_work_done(phba);
338 phba->work_wait = NULL;
343 * This is only called to handle FC worker events. Since this a rare
344 * occurance, we allocate a struct lpfc_work_evt structure here instead of
345 * embedding it in the IOCB.
348 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
351 struct lpfc_work_evt *evtp;
354 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
355 * be queued to worker thread for processing
357 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
361 evtp->evt_arg1 = arg1;
362 evtp->evt_arg2 = arg2;
365 spin_lock_irq(phba->host->host_lock);
366 list_add_tail(&evtp->evt_listp, &phba->work_list);
368 wake_up(phba->work_wait);
369 spin_unlock_irq(phba->host->host_lock);
375 lpfc_linkdown(struct lpfc_hba * phba)
377 struct lpfc_sli *psli;
378 struct lpfc_nodelist *ndlp, *next_ndlp;
379 struct list_head *listp, *node_list[7];
384 /* sysfs or selective reset may call this routine to clean up */
385 if (phba->hba_state >= LPFC_LINK_DOWN) {
386 if (phba->hba_state == LPFC_LINK_DOWN)
389 spin_lock_irq(phba->host->host_lock);
390 phba->hba_state = LPFC_LINK_DOWN;
391 spin_unlock_irq(phba->host->host_lock);
394 fc_host_post_event(phba->host, fc_get_event_number(),
395 FCH_EVT_LINKDOWN, 0);
397 /* Clean up any firmware default rpi's */
398 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
399 lpfc_unreg_did(phba, 0xffffffff, mb);
400 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
401 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
402 == MBX_NOT_FINISHED) {
403 mempool_free( mb, phba->mbox_mem_pool);
407 /* Cleanup any outstanding RSCN activity */
408 lpfc_els_flush_rscn(phba);
410 /* Cleanup any outstanding ELS commands */
411 lpfc_els_flush_cmd(phba);
413 /* Issue a LINK DOWN event to all nodes */
414 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
415 node_list[1] = &phba->fc_nlpmap_list;
416 node_list[2] = &phba->fc_nlpunmap_list;
417 node_list[3] = &phba->fc_prli_list;
418 node_list[4] = &phba->fc_reglogin_list;
419 node_list[5] = &phba->fc_adisc_list;
420 node_list[6] = &phba->fc_plogi_list;
421 for (i = 0; i < 7; i++) {
422 listp = node_list[i];
423 if (list_empty(listp))
426 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
428 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
429 NLP_EVT_DEVICE_RECOVERY);
434 /* free any ndlp's on unused list */
435 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
437 lpfc_drop_node(phba, ndlp);
439 /* Setup myDID for link up if we are in pt2pt mode */
440 if (phba->fc_flag & FC_PT2PT) {
442 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
443 lpfc_config_link(phba, mb);
444 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
445 if (lpfc_sli_issue_mbox
446 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
447 == MBX_NOT_FINISHED) {
448 mempool_free( mb, phba->mbox_mem_pool);
451 spin_lock_irq(phba->host->host_lock);
452 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
453 spin_unlock_irq(phba->host->host_lock);
455 spin_lock_irq(phba->host->host_lock);
456 phba->fc_flag &= ~FC_LBIT;
457 spin_unlock_irq(phba->host->host_lock);
459 /* Turn off discovery timer if its running */
460 lpfc_can_disctmo(phba);
462 /* Must process IOCBs on all rings to handle ABORTed I/Os */
467 lpfc_linkup(struct lpfc_hba * phba)
469 struct lpfc_nodelist *ndlp, *next_ndlp;
470 struct list_head *listp, *node_list[7];
473 fc_host_post_event(phba->host, fc_get_event_number(),
476 spin_lock_irq(phba->host->host_lock);
477 phba->hba_state = LPFC_LINK_UP;
478 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
479 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
480 phba->fc_flag |= FC_NDISC_ACTIVE;
481 phba->fc_ns_retry = 0;
482 spin_unlock_irq(phba->host->host_lock);
485 node_list[0] = &phba->fc_plogi_list;
486 node_list[1] = &phba->fc_adisc_list;
487 node_list[2] = &phba->fc_reglogin_list;
488 node_list[3] = &phba->fc_prli_list;
489 node_list[4] = &phba->fc_nlpunmap_list;
490 node_list[5] = &phba->fc_nlpmap_list;
491 node_list[6] = &phba->fc_npr_list;
492 for (i = 0; i < 7; i++) {
493 listp = node_list[i];
494 if (list_empty(listp))
497 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
498 if (phba->fc_flag & FC_LBIT) {
499 if (ndlp->nlp_type & NLP_FABRIC) {
500 /* On Linkup its safe to clean up the
501 * ndlp from Fabric connections.
503 lpfc_nlp_set_state(phba, ndlp,
504 NLP_STE_UNUSED_NODE);
505 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
506 /* Fail outstanding IO now since device
507 * is marked for PLOGI.
509 lpfc_unreg_rpi(phba, ndlp);
515 /* free any ndlp's on unused list */
516 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
518 lpfc_drop_node(phba, ndlp);
524 * This routine handles processing a CLEAR_LA mailbox
525 * command upon completion. It is setup in the LPFC_MBOXQ
526 * as the completion routine when the command is
527 * handed off to the SLI layer.
530 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
532 struct lpfc_sli *psli;
538 /* Since we don't do discovery right now, turn these off here */
539 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
540 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
541 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
543 /* Check for error */
544 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
545 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
546 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
547 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
549 phba->brd_no, mb->mbxStatus, phba->hba_state);
551 phba->hba_state = LPFC_HBA_ERROR;
555 if (phba->fc_flag & FC_ABORT_DISCOVERY)
558 phba->num_disc_nodes = 0;
559 /* go thru NPR list and issue ELS PLOGIs */
560 if (phba->fc_npr_cnt) {
561 lpfc_els_disc_plogi(phba);
564 if (!phba->num_disc_nodes) {
565 spin_lock_irq(phba->host->host_lock);
566 phba->fc_flag &= ~FC_NDISC_ACTIVE;
567 spin_unlock_irq(phba->host->host_lock);
570 phba->hba_state = LPFC_HBA_READY;
573 /* Device Discovery completes */
574 lpfc_printf_log(phba,
577 "%d:0225 Device Discovery completes\n",
580 mempool_free( pmb, phba->mbox_mem_pool);
582 spin_lock_irq(phba->host->host_lock);
583 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
584 if (phba->fc_flag & FC_ESTABLISH_LINK) {
585 phba->fc_flag &= ~FC_ESTABLISH_LINK;
587 spin_unlock_irq(phba->host->host_lock);
589 del_timer_sync(&phba->fc_estabtmo);
591 lpfc_can_disctmo(phba);
593 /* turn on Link Attention interrupts */
594 spin_lock_irq(phba->host->host_lock);
595 psli->sli_flag |= LPFC_PROCESS_LA;
596 control = readl(phba->HCregaddr);
597 control |= HC_LAINT_ENA;
598 writel(control, phba->HCregaddr);
599 readl(phba->HCregaddr); /* flush */
600 spin_unlock_irq(phba->host->host_lock);
606 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
608 struct lpfc_sli *psli = &phba->sli;
611 if (pmb->mb.mbxStatus)
614 mempool_free(pmb, phba->mbox_mem_pool);
616 if (phba->fc_topology == TOPOLOGY_LOOP &&
617 phba->fc_flag & FC_PUBLIC_LOOP &&
618 !(phba->fc_flag & FC_LBIT)) {
619 /* Need to wait for FAN - use discovery timer
620 * for timeout. hba_state is identically
621 * LPFC_LOCAL_CFG_LINK while waiting for FAN
623 lpfc_set_disctmo(phba);
627 /* Start discovery by sending a FLOGI. hba_state is identically
628 * LPFC_FLOGI while waiting for FLOGI cmpl
630 phba->hba_state = LPFC_FLOGI;
631 lpfc_set_disctmo(phba);
632 lpfc_initial_flogi(phba);
636 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
637 "%d:0306 CONFIG_LINK mbxStatus error x%x "
639 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
643 phba->hba_state = LPFC_HBA_ERROR;
645 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
646 "%d:0200 CONFIG_LINK bad hba state x%x\n",
647 phba->brd_no, phba->hba_state);
649 lpfc_clear_la(phba, pmb);
650 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
651 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
652 if (rc == MBX_NOT_FINISHED) {
653 mempool_free(pmb, phba->mbox_mem_pool);
654 lpfc_disc_flush_list(phba);
655 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
656 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
657 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
658 phba->hba_state = LPFC_HBA_READY;
664 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
666 struct lpfc_sli *psli = &phba->sli;
667 MAILBOX_t *mb = &pmb->mb;
668 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
671 /* Check for error */
673 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
674 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
675 "%d:0319 READ_SPARAM mbxStatus error x%x "
677 phba->brd_no, mb->mbxStatus, phba->hba_state);
680 phba->hba_state = LPFC_HBA_ERROR;
684 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
685 sizeof (struct serv_parm));
686 if (phba->cfg_soft_wwnn)
687 u64_to_wwn(phba->cfg_soft_wwnn, phba->fc_sparam.nodeName.u.wwn);
688 if (phba->cfg_soft_wwpn)
689 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
690 memcpy((uint8_t *) & phba->fc_nodename,
691 (uint8_t *) & phba->fc_sparam.nodeName,
692 sizeof (struct lpfc_name));
693 memcpy((uint8_t *) & phba->fc_portname,
694 (uint8_t *) & phba->fc_sparam.portName,
695 sizeof (struct lpfc_name));
696 lpfc_mbuf_free(phba, mp->virt, mp->phys);
698 mempool_free( pmb, phba->mbox_mem_pool);
702 pmb->context1 = NULL;
703 lpfc_mbuf_free(phba, mp->virt, mp->phys);
705 if (phba->hba_state != LPFC_CLEAR_LA) {
706 lpfc_clear_la(phba, pmb);
707 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
708 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
709 == MBX_NOT_FINISHED) {
710 mempool_free( pmb, phba->mbox_mem_pool);
711 lpfc_disc_flush_list(phba);
712 psli->ring[(psli->extra_ring)].flag &=
713 ~LPFC_STOP_IOCB_EVENT;
714 psli->ring[(psli->fcp_ring)].flag &=
715 ~LPFC_STOP_IOCB_EVENT;
716 psli->ring[(psli->next_ring)].flag &=
717 ~LPFC_STOP_IOCB_EVENT;
718 phba->hba_state = LPFC_HBA_READY;
721 mempool_free( pmb, phba->mbox_mem_pool);
727 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
730 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
731 struct lpfc_dmabuf *mp;
734 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
735 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
737 spin_lock_irq(phba->host->host_lock);
738 switch (la->UlnkSpeed) {
740 phba->fc_linkspeed = LA_1GHZ_LINK;
743 phba->fc_linkspeed = LA_2GHZ_LINK;
746 phba->fc_linkspeed = LA_4GHZ_LINK;
749 phba->fc_linkspeed = LA_UNKNW_LINK;
753 phba->fc_topology = la->topology;
755 if (phba->fc_topology == TOPOLOGY_LOOP) {
756 /* Get Loop Map information */
759 phba->fc_flag |= FC_LBIT;
761 phba->fc_myDID = la->granted_AL_PA;
762 i = la->un.lilpBde64.tus.f.bdeSize;
765 phba->alpa_map[0] = 0;
767 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
778 numalpa = phba->alpa_map[0];
780 while (j < numalpa) {
781 memset(un.pamap, 0, 16);
782 for (k = 1; j < numalpa; k++) {
784 phba->alpa_map[j + 1];
789 /* Link Up Event ALPA map */
790 lpfc_printf_log(phba,
793 "%d:1304 Link Up Event "
794 "ALPA map Data: x%x "
797 un.pa.wd1, un.pa.wd2,
798 un.pa.wd3, un.pa.wd4);
803 phba->fc_myDID = phba->fc_pref_DID;
804 phba->fc_flag |= FC_LBIT;
806 spin_unlock_irq(phba->host->host_lock);
810 lpfc_read_sparam(phba, sparam_mbox);
811 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
812 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
813 (MBX_NOWAIT | MBX_STOP_IOCB));
814 if (rc == MBX_NOT_FINISHED) {
815 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
816 lpfc_mbuf_free(phba, mp->virt, mp->phys);
818 mempool_free(sparam_mbox, phba->mbox_mem_pool);
820 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
826 phba->hba_state = LPFC_LOCAL_CFG_LINK;
827 lpfc_config_link(phba, cfglink_mbox);
828 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
829 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
830 (MBX_NOWAIT | MBX_STOP_IOCB));
831 if (rc == MBX_NOT_FINISHED)
832 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
837 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
839 struct lpfc_sli *psli = &phba->sli;
843 /* turn on Link Attention interrupts - no CLEAR_LA needed */
844 spin_lock_irq(phba->host->host_lock);
845 psli->sli_flag |= LPFC_PROCESS_LA;
846 control = readl(phba->HCregaddr);
847 control |= HC_LAINT_ENA;
848 writel(control, phba->HCregaddr);
849 readl(phba->HCregaddr); /* flush */
850 spin_unlock_irq(phba->host->host_lock);
854 * This routine handles processing a READ_LA mailbox
855 * command upon completion. It is setup in the LPFC_MBOXQ
856 * as the completion routine when the command is
857 * handed off to the SLI layer.
860 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
863 MAILBOX_t *mb = &pmb->mb;
864 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
866 /* Check for error */
868 lpfc_printf_log(phba,
871 "%d:1307 READ_LA mbox error x%x state x%x\n",
873 mb->mbxStatus, phba->hba_state);
874 lpfc_mbx_issue_link_down(phba);
875 phba->hba_state = LPFC_HBA_ERROR;
876 goto lpfc_mbx_cmpl_read_la_free_mbuf;
879 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
881 memcpy(&phba->alpa_map[0], mp->virt, 128);
883 spin_lock_irq(phba->host->host_lock);
885 phba->fc_flag |= FC_BYPASSED_MODE;
887 phba->fc_flag &= ~FC_BYPASSED_MODE;
888 spin_unlock_irq(phba->host->host_lock);
890 if (((phba->fc_eventTag + 1) < la->eventTag) ||
891 (phba->fc_eventTag == la->eventTag)) {
892 phba->fc_stat.LinkMultiEvent++;
893 if (la->attType == AT_LINK_UP) {
894 if (phba->fc_eventTag != 0)
899 phba->fc_eventTag = la->eventTag;
901 if (la->attType == AT_LINK_UP) {
902 phba->fc_stat.LinkUp++;
903 if (phba->fc_flag & FC_LOOPBACK_MODE) {
904 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
905 "%d:1306 Link Up Event in loop back mode "
906 "x%x received Data: x%x x%x x%x x%x\n",
907 phba->brd_no, la->eventTag, phba->fc_eventTag,
908 la->granted_AL_PA, la->UlnkSpeed,
911 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
912 "%d:1303 Link Up Event x%x received "
913 "Data: x%x x%x x%x x%x\n",
914 phba->brd_no, la->eventTag, phba->fc_eventTag,
915 la->granted_AL_PA, la->UlnkSpeed,
918 lpfc_mbx_process_link_up(phba, la);
920 phba->fc_stat.LinkDown++;
921 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
922 "%d:1305 Link Down Event x%x received "
923 "Data: x%x x%x x%x\n",
924 phba->brd_no, la->eventTag, phba->fc_eventTag,
925 phba->hba_state, phba->fc_flag);
926 lpfc_mbx_issue_link_down(phba);
929 lpfc_mbx_cmpl_read_la_free_mbuf:
930 lpfc_mbuf_free(phba, mp->virt, mp->phys);
932 mempool_free(pmb, phba->mbox_mem_pool);
937 * This routine handles processing a REG_LOGIN mailbox
938 * command upon completion. It is setup in the LPFC_MBOXQ
939 * as the completion routine when the command is
940 * handed off to the SLI layer.
943 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
945 struct lpfc_sli *psli;
947 struct lpfc_dmabuf *mp;
948 struct lpfc_nodelist *ndlp;
953 ndlp = (struct lpfc_nodelist *) pmb->context2;
954 mp = (struct lpfc_dmabuf *) (pmb->context1);
956 pmb->context1 = NULL;
958 /* Good status, call state machine */
959 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
960 lpfc_mbuf_free(phba, mp->virt, mp->phys);
962 mempool_free( pmb, phba->mbox_mem_pool);
968 * This routine handles processing a Fabric REG_LOGIN mailbox
969 * command upon completion. It is setup in the LPFC_MBOXQ
970 * as the completion routine when the command is
971 * handed off to the SLI layer.
974 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
976 struct lpfc_sli *psli;
978 struct lpfc_dmabuf *mp;
979 struct lpfc_nodelist *ndlp;
980 struct lpfc_nodelist *ndlp_fdmi;
986 ndlp = (struct lpfc_nodelist *) pmb->context2;
987 mp = (struct lpfc_dmabuf *) (pmb->context1);
990 lpfc_mbuf_free(phba, mp->virt, mp->phys);
992 mempool_free( pmb, phba->mbox_mem_pool);
993 mempool_free( ndlp, phba->nlp_mem_pool);
995 /* FLOGI failed, so just use loop map to make discovery list */
996 lpfc_disc_list_loopmap(phba);
998 /* Start discovery */
999 lpfc_disc_start(phba);
1003 pmb->context1 = NULL;
1005 ndlp->nlp_rpi = mb->un.varWords[0];
1006 ndlp->nlp_type |= NLP_FABRIC;
1007 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1009 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
1010 /* This NPort has been assigned an NPort_ID by the fabric as a
1011 * result of the completed fabric login. Issue a State Change
1012 * Registration (SCR) ELS request to the fabric controller
1013 * (SCR_DID) so that this NPort gets RSCN events from the
1016 lpfc_issue_els_scr(phba, SCR_DID, 0);
1018 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
1020 /* Allocate a new node instance. If the pool is empty,
1021 * start the discovery process and skip the Nameserver
1022 * login process. This is attempted again later on.
1023 * Otherwise, issue a Port Login (PLOGI) to NameServer.
1025 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1027 lpfc_disc_start(phba);
1028 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1030 mempool_free( pmb, phba->mbox_mem_pool);
1033 lpfc_nlp_init(phba, ndlp, NameServer_DID);
1034 ndlp->nlp_type |= NLP_FABRIC;
1037 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1038 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
1039 if (phba->cfg_fdmi_on) {
1040 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1043 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
1044 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1045 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
1046 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
1051 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1053 mempool_free( pmb, phba->mbox_mem_pool);
1058 * This routine handles processing a NameServer REG_LOGIN mailbox
1059 * command upon completion. It is setup in the LPFC_MBOXQ
1060 * as the completion routine when the command is
1061 * handed off to the SLI layer.
1064 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1066 struct lpfc_sli *psli;
1068 struct lpfc_dmabuf *mp;
1069 struct lpfc_nodelist *ndlp;
1074 ndlp = (struct lpfc_nodelist *) pmb->context2;
1075 mp = (struct lpfc_dmabuf *) (pmb->context1);
1077 if (mb->mbxStatus) {
1078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1080 mempool_free(pmb, phba->mbox_mem_pool);
1081 lpfc_drop_node(phba, ndlp);
1083 /* RegLogin failed, so just use loop map to make discovery
1085 lpfc_disc_list_loopmap(phba);
1087 /* Start discovery */
1088 lpfc_disc_start(phba);
1092 pmb->context1 = NULL;
1094 ndlp->nlp_rpi = mb->un.varWords[0];
1095 ndlp->nlp_type |= NLP_FABRIC;
1096 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1098 if (phba->hba_state < LPFC_HBA_READY) {
1099 /* Link up discovery requires Fabrib registration. */
1100 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1101 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1102 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1103 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFF_ID);
1106 phba->fc_ns_retry = 0;
1107 /* Good status, issue CT Request to NameServer */
1108 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1109 /* Cannot issue NameServer Query, so finish up discovery */
1110 lpfc_disc_start(phba);
1113 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1115 mempool_free( pmb, phba->mbox_mem_pool);
1121 lpfc_register_remote_port(struct lpfc_hba * phba,
1122 struct lpfc_nodelist * ndlp)
1124 struct fc_rport *rport;
1125 struct lpfc_rport_data *rdata;
1126 struct fc_rport_identifiers rport_ids;
1128 /* Remote port has reappeared. Re-register w/ FC transport */
1129 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1130 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1131 rport_ids.port_id = ndlp->nlp_DID;
1132 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1134 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1136 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1137 "Warning: fc_remote_port_add failed\n");
1141 /* initialize static port data */
1142 rport->maxframe_size = ndlp->nlp_maxframe;
1143 rport->supported_classes = ndlp->nlp_class_sup;
1144 rdata = rport->dd_data;
1145 rdata->pnode = ndlp;
1147 if (ndlp->nlp_type & NLP_FCP_TARGET)
1148 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1149 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1150 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1153 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1154 fc_remote_port_rolechg(rport, rport_ids.roles);
1156 if ((rport->scsi_target_id != -1) &&
1157 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1158 ndlp->nlp_sid = rport->scsi_target_id;
1165 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1166 struct lpfc_nodelist * ndlp)
1168 struct fc_rport *rport = ndlp->rport;
1169 struct lpfc_rport_data *rdata = rport->dd_data;
1171 if (rport->scsi_target_id == -1) {
1173 rdata->pnode = NULL;
1176 fc_remote_port_delete(rport);
1182 lpfc_nlp_counters(struct lpfc_hba *phba, int state, int count)
1185 case NLP_STE_UNUSED_NODE:
1186 phba->fc_unused_cnt += count;
1188 case NLP_STE_PLOGI_ISSUE:
1189 phba->fc_plogi_cnt += count;
1191 case NLP_STE_ADISC_ISSUE:
1192 phba->fc_adisc_cnt += count;
1194 case NLP_STE_REG_LOGIN_ISSUE:
1195 phba->fc_reglogin_cnt += count;
1197 case NLP_STE_PRLI_ISSUE:
1198 phba->fc_prli_cnt += count;
1200 case NLP_STE_UNMAPPED_NODE:
1201 phba->fc_unmap_cnt += count;
1203 case NLP_STE_MAPPED_NODE:
1204 phba->fc_map_cnt += count;
1206 case NLP_STE_NPR_NODE:
1207 phba->fc_npr_cnt += count;
1213 lpfc_delink_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1215 switch (ndlp->nlp_flag & NLP_LIST_MASK) {
1216 case NLP_UNUSED_LIST:
1217 list_del_init(&ndlp->nlp_listp);
1219 case NLP_PLOGI_LIST:
1220 list_del_init(&ndlp->nlp_listp);
1222 case NLP_ADISC_LIST:
1223 list_del_init(&ndlp->nlp_listp);
1225 case NLP_REGLOGIN_LIST:
1226 list_del_init(&ndlp->nlp_listp);
1229 list_del_init(&ndlp->nlp_listp);
1231 case NLP_UNMAPPED_LIST:
1232 list_del_init(&ndlp->nlp_listp);
1234 case NLP_MAPPED_LIST:
1235 list_del_init(&ndlp->nlp_listp);
1238 list_del_init(&ndlp->nlp_listp);
1242 ndlp->nlp_flag &= ~NLP_LIST_MASK;
1246 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1248 struct lpfc_sli *psli;
1251 /* Sanity check to ensure we are not moving to / from the same list */
1252 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1255 spin_lock_irq(phba->host->host_lock);
1256 lpfc_delink_node(phba, nlp);
1258 /* Add NPort <did> to <num> list */
1259 lpfc_printf_log(phba,
1262 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1264 nlp->nlp_DID, list, nlp->nlp_flag);
1267 case NLP_UNUSED_LIST:
1268 nlp->nlp_flag |= list;
1269 /* Put it at the end of the unused list */
1270 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1272 case NLP_PLOGI_LIST:
1273 nlp->nlp_flag |= list;
1274 /* Put it at the end of the plogi list */
1275 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1277 case NLP_ADISC_LIST:
1278 nlp->nlp_flag |= list;
1279 /* Put it at the end of the adisc list */
1280 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1282 case NLP_REGLOGIN_LIST:
1283 nlp->nlp_flag |= list;
1284 /* Put it at the end of the reglogin list */
1285 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1288 nlp->nlp_flag |= list;
1289 /* Put it at the end of the prli list */
1290 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1292 case NLP_UNMAPPED_LIST:
1293 nlp->nlp_flag |= list;
1294 /* Put it at the end of the unmap list */
1295 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1297 case NLP_MAPPED_LIST:
1298 nlp->nlp_flag |= list;
1299 /* Put it at the end of the map list */
1300 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1303 nlp->nlp_flag |= list;
1304 /* Put it at the end of the npr list */
1305 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1309 spin_unlock_irq(phba->host->host_lock);
1314 lpfc_nlp_state_cleanup(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1315 int old_state, int new_state)
1317 if (new_state == NLP_STE_UNMAPPED_NODE) {
1318 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1319 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1320 ndlp->nlp_type |= NLP_FC_NODE;
1322 if (new_state == NLP_STE_MAPPED_NODE)
1323 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1324 if (new_state == NLP_STE_NPR_NODE)
1325 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1327 /* Transport interface */
1328 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1329 old_state == NLP_STE_UNMAPPED_NODE)) {
1330 phba->nport_event_cnt++;
1331 lpfc_unregister_remote_port(phba, ndlp);
1334 if (new_state == NLP_STE_MAPPED_NODE ||
1335 new_state == NLP_STE_UNMAPPED_NODE) {
1336 phba->nport_event_cnt++;
1338 * Tell the fc transport about the port, if we haven't
1339 * already. If we have, and it's a scsi entity, be
1340 * sure to unblock any attached scsi devices
1342 lpfc_register_remote_port(phba, ndlp);
1346 * if we added to Mapped list, but the remote port
1347 * registration failed or assigned a target id outside
1348 * our presentable range - move the node to the
1351 if (new_state == NLP_STE_MAPPED_NODE &&
1353 ndlp->rport->scsi_target_id == -1 ||
1354 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1355 spin_lock_irq(phba->host->host_lock);
1356 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1357 spin_unlock_irq(phba->host->host_lock);
1358 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1363 lpfc_nlp_set_state(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int state)
1365 int old_state = ndlp->nlp_state;
1366 static int list_id[] = {
1367 [NLP_STE_UNUSED_NODE] = NLP_UNUSED_LIST,
1368 [NLP_STE_PLOGI_ISSUE] = NLP_PLOGI_LIST,
1369 [NLP_STE_ADISC_ISSUE] = NLP_ADISC_LIST,
1370 [NLP_STE_REG_LOGIN_ISSUE] = NLP_REGLOGIN_LIST,
1371 [NLP_STE_PRLI_ISSUE] = NLP_PRLI_LIST,
1372 [NLP_STE_UNMAPPED_NODE] = NLP_UNMAPPED_LIST,
1373 [NLP_STE_MAPPED_NODE] = NLP_MAPPED_LIST,
1374 [NLP_STE_NPR_NODE] = NLP_NPR_LIST,
1377 if (old_state == NLP_STE_NPR_NODE &&
1378 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1379 state != NLP_STE_NPR_NODE)
1380 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1381 if (old_state == NLP_STE_UNMAPPED_NODE) {
1382 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1383 ndlp->nlp_type &= ~NLP_FC_NODE;
1386 if (old_state && !list_empty(&ndlp->nlp_listp))
1387 lpfc_nlp_counters(phba, old_state, -1);
1389 ndlp->nlp_state = state;
1390 lpfc_nlp_list(phba, ndlp, list_id[state]);
1391 lpfc_nlp_counters(phba, state, 1);
1393 lpfc_nlp_state_cleanup(phba, ndlp, old_state, state);
1397 lpfc_dequeue_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1399 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1400 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1401 spin_lock_irq(phba->host->host_lock);
1402 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1403 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1404 lpfc_delink_node(phba, ndlp);
1405 spin_unlock_irq(phba->host->host_lock);
1406 lpfc_nlp_state_cleanup(phba, ndlp, ndlp->nlp_state, 0);
1410 lpfc_drop_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1412 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1413 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1414 spin_lock_irq(phba->host->host_lock);
1415 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1416 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1417 lpfc_delink_node(phba, ndlp);
1418 spin_unlock_irq(phba->host->host_lock);
1419 lpfc_nlp_remove(phba, ndlp);
1423 * Start / ReStart rescue timer for Discovery / RSCN handling
1426 lpfc_set_disctmo(struct lpfc_hba * phba)
1430 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1431 /* For FAN, timeout should be greater then edtov */
1432 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1434 /* Normal discovery timeout should be > then ELS/CT timeout
1435 * FC spec states we need 3 * ratov for CT requests
1437 tmo = ((phba->fc_ratov * 3) + 3);
1440 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1441 spin_lock_irq(phba->host->host_lock);
1442 phba->fc_flag |= FC_DISC_TMO;
1443 spin_unlock_irq(phba->host->host_lock);
1445 /* Start Discovery Timer state <hba_state> */
1446 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1447 "%d:0247 Start Discovery Timer state x%x "
1448 "Data: x%x x%lx x%x x%x\n",
1450 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1451 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1457 * Cancel rescue timer for Discovery / RSCN handling
1460 lpfc_can_disctmo(struct lpfc_hba * phba)
1462 /* Turn off discovery timer if its running */
1463 if (phba->fc_flag & FC_DISC_TMO) {
1464 spin_lock_irq(phba->host->host_lock);
1465 phba->fc_flag &= ~FC_DISC_TMO;
1466 spin_unlock_irq(phba->host->host_lock);
1467 del_timer_sync(&phba->fc_disctmo);
1468 phba->work_hba_events &= ~WORKER_DISC_TMO;
1471 /* Cancel Discovery Timer state <hba_state> */
1472 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1473 "%d:0248 Cancel Discovery Timer state x%x "
1474 "Data: x%x x%x x%x\n",
1475 phba->brd_no, phba->hba_state, phba->fc_flag,
1476 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1482 * Check specified ring for outstanding IOCB on the SLI queue
1483 * Return true if iocb matches the specified nport
1486 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1487 struct lpfc_sli_ring * pring,
1488 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1490 struct lpfc_sli *psli;
1495 if (pring->ringno == LPFC_ELS_RING) {
1496 switch (icmd->ulpCommand) {
1497 case CMD_GEN_REQUEST64_CR:
1498 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1500 case CMD_ELS_REQUEST64_CR:
1501 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1503 case CMD_XMIT_ELS_RSP64_CX:
1504 if (iocb->context1 == (uint8_t *) ndlp)
1507 } else if (pring->ringno == psli->extra_ring) {
1509 } else if (pring->ringno == psli->fcp_ring) {
1510 /* Skip match check if waiting to relogin to FCP target */
1511 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1512 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1515 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1518 } else if (pring->ringno == psli->next_ring) {
1525 * Free resources / clean up outstanding I/Os
1526 * associated with nlp_rpi in the LPFC_NODELIST entry.
1529 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1531 LIST_HEAD(completions);
1532 struct lpfc_sli *psli;
1533 struct lpfc_sli_ring *pring;
1534 struct lpfc_iocbq *iocb, *next_iocb;
1539 * Everything that matches on txcmplq will be returned
1540 * by firmware with a no rpi error.
1543 rpi = ndlp->nlp_rpi;
1545 /* Now process each ring */
1546 for (i = 0; i < psli->num_rings; i++) {
1547 pring = &psli->ring[i];
1549 spin_lock_irq(phba->host->host_lock);
1550 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1553 * Check to see if iocb matches the nport we are
1556 if ((lpfc_check_sli_ndlp
1557 (phba, pring, iocb, ndlp))) {
1558 /* It matches, so deque and call compl
1560 list_move_tail(&iocb->list,
1565 spin_unlock_irq(phba->host->host_lock);
1570 while (!list_empty(&completions)) {
1571 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1572 list_del(&iocb->list);
1574 if (iocb->iocb_cmpl) {
1576 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1577 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1578 (iocb->iocb_cmpl) (phba, iocb, iocb);
1580 lpfc_sli_release_iocbq(phba, iocb);
1587 * Free rpi associated with LPFC_NODELIST entry.
1588 * This routine is called from lpfc_freenode(), when we are removing
1589 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1590 * LOGO that completes successfully, and we are waiting to PLOGI back
1591 * to the remote NPort. In addition, it is called after we receive
1592 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1593 * we are waiting to PLOGI back to the remote NPort.
1596 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1601 if (ndlp->nlp_rpi) {
1602 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1603 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1604 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1605 rc = lpfc_sli_issue_mbox
1606 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1607 if (rc == MBX_NOT_FINISHED)
1608 mempool_free( mbox, phba->mbox_mem_pool);
1610 lpfc_no_rpi(phba, ndlp);
1618 * Free resources associated with LPFC_NODELIST entry
1619 * so it can be freed.
1622 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1625 LPFC_MBOXQ_t *nextmb;
1626 struct lpfc_dmabuf *mp;
1628 /* Cleanup node for NPort <nlp_DID> */
1629 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1630 "%d:0900 Cleanup node for NPort x%x "
1631 "Data: x%x x%x x%x\n",
1632 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1633 ndlp->nlp_state, ndlp->nlp_rpi);
1635 lpfc_dequeue_node(phba, ndlp);
1637 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1638 if ((mb = phba->sli.mbox_active)) {
1639 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1640 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1641 mb->context2 = NULL;
1642 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1646 spin_lock_irq(phba->host->host_lock);
1647 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1648 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1649 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1650 mp = (struct lpfc_dmabuf *) (mb->context1);
1652 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1655 list_del(&mb->list);
1656 mempool_free(mb, phba->mbox_mem_pool);
1659 spin_unlock_irq(phba->host->host_lock);
1661 lpfc_els_abort(phba,ndlp);
1662 spin_lock_irq(phba->host->host_lock);
1663 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1664 spin_unlock_irq(phba->host->host_lock);
1666 ndlp->nlp_last_elscmd = 0;
1667 del_timer_sync(&ndlp->nlp_delayfunc);
1669 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1670 list_del_init(&ndlp->els_retry_evt.evt_listp);
1672 lpfc_unreg_rpi(phba, ndlp);
1678 * Check to see if we can free the nlp back to the freelist.
1679 * If we are in the middle of using the nlp in the discovery state
1680 * machine, defer the free till we reach the end of the state machine.
1683 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1685 struct lpfc_rport_data *rdata;
1687 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1688 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1691 if (ndlp->nlp_disc_refcnt) {
1692 spin_lock_irq(phba->host->host_lock);
1693 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1694 spin_unlock_irq(phba->host->host_lock);
1696 lpfc_freenode(phba, ndlp);
1698 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1699 rdata = ndlp->rport->dd_data;
1700 rdata->pnode = NULL;
1704 mempool_free( ndlp, phba->nlp_mem_pool);
1710 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1716 if (did == Bcast_DID)
1719 if (ndlp->nlp_DID == 0) {
1723 /* First check for Direct match */
1724 if (ndlp->nlp_DID == did)
1727 /* Next check for area/domain identically equals 0 match */
1728 mydid.un.word = phba->fc_myDID;
1729 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1733 matchdid.un.word = did;
1734 ndlpdid.un.word = ndlp->nlp_DID;
1735 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1736 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1737 (mydid.un.b.area == matchdid.un.b.area)) {
1738 if ((ndlpdid.un.b.domain == 0) &&
1739 (ndlpdid.un.b.area == 0)) {
1740 if (ndlpdid.un.b.id)
1746 matchdid.un.word = ndlp->nlp_DID;
1747 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1748 (mydid.un.b.area == ndlpdid.un.b.area)) {
1749 if ((matchdid.un.b.domain == 0) &&
1750 (matchdid.un.b.area == 0)) {
1751 if (matchdid.un.b.id)
1759 /* Search for a nodelist entry on a specific list */
1760 struct lpfc_nodelist *
1761 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1763 struct lpfc_nodelist *ndlp;
1764 struct list_head *lists[]={&phba->fc_nlpunmap_list,
1765 &phba->fc_nlpmap_list,
1766 &phba->fc_plogi_list,
1767 &phba->fc_adisc_list,
1768 &phba->fc_reglogin_list,
1769 &phba->fc_prli_list,
1771 &phba->fc_unused_list};
1772 uint32_t search[]={NLP_SEARCH_UNMAPPED,
1776 NLP_SEARCH_REGLOGIN,
1783 spin_lock_irq(phba->host->host_lock);
1784 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
1785 if (!(order & search[i]))
1787 list_for_each_entry(ndlp, lists[i], nlp_listp) {
1788 if (lpfc_matchdid(phba, ndlp, did)) {
1789 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1790 ((uint32_t) ndlp->nlp_xri << 16) |
1791 ((uint32_t) ndlp->nlp_type << 8) |
1792 ((uint32_t) ndlp->nlp_rpi & 0xff));
1793 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1794 "%d:0929 FIND node DID "
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);
1804 spin_unlock_irq(phba->host->host_lock);
1806 /* FIND node did <did> NOT FOUND */
1807 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1808 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1809 phba->brd_no, did, order);
1813 struct lpfc_nodelist *
1814 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1816 struct lpfc_nodelist *ndlp;
1819 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1821 if ((phba->fc_flag & FC_RSCN_MODE) &&
1822 ((lpfc_rscn_payload_check(phba, did) == 0)))
1824 ndlp = (struct lpfc_nodelist *)
1825 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1828 lpfc_nlp_init(phba, ndlp, did);
1829 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1830 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1833 if (phba->fc_flag & FC_RSCN_MODE) {
1834 if (lpfc_rscn_payload_check(phba, did)) {
1835 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1837 /* Since this node is marked for discovery,
1838 * delay timeout is not needed.
1840 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1841 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1845 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1846 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1848 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1849 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1854 /* Build a list of nodes to discover based on the loopmap */
1856 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1859 uint32_t alpa, index;
1861 if (phba->hba_state <= LPFC_LINK_DOWN) {
1864 if (phba->fc_topology != TOPOLOGY_LOOP) {
1868 /* Check for loop map present or not */
1869 if (phba->alpa_map[0]) {
1870 for (j = 1; j <= phba->alpa_map[0]; j++) {
1871 alpa = phba->alpa_map[j];
1873 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1876 lpfc_setup_disc_node(phba, alpa);
1879 /* No alpamap, so try all alpa's */
1880 for (j = 0; j < FC_MAXLOOP; j++) {
1881 /* If cfg_scan_down is set, start from highest
1882 * ALPA (0xef) to lowest (0x1).
1884 if (phba->cfg_scan_down)
1887 index = FC_MAXLOOP - j - 1;
1888 alpa = lpfcAlpaArray[index];
1889 if ((phba->fc_myDID & 0xff) == alpa) {
1893 lpfc_setup_disc_node(phba, alpa);
1899 /* Start Link up / RSCN discovery on NPR list */
1901 lpfc_disc_start(struct lpfc_hba * phba)
1903 struct lpfc_sli *psli;
1905 struct lpfc_nodelist *ndlp, *next_ndlp;
1906 uint32_t did_changed, num_sent;
1907 uint32_t clear_la_pending;
1912 if (phba->hba_state <= LPFC_LINK_DOWN) {
1915 if (phba->hba_state == LPFC_CLEAR_LA)
1916 clear_la_pending = 1;
1918 clear_la_pending = 0;
1920 if (phba->hba_state < LPFC_HBA_READY) {
1921 phba->hba_state = LPFC_DISC_AUTH;
1923 lpfc_set_disctmo(phba);
1925 if (phba->fc_prevDID == phba->fc_myDID) {
1930 phba->fc_prevDID = phba->fc_myDID;
1931 phba->num_disc_nodes = 0;
1933 /* Start Discovery state <hba_state> */
1934 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1935 "%d:0202 Start Discovery hba state x%x "
1936 "Data: x%x x%x x%x\n",
1937 phba->brd_no, phba->hba_state, phba->fc_flag,
1938 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1940 /* If our did changed, we MUST do PLOGI */
1941 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1943 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1945 spin_lock_irq(phba->host->host_lock);
1946 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1947 spin_unlock_irq(phba->host->host_lock);
1952 /* First do ADISCs - if any */
1953 num_sent = lpfc_els_disc_adisc(phba);
1958 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
1959 /* If we get here, there is nothing to ADISC */
1960 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1961 phba->hba_state = LPFC_CLEAR_LA;
1962 lpfc_clear_la(phba, mbox);
1963 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1964 rc = lpfc_sli_issue_mbox(phba, mbox,
1965 (MBX_NOWAIT | MBX_STOP_IOCB));
1966 if (rc == MBX_NOT_FINISHED) {
1967 mempool_free( mbox, phba->mbox_mem_pool);
1968 lpfc_disc_flush_list(phba);
1969 psli->ring[(psli->extra_ring)].flag &=
1970 ~LPFC_STOP_IOCB_EVENT;
1971 psli->ring[(psli->fcp_ring)].flag &=
1972 ~LPFC_STOP_IOCB_EVENT;
1973 psli->ring[(psli->next_ring)].flag &=
1974 ~LPFC_STOP_IOCB_EVENT;
1975 phba->hba_state = LPFC_HBA_READY;
1979 /* Next do PLOGIs - if any */
1980 num_sent = lpfc_els_disc_plogi(phba);
1985 if (phba->fc_flag & FC_RSCN_MODE) {
1986 /* Check to see if more RSCNs came in while we
1987 * were processing this one.
1989 if ((phba->fc_rscn_id_cnt == 0) &&
1990 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1991 spin_lock_irq(phba->host->host_lock);
1992 phba->fc_flag &= ~FC_RSCN_MODE;
1993 spin_unlock_irq(phba->host->host_lock);
1995 lpfc_els_handle_rscn(phba);
2002 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2003 * ring the match the sppecified nodelist.
2006 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2008 LIST_HEAD(completions);
2009 struct lpfc_sli *psli;
2011 struct lpfc_iocbq *iocb, *next_iocb;
2012 struct lpfc_sli_ring *pring;
2015 pring = &psli->ring[LPFC_ELS_RING];
2017 /* Error matching iocb on txq or txcmplq
2018 * First check the txq.
2020 spin_lock_irq(phba->host->host_lock);
2021 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2022 if (iocb->context1 != ndlp) {
2026 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2027 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2029 list_move_tail(&iocb->list, &completions);
2034 /* Next check the txcmplq */
2035 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2036 if (iocb->context1 != ndlp) {
2040 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2041 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2042 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2045 spin_unlock_irq(phba->host->host_lock);
2047 while (!list_empty(&completions)) {
2048 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2049 list_del(&iocb->list);
2051 if (iocb->iocb_cmpl) {
2053 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2054 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2055 (iocb->iocb_cmpl) (phba, iocb, iocb);
2057 lpfc_sli_release_iocbq(phba, iocb);
2064 lpfc_disc_flush_list(struct lpfc_hba * phba)
2066 struct lpfc_nodelist *ndlp, *next_ndlp;
2068 if (phba->fc_plogi_cnt) {
2069 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2071 lpfc_free_tx(phba, ndlp);
2072 lpfc_nlp_remove(phba, ndlp);
2075 if (phba->fc_adisc_cnt) {
2076 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2078 lpfc_free_tx(phba, ndlp);
2079 lpfc_nlp_remove(phba, ndlp);
2085 /*****************************************************************************/
2087 * NAME: lpfc_disc_timeout
2089 * FUNCTION: Fibre Channel driver discovery timeout routine.
2091 * EXECUTION ENVIRONMENT: interrupt only
2099 /*****************************************************************************/
2101 lpfc_disc_timeout(unsigned long ptr)
2103 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2104 unsigned long flags = 0;
2106 if (unlikely(!phba))
2109 spin_lock_irqsave(phba->host->host_lock, flags);
2110 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2111 phba->work_hba_events |= WORKER_DISC_TMO;
2112 if (phba->work_wait)
2113 wake_up(phba->work_wait);
2115 spin_unlock_irqrestore(phba->host->host_lock, flags);
2120 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2122 struct lpfc_sli *psli;
2123 struct lpfc_nodelist *ndlp, *next_ndlp;
2124 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2125 int rc, clrlaerr = 0;
2127 if (unlikely(!phba))
2130 if (!(phba->fc_flag & FC_DISC_TMO))
2135 spin_lock_irq(phba->host->host_lock);
2136 phba->fc_flag &= ~FC_DISC_TMO;
2137 spin_unlock_irq(phba->host->host_lock);
2139 switch (phba->hba_state) {
2141 case LPFC_LOCAL_CFG_LINK:
2142 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2144 lpfc_printf_log(phba,
2147 "%d:0221 FAN timeout\n",
2150 /* Start discovery by sending FLOGI, clean up old rpis */
2151 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2153 if (ndlp->nlp_type & NLP_FABRIC) {
2154 /* Clean up the ndlp on Fabric connections */
2155 lpfc_drop_node(phba, ndlp);
2156 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2157 /* Fail outstanding IO now since device
2158 * is marked for PLOGI.
2160 lpfc_unreg_rpi(phba, ndlp);
2163 phba->hba_state = LPFC_FLOGI;
2164 lpfc_set_disctmo(phba);
2165 lpfc_initial_flogi(phba);
2169 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2170 /* Initial FLOGI timeout */
2171 lpfc_printf_log(phba,
2174 "%d:0222 Initial FLOGI timeout\n",
2177 /* Assume no Fabric and go on with discovery.
2178 * Check for outstanding ELS FLOGI to abort.
2181 /* FLOGI failed, so just use loop map to make discovery list */
2182 lpfc_disc_list_loopmap(phba);
2184 /* Start discovery */
2185 lpfc_disc_start(phba);
2188 case LPFC_FABRIC_CFG_LINK:
2189 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2191 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2192 "%d:0223 Timeout while waiting for NameServer "
2193 "login\n", phba->brd_no);
2195 /* Next look for NameServer ndlp */
2196 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2198 lpfc_nlp_remove(phba, ndlp);
2199 /* Start discovery */
2200 lpfc_disc_start(phba);
2204 /* Check for wait for NameServer Rsp timeout */
2205 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2206 "%d:0224 NameServer Query timeout "
2209 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2211 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2214 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2215 /* Try it one more time */
2216 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2220 phba->fc_ns_retry = 0;
2223 /* Nothing to authenticate, so CLEAR_LA right now */
2224 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2227 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2228 "%d:0226 Device Discovery "
2229 "completion error\n",
2231 phba->hba_state = LPFC_HBA_ERROR;
2235 phba->hba_state = LPFC_CLEAR_LA;
2236 lpfc_clear_la(phba, clearlambox);
2237 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2238 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2239 (MBX_NOWAIT | MBX_STOP_IOCB));
2240 if (rc == MBX_NOT_FINISHED) {
2241 mempool_free(clearlambox, phba->mbox_mem_pool);
2246 /* Setup and issue mailbox INITIALIZE LINK command */
2247 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2248 if (!initlinkmbox) {
2249 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2250 "%d:0206 Device Discovery "
2251 "completion error\n",
2253 phba->hba_state = LPFC_HBA_ERROR;
2257 lpfc_linkdown(phba);
2258 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2259 phba->cfg_link_speed);
2260 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2261 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2262 (MBX_NOWAIT | MBX_STOP_IOCB));
2263 lpfc_set_loopback_flag(phba);
2264 if (rc == MBX_NOT_FINISHED)
2265 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2269 case LPFC_DISC_AUTH:
2270 /* Node Authentication timeout */
2271 lpfc_printf_log(phba,
2274 "%d:0227 Node Authentication timeout\n",
2276 lpfc_disc_flush_list(phba);
2277 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2280 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2281 "%d:0207 Device Discovery "
2282 "completion error\n",
2284 phba->hba_state = LPFC_HBA_ERROR;
2287 phba->hba_state = LPFC_CLEAR_LA;
2288 lpfc_clear_la(phba, clearlambox);
2289 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2290 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2291 (MBX_NOWAIT | MBX_STOP_IOCB));
2292 if (rc == MBX_NOT_FINISHED) {
2293 mempool_free(clearlambox, phba->mbox_mem_pool);
2299 /* CLEAR LA timeout */
2300 lpfc_printf_log(phba,
2303 "%d:0228 CLEAR LA timeout\n",
2308 case LPFC_HBA_READY:
2309 if (phba->fc_flag & FC_RSCN_MODE) {
2310 lpfc_printf_log(phba,
2313 "%d:0231 RSCN timeout Data: x%x x%x\n",
2315 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2317 /* Cleanup any outstanding ELS commands */
2318 lpfc_els_flush_cmd(phba);
2320 lpfc_els_flush_rscn(phba);
2321 lpfc_disc_flush_list(phba);
2327 lpfc_disc_flush_list(phba);
2328 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2329 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2330 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2331 phba->hba_state = LPFC_HBA_READY;
2338 * This routine handles processing a NameServer REG_LOGIN mailbox
2339 * command upon completion. It is setup in the LPFC_MBOXQ
2340 * as the completion routine when the command is
2341 * handed off to the SLI layer.
2344 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2346 struct lpfc_sli *psli;
2348 struct lpfc_dmabuf *mp;
2349 struct lpfc_nodelist *ndlp;
2354 ndlp = (struct lpfc_nodelist *) pmb->context2;
2355 mp = (struct lpfc_dmabuf *) (pmb->context1);
2357 pmb->context1 = NULL;
2359 ndlp->nlp_rpi = mb->un.varWords[0];
2360 ndlp->nlp_type |= NLP_FABRIC;
2361 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
2363 /* Start issuing Fabric-Device Management Interface (FDMI)
2364 * command to 0xfffffa (FDMI well known port)
2366 if (phba->cfg_fdmi_on == 1) {
2367 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2370 * Delay issuing FDMI command if fdmi-on=2
2371 * (supporting RPA/hostnmae)
2373 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2376 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2378 mempool_free( pmb, phba->mbox_mem_pool);
2384 * This routine looks up the ndlp lists
2385 * for the given RPI. If rpi found
2386 * it return the node list pointer
2389 struct lpfc_nodelist *
2390 __lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2392 struct lpfc_nodelist *ndlp;
2393 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2394 &phba->fc_nlpmap_list,
2395 &phba->fc_plogi_list,
2396 &phba->fc_adisc_list,
2397 &phba->fc_reglogin_list};
2400 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2401 list_for_each_entry(ndlp, lists[i], nlp_listp)
2402 if (ndlp->nlp_rpi == rpi) {
2408 struct lpfc_nodelist *
2409 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2411 struct lpfc_nodelist *ndlp;
2413 spin_lock_irq(phba->host->host_lock);
2414 ndlp = __lpfc_findnode_rpi(phba, rpi);
2415 spin_unlock_irq(phba->host->host_lock);
2420 * This routine looks up the ndlp lists
2421 * for the given WWPN. If WWPN found
2422 * it return the node list pointer
2425 struct lpfc_nodelist *
2426 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2427 struct lpfc_name * wwpn)
2429 struct lpfc_nodelist *ndlp;
2430 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2431 &phba->fc_nlpmap_list,
2433 &phba->fc_plogi_list,
2434 &phba->fc_adisc_list,
2435 &phba->fc_reglogin_list,
2436 &phba->fc_prli_list};
2437 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2442 NLP_SEARCH_REGLOGIN,
2446 spin_lock_irq(phba->host->host_lock);
2447 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2448 if (!(order & search[i]))
2450 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2451 if (memcmp(&ndlp->nlp_portname, wwpn,
2452 sizeof(struct lpfc_name)) == 0) {
2453 spin_unlock_irq(phba->host->host_lock);
2458 spin_unlock_irq(phba->host->host_lock);
2463 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2466 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2467 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2468 init_timer(&ndlp->nlp_delayfunc);
2469 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2470 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2471 ndlp->nlp_DID = did;
2472 ndlp->nlp_phba = phba;
2473 ndlp->nlp_sid = NLP_NO_SID;