1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
40 /* AlpaArray for assignment of scsid for scan-down and bind_method */
41 static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
57 static void lpfc_disc_timeout_handler(struct lpfc_hba *);
60 lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
64 spin_lock_irq(phba->host->host_lock);
65 if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
66 spin_unlock_irq(phba->host->host_lock);
70 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
72 if (ndlp->nlp_sid != NLP_NO_SID) {
74 /* flush the target */
75 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
76 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
78 spin_unlock_irq(phba->host->host_lock);
81 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
82 "%d:0203 Nodev timeout on NPort x%x "
83 "Data: x%x x%x x%x\n",
84 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
85 ndlp->nlp_state, ndlp->nlp_rpi);
87 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
88 "%d:0204 Nodev timeout on NPort x%x "
89 "Data: x%x x%x x%x\n",
90 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
91 ndlp->nlp_state, ndlp->nlp_rpi);
94 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
99 lpfc_work_list_done(struct lpfc_hba * phba)
101 struct lpfc_work_evt *evtp = NULL;
102 struct lpfc_nodelist *ndlp;
105 spin_lock_irq(phba->host->host_lock);
106 while(!list_empty(&phba->work_list)) {
107 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
109 spin_unlock_irq(phba->host->host_lock);
112 case LPFC_EVT_NODEV_TMO:
113 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
114 lpfc_process_nodev_timeout(phba, ndlp);
117 case LPFC_EVT_ELS_RETRY:
118 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
119 lpfc_els_retry_delay_handler(ndlp);
122 case LPFC_EVT_ONLINE:
123 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
124 complete((struct completion *)(evtp->evt_arg2));
126 case LPFC_EVT_OFFLINE:
127 *(int *)(evtp->evt_arg1) = lpfc_offline(phba);
128 complete((struct completion *)(evtp->evt_arg2));
133 spin_lock_irq(phba->host->host_lock);
135 spin_unlock_irq(phba->host->host_lock);
140 lpfc_work_done(struct lpfc_hba * phba)
142 struct lpfc_sli_ring *pring;
146 uint32_t work_hba_events;
148 spin_lock_irq(phba->host->host_lock);
149 ha_copy = phba->work_ha;
151 work_hba_events=phba->work_hba_events;
152 spin_unlock_irq(phba->host->host_lock);
154 if(ha_copy & HA_ERATT)
155 lpfc_handle_eratt(phba);
157 if(ha_copy & HA_MBATT)
158 lpfc_sli_handle_mb_event(phba);
160 if(ha_copy & HA_LATT)
161 lpfc_handle_latt(phba);
163 if (work_hba_events & WORKER_DISC_TMO)
164 lpfc_disc_timeout_handler(phba);
166 if (work_hba_events & WORKER_ELS_TMO)
167 lpfc_els_timeout_handler(phba);
169 if (work_hba_events & WORKER_MBOX_TMO)
170 lpfc_mbox_timeout_handler(phba);
172 if (work_hba_events & WORKER_FDMI_TMO)
173 lpfc_fdmi_tmo_handler(phba);
175 spin_lock_irq(phba->host->host_lock);
176 phba->work_hba_events &= ~work_hba_events;
177 spin_unlock_irq(phba->host->host_lock);
179 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
180 pring = &phba->sli.ring[i];
181 if ((ha_copy & HA_RXATT)
182 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
183 if (pring->flag & LPFC_STOP_IOCB_MASK) {
184 pring->flag |= LPFC_DEFERRED_RING_EVENT;
186 lpfc_sli_handle_slow_ring_event(phba, pring,
189 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
192 * Turn on Ring interrupts
194 spin_lock_irq(phba->host->host_lock);
195 control = readl(phba->HCregaddr);
196 control |= (HC_R0INT_ENA << i);
197 writel(control, phba->HCregaddr);
198 readl(phba->HCregaddr); /* flush */
199 spin_unlock_irq(phba->host->host_lock);
203 lpfc_work_list_done (phba);
208 check_work_wait_done(struct lpfc_hba *phba) {
210 spin_lock_irq(phba->host->host_lock);
212 phba->work_hba_events ||
213 (!list_empty(&phba->work_list)) ||
214 kthread_should_stop()) {
215 spin_unlock_irq(phba->host->host_lock);
218 spin_unlock_irq(phba->host->host_lock);
224 lpfc_do_work(void *p)
226 struct lpfc_hba *phba = p;
228 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
230 set_user_nice(current, -20);
231 phba->work_wait = &work_waitq;
235 rc = wait_event_interruptible(work_waitq,
236 check_work_wait_done(phba));
239 if (kthread_should_stop())
242 lpfc_work_done(phba);
245 phba->work_wait = NULL;
250 * This is only called to handle FC worker events. Since this a rare
251 * occurance, we allocate a struct lpfc_work_evt structure here instead of
252 * embedding it in the IOCB.
255 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
258 struct lpfc_work_evt *evtp;
261 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
262 * be queued to worker thread for processing
264 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
268 evtp->evt_arg1 = arg1;
269 evtp->evt_arg2 = arg2;
272 list_add_tail(&evtp->evt_listp, &phba->work_list);
273 spin_lock_irq(phba->host->host_lock);
275 wake_up(phba->work_wait);
276 spin_unlock_irq(phba->host->host_lock);
282 lpfc_linkdown(struct lpfc_hba * phba)
284 struct lpfc_sli *psli;
285 struct lpfc_nodelist *ndlp, *next_ndlp;
286 struct list_head *listp;
287 struct list_head *node_list[7];
293 spin_lock_irq(phba->host->host_lock);
294 phba->hba_state = LPFC_LINK_DOWN;
295 spin_unlock_irq(phba->host->host_lock);
297 /* Clean up any firmware default rpi's */
298 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
299 lpfc_unreg_did(phba, 0xffffffff, mb);
300 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
301 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
302 == MBX_NOT_FINISHED) {
303 mempool_free( mb, phba->mbox_mem_pool);
307 /* Cleanup any outstanding RSCN activity */
308 lpfc_els_flush_rscn(phba);
310 /* Cleanup any outstanding ELS commands */
311 lpfc_els_flush_cmd(phba);
313 /* Issue a LINK DOWN event to all nodes */
314 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
315 node_list[1] = &phba->fc_nlpmap_list;
316 node_list[2] = &phba->fc_nlpunmap_list;
317 node_list[3] = &phba->fc_prli_list;
318 node_list[4] = &phba->fc_reglogin_list;
319 node_list[5] = &phba->fc_adisc_list;
320 node_list[6] = &phba->fc_plogi_list;
321 for (i = 0; i < 7; i++) {
322 listp = node_list[i];
323 if (list_empty(listp))
326 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
327 /* Fabric nodes are not handled thru state machine for
329 if (ndlp->nlp_type & NLP_FABRIC) {
330 /* Remove ALL Fabric nodes except Fabric_DID */
331 if (ndlp->nlp_DID != Fabric_DID) {
332 /* Take it off current list and free */
333 lpfc_nlp_list(phba, ndlp,
339 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
340 NLP_EVT_DEVICE_RECOVERY);
342 /* Check config parameter use-adisc or FCP-2 */
343 if ((rc != NLP_STE_FREED_NODE) &&
344 (phba->cfg_use_adisc == 0) &&
345 !(ndlp->nlp_fcp_info &
347 /* We know we will have to relogin, so
348 * unreglogin the rpi right now to fail
349 * any outstanding I/Os quickly.
351 lpfc_unreg_rpi(phba, ndlp);
357 /* free any ndlp's on unused list */
358 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
360 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
363 /* Setup myDID for link up if we are in pt2pt mode */
364 if (phba->fc_flag & FC_PT2PT) {
366 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
367 lpfc_config_link(phba, mb);
368 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
369 if (lpfc_sli_issue_mbox
370 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
371 == MBX_NOT_FINISHED) {
372 mempool_free( mb, phba->mbox_mem_pool);
375 spin_lock_irq(phba->host->host_lock);
376 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
377 spin_unlock_irq(phba->host->host_lock);
379 spin_lock_irq(phba->host->host_lock);
380 phba->fc_flag &= ~FC_LBIT;
381 spin_unlock_irq(phba->host->host_lock);
383 /* Turn off discovery timer if its running */
384 lpfc_can_disctmo(phba);
386 /* Must process IOCBs on all rings to handle ABORTed I/Os */
391 lpfc_linkup(struct lpfc_hba * phba)
393 struct lpfc_nodelist *ndlp, *next_ndlp;
395 spin_lock_irq(phba->host->host_lock);
396 phba->hba_state = LPFC_LINK_UP;
397 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
398 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
399 phba->fc_flag |= FC_NDISC_ACTIVE;
400 phba->fc_ns_retry = 0;
401 spin_unlock_irq(phba->host->host_lock);
405 * Clean up old Fabric NLP_FABRIC logins.
407 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
409 if (ndlp->nlp_DID == Fabric_DID) {
410 /* Take it off current list and free */
411 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
415 /* free any ndlp's on unused list */
416 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
418 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
425 * This routine handles processing a CLEAR_LA mailbox
426 * command upon completion. It is setup in the LPFC_MBOXQ
427 * as the completion routine when the command is
428 * handed off to the SLI layer.
431 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
433 struct lpfc_sli *psli;
439 /* Since we don't do discovery right now, turn these off here */
440 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
441 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
442 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
444 /* Check for error */
445 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
446 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
447 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
448 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
450 phba->brd_no, mb->mbxStatus, phba->hba_state);
452 phba->hba_state = LPFC_HBA_ERROR;
456 if (phba->fc_flag & FC_ABORT_DISCOVERY)
459 phba->num_disc_nodes = 0;
460 /* go thru NPR list and issue ELS PLOGIs */
461 if (phba->fc_npr_cnt) {
462 lpfc_els_disc_plogi(phba);
465 if(!phba->num_disc_nodes) {
466 spin_lock_irq(phba->host->host_lock);
467 phba->fc_flag &= ~FC_NDISC_ACTIVE;
468 spin_unlock_irq(phba->host->host_lock);
471 phba->hba_state = LPFC_HBA_READY;
474 /* Device Discovery completes */
475 lpfc_printf_log(phba,
478 "%d:0225 Device Discovery completes\n",
481 mempool_free( pmb, phba->mbox_mem_pool);
483 spin_lock_irq(phba->host->host_lock);
484 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
485 if (phba->fc_flag & FC_ESTABLISH_LINK) {
486 phba->fc_flag &= ~FC_ESTABLISH_LINK;
488 spin_unlock_irq(phba->host->host_lock);
490 del_timer_sync(&phba->fc_estabtmo);
492 lpfc_can_disctmo(phba);
494 /* turn on Link Attention interrupts */
495 spin_lock_irq(phba->host->host_lock);
496 psli->sli_flag |= LPFC_PROCESS_LA;
497 control = readl(phba->HCregaddr);
498 control |= HC_LAINT_ENA;
499 writel(control, phba->HCregaddr);
500 readl(phba->HCregaddr); /* flush */
501 spin_unlock_irq(phba->host->host_lock);
507 lpfc_mbx_cmpl_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
509 struct lpfc_sli *psli;
514 /* Check for error */
516 /* CONFIG_LINK mbox error <mbxStatus> state <hba_state> */
517 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
518 "%d:0306 CONFIG_LINK mbxStatus error x%x "
520 phba->brd_no, mb->mbxStatus, phba->hba_state);
523 phba->hba_state = LPFC_HBA_ERROR;
527 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
528 if (phba->fc_topology == TOPOLOGY_LOOP) {
529 /* If we are public loop and L bit was set */
530 if ((phba->fc_flag & FC_PUBLIC_LOOP) &&
531 !(phba->fc_flag & FC_LBIT)) {
532 /* Need to wait for FAN - use discovery timer
533 * for timeout. hba_state is identically
534 * LPFC_LOCAL_CFG_LINK while waiting for FAN
536 lpfc_set_disctmo(phba);
537 mempool_free( pmb, phba->mbox_mem_pool);
542 /* Start discovery by sending a FLOGI hba_state is identically
543 * LPFC_FLOGI while waiting for FLOGI cmpl
545 phba->hba_state = LPFC_FLOGI;
546 lpfc_set_disctmo(phba);
547 lpfc_initial_flogi(phba);
548 mempool_free( pmb, phba->mbox_mem_pool);
551 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
552 mempool_free( pmb, phba->mbox_mem_pool);
557 /* CONFIG_LINK bad hba state <hba_state> */
558 lpfc_printf_log(phba,
561 "%d:0200 CONFIG_LINK bad hba state x%x\n",
562 phba->brd_no, phba->hba_state);
564 if (phba->hba_state != LPFC_CLEAR_LA) {
565 lpfc_clear_la(phba, pmb);
566 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
567 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
568 == MBX_NOT_FINISHED) {
569 mempool_free( pmb, phba->mbox_mem_pool);
570 lpfc_disc_flush_list(phba);
571 psli->ring[(psli->ip_ring)].flag &=
572 ~LPFC_STOP_IOCB_EVENT;
573 psli->ring[(psli->fcp_ring)].flag &=
574 ~LPFC_STOP_IOCB_EVENT;
575 psli->ring[(psli->next_ring)].flag &=
576 ~LPFC_STOP_IOCB_EVENT;
577 phba->hba_state = LPFC_HBA_READY;
580 mempool_free( pmb, phba->mbox_mem_pool);
586 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
588 struct lpfc_sli *psli = &phba->sli;
589 MAILBOX_t *mb = &pmb->mb;
590 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
593 /* Check for error */
595 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
596 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
597 "%d:0319 READ_SPARAM mbxStatus error x%x "
599 phba->brd_no, mb->mbxStatus, phba->hba_state);
602 phba->hba_state = LPFC_HBA_ERROR;
606 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
607 sizeof (struct serv_parm));
608 memcpy((uint8_t *) & phba->fc_nodename,
609 (uint8_t *) & phba->fc_sparam.nodeName,
610 sizeof (struct lpfc_name));
611 memcpy((uint8_t *) & phba->fc_portname,
612 (uint8_t *) & phba->fc_sparam.portName,
613 sizeof (struct lpfc_name));
614 lpfc_mbuf_free(phba, mp->virt, mp->phys);
616 mempool_free( pmb, phba->mbox_mem_pool);
620 pmb->context1 = NULL;
621 lpfc_mbuf_free(phba, mp->virt, mp->phys);
623 if (phba->hba_state != LPFC_CLEAR_LA) {
624 lpfc_clear_la(phba, pmb);
625 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
626 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
627 == MBX_NOT_FINISHED) {
628 mempool_free( pmb, phba->mbox_mem_pool);
629 lpfc_disc_flush_list(phba);
630 psli->ring[(psli->ip_ring)].flag &=
631 ~LPFC_STOP_IOCB_EVENT;
632 psli->ring[(psli->fcp_ring)].flag &=
633 ~LPFC_STOP_IOCB_EVENT;
634 psli->ring[(psli->next_ring)].flag &=
635 ~LPFC_STOP_IOCB_EVENT;
636 phba->hba_state = LPFC_HBA_READY;
639 mempool_free( pmb, phba->mbox_mem_pool);
645 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
648 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
649 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
650 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
652 spin_lock_irq(phba->host->host_lock);
653 switch(la->UlnkSpeed) {
655 phba->fc_linkspeed = LA_1GHZ_LINK;
658 phba->fc_linkspeed = LA_2GHZ_LINK;
661 phba->fc_linkspeed = LA_4GHZ_LINK;
664 phba->fc_linkspeed = LA_UNKNW_LINK;
668 phba->fc_topology = la->topology;
670 if (phba->fc_topology == TOPOLOGY_LOOP) {
671 /* Get Loop Map information */
674 phba->fc_flag |= FC_LBIT;
676 phba->fc_myDID = la->granted_AL_PA;
677 i = la->un.lilpBde64.tus.f.bdeSize;
680 phba->alpa_map[0] = 0;
682 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
693 numalpa = phba->alpa_map[0];
695 while (j < numalpa) {
696 memset(un.pamap, 0, 16);
697 for (k = 1; j < numalpa; k++) {
699 phba->alpa_map[j + 1];
704 /* Link Up Event ALPA map */
705 lpfc_printf_log(phba,
708 "%d:1304 Link Up Event "
709 "ALPA map Data: x%x "
712 un.pa.wd1, un.pa.wd2,
713 un.pa.wd3, un.pa.wd4);
718 phba->fc_myDID = phba->fc_pref_DID;
719 phba->fc_flag |= FC_LBIT;
721 spin_unlock_irq(phba->host->host_lock);
725 lpfc_read_sparam(phba, sparam_mbox);
726 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
727 lpfc_sli_issue_mbox(phba, sparam_mbox,
728 (MBX_NOWAIT | MBX_STOP_IOCB));
732 phba->hba_state = LPFC_LOCAL_CFG_LINK;
733 lpfc_config_link(phba, cfglink_mbox);
734 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_config_link;
735 lpfc_sli_issue_mbox(phba, cfglink_mbox,
736 (MBX_NOWAIT | MBX_STOP_IOCB));
741 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
743 struct lpfc_sli *psli = &phba->sli;
747 /* turn on Link Attention interrupts - no CLEAR_LA needed */
748 spin_lock_irq(phba->host->host_lock);
749 psli->sli_flag |= LPFC_PROCESS_LA;
750 control = readl(phba->HCregaddr);
751 control |= HC_LAINT_ENA;
752 writel(control, phba->HCregaddr);
753 readl(phba->HCregaddr); /* flush */
754 spin_unlock_irq(phba->host->host_lock);
758 * This routine handles processing a READ_LA mailbox
759 * command upon completion. It is setup in the LPFC_MBOXQ
760 * as the completion routine when the command is
761 * handed off to the SLI layer.
764 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
767 MAILBOX_t *mb = &pmb->mb;
768 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
770 /* Check for error */
772 lpfc_printf_log(phba,
775 "%d:1307 READ_LA mbox error x%x state x%x\n",
777 mb->mbxStatus, phba->hba_state);
778 lpfc_mbx_issue_link_down(phba);
779 phba->hba_state = LPFC_HBA_ERROR;
780 goto lpfc_mbx_cmpl_read_la_free_mbuf;
783 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
785 memcpy(&phba->alpa_map[0], mp->virt, 128);
787 if (((phba->fc_eventTag + 1) < la->eventTag) ||
788 (phba->fc_eventTag == la->eventTag)) {
789 phba->fc_stat.LinkMultiEvent++;
790 if (la->attType == AT_LINK_UP) {
791 if (phba->fc_eventTag != 0)
796 phba->fc_eventTag = la->eventTag;
798 if (la->attType == AT_LINK_UP) {
799 phba->fc_stat.LinkUp++;
800 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
801 "%d:1303 Link Up Event x%x received "
802 "Data: x%x x%x x%x x%x\n",
803 phba->brd_no, la->eventTag, phba->fc_eventTag,
804 la->granted_AL_PA, la->UlnkSpeed,
806 lpfc_mbx_process_link_up(phba, la);
808 phba->fc_stat.LinkDown++;
809 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
810 "%d:1305 Link Down Event x%x received "
811 "Data: x%x x%x x%x\n",
812 phba->brd_no, la->eventTag, phba->fc_eventTag,
813 phba->hba_state, phba->fc_flag);
814 lpfc_mbx_issue_link_down(phba);
817 lpfc_mbx_cmpl_read_la_free_mbuf:
818 lpfc_mbuf_free(phba, mp->virt, mp->phys);
820 mempool_free(pmb, phba->mbox_mem_pool);
825 * This routine handles processing a REG_LOGIN mailbox
826 * command upon completion. It is setup in the LPFC_MBOXQ
827 * as the completion routine when the command is
828 * handed off to the SLI layer.
831 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
833 struct lpfc_sli *psli;
835 struct lpfc_dmabuf *mp;
836 struct lpfc_nodelist *ndlp;
841 ndlp = (struct lpfc_nodelist *) pmb->context2;
842 mp = (struct lpfc_dmabuf *) (pmb->context1);
844 pmb->context1 = NULL;
846 /* Good status, call state machine */
847 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
848 lpfc_mbuf_free(phba, mp->virt, mp->phys);
850 mempool_free( pmb, phba->mbox_mem_pool);
856 * This routine handles processing a Fabric REG_LOGIN mailbox
857 * command upon completion. It is setup in the LPFC_MBOXQ
858 * as the completion routine when the command is
859 * handed off to the SLI layer.
862 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
864 struct lpfc_sli *psli;
866 struct lpfc_dmabuf *mp;
867 struct lpfc_nodelist *ndlp;
868 struct lpfc_nodelist *ndlp_fdmi;
874 ndlp = (struct lpfc_nodelist *) pmb->context2;
875 mp = (struct lpfc_dmabuf *) (pmb->context1);
878 lpfc_mbuf_free(phba, mp->virt, mp->phys);
880 mempool_free( pmb, phba->mbox_mem_pool);
881 mempool_free( ndlp, phba->nlp_mem_pool);
883 /* FLOGI failed, so just use loop map to make discovery list */
884 lpfc_disc_list_loopmap(phba);
886 /* Start discovery */
887 lpfc_disc_start(phba);
891 pmb->context1 = NULL;
893 ndlp->nlp_rpi = mb->un.varWords[0];
894 ndlp->nlp_type |= NLP_FABRIC;
895 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
896 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
898 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
899 /* This NPort has been assigned an NPort_ID by the fabric as a
900 * result of the completed fabric login. Issue a State Change
901 * Registration (SCR) ELS request to the fabric controller
902 * (SCR_DID) so that this NPort gets RSCN events from the
905 lpfc_issue_els_scr(phba, SCR_DID, 0);
907 /* Allocate a new node instance. If the pool is empty, just
908 * start the discovery process and skip the Nameserver login
909 * process. This is attempted again later on. Otherwise, issue
910 * a Port Login (PLOGI) to the NameServer
912 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
914 lpfc_disc_start(phba);
916 lpfc_nlp_init(phba, ndlp, NameServer_DID);
917 ndlp->nlp_type |= NLP_FABRIC;
918 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
919 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
920 lpfc_issue_els_plogi(phba, ndlp, 0);
921 if (phba->cfg_fdmi_on) {
922 if ((ndlp_fdmi = mempool_alloc(
925 lpfc_nlp_init(phba, ndlp_fdmi,
927 ndlp_fdmi->nlp_type |= NLP_FABRIC;
928 ndlp_fdmi->nlp_state =
930 lpfc_issue_els_plogi(phba, ndlp_fdmi,
937 lpfc_mbuf_free(phba, mp->virt, mp->phys);
939 mempool_free( pmb, phba->mbox_mem_pool);
945 * This routine handles processing a NameServer REG_LOGIN mailbox
946 * command upon completion. It is setup in the LPFC_MBOXQ
947 * as the completion routine when the command is
948 * handed off to the SLI layer.
951 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
953 struct lpfc_sli *psli;
955 struct lpfc_dmabuf *mp;
956 struct lpfc_nodelist *ndlp;
961 ndlp = (struct lpfc_nodelist *) pmb->context2;
962 mp = (struct lpfc_dmabuf *) (pmb->context1);
965 lpfc_mbuf_free(phba, mp->virt, mp->phys);
967 mempool_free( pmb, phba->mbox_mem_pool);
968 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
970 /* RegLogin failed, so just use loop map to make discovery
972 lpfc_disc_list_loopmap(phba);
974 /* Start discovery */
975 lpfc_disc_start(phba);
979 pmb->context1 = NULL;
981 ndlp->nlp_rpi = mb->un.varWords[0];
982 ndlp->nlp_type |= NLP_FABRIC;
983 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
984 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
986 if (phba->hba_state < LPFC_HBA_READY) {
987 /* Link up discovery requires Fabrib registration. */
988 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
989 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
990 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
993 phba->fc_ns_retry = 0;
994 /* Good status, issue CT Request to NameServer */
995 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
996 /* Cannot issue NameServer Query, so finish up discovery */
997 lpfc_disc_start(phba);
1000 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1002 mempool_free( pmb, phba->mbox_mem_pool);
1008 lpfc_register_remote_port(struct lpfc_hba * phba,
1009 struct lpfc_nodelist * ndlp)
1011 struct fc_rport *rport;
1012 struct lpfc_rport_data *rdata;
1013 struct fc_rport_identifiers rport_ids;
1015 /* Remote port has reappeared. Re-register w/ FC transport */
1016 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1017 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1018 rport_ids.port_id = ndlp->nlp_DID;
1019 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1020 if (ndlp->nlp_type & NLP_FCP_TARGET)
1021 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1022 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1023 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1025 scsi_block_requests(phba->host);
1026 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1028 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1029 "Warning: fc_remote_port_add failed\n");
1033 /* initialize static port data */
1034 rport->maxframe_size = ndlp->nlp_maxframe;
1035 rport->supported_classes = ndlp->nlp_class_sup;
1036 if ((rport->scsi_target_id != -1) &&
1037 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1038 ndlp->nlp_sid = rport->scsi_target_id;
1040 rdata = rport->dd_data;
1041 rdata->pnode = ndlp;
1042 scsi_unblock_requests(phba->host);
1048 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1049 struct lpfc_nodelist * ndlp)
1051 struct fc_rport *rport = ndlp->rport;
1052 struct lpfc_rport_data *rdata = rport->dd_data;
1055 rdata->pnode = NULL;
1056 scsi_block_requests(phba->host);
1057 fc_remote_port_delete(rport);
1058 scsi_unblock_requests(phba->host);
1064 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1066 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1067 struct lpfc_sli *psli;
1070 /* Sanity check to ensure we are not moving to / from the same list */
1071 if ((nlp->nlp_flag & NLP_LIST_MASK) == list) {
1072 if (list != NLP_NO_LIST)
1076 switch(nlp->nlp_flag & NLP_LIST_MASK) {
1077 case NLP_NO_LIST: /* Not on any list */
1079 case NLP_UNUSED_LIST:
1080 phba->fc_unused_cnt--;
1081 list_del(&nlp->nlp_listp);
1083 case NLP_PLOGI_LIST:
1084 phba->fc_plogi_cnt--;
1085 list_del(&nlp->nlp_listp);
1087 case NLP_ADISC_LIST:
1088 phba->fc_adisc_cnt--;
1089 list_del(&nlp->nlp_listp);
1091 case NLP_REGLOGIN_LIST:
1092 phba->fc_reglogin_cnt--;
1093 list_del(&nlp->nlp_listp);
1096 phba->fc_prli_cnt--;
1097 list_del(&nlp->nlp_listp);
1099 case NLP_UNMAPPED_LIST:
1100 phba->fc_unmap_cnt--;
1101 list_del(&nlp->nlp_listp);
1102 spin_lock_irq(phba->host->host_lock);
1103 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1104 nlp->nlp_type &= ~NLP_FC_NODE;
1105 spin_unlock_irq(phba->host->host_lock);
1106 phba->nport_event_cnt++;
1108 rport_del = unmapped;
1110 case NLP_MAPPED_LIST:
1112 list_del(&nlp->nlp_listp);
1113 phba->nport_event_cnt++;
1119 list_del(&nlp->nlp_listp);
1120 /* Stop delay tmo if taking node off NPR list */
1121 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1122 (list != NLP_NPR_LIST)) {
1123 spin_lock_irq(phba->host->host_lock);
1124 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1125 spin_unlock_irq(phba->host->host_lock);
1126 del_timer_sync(&nlp->nlp_delayfunc);
1127 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1128 list_del_init(&nlp->els_retry_evt.evt_listp);
1133 spin_lock_irq(phba->host->host_lock);
1134 nlp->nlp_flag &= ~NLP_LIST_MASK;
1135 spin_unlock_irq(phba->host->host_lock);
1137 /* Add NPort <did> to <num> list */
1138 lpfc_printf_log(phba,
1141 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1143 nlp->nlp_DID, list, nlp->nlp_flag);
1146 case NLP_NO_LIST: /* No list, just remove it */
1147 lpfc_nlp_remove(phba, nlp);
1148 /* as node removed - stop further transport calls */
1151 case NLP_UNUSED_LIST:
1152 spin_lock_irq(phba->host->host_lock);
1153 nlp->nlp_flag |= list;
1154 spin_unlock_irq(phba->host->host_lock);
1155 /* Put it at the end of the unused list */
1156 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1157 phba->fc_unused_cnt++;
1159 case NLP_PLOGI_LIST:
1160 spin_lock_irq(phba->host->host_lock);
1161 nlp->nlp_flag |= list;
1162 spin_unlock_irq(phba->host->host_lock);
1163 /* Put it at the end of the plogi list */
1164 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1165 phba->fc_plogi_cnt++;
1167 case NLP_ADISC_LIST:
1168 spin_lock_irq(phba->host->host_lock);
1169 nlp->nlp_flag |= list;
1170 spin_unlock_irq(phba->host->host_lock);
1171 /* Put it at the end of the adisc list */
1172 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1173 phba->fc_adisc_cnt++;
1175 case NLP_REGLOGIN_LIST:
1176 spin_lock_irq(phba->host->host_lock);
1177 nlp->nlp_flag |= list;
1178 spin_unlock_irq(phba->host->host_lock);
1179 /* Put it at the end of the reglogin list */
1180 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1181 phba->fc_reglogin_cnt++;
1184 spin_lock_irq(phba->host->host_lock);
1185 nlp->nlp_flag |= list;
1186 spin_unlock_irq(phba->host->host_lock);
1187 /* Put it at the end of the prli list */
1188 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1189 phba->fc_prli_cnt++;
1191 case NLP_UNMAPPED_LIST:
1192 rport_add = unmapped;
1193 /* ensure all vestiges of "mapped" significance are gone */
1194 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1195 spin_lock_irq(phba->host->host_lock);
1196 nlp->nlp_flag |= list;
1197 spin_unlock_irq(phba->host->host_lock);
1198 /* Put it at the end of the unmap list */
1199 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1200 phba->fc_unmap_cnt++;
1201 phba->nport_event_cnt++;
1202 /* stop nodev tmo if running */
1203 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1204 spin_lock_irq(phba->host->host_lock);
1205 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1206 spin_unlock_irq(phba->host->host_lock);
1207 del_timer_sync(&nlp->nlp_tmofunc);
1208 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1209 list_del_init(&nlp->nodev_timeout_evt.
1213 nlp->nlp_type |= NLP_FC_NODE;
1215 case NLP_MAPPED_LIST:
1217 spin_lock_irq(phba->host->host_lock);
1218 nlp->nlp_flag |= list;
1219 spin_unlock_irq(phba->host->host_lock);
1220 /* Put it at the end of the map list */
1221 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1223 phba->nport_event_cnt++;
1224 /* stop nodev tmo if running */
1225 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1226 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1227 del_timer_sync(&nlp->nlp_tmofunc);
1228 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1229 list_del_init(&nlp->nodev_timeout_evt.
1235 spin_lock_irq(phba->host->host_lock);
1236 nlp->nlp_flag |= list;
1237 spin_unlock_irq(phba->host->host_lock);
1238 /* Put it at the end of the npr list */
1239 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1243 * Sanity check for Fabric entity.
1244 * Set nodev_tmo for NPR state, for Fabric use 1 sec.
1246 if (nlp->nlp_type & NLP_FABRIC) {
1247 mod_timer(&nlp->nlp_tmofunc, jiffies + HZ);
1250 mod_timer(&nlp->nlp_tmofunc,
1251 jiffies + HZ * phba->cfg_nodev_tmo);
1253 spin_lock_irq(phba->host->host_lock);
1254 nlp->nlp_flag |= NLP_NODEV_TMO;
1255 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1256 spin_unlock_irq(phba->host->host_lock);
1263 * We make all the calls into the transport after we have
1264 * moved the node between lists. This so that we don't
1265 * release the lock while in-between lists.
1268 /* Don't upcall midlayer if we're unloading */
1269 if (!(phba->fc_flag & FC_UNLOADING)) {
1271 * We revalidate the rport pointer as the "add" function
1272 * may have removed the remote port.
1274 if ((rport_del != none) && nlp->rport)
1275 lpfc_unregister_remote_port(phba, nlp);
1277 if (rport_add != none) {
1279 * Tell the fc transport about the port, if we haven't
1280 * already. If we have, and it's a scsi entity, be
1281 * sure to unblock any attached scsi devices
1284 lpfc_register_remote_port(phba, nlp);
1287 * if we added to Mapped list, but the remote port
1288 * registration failed or assigned a target id outside
1289 * our presentable range - move the node to the
1292 if ((rport_add == mapped) &&
1294 (nlp->rport->scsi_target_id == -1) ||
1295 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1296 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1297 spin_lock_irq(phba->host->host_lock);
1298 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1299 spin_unlock_irq(phba->host->host_lock);
1300 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1308 * Start / ReStart rescue timer for Discovery / RSCN handling
1311 lpfc_set_disctmo(struct lpfc_hba * phba)
1315 tmo = ((phba->fc_ratov * 2) + 1);
1317 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1318 spin_lock_irq(phba->host->host_lock);
1319 phba->fc_flag |= FC_DISC_TMO;
1320 spin_unlock_irq(phba->host->host_lock);
1322 /* Start Discovery Timer state <hba_state> */
1323 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1324 "%d:0247 Start Discovery Timer state x%x "
1325 "Data: x%x x%lx x%x x%x\n",
1327 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1328 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1334 * Cancel rescue timer for Discovery / RSCN handling
1337 lpfc_can_disctmo(struct lpfc_hba * phba)
1339 /* Turn off discovery timer if its running */
1340 if (phba->fc_flag & FC_DISC_TMO) {
1341 spin_lock_irq(phba->host->host_lock);
1342 phba->fc_flag &= ~FC_DISC_TMO;
1343 spin_unlock_irq(phba->host->host_lock);
1344 del_timer_sync(&phba->fc_disctmo);
1345 phba->work_hba_events &= ~WORKER_DISC_TMO;
1348 /* Cancel Discovery Timer state <hba_state> */
1349 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1350 "%d:0248 Cancel Discovery Timer state x%x "
1351 "Data: x%x x%x x%x\n",
1352 phba->brd_no, phba->hba_state, phba->fc_flag,
1353 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1359 * Check specified ring for outstanding IOCB on the SLI queue
1360 * Return true if iocb matches the specified nport
1363 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1364 struct lpfc_sli_ring * pring,
1365 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1367 struct lpfc_sli *psli;
1372 if (pring->ringno == LPFC_ELS_RING) {
1373 switch (icmd->ulpCommand) {
1374 case CMD_GEN_REQUEST64_CR:
1375 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1377 case CMD_ELS_REQUEST64_CR:
1378 case CMD_XMIT_ELS_RSP64_CX:
1379 if (iocb->context1 == (uint8_t *) ndlp)
1382 } else if (pring->ringno == psli->ip_ring) {
1384 } else if (pring->ringno == psli->fcp_ring) {
1385 /* Skip match check if waiting to relogin to FCP target */
1386 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1387 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1390 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1393 } else if (pring->ringno == psli->next_ring) {
1400 * Free resources / clean up outstanding I/Os
1401 * associated with nlp_rpi in the LPFC_NODELIST entry.
1404 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1406 struct lpfc_sli *psli;
1407 struct lpfc_sli_ring *pring;
1408 struct lpfc_iocbq *iocb, *next_iocb;
1413 * Everything that matches on txcmplq will be returned
1414 * by firmware with a no rpi error.
1417 rpi = ndlp->nlp_rpi;
1419 /* Now process each ring */
1420 for (i = 0; i < psli->num_rings; i++) {
1421 pring = &psli->ring[i];
1423 spin_lock_irq(phba->host->host_lock);
1424 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1427 * Check to see if iocb matches the nport we are
1430 if ((lpfc_check_sli_ndlp
1431 (phba, pring, iocb, ndlp))) {
1432 /* It matches, so deque and call compl
1434 list_del(&iocb->list);
1436 if (iocb->iocb_cmpl) {
1439 IOSTAT_LOCAL_REJECT;
1440 icmd->un.ulpWord[4] =
1442 spin_unlock_irq(phba->host->
1444 (iocb->iocb_cmpl) (phba,
1446 spin_lock_irq(phba->host->
1449 lpfc_sli_release_iocbq(phba,
1453 spin_unlock_irq(phba->host->host_lock);
1461 * Free rpi associated with LPFC_NODELIST entry.
1462 * This routine is called from lpfc_freenode(), when we are removing
1463 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1464 * LOGO that completes successfully, and we are waiting to PLOGI back
1465 * to the remote NPort. In addition, it is called after we receive
1466 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1467 * we are waiting to PLOGI back to the remote NPort.
1470 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1475 if (ndlp->nlp_rpi) {
1476 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1477 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1478 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1479 rc = lpfc_sli_issue_mbox
1480 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1481 if (rc == MBX_NOT_FINISHED)
1482 mempool_free( mbox, phba->mbox_mem_pool);
1484 lpfc_no_rpi(phba, ndlp);
1492 * Free resources associated with LPFC_NODELIST entry
1493 * so it can be freed.
1496 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1499 LPFC_MBOXQ_t *nextmb;
1500 struct lpfc_dmabuf *mp;
1502 /* Cleanup node for NPort <nlp_DID> */
1503 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1504 "%d:0900 Cleanup node for NPort x%x "
1505 "Data: x%x x%x x%x\n",
1506 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1507 ndlp->nlp_state, ndlp->nlp_rpi);
1509 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1512 * if unloading the driver - just leave the remote port in place.
1513 * The driver unload will force the attached devices to detach
1514 * and flush cache's w/o generating flush errors.
1516 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1517 lpfc_unregister_remote_port(phba, ndlp);
1518 ndlp->nlp_sid = NLP_NO_SID;
1521 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1522 if ((mb = phba->sli.mbox_active)) {
1523 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1524 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1525 mb->context2 = NULL;
1526 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1529 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1530 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1531 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1532 mp = (struct lpfc_dmabuf *) (mb->context1);
1534 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1537 list_del(&mb->list);
1538 mempool_free(mb, phba->mbox_mem_pool);
1542 lpfc_els_abort(phba,ndlp,0);
1543 spin_lock_irq(phba->host->host_lock);
1544 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1545 spin_unlock_irq(phba->host->host_lock);
1546 del_timer_sync(&ndlp->nlp_tmofunc);
1548 del_timer_sync(&ndlp->nlp_delayfunc);
1550 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1551 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1552 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1553 list_del_init(&ndlp->els_retry_evt.evt_listp);
1555 lpfc_unreg_rpi(phba, ndlp);
1561 * Check to see if we can free the nlp back to the freelist.
1562 * If we are in the middle of using the nlp in the discovery state
1563 * machine, defer the free till we reach the end of the state machine.
1566 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1568 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1569 spin_lock_irq(phba->host->host_lock);
1570 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1571 spin_unlock_irq(phba->host->host_lock);
1572 del_timer_sync(&ndlp->nlp_tmofunc);
1573 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1574 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1579 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1580 spin_lock_irq(phba->host->host_lock);
1581 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1582 spin_unlock_irq(phba->host->host_lock);
1583 del_timer_sync(&ndlp->nlp_delayfunc);
1584 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1585 list_del_init(&ndlp->els_retry_evt.evt_listp);
1588 if (ndlp->nlp_disc_refcnt) {
1589 spin_lock_irq(phba->host->host_lock);
1590 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1591 spin_unlock_irq(phba->host->host_lock);
1594 lpfc_freenode(phba, ndlp);
1595 mempool_free( ndlp, phba->nlp_mem_pool);
1601 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1607 if (did == Bcast_DID)
1610 if (ndlp->nlp_DID == 0) {
1614 /* First check for Direct match */
1615 if (ndlp->nlp_DID == did)
1618 /* Next check for area/domain identically equals 0 match */
1619 mydid.un.word = phba->fc_myDID;
1620 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1624 matchdid.un.word = did;
1625 ndlpdid.un.word = ndlp->nlp_DID;
1626 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1627 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1628 (mydid.un.b.area == matchdid.un.b.area)) {
1629 if ((ndlpdid.un.b.domain == 0) &&
1630 (ndlpdid.un.b.area == 0)) {
1631 if (ndlpdid.un.b.id)
1637 matchdid.un.word = ndlp->nlp_DID;
1638 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1639 (mydid.un.b.area == ndlpdid.un.b.area)) {
1640 if ((matchdid.un.b.domain == 0) &&
1641 (matchdid.un.b.area == 0)) {
1642 if (matchdid.un.b.id)
1650 /* Search for a nodelist entry on a specific list */
1651 struct lpfc_nodelist *
1652 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1654 struct lpfc_nodelist *ndlp, *next_ndlp;
1657 if (order & NLP_SEARCH_UNMAPPED) {
1658 list_for_each_entry_safe(ndlp, next_ndlp,
1659 &phba->fc_nlpunmap_list, nlp_listp) {
1660 if (lpfc_matchdid(phba, ndlp, did)) {
1661 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1662 ((uint32_t) ndlp->nlp_xri << 16) |
1663 ((uint32_t) ndlp->nlp_type << 8) |
1664 ((uint32_t) ndlp->nlp_rpi & 0xff));
1665 /* FIND node DID unmapped */
1666 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1667 "%d:0929 FIND node DID unmapped"
1668 " Data: x%p x%x x%x x%x\n",
1670 ndlp, ndlp->nlp_DID,
1671 ndlp->nlp_flag, data1);
1677 if (order & NLP_SEARCH_MAPPED) {
1678 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1680 if (lpfc_matchdid(phba, ndlp, did)) {
1682 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1683 ((uint32_t) ndlp->nlp_xri << 16) |
1684 ((uint32_t) ndlp->nlp_type << 8) |
1685 ((uint32_t) ndlp->nlp_rpi & 0xff));
1686 /* FIND node DID mapped */
1687 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1688 "%d:0930 FIND node DID mapped "
1689 "Data: x%p x%x x%x x%x\n",
1691 ndlp, ndlp->nlp_DID,
1692 ndlp->nlp_flag, data1);
1698 if (order & NLP_SEARCH_PLOGI) {
1699 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1701 if (lpfc_matchdid(phba, ndlp, did)) {
1703 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1704 ((uint32_t) ndlp->nlp_xri << 16) |
1705 ((uint32_t) ndlp->nlp_type << 8) |
1706 ((uint32_t) ndlp->nlp_rpi & 0xff));
1707 /* LOG change to PLOGI */
1708 /* FIND node DID plogi */
1709 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1710 "%d:0908 FIND node DID plogi "
1711 "Data: x%p x%x x%x x%x\n",
1713 ndlp, ndlp->nlp_DID,
1714 ndlp->nlp_flag, data1);
1720 if (order & NLP_SEARCH_ADISC) {
1721 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1723 if (lpfc_matchdid(phba, ndlp, did)) {
1725 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1726 ((uint32_t) ndlp->nlp_xri << 16) |
1727 ((uint32_t) ndlp->nlp_type << 8) |
1728 ((uint32_t) ndlp->nlp_rpi & 0xff));
1729 /* LOG change to ADISC */
1730 /* FIND node DID adisc */
1731 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1732 "%d:0931 FIND node DID adisc "
1733 "Data: x%p x%x x%x x%x\n",
1735 ndlp, ndlp->nlp_DID,
1736 ndlp->nlp_flag, data1);
1742 if (order & NLP_SEARCH_REGLOGIN) {
1743 list_for_each_entry_safe(ndlp, next_ndlp,
1744 &phba->fc_reglogin_list, nlp_listp) {
1745 if (lpfc_matchdid(phba, ndlp, did)) {
1747 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1748 ((uint32_t) ndlp->nlp_xri << 16) |
1749 ((uint32_t) ndlp->nlp_type << 8) |
1750 ((uint32_t) ndlp->nlp_rpi & 0xff));
1751 /* LOG change to REGLOGIN */
1752 /* FIND node DID reglogin */
1753 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1754 "%d:0931 FIND node DID reglogin"
1755 " Data: x%p x%x x%x x%x\n",
1757 ndlp, ndlp->nlp_DID,
1758 ndlp->nlp_flag, data1);
1764 if (order & NLP_SEARCH_PRLI) {
1765 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1767 if (lpfc_matchdid(phba, ndlp, did)) {
1769 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1770 ((uint32_t) ndlp->nlp_xri << 16) |
1771 ((uint32_t) ndlp->nlp_type << 8) |
1772 ((uint32_t) ndlp->nlp_rpi & 0xff));
1773 /* LOG change to PRLI */
1774 /* FIND node DID prli */
1775 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1776 "%d:0931 FIND node DID prli "
1777 "Data: x%p x%x x%x x%x\n",
1779 ndlp, ndlp->nlp_DID,
1780 ndlp->nlp_flag, data1);
1786 if (order & NLP_SEARCH_NPR) {
1787 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1789 if (lpfc_matchdid(phba, ndlp, did)) {
1791 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1792 ((uint32_t) ndlp->nlp_xri << 16) |
1793 ((uint32_t) ndlp->nlp_type << 8) |
1794 ((uint32_t) ndlp->nlp_rpi & 0xff));
1795 /* LOG change to NPR */
1796 /* FIND node DID npr */
1797 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1798 "%d:0931 FIND node DID npr "
1799 "Data: x%p x%x x%x x%x\n",
1801 ndlp, ndlp->nlp_DID,
1802 ndlp->nlp_flag, data1);
1808 if (order & NLP_SEARCH_UNUSED) {
1809 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1811 if (lpfc_matchdid(phba, ndlp, did)) {
1813 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1814 ((uint32_t) ndlp->nlp_xri << 16) |
1815 ((uint32_t) ndlp->nlp_type << 8) |
1816 ((uint32_t) ndlp->nlp_rpi & 0xff));
1817 /* LOG change to UNUSED */
1818 /* FIND node DID unused */
1819 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1820 "%d:0931 FIND node DID unused "
1821 "Data: x%p x%x x%x x%x\n",
1823 ndlp, ndlp->nlp_DID,
1824 ndlp->nlp_flag, data1);
1830 /* FIND node did <did> NOT FOUND */
1831 lpfc_printf_log(phba,
1834 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1835 phba->brd_no, did, order);
1837 /* no match found */
1841 struct lpfc_nodelist *
1842 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1844 struct lpfc_nodelist *ndlp;
1847 if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
1848 if ((phba->hba_state == LPFC_HBA_READY) &&
1849 ((lpfc_rscn_payload_check(phba, did) == 0)))
1851 ndlp = (struct lpfc_nodelist *)
1852 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1855 lpfc_nlp_init(phba, ndlp, did);
1856 ndlp->nlp_state = NLP_STE_NPR_NODE;
1857 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1858 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1861 if ((phba->hba_state == LPFC_HBA_READY) &&
1862 (phba->fc_flag & FC_RSCN_MODE)) {
1863 if (lpfc_rscn_payload_check(phba, did)) {
1864 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1867 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1872 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1873 if ((flg == NLP_ADISC_LIST) ||
1874 (flg == NLP_PLOGI_LIST)) {
1877 ndlp->nlp_state = NLP_STE_NPR_NODE;
1878 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1879 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1884 /* Build a list of nodes to discover based on the loopmap */
1886 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1889 uint32_t alpa, index;
1891 if (phba->hba_state <= LPFC_LINK_DOWN) {
1894 if (phba->fc_topology != TOPOLOGY_LOOP) {
1898 /* Check for loop map present or not */
1899 if (phba->alpa_map[0]) {
1900 for (j = 1; j <= phba->alpa_map[0]; j++) {
1901 alpa = phba->alpa_map[j];
1903 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1906 lpfc_setup_disc_node(phba, alpa);
1909 /* No alpamap, so try all alpa's */
1910 for (j = 0; j < FC_MAXLOOP; j++) {
1911 /* If cfg_scan_down is set, start from highest
1912 * ALPA (0xef) to lowest (0x1).
1914 if (phba->cfg_scan_down)
1917 index = FC_MAXLOOP - j - 1;
1918 alpa = lpfcAlpaArray[index];
1919 if ((phba->fc_myDID & 0xff) == alpa) {
1923 lpfc_setup_disc_node(phba, alpa);
1929 /* Start Link up / RSCN discovery on NPR list */
1931 lpfc_disc_start(struct lpfc_hba * phba)
1933 struct lpfc_sli *psli;
1935 struct lpfc_nodelist *ndlp, *next_ndlp;
1936 uint32_t did_changed, num_sent;
1937 uint32_t clear_la_pending;
1942 if (phba->hba_state <= LPFC_LINK_DOWN) {
1945 if (phba->hba_state == LPFC_CLEAR_LA)
1946 clear_la_pending = 1;
1948 clear_la_pending = 0;
1950 if (phba->hba_state < LPFC_HBA_READY) {
1951 phba->hba_state = LPFC_DISC_AUTH;
1953 lpfc_set_disctmo(phba);
1955 if (phba->fc_prevDID == phba->fc_myDID) {
1960 phba->fc_prevDID = phba->fc_myDID;
1961 phba->num_disc_nodes = 0;
1963 /* Start Discovery state <hba_state> */
1964 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1965 "%d:0202 Start Discovery hba state x%x "
1966 "Data: x%x x%x x%x\n",
1967 phba->brd_no, phba->hba_state, phba->fc_flag,
1968 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1970 /* If our did changed, we MUST do PLOGI */
1971 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1973 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1975 spin_lock_irq(phba->host->host_lock);
1976 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1977 spin_unlock_irq(phba->host->host_lock);
1982 /* First do ADISCs - if any */
1983 num_sent = lpfc_els_disc_adisc(phba);
1988 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
1989 /* If we get here, there is nothing to ADISC */
1990 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1991 phba->hba_state = LPFC_CLEAR_LA;
1992 lpfc_clear_la(phba, mbox);
1993 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1994 rc = lpfc_sli_issue_mbox(phba, mbox,
1995 (MBX_NOWAIT | MBX_STOP_IOCB));
1996 if (rc == MBX_NOT_FINISHED) {
1997 mempool_free( mbox, phba->mbox_mem_pool);
1998 lpfc_disc_flush_list(phba);
1999 psli->ring[(psli->ip_ring)].flag &=
2000 ~LPFC_STOP_IOCB_EVENT;
2001 psli->ring[(psli->fcp_ring)].flag &=
2002 ~LPFC_STOP_IOCB_EVENT;
2003 psli->ring[(psli->next_ring)].flag &=
2004 ~LPFC_STOP_IOCB_EVENT;
2005 phba->hba_state = LPFC_HBA_READY;
2009 /* Next do PLOGIs - if any */
2010 num_sent = lpfc_els_disc_plogi(phba);
2015 if (phba->fc_flag & FC_RSCN_MODE) {
2016 /* Check to see if more RSCNs came in while we
2017 * were processing this one.
2019 if ((phba->fc_rscn_id_cnt == 0) &&
2020 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2021 spin_lock_irq(phba->host->host_lock);
2022 phba->fc_flag &= ~FC_RSCN_MODE;
2023 spin_unlock_irq(phba->host->host_lock);
2026 lpfc_els_handle_rscn(phba);
2033 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2034 * ring the match the sppecified nodelist.
2037 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2039 struct lpfc_sli *psli;
2041 struct lpfc_iocbq *iocb, *next_iocb;
2042 struct lpfc_sli_ring *pring;
2043 struct lpfc_dmabuf *mp;
2046 pring = &psli->ring[LPFC_ELS_RING];
2048 /* Error matching iocb on txq or txcmplq
2049 * First check the txq.
2051 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2052 if (iocb->context1 != ndlp) {
2056 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2057 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2059 list_del(&iocb->list);
2061 lpfc_els_free_iocb(phba, iocb);
2065 /* Next check the txcmplq */
2066 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2067 if (iocb->context1 != ndlp) {
2071 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2072 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2074 iocb->iocb_cmpl = NULL;
2075 /* context2 = cmd, context2->next = rsp, context3 =
2077 if (iocb->context2) {
2078 /* Free the response IOCB before handling the
2081 mp = (struct lpfc_dmabuf *) (iocb->context2);
2082 mp = list_get_first(&mp->list,
2086 /* Delay before releasing rsp buffer to
2087 * give UNREG mbox a chance to take
2091 &phba->freebufList);
2093 lpfc_mbuf_free(phba,
2094 ((struct lpfc_dmabuf *)
2095 iocb->context2)->virt,
2096 ((struct lpfc_dmabuf *)
2097 iocb->context2)->phys);
2098 kfree(iocb->context2);
2101 if (iocb->context3) {
2102 lpfc_mbuf_free(phba,
2103 ((struct lpfc_dmabuf *)
2104 iocb->context3)->virt,
2105 ((struct lpfc_dmabuf *)
2106 iocb->context3)->phys);
2107 kfree(iocb->context3);
2116 lpfc_disc_flush_list(struct lpfc_hba * phba)
2118 struct lpfc_nodelist *ndlp, *next_ndlp;
2120 if (phba->fc_plogi_cnt) {
2121 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2123 lpfc_free_tx(phba, ndlp);
2124 lpfc_nlp_remove(phba, ndlp);
2127 if (phba->fc_adisc_cnt) {
2128 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2130 lpfc_free_tx(phba, ndlp);
2131 lpfc_nlp_remove(phba, ndlp);
2137 /*****************************************************************************/
2139 * NAME: lpfc_disc_timeout
2141 * FUNCTION: Fibre Channel driver discovery timeout routine.
2143 * EXECUTION ENVIRONMENT: interrupt only
2151 /*****************************************************************************/
2153 lpfc_disc_timeout(unsigned long ptr)
2155 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2156 unsigned long flags = 0;
2158 if (unlikely(!phba))
2161 spin_lock_irqsave(phba->host->host_lock, flags);
2162 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2163 phba->work_hba_events |= WORKER_DISC_TMO;
2164 if (phba->work_wait)
2165 wake_up(phba->work_wait);
2167 spin_unlock_irqrestore(phba->host->host_lock, flags);
2172 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2174 struct lpfc_sli *psli;
2175 struct lpfc_nodelist *ndlp;
2176 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2177 int rc, clrlaerr = 0;
2179 if (unlikely(!phba))
2182 if (!(phba->fc_flag & FC_DISC_TMO))
2187 spin_lock_irq(phba->host->host_lock);
2188 phba->fc_flag &= ~FC_DISC_TMO;
2189 spin_unlock_irq(phba->host->host_lock);
2191 switch (phba->hba_state) {
2193 case LPFC_LOCAL_CFG_LINK:
2194 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2196 lpfc_printf_log(phba,
2199 "%d:0221 FAN timeout\n",
2202 /* Forget about FAN, Start discovery by sending a FLOGI
2203 * hba_state is identically LPFC_FLOGI while waiting for FLOGI
2206 phba->hba_state = LPFC_FLOGI;
2207 lpfc_set_disctmo(phba);
2208 lpfc_initial_flogi(phba);
2212 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2213 /* Initial FLOGI timeout */
2214 lpfc_printf_log(phba,
2217 "%d:0222 Initial FLOGI timeout\n",
2220 /* Assume no Fabric and go on with discovery.
2221 * Check for outstanding ELS FLOGI to abort.
2224 /* FLOGI failed, so just use loop map to make discovery list */
2225 lpfc_disc_list_loopmap(phba);
2227 /* Start discovery */
2228 lpfc_disc_start(phba);
2231 case LPFC_FABRIC_CFG_LINK:
2232 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2234 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2235 "%d:0223 Timeout while waiting for NameServer "
2236 "login\n", phba->brd_no);
2238 /* Next look for NameServer ndlp */
2239 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2241 lpfc_nlp_remove(phba, ndlp);
2242 /* Start discovery */
2243 lpfc_disc_start(phba);
2247 /* Check for wait for NameServer Rsp timeout */
2248 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2249 "%d:0224 NameServer Query timeout "
2252 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2254 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2257 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2258 /* Try it one more time */
2259 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2263 phba->fc_ns_retry = 0;
2266 /* Nothing to authenticate, so CLEAR_LA right now */
2267 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2270 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2271 "%d:0226 Device Discovery "
2272 "completion error\n",
2274 phba->hba_state = LPFC_HBA_ERROR;
2278 phba->hba_state = LPFC_CLEAR_LA;
2279 lpfc_clear_la(phba, clearlambox);
2280 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2281 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2282 (MBX_NOWAIT | MBX_STOP_IOCB));
2283 if (rc == MBX_NOT_FINISHED) {
2284 mempool_free(clearlambox, phba->mbox_mem_pool);
2289 /* Setup and issue mailbox INITIALIZE LINK command */
2290 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2291 if (!initlinkmbox) {
2292 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2293 "%d:0226 Device Discovery "
2294 "completion error\n",
2296 phba->hba_state = LPFC_HBA_ERROR;
2300 lpfc_linkdown(phba);
2301 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2302 phba->cfg_link_speed);
2303 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2304 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2305 (MBX_NOWAIT | MBX_STOP_IOCB));
2306 if (rc == MBX_NOT_FINISHED)
2307 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2311 case LPFC_DISC_AUTH:
2312 /* Node Authentication timeout */
2313 lpfc_printf_log(phba,
2316 "%d:0227 Node Authentication timeout\n",
2318 lpfc_disc_flush_list(phba);
2319 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2322 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2323 "%d:0226 Device Discovery "
2324 "completion error\n",
2326 phba->hba_state = LPFC_HBA_ERROR;
2329 phba->hba_state = LPFC_CLEAR_LA;
2330 lpfc_clear_la(phba, clearlambox);
2331 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2332 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2333 (MBX_NOWAIT | MBX_STOP_IOCB));
2334 if (rc == MBX_NOT_FINISHED) {
2335 mempool_free(clearlambox, phba->mbox_mem_pool);
2341 /* CLEAR LA timeout */
2342 lpfc_printf_log(phba,
2345 "%d:0228 CLEAR LA timeout\n",
2350 case LPFC_HBA_READY:
2351 if (phba->fc_flag & FC_RSCN_MODE) {
2352 lpfc_printf_log(phba,
2355 "%d:0231 RSCN timeout Data: x%x x%x\n",
2357 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2359 /* Cleanup any outstanding ELS commands */
2360 lpfc_els_flush_cmd(phba);
2362 lpfc_els_flush_rscn(phba);
2363 lpfc_disc_flush_list(phba);
2369 lpfc_disc_flush_list(phba);
2370 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2371 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2372 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2373 phba->hba_state = LPFC_HBA_READY;
2380 lpfc_nodev_timeout(unsigned long ptr)
2382 struct lpfc_hba *phba;
2383 struct lpfc_nodelist *ndlp;
2384 unsigned long iflag;
2385 struct lpfc_work_evt *evtp;
2387 ndlp = (struct lpfc_nodelist *)ptr;
2388 phba = ndlp->nlp_phba;
2389 evtp = &ndlp->nodev_timeout_evt;
2390 spin_lock_irqsave(phba->host->host_lock, iflag);
2392 if (!list_empty(&evtp->evt_listp)) {
2393 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2396 evtp->evt_arg1 = ndlp;
2397 evtp->evt = LPFC_EVT_NODEV_TMO;
2398 list_add_tail(&evtp->evt_listp, &phba->work_list);
2399 if (phba->work_wait)
2400 wake_up(phba->work_wait);
2402 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2408 * This routine handles processing a NameServer REG_LOGIN mailbox
2409 * command upon completion. It is setup in the LPFC_MBOXQ
2410 * as the completion routine when the command is
2411 * handed off to the SLI layer.
2414 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2416 struct lpfc_sli *psli;
2418 struct lpfc_dmabuf *mp;
2419 struct lpfc_nodelist *ndlp;
2424 ndlp = (struct lpfc_nodelist *) pmb->context2;
2425 mp = (struct lpfc_dmabuf *) (pmb->context1);
2427 pmb->context1 = NULL;
2429 ndlp->nlp_rpi = mb->un.varWords[0];
2430 ndlp->nlp_type |= NLP_FABRIC;
2431 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2432 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2434 /* Start issuing Fabric-Device Management Interface (FDMI)
2435 * command to 0xfffffa (FDMI well known port)
2437 if (phba->cfg_fdmi_on == 1) {
2438 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2441 * Delay issuing FDMI command if fdmi-on=2
2442 * (supporting RPA/hostnmae)
2444 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2447 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2449 mempool_free( pmb, phba->mbox_mem_pool);
2455 * This routine looks up the ndlp lists
2456 * for the given RPI. If rpi found
2457 * it return the node list pointer
2460 struct lpfc_nodelist *
2461 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2463 struct lpfc_nodelist *ndlp;
2464 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2465 &phba->fc_nlpmap_list,
2466 &phba->fc_plogi_list,
2467 &phba->fc_adisc_list,
2468 &phba->fc_reglogin_list};
2471 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2472 list_for_each_entry(ndlp, lists[i], nlp_listp)
2473 if (ndlp->nlp_rpi == rpi)
2480 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2483 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2484 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2485 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2486 init_timer(&ndlp->nlp_tmofunc);
2487 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2488 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2489 init_timer(&ndlp->nlp_delayfunc);
2490 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2491 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2492 ndlp->nlp_DID = did;
2493 ndlp->nlp_phba = phba;
2494 ndlp->nlp_sid = NLP_NO_SID;