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 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
904 "%d:1303 Link Up Event x%x received "
905 "Data: x%x x%x x%x x%x\n",
906 phba->brd_no, la->eventTag, phba->fc_eventTag,
907 la->granted_AL_PA, la->UlnkSpeed,
909 lpfc_mbx_process_link_up(phba, la);
911 phba->fc_stat.LinkDown++;
912 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
913 "%d:1305 Link Down Event x%x received "
914 "Data: x%x x%x x%x\n",
915 phba->brd_no, la->eventTag, phba->fc_eventTag,
916 phba->hba_state, phba->fc_flag);
917 lpfc_mbx_issue_link_down(phba);
920 lpfc_mbx_cmpl_read_la_free_mbuf:
921 lpfc_mbuf_free(phba, mp->virt, mp->phys);
923 mempool_free(pmb, phba->mbox_mem_pool);
928 * This routine handles processing a REG_LOGIN mailbox
929 * command upon completion. It is setup in the LPFC_MBOXQ
930 * as the completion routine when the command is
931 * handed off to the SLI layer.
934 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
936 struct lpfc_sli *psli;
938 struct lpfc_dmabuf *mp;
939 struct lpfc_nodelist *ndlp;
944 ndlp = (struct lpfc_nodelist *) pmb->context2;
945 mp = (struct lpfc_dmabuf *) (pmb->context1);
947 pmb->context1 = NULL;
949 /* Good status, call state machine */
950 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
951 lpfc_mbuf_free(phba, mp->virt, mp->phys);
953 mempool_free( pmb, phba->mbox_mem_pool);
959 * This routine handles processing a Fabric REG_LOGIN mailbox
960 * command upon completion. It is setup in the LPFC_MBOXQ
961 * as the completion routine when the command is
962 * handed off to the SLI layer.
965 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
967 struct lpfc_sli *psli;
969 struct lpfc_dmabuf *mp;
970 struct lpfc_nodelist *ndlp;
971 struct lpfc_nodelist *ndlp_fdmi;
977 ndlp = (struct lpfc_nodelist *) pmb->context2;
978 mp = (struct lpfc_dmabuf *) (pmb->context1);
981 lpfc_mbuf_free(phba, mp->virt, mp->phys);
983 mempool_free( pmb, phba->mbox_mem_pool);
984 mempool_free( ndlp, phba->nlp_mem_pool);
986 /* FLOGI failed, so just use loop map to make discovery list */
987 lpfc_disc_list_loopmap(phba);
989 /* Start discovery */
990 lpfc_disc_start(phba);
994 pmb->context1 = NULL;
996 ndlp->nlp_rpi = mb->un.varWords[0];
997 ndlp->nlp_type |= NLP_FABRIC;
998 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1000 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
1001 /* This NPort has been assigned an NPort_ID by the fabric as a
1002 * result of the completed fabric login. Issue a State Change
1003 * Registration (SCR) ELS request to the fabric controller
1004 * (SCR_DID) so that this NPort gets RSCN events from the
1007 lpfc_issue_els_scr(phba, SCR_DID, 0);
1009 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
1011 /* Allocate a new node instance. If the pool is empty,
1012 * start the discovery process and skip the Nameserver
1013 * login process. This is attempted again later on.
1014 * Otherwise, issue a Port Login (PLOGI) to NameServer.
1016 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1018 lpfc_disc_start(phba);
1019 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1021 mempool_free( pmb, phba->mbox_mem_pool);
1024 lpfc_nlp_init(phba, ndlp, NameServer_DID);
1025 ndlp->nlp_type |= NLP_FABRIC;
1028 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1029 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
1030 if (phba->cfg_fdmi_on) {
1031 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1034 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
1035 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1036 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
1037 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
1042 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1044 mempool_free( pmb, phba->mbox_mem_pool);
1049 * This routine handles processing a NameServer REG_LOGIN mailbox
1050 * command upon completion. It is setup in the LPFC_MBOXQ
1051 * as the completion routine when the command is
1052 * handed off to the SLI layer.
1055 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1057 struct lpfc_sli *psli;
1059 struct lpfc_dmabuf *mp;
1060 struct lpfc_nodelist *ndlp;
1065 ndlp = (struct lpfc_nodelist *) pmb->context2;
1066 mp = (struct lpfc_dmabuf *) (pmb->context1);
1068 if (mb->mbxStatus) {
1069 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1071 mempool_free(pmb, phba->mbox_mem_pool);
1072 lpfc_drop_node(phba, ndlp);
1074 /* RegLogin failed, so just use loop map to make discovery
1076 lpfc_disc_list_loopmap(phba);
1078 /* Start discovery */
1079 lpfc_disc_start(phba);
1083 pmb->context1 = NULL;
1085 ndlp->nlp_rpi = mb->un.varWords[0];
1086 ndlp->nlp_type |= NLP_FABRIC;
1087 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1089 if (phba->hba_state < LPFC_HBA_READY) {
1090 /* Link up discovery requires Fabrib registration. */
1091 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1092 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1093 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1094 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFF_ID);
1097 phba->fc_ns_retry = 0;
1098 /* Good status, issue CT Request to NameServer */
1099 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1100 /* Cannot issue NameServer Query, so finish up discovery */
1101 lpfc_disc_start(phba);
1104 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1106 mempool_free( pmb, phba->mbox_mem_pool);
1112 lpfc_register_remote_port(struct lpfc_hba * phba,
1113 struct lpfc_nodelist * ndlp)
1115 struct fc_rport *rport;
1116 struct lpfc_rport_data *rdata;
1117 struct fc_rport_identifiers rport_ids;
1119 /* Remote port has reappeared. Re-register w/ FC transport */
1120 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1121 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1122 rport_ids.port_id = ndlp->nlp_DID;
1123 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1125 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1127 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1128 "Warning: fc_remote_port_add failed\n");
1132 /* initialize static port data */
1133 rport->maxframe_size = ndlp->nlp_maxframe;
1134 rport->supported_classes = ndlp->nlp_class_sup;
1135 rdata = rport->dd_data;
1136 rdata->pnode = ndlp;
1138 if (ndlp->nlp_type & NLP_FCP_TARGET)
1139 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1140 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1141 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1144 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1145 fc_remote_port_rolechg(rport, rport_ids.roles);
1147 if ((rport->scsi_target_id != -1) &&
1148 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1149 ndlp->nlp_sid = rport->scsi_target_id;
1156 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1157 struct lpfc_nodelist * ndlp)
1159 struct fc_rport *rport = ndlp->rport;
1160 struct lpfc_rport_data *rdata = rport->dd_data;
1162 if (rport->scsi_target_id == -1) {
1164 rdata->pnode = NULL;
1167 fc_remote_port_delete(rport);
1173 lpfc_nlp_counters(struct lpfc_hba *phba, int state, int count)
1176 case NLP_STE_UNUSED_NODE:
1177 phba->fc_unused_cnt += count;
1179 case NLP_STE_PLOGI_ISSUE:
1180 phba->fc_plogi_cnt += count;
1182 case NLP_STE_ADISC_ISSUE:
1183 phba->fc_adisc_cnt += count;
1185 case NLP_STE_REG_LOGIN_ISSUE:
1186 phba->fc_reglogin_cnt += count;
1188 case NLP_STE_PRLI_ISSUE:
1189 phba->fc_prli_cnt += count;
1191 case NLP_STE_UNMAPPED_NODE:
1192 phba->fc_unmap_cnt += count;
1194 case NLP_STE_MAPPED_NODE:
1195 phba->fc_map_cnt += count;
1197 case NLP_STE_NPR_NODE:
1198 phba->fc_npr_cnt += count;
1204 lpfc_delink_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1206 switch (ndlp->nlp_flag & NLP_LIST_MASK) {
1207 case NLP_UNUSED_LIST:
1208 list_del_init(&ndlp->nlp_listp);
1210 case NLP_PLOGI_LIST:
1211 list_del_init(&ndlp->nlp_listp);
1213 case NLP_ADISC_LIST:
1214 list_del_init(&ndlp->nlp_listp);
1216 case NLP_REGLOGIN_LIST:
1217 list_del_init(&ndlp->nlp_listp);
1220 list_del_init(&ndlp->nlp_listp);
1222 case NLP_UNMAPPED_LIST:
1223 list_del_init(&ndlp->nlp_listp);
1225 case NLP_MAPPED_LIST:
1226 list_del_init(&ndlp->nlp_listp);
1229 list_del_init(&ndlp->nlp_listp);
1233 ndlp->nlp_flag &= ~NLP_LIST_MASK;
1237 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1239 struct lpfc_sli *psli;
1242 /* Sanity check to ensure we are not moving to / from the same list */
1243 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1246 spin_lock_irq(phba->host->host_lock);
1247 lpfc_delink_node(phba, nlp);
1249 /* Add NPort <did> to <num> list */
1250 lpfc_printf_log(phba,
1253 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1255 nlp->nlp_DID, list, nlp->nlp_flag);
1258 case NLP_UNUSED_LIST:
1259 nlp->nlp_flag |= list;
1260 /* Put it at the end of the unused list */
1261 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1263 case NLP_PLOGI_LIST:
1264 nlp->nlp_flag |= list;
1265 /* Put it at the end of the plogi list */
1266 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1268 case NLP_ADISC_LIST:
1269 nlp->nlp_flag |= list;
1270 /* Put it at the end of the adisc list */
1271 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1273 case NLP_REGLOGIN_LIST:
1274 nlp->nlp_flag |= list;
1275 /* Put it at the end of the reglogin list */
1276 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1279 nlp->nlp_flag |= list;
1280 /* Put it at the end of the prli list */
1281 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1283 case NLP_UNMAPPED_LIST:
1284 nlp->nlp_flag |= list;
1285 /* Put it at the end of the unmap list */
1286 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1288 case NLP_MAPPED_LIST:
1289 nlp->nlp_flag |= list;
1290 /* Put it at the end of the map list */
1291 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1294 nlp->nlp_flag |= list;
1295 /* Put it at the end of the npr list */
1296 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1300 spin_unlock_irq(phba->host->host_lock);
1305 lpfc_nlp_state_cleanup(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1306 int old_state, int new_state)
1308 if (new_state == NLP_STE_UNMAPPED_NODE) {
1309 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1310 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1311 ndlp->nlp_type |= NLP_FC_NODE;
1313 if (new_state == NLP_STE_MAPPED_NODE)
1314 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1315 if (new_state == NLP_STE_NPR_NODE)
1316 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1318 /* Transport interface */
1319 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1320 old_state == NLP_STE_UNMAPPED_NODE)) {
1321 phba->nport_event_cnt++;
1322 lpfc_unregister_remote_port(phba, ndlp);
1325 if (new_state == NLP_STE_MAPPED_NODE ||
1326 new_state == NLP_STE_UNMAPPED_NODE) {
1327 phba->nport_event_cnt++;
1329 * Tell the fc transport about the port, if we haven't
1330 * already. If we have, and it's a scsi entity, be
1331 * sure to unblock any attached scsi devices
1333 lpfc_register_remote_port(phba, ndlp);
1337 * if we added to Mapped list, but the remote port
1338 * registration failed or assigned a target id outside
1339 * our presentable range - move the node to the
1342 if (new_state == NLP_STE_MAPPED_NODE &&
1344 ndlp->rport->scsi_target_id == -1 ||
1345 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1346 spin_lock_irq(phba->host->host_lock);
1347 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1348 spin_unlock_irq(phba->host->host_lock);
1349 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1354 lpfc_nlp_set_state(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int state)
1356 int old_state = ndlp->nlp_state;
1357 static int list_id[] = {
1358 [NLP_STE_UNUSED_NODE] = NLP_UNUSED_LIST,
1359 [NLP_STE_PLOGI_ISSUE] = NLP_PLOGI_LIST,
1360 [NLP_STE_ADISC_ISSUE] = NLP_ADISC_LIST,
1361 [NLP_STE_REG_LOGIN_ISSUE] = NLP_REGLOGIN_LIST,
1362 [NLP_STE_PRLI_ISSUE] = NLP_PRLI_LIST,
1363 [NLP_STE_UNMAPPED_NODE] = NLP_UNMAPPED_LIST,
1364 [NLP_STE_MAPPED_NODE] = NLP_MAPPED_LIST,
1365 [NLP_STE_NPR_NODE] = NLP_NPR_LIST,
1368 if (old_state == NLP_STE_NPR_NODE &&
1369 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1370 state != NLP_STE_NPR_NODE)
1371 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1372 if (old_state == NLP_STE_UNMAPPED_NODE) {
1373 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1374 ndlp->nlp_type &= ~NLP_FC_NODE;
1377 if (old_state && !list_empty(&ndlp->nlp_listp))
1378 lpfc_nlp_counters(phba, old_state, -1);
1380 ndlp->nlp_state = state;
1381 lpfc_nlp_list(phba, ndlp, list_id[state]);
1382 lpfc_nlp_counters(phba, state, 1);
1384 lpfc_nlp_state_cleanup(phba, ndlp, old_state, state);
1388 lpfc_dequeue_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1390 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1391 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1392 spin_lock_irq(phba->host->host_lock);
1393 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1394 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1395 lpfc_delink_node(phba, ndlp);
1396 spin_unlock_irq(phba->host->host_lock);
1397 lpfc_nlp_state_cleanup(phba, ndlp, ndlp->nlp_state, 0);
1401 lpfc_drop_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1403 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1404 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1405 spin_lock_irq(phba->host->host_lock);
1406 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1407 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1408 lpfc_delink_node(phba, ndlp);
1409 spin_unlock_irq(phba->host->host_lock);
1410 lpfc_nlp_remove(phba, ndlp);
1414 * Start / ReStart rescue timer for Discovery / RSCN handling
1417 lpfc_set_disctmo(struct lpfc_hba * phba)
1421 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1422 /* For FAN, timeout should be greater then edtov */
1423 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1425 /* Normal discovery timeout should be > then ELS/CT timeout
1426 * FC spec states we need 3 * ratov for CT requests
1428 tmo = ((phba->fc_ratov * 3) + 3);
1431 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1432 spin_lock_irq(phba->host->host_lock);
1433 phba->fc_flag |= FC_DISC_TMO;
1434 spin_unlock_irq(phba->host->host_lock);
1436 /* Start Discovery Timer state <hba_state> */
1437 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1438 "%d:0247 Start Discovery Timer state x%x "
1439 "Data: x%x x%lx x%x x%x\n",
1441 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1442 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1448 * Cancel rescue timer for Discovery / RSCN handling
1451 lpfc_can_disctmo(struct lpfc_hba * phba)
1453 /* Turn off discovery timer if its running */
1454 if (phba->fc_flag & FC_DISC_TMO) {
1455 spin_lock_irq(phba->host->host_lock);
1456 phba->fc_flag &= ~FC_DISC_TMO;
1457 spin_unlock_irq(phba->host->host_lock);
1458 del_timer_sync(&phba->fc_disctmo);
1459 phba->work_hba_events &= ~WORKER_DISC_TMO;
1462 /* Cancel Discovery Timer state <hba_state> */
1463 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1464 "%d:0248 Cancel Discovery Timer state x%x "
1465 "Data: x%x x%x x%x\n",
1466 phba->brd_no, phba->hba_state, phba->fc_flag,
1467 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1473 * Check specified ring for outstanding IOCB on the SLI queue
1474 * Return true if iocb matches the specified nport
1477 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1478 struct lpfc_sli_ring * pring,
1479 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1481 struct lpfc_sli *psli;
1486 if (pring->ringno == LPFC_ELS_RING) {
1487 switch (icmd->ulpCommand) {
1488 case CMD_GEN_REQUEST64_CR:
1489 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1491 case CMD_ELS_REQUEST64_CR:
1492 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1494 case CMD_XMIT_ELS_RSP64_CX:
1495 if (iocb->context1 == (uint8_t *) ndlp)
1498 } else if (pring->ringno == psli->extra_ring) {
1500 } else if (pring->ringno == psli->fcp_ring) {
1501 /* Skip match check if waiting to relogin to FCP target */
1502 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1503 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1506 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1509 } else if (pring->ringno == psli->next_ring) {
1516 * Free resources / clean up outstanding I/Os
1517 * associated with nlp_rpi in the LPFC_NODELIST entry.
1520 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1522 LIST_HEAD(completions);
1523 struct lpfc_sli *psli;
1524 struct lpfc_sli_ring *pring;
1525 struct lpfc_iocbq *iocb, *next_iocb;
1530 * Everything that matches on txcmplq will be returned
1531 * by firmware with a no rpi error.
1534 rpi = ndlp->nlp_rpi;
1536 /* Now process each ring */
1537 for (i = 0; i < psli->num_rings; i++) {
1538 pring = &psli->ring[i];
1540 spin_lock_irq(phba->host->host_lock);
1541 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1544 * Check to see if iocb matches the nport we are
1547 if ((lpfc_check_sli_ndlp
1548 (phba, pring, iocb, ndlp))) {
1549 /* It matches, so deque and call compl
1551 list_move_tail(&iocb->list,
1556 spin_unlock_irq(phba->host->host_lock);
1561 while (!list_empty(&completions)) {
1562 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1563 list_del(&iocb->list);
1565 if (iocb->iocb_cmpl) {
1567 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1568 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1569 (iocb->iocb_cmpl) (phba, iocb, iocb);
1571 lpfc_sli_release_iocbq(phba, iocb);
1578 * Free rpi associated with LPFC_NODELIST entry.
1579 * This routine is called from lpfc_freenode(), when we are removing
1580 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1581 * LOGO that completes successfully, and we are waiting to PLOGI back
1582 * to the remote NPort. In addition, it is called after we receive
1583 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1584 * we are waiting to PLOGI back to the remote NPort.
1587 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1592 if (ndlp->nlp_rpi) {
1593 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1594 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1595 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1596 rc = lpfc_sli_issue_mbox
1597 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1598 if (rc == MBX_NOT_FINISHED)
1599 mempool_free( mbox, phba->mbox_mem_pool);
1601 lpfc_no_rpi(phba, ndlp);
1609 * Free resources associated with LPFC_NODELIST entry
1610 * so it can be freed.
1613 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1616 LPFC_MBOXQ_t *nextmb;
1617 struct lpfc_dmabuf *mp;
1619 /* Cleanup node for NPort <nlp_DID> */
1620 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1621 "%d:0900 Cleanup node for NPort x%x "
1622 "Data: x%x x%x x%x\n",
1623 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1624 ndlp->nlp_state, ndlp->nlp_rpi);
1626 lpfc_dequeue_node(phba, ndlp);
1628 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1629 if ((mb = phba->sli.mbox_active)) {
1630 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1631 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1632 mb->context2 = NULL;
1633 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1637 spin_lock_irq(phba->host->host_lock);
1638 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1639 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1640 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1641 mp = (struct lpfc_dmabuf *) (mb->context1);
1643 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1646 list_del(&mb->list);
1647 mempool_free(mb, phba->mbox_mem_pool);
1650 spin_unlock_irq(phba->host->host_lock);
1652 lpfc_els_abort(phba,ndlp);
1653 spin_lock_irq(phba->host->host_lock);
1654 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1655 spin_unlock_irq(phba->host->host_lock);
1657 ndlp->nlp_last_elscmd = 0;
1658 del_timer_sync(&ndlp->nlp_delayfunc);
1660 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1661 list_del_init(&ndlp->els_retry_evt.evt_listp);
1663 lpfc_unreg_rpi(phba, ndlp);
1669 * Check to see if we can free the nlp back to the freelist.
1670 * If we are in the middle of using the nlp in the discovery state
1671 * machine, defer the free till we reach the end of the state machine.
1674 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1676 struct lpfc_rport_data *rdata;
1678 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1679 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1682 if (ndlp->nlp_disc_refcnt) {
1683 spin_lock_irq(phba->host->host_lock);
1684 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1685 spin_unlock_irq(phba->host->host_lock);
1687 lpfc_freenode(phba, ndlp);
1689 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1690 rdata = ndlp->rport->dd_data;
1691 rdata->pnode = NULL;
1695 mempool_free( ndlp, phba->nlp_mem_pool);
1701 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1707 if (did == Bcast_DID)
1710 if (ndlp->nlp_DID == 0) {
1714 /* First check for Direct match */
1715 if (ndlp->nlp_DID == did)
1718 /* Next check for area/domain identically equals 0 match */
1719 mydid.un.word = phba->fc_myDID;
1720 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1724 matchdid.un.word = did;
1725 ndlpdid.un.word = ndlp->nlp_DID;
1726 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1727 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1728 (mydid.un.b.area == matchdid.un.b.area)) {
1729 if ((ndlpdid.un.b.domain == 0) &&
1730 (ndlpdid.un.b.area == 0)) {
1731 if (ndlpdid.un.b.id)
1737 matchdid.un.word = ndlp->nlp_DID;
1738 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1739 (mydid.un.b.area == ndlpdid.un.b.area)) {
1740 if ((matchdid.un.b.domain == 0) &&
1741 (matchdid.un.b.area == 0)) {
1742 if (matchdid.un.b.id)
1750 /* Search for a nodelist entry on a specific list */
1751 struct lpfc_nodelist *
1752 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1754 struct lpfc_nodelist *ndlp;
1755 struct list_head *lists[]={&phba->fc_nlpunmap_list,
1756 &phba->fc_nlpmap_list,
1757 &phba->fc_plogi_list,
1758 &phba->fc_adisc_list,
1759 &phba->fc_reglogin_list,
1760 &phba->fc_prli_list,
1762 &phba->fc_unused_list};
1763 uint32_t search[]={NLP_SEARCH_UNMAPPED,
1767 NLP_SEARCH_REGLOGIN,
1774 spin_lock_irq(phba->host->host_lock);
1775 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
1776 if (!(order & search[i]))
1778 list_for_each_entry(ndlp, lists[i], nlp_listp) {
1779 if (lpfc_matchdid(phba, ndlp, did)) {
1780 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1781 ((uint32_t) ndlp->nlp_xri << 16) |
1782 ((uint32_t) ndlp->nlp_type << 8) |
1783 ((uint32_t) ndlp->nlp_rpi & 0xff));
1784 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1785 "%d:0929 FIND node DID "
1786 " Data: x%p x%x x%x x%x\n",
1788 ndlp, ndlp->nlp_DID,
1789 ndlp->nlp_flag, data1);
1790 spin_unlock_irq(phba->host->host_lock);
1795 spin_unlock_irq(phba->host->host_lock);
1797 /* FIND node did <did> NOT FOUND */
1798 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1799 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1800 phba->brd_no, did, order);
1804 struct lpfc_nodelist *
1805 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1807 struct lpfc_nodelist *ndlp;
1810 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1812 if ((phba->fc_flag & FC_RSCN_MODE) &&
1813 ((lpfc_rscn_payload_check(phba, did) == 0)))
1815 ndlp = (struct lpfc_nodelist *)
1816 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1819 lpfc_nlp_init(phba, ndlp, did);
1820 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1821 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1824 if (phba->fc_flag & FC_RSCN_MODE) {
1825 if (lpfc_rscn_payload_check(phba, did)) {
1826 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1828 /* Since this node is marked for discovery,
1829 * delay timeout is not needed.
1831 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1832 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1836 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1837 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1839 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1840 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1845 /* Build a list of nodes to discover based on the loopmap */
1847 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1850 uint32_t alpa, index;
1852 if (phba->hba_state <= LPFC_LINK_DOWN) {
1855 if (phba->fc_topology != TOPOLOGY_LOOP) {
1859 /* Check for loop map present or not */
1860 if (phba->alpa_map[0]) {
1861 for (j = 1; j <= phba->alpa_map[0]; j++) {
1862 alpa = phba->alpa_map[j];
1864 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1867 lpfc_setup_disc_node(phba, alpa);
1870 /* No alpamap, so try all alpa's */
1871 for (j = 0; j < FC_MAXLOOP; j++) {
1872 /* If cfg_scan_down is set, start from highest
1873 * ALPA (0xef) to lowest (0x1).
1875 if (phba->cfg_scan_down)
1878 index = FC_MAXLOOP - j - 1;
1879 alpa = lpfcAlpaArray[index];
1880 if ((phba->fc_myDID & 0xff) == alpa) {
1884 lpfc_setup_disc_node(phba, alpa);
1890 /* Start Link up / RSCN discovery on NPR list */
1892 lpfc_disc_start(struct lpfc_hba * phba)
1894 struct lpfc_sli *psli;
1896 struct lpfc_nodelist *ndlp, *next_ndlp;
1897 uint32_t did_changed, num_sent;
1898 uint32_t clear_la_pending;
1903 if (phba->hba_state <= LPFC_LINK_DOWN) {
1906 if (phba->hba_state == LPFC_CLEAR_LA)
1907 clear_la_pending = 1;
1909 clear_la_pending = 0;
1911 if (phba->hba_state < LPFC_HBA_READY) {
1912 phba->hba_state = LPFC_DISC_AUTH;
1914 lpfc_set_disctmo(phba);
1916 if (phba->fc_prevDID == phba->fc_myDID) {
1921 phba->fc_prevDID = phba->fc_myDID;
1922 phba->num_disc_nodes = 0;
1924 /* Start Discovery state <hba_state> */
1925 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1926 "%d:0202 Start Discovery hba state x%x "
1927 "Data: x%x x%x x%x\n",
1928 phba->brd_no, phba->hba_state, phba->fc_flag,
1929 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1931 /* If our did changed, we MUST do PLOGI */
1932 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1934 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1936 spin_lock_irq(phba->host->host_lock);
1937 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1938 spin_unlock_irq(phba->host->host_lock);
1943 /* First do ADISCs - if any */
1944 num_sent = lpfc_els_disc_adisc(phba);
1949 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
1950 /* If we get here, there is nothing to ADISC */
1951 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1952 phba->hba_state = LPFC_CLEAR_LA;
1953 lpfc_clear_la(phba, mbox);
1954 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1955 rc = lpfc_sli_issue_mbox(phba, mbox,
1956 (MBX_NOWAIT | MBX_STOP_IOCB));
1957 if (rc == MBX_NOT_FINISHED) {
1958 mempool_free( mbox, phba->mbox_mem_pool);
1959 lpfc_disc_flush_list(phba);
1960 psli->ring[(psli->extra_ring)].flag &=
1961 ~LPFC_STOP_IOCB_EVENT;
1962 psli->ring[(psli->fcp_ring)].flag &=
1963 ~LPFC_STOP_IOCB_EVENT;
1964 psli->ring[(psli->next_ring)].flag &=
1965 ~LPFC_STOP_IOCB_EVENT;
1966 phba->hba_state = LPFC_HBA_READY;
1970 /* Next do PLOGIs - if any */
1971 num_sent = lpfc_els_disc_plogi(phba);
1976 if (phba->fc_flag & FC_RSCN_MODE) {
1977 /* Check to see if more RSCNs came in while we
1978 * were processing this one.
1980 if ((phba->fc_rscn_id_cnt == 0) &&
1981 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1982 spin_lock_irq(phba->host->host_lock);
1983 phba->fc_flag &= ~FC_RSCN_MODE;
1984 spin_unlock_irq(phba->host->host_lock);
1986 lpfc_els_handle_rscn(phba);
1993 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
1994 * ring the match the sppecified nodelist.
1997 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1999 LIST_HEAD(completions);
2000 struct lpfc_sli *psli;
2002 struct lpfc_iocbq *iocb, *next_iocb;
2003 struct lpfc_sli_ring *pring;
2006 pring = &psli->ring[LPFC_ELS_RING];
2008 /* Error matching iocb on txq or txcmplq
2009 * First check the txq.
2011 spin_lock_irq(phba->host->host_lock);
2012 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2013 if (iocb->context1 != ndlp) {
2017 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2018 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2020 list_move_tail(&iocb->list, &completions);
2025 /* Next check the txcmplq */
2026 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2027 if (iocb->context1 != ndlp) {
2031 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2032 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2033 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2036 spin_unlock_irq(phba->host->host_lock);
2038 while (!list_empty(&completions)) {
2039 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2040 list_del(&iocb->list);
2042 if (iocb->iocb_cmpl) {
2044 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2045 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2046 (iocb->iocb_cmpl) (phba, iocb, iocb);
2048 lpfc_sli_release_iocbq(phba, iocb);
2055 lpfc_disc_flush_list(struct lpfc_hba * phba)
2057 struct lpfc_nodelist *ndlp, *next_ndlp;
2059 if (phba->fc_plogi_cnt) {
2060 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2062 lpfc_free_tx(phba, ndlp);
2063 lpfc_nlp_remove(phba, ndlp);
2066 if (phba->fc_adisc_cnt) {
2067 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2069 lpfc_free_tx(phba, ndlp);
2070 lpfc_nlp_remove(phba, ndlp);
2076 /*****************************************************************************/
2078 * NAME: lpfc_disc_timeout
2080 * FUNCTION: Fibre Channel driver discovery timeout routine.
2082 * EXECUTION ENVIRONMENT: interrupt only
2090 /*****************************************************************************/
2092 lpfc_disc_timeout(unsigned long ptr)
2094 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2095 unsigned long flags = 0;
2097 if (unlikely(!phba))
2100 spin_lock_irqsave(phba->host->host_lock, flags);
2101 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2102 phba->work_hba_events |= WORKER_DISC_TMO;
2103 if (phba->work_wait)
2104 wake_up(phba->work_wait);
2106 spin_unlock_irqrestore(phba->host->host_lock, flags);
2111 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2113 struct lpfc_sli *psli;
2114 struct lpfc_nodelist *ndlp, *next_ndlp;
2115 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2116 int rc, clrlaerr = 0;
2118 if (unlikely(!phba))
2121 if (!(phba->fc_flag & FC_DISC_TMO))
2126 spin_lock_irq(phba->host->host_lock);
2127 phba->fc_flag &= ~FC_DISC_TMO;
2128 spin_unlock_irq(phba->host->host_lock);
2130 switch (phba->hba_state) {
2132 case LPFC_LOCAL_CFG_LINK:
2133 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2135 lpfc_printf_log(phba,
2138 "%d:0221 FAN timeout\n",
2141 /* Start discovery by sending FLOGI, clean up old rpis */
2142 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2144 if (ndlp->nlp_type & NLP_FABRIC) {
2145 /* Clean up the ndlp on Fabric connections */
2146 lpfc_drop_node(phba, ndlp);
2147 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2148 /* Fail outstanding IO now since device
2149 * is marked for PLOGI.
2151 lpfc_unreg_rpi(phba, ndlp);
2154 phba->hba_state = LPFC_FLOGI;
2155 lpfc_set_disctmo(phba);
2156 lpfc_initial_flogi(phba);
2160 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2161 /* Initial FLOGI timeout */
2162 lpfc_printf_log(phba,
2165 "%d:0222 Initial FLOGI timeout\n",
2168 /* Assume no Fabric and go on with discovery.
2169 * Check for outstanding ELS FLOGI to abort.
2172 /* FLOGI failed, so just use loop map to make discovery list */
2173 lpfc_disc_list_loopmap(phba);
2175 /* Start discovery */
2176 lpfc_disc_start(phba);
2179 case LPFC_FABRIC_CFG_LINK:
2180 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2182 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2183 "%d:0223 Timeout while waiting for NameServer "
2184 "login\n", phba->brd_no);
2186 /* Next look for NameServer ndlp */
2187 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2189 lpfc_nlp_remove(phba, ndlp);
2190 /* Start discovery */
2191 lpfc_disc_start(phba);
2195 /* Check for wait for NameServer Rsp timeout */
2196 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2197 "%d:0224 NameServer Query timeout "
2200 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2202 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2205 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2206 /* Try it one more time */
2207 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2211 phba->fc_ns_retry = 0;
2214 /* Nothing to authenticate, so CLEAR_LA right now */
2215 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2218 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2219 "%d:0226 Device Discovery "
2220 "completion error\n",
2222 phba->hba_state = LPFC_HBA_ERROR;
2226 phba->hba_state = LPFC_CLEAR_LA;
2227 lpfc_clear_la(phba, clearlambox);
2228 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2229 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2230 (MBX_NOWAIT | MBX_STOP_IOCB));
2231 if (rc == MBX_NOT_FINISHED) {
2232 mempool_free(clearlambox, phba->mbox_mem_pool);
2237 /* Setup and issue mailbox INITIALIZE LINK command */
2238 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2239 if (!initlinkmbox) {
2240 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2241 "%d:0206 Device Discovery "
2242 "completion error\n",
2244 phba->hba_state = LPFC_HBA_ERROR;
2248 lpfc_linkdown(phba);
2249 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2250 phba->cfg_link_speed);
2251 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2252 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2253 (MBX_NOWAIT | MBX_STOP_IOCB));
2254 if (rc == MBX_NOT_FINISHED)
2255 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2259 case LPFC_DISC_AUTH:
2260 /* Node Authentication timeout */
2261 lpfc_printf_log(phba,
2264 "%d:0227 Node Authentication timeout\n",
2266 lpfc_disc_flush_list(phba);
2267 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2270 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2271 "%d:0207 Device Discovery "
2272 "completion error\n",
2274 phba->hba_state = LPFC_HBA_ERROR;
2277 phba->hba_state = LPFC_CLEAR_LA;
2278 lpfc_clear_la(phba, clearlambox);
2279 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2280 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2281 (MBX_NOWAIT | MBX_STOP_IOCB));
2282 if (rc == MBX_NOT_FINISHED) {
2283 mempool_free(clearlambox, phba->mbox_mem_pool);
2289 /* CLEAR LA timeout */
2290 lpfc_printf_log(phba,
2293 "%d:0228 CLEAR LA timeout\n",
2298 case LPFC_HBA_READY:
2299 if (phba->fc_flag & FC_RSCN_MODE) {
2300 lpfc_printf_log(phba,
2303 "%d:0231 RSCN timeout Data: x%x x%x\n",
2305 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2307 /* Cleanup any outstanding ELS commands */
2308 lpfc_els_flush_cmd(phba);
2310 lpfc_els_flush_rscn(phba);
2311 lpfc_disc_flush_list(phba);
2317 lpfc_disc_flush_list(phba);
2318 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2319 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2320 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2321 phba->hba_state = LPFC_HBA_READY;
2328 * This routine handles processing a NameServer REG_LOGIN mailbox
2329 * command upon completion. It is setup in the LPFC_MBOXQ
2330 * as the completion routine when the command is
2331 * handed off to the SLI layer.
2334 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2336 struct lpfc_sli *psli;
2338 struct lpfc_dmabuf *mp;
2339 struct lpfc_nodelist *ndlp;
2344 ndlp = (struct lpfc_nodelist *) pmb->context2;
2345 mp = (struct lpfc_dmabuf *) (pmb->context1);
2347 pmb->context1 = NULL;
2349 ndlp->nlp_rpi = mb->un.varWords[0];
2350 ndlp->nlp_type |= NLP_FABRIC;
2351 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
2353 /* Start issuing Fabric-Device Management Interface (FDMI)
2354 * command to 0xfffffa (FDMI well known port)
2356 if (phba->cfg_fdmi_on == 1) {
2357 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2360 * Delay issuing FDMI command if fdmi-on=2
2361 * (supporting RPA/hostnmae)
2363 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2366 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2368 mempool_free( pmb, phba->mbox_mem_pool);
2374 * This routine looks up the ndlp lists
2375 * for the given RPI. If rpi found
2376 * it return the node list pointer
2379 struct lpfc_nodelist *
2380 __lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2382 struct lpfc_nodelist *ndlp;
2383 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2384 &phba->fc_nlpmap_list,
2385 &phba->fc_plogi_list,
2386 &phba->fc_adisc_list,
2387 &phba->fc_reglogin_list};
2390 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2391 list_for_each_entry(ndlp, lists[i], nlp_listp)
2392 if (ndlp->nlp_rpi == rpi) {
2398 struct lpfc_nodelist *
2399 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2401 struct lpfc_nodelist *ndlp;
2403 spin_lock_irq(phba->host->host_lock);
2404 ndlp = __lpfc_findnode_rpi(phba, rpi);
2405 spin_unlock_irq(phba->host->host_lock);
2410 * This routine looks up the ndlp lists
2411 * for the given WWPN. If WWPN found
2412 * it return the node list pointer
2415 struct lpfc_nodelist *
2416 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2417 struct lpfc_name * wwpn)
2419 struct lpfc_nodelist *ndlp;
2420 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2421 &phba->fc_nlpmap_list,
2423 &phba->fc_plogi_list,
2424 &phba->fc_adisc_list,
2425 &phba->fc_reglogin_list,
2426 &phba->fc_prli_list};
2427 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2432 NLP_SEARCH_REGLOGIN,
2436 spin_lock_irq(phba->host->host_lock);
2437 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2438 if (!(order & search[i]))
2440 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2441 if (memcmp(&ndlp->nlp_portname, wwpn,
2442 sizeof(struct lpfc_name)) == 0) {
2443 spin_unlock_irq(phba->host->host_lock);
2448 spin_unlock_irq(phba->host->host_lock);
2453 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2456 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2457 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2458 init_timer(&ndlp->nlp_delayfunc);
2459 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2460 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2461 ndlp->nlp_DID = did;
2462 ndlp->nlp_phba = phba;
2463 ndlp->nlp_sid = NLP_NO_SID;