1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
40 /* AlpaArray for assignment of scsid for scan-down and bind_method */
41 static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
57 static void lpfc_disc_timeout_handler(struct lpfc_hba *);
60 lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
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 if (phba->hba_state < LPFC_LINK_DOWN)
124 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
126 *(int *)(evtp->evt_arg1) = 0;
127 complete((struct completion *)(evtp->evt_arg2));
129 case LPFC_EVT_OFFLINE:
130 if (phba->hba_state >= LPFC_LINK_DOWN)
132 lpfc_sli_brdrestart(phba);
133 *(int *)(evtp->evt_arg1) =
134 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
135 complete((struct completion *)(evtp->evt_arg2));
137 case LPFC_EVT_WARM_START:
138 if (phba->hba_state >= LPFC_LINK_DOWN)
140 lpfc_sli_brdreset(phba);
141 lpfc_hba_down_post(phba);
142 *(int *)(evtp->evt_arg1) =
143 lpfc_sli_brdready(phba, HS_MBRDY);
144 complete((struct completion *)(evtp->evt_arg2));
147 if (phba->hba_state >= LPFC_LINK_DOWN)
149 *(int *)(evtp->evt_arg1) = lpfc_sli_brdkill(phba);
150 complete((struct completion *)(evtp->evt_arg2));
155 spin_lock_irq(phba->host->host_lock);
157 spin_unlock_irq(phba->host->host_lock);
162 lpfc_work_done(struct lpfc_hba * phba)
164 struct lpfc_sli_ring *pring;
168 uint32_t work_hba_events;
170 spin_lock_irq(phba->host->host_lock);
171 ha_copy = phba->work_ha;
173 work_hba_events=phba->work_hba_events;
174 spin_unlock_irq(phba->host->host_lock);
176 if(ha_copy & HA_ERATT)
177 lpfc_handle_eratt(phba);
179 if(ha_copy & HA_MBATT)
180 lpfc_sli_handle_mb_event(phba);
182 if(ha_copy & HA_LATT)
183 lpfc_handle_latt(phba);
185 if (work_hba_events & WORKER_DISC_TMO)
186 lpfc_disc_timeout_handler(phba);
188 if (work_hba_events & WORKER_ELS_TMO)
189 lpfc_els_timeout_handler(phba);
191 if (work_hba_events & WORKER_MBOX_TMO)
192 lpfc_mbox_timeout_handler(phba);
194 if (work_hba_events & WORKER_FDMI_TMO)
195 lpfc_fdmi_tmo_handler(phba);
197 spin_lock_irq(phba->host->host_lock);
198 phba->work_hba_events &= ~work_hba_events;
199 spin_unlock_irq(phba->host->host_lock);
201 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
202 pring = &phba->sli.ring[i];
203 if ((ha_copy & HA_RXATT)
204 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
205 if (pring->flag & LPFC_STOP_IOCB_MASK) {
206 pring->flag |= LPFC_DEFERRED_RING_EVENT;
208 lpfc_sli_handle_slow_ring_event(phba, pring,
211 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
214 * Turn on Ring interrupts
216 spin_lock_irq(phba->host->host_lock);
217 control = readl(phba->HCregaddr);
218 control |= (HC_R0INT_ENA << i);
219 writel(control, phba->HCregaddr);
220 readl(phba->HCregaddr); /* flush */
221 spin_unlock_irq(phba->host->host_lock);
225 lpfc_work_list_done (phba);
230 check_work_wait_done(struct lpfc_hba *phba) {
232 spin_lock_irq(phba->host->host_lock);
234 phba->work_hba_events ||
235 (!list_empty(&phba->work_list)) ||
236 kthread_should_stop()) {
237 spin_unlock_irq(phba->host->host_lock);
240 spin_unlock_irq(phba->host->host_lock);
246 lpfc_do_work(void *p)
248 struct lpfc_hba *phba = p;
250 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
252 set_user_nice(current, -20);
253 phba->work_wait = &work_waitq;
257 rc = wait_event_interruptible(work_waitq,
258 check_work_wait_done(phba));
261 if (kthread_should_stop())
264 lpfc_work_done(phba);
267 phba->work_wait = NULL;
272 * This is only called to handle FC worker events. Since this a rare
273 * occurance, we allocate a struct lpfc_work_evt structure here instead of
274 * embedding it in the IOCB.
277 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
280 struct lpfc_work_evt *evtp;
283 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
284 * be queued to worker thread for processing
286 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
290 evtp->evt_arg1 = arg1;
291 evtp->evt_arg2 = arg2;
294 list_add_tail(&evtp->evt_listp, &phba->work_list);
295 spin_lock_irq(phba->host->host_lock);
297 wake_up(phba->work_wait);
298 spin_unlock_irq(phba->host->host_lock);
304 lpfc_linkdown(struct lpfc_hba * phba)
306 struct lpfc_sli *psli;
307 struct lpfc_nodelist *ndlp, *next_ndlp;
308 struct list_head *listp, *node_list[7];
313 /* sysfs or selective reset may call this routine to clean up */
314 if (phba->hba_state >= LPFC_LINK_DOWN) {
315 if (phba->hba_state == LPFC_LINK_DOWN)
318 spin_lock_irq(phba->host->host_lock);
319 phba->hba_state = LPFC_LINK_DOWN;
320 spin_unlock_irq(phba->host->host_lock);
323 /* Clean up any firmware default rpi's */
324 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
325 lpfc_unreg_did(phba, 0xffffffff, mb);
326 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
327 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
328 == MBX_NOT_FINISHED) {
329 mempool_free( mb, phba->mbox_mem_pool);
333 /* Cleanup any outstanding RSCN activity */
334 lpfc_els_flush_rscn(phba);
336 /* Cleanup any outstanding ELS commands */
337 lpfc_els_flush_cmd(phba);
339 /* Issue a LINK DOWN event to all nodes */
340 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
341 node_list[1] = &phba->fc_nlpmap_list;
342 node_list[2] = &phba->fc_nlpunmap_list;
343 node_list[3] = &phba->fc_prli_list;
344 node_list[4] = &phba->fc_reglogin_list;
345 node_list[5] = &phba->fc_adisc_list;
346 node_list[6] = &phba->fc_plogi_list;
347 for (i = 0; i < 7; i++) {
348 listp = node_list[i];
349 if (list_empty(listp))
352 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
354 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
355 NLP_EVT_DEVICE_RECOVERY);
357 /* Check config parameter use-adisc or FCP-2 */
358 if ((rc != NLP_STE_FREED_NODE) &&
359 (phba->cfg_use_adisc == 0) &&
360 !(ndlp->nlp_fcp_info &
362 /* We know we will have to relogin, so
363 * unreglogin the rpi right now to fail
364 * any outstanding I/Os quickly.
366 lpfc_unreg_rpi(phba, ndlp);
371 /* free any ndlp's on unused list */
372 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
374 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
377 /* Setup myDID for link up if we are in pt2pt mode */
378 if (phba->fc_flag & FC_PT2PT) {
380 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
381 lpfc_config_link(phba, mb);
382 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
383 if (lpfc_sli_issue_mbox
384 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
385 == MBX_NOT_FINISHED) {
386 mempool_free( mb, phba->mbox_mem_pool);
389 spin_lock_irq(phba->host->host_lock);
390 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
391 spin_unlock_irq(phba->host->host_lock);
393 spin_lock_irq(phba->host->host_lock);
394 phba->fc_flag &= ~FC_LBIT;
395 spin_unlock_irq(phba->host->host_lock);
397 /* Turn off discovery timer if its running */
398 lpfc_can_disctmo(phba);
400 /* Must process IOCBs on all rings to handle ABORTed I/Os */
405 lpfc_linkup(struct lpfc_hba * phba)
407 struct lpfc_nodelist *ndlp, *next_ndlp;
408 struct list_head *listp, *node_list[7];
411 spin_lock_irq(phba->host->host_lock);
412 phba->hba_state = LPFC_LINK_UP;
413 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
414 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
415 phba->fc_flag |= FC_NDISC_ACTIVE;
416 phba->fc_ns_retry = 0;
417 spin_unlock_irq(phba->host->host_lock);
420 node_list[0] = &phba->fc_plogi_list;
421 node_list[1] = &phba->fc_adisc_list;
422 node_list[2] = &phba->fc_reglogin_list;
423 node_list[3] = &phba->fc_prli_list;
424 node_list[4] = &phba->fc_nlpunmap_list;
425 node_list[5] = &phba->fc_nlpmap_list;
426 node_list[6] = &phba->fc_npr_list;
427 for (i = 0; i < 7; i++) {
428 listp = node_list[i];
429 if (list_empty(listp))
432 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
433 if (phba->fc_flag & FC_LBIT) {
434 if (ndlp->nlp_type & NLP_FABRIC) {
435 /* On Linkup its safe to clean up the
436 * ndlp from Fabric connections.
438 lpfc_nlp_list(phba, ndlp,
440 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
441 /* Fail outstanding IO now since device
442 * is marked for PLOGI.
444 lpfc_unreg_rpi(phba, ndlp);
450 /* free any ndlp's on unused list */
451 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
453 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
460 * This routine handles processing a CLEAR_LA mailbox
461 * command upon completion. It is setup in the LPFC_MBOXQ
462 * as the completion routine when the command is
463 * handed off to the SLI layer.
466 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
468 struct lpfc_sli *psli;
474 /* Since we don't do discovery right now, turn these off here */
475 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
476 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
477 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
479 /* Check for error */
480 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
481 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
482 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
483 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
485 phba->brd_no, mb->mbxStatus, phba->hba_state);
487 phba->hba_state = LPFC_HBA_ERROR;
491 if (phba->fc_flag & FC_ABORT_DISCOVERY)
494 phba->num_disc_nodes = 0;
495 /* go thru NPR list and issue ELS PLOGIs */
496 if (phba->fc_npr_cnt) {
497 lpfc_els_disc_plogi(phba);
500 if(!phba->num_disc_nodes) {
501 spin_lock_irq(phba->host->host_lock);
502 phba->fc_flag &= ~FC_NDISC_ACTIVE;
503 spin_unlock_irq(phba->host->host_lock);
506 phba->hba_state = LPFC_HBA_READY;
509 /* Device Discovery completes */
510 lpfc_printf_log(phba,
513 "%d:0225 Device Discovery completes\n",
516 mempool_free( pmb, phba->mbox_mem_pool);
518 spin_lock_irq(phba->host->host_lock);
519 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
520 if (phba->fc_flag & FC_ESTABLISH_LINK) {
521 phba->fc_flag &= ~FC_ESTABLISH_LINK;
523 spin_unlock_irq(phba->host->host_lock);
525 del_timer_sync(&phba->fc_estabtmo);
527 lpfc_can_disctmo(phba);
529 /* turn on Link Attention interrupts */
530 spin_lock_irq(phba->host->host_lock);
531 psli->sli_flag |= LPFC_PROCESS_LA;
532 control = readl(phba->HCregaddr);
533 control |= HC_LAINT_ENA;
534 writel(control, phba->HCregaddr);
535 readl(phba->HCregaddr); /* flush */
536 spin_unlock_irq(phba->host->host_lock);
542 lpfc_mbx_cmpl_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
544 struct lpfc_sli *psli;
549 /* Check for error */
551 /* CONFIG_LINK mbox error <mbxStatus> state <hba_state> */
552 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
553 "%d:0306 CONFIG_LINK mbxStatus error x%x "
555 phba->brd_no, mb->mbxStatus, phba->hba_state);
558 phba->hba_state = LPFC_HBA_ERROR;
562 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
563 if (phba->fc_topology == TOPOLOGY_LOOP) {
564 /* If we are public loop and L bit was set */
565 if ((phba->fc_flag & FC_PUBLIC_LOOP) &&
566 !(phba->fc_flag & FC_LBIT)) {
567 /* Need to wait for FAN - use discovery timer
568 * for timeout. hba_state is identically
569 * LPFC_LOCAL_CFG_LINK while waiting for FAN
571 lpfc_set_disctmo(phba);
572 mempool_free( pmb, phba->mbox_mem_pool);
577 /* Start discovery by sending a FLOGI hba_state is identically
578 * LPFC_FLOGI while waiting for FLOGI cmpl
580 phba->hba_state = LPFC_FLOGI;
581 lpfc_set_disctmo(phba);
582 lpfc_initial_flogi(phba);
583 mempool_free( pmb, phba->mbox_mem_pool);
586 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
587 mempool_free( pmb, phba->mbox_mem_pool);
592 /* CONFIG_LINK bad hba state <hba_state> */
593 lpfc_printf_log(phba,
596 "%d:0200 CONFIG_LINK bad hba state x%x\n",
597 phba->brd_no, phba->hba_state);
599 if (phba->hba_state != LPFC_CLEAR_LA) {
600 lpfc_clear_la(phba, pmb);
601 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
602 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
603 == MBX_NOT_FINISHED) {
604 mempool_free( pmb, phba->mbox_mem_pool);
605 lpfc_disc_flush_list(phba);
606 psli->ring[(psli->ip_ring)].flag &=
607 ~LPFC_STOP_IOCB_EVENT;
608 psli->ring[(psli->fcp_ring)].flag &=
609 ~LPFC_STOP_IOCB_EVENT;
610 psli->ring[(psli->next_ring)].flag &=
611 ~LPFC_STOP_IOCB_EVENT;
612 phba->hba_state = LPFC_HBA_READY;
615 mempool_free( pmb, phba->mbox_mem_pool);
621 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
623 struct lpfc_sli *psli = &phba->sli;
624 MAILBOX_t *mb = &pmb->mb;
625 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
628 /* Check for error */
630 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
631 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
632 "%d:0319 READ_SPARAM mbxStatus error x%x "
634 phba->brd_no, mb->mbxStatus, phba->hba_state);
637 phba->hba_state = LPFC_HBA_ERROR;
641 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
642 sizeof (struct serv_parm));
643 memcpy((uint8_t *) & phba->fc_nodename,
644 (uint8_t *) & phba->fc_sparam.nodeName,
645 sizeof (struct lpfc_name));
646 memcpy((uint8_t *) & phba->fc_portname,
647 (uint8_t *) & phba->fc_sparam.portName,
648 sizeof (struct lpfc_name));
649 lpfc_mbuf_free(phba, mp->virt, mp->phys);
651 mempool_free( pmb, phba->mbox_mem_pool);
655 pmb->context1 = NULL;
656 lpfc_mbuf_free(phba, mp->virt, mp->phys);
658 if (phba->hba_state != LPFC_CLEAR_LA) {
659 lpfc_clear_la(phba, pmb);
660 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
661 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
662 == MBX_NOT_FINISHED) {
663 mempool_free( pmb, phba->mbox_mem_pool);
664 lpfc_disc_flush_list(phba);
665 psli->ring[(psli->ip_ring)].flag &=
666 ~LPFC_STOP_IOCB_EVENT;
667 psli->ring[(psli->fcp_ring)].flag &=
668 ~LPFC_STOP_IOCB_EVENT;
669 psli->ring[(psli->next_ring)].flag &=
670 ~LPFC_STOP_IOCB_EVENT;
671 phba->hba_state = LPFC_HBA_READY;
674 mempool_free( pmb, phba->mbox_mem_pool);
680 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
683 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
684 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
685 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
687 spin_lock_irq(phba->host->host_lock);
688 switch(la->UlnkSpeed) {
690 phba->fc_linkspeed = LA_1GHZ_LINK;
693 phba->fc_linkspeed = LA_2GHZ_LINK;
696 phba->fc_linkspeed = LA_4GHZ_LINK;
699 phba->fc_linkspeed = LA_UNKNW_LINK;
703 phba->fc_topology = la->topology;
705 if (phba->fc_topology == TOPOLOGY_LOOP) {
706 /* Get Loop Map information */
709 phba->fc_flag |= FC_LBIT;
711 phba->fc_myDID = la->granted_AL_PA;
712 i = la->un.lilpBde64.tus.f.bdeSize;
715 phba->alpa_map[0] = 0;
717 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
728 numalpa = phba->alpa_map[0];
730 while (j < numalpa) {
731 memset(un.pamap, 0, 16);
732 for (k = 1; j < numalpa; k++) {
734 phba->alpa_map[j + 1];
739 /* Link Up Event ALPA map */
740 lpfc_printf_log(phba,
743 "%d:1304 Link Up Event "
744 "ALPA map Data: x%x "
747 un.pa.wd1, un.pa.wd2,
748 un.pa.wd3, un.pa.wd4);
753 phba->fc_myDID = phba->fc_pref_DID;
754 phba->fc_flag |= FC_LBIT;
756 spin_unlock_irq(phba->host->host_lock);
760 lpfc_read_sparam(phba, sparam_mbox);
761 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
762 lpfc_sli_issue_mbox(phba, sparam_mbox,
763 (MBX_NOWAIT | MBX_STOP_IOCB));
767 phba->hba_state = LPFC_LOCAL_CFG_LINK;
768 lpfc_config_link(phba, cfglink_mbox);
769 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_config_link;
770 lpfc_sli_issue_mbox(phba, cfglink_mbox,
771 (MBX_NOWAIT | MBX_STOP_IOCB));
776 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
778 struct lpfc_sli *psli = &phba->sli;
782 /* turn on Link Attention interrupts - no CLEAR_LA needed */
783 spin_lock_irq(phba->host->host_lock);
784 psli->sli_flag |= LPFC_PROCESS_LA;
785 control = readl(phba->HCregaddr);
786 control |= HC_LAINT_ENA;
787 writel(control, phba->HCregaddr);
788 readl(phba->HCregaddr); /* flush */
789 spin_unlock_irq(phba->host->host_lock);
793 * This routine handles processing a READ_LA mailbox
794 * command upon completion. It is setup in the LPFC_MBOXQ
795 * as the completion routine when the command is
796 * handed off to the SLI layer.
799 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
802 MAILBOX_t *mb = &pmb->mb;
803 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
805 /* Check for error */
807 lpfc_printf_log(phba,
810 "%d:1307 READ_LA mbox error x%x state x%x\n",
812 mb->mbxStatus, phba->hba_state);
813 lpfc_mbx_issue_link_down(phba);
814 phba->hba_state = LPFC_HBA_ERROR;
815 goto lpfc_mbx_cmpl_read_la_free_mbuf;
818 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
820 memcpy(&phba->alpa_map[0], mp->virt, 128);
822 spin_lock_irq(phba->host->host_lock);
824 phba->fc_flag |= FC_BYPASSED_MODE;
826 phba->fc_flag &= ~FC_BYPASSED_MODE;
827 spin_unlock_irq(phba->host->host_lock);
829 if (((phba->fc_eventTag + 1) < la->eventTag) ||
830 (phba->fc_eventTag == la->eventTag)) {
831 phba->fc_stat.LinkMultiEvent++;
832 if (la->attType == AT_LINK_UP) {
833 if (phba->fc_eventTag != 0)
838 phba->fc_eventTag = la->eventTag;
840 if (la->attType == AT_LINK_UP) {
841 phba->fc_stat.LinkUp++;
842 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
843 "%d:1303 Link Up Event x%x received "
844 "Data: x%x x%x x%x x%x\n",
845 phba->brd_no, la->eventTag, phba->fc_eventTag,
846 la->granted_AL_PA, la->UlnkSpeed,
848 lpfc_mbx_process_link_up(phba, la);
850 phba->fc_stat.LinkDown++;
851 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
852 "%d:1305 Link Down Event x%x received "
853 "Data: x%x x%x x%x\n",
854 phba->brd_no, la->eventTag, phba->fc_eventTag,
855 phba->hba_state, phba->fc_flag);
856 lpfc_mbx_issue_link_down(phba);
859 lpfc_mbx_cmpl_read_la_free_mbuf:
860 lpfc_mbuf_free(phba, mp->virt, mp->phys);
862 mempool_free(pmb, phba->mbox_mem_pool);
867 * This routine handles processing a REG_LOGIN mailbox
868 * command upon completion. It is setup in the LPFC_MBOXQ
869 * as the completion routine when the command is
870 * handed off to the SLI layer.
873 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
875 struct lpfc_sli *psli;
877 struct lpfc_dmabuf *mp;
878 struct lpfc_nodelist *ndlp;
883 ndlp = (struct lpfc_nodelist *) pmb->context2;
884 mp = (struct lpfc_dmabuf *) (pmb->context1);
886 pmb->context1 = NULL;
888 /* Good status, call state machine */
889 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
890 lpfc_mbuf_free(phba, mp->virt, mp->phys);
892 mempool_free( pmb, phba->mbox_mem_pool);
898 * This routine handles processing a Fabric REG_LOGIN mailbox
899 * command upon completion. It is setup in the LPFC_MBOXQ
900 * as the completion routine when the command is
901 * handed off to the SLI layer.
904 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
906 struct lpfc_sli *psli;
908 struct lpfc_dmabuf *mp;
909 struct lpfc_nodelist *ndlp;
910 struct lpfc_nodelist *ndlp_fdmi;
916 ndlp = (struct lpfc_nodelist *) pmb->context2;
917 mp = (struct lpfc_dmabuf *) (pmb->context1);
920 lpfc_mbuf_free(phba, mp->virt, mp->phys);
922 mempool_free( pmb, phba->mbox_mem_pool);
923 mempool_free( ndlp, phba->nlp_mem_pool);
925 /* FLOGI failed, so just use loop map to make discovery list */
926 lpfc_disc_list_loopmap(phba);
928 /* Start discovery */
929 lpfc_disc_start(phba);
933 pmb->context1 = NULL;
935 ndlp->nlp_rpi = mb->un.varWords[0];
936 ndlp->nlp_type |= NLP_FABRIC;
937 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
938 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
940 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
941 /* This NPort has been assigned an NPort_ID by the fabric as a
942 * result of the completed fabric login. Issue a State Change
943 * Registration (SCR) ELS request to the fabric controller
944 * (SCR_DID) so that this NPort gets RSCN events from the
947 lpfc_issue_els_scr(phba, SCR_DID, 0);
949 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
951 /* Allocate a new node instance. If the pool is empty,
952 * start the discovery process and skip the Nameserver
953 * login process. This is attempted again later on.
954 * Otherwise, issue a Port Login (PLOGI) to NameServer.
956 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
958 lpfc_disc_start(phba);
959 lpfc_mbuf_free(phba, mp->virt, mp->phys);
961 mempool_free( pmb, phba->mbox_mem_pool);
964 lpfc_nlp_init(phba, ndlp, NameServer_DID);
965 ndlp->nlp_type |= NLP_FABRIC;
968 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
969 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
970 lpfc_issue_els_plogi(phba, ndlp, 0);
971 if (phba->cfg_fdmi_on) {
972 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
975 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
976 ndlp_fdmi->nlp_type |= NLP_FABRIC;
977 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
978 lpfc_issue_els_plogi(phba, ndlp_fdmi, 0);
983 lpfc_mbuf_free(phba, mp->virt, mp->phys);
985 mempool_free( pmb, phba->mbox_mem_pool);
990 * This routine handles processing a NameServer REG_LOGIN mailbox
991 * command upon completion. It is setup in the LPFC_MBOXQ
992 * as the completion routine when the command is
993 * handed off to the SLI layer.
996 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
998 struct lpfc_sli *psli;
1000 struct lpfc_dmabuf *mp;
1001 struct lpfc_nodelist *ndlp;
1006 ndlp = (struct lpfc_nodelist *) pmb->context2;
1007 mp = (struct lpfc_dmabuf *) (pmb->context1);
1009 if (mb->mbxStatus) {
1010 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1012 mempool_free( pmb, phba->mbox_mem_pool);
1013 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1015 /* RegLogin failed, so just use loop map to make discovery
1017 lpfc_disc_list_loopmap(phba);
1019 /* Start discovery */
1020 lpfc_disc_start(phba);
1024 pmb->context1 = NULL;
1026 ndlp->nlp_rpi = mb->un.varWords[0];
1027 ndlp->nlp_type |= NLP_FABRIC;
1028 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1029 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1031 if (phba->hba_state < LPFC_HBA_READY) {
1032 /* Link up discovery requires Fabrib registration. */
1033 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1034 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1035 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1038 phba->fc_ns_retry = 0;
1039 /* Good status, issue CT Request to NameServer */
1040 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1041 /* Cannot issue NameServer Query, so finish up discovery */
1042 lpfc_disc_start(phba);
1045 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1047 mempool_free( pmb, phba->mbox_mem_pool);
1053 lpfc_register_remote_port(struct lpfc_hba * phba,
1054 struct lpfc_nodelist * ndlp)
1056 struct fc_rport *rport;
1057 struct lpfc_rport_data *rdata;
1058 struct fc_rport_identifiers rport_ids;
1060 /* Remote port has reappeared. Re-register w/ FC transport */
1061 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1062 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1063 rport_ids.port_id = ndlp->nlp_DID;
1064 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1066 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1068 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1069 "Warning: fc_remote_port_add failed\n");
1073 /* initialize static port data */
1074 rport->maxframe_size = ndlp->nlp_maxframe;
1075 rport->supported_classes = ndlp->nlp_class_sup;
1076 if ((rport->scsi_target_id != -1) &&
1077 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1078 ndlp->nlp_sid = rport->scsi_target_id;
1080 rdata = rport->dd_data;
1081 rdata->pnode = ndlp;
1083 if (ndlp->nlp_type & NLP_FCP_TARGET)
1084 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1085 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1086 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1089 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1090 fc_remote_port_rolechg(rport, rport_ids.roles);
1097 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1098 struct lpfc_nodelist * ndlp)
1100 struct fc_rport *rport = ndlp->rport;
1101 struct lpfc_rport_data *rdata = rport->dd_data;
1104 rdata->pnode = NULL;
1105 fc_remote_port_delete(rport);
1111 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1113 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1114 struct lpfc_sli *psli;
1117 /* Sanity check to ensure we are not moving to / from the same list */
1118 if ((nlp->nlp_flag & NLP_LIST_MASK) == list) {
1119 if (list != NLP_NO_LIST)
1123 switch(nlp->nlp_flag & NLP_LIST_MASK) {
1124 case NLP_NO_LIST: /* Not on any list */
1126 case NLP_UNUSED_LIST:
1127 phba->fc_unused_cnt--;
1128 list_del(&nlp->nlp_listp);
1130 case NLP_PLOGI_LIST:
1131 phba->fc_plogi_cnt--;
1132 list_del(&nlp->nlp_listp);
1134 case NLP_ADISC_LIST:
1135 phba->fc_adisc_cnt--;
1136 list_del(&nlp->nlp_listp);
1138 case NLP_REGLOGIN_LIST:
1139 phba->fc_reglogin_cnt--;
1140 list_del(&nlp->nlp_listp);
1143 phba->fc_prli_cnt--;
1144 list_del(&nlp->nlp_listp);
1146 case NLP_UNMAPPED_LIST:
1147 phba->fc_unmap_cnt--;
1148 list_del(&nlp->nlp_listp);
1149 spin_lock_irq(phba->host->host_lock);
1150 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1151 nlp->nlp_type &= ~NLP_FC_NODE;
1152 spin_unlock_irq(phba->host->host_lock);
1153 phba->nport_event_cnt++;
1155 rport_del = unmapped;
1157 case NLP_MAPPED_LIST:
1159 list_del(&nlp->nlp_listp);
1160 phba->nport_event_cnt++;
1166 list_del(&nlp->nlp_listp);
1167 /* Stop delay tmo if taking node off NPR list */
1168 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1169 (list != NLP_NPR_LIST)) {
1170 spin_lock_irq(phba->host->host_lock);
1171 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1172 spin_unlock_irq(phba->host->host_lock);
1173 nlp->nlp_last_elscmd = 0;
1174 del_timer_sync(&nlp->nlp_delayfunc);
1175 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1176 list_del_init(&nlp->els_retry_evt.evt_listp);
1181 spin_lock_irq(phba->host->host_lock);
1182 nlp->nlp_flag &= ~NLP_LIST_MASK;
1183 spin_unlock_irq(phba->host->host_lock);
1185 /* Add NPort <did> to <num> list */
1186 lpfc_printf_log(phba,
1189 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1191 nlp->nlp_DID, list, nlp->nlp_flag);
1194 case NLP_NO_LIST: /* No list, just remove it */
1195 lpfc_nlp_remove(phba, nlp);
1196 /* as node removed - stop further transport calls */
1199 case NLP_UNUSED_LIST:
1200 spin_lock_irq(phba->host->host_lock);
1201 nlp->nlp_flag |= list;
1202 spin_unlock_irq(phba->host->host_lock);
1203 /* Put it at the end of the unused list */
1204 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1205 phba->fc_unused_cnt++;
1207 case NLP_PLOGI_LIST:
1208 spin_lock_irq(phba->host->host_lock);
1209 nlp->nlp_flag |= list;
1210 spin_unlock_irq(phba->host->host_lock);
1211 /* Put it at the end of the plogi list */
1212 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1213 phba->fc_plogi_cnt++;
1215 case NLP_ADISC_LIST:
1216 spin_lock_irq(phba->host->host_lock);
1217 nlp->nlp_flag |= list;
1218 spin_unlock_irq(phba->host->host_lock);
1219 /* Put it at the end of the adisc list */
1220 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1221 phba->fc_adisc_cnt++;
1223 case NLP_REGLOGIN_LIST:
1224 spin_lock_irq(phba->host->host_lock);
1225 nlp->nlp_flag |= list;
1226 spin_unlock_irq(phba->host->host_lock);
1227 /* Put it at the end of the reglogin list */
1228 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1229 phba->fc_reglogin_cnt++;
1232 spin_lock_irq(phba->host->host_lock);
1233 nlp->nlp_flag |= list;
1234 spin_unlock_irq(phba->host->host_lock);
1235 /* Put it at the end of the prli list */
1236 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1237 phba->fc_prli_cnt++;
1239 case NLP_UNMAPPED_LIST:
1240 rport_add = unmapped;
1241 /* ensure all vestiges of "mapped" significance are gone */
1242 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1243 spin_lock_irq(phba->host->host_lock);
1244 nlp->nlp_flag |= list;
1245 spin_unlock_irq(phba->host->host_lock);
1246 /* Put it at the end of the unmap list */
1247 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1248 phba->fc_unmap_cnt++;
1249 phba->nport_event_cnt++;
1250 /* stop nodev tmo if running */
1251 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1252 spin_lock_irq(phba->host->host_lock);
1253 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1254 spin_unlock_irq(phba->host->host_lock);
1255 del_timer_sync(&nlp->nlp_tmofunc);
1256 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1257 list_del_init(&nlp->nodev_timeout_evt.
1261 nlp->nlp_type |= NLP_FC_NODE;
1263 case NLP_MAPPED_LIST:
1265 spin_lock_irq(phba->host->host_lock);
1266 nlp->nlp_flag |= list;
1267 spin_unlock_irq(phba->host->host_lock);
1268 /* Put it at the end of the map list */
1269 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1271 phba->nport_event_cnt++;
1272 /* stop nodev tmo if running */
1273 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1274 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1275 del_timer_sync(&nlp->nlp_tmofunc);
1276 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1277 list_del_init(&nlp->nodev_timeout_evt.
1283 spin_lock_irq(phba->host->host_lock);
1284 nlp->nlp_flag |= list;
1285 spin_unlock_irq(phba->host->host_lock);
1286 /* Put it at the end of the npr list */
1287 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1290 if (!(nlp->nlp_flag & NLP_NODEV_TMO)) {
1291 mod_timer(&nlp->nlp_tmofunc,
1292 jiffies + HZ * phba->cfg_nodev_tmo);
1294 spin_lock_irq(phba->host->host_lock);
1295 nlp->nlp_flag |= NLP_NODEV_TMO;
1296 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1297 spin_unlock_irq(phba->host->host_lock);
1304 * We make all the calls into the transport after we have
1305 * moved the node between lists. This so that we don't
1306 * release the lock while in-between lists.
1309 /* Don't upcall midlayer if we're unloading */
1310 if (!(phba->fc_flag & FC_UNLOADING)) {
1312 * We revalidate the rport pointer as the "add" function
1313 * may have removed the remote port.
1315 if ((rport_del != none) && nlp->rport)
1316 lpfc_unregister_remote_port(phba, nlp);
1318 if (rport_add != none) {
1320 * Tell the fc transport about the port, if we haven't
1321 * already. If we have, and it's a scsi entity, be
1322 * sure to unblock any attached scsi devices
1325 lpfc_register_remote_port(phba, nlp);
1328 * if we added to Mapped list, but the remote port
1329 * registration failed or assigned a target id outside
1330 * our presentable range - move the node to the
1333 if ((rport_add == mapped) &&
1335 (nlp->rport->scsi_target_id == -1) ||
1336 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1337 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1338 spin_lock_irq(phba->host->host_lock);
1339 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1340 spin_unlock_irq(phba->host->host_lock);
1341 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1349 * Start / ReStart rescue timer for Discovery / RSCN handling
1352 lpfc_set_disctmo(struct lpfc_hba * phba)
1356 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1357 /* For FAN, timeout should be greater then edtov */
1358 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1360 /* Normal discovery timeout should be > then ELS/CT timeout
1361 * FC spec states we need 3 * ratov for CT requests
1363 tmo = ((phba->fc_ratov * 3) + 3);
1366 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1367 spin_lock_irq(phba->host->host_lock);
1368 phba->fc_flag |= FC_DISC_TMO;
1369 spin_unlock_irq(phba->host->host_lock);
1371 /* Start Discovery Timer state <hba_state> */
1372 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1373 "%d:0247 Start Discovery Timer state x%x "
1374 "Data: x%x x%lx x%x x%x\n",
1376 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1377 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1383 * Cancel rescue timer for Discovery / RSCN handling
1386 lpfc_can_disctmo(struct lpfc_hba * phba)
1388 /* Turn off discovery timer if its running */
1389 if (phba->fc_flag & FC_DISC_TMO) {
1390 spin_lock_irq(phba->host->host_lock);
1391 phba->fc_flag &= ~FC_DISC_TMO;
1392 spin_unlock_irq(phba->host->host_lock);
1393 del_timer_sync(&phba->fc_disctmo);
1394 phba->work_hba_events &= ~WORKER_DISC_TMO;
1397 /* Cancel Discovery Timer state <hba_state> */
1398 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1399 "%d:0248 Cancel Discovery Timer state x%x "
1400 "Data: x%x x%x x%x\n",
1401 phba->brd_no, phba->hba_state, phba->fc_flag,
1402 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1408 * Check specified ring for outstanding IOCB on the SLI queue
1409 * Return true if iocb matches the specified nport
1412 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1413 struct lpfc_sli_ring * pring,
1414 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1416 struct lpfc_sli *psli;
1421 if (pring->ringno == LPFC_ELS_RING) {
1422 switch (icmd->ulpCommand) {
1423 case CMD_GEN_REQUEST64_CR:
1424 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1426 case CMD_ELS_REQUEST64_CR:
1427 case CMD_XMIT_ELS_RSP64_CX:
1428 if (iocb->context1 == (uint8_t *) ndlp)
1431 } else if (pring->ringno == psli->ip_ring) {
1433 } else if (pring->ringno == psli->fcp_ring) {
1434 /* Skip match check if waiting to relogin to FCP target */
1435 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1436 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1439 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1442 } else if (pring->ringno == psli->next_ring) {
1449 * Free resources / clean up outstanding I/Os
1450 * associated with nlp_rpi in the LPFC_NODELIST entry.
1453 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1455 struct lpfc_sli *psli;
1456 struct lpfc_sli_ring *pring;
1457 struct lpfc_iocbq *iocb, *next_iocb;
1462 * Everything that matches on txcmplq will be returned
1463 * by firmware with a no rpi error.
1466 rpi = ndlp->nlp_rpi;
1468 /* Now process each ring */
1469 for (i = 0; i < psli->num_rings; i++) {
1470 pring = &psli->ring[i];
1472 spin_lock_irq(phba->host->host_lock);
1473 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1476 * Check to see if iocb matches the nport we are
1479 if ((lpfc_check_sli_ndlp
1480 (phba, pring, iocb, ndlp))) {
1481 /* It matches, so deque and call compl
1483 list_del(&iocb->list);
1485 if (iocb->iocb_cmpl) {
1488 IOSTAT_LOCAL_REJECT;
1489 icmd->un.ulpWord[4] =
1491 spin_unlock_irq(phba->host->
1493 (iocb->iocb_cmpl) (phba,
1495 spin_lock_irq(phba->host->
1498 lpfc_sli_release_iocbq(phba,
1502 spin_unlock_irq(phba->host->host_lock);
1510 * Free rpi associated with LPFC_NODELIST entry.
1511 * This routine is called from lpfc_freenode(), when we are removing
1512 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1513 * LOGO that completes successfully, and we are waiting to PLOGI back
1514 * to the remote NPort. In addition, it is called after we receive
1515 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1516 * we are waiting to PLOGI back to the remote NPort.
1519 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1524 if (ndlp->nlp_rpi) {
1525 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1526 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1527 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1528 rc = lpfc_sli_issue_mbox
1529 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1530 if (rc == MBX_NOT_FINISHED)
1531 mempool_free( mbox, phba->mbox_mem_pool);
1533 lpfc_no_rpi(phba, ndlp);
1541 * Free resources associated with LPFC_NODELIST entry
1542 * so it can be freed.
1545 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1548 LPFC_MBOXQ_t *nextmb;
1549 struct lpfc_dmabuf *mp;
1551 /* Cleanup node for NPort <nlp_DID> */
1552 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1553 "%d:0900 Cleanup node for NPort x%x "
1554 "Data: x%x x%x x%x\n",
1555 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1556 ndlp->nlp_state, ndlp->nlp_rpi);
1558 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1561 * if unloading the driver - just leave the remote port in place.
1562 * The driver unload will force the attached devices to detach
1563 * and flush cache's w/o generating flush errors.
1565 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1566 lpfc_unregister_remote_port(phba, ndlp);
1567 ndlp->nlp_sid = NLP_NO_SID;
1570 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1571 if ((mb = phba->sli.mbox_active)) {
1572 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1573 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1574 mb->context2 = NULL;
1575 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1578 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1579 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1580 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1581 mp = (struct lpfc_dmabuf *) (mb->context1);
1583 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1586 list_del(&mb->list);
1587 mempool_free(mb, phba->mbox_mem_pool);
1591 lpfc_els_abort(phba,ndlp,0);
1592 spin_lock_irq(phba->host->host_lock);
1593 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1594 spin_unlock_irq(phba->host->host_lock);
1595 del_timer_sync(&ndlp->nlp_tmofunc);
1597 ndlp->nlp_last_elscmd = 0;
1598 del_timer_sync(&ndlp->nlp_delayfunc);
1600 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1601 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1602 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1603 list_del_init(&ndlp->els_retry_evt.evt_listp);
1605 lpfc_unreg_rpi(phba, ndlp);
1611 * Check to see if we can free the nlp back to the freelist.
1612 * If we are in the middle of using the nlp in the discovery state
1613 * machine, defer the free till we reach the end of the state machine.
1616 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1618 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1619 spin_lock_irq(phba->host->host_lock);
1620 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1621 spin_unlock_irq(phba->host->host_lock);
1622 del_timer_sync(&ndlp->nlp_tmofunc);
1623 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1624 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1629 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1630 spin_lock_irq(phba->host->host_lock);
1631 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1632 spin_unlock_irq(phba->host->host_lock);
1633 ndlp->nlp_last_elscmd = 0;
1634 del_timer_sync(&ndlp->nlp_delayfunc);
1635 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1636 list_del_init(&ndlp->els_retry_evt.evt_listp);
1639 if (ndlp->nlp_disc_refcnt) {
1640 spin_lock_irq(phba->host->host_lock);
1641 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1642 spin_unlock_irq(phba->host->host_lock);
1645 lpfc_freenode(phba, ndlp);
1646 mempool_free( ndlp, phba->nlp_mem_pool);
1652 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1658 if (did == Bcast_DID)
1661 if (ndlp->nlp_DID == 0) {
1665 /* First check for Direct match */
1666 if (ndlp->nlp_DID == did)
1669 /* Next check for area/domain identically equals 0 match */
1670 mydid.un.word = phba->fc_myDID;
1671 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1675 matchdid.un.word = did;
1676 ndlpdid.un.word = ndlp->nlp_DID;
1677 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1678 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1679 (mydid.un.b.area == matchdid.un.b.area)) {
1680 if ((ndlpdid.un.b.domain == 0) &&
1681 (ndlpdid.un.b.area == 0)) {
1682 if (ndlpdid.un.b.id)
1688 matchdid.un.word = ndlp->nlp_DID;
1689 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1690 (mydid.un.b.area == ndlpdid.un.b.area)) {
1691 if ((matchdid.un.b.domain == 0) &&
1692 (matchdid.un.b.area == 0)) {
1693 if (matchdid.un.b.id)
1701 /* Search for a nodelist entry on a specific list */
1702 struct lpfc_nodelist *
1703 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1705 struct lpfc_nodelist *ndlp, *next_ndlp;
1708 if (order & NLP_SEARCH_UNMAPPED) {
1709 list_for_each_entry_safe(ndlp, next_ndlp,
1710 &phba->fc_nlpunmap_list, nlp_listp) {
1711 if (lpfc_matchdid(phba, ndlp, did)) {
1712 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1713 ((uint32_t) ndlp->nlp_xri << 16) |
1714 ((uint32_t) ndlp->nlp_type << 8) |
1715 ((uint32_t) ndlp->nlp_rpi & 0xff));
1716 /* FIND node DID unmapped */
1717 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1718 "%d:0929 FIND node DID unmapped"
1719 " Data: x%p x%x x%x x%x\n",
1721 ndlp, ndlp->nlp_DID,
1722 ndlp->nlp_flag, data1);
1728 if (order & NLP_SEARCH_MAPPED) {
1729 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1731 if (lpfc_matchdid(phba, ndlp, did)) {
1733 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1734 ((uint32_t) ndlp->nlp_xri << 16) |
1735 ((uint32_t) ndlp->nlp_type << 8) |
1736 ((uint32_t) ndlp->nlp_rpi & 0xff));
1737 /* FIND node DID mapped */
1738 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1739 "%d:0930 FIND node DID mapped "
1740 "Data: x%p x%x x%x x%x\n",
1742 ndlp, ndlp->nlp_DID,
1743 ndlp->nlp_flag, data1);
1749 if (order & NLP_SEARCH_PLOGI) {
1750 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1752 if (lpfc_matchdid(phba, ndlp, did)) {
1754 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1755 ((uint32_t) ndlp->nlp_xri << 16) |
1756 ((uint32_t) ndlp->nlp_type << 8) |
1757 ((uint32_t) ndlp->nlp_rpi & 0xff));
1758 /* LOG change to PLOGI */
1759 /* FIND node DID plogi */
1760 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1761 "%d:0908 FIND node DID plogi "
1762 "Data: x%p x%x x%x x%x\n",
1764 ndlp, ndlp->nlp_DID,
1765 ndlp->nlp_flag, data1);
1771 if (order & NLP_SEARCH_ADISC) {
1772 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1774 if (lpfc_matchdid(phba, ndlp, did)) {
1776 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1777 ((uint32_t) ndlp->nlp_xri << 16) |
1778 ((uint32_t) ndlp->nlp_type << 8) |
1779 ((uint32_t) ndlp->nlp_rpi & 0xff));
1780 /* LOG change to ADISC */
1781 /* FIND node DID adisc */
1782 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1783 "%d:0931 FIND node DID adisc "
1784 "Data: x%p x%x x%x x%x\n",
1786 ndlp, ndlp->nlp_DID,
1787 ndlp->nlp_flag, data1);
1793 if (order & NLP_SEARCH_REGLOGIN) {
1794 list_for_each_entry_safe(ndlp, next_ndlp,
1795 &phba->fc_reglogin_list, nlp_listp) {
1796 if (lpfc_matchdid(phba, ndlp, did)) {
1798 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1799 ((uint32_t) ndlp->nlp_xri << 16) |
1800 ((uint32_t) ndlp->nlp_type << 8) |
1801 ((uint32_t) ndlp->nlp_rpi & 0xff));
1802 /* LOG change to REGLOGIN */
1803 /* FIND node DID reglogin */
1804 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1805 "%d:0931 FIND node DID reglogin"
1806 " Data: x%p x%x x%x x%x\n",
1808 ndlp, ndlp->nlp_DID,
1809 ndlp->nlp_flag, data1);
1815 if (order & NLP_SEARCH_PRLI) {
1816 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1818 if (lpfc_matchdid(phba, ndlp, did)) {
1820 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1821 ((uint32_t) ndlp->nlp_xri << 16) |
1822 ((uint32_t) ndlp->nlp_type << 8) |
1823 ((uint32_t) ndlp->nlp_rpi & 0xff));
1824 /* LOG change to PRLI */
1825 /* FIND node DID prli */
1826 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1827 "%d:0931 FIND node DID prli "
1828 "Data: x%p x%x x%x x%x\n",
1830 ndlp, ndlp->nlp_DID,
1831 ndlp->nlp_flag, data1);
1837 if (order & NLP_SEARCH_NPR) {
1838 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1840 if (lpfc_matchdid(phba, ndlp, did)) {
1842 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1843 ((uint32_t) ndlp->nlp_xri << 16) |
1844 ((uint32_t) ndlp->nlp_type << 8) |
1845 ((uint32_t) ndlp->nlp_rpi & 0xff));
1846 /* LOG change to NPR */
1847 /* FIND node DID npr */
1848 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1849 "%d:0931 FIND node DID npr "
1850 "Data: x%p x%x x%x x%x\n",
1852 ndlp, ndlp->nlp_DID,
1853 ndlp->nlp_flag, data1);
1859 if (order & NLP_SEARCH_UNUSED) {
1860 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1862 if (lpfc_matchdid(phba, ndlp, did)) {
1864 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1865 ((uint32_t) ndlp->nlp_xri << 16) |
1866 ((uint32_t) ndlp->nlp_type << 8) |
1867 ((uint32_t) ndlp->nlp_rpi & 0xff));
1868 /* LOG change to UNUSED */
1869 /* FIND node DID unused */
1870 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1871 "%d:0931 FIND node DID unused "
1872 "Data: x%p x%x x%x x%x\n",
1874 ndlp, ndlp->nlp_DID,
1875 ndlp->nlp_flag, data1);
1881 /* FIND node did <did> NOT FOUND */
1882 lpfc_printf_log(phba,
1885 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1886 phba->brd_no, did, order);
1888 /* no match found */
1892 struct lpfc_nodelist *
1893 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1895 struct lpfc_nodelist *ndlp;
1898 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1900 if ((phba->fc_flag & FC_RSCN_MODE) &&
1901 ((lpfc_rscn_payload_check(phba, did) == 0)))
1903 ndlp = (struct lpfc_nodelist *)
1904 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1907 lpfc_nlp_init(phba, ndlp, did);
1908 ndlp->nlp_state = NLP_STE_NPR_NODE;
1909 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1910 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1913 if (phba->fc_flag & FC_RSCN_MODE) {
1914 if (lpfc_rscn_payload_check(phba, did)) {
1915 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1917 /* Since this node is marked for discovery,
1918 * delay timeout is not needed.
1920 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1921 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1922 spin_unlock_irq(phba->host->host_lock);
1923 del_timer_sync(&ndlp->nlp_delayfunc);
1924 spin_lock_irq(phba->host->host_lock);
1925 if (!list_empty(&ndlp->els_retry_evt.
1927 list_del_init(&ndlp->els_retry_evt.
1932 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1937 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1938 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1940 ndlp->nlp_state = NLP_STE_NPR_NODE;
1941 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1942 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1947 /* Build a list of nodes to discover based on the loopmap */
1949 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1952 uint32_t alpa, index;
1954 if (phba->hba_state <= LPFC_LINK_DOWN) {
1957 if (phba->fc_topology != TOPOLOGY_LOOP) {
1961 /* Check for loop map present or not */
1962 if (phba->alpa_map[0]) {
1963 for (j = 1; j <= phba->alpa_map[0]; j++) {
1964 alpa = phba->alpa_map[j];
1966 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1969 lpfc_setup_disc_node(phba, alpa);
1972 /* No alpamap, so try all alpa's */
1973 for (j = 0; j < FC_MAXLOOP; j++) {
1974 /* If cfg_scan_down is set, start from highest
1975 * ALPA (0xef) to lowest (0x1).
1977 if (phba->cfg_scan_down)
1980 index = FC_MAXLOOP - j - 1;
1981 alpa = lpfcAlpaArray[index];
1982 if ((phba->fc_myDID & 0xff) == alpa) {
1986 lpfc_setup_disc_node(phba, alpa);
1992 /* Start Link up / RSCN discovery on NPR list */
1994 lpfc_disc_start(struct lpfc_hba * phba)
1996 struct lpfc_sli *psli;
1998 struct lpfc_nodelist *ndlp, *next_ndlp;
1999 uint32_t did_changed, num_sent;
2000 uint32_t clear_la_pending;
2005 if (phba->hba_state <= LPFC_LINK_DOWN) {
2008 if (phba->hba_state == LPFC_CLEAR_LA)
2009 clear_la_pending = 1;
2011 clear_la_pending = 0;
2013 if (phba->hba_state < LPFC_HBA_READY) {
2014 phba->hba_state = LPFC_DISC_AUTH;
2016 lpfc_set_disctmo(phba);
2018 if (phba->fc_prevDID == phba->fc_myDID) {
2023 phba->fc_prevDID = phba->fc_myDID;
2024 phba->num_disc_nodes = 0;
2026 /* Start Discovery state <hba_state> */
2027 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2028 "%d:0202 Start Discovery hba state x%x "
2029 "Data: x%x x%x x%x\n",
2030 phba->brd_no, phba->hba_state, phba->fc_flag,
2031 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2033 /* If our did changed, we MUST do PLOGI */
2034 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2036 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2038 spin_lock_irq(phba->host->host_lock);
2039 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2040 spin_unlock_irq(phba->host->host_lock);
2045 /* First do ADISCs - if any */
2046 num_sent = lpfc_els_disc_adisc(phba);
2051 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2052 /* If we get here, there is nothing to ADISC */
2053 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2054 phba->hba_state = LPFC_CLEAR_LA;
2055 lpfc_clear_la(phba, mbox);
2056 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2057 rc = lpfc_sli_issue_mbox(phba, mbox,
2058 (MBX_NOWAIT | MBX_STOP_IOCB));
2059 if (rc == MBX_NOT_FINISHED) {
2060 mempool_free( mbox, phba->mbox_mem_pool);
2061 lpfc_disc_flush_list(phba);
2062 psli->ring[(psli->ip_ring)].flag &=
2063 ~LPFC_STOP_IOCB_EVENT;
2064 psli->ring[(psli->fcp_ring)].flag &=
2065 ~LPFC_STOP_IOCB_EVENT;
2066 psli->ring[(psli->next_ring)].flag &=
2067 ~LPFC_STOP_IOCB_EVENT;
2068 phba->hba_state = LPFC_HBA_READY;
2072 /* Next do PLOGIs - if any */
2073 num_sent = lpfc_els_disc_plogi(phba);
2078 if (phba->fc_flag & FC_RSCN_MODE) {
2079 /* Check to see if more RSCNs came in while we
2080 * were processing this one.
2082 if ((phba->fc_rscn_id_cnt == 0) &&
2083 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2084 spin_lock_irq(phba->host->host_lock);
2085 phba->fc_flag &= ~FC_RSCN_MODE;
2086 spin_unlock_irq(phba->host->host_lock);
2089 lpfc_els_handle_rscn(phba);
2096 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2097 * ring the match the sppecified nodelist.
2100 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2102 struct lpfc_sli *psli;
2104 struct lpfc_iocbq *iocb, *next_iocb;
2105 struct lpfc_sli_ring *pring;
2106 struct lpfc_dmabuf *mp;
2109 pring = &psli->ring[LPFC_ELS_RING];
2111 /* Error matching iocb on txq or txcmplq
2112 * First check the txq.
2114 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2115 if (iocb->context1 != ndlp) {
2119 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2120 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2122 list_del(&iocb->list);
2124 lpfc_els_free_iocb(phba, iocb);
2128 /* Next check the txcmplq */
2129 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2130 if (iocb->context1 != ndlp) {
2134 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2135 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2137 iocb->iocb_cmpl = NULL;
2138 /* context2 = cmd, context2->next = rsp, context3 =
2140 if (iocb->context2) {
2141 /* Free the response IOCB before handling the
2144 mp = (struct lpfc_dmabuf *) (iocb->context2);
2145 mp = list_get_first(&mp->list,
2149 /* Delay before releasing rsp buffer to
2150 * give UNREG mbox a chance to take
2154 &phba->freebufList);
2156 lpfc_mbuf_free(phba,
2157 ((struct lpfc_dmabuf *)
2158 iocb->context2)->virt,
2159 ((struct lpfc_dmabuf *)
2160 iocb->context2)->phys);
2161 kfree(iocb->context2);
2164 if (iocb->context3) {
2165 lpfc_mbuf_free(phba,
2166 ((struct lpfc_dmabuf *)
2167 iocb->context3)->virt,
2168 ((struct lpfc_dmabuf *)
2169 iocb->context3)->phys);
2170 kfree(iocb->context3);
2179 lpfc_disc_flush_list(struct lpfc_hba * phba)
2181 struct lpfc_nodelist *ndlp, *next_ndlp;
2183 if (phba->fc_plogi_cnt) {
2184 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2186 lpfc_free_tx(phba, ndlp);
2187 lpfc_nlp_remove(phba, ndlp);
2190 if (phba->fc_adisc_cnt) {
2191 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2193 lpfc_free_tx(phba, ndlp);
2194 lpfc_nlp_remove(phba, ndlp);
2200 /*****************************************************************************/
2202 * NAME: lpfc_disc_timeout
2204 * FUNCTION: Fibre Channel driver discovery timeout routine.
2206 * EXECUTION ENVIRONMENT: interrupt only
2214 /*****************************************************************************/
2216 lpfc_disc_timeout(unsigned long ptr)
2218 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2219 unsigned long flags = 0;
2221 if (unlikely(!phba))
2224 spin_lock_irqsave(phba->host->host_lock, flags);
2225 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2226 phba->work_hba_events |= WORKER_DISC_TMO;
2227 if (phba->work_wait)
2228 wake_up(phba->work_wait);
2230 spin_unlock_irqrestore(phba->host->host_lock, flags);
2235 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2237 struct lpfc_sli *psli;
2238 struct lpfc_nodelist *ndlp, *next_ndlp;
2239 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2240 int rc, clrlaerr = 0;
2242 if (unlikely(!phba))
2245 if (!(phba->fc_flag & FC_DISC_TMO))
2250 spin_lock_irq(phba->host->host_lock);
2251 phba->fc_flag &= ~FC_DISC_TMO;
2252 spin_unlock_irq(phba->host->host_lock);
2254 switch (phba->hba_state) {
2256 case LPFC_LOCAL_CFG_LINK:
2257 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2259 lpfc_printf_log(phba,
2262 "%d:0221 FAN timeout\n",
2265 /* Start discovery by sending FLOGI, clean up old rpis */
2266 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2268 if (ndlp->nlp_type & NLP_FABRIC) {
2269 /* Clean up the ndlp on Fabric connections */
2270 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2272 else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2273 /* Fail outstanding IO now since device
2274 * is marked for PLOGI.
2276 lpfc_unreg_rpi(phba, ndlp);
2279 phba->hba_state = LPFC_FLOGI;
2280 lpfc_set_disctmo(phba);
2281 lpfc_initial_flogi(phba);
2285 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2286 /* Initial FLOGI timeout */
2287 lpfc_printf_log(phba,
2290 "%d:0222 Initial FLOGI timeout\n",
2293 /* Assume no Fabric and go on with discovery.
2294 * Check for outstanding ELS FLOGI to abort.
2297 /* FLOGI failed, so just use loop map to make discovery list */
2298 lpfc_disc_list_loopmap(phba);
2300 /* Start discovery */
2301 lpfc_disc_start(phba);
2304 case LPFC_FABRIC_CFG_LINK:
2305 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2307 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2308 "%d:0223 Timeout while waiting for NameServer "
2309 "login\n", phba->brd_no);
2311 /* Next look for NameServer ndlp */
2312 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2314 lpfc_nlp_remove(phba, ndlp);
2315 /* Start discovery */
2316 lpfc_disc_start(phba);
2320 /* Check for wait for NameServer Rsp timeout */
2321 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2322 "%d:0224 NameServer Query timeout "
2325 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2327 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2330 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2331 /* Try it one more time */
2332 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2336 phba->fc_ns_retry = 0;
2339 /* Nothing to authenticate, so CLEAR_LA right now */
2340 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2343 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2344 "%d:0226 Device Discovery "
2345 "completion error\n",
2347 phba->hba_state = LPFC_HBA_ERROR;
2351 phba->hba_state = LPFC_CLEAR_LA;
2352 lpfc_clear_la(phba, clearlambox);
2353 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2354 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2355 (MBX_NOWAIT | MBX_STOP_IOCB));
2356 if (rc == MBX_NOT_FINISHED) {
2357 mempool_free(clearlambox, phba->mbox_mem_pool);
2362 /* Setup and issue mailbox INITIALIZE LINK command */
2363 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2364 if (!initlinkmbox) {
2365 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2366 "%d:0226 Device Discovery "
2367 "completion error\n",
2369 phba->hba_state = LPFC_HBA_ERROR;
2373 lpfc_linkdown(phba);
2374 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2375 phba->cfg_link_speed);
2376 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2377 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2378 (MBX_NOWAIT | MBX_STOP_IOCB));
2379 if (rc == MBX_NOT_FINISHED)
2380 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2384 case LPFC_DISC_AUTH:
2385 /* Node Authentication timeout */
2386 lpfc_printf_log(phba,
2389 "%d:0227 Node Authentication timeout\n",
2391 lpfc_disc_flush_list(phba);
2392 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2395 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2396 "%d:0226 Device Discovery "
2397 "completion error\n",
2399 phba->hba_state = LPFC_HBA_ERROR;
2402 phba->hba_state = LPFC_CLEAR_LA;
2403 lpfc_clear_la(phba, clearlambox);
2404 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2405 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2406 (MBX_NOWAIT | MBX_STOP_IOCB));
2407 if (rc == MBX_NOT_FINISHED) {
2408 mempool_free(clearlambox, phba->mbox_mem_pool);
2414 /* CLEAR LA timeout */
2415 lpfc_printf_log(phba,
2418 "%d:0228 CLEAR LA timeout\n",
2423 case LPFC_HBA_READY:
2424 if (phba->fc_flag & FC_RSCN_MODE) {
2425 lpfc_printf_log(phba,
2428 "%d:0231 RSCN timeout Data: x%x x%x\n",
2430 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2432 /* Cleanup any outstanding ELS commands */
2433 lpfc_els_flush_cmd(phba);
2435 lpfc_els_flush_rscn(phba);
2436 lpfc_disc_flush_list(phba);
2442 lpfc_disc_flush_list(phba);
2443 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2444 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2445 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2446 phba->hba_state = LPFC_HBA_READY;
2453 lpfc_nodev_timeout(unsigned long ptr)
2455 struct lpfc_hba *phba;
2456 struct lpfc_nodelist *ndlp;
2457 unsigned long iflag;
2458 struct lpfc_work_evt *evtp;
2460 ndlp = (struct lpfc_nodelist *)ptr;
2461 phba = ndlp->nlp_phba;
2462 evtp = &ndlp->nodev_timeout_evt;
2463 spin_lock_irqsave(phba->host->host_lock, iflag);
2465 if (!list_empty(&evtp->evt_listp)) {
2466 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2469 evtp->evt_arg1 = ndlp;
2470 evtp->evt = LPFC_EVT_NODEV_TMO;
2471 list_add_tail(&evtp->evt_listp, &phba->work_list);
2472 if (phba->work_wait)
2473 wake_up(phba->work_wait);
2475 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2481 * This routine handles processing a NameServer REG_LOGIN mailbox
2482 * command upon completion. It is setup in the LPFC_MBOXQ
2483 * as the completion routine when the command is
2484 * handed off to the SLI layer.
2487 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2489 struct lpfc_sli *psli;
2491 struct lpfc_dmabuf *mp;
2492 struct lpfc_nodelist *ndlp;
2497 ndlp = (struct lpfc_nodelist *) pmb->context2;
2498 mp = (struct lpfc_dmabuf *) (pmb->context1);
2500 pmb->context1 = NULL;
2502 ndlp->nlp_rpi = mb->un.varWords[0];
2503 ndlp->nlp_type |= NLP_FABRIC;
2504 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2505 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2507 /* Start issuing Fabric-Device Management Interface (FDMI)
2508 * command to 0xfffffa (FDMI well known port)
2510 if (phba->cfg_fdmi_on == 1) {
2511 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2514 * Delay issuing FDMI command if fdmi-on=2
2515 * (supporting RPA/hostnmae)
2517 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2520 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2522 mempool_free( pmb, phba->mbox_mem_pool);
2528 * This routine looks up the ndlp lists
2529 * for the given RPI. If rpi found
2530 * it return the node list pointer
2533 struct lpfc_nodelist *
2534 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2536 struct lpfc_nodelist *ndlp;
2537 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2538 &phba->fc_nlpmap_list,
2539 &phba->fc_plogi_list,
2540 &phba->fc_adisc_list,
2541 &phba->fc_reglogin_list};
2544 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2545 list_for_each_entry(ndlp, lists[i], nlp_listp)
2546 if (ndlp->nlp_rpi == rpi)
2553 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2556 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2557 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2558 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2559 init_timer(&ndlp->nlp_tmofunc);
2560 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2561 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2562 init_timer(&ndlp->nlp_delayfunc);
2563 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2564 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2565 ndlp->nlp_DID = did;
2566 ndlp->nlp_phba = phba;
2567 ndlp->nlp_sid = NLP_NO_SID;