1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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"
39 #include "lpfc_vport.h"
41 /* AlpaArray for assignment of scsid for scan-down and bind_method */
42 static uint8_t lpfcAlpaArray[] = {
43 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
44 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
45 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
46 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
47 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
48 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
49 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
50 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
51 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
52 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
53 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
54 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
55 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
58 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
61 lpfc_terminate_rport_io(struct fc_rport *rport)
63 struct lpfc_rport_data *rdata;
64 struct lpfc_nodelist * ndlp;
65 struct lpfc_hba *phba;
67 rdata = rport->dd_data;
71 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
72 printk(KERN_ERR "Cannot find remote node"
73 " to terminate I/O Data x%x\n",
78 phba = ndlp->vport->phba;
80 if (ndlp->nlp_sid != NLP_NO_SID) {
81 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
82 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
89 * This function will be called when dev_loss_tmo fire.
92 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
94 struct lpfc_rport_data *rdata;
95 struct lpfc_nodelist * ndlp;
98 struct lpfc_hba *phba;
99 struct lpfc_vport *vport;
103 rdata = rport->dd_data;
107 if (rport->scsi_target_id != -1) {
108 printk(KERN_ERR "Cannot find remote node"
109 " for rport in dev_loss_tmo_callbk x%x\n",
115 if (ndlp->nlp_type & NLP_FABRIC) {
116 /* We will clean up these Nodes in linkup */
117 put_node = rdata->pnode != NULL;
118 put_rport = ndlp->rport != NULL;
124 put_device(&rport->dev);
128 name = (uint8_t *)&ndlp->nlp_portname;
132 if (!(vport->load_flag & FC_UNLOADING) &&
133 ndlp->nlp_state == NLP_STE_MAPPED_NODE)
137 if (ndlp->nlp_sid != NLP_NO_SID) {
139 /* flush the target */
140 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
141 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
143 if (vport->load_flag & FC_UNLOADING)
147 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
148 "%d (%d):0203 Devloss timeout on "
149 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
150 "NPort x%x Data: x%x x%x x%x\n",
151 phba->brd_no, vport->vpi,
152 *name, *(name+1), *(name+2), *(name+3),
153 *(name+4), *(name+5), *(name+6), *(name+7),
154 ndlp->nlp_DID, ndlp->nlp_flag,
155 ndlp->nlp_state, ndlp->nlp_rpi);
157 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
158 "%d (%d):0204 Devloss timeout on "
159 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
160 "NPort x%x Data: x%x x%x x%x\n",
161 phba->brd_no, vport->vpi,
162 *name, *(name+1), *(name+2), *(name+3),
163 *(name+4), *(name+5), *(name+6), *(name+7),
164 ndlp->nlp_DID, ndlp->nlp_flag,
165 ndlp->nlp_state, ndlp->nlp_rpi);
168 if (!(vport->load_flag & FC_UNLOADING) &&
169 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
170 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
171 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
172 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
174 put_node = rdata->pnode != NULL;
175 put_rport = ndlp->rport != NULL;
181 put_device(&rport->dev);
188 lpfc_worker_wake_up(struct lpfc_hba *phba)
190 wake_up(phba->work_wait);
195 lpfc_work_list_done(struct lpfc_hba *phba)
197 struct lpfc_work_evt *evtp = NULL;
198 struct lpfc_nodelist *ndlp;
199 struct lpfc_vport *vport;
202 spin_lock_irq(&phba->hbalock);
203 while (!list_empty(&phba->work_list)) {
204 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
206 spin_unlock_irq(&phba->hbalock);
209 case LPFC_EVT_DEV_LOSS:
210 free_evt = 0; /* evt is part of ndlp */
211 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
215 if (!(vport->load_flag & FC_UNLOADING) &&
216 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
217 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
218 lpfc_disc_state_machine(vport, ndlp, NULL,
222 case LPFC_EVT_ELS_RETRY:
223 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
224 lpfc_els_retry_delay_handler(ndlp);
225 free_evt = 0; /* evt is part of ndlp */
227 case LPFC_EVT_ONLINE:
228 if (phba->link_state < LPFC_LINK_DOWN)
229 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
231 *(int *) (evtp->evt_arg1) = 0;
232 complete((struct completion *)(evtp->evt_arg2));
234 case LPFC_EVT_OFFLINE_PREP:
235 if (phba->link_state >= LPFC_LINK_DOWN)
236 lpfc_offline_prep(phba);
237 *(int *)(evtp->evt_arg1) = 0;
238 complete((struct completion *)(evtp->evt_arg2));
240 case LPFC_EVT_OFFLINE:
242 lpfc_sli_brdrestart(phba);
243 *(int *)(evtp->evt_arg1) =
244 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
245 lpfc_unblock_mgmt_io(phba);
246 complete((struct completion *)(evtp->evt_arg2));
248 case LPFC_EVT_WARM_START:
250 lpfc_reset_barrier(phba);
251 lpfc_sli_brdreset(phba);
252 lpfc_hba_down_post(phba);
253 *(int *)(evtp->evt_arg1) =
254 lpfc_sli_brdready(phba, HS_MBRDY);
255 lpfc_unblock_mgmt_io(phba);
256 complete((struct completion *)(evtp->evt_arg2));
260 *(int *)(evtp->evt_arg1)
261 = (phba->pport->stopped)
262 ? 0 : lpfc_sli_brdkill(phba);
263 lpfc_unblock_mgmt_io(phba);
264 complete((struct completion *)(evtp->evt_arg2));
269 spin_lock_irq(&phba->hbalock);
271 spin_unlock_irq(&phba->hbalock);
276 lpfc_work_done(struct lpfc_hba *phba)
278 struct lpfc_sli_ring *pring;
279 uint32_t ha_copy, control, work_port_events;
280 struct lpfc_vport *vport;
283 spin_lock_irq(&phba->hbalock);
284 ha_copy = phba->work_ha;
286 spin_unlock_irq(&phba->hbalock);
288 if (ha_copy & HA_ERATT)
289 lpfc_handle_eratt(phba);
291 if (ha_copy & HA_MBATT)
292 lpfc_sli_handle_mb_event(phba);
294 if (ha_copy & HA_LATT)
295 lpfc_handle_latt(phba);
297 spin_lock_irq(&phba->hbalock);
298 list_for_each_entry(vport, &phba->port_list, listentry) {
299 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
301 if (!scsi_host_get(shost)) {
304 spin_unlock_irq(&phba->hbalock);
305 work_port_events = vport->work_port_events;
307 if (work_port_events & WORKER_DISC_TMO)
308 lpfc_disc_timeout_handler(vport);
310 if (work_port_events & WORKER_ELS_TMO)
311 lpfc_els_timeout_handler(vport);
313 if (work_port_events & WORKER_MBOX_TMO)
314 lpfc_mbox_timeout_handler(phba);
316 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
317 lpfc_unblock_fabric_iocbs(phba);
319 if (work_port_events & WORKER_FDMI_TMO)
320 lpfc_fdmi_timeout_handler(vport);
322 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
323 lpfc_ramp_down_queue_handler(phba);
325 if (work_port_events & WORKER_RAMP_UP_QUEUE)
326 lpfc_ramp_up_queue_handler(phba);
328 spin_lock_irq(&vport->work_port_lock);
329 vport->work_port_events &= ~work_port_events;
330 spin_unlock_irq(&vport->work_port_lock);
331 scsi_host_put(shost);
332 spin_lock_irq(&phba->hbalock);
334 spin_unlock_irq(&phba->hbalock);
336 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
337 pring = &phba->sli.ring[i];
338 if ((ha_copy & HA_RXATT)
339 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
340 if (pring->flag & LPFC_STOP_IOCB_MASK) {
341 pring->flag |= LPFC_DEFERRED_RING_EVENT;
343 lpfc_sli_handle_slow_ring_event(phba, pring,
346 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
349 * Turn on Ring interrupts
351 spin_lock_irq(&phba->hbalock);
352 control = readl(phba->HCregaddr);
353 control |= (HC_R0INT_ENA << i);
354 writel(control, phba->HCregaddr);
355 readl(phba->HCregaddr); /* flush */
356 spin_unlock_irq(&phba->hbalock);
360 lpfc_work_list_done(phba);
364 check_work_wait_done(struct lpfc_hba *phba)
366 struct lpfc_vport *vport;
367 struct lpfc_sli_ring *pring;
370 spin_lock_irq(&phba->hbalock);
371 list_for_each_entry(vport, &phba->port_list, listentry) {
372 if (vport->work_port_events) {
378 if (phba->work_ha || (!list_empty(&phba->work_list)) ||
379 kthread_should_stop()) {
383 for (i = 0; i < phba->sli.num_rings; i++) {
384 pring = &phba->sli.ring[i];
385 if (pring->flag & LPFC_DEFERRED_RING_EVENT) {
394 phba->work_found = 0;
396 spin_unlock_irq(&phba->hbalock);
402 lpfc_do_work(void *p)
404 struct lpfc_hba *phba = p;
406 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
408 set_user_nice(current, -20);
409 phba->work_wait = &work_waitq;
410 phba->work_found = 0;
414 rc = wait_event_interruptible(work_waitq,
415 check_work_wait_done(phba));
419 if (kthread_should_stop())
422 lpfc_work_done(phba);
424 /* If there is alot of slow ring work, like during link up
425 * check_work_wait_done() may cause this thread to not give
426 * up the CPU for very long periods of time. This may cause
427 * soft lockups or other problems. To avoid these situations
428 * give up the CPU here after LPFC_MAX_WORKER_ITERATION
429 * consecutive iterations.
431 if (phba->work_found >= LPFC_MAX_WORKER_ITERATION) {
432 phba->work_found = 0;
436 phba->work_wait = NULL;
441 * This is only called to handle FC worker events. Since this a rare
442 * occurance, we allocate a struct lpfc_work_evt structure here instead of
443 * embedding it in the IOCB.
446 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
449 struct lpfc_work_evt *evtp;
453 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
454 * be queued to worker thread for processing
456 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
460 evtp->evt_arg1 = arg1;
461 evtp->evt_arg2 = arg2;
464 spin_lock_irqsave(&phba->hbalock, flags);
465 list_add_tail(&evtp->evt_listp, &phba->work_list);
467 lpfc_worker_wake_up(phba);
468 spin_unlock_irqrestore(&phba->hbalock, flags);
474 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
476 struct lpfc_hba *phba = vport->phba;
477 struct lpfc_nodelist *ndlp, *next_ndlp;
480 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
481 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
484 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN)
485 lpfc_unreg_rpi(vport, ndlp);
487 /* Leave Fabric nodes alone on link down */
488 if (!remove && ndlp->nlp_type & NLP_FABRIC)
490 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
493 : NLP_EVT_DEVICE_RECOVERY);
495 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
496 lpfc_mbx_unreg_vpi(vport);
497 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
502 lpfc_linkdown_port(struct lpfc_vport *vport)
504 struct lpfc_nodelist *ndlp, *next_ndlp;
505 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
507 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
509 /* Cleanup any outstanding RSCN activity */
510 lpfc_els_flush_rscn(vport);
512 /* Cleanup any outstanding ELS commands */
513 lpfc_els_flush_cmd(vport);
515 lpfc_cleanup_rpis(vport, 0);
517 /* free any ndlp's on unused list */
518 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
519 /* free any ndlp's in unused state */
520 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
521 lpfc_drop_node(vport, ndlp);
523 /* Turn off discovery timer if its running */
524 lpfc_can_disctmo(vport);
528 lpfc_linkdown(struct lpfc_hba *phba)
530 struct lpfc_vport *vport = phba->pport;
531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
532 struct lpfc_vport *port_iterator;
535 if (phba->link_state == LPFC_LINK_DOWN) {
538 spin_lock_irq(&phba->hbalock);
539 if (phba->link_state > LPFC_LINK_DOWN) {
540 phba->link_state = LPFC_LINK_DOWN;
541 phba->pport->fc_flag &= ~FC_LBIT;
543 spin_unlock_irq(&phba->hbalock);
545 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
547 /* Issue a LINK DOWN event to all nodes */
548 lpfc_linkdown_port(port_iterator);
551 /* Clean up any firmware default rpi's */
552 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
554 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
556 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
557 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
558 == MBX_NOT_FINISHED) {
559 mempool_free(mb, phba->mbox_mem_pool);
563 /* Setup myDID for link up if we are in pt2pt mode */
564 if (phba->pport->fc_flag & FC_PT2PT) {
565 phba->pport->fc_myDID = 0;
566 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
568 lpfc_config_link(phba, mb);
569 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
571 if (lpfc_sli_issue_mbox(phba, mb,
572 (MBX_NOWAIT | MBX_STOP_IOCB))
573 == MBX_NOT_FINISHED) {
574 mempool_free(mb, phba->mbox_mem_pool);
577 spin_lock_irq(shost->host_lock);
578 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
579 spin_unlock_irq(shost->host_lock);
586 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
588 struct lpfc_nodelist *ndlp;
590 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
591 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
594 if (ndlp->nlp_type & NLP_FABRIC) {
595 /* On Linkup its safe to clean up the ndlp
596 * from Fabric connections.
598 if (ndlp->nlp_DID != Fabric_DID)
599 lpfc_unreg_rpi(vport, ndlp);
600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
601 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
602 /* Fail outstanding IO now since device is
605 lpfc_unreg_rpi(vport, ndlp);
611 lpfc_linkup_port(struct lpfc_vport *vport)
613 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
614 struct lpfc_nodelist *ndlp, *next_ndlp;
615 struct lpfc_hba *phba = vport->phba;
617 if ((vport->load_flag & FC_UNLOADING) != 0)
620 /* If NPIV is not enabled, only bring the physical port up */
621 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
622 (vport != phba->pport))
625 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
627 spin_lock_irq(shost->host_lock);
628 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
629 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
630 vport->fc_flag |= FC_NDISC_ACTIVE;
631 vport->fc_ns_retry = 0;
632 spin_unlock_irq(shost->host_lock);
634 if (vport->fc_flag & FC_LBIT)
635 lpfc_linkup_cleanup_nodes(vport);
637 /* free any ndlp's in unused state */
638 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
640 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
641 lpfc_drop_node(vport, ndlp);
645 lpfc_linkup(struct lpfc_hba *phba)
647 struct lpfc_vport *vport;
649 phba->link_state = LPFC_LINK_UP;
651 /* Unblock fabric iocbs if they are blocked */
652 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
653 del_timer_sync(&phba->fabric_block_timer);
655 list_for_each_entry(vport, &phba->port_list, listentry) {
656 lpfc_linkup_port(vport);
658 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
659 lpfc_issue_clear_la(phba, phba->pport);
665 * This routine handles processing a CLEAR_LA mailbox
666 * command upon completion. It is setup in the LPFC_MBOXQ
667 * as the completion routine when the command is
668 * handed off to the SLI layer.
671 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
673 struct lpfc_vport *vport = pmb->vport;
674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
675 struct lpfc_sli *psli = &phba->sli;
676 MAILBOX_t *mb = &pmb->mb;
679 /* Since we don't do discovery right now, turn these off here */
680 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
681 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
682 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
684 /* Check for error */
685 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
686 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
687 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
688 "%d (%d):0320 CLEAR_LA mbxStatus error x%x hba "
690 phba->brd_no, vport->vpi, mb->mbxStatus,
693 phba->link_state = LPFC_HBA_ERROR;
697 if (vport->port_type == LPFC_PHYSICAL_PORT)
698 phba->link_state = LPFC_HBA_READY;
700 spin_lock_irq(&phba->hbalock);
701 psli->sli_flag |= LPFC_PROCESS_LA;
702 control = readl(phba->HCregaddr);
703 control |= HC_LAINT_ENA;
704 writel(control, phba->HCregaddr);
705 readl(phba->HCregaddr); /* flush */
706 spin_unlock_irq(&phba->hbalock);
709 vport->num_disc_nodes = 0;
710 /* go thru NPR nodes and issue ELS PLOGIs */
711 if (vport->fc_npr_cnt)
712 lpfc_els_disc_plogi(vport);
714 if (!vport->num_disc_nodes) {
715 spin_lock_irq(shost->host_lock);
716 vport->fc_flag &= ~FC_NDISC_ACTIVE;
717 spin_unlock_irq(shost->host_lock);
720 vport->port_state = LPFC_VPORT_READY;
723 /* Device Discovery completes */
724 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
725 "%d (%d):0225 Device Discovery completes\n",
726 phba->brd_no, vport->vpi);
728 mempool_free(pmb, phba->mbox_mem_pool);
730 spin_lock_irq(shost->host_lock);
731 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
732 spin_unlock_irq(shost->host_lock);
734 del_timer_sync(&phba->fc_estabtmo);
736 lpfc_can_disctmo(vport);
738 /* turn on Link Attention interrupts */
740 spin_lock_irq(&phba->hbalock);
741 psli->sli_flag |= LPFC_PROCESS_LA;
742 control = readl(phba->HCregaddr);
743 control |= HC_LAINT_ENA;
744 writel(control, phba->HCregaddr);
745 readl(phba->HCregaddr); /* flush */
746 spin_unlock_irq(&phba->hbalock);
753 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
755 struct lpfc_vport *vport = pmb->vport;
757 if (pmb->mb.mbxStatus)
760 mempool_free(pmb, phba->mbox_mem_pool);
762 if (phba->fc_topology == TOPOLOGY_LOOP &&
763 vport->fc_flag & FC_PUBLIC_LOOP &&
764 !(vport->fc_flag & FC_LBIT)) {
765 /* Need to wait for FAN - use discovery timer
766 * for timeout. port_state is identically
767 * LPFC_LOCAL_CFG_LINK while waiting for FAN
769 lpfc_set_disctmo(vport);
773 /* Start discovery by sending a FLOGI. port_state is identically
774 * LPFC_FLOGI while waiting for FLOGI cmpl
776 if (vport->port_state != LPFC_FLOGI) {
777 vport->port_state = LPFC_FLOGI;
778 lpfc_set_disctmo(vport);
779 lpfc_initial_flogi(vport);
784 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
785 "%d (%d):0306 CONFIG_LINK mbxStatus error x%x "
787 phba->brd_no, vport->vpi, pmb->mb.mbxStatus,
790 mempool_free(pmb, phba->mbox_mem_pool);
794 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
795 "%d (%d):0200 CONFIG_LINK bad hba state x%x\n",
796 phba->brd_no, vport->vpi, vport->port_state);
798 lpfc_issue_clear_la(phba, vport);
803 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
805 MAILBOX_t *mb = &pmb->mb;
806 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
807 struct lpfc_vport *vport = pmb->vport;
810 /* Check for error */
812 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
813 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
814 "%d (%d):0319 READ_SPARAM mbxStatus error x%x "
816 phba->brd_no, vport->vpi, mb->mbxStatus,
823 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
824 sizeof (struct serv_parm));
825 if (phba->cfg_soft_wwnn)
826 u64_to_wwn(phba->cfg_soft_wwnn,
827 vport->fc_sparam.nodeName.u.wwn);
828 if (phba->cfg_soft_wwpn)
829 u64_to_wwn(phba->cfg_soft_wwpn,
830 vport->fc_sparam.portName.u.wwn);
831 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
832 sizeof(vport->fc_nodename));
833 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
834 sizeof(vport->fc_portname));
835 if (vport->port_type == LPFC_PHYSICAL_PORT) {
836 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
837 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
840 lpfc_mbuf_free(phba, mp->virt, mp->phys);
842 mempool_free(pmb, phba->mbox_mem_pool);
846 pmb->context1 = NULL;
847 lpfc_mbuf_free(phba, mp->virt, mp->phys);
849 lpfc_issue_clear_la(phba, vport);
850 mempool_free(pmb, phba->mbox_mem_pool);
855 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
857 struct lpfc_vport *vport = phba->pport;
858 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
860 struct lpfc_dmabuf *mp;
863 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
864 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
866 spin_lock_irq(&phba->hbalock);
867 switch (la->UlnkSpeed) {
869 phba->fc_linkspeed = LA_1GHZ_LINK;
872 phba->fc_linkspeed = LA_2GHZ_LINK;
875 phba->fc_linkspeed = LA_4GHZ_LINK;
878 phba->fc_linkspeed = LA_8GHZ_LINK;
881 phba->fc_linkspeed = LA_UNKNW_LINK;
885 phba->fc_topology = la->topology;
886 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
888 if (phba->fc_topology == TOPOLOGY_LOOP) {
889 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
891 /* Get Loop Map information */
893 vport->fc_flag |= FC_LBIT;
895 vport->fc_myDID = la->granted_AL_PA;
896 i = la->un.lilpBde64.tus.f.bdeSize;
899 phba->alpa_map[0] = 0;
901 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
912 numalpa = phba->alpa_map[0];
914 while (j < numalpa) {
915 memset(un.pamap, 0, 16);
916 for (k = 1; j < numalpa; k++) {
918 phba->alpa_map[j + 1];
923 /* Link Up Event ALPA map */
924 lpfc_printf_log(phba,
927 "%d:1304 Link Up Event "
928 "ALPA map Data: x%x "
931 un.pa.wd1, un.pa.wd2,
932 un.pa.wd3, un.pa.wd4);
937 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
938 if (phba->max_vpi && lpfc_npiv_enable &&
939 (phba->sli_rev == 3))
940 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
942 vport->fc_myDID = phba->fc_pref_DID;
943 vport->fc_flag |= FC_LBIT;
945 spin_unlock_irq(&phba->hbalock);
949 lpfc_read_sparam(phba, sparam_mbox, 0);
950 sparam_mbox->vport = vport;
951 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
952 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
953 (MBX_NOWAIT | MBX_STOP_IOCB));
954 if (rc == MBX_NOT_FINISHED) {
955 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
956 lpfc_mbuf_free(phba, mp->virt, mp->phys);
958 mempool_free(sparam_mbox, phba->mbox_mem_pool);
960 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
966 vport->port_state = LPFC_LOCAL_CFG_LINK;
967 lpfc_config_link(phba, cfglink_mbox);
968 cfglink_mbox->vport = vport;
969 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
970 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
971 (MBX_NOWAIT | MBX_STOP_IOCB));
972 if (rc != MBX_NOT_FINISHED)
974 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
977 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
978 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
979 "%d (%d):0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
980 phba->brd_no, vport->vpi,
981 vport->port_state, sparam_mbox, cfglink_mbox);
983 lpfc_issue_clear_la(phba, vport);
988 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
991 struct lpfc_sli *psli = &phba->sli;
995 /* turn on Link Attention interrupts - no CLEAR_LA needed */
996 spin_lock_irq(&phba->hbalock);
997 psli->sli_flag |= LPFC_PROCESS_LA;
998 control = readl(phba->HCregaddr);
999 control |= HC_LAINT_ENA;
1000 writel(control, phba->HCregaddr);
1001 readl(phba->HCregaddr); /* flush */
1002 spin_unlock_irq(&phba->hbalock);
1006 * This routine handles processing a READ_LA mailbox
1007 * command upon completion. It is setup in the LPFC_MBOXQ
1008 * as the completion routine when the command is
1009 * handed off to the SLI layer.
1012 lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1014 struct lpfc_vport *vport = pmb->vport;
1015 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1017 MAILBOX_t *mb = &pmb->mb;
1018 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1020 /* Check for error */
1021 if (mb->mbxStatus) {
1022 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1023 "%d:1307 READ_LA mbox error x%x state x%x\n",
1024 phba->brd_no, mb->mbxStatus, vport->port_state);
1025 lpfc_mbx_issue_link_down(phba);
1026 phba->link_state = LPFC_HBA_ERROR;
1027 goto lpfc_mbx_cmpl_read_la_free_mbuf;
1030 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
1032 memcpy(&phba->alpa_map[0], mp->virt, 128);
1034 spin_lock_irq(shost->host_lock);
1036 vport->fc_flag |= FC_BYPASSED_MODE;
1038 vport->fc_flag &= ~FC_BYPASSED_MODE;
1039 spin_unlock_irq(shost->host_lock);
1041 if (((phba->fc_eventTag + 1) < la->eventTag) ||
1042 (phba->fc_eventTag == la->eventTag)) {
1043 phba->fc_stat.LinkMultiEvent++;
1044 if (la->attType == AT_LINK_UP)
1045 if (phba->fc_eventTag != 0)
1046 lpfc_linkdown(phba);
1049 phba->fc_eventTag = la->eventTag;
1051 if (la->attType == AT_LINK_UP) {
1052 phba->fc_stat.LinkUp++;
1053 if (phba->link_flag & LS_LOOPBACK_MODE) {
1054 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1055 "%d:1306 Link Up Event in loop back mode "
1056 "x%x received Data: x%x x%x x%x x%x\n",
1057 phba->brd_no, la->eventTag, phba->fc_eventTag,
1058 la->granted_AL_PA, la->UlnkSpeed,
1061 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1062 "%d:1303 Link Up Event x%x received "
1063 "Data: x%x x%x x%x x%x\n",
1064 phba->brd_no, la->eventTag, phba->fc_eventTag,
1065 la->granted_AL_PA, la->UlnkSpeed,
1068 lpfc_mbx_process_link_up(phba, la);
1070 phba->fc_stat.LinkDown++;
1071 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1072 "%d:1305 Link Down Event x%x received "
1073 "Data: x%x x%x x%x\n",
1074 phba->brd_no, la->eventTag, phba->fc_eventTag,
1075 phba->pport->port_state, vport->fc_flag);
1076 lpfc_mbx_issue_link_down(phba);
1079 lpfc_mbx_cmpl_read_la_free_mbuf:
1080 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1082 mempool_free(pmb, phba->mbox_mem_pool);
1087 * This routine handles processing a REG_LOGIN mailbox
1088 * command upon completion. It is setup in the LPFC_MBOXQ
1089 * as the completion routine when the command is
1090 * handed off to the SLI layer.
1093 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1095 struct lpfc_vport *vport = pmb->vport;
1096 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1097 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1099 pmb->context1 = NULL;
1101 /* Good status, call state machine */
1102 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
1103 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1105 mempool_free(pmb, phba->mbox_mem_pool);
1112 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1114 MAILBOX_t *mb = &pmb->mb;
1115 struct lpfc_vport *vport = pmb->vport;
1116 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1118 switch (mb->mbxStatus) {
1122 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1123 "%d (%d):0911 cmpl_unreg_vpi, "
1124 "mb status = 0x%x\n",
1125 phba->brd_no, vport->vpi, mb->mbxStatus);
1130 vport->unreg_vpi_cmpl = VPORT_OK;
1131 mempool_free(pmb, phba->mbox_mem_pool);
1133 * This shost reference might have been taken at the beginning of
1134 * lpfc_vport_delete()
1136 if (vport->load_flag & FC_UNLOADING)
1137 scsi_host_put(shost);
1141 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
1143 struct lpfc_hba *phba = vport->phba;
1147 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1151 lpfc_unreg_vpi(phba, vport->vpi, mbox);
1152 mbox->vport = vport;
1153 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
1154 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1155 if (rc == MBX_NOT_FINISHED) {
1156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1157 "%d (%d):1800 Could not issue unreg_vpi\n",
1158 phba->brd_no, vport->vpi);
1159 mempool_free(mbox, phba->mbox_mem_pool);
1160 vport->unreg_vpi_cmpl = VPORT_ERROR;
1165 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1167 struct lpfc_vport *vport = pmb->vport;
1168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1169 MAILBOX_t *mb = &pmb->mb;
1171 switch (mb->mbxStatus) {
1175 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1176 "%d (%d):0912 cmpl_reg_vpi, mb status = 0x%x\n",
1177 phba->brd_no, vport->vpi, mb->mbxStatus);
1178 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1179 spin_lock_irq(shost->host_lock);
1180 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1181 spin_unlock_irq(shost->host_lock);
1182 vport->fc_myDID = 0;
1187 vport->num_disc_nodes = 0;
1188 /* go thru NPR list and issue ELS PLOGIs */
1189 if (vport->fc_npr_cnt)
1190 lpfc_els_disc_plogi(vport);
1192 if (!vport->num_disc_nodes) {
1193 spin_lock_irq(shost->host_lock);
1194 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1195 spin_unlock_irq(shost->host_lock);
1196 lpfc_can_disctmo(vport);
1198 vport->port_state = LPFC_VPORT_READY;
1201 mempool_free(pmb, phba->mbox_mem_pool);
1206 * This routine handles processing a Fabric REG_LOGIN mailbox
1207 * command upon completion. It is setup in the LPFC_MBOXQ
1208 * as the completion routine when the command is
1209 * handed off to the SLI layer.
1212 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1214 struct lpfc_vport *vport = pmb->vport;
1215 struct lpfc_vport *next_vport;
1216 MAILBOX_t *mb = &pmb->mb;
1217 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1218 struct lpfc_nodelist *ndlp;
1219 ndlp = (struct lpfc_nodelist *) pmb->context2;
1221 pmb->context1 = NULL;
1222 pmb->context2 = NULL;
1224 if (mb->mbxStatus) {
1225 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1227 mempool_free(pmb, phba->mbox_mem_pool);
1230 if (phba->fc_topology == TOPOLOGY_LOOP) {
1231 /* FLOGI failed, use loop map to make discovery list */
1232 lpfc_disc_list_loopmap(vport);
1234 /* Start discovery */
1235 lpfc_disc_start(vport);
1239 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1240 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1241 "%d (%d):0258 Register Fabric login error: 0x%x\n",
1242 phba->brd_no, vport->vpi, mb->mbxStatus);
1247 ndlp->nlp_rpi = mb->un.varWords[0];
1248 ndlp->nlp_type |= NLP_FABRIC;
1249 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1251 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
1253 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
1254 list_for_each_entry(next_vport, &phba->port_list, listentry) {
1255 if (next_vport->port_type == LPFC_PHYSICAL_PORT)
1258 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1259 lpfc_initial_fdisc(next_vport);
1261 if (phba->sli3_options &
1262 LPFC_SLI3_NPIV_ENABLED) {
1263 lpfc_vport_set_state(vport,
1264 FC_VPORT_NO_FABRIC_SUPP);
1265 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1266 "%d (%d):0259 No NPIV Fabric "
1268 phba->brd_no, vport->vpi);
1272 lpfc_do_scr_ns_plogi(phba, vport);
1275 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1277 mempool_free(pmb, phba->mbox_mem_pool);
1282 * This routine handles processing a NameServer REG_LOGIN mailbox
1283 * command upon completion. It is setup in the LPFC_MBOXQ
1284 * as the completion routine when the command is
1285 * handed off to the SLI layer.
1288 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1290 MAILBOX_t *mb = &pmb->mb;
1291 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1292 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1293 struct lpfc_vport *vport = pmb->vport;
1295 if (mb->mbxStatus) {
1298 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1300 mempool_free(pmb, phba->mbox_mem_pool);
1301 lpfc_drop_node(vport, ndlp);
1303 if (phba->fc_topology == TOPOLOGY_LOOP) {
1305 * RegLogin failed, use loop map to make discovery
1308 lpfc_disc_list_loopmap(vport);
1310 /* Start discovery */
1311 lpfc_disc_start(vport);
1314 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1315 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1316 "%d (%d):0260 Register NameServer error: 0x%x\n",
1317 phba->brd_no, vport->vpi, mb->mbxStatus);
1321 pmb->context1 = NULL;
1323 ndlp->nlp_rpi = mb->un.varWords[0];
1324 ndlp->nlp_type |= NLP_FABRIC;
1325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1327 if (vport->port_state < LPFC_VPORT_READY) {
1328 /* Link up discovery requires Fabric registration. */
1329 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
1330 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
1331 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
1332 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
1333 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
1335 /* Issue SCR just before NameServer GID_FT Query */
1336 lpfc_issue_els_scr(vport, SCR_DID, 0);
1339 vport->fc_ns_retry = 0;
1340 /* Good status, issue CT Request to NameServer */
1341 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
1342 /* Cannot issue NameServer Query, so finish up discovery */
1347 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1349 mempool_free(pmb, phba->mbox_mem_pool);
1355 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1358 struct fc_rport *rport;
1359 struct lpfc_rport_data *rdata;
1360 struct fc_rport_identifiers rport_ids;
1361 struct lpfc_hba *phba = vport->phba;
1363 /* Remote port has reappeared. Re-register w/ FC transport */
1364 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1365 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1366 rport_ids.port_id = ndlp->nlp_DID;
1367 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1370 * We leave our node pointer in rport->dd_data when we unregister a
1371 * FCP target port. But fc_remote_port_add zeros the space to which
1372 * rport->dd_data points. So, if we're reusing a previously
1373 * registered port, drop the reference that we took the last time we
1374 * registered the port.
1376 if (ndlp->rport && ndlp->rport->dd_data &&
1377 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) {
1380 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
1381 if (!rport || !get_device(&rport->dev)) {
1382 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1383 "Warning: fc_remote_port_add failed\n");
1387 /* initialize static port data */
1388 rport->maxframe_size = ndlp->nlp_maxframe;
1389 rport->supported_classes = ndlp->nlp_class_sup;
1390 rdata = rport->dd_data;
1391 rdata->pnode = lpfc_nlp_get(ndlp);
1393 if (ndlp->nlp_type & NLP_FCP_TARGET)
1394 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1395 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1396 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1397 del_timer_sync(&ndlp->nlp_initiator_tmr);
1400 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1401 fc_remote_port_rolechg(rport, rport_ids.roles);
1403 if ((rport->scsi_target_id != -1) &&
1404 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1405 ndlp->nlp_sid = rport->scsi_target_id;
1411 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
1413 struct fc_rport *rport = ndlp->rport;
1415 fc_remote_port_delete(rport);
1421 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
1423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1425 spin_lock_irq(shost->host_lock);
1427 case NLP_STE_UNUSED_NODE:
1428 vport->fc_unused_cnt += count;
1430 case NLP_STE_PLOGI_ISSUE:
1431 vport->fc_plogi_cnt += count;
1433 case NLP_STE_ADISC_ISSUE:
1434 vport->fc_adisc_cnt += count;
1436 case NLP_STE_REG_LOGIN_ISSUE:
1437 vport->fc_reglogin_cnt += count;
1439 case NLP_STE_PRLI_ISSUE:
1440 vport->fc_prli_cnt += count;
1442 case NLP_STE_UNMAPPED_NODE:
1443 vport->fc_unmap_cnt += count;
1445 case NLP_STE_MAPPED_NODE:
1446 vport->fc_map_cnt += count;
1448 case NLP_STE_NPR_NODE:
1449 vport->fc_npr_cnt += count;
1452 spin_unlock_irq(shost->host_lock);
1456 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1457 int old_state, int new_state)
1459 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1461 if (new_state == NLP_STE_UNMAPPED_NODE) {
1462 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1463 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1464 ndlp->nlp_type |= NLP_FC_NODE;
1466 if (new_state == NLP_STE_MAPPED_NODE)
1467 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1468 if (new_state == NLP_STE_NPR_NODE)
1469 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1471 /* Transport interface */
1472 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1473 old_state == NLP_STE_UNMAPPED_NODE)) {
1474 vport->phba->nport_event_cnt++;
1475 lpfc_unregister_remote_port(ndlp);
1478 if (new_state == NLP_STE_MAPPED_NODE ||
1479 new_state == NLP_STE_UNMAPPED_NODE) {
1480 vport->phba->nport_event_cnt++;
1482 * Tell the fc transport about the port, if we haven't
1483 * already. If we have, and it's a scsi entity, be
1484 * sure to unblock any attached scsi devices
1486 lpfc_register_remote_port(vport, ndlp);
1490 * if we added to Mapped list, but the remote port
1491 * registration failed or assigned a target id outside
1492 * our presentable range - move the node to the
1495 if (new_state == NLP_STE_MAPPED_NODE &&
1497 ndlp->rport->scsi_target_id == -1 ||
1498 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1499 spin_lock_irq(shost->host_lock);
1500 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1501 spin_unlock_irq(shost->host_lock);
1502 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1507 lpfc_nlp_state_name(char *buffer, size_t size, int state)
1509 static char *states[] = {
1510 [NLP_STE_UNUSED_NODE] = "UNUSED",
1511 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1512 [NLP_STE_ADISC_ISSUE] = "ADISC",
1513 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1514 [NLP_STE_PRLI_ISSUE] = "PRLI",
1515 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1516 [NLP_STE_MAPPED_NODE] = "MAPPED",
1517 [NLP_STE_NPR_NODE] = "NPR",
1520 if (state < ARRAY_SIZE(states) && states[state])
1521 strlcpy(buffer, states[state], size);
1523 snprintf(buffer, size, "unknown (%d)", state);
1528 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1532 int old_state = ndlp->nlp_state;
1533 char name1[16], name2[16];
1535 lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
1536 "%d:0904 NPort state transition x%06x, %s -> %s\n",
1537 vport->phba->brd_no,
1539 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1540 lpfc_nlp_state_name(name2, sizeof(name2), state));
1541 if (old_state == NLP_STE_NPR_NODE &&
1542 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1543 state != NLP_STE_NPR_NODE)
1544 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1545 if (old_state == NLP_STE_UNMAPPED_NODE) {
1546 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1547 ndlp->nlp_type &= ~NLP_FC_NODE;
1550 if (list_empty(&ndlp->nlp_listp)) {
1551 spin_lock_irq(shost->host_lock);
1552 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1553 spin_unlock_irq(shost->host_lock);
1554 } else if (old_state)
1555 lpfc_nlp_counters(vport, old_state, -1);
1557 ndlp->nlp_state = state;
1558 lpfc_nlp_counters(vport, state, 1);
1559 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
1563 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1567 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1568 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1569 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1570 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1571 spin_lock_irq(shost->host_lock);
1572 list_del_init(&ndlp->nlp_listp);
1573 spin_unlock_irq(shost->host_lock);
1574 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, 0);
1578 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1582 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1583 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1584 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1585 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1586 spin_lock_irq(shost->host_lock);
1587 list_del_init(&ndlp->nlp_listp);
1588 spin_unlock_irq(shost->host_lock);
1593 * Start / ReStart rescue timer for Discovery / RSCN handling
1596 lpfc_set_disctmo(struct lpfc_vport *vport)
1598 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1599 struct lpfc_hba *phba = vport->phba;
1602 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
1603 /* For FAN, timeout should be greater then edtov */
1604 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1606 /* Normal discovery timeout should be > then ELS/CT timeout
1607 * FC spec states we need 3 * ratov for CT requests
1609 tmo = ((phba->fc_ratov * 3) + 3);
1612 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1613 spin_lock_irq(shost->host_lock);
1614 vport->fc_flag |= FC_DISC_TMO;
1615 spin_unlock_irq(shost->host_lock);
1617 /* Start Discovery Timer state <hba_state> */
1618 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1619 "%d (%d):0247 Start Discovery Timer state x%x "
1620 "Data: x%x x%lx x%x x%x\n",
1621 phba->brd_no, vport->vpi, vport->port_state, tmo,
1622 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1623 vport->fc_adisc_cnt);
1629 * Cancel rescue timer for Discovery / RSCN handling
1632 lpfc_can_disctmo(struct lpfc_vport *vport)
1634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1635 struct lpfc_hba *phba = vport->phba;
1636 unsigned long iflags;
1638 /* Turn off discovery timer if its running */
1639 if (vport->fc_flag & FC_DISC_TMO) {
1640 spin_lock_irqsave(shost->host_lock, iflags);
1641 vport->fc_flag &= ~FC_DISC_TMO;
1642 spin_unlock_irqrestore(shost->host_lock, iflags);
1643 del_timer_sync(&vport->fc_disctmo);
1644 spin_lock_irqsave(&vport->work_port_lock, iflags);
1645 vport->work_port_events &= ~WORKER_DISC_TMO;
1646 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
1649 /* Cancel Discovery Timer state <hba_state> */
1650 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1651 "%d (%d):0248 Cancel Discovery Timer state x%x "
1652 "Data: x%x x%x x%x\n",
1653 phba->brd_no, vport->vpi, vport->port_state,
1654 vport->fc_flag, vport->fc_plogi_cnt,
1655 vport->fc_adisc_cnt);
1661 * Check specified ring for outstanding IOCB on the SLI queue
1662 * Return true if iocb matches the specified nport
1665 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1666 struct lpfc_sli_ring *pring,
1667 struct lpfc_iocbq *iocb,
1668 struct lpfc_nodelist *ndlp)
1670 struct lpfc_sli *psli = &phba->sli;
1671 IOCB_t *icmd = &iocb->iocb;
1672 struct lpfc_vport *vport = ndlp->vport;
1674 if (iocb->vport != vport)
1677 if (pring->ringno == LPFC_ELS_RING) {
1678 switch (icmd->ulpCommand) {
1679 case CMD_GEN_REQUEST64_CR:
1680 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1682 case CMD_ELS_REQUEST64_CR:
1683 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1685 case CMD_XMIT_ELS_RSP64_CX:
1686 if (iocb->context1 == (uint8_t *) ndlp)
1689 } else if (pring->ringno == psli->extra_ring) {
1691 } else if (pring->ringno == psli->fcp_ring) {
1692 /* Skip match check if waiting to relogin to FCP target */
1693 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1694 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1697 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1700 } else if (pring->ringno == psli->next_ring) {
1707 * Free resources / clean up outstanding I/Os
1708 * associated with nlp_rpi in the LPFC_NODELIST entry.
1711 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1713 LIST_HEAD(completions);
1714 struct lpfc_sli *psli;
1715 struct lpfc_sli_ring *pring;
1716 struct lpfc_iocbq *iocb, *next_iocb;
1720 lpfc_fabric_abort_nport(ndlp);
1723 * Everything that matches on txcmplq will be returned
1724 * by firmware with a no rpi error.
1727 rpi = ndlp->nlp_rpi;
1729 /* Now process each ring */
1730 for (i = 0; i < psli->num_rings; i++) {
1731 pring = &psli->ring[i];
1733 spin_lock_irq(&phba->hbalock);
1734 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1737 * Check to see if iocb matches the nport we are
1740 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
1742 /* It matches, so deque and call compl
1744 list_move_tail(&iocb->list,
1749 spin_unlock_irq(&phba->hbalock);
1753 while (!list_empty(&completions)) {
1754 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1755 list_del_init(&iocb->list);
1757 if (!iocb->iocb_cmpl)
1758 lpfc_sli_release_iocbq(phba, iocb);
1761 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1762 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1763 (iocb->iocb_cmpl)(phba, iocb, iocb);
1771 * Free rpi associated with LPFC_NODELIST entry.
1772 * This routine is called from lpfc_freenode(), when we are removing
1773 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1774 * LOGO that completes successfully, and we are waiting to PLOGI back
1775 * to the remote NPort. In addition, it is called after we receive
1776 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1777 * we are waiting to PLOGI back to the remote NPort.
1780 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1782 struct lpfc_hba *phba = vport->phba;
1786 if (ndlp->nlp_rpi) {
1787 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1789 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
1790 mbox->vport = vport;
1791 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1792 rc = lpfc_sli_issue_mbox(phba, mbox,
1793 (MBX_NOWAIT | MBX_STOP_IOCB));
1794 if (rc == MBX_NOT_FINISHED)
1795 mempool_free(mbox, phba->mbox_mem_pool);
1797 lpfc_no_rpi(phba, ndlp);
1805 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
1807 struct lpfc_hba *phba = vport->phba;
1811 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1813 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
1814 mbox->vport = vport;
1815 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1816 rc = lpfc_sli_issue_mbox(phba, mbox,
1817 (MBX_NOWAIT | MBX_STOP_IOCB));
1818 if (rc == MBX_NOT_FINISHED) {
1819 mempool_free(mbox, phba->mbox_mem_pool);
1825 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
1827 struct lpfc_hba *phba = vport->phba;
1831 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1833 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
1834 mbox->vport = vport;
1835 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1836 rc = lpfc_sli_issue_mbox(phba, mbox,
1837 (MBX_NOWAIT | MBX_STOP_IOCB));
1838 if (rc == MBX_NOT_FINISHED) {
1839 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1840 "%d (%d):1815 Could not issue "
1841 "unreg_did (default rpis)\n",
1842 phba->brd_no, vport->vpi);
1843 mempool_free(mbox, phba->mbox_mem_pool);
1849 * Free resources associated with LPFC_NODELIST entry
1850 * so it can be freed.
1853 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1856 struct lpfc_hba *phba = vport->phba;
1857 LPFC_MBOXQ_t *mb, *nextmb;
1858 struct lpfc_dmabuf *mp;
1860 /* Cleanup node for NPort <nlp_DID> */
1861 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1862 "%d (%d):0900 Cleanup node for NPort x%x "
1863 "Data: x%x x%x x%x\n",
1864 phba->brd_no, vport->vpi, ndlp->nlp_DID, ndlp->nlp_flag,
1865 ndlp->nlp_state, ndlp->nlp_rpi);
1867 lpfc_dequeue_node(vport, ndlp);
1869 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1870 if ((mb = phba->sli.mbox_active)) {
1871 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1872 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1873 mb->context2 = NULL;
1874 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1878 spin_lock_irq(&phba->hbalock);
1879 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1880 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1881 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1882 mp = (struct lpfc_dmabuf *) (mb->context1);
1884 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1887 list_del(&mb->list);
1888 mempool_free(mb, phba->mbox_mem_pool);
1892 spin_unlock_irq(&phba->hbalock);
1894 lpfc_els_abort(phba,ndlp);
1895 spin_lock_irq(shost->host_lock);
1896 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1897 spin_unlock_irq(shost->host_lock);
1899 ndlp->nlp_last_elscmd = 0;
1900 del_timer_sync(&ndlp->nlp_delayfunc);
1901 del_timer_sync(&ndlp->nlp_initiator_tmr);
1903 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1904 list_del_init(&ndlp->els_retry_evt.evt_listp);
1905 if (!list_empty(&ndlp->dev_loss_evt.evt_listp))
1906 list_del_init(&ndlp->dev_loss_evt.evt_listp);
1908 lpfc_unreg_rpi(vport, ndlp);
1914 * Check to see if we can free the nlp back to the freelist.
1915 * If we are in the middle of using the nlp in the discovery state
1916 * machine, defer the free till we reach the end of the state machine.
1919 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1921 struct lpfc_rport_data *rdata;
1923 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1924 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1927 lpfc_cleanup_node(vport, ndlp);
1930 * We can get here with a non-NULL ndlp->rport because when we
1931 * unregister a rport we don't break the rport/node linkage. So if we
1932 * do, make sure we don't leaving any dangling pointers behind.
1935 rdata = ndlp->rport->dd_data;
1936 rdata->pnode = NULL;
1942 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1945 D_ID mydid, ndlpdid, matchdid;
1947 if (did == Bcast_DID)
1950 if (ndlp->nlp_DID == 0) {
1954 /* First check for Direct match */
1955 if (ndlp->nlp_DID == did)
1958 /* Next check for area/domain identically equals 0 match */
1959 mydid.un.word = vport->fc_myDID;
1960 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1964 matchdid.un.word = did;
1965 ndlpdid.un.word = ndlp->nlp_DID;
1966 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1967 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1968 (mydid.un.b.area == matchdid.un.b.area)) {
1969 if ((ndlpdid.un.b.domain == 0) &&
1970 (ndlpdid.un.b.area == 0)) {
1971 if (ndlpdid.un.b.id)
1977 matchdid.un.word = ndlp->nlp_DID;
1978 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1979 (mydid.un.b.area == ndlpdid.un.b.area)) {
1980 if ((matchdid.un.b.domain == 0) &&
1981 (matchdid.un.b.area == 0)) {
1982 if (matchdid.un.b.id)
1990 /* Search for a nodelist entry */
1991 static struct lpfc_nodelist *
1992 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
1994 struct lpfc_hba *phba = vport->phba;
1995 struct lpfc_nodelist *ndlp;
1998 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1999 if (lpfc_matchdid(vport, ndlp, did)) {
2000 data1 = (((uint32_t) ndlp->nlp_state << 24) |
2001 ((uint32_t) ndlp->nlp_xri << 16) |
2002 ((uint32_t) ndlp->nlp_type << 8) |
2003 ((uint32_t) ndlp->nlp_rpi & 0xff));
2004 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
2005 "%d (%d):0929 FIND node DID "
2006 " Data: x%p x%x x%x x%x\n",
2007 phba->brd_no, vport->vpi,
2008 ndlp, ndlp->nlp_DID,
2009 ndlp->nlp_flag, data1);
2014 /* FIND node did <did> NOT FOUND */
2015 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
2016 "%d (%d):0932 FIND node did x%x NOT FOUND.\n",
2017 phba->brd_no, vport->vpi, did);
2021 struct lpfc_nodelist *
2022 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
2024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2025 struct lpfc_nodelist *ndlp;
2027 spin_lock_irq(shost->host_lock);
2028 ndlp = __lpfc_findnode_did(vport, did);
2029 spin_unlock_irq(shost->host_lock);
2033 struct lpfc_nodelist *
2034 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
2036 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2037 struct lpfc_nodelist *ndlp;
2039 ndlp = lpfc_findnode_did(vport, did);
2041 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
2042 lpfc_rscn_payload_check(vport, did) == 0)
2044 ndlp = (struct lpfc_nodelist *)
2045 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
2048 lpfc_nlp_init(vport, ndlp, did);
2049 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2050 spin_lock_irq(shost->host_lock);
2051 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2052 spin_unlock_irq(shost->host_lock);
2055 if (vport->fc_flag & FC_RSCN_MODE) {
2056 if (lpfc_rscn_payload_check(vport, did)) {
2057 spin_lock_irq(shost->host_lock);
2058 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2059 spin_unlock_irq(shost->host_lock);
2061 /* Since this node is marked for discovery,
2062 * delay timeout is not needed.
2064 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2065 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2069 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
2070 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
2072 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2073 spin_lock_irq(shost->host_lock);
2074 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2075 spin_unlock_irq(shost->host_lock);
2080 /* Build a list of nodes to discover based on the loopmap */
2082 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
2084 struct lpfc_hba *phba = vport->phba;
2086 uint32_t alpa, index;
2088 if (!lpfc_is_link_up(phba))
2091 if (phba->fc_topology != TOPOLOGY_LOOP)
2094 /* Check for loop map present or not */
2095 if (phba->alpa_map[0]) {
2096 for (j = 1; j <= phba->alpa_map[0]; j++) {
2097 alpa = phba->alpa_map[j];
2098 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
2100 lpfc_setup_disc_node(vport, alpa);
2103 /* No alpamap, so try all alpa's */
2104 for (j = 0; j < FC_MAXLOOP; j++) {
2105 /* If cfg_scan_down is set, start from highest
2106 * ALPA (0xef) to lowest (0x1).
2108 if (phba->cfg_scan_down)
2111 index = FC_MAXLOOP - j - 1;
2112 alpa = lpfcAlpaArray[index];
2113 if ((vport->fc_myDID & 0xff) == alpa)
2115 lpfc_setup_disc_node(vport, alpa);
2122 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
2125 struct lpfc_sli *psli = &phba->sli;
2126 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
2127 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
2128 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
2132 * if it's not a physical port or if we already send
2133 * clear_la then don't send it.
2135 if ((phba->link_state >= LPFC_CLEAR_LA) ||
2136 (vport->port_type != LPFC_PHYSICAL_PORT))
2139 /* Link up discovery */
2140 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
2141 phba->link_state = LPFC_CLEAR_LA;
2142 lpfc_clear_la(phba, mbox);
2143 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2144 mbox->vport = vport;
2145 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
2147 if (rc == MBX_NOT_FINISHED) {
2148 mempool_free(mbox, phba->mbox_mem_pool);
2149 lpfc_disc_flush_list(vport);
2150 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2151 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2152 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2153 phba->link_state = LPFC_HBA_ERROR;
2158 /* Reg_vpi to tell firmware to resume normal operations */
2160 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
2162 LPFC_MBOXQ_t *regvpimbox;
2164 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2166 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
2167 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
2168 regvpimbox->vport = vport;
2169 if (lpfc_sli_issue_mbox(phba, regvpimbox,
2170 (MBX_NOWAIT | MBX_STOP_IOCB))
2171 == MBX_NOT_FINISHED) {
2172 mempool_free(regvpimbox, phba->mbox_mem_pool);
2177 /* Start Link up / RSCN discovery on NPR nodes */
2179 lpfc_disc_start(struct lpfc_vport *vport)
2181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2182 struct lpfc_hba *phba = vport->phba;
2184 uint32_t clear_la_pending;
2187 if (!lpfc_is_link_up(phba))
2190 if (phba->link_state == LPFC_CLEAR_LA)
2191 clear_la_pending = 1;
2193 clear_la_pending = 0;
2195 if (vport->port_state < LPFC_VPORT_READY)
2196 vport->port_state = LPFC_DISC_AUTH;
2198 lpfc_set_disctmo(vport);
2200 if (vport->fc_prevDID == vport->fc_myDID)
2205 vport->fc_prevDID = vport->fc_myDID;
2206 vport->num_disc_nodes = 0;
2208 /* Start Discovery state <hba_state> */
2209 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2210 "%d (%d):0202 Start Discovery hba state x%x "
2211 "Data: x%x x%x x%x\n",
2212 phba->brd_no, vport->vpi, vport->port_state,
2213 vport->fc_flag, vport->fc_plogi_cnt,
2214 vport->fc_adisc_cnt);
2216 /* First do ADISCs - if any */
2217 num_sent = lpfc_els_disc_adisc(vport);
2223 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2224 * continue discovery.
2226 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2227 !(vport->fc_flag & FC_RSCN_MODE)) {
2228 lpfc_issue_reg_vpi(phba, vport);
2233 * For SLI2, we need to set port_state to READY and continue
2236 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
2237 /* If we get here, there is nothing to ADISC */
2238 if (vport->port_type == LPFC_PHYSICAL_PORT)
2239 lpfc_issue_clear_la(phba, vport);
2241 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2242 vport->num_disc_nodes = 0;
2243 /* go thru NPR nodes and issue ELS PLOGIs */
2244 if (vport->fc_npr_cnt)
2245 lpfc_els_disc_plogi(vport);
2247 if (!vport->num_disc_nodes) {
2248 spin_lock_irq(shost->host_lock);
2249 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2250 spin_unlock_irq(shost->host_lock);
2251 lpfc_can_disctmo(vport);
2254 vport->port_state = LPFC_VPORT_READY;
2256 /* Next do PLOGIs - if any */
2257 num_sent = lpfc_els_disc_plogi(vport);
2262 if (vport->fc_flag & FC_RSCN_MODE) {
2263 /* Check to see if more RSCNs came in while we
2264 * were processing this one.
2266 if ((vport->fc_rscn_id_cnt == 0) &&
2267 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
2268 spin_lock_irq(shost->host_lock);
2269 vport->fc_flag &= ~FC_RSCN_MODE;
2270 spin_unlock_irq(shost->host_lock);
2271 lpfc_can_disctmo(vport);
2273 lpfc_els_handle_rscn(vport);
2280 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2281 * ring the match the sppecified nodelist.
2284 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
2286 LIST_HEAD(completions);
2287 struct lpfc_sli *psli;
2289 struct lpfc_iocbq *iocb, *next_iocb;
2290 struct lpfc_sli_ring *pring;
2293 pring = &psli->ring[LPFC_ELS_RING];
2295 /* Error matching iocb on txq or txcmplq
2296 * First check the txq.
2298 spin_lock_irq(&phba->hbalock);
2299 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2300 if (iocb->context1 != ndlp) {
2304 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2305 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2307 list_move_tail(&iocb->list, &completions);
2312 /* Next check the txcmplq */
2313 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2314 if (iocb->context1 != ndlp) {
2318 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
2319 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
2320 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2323 spin_unlock_irq(&phba->hbalock);
2325 while (!list_empty(&completions)) {
2326 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2327 list_del_init(&iocb->list);
2329 if (!iocb->iocb_cmpl)
2330 lpfc_sli_release_iocbq(phba, iocb);
2333 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2334 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2335 (iocb->iocb_cmpl) (phba, iocb, iocb);
2341 lpfc_disc_flush_list(struct lpfc_vport *vport)
2343 struct lpfc_nodelist *ndlp, *next_ndlp;
2344 struct lpfc_hba *phba = vport->phba;
2346 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2347 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
2349 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2350 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2351 lpfc_free_tx(phba, ndlp);
2359 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
2361 lpfc_els_flush_rscn(vport);
2362 lpfc_els_flush_cmd(vport);
2363 lpfc_disc_flush_list(vport);
2366 /*****************************************************************************/
2368 * NAME: lpfc_disc_timeout
2370 * FUNCTION: Fibre Channel driver discovery timeout routine.
2372 * EXECUTION ENVIRONMENT: interrupt only
2380 /*****************************************************************************/
2382 lpfc_disc_timeout(unsigned long ptr)
2384 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2385 struct lpfc_hba *phba = vport->phba;
2386 unsigned long flags = 0;
2388 if (unlikely(!phba))
2391 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
2392 spin_lock_irqsave(&vport->work_port_lock, flags);
2393 vport->work_port_events |= WORKER_DISC_TMO;
2394 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2396 spin_lock_irqsave(&phba->hbalock, flags);
2397 if (phba->work_wait)
2398 lpfc_worker_wake_up(phba);
2399 spin_unlock_irqrestore(&phba->hbalock, flags);
2405 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
2407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2408 struct lpfc_hba *phba = vport->phba;
2409 struct lpfc_sli *psli = &phba->sli;
2410 struct lpfc_nodelist *ndlp, *next_ndlp;
2411 LPFC_MBOXQ_t *initlinkmbox;
2412 int rc, clrlaerr = 0;
2414 if (!(vport->fc_flag & FC_DISC_TMO))
2417 spin_lock_irq(shost->host_lock);
2418 vport->fc_flag &= ~FC_DISC_TMO;
2419 spin_unlock_irq(shost->host_lock);
2421 switch (vport->port_state) {
2423 case LPFC_LOCAL_CFG_LINK:
2424 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2428 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
2429 "%d (%d):0221 FAN timeout\n",
2430 phba->brd_no, vport->vpi);
2432 /* Start discovery by sending FLOGI, clean up old rpis */
2433 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
2435 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2437 if (ndlp->nlp_type & NLP_FABRIC) {
2438 /* Clean up the ndlp on Fabric connections */
2439 lpfc_drop_node(vport, ndlp);
2440 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2441 /* Fail outstanding IO now since device
2442 * is marked for PLOGI.
2444 lpfc_unreg_rpi(vport, ndlp);
2447 if (vport->port_state != LPFC_FLOGI) {
2448 vport->port_state = LPFC_FLOGI;
2449 lpfc_set_disctmo(vport);
2450 lpfc_initial_flogi(vport);
2456 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2457 /* Initial FLOGI timeout */
2458 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2459 "%d (%d):0222 Initial %s timeout\n",
2460 phba->brd_no, vport->vpi,
2461 vport->vpi ? "FLOGI" : "FDISC");
2463 /* Assume no Fabric and go on with discovery.
2464 * Check for outstanding ELS FLOGI to abort.
2467 /* FLOGI failed, so just use loop map to make discovery list */
2468 lpfc_disc_list_loopmap(vport);
2470 /* Start discovery */
2471 lpfc_disc_start(vport);
2474 case LPFC_FABRIC_CFG_LINK:
2475 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2477 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2478 "%d (%d):0223 Timeout while waiting for "
2479 "NameServer login\n",
2480 phba->brd_no, vport->vpi);
2482 /* Next look for NameServer ndlp */
2483 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2486 /* Start discovery */
2487 lpfc_disc_start(vport);
2491 /* Check for wait for NameServer Rsp timeout */
2492 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2493 "%d (%d):0224 NameServer Query timeout "
2495 phba->brd_no, vport->vpi,
2496 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
2498 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2499 /* Try it one more time */
2500 vport->fc_ns_retry++;
2501 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
2502 vport->fc_ns_retry, 0);
2506 vport->fc_ns_retry = 0;
2509 * Discovery is over.
2510 * set port_state to PORT_READY if SLI2.
2511 * cmpl_reg_vpi will set port_state to READY for SLI3.
2513 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2514 lpfc_issue_reg_vpi(phba, vport);
2515 else { /* NPIV Not enabled */
2516 lpfc_issue_clear_la(phba, vport);
2517 vport->port_state = LPFC_VPORT_READY;
2520 /* Setup and issue mailbox INITIALIZE LINK command */
2521 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2522 if (!initlinkmbox) {
2523 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2524 "%d (%d):0206 Device Discovery "
2525 "completion error\n",
2526 phba->brd_no, vport->vpi);
2527 phba->link_state = LPFC_HBA_ERROR;
2531 lpfc_linkdown(phba);
2532 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2533 phba->cfg_link_speed);
2534 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2535 initlinkmbox->vport = vport;
2536 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2537 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2538 (MBX_NOWAIT | MBX_STOP_IOCB));
2539 lpfc_set_loopback_flag(phba);
2540 if (rc == MBX_NOT_FINISHED)
2541 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2545 case LPFC_DISC_AUTH:
2546 /* Node Authentication timeout */
2547 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2548 "%d (%d):0227 Node Authentication timeout\n",
2549 phba->brd_no, vport->vpi);
2550 lpfc_disc_flush_list(vport);
2553 * set port_state to PORT_READY if SLI2.
2554 * cmpl_reg_vpi will set port_state to READY for SLI3.
2556 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2557 lpfc_issue_reg_vpi(phba, vport);
2558 else { /* NPIV Not enabled */
2559 lpfc_issue_clear_la(phba, vport);
2560 vport->port_state = LPFC_VPORT_READY;
2564 case LPFC_VPORT_READY:
2565 if (vport->fc_flag & FC_RSCN_MODE) {
2566 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2567 "%d (%d):0231 RSCN timeout Data: x%x "
2569 phba->brd_no, vport->vpi,
2570 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
2572 /* Cleanup any outstanding ELS commands */
2573 lpfc_els_flush_cmd(vport);
2575 lpfc_els_flush_rscn(vport);
2576 lpfc_disc_flush_list(vport);
2581 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2582 "%d (%d):0229 Unexpected discovery timeout, "
2583 "vport State x%x\n",
2584 phba->brd_no, vport->vpi, vport->port_state);
2589 switch (phba->link_state) {
2591 /* CLEAR LA timeout */
2592 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2593 "%d (%d):0228 CLEAR LA timeout\n",
2594 phba->brd_no, vport->vpi);
2598 case LPFC_LINK_UNKNOWN:
2599 case LPFC_WARM_START:
2600 case LPFC_INIT_START:
2601 case LPFC_INIT_MBX_CMDS:
2602 case LPFC_LINK_DOWN:
2604 case LPFC_HBA_ERROR:
2605 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2606 "%d (%d):0230 Unexpected timeout, hba link "
2608 phba->brd_no, vport->vpi, phba->link_state);
2612 case LPFC_HBA_READY:
2617 lpfc_disc_flush_list(vport);
2618 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2619 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2620 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2621 vport->port_state = LPFC_VPORT_READY;
2628 * This routine handles processing a NameServer REG_LOGIN mailbox
2629 * command upon completion. It is setup in the LPFC_MBOXQ
2630 * as the completion routine when the command is
2631 * handed off to the SLI layer.
2634 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2636 MAILBOX_t *mb = &pmb->mb;
2637 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2638 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2639 struct lpfc_vport *vport = pmb->vport;
2641 pmb->context1 = NULL;
2643 ndlp->nlp_rpi = mb->un.varWords[0];
2644 ndlp->nlp_type |= NLP_FABRIC;
2645 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2648 * Start issuing Fabric-Device Management Interface (FDMI) command to
2649 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2650 * fdmi-on=2 (supporting RPA/hostnmae)
2653 if (phba->cfg_fdmi_on == 1)
2654 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2656 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
2658 /* Mailbox took a reference to the node */
2660 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2662 mempool_free(pmb, phba->mbox_mem_pool);
2668 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2670 uint16_t *rpi = param;
2672 return ndlp->nlp_rpi == *rpi;
2676 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2678 return memcmp(&ndlp->nlp_portname, param,
2679 sizeof(ndlp->nlp_portname)) == 0;
2682 struct lpfc_nodelist *
2683 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
2685 struct lpfc_nodelist *ndlp;
2687 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2688 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2689 filter(ndlp, param))
2696 * Search node lists for a remote port matching filter criteria
2697 * Caller needs to hold host_lock before calling this routine.
2699 struct lpfc_nodelist *
2700 lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
2702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2703 struct lpfc_nodelist *ndlp;
2705 spin_lock_irq(shost->host_lock);
2706 ndlp = __lpfc_find_node(vport, filter, param);
2707 spin_unlock_irq(shost->host_lock);
2712 * This routine looks up the ndlp lists for the given RPI. If rpi found it
2713 * returns the node list element pointer else return NULL.
2715 struct lpfc_nodelist *
2716 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
2718 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
2721 struct lpfc_nodelist *
2722 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
2724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2725 struct lpfc_nodelist *ndlp;
2727 spin_lock_irq(shost->host_lock);
2728 ndlp = __lpfc_findnode_rpi(vport, rpi);
2729 spin_unlock_irq(shost->host_lock);
2734 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
2735 * returns the node element list pointer else return NULL.
2737 struct lpfc_nodelist *
2738 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
2740 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2741 struct lpfc_nodelist *ndlp;
2743 spin_lock_irq(shost->host_lock);
2744 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2745 spin_unlock_irq(shost->host_lock);
2750 lpfc_dev_loss_delay(unsigned long ptr)
2752 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2753 struct lpfc_vport *vport = ndlp->vport;
2754 struct lpfc_hba *phba = vport->phba;
2755 struct lpfc_work_evt *evtp = &ndlp->dev_loss_evt;
2756 unsigned long flags;
2758 evtp = &ndlp->dev_loss_evt;
2760 spin_lock_irqsave(&phba->hbalock, flags);
2761 if (!list_empty(&evtp->evt_listp)) {
2762 spin_unlock_irqrestore(&phba->hbalock, flags);
2766 evtp->evt_arg1 = ndlp;
2767 evtp->evt = LPFC_EVT_DEV_LOSS;
2768 list_add_tail(&evtp->evt_listp, &phba->work_list);
2769 if (phba->work_wait)
2770 lpfc_worker_wake_up(phba);
2771 spin_unlock_irqrestore(&phba->hbalock, flags);
2776 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2779 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2780 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2781 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
2782 init_timer(&ndlp->nlp_initiator_tmr);
2783 ndlp->nlp_initiator_tmr.function = lpfc_dev_loss_delay;
2784 ndlp->nlp_initiator_tmr.data = (unsigned long)ndlp;
2785 init_timer(&ndlp->nlp_delayfunc);
2786 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2787 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2788 ndlp->nlp_DID = did;
2789 ndlp->vport = vport;
2790 ndlp->nlp_sid = NLP_NO_SID;
2791 INIT_LIST_HEAD(&ndlp->nlp_listp);
2792 kref_init(&ndlp->kref);
2797 lpfc_nlp_release(struct kref *kref)
2799 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2801 lpfc_nlp_remove(ndlp->vport, ndlp);
2802 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
2805 struct lpfc_nodelist *
2806 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2809 kref_get(&ndlp->kref);
2814 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2816 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;