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 & NLP_FCP_2_DEVICE)) {
361 /* We know we will have to relogin, so
362 * unreglogin the rpi right now to fail
363 * any outstanding I/Os quickly.
365 lpfc_unreg_rpi(phba, ndlp);
370 /* free any ndlp's on unused list */
371 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
373 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
376 /* Setup myDID for link up if we are in pt2pt mode */
377 if (phba->fc_flag & FC_PT2PT) {
379 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
380 lpfc_config_link(phba, mb);
381 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
382 if (lpfc_sli_issue_mbox
383 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
384 == MBX_NOT_FINISHED) {
385 mempool_free( mb, phba->mbox_mem_pool);
388 spin_lock_irq(phba->host->host_lock);
389 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
390 spin_unlock_irq(phba->host->host_lock);
392 spin_lock_irq(phba->host->host_lock);
393 phba->fc_flag &= ~FC_LBIT;
394 spin_unlock_irq(phba->host->host_lock);
396 /* Turn off discovery timer if its running */
397 lpfc_can_disctmo(phba);
399 /* Must process IOCBs on all rings to handle ABORTed I/Os */
404 lpfc_linkup(struct lpfc_hba * phba)
406 struct lpfc_nodelist *ndlp, *next_ndlp;
407 struct list_head *listp, *node_list[7];
410 spin_lock_irq(phba->host->host_lock);
411 phba->hba_state = LPFC_LINK_UP;
412 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
413 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
414 phba->fc_flag |= FC_NDISC_ACTIVE;
415 phba->fc_ns_retry = 0;
416 spin_unlock_irq(phba->host->host_lock);
419 node_list[0] = &phba->fc_plogi_list;
420 node_list[1] = &phba->fc_adisc_list;
421 node_list[2] = &phba->fc_reglogin_list;
422 node_list[3] = &phba->fc_prli_list;
423 node_list[4] = &phba->fc_nlpunmap_list;
424 node_list[5] = &phba->fc_nlpmap_list;
425 node_list[6] = &phba->fc_npr_list;
426 for (i = 0; i < 7; i++) {
427 listp = node_list[i];
428 if (list_empty(listp))
431 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
432 if (phba->fc_flag & FC_LBIT) {
433 if (ndlp->nlp_type & NLP_FABRIC) {
434 /* On Linkup its safe to clean up the
435 * ndlp from Fabric connections.
437 lpfc_nlp_list(phba, ndlp,
439 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
440 /* Fail outstanding IO now since device
441 * is marked for PLOGI.
443 lpfc_unreg_rpi(phba, ndlp);
449 /* free any ndlp's on unused list */
450 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
452 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
459 * This routine handles processing a CLEAR_LA mailbox
460 * command upon completion. It is setup in the LPFC_MBOXQ
461 * as the completion routine when the command is
462 * handed off to the SLI layer.
465 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
467 struct lpfc_sli *psli;
473 /* Since we don't do discovery right now, turn these off here */
474 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
475 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
476 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
478 /* Check for error */
479 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
480 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
481 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
482 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
484 phba->brd_no, mb->mbxStatus, phba->hba_state);
486 phba->hba_state = LPFC_HBA_ERROR;
490 if (phba->fc_flag & FC_ABORT_DISCOVERY)
493 phba->num_disc_nodes = 0;
494 /* go thru NPR list and issue ELS PLOGIs */
495 if (phba->fc_npr_cnt) {
496 lpfc_els_disc_plogi(phba);
499 if (!phba->num_disc_nodes) {
500 spin_lock_irq(phba->host->host_lock);
501 phba->fc_flag &= ~FC_NDISC_ACTIVE;
502 spin_unlock_irq(phba->host->host_lock);
505 phba->hba_state = LPFC_HBA_READY;
508 /* Device Discovery completes */
509 lpfc_printf_log(phba,
512 "%d:0225 Device Discovery completes\n",
515 mempool_free( pmb, phba->mbox_mem_pool);
517 spin_lock_irq(phba->host->host_lock);
518 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
519 if (phba->fc_flag & FC_ESTABLISH_LINK) {
520 phba->fc_flag &= ~FC_ESTABLISH_LINK;
522 spin_unlock_irq(phba->host->host_lock);
524 del_timer_sync(&phba->fc_estabtmo);
526 lpfc_can_disctmo(phba);
528 /* turn on Link Attention interrupts */
529 spin_lock_irq(phba->host->host_lock);
530 psli->sli_flag |= LPFC_PROCESS_LA;
531 control = readl(phba->HCregaddr);
532 control |= HC_LAINT_ENA;
533 writel(control, phba->HCregaddr);
534 readl(phba->HCregaddr); /* flush */
535 spin_unlock_irq(phba->host->host_lock);
541 lpfc_mbx_cmpl_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
543 struct lpfc_sli *psli;
548 /* Check for error */
550 /* CONFIG_LINK mbox error <mbxStatus> state <hba_state> */
551 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
552 "%d:0306 CONFIG_LINK mbxStatus error x%x "
554 phba->brd_no, mb->mbxStatus, phba->hba_state);
557 phba->hba_state = LPFC_HBA_ERROR;
561 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
562 if (phba->fc_topology == TOPOLOGY_LOOP) {
563 /* If we are public loop and L bit was set */
564 if ((phba->fc_flag & FC_PUBLIC_LOOP) &&
565 !(phba->fc_flag & FC_LBIT)) {
566 /* Need to wait for FAN - use discovery timer
567 * for timeout. hba_state is identically
568 * LPFC_LOCAL_CFG_LINK while waiting for FAN
570 lpfc_set_disctmo(phba);
571 mempool_free( pmb, phba->mbox_mem_pool);
576 /* Start discovery by sending a FLOGI hba_state is identically
577 * LPFC_FLOGI while waiting for FLOGI cmpl
579 phba->hba_state = LPFC_FLOGI;
580 lpfc_set_disctmo(phba);
581 lpfc_initial_flogi(phba);
582 mempool_free( pmb, phba->mbox_mem_pool);
585 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
586 mempool_free( pmb, phba->mbox_mem_pool);
591 /* CONFIG_LINK bad hba state <hba_state> */
592 lpfc_printf_log(phba,
595 "%d:0200 CONFIG_LINK bad hba state x%x\n",
596 phba->brd_no, phba->hba_state);
598 if (phba->hba_state != LPFC_CLEAR_LA) {
599 lpfc_clear_la(phba, pmb);
600 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
601 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
602 == MBX_NOT_FINISHED) {
603 mempool_free( pmb, phba->mbox_mem_pool);
604 lpfc_disc_flush_list(phba);
605 psli->ring[(psli->ip_ring)].flag &=
606 ~LPFC_STOP_IOCB_EVENT;
607 psli->ring[(psli->fcp_ring)].flag &=
608 ~LPFC_STOP_IOCB_EVENT;
609 psli->ring[(psli->next_ring)].flag &=
610 ~LPFC_STOP_IOCB_EVENT;
611 phba->hba_state = LPFC_HBA_READY;
614 mempool_free( pmb, phba->mbox_mem_pool);
620 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
622 struct lpfc_sli *psli = &phba->sli;
623 MAILBOX_t *mb = &pmb->mb;
624 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
627 /* Check for error */
629 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
630 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
631 "%d:0319 READ_SPARAM mbxStatus error x%x "
633 phba->brd_no, mb->mbxStatus, phba->hba_state);
636 phba->hba_state = LPFC_HBA_ERROR;
640 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
641 sizeof (struct serv_parm));
642 memcpy((uint8_t *) & phba->fc_nodename,
643 (uint8_t *) & phba->fc_sparam.nodeName,
644 sizeof (struct lpfc_name));
645 memcpy((uint8_t *) & phba->fc_portname,
646 (uint8_t *) & phba->fc_sparam.portName,
647 sizeof (struct lpfc_name));
648 lpfc_mbuf_free(phba, mp->virt, mp->phys);
650 mempool_free( pmb, phba->mbox_mem_pool);
654 pmb->context1 = NULL;
655 lpfc_mbuf_free(phba, mp->virt, mp->phys);
657 if (phba->hba_state != LPFC_CLEAR_LA) {
658 lpfc_clear_la(phba, pmb);
659 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
660 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
661 == MBX_NOT_FINISHED) {
662 mempool_free( pmb, phba->mbox_mem_pool);
663 lpfc_disc_flush_list(phba);
664 psli->ring[(psli->ip_ring)].flag &=
665 ~LPFC_STOP_IOCB_EVENT;
666 psli->ring[(psli->fcp_ring)].flag &=
667 ~LPFC_STOP_IOCB_EVENT;
668 psli->ring[(psli->next_ring)].flag &=
669 ~LPFC_STOP_IOCB_EVENT;
670 phba->hba_state = LPFC_HBA_READY;
673 mempool_free( pmb, phba->mbox_mem_pool);
679 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
682 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
683 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
684 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
686 spin_lock_irq(phba->host->host_lock);
687 switch (la->UlnkSpeed) {
689 phba->fc_linkspeed = LA_1GHZ_LINK;
692 phba->fc_linkspeed = LA_2GHZ_LINK;
695 phba->fc_linkspeed = LA_4GHZ_LINK;
698 phba->fc_linkspeed = LA_UNKNW_LINK;
702 phba->fc_topology = la->topology;
704 if (phba->fc_topology == TOPOLOGY_LOOP) {
705 /* Get Loop Map information */
708 phba->fc_flag |= FC_LBIT;
710 phba->fc_myDID = la->granted_AL_PA;
711 i = la->un.lilpBde64.tus.f.bdeSize;
714 phba->alpa_map[0] = 0;
716 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
727 numalpa = phba->alpa_map[0];
729 while (j < numalpa) {
730 memset(un.pamap, 0, 16);
731 for (k = 1; j < numalpa; k++) {
733 phba->alpa_map[j + 1];
738 /* Link Up Event ALPA map */
739 lpfc_printf_log(phba,
742 "%d:1304 Link Up Event "
743 "ALPA map Data: x%x "
746 un.pa.wd1, un.pa.wd2,
747 un.pa.wd3, un.pa.wd4);
752 phba->fc_myDID = phba->fc_pref_DID;
753 phba->fc_flag |= FC_LBIT;
755 spin_unlock_irq(phba->host->host_lock);
759 lpfc_read_sparam(phba, sparam_mbox);
760 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
761 lpfc_sli_issue_mbox(phba, sparam_mbox,
762 (MBX_NOWAIT | MBX_STOP_IOCB));
766 phba->hba_state = LPFC_LOCAL_CFG_LINK;
767 lpfc_config_link(phba, cfglink_mbox);
768 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_config_link;
769 lpfc_sli_issue_mbox(phba, cfglink_mbox,
770 (MBX_NOWAIT | MBX_STOP_IOCB));
775 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
777 struct lpfc_sli *psli = &phba->sli;
781 /* turn on Link Attention interrupts - no CLEAR_LA needed */
782 spin_lock_irq(phba->host->host_lock);
783 psli->sli_flag |= LPFC_PROCESS_LA;
784 control = readl(phba->HCregaddr);
785 control |= HC_LAINT_ENA;
786 writel(control, phba->HCregaddr);
787 readl(phba->HCregaddr); /* flush */
788 spin_unlock_irq(phba->host->host_lock);
792 * This routine handles processing a READ_LA mailbox
793 * command upon completion. It is setup in the LPFC_MBOXQ
794 * as the completion routine when the command is
795 * handed off to the SLI layer.
798 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
801 MAILBOX_t *mb = &pmb->mb;
802 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
804 /* Check for error */
806 lpfc_printf_log(phba,
809 "%d:1307 READ_LA mbox error x%x state x%x\n",
811 mb->mbxStatus, phba->hba_state);
812 lpfc_mbx_issue_link_down(phba);
813 phba->hba_state = LPFC_HBA_ERROR;
814 goto lpfc_mbx_cmpl_read_la_free_mbuf;
817 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
819 memcpy(&phba->alpa_map[0], mp->virt, 128);
821 spin_lock_irq(phba->host->host_lock);
823 phba->fc_flag |= FC_BYPASSED_MODE;
825 phba->fc_flag &= ~FC_BYPASSED_MODE;
826 spin_unlock_irq(phba->host->host_lock);
828 if (((phba->fc_eventTag + 1) < la->eventTag) ||
829 (phba->fc_eventTag == la->eventTag)) {
830 phba->fc_stat.LinkMultiEvent++;
831 if (la->attType == AT_LINK_UP) {
832 if (phba->fc_eventTag != 0)
837 phba->fc_eventTag = la->eventTag;
839 if (la->attType == AT_LINK_UP) {
840 phba->fc_stat.LinkUp++;
841 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
842 "%d:1303 Link Up Event x%x received "
843 "Data: x%x x%x x%x x%x\n",
844 phba->brd_no, la->eventTag, phba->fc_eventTag,
845 la->granted_AL_PA, la->UlnkSpeed,
847 lpfc_mbx_process_link_up(phba, la);
849 phba->fc_stat.LinkDown++;
850 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
851 "%d:1305 Link Down Event x%x received "
852 "Data: x%x x%x x%x\n",
853 phba->brd_no, la->eventTag, phba->fc_eventTag,
854 phba->hba_state, phba->fc_flag);
855 lpfc_mbx_issue_link_down(phba);
858 lpfc_mbx_cmpl_read_la_free_mbuf:
859 lpfc_mbuf_free(phba, mp->virt, mp->phys);
861 mempool_free(pmb, phba->mbox_mem_pool);
866 * This routine handles processing a REG_LOGIN mailbox
867 * command upon completion. It is setup in the LPFC_MBOXQ
868 * as the completion routine when the command is
869 * handed off to the SLI layer.
872 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
874 struct lpfc_sli *psli;
876 struct lpfc_dmabuf *mp;
877 struct lpfc_nodelist *ndlp;
882 ndlp = (struct lpfc_nodelist *) pmb->context2;
883 mp = (struct lpfc_dmabuf *) (pmb->context1);
885 pmb->context1 = NULL;
887 /* Good status, call state machine */
888 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
889 lpfc_mbuf_free(phba, mp->virt, mp->phys);
891 mempool_free( pmb, phba->mbox_mem_pool);
897 * This routine handles processing a Fabric REG_LOGIN mailbox
898 * command upon completion. It is setup in the LPFC_MBOXQ
899 * as the completion routine when the command is
900 * handed off to the SLI layer.
903 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
905 struct lpfc_sli *psli;
907 struct lpfc_dmabuf *mp;
908 struct lpfc_nodelist *ndlp;
909 struct lpfc_nodelist *ndlp_fdmi;
915 ndlp = (struct lpfc_nodelist *) pmb->context2;
916 mp = (struct lpfc_dmabuf *) (pmb->context1);
919 lpfc_mbuf_free(phba, mp->virt, mp->phys);
921 mempool_free( pmb, phba->mbox_mem_pool);
922 mempool_free( ndlp, phba->nlp_mem_pool);
924 /* FLOGI failed, so just use loop map to make discovery list */
925 lpfc_disc_list_loopmap(phba);
927 /* Start discovery */
928 lpfc_disc_start(phba);
932 pmb->context1 = NULL;
934 ndlp->nlp_rpi = mb->un.varWords[0];
935 ndlp->nlp_type |= NLP_FABRIC;
936 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
937 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
939 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
940 /* This NPort has been assigned an NPort_ID by the fabric as a
941 * result of the completed fabric login. Issue a State Change
942 * Registration (SCR) ELS request to the fabric controller
943 * (SCR_DID) so that this NPort gets RSCN events from the
946 lpfc_issue_els_scr(phba, SCR_DID, 0);
948 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
950 /* Allocate a new node instance. If the pool is empty,
951 * start the discovery process and skip the Nameserver
952 * login process. This is attempted again later on.
953 * Otherwise, issue a Port Login (PLOGI) to NameServer.
955 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
957 lpfc_disc_start(phba);
958 lpfc_mbuf_free(phba, mp->virt, mp->phys);
960 mempool_free( pmb, phba->mbox_mem_pool);
963 lpfc_nlp_init(phba, ndlp, NameServer_DID);
964 ndlp->nlp_type |= NLP_FABRIC;
967 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
968 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
969 lpfc_issue_els_plogi(phba, ndlp, 0);
970 if (phba->cfg_fdmi_on) {
971 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
974 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
975 ndlp_fdmi->nlp_type |= NLP_FABRIC;
976 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
977 lpfc_issue_els_plogi(phba, ndlp_fdmi, 0);
982 lpfc_mbuf_free(phba, mp->virt, mp->phys);
984 mempool_free( pmb, phba->mbox_mem_pool);
989 * This routine handles processing a NameServer REG_LOGIN mailbox
990 * command upon completion. It is setup in the LPFC_MBOXQ
991 * as the completion routine when the command is
992 * handed off to the SLI layer.
995 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
997 struct lpfc_sli *psli;
999 struct lpfc_dmabuf *mp;
1000 struct lpfc_nodelist *ndlp;
1005 ndlp = (struct lpfc_nodelist *) pmb->context2;
1006 mp = (struct lpfc_dmabuf *) (pmb->context1);
1008 if (mb->mbxStatus) {
1009 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1011 mempool_free( pmb, phba->mbox_mem_pool);
1012 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1014 /* RegLogin failed, so just use loop map to make discovery
1016 lpfc_disc_list_loopmap(phba);
1018 /* Start discovery */
1019 lpfc_disc_start(phba);
1023 pmb->context1 = NULL;
1025 ndlp->nlp_rpi = mb->un.varWords[0];
1026 ndlp->nlp_type |= NLP_FABRIC;
1027 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1028 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1030 if (phba->hba_state < LPFC_HBA_READY) {
1031 /* Link up discovery requires Fabrib registration. */
1032 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1033 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1034 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1037 phba->fc_ns_retry = 0;
1038 /* Good status, issue CT Request to NameServer */
1039 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1040 /* Cannot issue NameServer Query, so finish up discovery */
1041 lpfc_disc_start(phba);
1044 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1046 mempool_free( pmb, phba->mbox_mem_pool);
1052 lpfc_register_remote_port(struct lpfc_hba * phba,
1053 struct lpfc_nodelist * ndlp)
1055 struct fc_rport *rport;
1056 struct lpfc_rport_data *rdata;
1057 struct fc_rport_identifiers rport_ids;
1059 /* Remote port has reappeared. Re-register w/ FC transport */
1060 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1061 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1062 rport_ids.port_id = ndlp->nlp_DID;
1063 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1065 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1067 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1068 "Warning: fc_remote_port_add failed\n");
1072 /* initialize static port data */
1073 rport->maxframe_size = ndlp->nlp_maxframe;
1074 rport->supported_classes = ndlp->nlp_class_sup;
1075 if ((rport->scsi_target_id != -1) &&
1076 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1077 ndlp->nlp_sid = rport->scsi_target_id;
1079 rdata = rport->dd_data;
1080 rdata->pnode = ndlp;
1082 if (ndlp->nlp_type & NLP_FCP_TARGET)
1083 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1084 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1085 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1088 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1089 fc_remote_port_rolechg(rport, rport_ids.roles);
1096 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1097 struct lpfc_nodelist * ndlp)
1099 struct fc_rport *rport = ndlp->rport;
1100 struct lpfc_rport_data *rdata = rport->dd_data;
1103 rdata->pnode = NULL;
1104 fc_remote_port_delete(rport);
1110 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1112 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1113 struct lpfc_sli *psli;
1116 /* Sanity check to ensure we are not moving to / from the same list */
1117 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1118 if (list != NLP_NO_LIST)
1121 switch (nlp->nlp_flag & NLP_LIST_MASK) {
1122 case NLP_NO_LIST: /* Not on any list */
1124 case NLP_UNUSED_LIST:
1125 phba->fc_unused_cnt--;
1126 list_del(&nlp->nlp_listp);
1128 case NLP_PLOGI_LIST:
1129 phba->fc_plogi_cnt--;
1130 list_del(&nlp->nlp_listp);
1132 case NLP_ADISC_LIST:
1133 phba->fc_adisc_cnt--;
1134 list_del(&nlp->nlp_listp);
1136 case NLP_REGLOGIN_LIST:
1137 phba->fc_reglogin_cnt--;
1138 list_del(&nlp->nlp_listp);
1141 phba->fc_prli_cnt--;
1142 list_del(&nlp->nlp_listp);
1144 case NLP_UNMAPPED_LIST:
1145 phba->fc_unmap_cnt--;
1146 list_del(&nlp->nlp_listp);
1147 spin_lock_irq(phba->host->host_lock);
1148 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1149 nlp->nlp_type &= ~NLP_FC_NODE;
1150 spin_unlock_irq(phba->host->host_lock);
1151 phba->nport_event_cnt++;
1153 rport_del = unmapped;
1155 case NLP_MAPPED_LIST:
1157 list_del(&nlp->nlp_listp);
1158 phba->nport_event_cnt++;
1164 list_del(&nlp->nlp_listp);
1165 /* Stop delay tmo if taking node off NPR list */
1166 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1167 (list != NLP_NPR_LIST)) {
1168 spin_lock_irq(phba->host->host_lock);
1169 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1170 spin_unlock_irq(phba->host->host_lock);
1171 nlp->nlp_last_elscmd = 0;
1172 del_timer_sync(&nlp->nlp_delayfunc);
1173 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1174 list_del_init(&nlp->els_retry_evt.evt_listp);
1179 spin_lock_irq(phba->host->host_lock);
1180 nlp->nlp_flag &= ~NLP_LIST_MASK;
1181 spin_unlock_irq(phba->host->host_lock);
1183 /* Add NPort <did> to <num> list */
1184 lpfc_printf_log(phba,
1187 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1189 nlp->nlp_DID, list, nlp->nlp_flag);
1192 case NLP_NO_LIST: /* No list, just remove it */
1193 lpfc_nlp_remove(phba, nlp);
1194 /* as node removed - stop further transport calls */
1197 case NLP_UNUSED_LIST:
1198 spin_lock_irq(phba->host->host_lock);
1199 nlp->nlp_flag |= list;
1200 spin_unlock_irq(phba->host->host_lock);
1201 /* Put it at the end of the unused list */
1202 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1203 phba->fc_unused_cnt++;
1205 case NLP_PLOGI_LIST:
1206 spin_lock_irq(phba->host->host_lock);
1207 nlp->nlp_flag |= list;
1208 spin_unlock_irq(phba->host->host_lock);
1209 /* Put it at the end of the plogi list */
1210 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1211 phba->fc_plogi_cnt++;
1213 case NLP_ADISC_LIST:
1214 spin_lock_irq(phba->host->host_lock);
1215 nlp->nlp_flag |= list;
1216 spin_unlock_irq(phba->host->host_lock);
1217 /* Put it at the end of the adisc list */
1218 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1219 phba->fc_adisc_cnt++;
1221 case NLP_REGLOGIN_LIST:
1222 spin_lock_irq(phba->host->host_lock);
1223 nlp->nlp_flag |= list;
1224 spin_unlock_irq(phba->host->host_lock);
1225 /* Put it at the end of the reglogin list */
1226 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1227 phba->fc_reglogin_cnt++;
1230 spin_lock_irq(phba->host->host_lock);
1231 nlp->nlp_flag |= list;
1232 spin_unlock_irq(phba->host->host_lock);
1233 /* Put it at the end of the prli list */
1234 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1235 phba->fc_prli_cnt++;
1237 case NLP_UNMAPPED_LIST:
1238 rport_add = unmapped;
1239 /* ensure all vestiges of "mapped" significance are gone */
1240 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1241 spin_lock_irq(phba->host->host_lock);
1242 nlp->nlp_flag |= list;
1243 spin_unlock_irq(phba->host->host_lock);
1244 /* Put it at the end of the unmap list */
1245 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1246 phba->fc_unmap_cnt++;
1247 phba->nport_event_cnt++;
1248 /* stop nodev tmo if running */
1249 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1250 spin_lock_irq(phba->host->host_lock);
1251 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1252 spin_unlock_irq(phba->host->host_lock);
1253 del_timer_sync(&nlp->nlp_tmofunc);
1254 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1255 list_del_init(&nlp->nodev_timeout_evt.
1259 nlp->nlp_type |= NLP_FC_NODE;
1261 case NLP_MAPPED_LIST:
1263 spin_lock_irq(phba->host->host_lock);
1264 nlp->nlp_flag |= list;
1265 spin_unlock_irq(phba->host->host_lock);
1266 /* Put it at the end of the map list */
1267 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1269 phba->nport_event_cnt++;
1270 /* stop nodev tmo if running */
1271 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1272 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1273 del_timer_sync(&nlp->nlp_tmofunc);
1274 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1275 list_del_init(&nlp->nodev_timeout_evt.
1281 spin_lock_irq(phba->host->host_lock);
1282 nlp->nlp_flag |= list;
1283 spin_unlock_irq(phba->host->host_lock);
1284 /* Put it at the end of the npr list */
1285 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1288 if (!(nlp->nlp_flag & NLP_NODEV_TMO))
1289 mod_timer(&nlp->nlp_tmofunc,
1290 jiffies + HZ * phba->cfg_nodev_tmo);
1292 spin_lock_irq(phba->host->host_lock);
1293 nlp->nlp_flag |= NLP_NODEV_TMO;
1294 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1295 spin_unlock_irq(phba->host->host_lock);
1302 * We make all the calls into the transport after we have
1303 * moved the node between lists. This so that we don't
1304 * release the lock while in-between lists.
1307 /* Don't upcall midlayer if we're unloading */
1308 if (!(phba->fc_flag & FC_UNLOADING)) {
1310 * We revalidate the rport pointer as the "add" function
1311 * may have removed the remote port.
1313 if ((rport_del != none) && nlp->rport)
1314 lpfc_unregister_remote_port(phba, nlp);
1316 if (rport_add != none) {
1318 * Tell the fc transport about the port, if we haven't
1319 * already. If we have, and it's a scsi entity, be
1320 * sure to unblock any attached scsi devices
1323 lpfc_register_remote_port(phba, nlp);
1326 * if we added to Mapped list, but the remote port
1327 * registration failed or assigned a target id outside
1328 * our presentable range - move the node to the
1331 if ((rport_add == mapped) &&
1333 (nlp->rport->scsi_target_id == -1) ||
1334 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1335 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1336 spin_lock_irq(phba->host->host_lock);
1337 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1338 spin_unlock_irq(phba->host->host_lock);
1339 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1347 * Start / ReStart rescue timer for Discovery / RSCN handling
1350 lpfc_set_disctmo(struct lpfc_hba * phba)
1354 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1355 /* For FAN, timeout should be greater then edtov */
1356 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1358 /* Normal discovery timeout should be > then ELS/CT timeout
1359 * FC spec states we need 3 * ratov for CT requests
1361 tmo = ((phba->fc_ratov * 3) + 3);
1364 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1365 spin_lock_irq(phba->host->host_lock);
1366 phba->fc_flag |= FC_DISC_TMO;
1367 spin_unlock_irq(phba->host->host_lock);
1369 /* Start Discovery Timer state <hba_state> */
1370 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1371 "%d:0247 Start Discovery Timer state x%x "
1372 "Data: x%x x%lx x%x x%x\n",
1374 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1375 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1381 * Cancel rescue timer for Discovery / RSCN handling
1384 lpfc_can_disctmo(struct lpfc_hba * phba)
1386 /* Turn off discovery timer if its running */
1387 if (phba->fc_flag & FC_DISC_TMO) {
1388 spin_lock_irq(phba->host->host_lock);
1389 phba->fc_flag &= ~FC_DISC_TMO;
1390 spin_unlock_irq(phba->host->host_lock);
1391 del_timer_sync(&phba->fc_disctmo);
1392 phba->work_hba_events &= ~WORKER_DISC_TMO;
1395 /* Cancel Discovery Timer state <hba_state> */
1396 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1397 "%d:0248 Cancel Discovery Timer state x%x "
1398 "Data: x%x x%x x%x\n",
1399 phba->brd_no, phba->hba_state, phba->fc_flag,
1400 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1406 * Check specified ring for outstanding IOCB on the SLI queue
1407 * Return true if iocb matches the specified nport
1410 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1411 struct lpfc_sli_ring * pring,
1412 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1414 struct lpfc_sli *psli;
1419 if (pring->ringno == LPFC_ELS_RING) {
1420 switch (icmd->ulpCommand) {
1421 case CMD_GEN_REQUEST64_CR:
1422 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1424 case CMD_ELS_REQUEST64_CR:
1425 case CMD_XMIT_ELS_RSP64_CX:
1426 if (iocb->context1 == (uint8_t *) ndlp)
1429 } else if (pring->ringno == psli->ip_ring) {
1431 } else if (pring->ringno == psli->fcp_ring) {
1432 /* Skip match check if waiting to relogin to FCP target */
1433 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1434 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1437 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1440 } else if (pring->ringno == psli->next_ring) {
1447 * Free resources / clean up outstanding I/Os
1448 * associated with nlp_rpi in the LPFC_NODELIST entry.
1451 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1453 struct lpfc_sli *psli;
1454 struct lpfc_sli_ring *pring;
1455 struct lpfc_iocbq *iocb, *next_iocb;
1460 * Everything that matches on txcmplq will be returned
1461 * by firmware with a no rpi error.
1464 rpi = ndlp->nlp_rpi;
1466 /* Now process each ring */
1467 for (i = 0; i < psli->num_rings; i++) {
1468 pring = &psli->ring[i];
1470 spin_lock_irq(phba->host->host_lock);
1471 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1474 * Check to see if iocb matches the nport we are
1477 if ((lpfc_check_sli_ndlp
1478 (phba, pring, iocb, ndlp))) {
1479 /* It matches, so deque and call compl
1481 list_del(&iocb->list);
1483 if (iocb->iocb_cmpl) {
1486 IOSTAT_LOCAL_REJECT;
1487 icmd->un.ulpWord[4] =
1489 spin_unlock_irq(phba->host->
1491 (iocb->iocb_cmpl) (phba,
1493 spin_lock_irq(phba->host->
1496 lpfc_sli_release_iocbq(phba,
1500 spin_unlock_irq(phba->host->host_lock);
1508 * Free rpi associated with LPFC_NODELIST entry.
1509 * This routine is called from lpfc_freenode(), when we are removing
1510 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1511 * LOGO that completes successfully, and we are waiting to PLOGI back
1512 * to the remote NPort. In addition, it is called after we receive
1513 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1514 * we are waiting to PLOGI back to the remote NPort.
1517 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1522 if (ndlp->nlp_rpi) {
1523 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1524 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1525 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1526 rc = lpfc_sli_issue_mbox
1527 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1528 if (rc == MBX_NOT_FINISHED)
1529 mempool_free( mbox, phba->mbox_mem_pool);
1531 lpfc_no_rpi(phba, ndlp);
1539 * Free resources associated with LPFC_NODELIST entry
1540 * so it can be freed.
1543 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1546 LPFC_MBOXQ_t *nextmb;
1547 struct lpfc_dmabuf *mp;
1549 /* Cleanup node for NPort <nlp_DID> */
1550 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1551 "%d:0900 Cleanup node for NPort x%x "
1552 "Data: x%x x%x x%x\n",
1553 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1554 ndlp->nlp_state, ndlp->nlp_rpi);
1556 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1559 * if unloading the driver - just leave the remote port in place.
1560 * The driver unload will force the attached devices to detach
1561 * and flush cache's w/o generating flush errors.
1563 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1564 lpfc_unregister_remote_port(phba, ndlp);
1565 ndlp->nlp_sid = NLP_NO_SID;
1568 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1569 if ((mb = phba->sli.mbox_active)) {
1570 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1571 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1572 mb->context2 = NULL;
1573 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1576 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1577 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1578 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1579 mp = (struct lpfc_dmabuf *) (mb->context1);
1581 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1584 list_del(&mb->list);
1585 mempool_free(mb, phba->mbox_mem_pool);
1589 lpfc_els_abort(phba,ndlp,0);
1590 spin_lock_irq(phba->host->host_lock);
1591 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1592 spin_unlock_irq(phba->host->host_lock);
1593 del_timer_sync(&ndlp->nlp_tmofunc);
1595 ndlp->nlp_last_elscmd = 0;
1596 del_timer_sync(&ndlp->nlp_delayfunc);
1598 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1599 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1600 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1601 list_del_init(&ndlp->els_retry_evt.evt_listp);
1603 lpfc_unreg_rpi(phba, ndlp);
1609 * Check to see if we can free the nlp back to the freelist.
1610 * If we are in the middle of using the nlp in the discovery state
1611 * machine, defer the free till we reach the end of the state machine.
1614 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1616 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1617 spin_lock_irq(phba->host->host_lock);
1618 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1619 spin_unlock_irq(phba->host->host_lock);
1620 del_timer_sync(&ndlp->nlp_tmofunc);
1621 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1622 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1627 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1628 spin_lock_irq(phba->host->host_lock);
1629 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1630 spin_unlock_irq(phba->host->host_lock);
1631 ndlp->nlp_last_elscmd = 0;
1632 del_timer_sync(&ndlp->nlp_delayfunc);
1633 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1634 list_del_init(&ndlp->els_retry_evt.evt_listp);
1637 if (ndlp->nlp_disc_refcnt) {
1638 spin_lock_irq(phba->host->host_lock);
1639 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1640 spin_unlock_irq(phba->host->host_lock);
1642 lpfc_freenode(phba, ndlp);
1643 mempool_free( ndlp, phba->nlp_mem_pool);
1649 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1655 if (did == Bcast_DID)
1658 if (ndlp->nlp_DID == 0) {
1662 /* First check for Direct match */
1663 if (ndlp->nlp_DID == did)
1666 /* Next check for area/domain identically equals 0 match */
1667 mydid.un.word = phba->fc_myDID;
1668 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1672 matchdid.un.word = did;
1673 ndlpdid.un.word = ndlp->nlp_DID;
1674 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1675 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1676 (mydid.un.b.area == matchdid.un.b.area)) {
1677 if ((ndlpdid.un.b.domain == 0) &&
1678 (ndlpdid.un.b.area == 0)) {
1679 if (ndlpdid.un.b.id)
1685 matchdid.un.word = ndlp->nlp_DID;
1686 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1687 (mydid.un.b.area == ndlpdid.un.b.area)) {
1688 if ((matchdid.un.b.domain == 0) &&
1689 (matchdid.un.b.area == 0)) {
1690 if (matchdid.un.b.id)
1698 /* Search for a nodelist entry on a specific list */
1699 struct lpfc_nodelist *
1700 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1702 struct lpfc_nodelist *ndlp, *next_ndlp;
1705 if (order & NLP_SEARCH_UNMAPPED) {
1706 list_for_each_entry_safe(ndlp, next_ndlp,
1707 &phba->fc_nlpunmap_list, nlp_listp) {
1708 if (lpfc_matchdid(phba, ndlp, did)) {
1709 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1710 ((uint32_t) ndlp->nlp_xri << 16) |
1711 ((uint32_t) ndlp->nlp_type << 8) |
1712 ((uint32_t) ndlp->nlp_rpi & 0xff));
1713 /* FIND node DID unmapped */
1714 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1715 "%d:0929 FIND node DID unmapped"
1716 " Data: x%p x%x x%x x%x\n",
1718 ndlp, ndlp->nlp_DID,
1719 ndlp->nlp_flag, data1);
1725 if (order & NLP_SEARCH_MAPPED) {
1726 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1728 if (lpfc_matchdid(phba, ndlp, did)) {
1730 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1731 ((uint32_t) ndlp->nlp_xri << 16) |
1732 ((uint32_t) ndlp->nlp_type << 8) |
1733 ((uint32_t) ndlp->nlp_rpi & 0xff));
1734 /* FIND node DID mapped */
1735 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1736 "%d:0930 FIND node DID mapped "
1737 "Data: x%p x%x x%x x%x\n",
1739 ndlp, ndlp->nlp_DID,
1740 ndlp->nlp_flag, data1);
1746 if (order & NLP_SEARCH_PLOGI) {
1747 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1749 if (lpfc_matchdid(phba, ndlp, did)) {
1751 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1752 ((uint32_t) ndlp->nlp_xri << 16) |
1753 ((uint32_t) ndlp->nlp_type << 8) |
1754 ((uint32_t) ndlp->nlp_rpi & 0xff));
1755 /* LOG change to PLOGI */
1756 /* FIND node DID plogi */
1757 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1758 "%d:0908 FIND node DID plogi "
1759 "Data: x%p x%x x%x x%x\n",
1761 ndlp, ndlp->nlp_DID,
1762 ndlp->nlp_flag, data1);
1768 if (order & NLP_SEARCH_ADISC) {
1769 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1771 if (lpfc_matchdid(phba, ndlp, did)) {
1773 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1774 ((uint32_t) ndlp->nlp_xri << 16) |
1775 ((uint32_t) ndlp->nlp_type << 8) |
1776 ((uint32_t) ndlp->nlp_rpi & 0xff));
1777 /* LOG change to ADISC */
1778 /* FIND node DID adisc */
1779 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1780 "%d:0931 FIND node DID adisc "
1781 "Data: x%p x%x x%x x%x\n",
1783 ndlp, ndlp->nlp_DID,
1784 ndlp->nlp_flag, data1);
1790 if (order & NLP_SEARCH_REGLOGIN) {
1791 list_for_each_entry_safe(ndlp, next_ndlp,
1792 &phba->fc_reglogin_list, nlp_listp) {
1793 if (lpfc_matchdid(phba, ndlp, did)) {
1795 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1796 ((uint32_t) ndlp->nlp_xri << 16) |
1797 ((uint32_t) ndlp->nlp_type << 8) |
1798 ((uint32_t) ndlp->nlp_rpi & 0xff));
1799 /* LOG change to REGLOGIN */
1800 /* FIND node DID reglogin */
1801 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1802 "%d:0931 FIND node DID reglogin"
1803 " Data: x%p x%x x%x x%x\n",
1805 ndlp, ndlp->nlp_DID,
1806 ndlp->nlp_flag, data1);
1812 if (order & NLP_SEARCH_PRLI) {
1813 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1815 if (lpfc_matchdid(phba, ndlp, did)) {
1817 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1818 ((uint32_t) ndlp->nlp_xri << 16) |
1819 ((uint32_t) ndlp->nlp_type << 8) |
1820 ((uint32_t) ndlp->nlp_rpi & 0xff));
1821 /* LOG change to PRLI */
1822 /* FIND node DID prli */
1823 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1824 "%d:0931 FIND node DID prli "
1825 "Data: x%p x%x x%x x%x\n",
1827 ndlp, ndlp->nlp_DID,
1828 ndlp->nlp_flag, data1);
1834 if (order & NLP_SEARCH_NPR) {
1835 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1837 if (lpfc_matchdid(phba, ndlp, did)) {
1839 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1840 ((uint32_t) ndlp->nlp_xri << 16) |
1841 ((uint32_t) ndlp->nlp_type << 8) |
1842 ((uint32_t) ndlp->nlp_rpi & 0xff));
1843 /* LOG change to NPR */
1844 /* FIND node DID npr */
1845 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1846 "%d:0931 FIND node DID npr "
1847 "Data: x%p x%x x%x x%x\n",
1849 ndlp, ndlp->nlp_DID,
1850 ndlp->nlp_flag, data1);
1856 if (order & NLP_SEARCH_UNUSED) {
1857 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1859 if (lpfc_matchdid(phba, ndlp, did)) {
1861 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1862 ((uint32_t) ndlp->nlp_xri << 16) |
1863 ((uint32_t) ndlp->nlp_type << 8) |
1864 ((uint32_t) ndlp->nlp_rpi & 0xff));
1865 /* LOG change to UNUSED */
1866 /* FIND node DID unused */
1867 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1868 "%d:0931 FIND node DID unused "
1869 "Data: x%p x%x x%x x%x\n",
1871 ndlp, ndlp->nlp_DID,
1872 ndlp->nlp_flag, data1);
1878 /* FIND node did <did> NOT FOUND */
1879 lpfc_printf_log(phba,
1882 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1883 phba->brd_no, did, order);
1885 /* no match found */
1889 struct lpfc_nodelist *
1890 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1892 struct lpfc_nodelist *ndlp;
1895 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1897 if ((phba->fc_flag & FC_RSCN_MODE) &&
1898 ((lpfc_rscn_payload_check(phba, did) == 0)))
1900 ndlp = (struct lpfc_nodelist *)
1901 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1904 lpfc_nlp_init(phba, ndlp, did);
1905 ndlp->nlp_state = NLP_STE_NPR_NODE;
1906 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1907 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1910 if (phba->fc_flag & FC_RSCN_MODE) {
1911 if (lpfc_rscn_payload_check(phba, did)) {
1912 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1914 /* Since this node is marked for discovery,
1915 * delay timeout is not needed.
1917 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1918 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1919 spin_unlock_irq(phba->host->host_lock);
1920 del_timer_sync(&ndlp->nlp_delayfunc);
1921 spin_lock_irq(phba->host->host_lock);
1922 if (!list_empty(&ndlp->els_retry_evt.
1924 list_del_init(&ndlp->els_retry_evt.
1928 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1932 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1933 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1935 ndlp->nlp_state = NLP_STE_NPR_NODE;
1936 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1937 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1942 /* Build a list of nodes to discover based on the loopmap */
1944 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1947 uint32_t alpa, index;
1949 if (phba->hba_state <= LPFC_LINK_DOWN) {
1952 if (phba->fc_topology != TOPOLOGY_LOOP) {
1956 /* Check for loop map present or not */
1957 if (phba->alpa_map[0]) {
1958 for (j = 1; j <= phba->alpa_map[0]; j++) {
1959 alpa = phba->alpa_map[j];
1961 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1964 lpfc_setup_disc_node(phba, alpa);
1967 /* No alpamap, so try all alpa's */
1968 for (j = 0; j < FC_MAXLOOP; j++) {
1969 /* If cfg_scan_down is set, start from highest
1970 * ALPA (0xef) to lowest (0x1).
1972 if (phba->cfg_scan_down)
1975 index = FC_MAXLOOP - j - 1;
1976 alpa = lpfcAlpaArray[index];
1977 if ((phba->fc_myDID & 0xff) == alpa) {
1981 lpfc_setup_disc_node(phba, alpa);
1987 /* Start Link up / RSCN discovery on NPR list */
1989 lpfc_disc_start(struct lpfc_hba * phba)
1991 struct lpfc_sli *psli;
1993 struct lpfc_nodelist *ndlp, *next_ndlp;
1994 uint32_t did_changed, num_sent;
1995 uint32_t clear_la_pending;
2000 if (phba->hba_state <= LPFC_LINK_DOWN) {
2003 if (phba->hba_state == LPFC_CLEAR_LA)
2004 clear_la_pending = 1;
2006 clear_la_pending = 0;
2008 if (phba->hba_state < LPFC_HBA_READY) {
2009 phba->hba_state = LPFC_DISC_AUTH;
2011 lpfc_set_disctmo(phba);
2013 if (phba->fc_prevDID == phba->fc_myDID) {
2018 phba->fc_prevDID = phba->fc_myDID;
2019 phba->num_disc_nodes = 0;
2021 /* Start Discovery state <hba_state> */
2022 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2023 "%d:0202 Start Discovery hba state x%x "
2024 "Data: x%x x%x x%x\n",
2025 phba->brd_no, phba->hba_state, phba->fc_flag,
2026 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2028 /* If our did changed, we MUST do PLOGI */
2029 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2031 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2033 spin_lock_irq(phba->host->host_lock);
2034 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2035 spin_unlock_irq(phba->host->host_lock);
2040 /* First do ADISCs - if any */
2041 num_sent = lpfc_els_disc_adisc(phba);
2046 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2047 /* If we get here, there is nothing to ADISC */
2048 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2049 phba->hba_state = LPFC_CLEAR_LA;
2050 lpfc_clear_la(phba, mbox);
2051 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2052 rc = lpfc_sli_issue_mbox(phba, mbox,
2053 (MBX_NOWAIT | MBX_STOP_IOCB));
2054 if (rc == MBX_NOT_FINISHED) {
2055 mempool_free( mbox, phba->mbox_mem_pool);
2056 lpfc_disc_flush_list(phba);
2057 psli->ring[(psli->ip_ring)].flag &=
2058 ~LPFC_STOP_IOCB_EVENT;
2059 psli->ring[(psli->fcp_ring)].flag &=
2060 ~LPFC_STOP_IOCB_EVENT;
2061 psli->ring[(psli->next_ring)].flag &=
2062 ~LPFC_STOP_IOCB_EVENT;
2063 phba->hba_state = LPFC_HBA_READY;
2067 /* Next do PLOGIs - if any */
2068 num_sent = lpfc_els_disc_plogi(phba);
2073 if (phba->fc_flag & FC_RSCN_MODE) {
2074 /* Check to see if more RSCNs came in while we
2075 * were processing this one.
2077 if ((phba->fc_rscn_id_cnt == 0) &&
2078 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2079 spin_lock_irq(phba->host->host_lock);
2080 phba->fc_flag &= ~FC_RSCN_MODE;
2081 spin_unlock_irq(phba->host->host_lock);
2083 lpfc_els_handle_rscn(phba);
2090 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2091 * ring the match the sppecified nodelist.
2094 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2096 struct lpfc_sli *psli;
2098 struct lpfc_iocbq *iocb, *next_iocb;
2099 struct lpfc_sli_ring *pring;
2100 struct lpfc_dmabuf *mp;
2103 pring = &psli->ring[LPFC_ELS_RING];
2105 /* Error matching iocb on txq or txcmplq
2106 * First check the txq.
2108 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2109 if (iocb->context1 != ndlp) {
2113 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2114 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2116 list_del(&iocb->list);
2118 lpfc_els_free_iocb(phba, iocb);
2122 /* Next check the txcmplq */
2123 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2124 if (iocb->context1 != ndlp) {
2128 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2129 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2131 iocb->iocb_cmpl = NULL;
2132 /* context2 = cmd, context2->next = rsp, context3 =
2134 if (iocb->context2) {
2135 /* Free the response IOCB before handling the
2138 mp = (struct lpfc_dmabuf *) (iocb->context2);
2139 mp = list_get_first(&mp->list,
2143 /* Delay before releasing rsp buffer to
2144 * give UNREG mbox a chance to take
2148 &phba->freebufList);
2150 lpfc_mbuf_free(phba,
2151 ((struct lpfc_dmabuf *)
2152 iocb->context2)->virt,
2153 ((struct lpfc_dmabuf *)
2154 iocb->context2)->phys);
2155 kfree(iocb->context2);
2158 if (iocb->context3) {
2159 lpfc_mbuf_free(phba,
2160 ((struct lpfc_dmabuf *)
2161 iocb->context3)->virt,
2162 ((struct lpfc_dmabuf *)
2163 iocb->context3)->phys);
2164 kfree(iocb->context3);
2173 lpfc_disc_flush_list(struct lpfc_hba * phba)
2175 struct lpfc_nodelist *ndlp, *next_ndlp;
2177 if (phba->fc_plogi_cnt) {
2178 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2180 lpfc_free_tx(phba, ndlp);
2181 lpfc_nlp_remove(phba, ndlp);
2184 if (phba->fc_adisc_cnt) {
2185 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2187 lpfc_free_tx(phba, ndlp);
2188 lpfc_nlp_remove(phba, ndlp);
2194 /*****************************************************************************/
2196 * NAME: lpfc_disc_timeout
2198 * FUNCTION: Fibre Channel driver discovery timeout routine.
2200 * EXECUTION ENVIRONMENT: interrupt only
2208 /*****************************************************************************/
2210 lpfc_disc_timeout(unsigned long ptr)
2212 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2213 unsigned long flags = 0;
2215 if (unlikely(!phba))
2218 spin_lock_irqsave(phba->host->host_lock, flags);
2219 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2220 phba->work_hba_events |= WORKER_DISC_TMO;
2221 if (phba->work_wait)
2222 wake_up(phba->work_wait);
2224 spin_unlock_irqrestore(phba->host->host_lock, flags);
2229 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2231 struct lpfc_sli *psli;
2232 struct lpfc_nodelist *ndlp, *next_ndlp;
2233 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2234 int rc, clrlaerr = 0;
2236 if (unlikely(!phba))
2239 if (!(phba->fc_flag & FC_DISC_TMO))
2244 spin_lock_irq(phba->host->host_lock);
2245 phba->fc_flag &= ~FC_DISC_TMO;
2246 spin_unlock_irq(phba->host->host_lock);
2248 switch (phba->hba_state) {
2250 case LPFC_LOCAL_CFG_LINK:
2251 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2253 lpfc_printf_log(phba,
2256 "%d:0221 FAN timeout\n",
2259 /* Start discovery by sending FLOGI, clean up old rpis */
2260 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2262 if (ndlp->nlp_type & NLP_FABRIC) {
2263 /* Clean up the ndlp on Fabric connections */
2264 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2265 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2266 /* Fail outstanding IO now since device
2267 * is marked for PLOGI.
2269 lpfc_unreg_rpi(phba, ndlp);
2272 phba->hba_state = LPFC_FLOGI;
2273 lpfc_set_disctmo(phba);
2274 lpfc_initial_flogi(phba);
2278 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2279 /* Initial FLOGI timeout */
2280 lpfc_printf_log(phba,
2283 "%d:0222 Initial FLOGI timeout\n",
2286 /* Assume no Fabric and go on with discovery.
2287 * Check for outstanding ELS FLOGI to abort.
2290 /* FLOGI failed, so just use loop map to make discovery list */
2291 lpfc_disc_list_loopmap(phba);
2293 /* Start discovery */
2294 lpfc_disc_start(phba);
2297 case LPFC_FABRIC_CFG_LINK:
2298 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2300 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2301 "%d:0223 Timeout while waiting for NameServer "
2302 "login\n", phba->brd_no);
2304 /* Next look for NameServer ndlp */
2305 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2307 lpfc_nlp_remove(phba, ndlp);
2308 /* Start discovery */
2309 lpfc_disc_start(phba);
2313 /* Check for wait for NameServer Rsp timeout */
2314 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2315 "%d:0224 NameServer Query timeout "
2318 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2320 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2323 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2324 /* Try it one more time */
2325 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2329 phba->fc_ns_retry = 0;
2332 /* Nothing to authenticate, so CLEAR_LA right now */
2333 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2336 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2337 "%d:0226 Device Discovery "
2338 "completion error\n",
2340 phba->hba_state = LPFC_HBA_ERROR;
2344 phba->hba_state = LPFC_CLEAR_LA;
2345 lpfc_clear_la(phba, clearlambox);
2346 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2347 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2348 (MBX_NOWAIT | MBX_STOP_IOCB));
2349 if (rc == MBX_NOT_FINISHED) {
2350 mempool_free(clearlambox, phba->mbox_mem_pool);
2355 /* Setup and issue mailbox INITIALIZE LINK command */
2356 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2357 if (!initlinkmbox) {
2358 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2359 "%d:0226 Device Discovery "
2360 "completion error\n",
2362 phba->hba_state = LPFC_HBA_ERROR;
2366 lpfc_linkdown(phba);
2367 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2368 phba->cfg_link_speed);
2369 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2370 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2371 (MBX_NOWAIT | MBX_STOP_IOCB));
2372 if (rc == MBX_NOT_FINISHED)
2373 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2377 case LPFC_DISC_AUTH:
2378 /* Node Authentication timeout */
2379 lpfc_printf_log(phba,
2382 "%d:0227 Node Authentication timeout\n",
2384 lpfc_disc_flush_list(phba);
2385 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2388 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2389 "%d:0226 Device Discovery "
2390 "completion error\n",
2392 phba->hba_state = LPFC_HBA_ERROR;
2395 phba->hba_state = LPFC_CLEAR_LA;
2396 lpfc_clear_la(phba, clearlambox);
2397 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2398 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2399 (MBX_NOWAIT | MBX_STOP_IOCB));
2400 if (rc == MBX_NOT_FINISHED) {
2401 mempool_free(clearlambox, phba->mbox_mem_pool);
2407 /* CLEAR LA timeout */
2408 lpfc_printf_log(phba,
2411 "%d:0228 CLEAR LA timeout\n",
2416 case LPFC_HBA_READY:
2417 if (phba->fc_flag & FC_RSCN_MODE) {
2418 lpfc_printf_log(phba,
2421 "%d:0231 RSCN timeout Data: x%x x%x\n",
2423 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2425 /* Cleanup any outstanding ELS commands */
2426 lpfc_els_flush_cmd(phba);
2428 lpfc_els_flush_rscn(phba);
2429 lpfc_disc_flush_list(phba);
2435 lpfc_disc_flush_list(phba);
2436 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2437 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2438 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2439 phba->hba_state = LPFC_HBA_READY;
2446 lpfc_nodev_timeout(unsigned long ptr)
2448 struct lpfc_hba *phba;
2449 struct lpfc_nodelist *ndlp;
2450 unsigned long iflag;
2451 struct lpfc_work_evt *evtp;
2453 ndlp = (struct lpfc_nodelist *)ptr;
2454 phba = ndlp->nlp_phba;
2455 evtp = &ndlp->nodev_timeout_evt;
2456 spin_lock_irqsave(phba->host->host_lock, iflag);
2458 if (!list_empty(&evtp->evt_listp)) {
2459 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2462 evtp->evt_arg1 = ndlp;
2463 evtp->evt = LPFC_EVT_NODEV_TMO;
2464 list_add_tail(&evtp->evt_listp, &phba->work_list);
2465 if (phba->work_wait)
2466 wake_up(phba->work_wait);
2468 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2474 * This routine handles processing a NameServer REG_LOGIN mailbox
2475 * command upon completion. It is setup in the LPFC_MBOXQ
2476 * as the completion routine when the command is
2477 * handed off to the SLI layer.
2480 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2482 struct lpfc_sli *psli;
2484 struct lpfc_dmabuf *mp;
2485 struct lpfc_nodelist *ndlp;
2490 ndlp = (struct lpfc_nodelist *) pmb->context2;
2491 mp = (struct lpfc_dmabuf *) (pmb->context1);
2493 pmb->context1 = NULL;
2495 ndlp->nlp_rpi = mb->un.varWords[0];
2496 ndlp->nlp_type |= NLP_FABRIC;
2497 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2498 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2500 /* Start issuing Fabric-Device Management Interface (FDMI)
2501 * command to 0xfffffa (FDMI well known port)
2503 if (phba->cfg_fdmi_on == 1) {
2504 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2507 * Delay issuing FDMI command if fdmi-on=2
2508 * (supporting RPA/hostnmae)
2510 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2513 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2515 mempool_free( pmb, phba->mbox_mem_pool);
2521 * This routine looks up the ndlp lists
2522 * for the given RPI. If rpi found
2523 * it return the node list pointer
2526 struct lpfc_nodelist *
2527 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2529 struct lpfc_nodelist *ndlp;
2530 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2531 &phba->fc_nlpmap_list,
2532 &phba->fc_plogi_list,
2533 &phba->fc_adisc_list,
2534 &phba->fc_reglogin_list};
2537 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2538 list_for_each_entry(ndlp, lists[i], nlp_listp)
2539 if (ndlp->nlp_rpi == rpi)
2546 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2549 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2550 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2551 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2552 init_timer(&ndlp->nlp_tmofunc);
2553 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2554 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2555 init_timer(&ndlp->nlp_delayfunc);
2556 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2557 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2558 ndlp->nlp_DID = did;
2559 ndlp->nlp_phba = phba;
2560 ndlp->nlp_sid = NLP_NO_SID;