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"
40 #include "lpfc_debugfs.h"
42 /* AlpaArray for assignment of scsid for scan-down and bind_method */
43 static uint8_t lpfcAlpaArray[] = {
44 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
45 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
46 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
47 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
48 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
49 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
50 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
51 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
52 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
53 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
54 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
55 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
56 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
59 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
62 lpfc_terminate_rport_io(struct fc_rport *rport)
64 struct lpfc_rport_data *rdata;
65 struct lpfc_nodelist * ndlp;
66 struct lpfc_hba *phba;
68 rdata = rport->dd_data;
72 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
73 printk(KERN_ERR "Cannot find remote node"
74 " to terminate I/O Data x%x\n",
79 phba = ndlp->vport->phba;
81 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
82 "rport terminate: sid:x%x did:x%x flg:x%x",
83 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
85 if (ndlp->nlp_sid != NLP_NO_SID) {
86 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
87 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
94 * This function will be called when dev_loss_tmo fire.
97 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
99 struct lpfc_rport_data *rdata;
100 struct lpfc_nodelist * ndlp;
101 struct lpfc_vport *vport;
102 struct lpfc_hba *phba;
103 struct completion devloss_compl;
104 struct lpfc_work_evt *evtp;
106 rdata = rport->dd_data;
110 if (rport->scsi_target_id != -1) {
111 printk(KERN_ERR "Cannot find remote node"
112 " for rport in dev_loss_tmo_callbk x%x\n",
121 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
122 "rport devlosscb: sid:x%x did:x%x flg:x%x",
123 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
125 init_completion(&devloss_compl);
126 evtp = &ndlp->dev_loss_evt;
128 if (!list_empty(&evtp->evt_listp))
131 spin_lock_irq(&phba->hbalock);
132 evtp->evt_arg1 = ndlp;
133 evtp->evt_arg2 = &devloss_compl;
134 evtp->evt = LPFC_EVT_DEV_LOSS;
135 list_add_tail(&evtp->evt_listp, &phba->work_list);
137 wake_up(phba->work_wait);
139 spin_unlock_irq(&phba->hbalock);
141 wait_for_completion(&devloss_compl);
147 * This function is called from the worker thread when dev_loss_tmo
151 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
153 struct lpfc_rport_data *rdata;
154 struct fc_rport *rport;
155 struct lpfc_vport *vport;
156 struct lpfc_hba *phba;
165 rdata = rport->dd_data;
166 name = (uint8_t *) &ndlp->nlp_portname;
170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
171 "rport devlosstmo:did:x%x type:x%x id:x%x",
172 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
174 if (!(vport->load_flag & FC_UNLOADING) &&
175 ndlp->nlp_state == NLP_STE_MAPPED_NODE)
178 if (ndlp->nlp_type & NLP_FABRIC) {
182 /* We will clean up these Nodes in linkup */
183 put_node = rdata->pnode != NULL;
184 put_rport = ndlp->rport != NULL;
190 put_device(&rport->dev);
194 if (ndlp->nlp_sid != NLP_NO_SID) {
196 /* flush the target */
197 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
198 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
200 if (vport->load_flag & FC_UNLOADING)
204 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
205 "%d (%d):0203 Devloss timeout on "
206 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
207 "NPort x%x Data: x%x x%x x%x\n",
208 phba->brd_no, vport->vpi,
209 *name, *(name+1), *(name+2), *(name+3),
210 *(name+4), *(name+5), *(name+6), *(name+7),
211 ndlp->nlp_DID, ndlp->nlp_flag,
212 ndlp->nlp_state, ndlp->nlp_rpi);
214 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
215 "%d (%d):0204 Devloss timeout on "
216 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
217 "NPort x%x Data: x%x x%x x%x\n",
218 phba->brd_no, vport->vpi,
219 *name, *(name+1), *(name+2), *(name+3),
220 *(name+4), *(name+5), *(name+6), *(name+7),
221 ndlp->nlp_DID, ndlp->nlp_flag,
222 ndlp->nlp_state, ndlp->nlp_rpi);
225 if (!(vport->load_flag & FC_UNLOADING) &&
226 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
227 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
228 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
229 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
234 put_node = rdata->pnode != NULL;
235 put_rport = ndlp->rport != NULL;
241 put_device(&rport->dev);
247 lpfc_worker_wake_up(struct lpfc_hba *phba)
249 wake_up(phba->work_wait);
254 lpfc_work_list_done(struct lpfc_hba *phba)
256 struct lpfc_work_evt *evtp = NULL;
257 struct lpfc_nodelist *ndlp;
258 struct lpfc_vport *vport;
261 spin_lock_irq(&phba->hbalock);
262 while (!list_empty(&phba->work_list)) {
263 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
265 spin_unlock_irq(&phba->hbalock);
268 case LPFC_EVT_DEV_LOSS_DELAY:
269 free_evt = 0; /* evt is part of ndlp */
270 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
275 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
276 "rport devlossdly:did:x%x flg:x%x",
277 ndlp->nlp_DID, ndlp->nlp_flag, 0);
279 if (!(vport->load_flag & FC_UNLOADING) &&
280 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
281 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
282 lpfc_disc_state_machine(vport, ndlp, NULL,
286 case LPFC_EVT_ELS_RETRY:
287 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
288 lpfc_els_retry_delay_handler(ndlp);
289 free_evt = 0; /* evt is part of ndlp */
291 case LPFC_EVT_DEV_LOSS:
292 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
294 lpfc_dev_loss_tmo_handler(ndlp);
296 complete((struct completion *)(evtp->evt_arg2));
299 case LPFC_EVT_ONLINE:
300 if (phba->link_state < LPFC_LINK_DOWN)
301 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
303 *(int *) (evtp->evt_arg1) = 0;
304 complete((struct completion *)(evtp->evt_arg2));
306 case LPFC_EVT_OFFLINE_PREP:
307 if (phba->link_state >= LPFC_LINK_DOWN)
308 lpfc_offline_prep(phba);
309 *(int *)(evtp->evt_arg1) = 0;
310 complete((struct completion *)(evtp->evt_arg2));
312 case LPFC_EVT_OFFLINE:
314 lpfc_sli_brdrestart(phba);
315 *(int *)(evtp->evt_arg1) =
316 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
317 lpfc_unblock_mgmt_io(phba);
318 complete((struct completion *)(evtp->evt_arg2));
320 case LPFC_EVT_WARM_START:
322 lpfc_reset_barrier(phba);
323 lpfc_sli_brdreset(phba);
324 lpfc_hba_down_post(phba);
325 *(int *)(evtp->evt_arg1) =
326 lpfc_sli_brdready(phba, HS_MBRDY);
327 lpfc_unblock_mgmt_io(phba);
328 complete((struct completion *)(evtp->evt_arg2));
332 *(int *)(evtp->evt_arg1)
333 = (phba->pport->stopped)
334 ? 0 : lpfc_sli_brdkill(phba);
335 lpfc_unblock_mgmt_io(phba);
336 complete((struct completion *)(evtp->evt_arg2));
341 spin_lock_irq(&phba->hbalock);
343 spin_unlock_irq(&phba->hbalock);
348 lpfc_work_done(struct lpfc_hba *phba)
350 struct lpfc_sli_ring *pring;
351 uint32_t ha_copy, status, control, work_port_events;
352 struct lpfc_vport **vports;
355 spin_lock_irq(&phba->hbalock);
356 ha_copy = phba->work_ha;
358 spin_unlock_irq(&phba->hbalock);
360 if (ha_copy & HA_ERATT)
361 lpfc_handle_eratt(phba);
363 if (ha_copy & HA_MBATT)
364 lpfc_sli_handle_mb_event(phba);
366 if (ha_copy & HA_LATT)
367 lpfc_handle_latt(phba);
368 vports = lpfc_create_vport_work_array(phba);
370 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
371 work_port_events = vports[i]->work_port_events;
372 if (work_port_events & WORKER_DISC_TMO)
373 lpfc_disc_timeout_handler(vports[i]);
374 if (work_port_events & WORKER_ELS_TMO)
375 lpfc_els_timeout_handler(vports[i]);
376 if (work_port_events & WORKER_HB_TMO)
377 lpfc_hb_timeout_handler(phba);
378 if (work_port_events & WORKER_MBOX_TMO)
379 lpfc_mbox_timeout_handler(phba);
380 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
381 lpfc_unblock_fabric_iocbs(phba);
382 if (work_port_events & WORKER_FDMI_TMO)
383 lpfc_fdmi_timeout_handler(vports[i]);
384 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
385 lpfc_ramp_down_queue_handler(phba);
386 if (work_port_events & WORKER_RAMP_UP_QUEUE)
387 lpfc_ramp_up_queue_handler(phba);
388 spin_lock_irq(&vports[i]->work_port_lock);
389 vports[i]->work_port_events &= ~work_port_events;
390 spin_unlock_irq(&vports[i]->work_port_lock);
392 lpfc_destroy_vport_work_array(vports);
394 pring = &phba->sli.ring[LPFC_ELS_RING];
395 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
396 status >>= (4*LPFC_ELS_RING);
397 if ((status & HA_RXMASK)
398 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
399 if (pring->flag & LPFC_STOP_IOCB_MASK) {
400 pring->flag |= LPFC_DEFERRED_RING_EVENT;
402 lpfc_sli_handle_slow_ring_event(phba, pring,
405 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
408 * Turn on Ring interrupts
410 spin_lock_irq(&phba->hbalock);
411 control = readl(phba->HCregaddr);
412 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
413 lpfc_debugfs_slow_ring_trc(phba,
414 "WRK Enable ring: cntl:x%x hacopy:x%x",
415 control, ha_copy, 0);
417 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
418 writel(control, phba->HCregaddr);
419 readl(phba->HCregaddr); /* flush */
422 lpfc_debugfs_slow_ring_trc(phba,
423 "WRK Ring ok: cntl:x%x hacopy:x%x",
424 control, ha_copy, 0);
426 spin_unlock_irq(&phba->hbalock);
428 lpfc_work_list_done(phba);
432 check_work_wait_done(struct lpfc_hba *phba)
434 struct lpfc_vport *vport;
435 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
438 spin_lock_irq(&phba->hbalock);
439 list_for_each_entry(vport, &phba->port_list, listentry) {
440 if (vport->work_port_events) {
445 if (rc || phba->work_ha || (!list_empty(&phba->work_list)) ||
446 kthread_should_stop() || pring->flag & LPFC_DEFERRED_RING_EVENT) {
450 phba->work_found = 0;
451 spin_unlock_irq(&phba->hbalock);
457 lpfc_do_work(void *p)
459 struct lpfc_hba *phba = p;
461 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
463 set_user_nice(current, -20);
464 phba->work_wait = &work_waitq;
465 phba->work_found = 0;
469 rc = wait_event_interruptible(work_waitq,
470 check_work_wait_done(phba));
474 if (kthread_should_stop())
477 lpfc_work_done(phba);
479 /* If there is alot of slow ring work, like during link up
480 * check_work_wait_done() may cause this thread to not give
481 * up the CPU for very long periods of time. This may cause
482 * soft lockups or other problems. To avoid these situations
483 * give up the CPU here after LPFC_MAX_WORKER_ITERATION
484 * consecutive iterations.
486 if (phba->work_found >= LPFC_MAX_WORKER_ITERATION) {
487 phba->work_found = 0;
491 phba->work_wait = NULL;
496 * This is only called to handle FC worker events. Since this a rare
497 * occurance, we allocate a struct lpfc_work_evt structure here instead of
498 * embedding it in the IOCB.
501 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
504 struct lpfc_work_evt *evtp;
508 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
509 * be queued to worker thread for processing
511 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
515 evtp->evt_arg1 = arg1;
516 evtp->evt_arg2 = arg2;
519 spin_lock_irqsave(&phba->hbalock, flags);
520 list_add_tail(&evtp->evt_listp, &phba->work_list);
522 lpfc_worker_wake_up(phba);
523 spin_unlock_irqrestore(&phba->hbalock, flags);
529 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
531 struct lpfc_hba *phba = vport->phba;
532 struct lpfc_nodelist *ndlp, *next_ndlp;
535 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
536 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
539 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN)
540 lpfc_unreg_rpi(vport, ndlp);
542 /* Leave Fabric nodes alone on link down */
543 if (!remove && ndlp->nlp_type & NLP_FABRIC)
545 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
548 : NLP_EVT_DEVICE_RECOVERY);
550 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
551 lpfc_mbx_unreg_vpi(vport);
552 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
557 lpfc_linkdown_port(struct lpfc_vport *vport)
559 struct lpfc_nodelist *ndlp, *next_ndlp;
560 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
562 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
565 "Link Down: state:x%x rtry:x%x flg:x%x",
566 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
568 /* Cleanup any outstanding RSCN activity */
569 lpfc_els_flush_rscn(vport);
571 /* Cleanup any outstanding ELS commands */
572 lpfc_els_flush_cmd(vport);
574 lpfc_cleanup_rpis(vport, 0);
576 /* free any ndlp's on unused list */
577 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
578 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
579 lpfc_drop_node(vport, ndlp);
581 /* Turn off discovery timer if its running */
582 lpfc_can_disctmo(vport);
586 lpfc_linkdown(struct lpfc_hba *phba)
588 struct lpfc_vport *vport = phba->pport;
589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
590 struct lpfc_vport **vports;
594 if (phba->link_state == LPFC_LINK_DOWN) {
597 spin_lock_irq(&phba->hbalock);
598 if (phba->link_state > LPFC_LINK_DOWN) {
599 phba->link_state = LPFC_LINK_DOWN;
600 phba->pport->fc_flag &= ~FC_LBIT;
602 spin_unlock_irq(&phba->hbalock);
603 vports = lpfc_create_vport_work_array(phba);
605 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
606 /* Issue a LINK DOWN event to all nodes */
607 lpfc_linkdown_port(vports[i]);
609 lpfc_destroy_vport_work_array(vports);
610 /* Clean up any firmware default rpi's */
611 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
613 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
615 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
616 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
617 == MBX_NOT_FINISHED) {
618 mempool_free(mb, phba->mbox_mem_pool);
622 /* Setup myDID for link up if we are in pt2pt mode */
623 if (phba->pport->fc_flag & FC_PT2PT) {
624 phba->pport->fc_myDID = 0;
625 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
627 lpfc_config_link(phba, mb);
628 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
630 if (lpfc_sli_issue_mbox(phba, mb,
631 (MBX_NOWAIT | MBX_STOP_IOCB))
632 == MBX_NOT_FINISHED) {
633 mempool_free(mb, phba->mbox_mem_pool);
636 spin_lock_irq(shost->host_lock);
637 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
638 spin_unlock_irq(shost->host_lock);
645 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
647 struct lpfc_nodelist *ndlp;
649 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
650 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
653 if (ndlp->nlp_type & NLP_FABRIC) {
654 /* On Linkup its safe to clean up the ndlp
655 * from Fabric connections.
657 if (ndlp->nlp_DID != Fabric_DID)
658 lpfc_unreg_rpi(vport, ndlp);
659 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
660 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
661 /* Fail outstanding IO now since device is
664 lpfc_unreg_rpi(vport, ndlp);
670 lpfc_linkup_port(struct lpfc_vport *vport)
672 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
673 struct lpfc_nodelist *ndlp, *next_ndlp;
674 struct lpfc_hba *phba = vport->phba;
676 if ((vport->load_flag & FC_UNLOADING) != 0)
679 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
680 "Link Up: top:x%x speed:x%x flg:x%x",
681 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
683 /* If NPIV is not enabled, only bring the physical port up */
684 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
685 (vport != phba->pport))
688 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
690 spin_lock_irq(shost->host_lock);
691 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
692 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
693 vport->fc_flag |= FC_NDISC_ACTIVE;
694 vport->fc_ns_retry = 0;
695 spin_unlock_irq(shost->host_lock);
697 if (vport->fc_flag & FC_LBIT)
698 lpfc_linkup_cleanup_nodes(vport);
700 /* free any ndlp's in unused state */
701 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
703 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
704 lpfc_drop_node(vport, ndlp);
708 lpfc_linkup(struct lpfc_hba *phba)
710 struct lpfc_vport **vports;
713 phba->link_state = LPFC_LINK_UP;
715 /* Unblock fabric iocbs if they are blocked */
716 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
717 del_timer_sync(&phba->fabric_block_timer);
719 vports = lpfc_create_vport_work_array(phba);
721 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
722 lpfc_linkup_port(vports[i]);
723 lpfc_destroy_vport_work_array(vports);
724 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
725 lpfc_issue_clear_la(phba, phba->pport);
731 * This routine handles processing a CLEAR_LA mailbox
732 * command upon completion. It is setup in the LPFC_MBOXQ
733 * as the completion routine when the command is
734 * handed off to the SLI layer.
737 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
739 struct lpfc_vport *vport = pmb->vport;
740 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
741 struct lpfc_sli *psli = &phba->sli;
742 MAILBOX_t *mb = &pmb->mb;
745 /* Since we don't do discovery right now, turn these off here */
746 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
747 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
748 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
750 /* Check for error */
751 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
752 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
753 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
754 "%d (%d):0320 CLEAR_LA mbxStatus error x%x hba "
756 phba->brd_no, vport->vpi, mb->mbxStatus,
759 phba->link_state = LPFC_HBA_ERROR;
763 if (vport->port_type == LPFC_PHYSICAL_PORT)
764 phba->link_state = LPFC_HBA_READY;
766 spin_lock_irq(&phba->hbalock);
767 psli->sli_flag |= LPFC_PROCESS_LA;
768 control = readl(phba->HCregaddr);
769 control |= HC_LAINT_ENA;
770 writel(control, phba->HCregaddr);
771 readl(phba->HCregaddr); /* flush */
772 spin_unlock_irq(&phba->hbalock);
775 vport->num_disc_nodes = 0;
776 /* go thru NPR nodes and issue ELS PLOGIs */
777 if (vport->fc_npr_cnt)
778 lpfc_els_disc_plogi(vport);
780 if (!vport->num_disc_nodes) {
781 spin_lock_irq(shost->host_lock);
782 vport->fc_flag &= ~FC_NDISC_ACTIVE;
783 spin_unlock_irq(shost->host_lock);
786 vport->port_state = LPFC_VPORT_READY;
789 /* Device Discovery completes */
790 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
791 "%d (%d):0225 Device Discovery completes\n",
792 phba->brd_no, vport->vpi);
794 mempool_free(pmb, phba->mbox_mem_pool);
796 spin_lock_irq(shost->host_lock);
797 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
798 spin_unlock_irq(shost->host_lock);
800 del_timer_sync(&phba->fc_estabtmo);
802 lpfc_can_disctmo(vport);
804 /* turn on Link Attention interrupts */
806 spin_lock_irq(&phba->hbalock);
807 psli->sli_flag |= LPFC_PROCESS_LA;
808 control = readl(phba->HCregaddr);
809 control |= HC_LAINT_ENA;
810 writel(control, phba->HCregaddr);
811 readl(phba->HCregaddr); /* flush */
812 spin_unlock_irq(&phba->hbalock);
819 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
821 struct lpfc_vport *vport = pmb->vport;
823 if (pmb->mb.mbxStatus)
826 mempool_free(pmb, phba->mbox_mem_pool);
828 if (phba->fc_topology == TOPOLOGY_LOOP &&
829 vport->fc_flag & FC_PUBLIC_LOOP &&
830 !(vport->fc_flag & FC_LBIT)) {
831 /* Need to wait for FAN - use discovery timer
832 * for timeout. port_state is identically
833 * LPFC_LOCAL_CFG_LINK while waiting for FAN
835 lpfc_set_disctmo(vport);
839 /* Start discovery by sending a FLOGI. port_state is identically
840 * LPFC_FLOGI while waiting for FLOGI cmpl
842 if (vport->port_state != LPFC_FLOGI) {
843 vport->port_state = LPFC_FLOGI;
844 lpfc_set_disctmo(vport);
845 lpfc_initial_flogi(vport);
850 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
851 "%d (%d):0306 CONFIG_LINK mbxStatus error x%x "
853 phba->brd_no, vport->vpi, pmb->mb.mbxStatus,
856 mempool_free(pmb, phba->mbox_mem_pool);
860 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
861 "%d (%d):0200 CONFIG_LINK bad hba state x%x\n",
862 phba->brd_no, vport->vpi, vport->port_state);
864 lpfc_issue_clear_la(phba, vport);
869 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
871 MAILBOX_t *mb = &pmb->mb;
872 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
873 struct lpfc_vport *vport = pmb->vport;
876 /* Check for error */
878 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
879 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
880 "%d (%d):0319 READ_SPARAM mbxStatus error x%x "
882 phba->brd_no, vport->vpi, mb->mbxStatus,
889 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
890 sizeof (struct serv_parm));
891 if (phba->cfg_soft_wwnn)
892 u64_to_wwn(phba->cfg_soft_wwnn,
893 vport->fc_sparam.nodeName.u.wwn);
894 if (phba->cfg_soft_wwpn)
895 u64_to_wwn(phba->cfg_soft_wwpn,
896 vport->fc_sparam.portName.u.wwn);
897 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
898 sizeof(vport->fc_nodename));
899 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
900 sizeof(vport->fc_portname));
901 if (vport->port_type == LPFC_PHYSICAL_PORT) {
902 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
903 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
906 lpfc_mbuf_free(phba, mp->virt, mp->phys);
908 mempool_free(pmb, phba->mbox_mem_pool);
912 pmb->context1 = NULL;
913 lpfc_mbuf_free(phba, mp->virt, mp->phys);
915 lpfc_issue_clear_la(phba, vport);
916 mempool_free(pmb, phba->mbox_mem_pool);
921 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
923 struct lpfc_vport *vport = phba->pport;
924 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
926 struct lpfc_dmabuf *mp;
929 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
930 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
932 spin_lock_irq(&phba->hbalock);
933 switch (la->UlnkSpeed) {
935 phba->fc_linkspeed = LA_1GHZ_LINK;
938 phba->fc_linkspeed = LA_2GHZ_LINK;
941 phba->fc_linkspeed = LA_4GHZ_LINK;
944 phba->fc_linkspeed = LA_8GHZ_LINK;
947 phba->fc_linkspeed = LA_UNKNW_LINK;
951 phba->fc_topology = la->topology;
952 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
954 if (phba->fc_topology == TOPOLOGY_LOOP) {
955 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
957 /* Get Loop Map information */
959 vport->fc_flag |= FC_LBIT;
961 vport->fc_myDID = la->granted_AL_PA;
962 i = la->un.lilpBde64.tus.f.bdeSize;
965 phba->alpa_map[0] = 0;
967 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
978 numalpa = phba->alpa_map[0];
980 while (j < numalpa) {
981 memset(un.pamap, 0, 16);
982 for (k = 1; j < numalpa; k++) {
984 phba->alpa_map[j + 1];
989 /* Link Up Event ALPA map */
990 lpfc_printf_log(phba,
993 "%d:1304 Link Up Event "
994 "ALPA map Data: x%x "
997 un.pa.wd1, un.pa.wd2,
998 un.pa.wd3, un.pa.wd4);
1003 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
1004 if (phba->max_vpi && phba->cfg_npiv_enable &&
1005 (phba->sli_rev == 3))
1006 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
1008 vport->fc_myDID = phba->fc_pref_DID;
1009 vport->fc_flag |= FC_LBIT;
1011 spin_unlock_irq(&phba->hbalock);
1015 lpfc_read_sparam(phba, sparam_mbox, 0);
1016 sparam_mbox->vport = vport;
1017 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1018 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
1019 (MBX_NOWAIT | MBX_STOP_IOCB));
1020 if (rc == MBX_NOT_FINISHED) {
1021 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
1022 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1024 mempool_free(sparam_mbox, phba->mbox_mem_pool);
1026 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
1032 vport->port_state = LPFC_LOCAL_CFG_LINK;
1033 lpfc_config_link(phba, cfglink_mbox);
1034 cfglink_mbox->vport = vport;
1035 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
1036 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
1037 (MBX_NOWAIT | MBX_STOP_IOCB));
1038 if (rc != MBX_NOT_FINISHED)
1040 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
1043 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1044 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1045 "%d (%d):0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1046 phba->brd_no, vport->vpi,
1047 vport->port_state, sparam_mbox, cfglink_mbox);
1049 lpfc_issue_clear_la(phba, vport);
1054 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
1057 struct lpfc_sli *psli = &phba->sli;
1059 lpfc_linkdown(phba);
1061 /* turn on Link Attention interrupts - no CLEAR_LA needed */
1062 spin_lock_irq(&phba->hbalock);
1063 psli->sli_flag |= LPFC_PROCESS_LA;
1064 control = readl(phba->HCregaddr);
1065 control |= HC_LAINT_ENA;
1066 writel(control, phba->HCregaddr);
1067 readl(phba->HCregaddr); /* flush */
1068 spin_unlock_irq(&phba->hbalock);
1072 * This routine handles processing a READ_LA mailbox
1073 * command upon completion. It is setup in the LPFC_MBOXQ
1074 * as the completion routine when the command is
1075 * handed off to the SLI layer.
1078 lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1080 struct lpfc_vport *vport = pmb->vport;
1081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1083 MAILBOX_t *mb = &pmb->mb;
1084 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1086 /* Check for error */
1087 if (mb->mbxStatus) {
1088 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1089 "%d:1307 READ_LA mbox error x%x state x%x\n",
1090 phba->brd_no, mb->mbxStatus, vport->port_state);
1091 lpfc_mbx_issue_link_down(phba);
1092 phba->link_state = LPFC_HBA_ERROR;
1093 goto lpfc_mbx_cmpl_read_la_free_mbuf;
1096 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
1098 memcpy(&phba->alpa_map[0], mp->virt, 128);
1100 spin_lock_irq(shost->host_lock);
1102 vport->fc_flag |= FC_BYPASSED_MODE;
1104 vport->fc_flag &= ~FC_BYPASSED_MODE;
1105 spin_unlock_irq(shost->host_lock);
1107 if (((phba->fc_eventTag + 1) < la->eventTag) ||
1108 (phba->fc_eventTag == la->eventTag)) {
1109 phba->fc_stat.LinkMultiEvent++;
1110 if (la->attType == AT_LINK_UP)
1111 if (phba->fc_eventTag != 0)
1112 lpfc_linkdown(phba);
1115 phba->fc_eventTag = la->eventTag;
1117 if (la->attType == AT_LINK_UP) {
1118 phba->fc_stat.LinkUp++;
1119 if (phba->link_flag & LS_LOOPBACK_MODE) {
1120 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1121 "%d:1306 Link Up Event in loop back mode "
1122 "x%x received Data: x%x x%x x%x x%x\n",
1123 phba->brd_no, la->eventTag, phba->fc_eventTag,
1124 la->granted_AL_PA, la->UlnkSpeed,
1127 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1128 "%d:1303 Link Up Event x%x received "
1129 "Data: x%x x%x x%x x%x\n",
1130 phba->brd_no, la->eventTag, phba->fc_eventTag,
1131 la->granted_AL_PA, la->UlnkSpeed,
1134 lpfc_mbx_process_link_up(phba, la);
1136 phba->fc_stat.LinkDown++;
1137 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1138 "%d:1305 Link Down Event x%x received "
1139 "Data: x%x x%x x%x\n",
1140 phba->brd_no, la->eventTag, phba->fc_eventTag,
1141 phba->pport->port_state, vport->fc_flag);
1142 lpfc_mbx_issue_link_down(phba);
1145 lpfc_mbx_cmpl_read_la_free_mbuf:
1146 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1148 mempool_free(pmb, phba->mbox_mem_pool);
1153 * This routine handles processing a REG_LOGIN mailbox
1154 * command upon completion. It is setup in the LPFC_MBOXQ
1155 * as the completion routine when the command is
1156 * handed off to the SLI layer.
1159 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1161 struct lpfc_vport *vport = pmb->vport;
1162 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1163 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1165 pmb->context1 = NULL;
1167 /* Good status, call state machine */
1168 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
1169 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1171 mempool_free(pmb, phba->mbox_mem_pool);
1178 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1180 MAILBOX_t *mb = &pmb->mb;
1181 struct lpfc_vport *vport = pmb->vport;
1182 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1184 switch (mb->mbxStatus) {
1188 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1189 "%d (%d):0911 cmpl_unreg_vpi, "
1190 "mb status = 0x%x\n",
1191 phba->brd_no, vport->vpi, mb->mbxStatus);
1194 vport->unreg_vpi_cmpl = VPORT_OK;
1195 mempool_free(pmb, phba->mbox_mem_pool);
1197 * This shost reference might have been taken at the beginning of
1198 * lpfc_vport_delete()
1200 if (vport->load_flag & FC_UNLOADING)
1201 scsi_host_put(shost);
1205 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
1207 struct lpfc_hba *phba = vport->phba;
1211 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1215 lpfc_unreg_vpi(phba, vport->vpi, mbox);
1216 mbox->vport = vport;
1217 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
1218 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1219 if (rc == MBX_NOT_FINISHED) {
1220 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1221 "%d (%d):1800 Could not issue unreg_vpi\n",
1222 phba->brd_no, vport->vpi);
1223 mempool_free(mbox, phba->mbox_mem_pool);
1224 vport->unreg_vpi_cmpl = VPORT_ERROR;
1229 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1231 struct lpfc_vport *vport = pmb->vport;
1232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1233 MAILBOX_t *mb = &pmb->mb;
1235 switch (mb->mbxStatus) {
1239 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1240 "%d (%d):0912 cmpl_reg_vpi, mb status = 0x%x\n",
1241 phba->brd_no, vport->vpi, mb->mbxStatus);
1242 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1243 spin_lock_irq(shost->host_lock);
1244 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1245 spin_unlock_irq(shost->host_lock);
1246 vport->fc_myDID = 0;
1250 vport->num_disc_nodes = 0;
1251 /* go thru NPR list and issue ELS PLOGIs */
1252 if (vport->fc_npr_cnt)
1253 lpfc_els_disc_plogi(vport);
1255 if (!vport->num_disc_nodes) {
1256 spin_lock_irq(shost->host_lock);
1257 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1258 spin_unlock_irq(shost->host_lock);
1259 lpfc_can_disctmo(vport);
1261 vport->port_state = LPFC_VPORT_READY;
1264 mempool_free(pmb, phba->mbox_mem_pool);
1269 * This routine handles processing a Fabric REG_LOGIN mailbox
1270 * command upon completion. It is setup in the LPFC_MBOXQ
1271 * as the completion routine when the command is
1272 * handed off to the SLI layer.
1275 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1277 struct lpfc_vport *vport = pmb->vport;
1278 MAILBOX_t *mb = &pmb->mb;
1279 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1280 struct lpfc_nodelist *ndlp;
1281 struct lpfc_vport **vports;
1284 ndlp = (struct lpfc_nodelist *) pmb->context2;
1285 pmb->context1 = NULL;
1286 pmb->context2 = NULL;
1287 if (mb->mbxStatus) {
1288 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1290 mempool_free(pmb, phba->mbox_mem_pool);
1293 if (phba->fc_topology == TOPOLOGY_LOOP) {
1294 /* FLOGI failed, use loop map to make discovery list */
1295 lpfc_disc_list_loopmap(vport);
1297 /* Start discovery */
1298 lpfc_disc_start(vport);
1302 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1303 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1304 "%d (%d):0258 Register Fabric login error: 0x%x\n",
1305 phba->brd_no, vport->vpi, mb->mbxStatus);
1310 ndlp->nlp_rpi = mb->un.varWords[0];
1311 ndlp->nlp_type |= NLP_FABRIC;
1312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1314 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
1316 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
1317 vports = lpfc_create_vport_work_array(phba);
1320 i < LPFC_MAX_VPORTS && vports[i] != NULL;
1322 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
1324 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1325 lpfc_initial_fdisc(vports[i]);
1326 else if (phba->sli3_options &
1327 LPFC_SLI3_NPIV_ENABLED) {
1328 lpfc_vport_set_state(vports[i],
1329 FC_VPORT_NO_FABRIC_SUPP);
1330 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1331 "%d (%d):0259 No NPIV "
1337 lpfc_destroy_vport_work_array(vports);
1338 lpfc_do_scr_ns_plogi(phba, vport);
1341 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1343 mempool_free(pmb, phba->mbox_mem_pool);
1348 * This routine handles processing a NameServer REG_LOGIN mailbox
1349 * command upon completion. It is setup in the LPFC_MBOXQ
1350 * as the completion routine when the command is
1351 * handed off to the SLI layer.
1354 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1356 MAILBOX_t *mb = &pmb->mb;
1357 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1358 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1359 struct lpfc_vport *vport = pmb->vport;
1361 if (mb->mbxStatus) {
1364 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1366 mempool_free(pmb, phba->mbox_mem_pool);
1367 lpfc_drop_node(vport, ndlp);
1369 if (phba->fc_topology == TOPOLOGY_LOOP) {
1371 * RegLogin failed, use loop map to make discovery
1374 lpfc_disc_list_loopmap(vport);
1376 /* Start discovery */
1377 lpfc_disc_start(vport);
1380 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1381 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1382 "%d (%d):0260 Register NameServer error: 0x%x\n",
1383 phba->brd_no, vport->vpi, mb->mbxStatus);
1387 pmb->context1 = NULL;
1389 ndlp->nlp_rpi = mb->un.varWords[0];
1390 ndlp->nlp_type |= NLP_FABRIC;
1391 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1393 if (vport->port_state < LPFC_VPORT_READY) {
1394 /* Link up discovery requires Fabric registration. */
1395 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
1396 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
1397 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
1398 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
1399 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
1401 /* Issue SCR just before NameServer GID_FT Query */
1402 lpfc_issue_els_scr(vport, SCR_DID, 0);
1405 vport->fc_ns_retry = 0;
1406 /* Good status, issue CT Request to NameServer */
1407 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
1408 /* Cannot issue NameServer Query, so finish up discovery */
1413 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1415 mempool_free(pmb, phba->mbox_mem_pool);
1421 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1424 struct fc_rport *rport;
1425 struct lpfc_rport_data *rdata;
1426 struct fc_rport_identifiers rport_ids;
1427 struct lpfc_hba *phba = vport->phba;
1429 /* Remote port has reappeared. Re-register w/ FC transport */
1430 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1431 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1432 rport_ids.port_id = ndlp->nlp_DID;
1433 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1436 * We leave our node pointer in rport->dd_data when we unregister a
1437 * FCP target port. But fc_remote_port_add zeros the space to which
1438 * rport->dd_data points. So, if we're reusing a previously
1439 * registered port, drop the reference that we took the last time we
1440 * registered the port.
1442 if (ndlp->rport && ndlp->rport->dd_data &&
1443 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) {
1447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1448 "rport add: did:x%x flg:x%x type x%x",
1449 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1451 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
1452 if (!rport || !get_device(&rport->dev)) {
1453 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1454 "Warning: fc_remote_port_add failed\n");
1458 /* initialize static port data */
1459 rport->maxframe_size = ndlp->nlp_maxframe;
1460 rport->supported_classes = ndlp->nlp_class_sup;
1461 rdata = rport->dd_data;
1462 rdata->pnode = lpfc_nlp_get(ndlp);
1464 if (ndlp->nlp_type & NLP_FCP_TARGET)
1465 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1466 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1467 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1470 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1471 fc_remote_port_rolechg(rport, rport_ids.roles);
1473 if ((rport->scsi_target_id != -1) &&
1474 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1475 ndlp->nlp_sid = rport->scsi_target_id;
1481 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
1483 struct fc_rport *rport = ndlp->rport;
1485 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
1486 "rport delete: did:x%x flg:x%x type x%x",
1487 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1489 fc_remote_port_delete(rport);
1495 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
1497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1499 spin_lock_irq(shost->host_lock);
1501 case NLP_STE_UNUSED_NODE:
1502 vport->fc_unused_cnt += count;
1504 case NLP_STE_PLOGI_ISSUE:
1505 vport->fc_plogi_cnt += count;
1507 case NLP_STE_ADISC_ISSUE:
1508 vport->fc_adisc_cnt += count;
1510 case NLP_STE_REG_LOGIN_ISSUE:
1511 vport->fc_reglogin_cnt += count;
1513 case NLP_STE_PRLI_ISSUE:
1514 vport->fc_prli_cnt += count;
1516 case NLP_STE_UNMAPPED_NODE:
1517 vport->fc_unmap_cnt += count;
1519 case NLP_STE_MAPPED_NODE:
1520 vport->fc_map_cnt += count;
1522 case NLP_STE_NPR_NODE:
1523 vport->fc_npr_cnt += count;
1526 spin_unlock_irq(shost->host_lock);
1530 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1531 int old_state, int new_state)
1533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1535 if (new_state == NLP_STE_UNMAPPED_NODE) {
1536 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1537 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1538 ndlp->nlp_type |= NLP_FC_NODE;
1540 if (new_state == NLP_STE_MAPPED_NODE)
1541 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1542 if (new_state == NLP_STE_NPR_NODE)
1543 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1545 /* Transport interface */
1546 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1547 old_state == NLP_STE_UNMAPPED_NODE)) {
1548 vport->phba->nport_event_cnt++;
1549 lpfc_unregister_remote_port(ndlp);
1552 if (new_state == NLP_STE_MAPPED_NODE ||
1553 new_state == NLP_STE_UNMAPPED_NODE) {
1554 vport->phba->nport_event_cnt++;
1556 * Tell the fc transport about the port, if we haven't
1557 * already. If we have, and it's a scsi entity, be
1558 * sure to unblock any attached scsi devices
1560 lpfc_register_remote_port(vport, ndlp);
1563 * if we added to Mapped list, but the remote port
1564 * registration failed or assigned a target id outside
1565 * our presentable range - move the node to the
1568 if (new_state == NLP_STE_MAPPED_NODE &&
1570 ndlp->rport->scsi_target_id == -1 ||
1571 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1572 spin_lock_irq(shost->host_lock);
1573 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1574 spin_unlock_irq(shost->host_lock);
1575 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1580 lpfc_nlp_state_name(char *buffer, size_t size, int state)
1582 static char *states[] = {
1583 [NLP_STE_UNUSED_NODE] = "UNUSED",
1584 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1585 [NLP_STE_ADISC_ISSUE] = "ADISC",
1586 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1587 [NLP_STE_PRLI_ISSUE] = "PRLI",
1588 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1589 [NLP_STE_MAPPED_NODE] = "MAPPED",
1590 [NLP_STE_NPR_NODE] = "NPR",
1593 if (state < ARRAY_SIZE(states) && states[state])
1594 strlcpy(buffer, states[state], size);
1596 snprintf(buffer, size, "unknown (%d)", state);
1601 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1605 int old_state = ndlp->nlp_state;
1606 char name1[16], name2[16];
1608 lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
1609 "%d (%d):0904 NPort state transition x%06x, %s -> %s\n",
1610 vport->phba->brd_no, vport->vpi,
1612 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1613 lpfc_nlp_state_name(name2, sizeof(name2), state));
1615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
1616 "node statechg did:x%x old:%d ste:%d",
1617 ndlp->nlp_DID, old_state, state);
1619 if (old_state == NLP_STE_NPR_NODE &&
1620 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1621 state != NLP_STE_NPR_NODE)
1622 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1623 if (old_state == NLP_STE_UNMAPPED_NODE) {
1624 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1625 ndlp->nlp_type &= ~NLP_FC_NODE;
1628 if (list_empty(&ndlp->nlp_listp)) {
1629 spin_lock_irq(shost->host_lock);
1630 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1631 spin_unlock_irq(shost->host_lock);
1632 } else if (old_state)
1633 lpfc_nlp_counters(vport, old_state, -1);
1635 ndlp->nlp_state = state;
1636 lpfc_nlp_counters(vport, state, 1);
1637 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
1641 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1645 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1646 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1647 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1648 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1649 spin_lock_irq(shost->host_lock);
1650 list_del_init(&ndlp->nlp_listp);
1651 spin_unlock_irq(shost->host_lock);
1652 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
1653 NLP_STE_UNUSED_NODE);
1657 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1661 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1662 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1663 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1664 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1665 spin_lock_irq(shost->host_lock);
1666 list_del_init(&ndlp->nlp_listp);
1667 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
1668 spin_unlock_irq(shost->host_lock);
1673 * Start / ReStart rescue timer for Discovery / RSCN handling
1676 lpfc_set_disctmo(struct lpfc_vport *vport)
1678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1679 struct lpfc_hba *phba = vport->phba;
1682 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
1683 /* For FAN, timeout should be greater then edtov */
1684 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1686 /* Normal discovery timeout should be > then ELS/CT timeout
1687 * FC spec states we need 3 * ratov for CT requests
1689 tmo = ((phba->fc_ratov * 3) + 3);
1693 if (!timer_pending(&vport->fc_disctmo)) {
1694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1695 "set disc timer: tmo:x%x state:x%x flg:x%x",
1696 tmo, vport->port_state, vport->fc_flag);
1699 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1700 spin_lock_irq(shost->host_lock);
1701 vport->fc_flag |= FC_DISC_TMO;
1702 spin_unlock_irq(shost->host_lock);
1704 /* Start Discovery Timer state <hba_state> */
1705 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1706 "%d (%d):0247 Start Discovery Timer state x%x "
1707 "Data: x%x x%lx x%x x%x\n",
1708 phba->brd_no, vport->vpi, vport->port_state, tmo,
1709 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1710 vport->fc_adisc_cnt);
1716 * Cancel rescue timer for Discovery / RSCN handling
1719 lpfc_can_disctmo(struct lpfc_vport *vport)
1721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1722 struct lpfc_hba *phba = vport->phba;
1723 unsigned long iflags;
1725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1726 "can disc timer: state:x%x rtry:x%x flg:x%x",
1727 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1729 /* Turn off discovery timer if its running */
1730 if (vport->fc_flag & FC_DISC_TMO) {
1731 spin_lock_irqsave(shost->host_lock, iflags);
1732 vport->fc_flag &= ~FC_DISC_TMO;
1733 spin_unlock_irqrestore(shost->host_lock, iflags);
1734 del_timer_sync(&vport->fc_disctmo);
1735 spin_lock_irqsave(&vport->work_port_lock, iflags);
1736 vport->work_port_events &= ~WORKER_DISC_TMO;
1737 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
1740 /* Cancel Discovery Timer state <hba_state> */
1741 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1742 "%d (%d):0248 Cancel Discovery Timer state x%x "
1743 "Data: x%x x%x x%x\n",
1744 phba->brd_no, vport->vpi, vport->port_state,
1745 vport->fc_flag, vport->fc_plogi_cnt,
1746 vport->fc_adisc_cnt);
1752 * Check specified ring for outstanding IOCB on the SLI queue
1753 * Return true if iocb matches the specified nport
1756 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1757 struct lpfc_sli_ring *pring,
1758 struct lpfc_iocbq *iocb,
1759 struct lpfc_nodelist *ndlp)
1761 struct lpfc_sli *psli = &phba->sli;
1762 IOCB_t *icmd = &iocb->iocb;
1763 struct lpfc_vport *vport = ndlp->vport;
1765 if (iocb->vport != vport)
1768 if (pring->ringno == LPFC_ELS_RING) {
1769 switch (icmd->ulpCommand) {
1770 case CMD_GEN_REQUEST64_CR:
1771 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1773 case CMD_ELS_REQUEST64_CR:
1774 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1776 case CMD_XMIT_ELS_RSP64_CX:
1777 if (iocb->context1 == (uint8_t *) ndlp)
1780 } else if (pring->ringno == psli->extra_ring) {
1782 } else if (pring->ringno == psli->fcp_ring) {
1783 /* Skip match check if waiting to relogin to FCP target */
1784 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1785 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1788 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1791 } else if (pring->ringno == psli->next_ring) {
1798 * Free resources / clean up outstanding I/Os
1799 * associated with nlp_rpi in the LPFC_NODELIST entry.
1802 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1804 LIST_HEAD(completions);
1805 struct lpfc_sli *psli;
1806 struct lpfc_sli_ring *pring;
1807 struct lpfc_iocbq *iocb, *next_iocb;
1811 lpfc_fabric_abort_nport(ndlp);
1814 * Everything that matches on txcmplq will be returned
1815 * by firmware with a no rpi error.
1818 rpi = ndlp->nlp_rpi;
1820 /* Now process each ring */
1821 for (i = 0; i < psli->num_rings; i++) {
1822 pring = &psli->ring[i];
1824 spin_lock_irq(&phba->hbalock);
1825 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1828 * Check to see if iocb matches the nport we are
1831 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
1833 /* It matches, so deque and call compl
1835 list_move_tail(&iocb->list,
1840 spin_unlock_irq(&phba->hbalock);
1844 while (!list_empty(&completions)) {
1845 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1846 list_del_init(&iocb->list);
1848 if (!iocb->iocb_cmpl)
1849 lpfc_sli_release_iocbq(phba, iocb);
1852 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1853 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1854 (iocb->iocb_cmpl)(phba, iocb, iocb);
1862 * Free rpi associated with LPFC_NODELIST entry.
1863 * This routine is called from lpfc_freenode(), when we are removing
1864 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1865 * LOGO that completes successfully, and we are waiting to PLOGI back
1866 * to the remote NPort. In addition, it is called after we receive
1867 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1868 * we are waiting to PLOGI back to the remote NPort.
1871 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1873 struct lpfc_hba *phba = vport->phba;
1877 if (ndlp->nlp_rpi) {
1878 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1880 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
1881 mbox->vport = vport;
1882 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1883 rc = lpfc_sli_issue_mbox(phba, mbox,
1884 (MBX_NOWAIT | MBX_STOP_IOCB));
1885 if (rc == MBX_NOT_FINISHED)
1886 mempool_free(mbox, phba->mbox_mem_pool);
1888 lpfc_no_rpi(phba, ndlp);
1896 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
1898 struct lpfc_hba *phba = vport->phba;
1902 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1904 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
1905 mbox->vport = vport;
1906 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1907 rc = lpfc_sli_issue_mbox(phba, mbox,
1908 (MBX_NOWAIT | MBX_STOP_IOCB));
1909 if (rc == MBX_NOT_FINISHED) {
1910 mempool_free(mbox, phba->mbox_mem_pool);
1916 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
1918 struct lpfc_hba *phba = vport->phba;
1922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1924 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
1925 mbox->vport = vport;
1926 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1927 rc = lpfc_sli_issue_mbox(phba, mbox,
1928 (MBX_NOWAIT | MBX_STOP_IOCB));
1929 if (rc == MBX_NOT_FINISHED) {
1930 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1931 "%d (%d):1815 Could not issue "
1932 "unreg_did (default rpis)\n",
1933 phba->brd_no, vport->vpi);
1934 mempool_free(mbox, phba->mbox_mem_pool);
1940 * Free resources associated with LPFC_NODELIST entry
1941 * so it can be freed.
1944 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1947 struct lpfc_hba *phba = vport->phba;
1948 LPFC_MBOXQ_t *mb, *nextmb;
1949 struct lpfc_dmabuf *mp;
1951 /* Cleanup node for NPort <nlp_DID> */
1952 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1953 "%d (%d):0900 Cleanup node for NPort x%x "
1954 "Data: x%x x%x x%x\n",
1955 phba->brd_no, vport->vpi, ndlp->nlp_DID, ndlp->nlp_flag,
1956 ndlp->nlp_state, ndlp->nlp_rpi);
1958 lpfc_dequeue_node(vport, ndlp);
1960 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1961 if ((mb = phba->sli.mbox_active)) {
1962 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1963 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1964 mb->context2 = NULL;
1965 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1969 spin_lock_irq(&phba->hbalock);
1970 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1971 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1972 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1973 mp = (struct lpfc_dmabuf *) (mb->context1);
1975 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1978 list_del(&mb->list);
1979 mempool_free(mb, phba->mbox_mem_pool);
1983 spin_unlock_irq(&phba->hbalock);
1985 lpfc_els_abort(phba,ndlp);
1986 spin_lock_irq(shost->host_lock);
1987 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1988 spin_unlock_irq(shost->host_lock);
1990 ndlp->nlp_last_elscmd = 0;
1991 del_timer_sync(&ndlp->nlp_delayfunc);
1993 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1994 list_del_init(&ndlp->els_retry_evt.evt_listp);
1995 if (!list_empty(&ndlp->dev_loss_evt.evt_listp))
1996 list_del_init(&ndlp->dev_loss_evt.evt_listp);
1998 if (!list_empty(&ndlp->dev_loss_evt.evt_listp)) {
1999 list_del_init(&ndlp->dev_loss_evt.evt_listp);
2000 complete((struct completion *)(ndlp->dev_loss_evt.evt_arg2));
2003 lpfc_unreg_rpi(vport, ndlp);
2009 * Check to see if we can free the nlp back to the freelist.
2010 * If we are in the middle of using the nlp in the discovery state
2011 * machine, defer the free till we reach the end of the state machine.
2014 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2016 struct lpfc_rport_data *rdata;
2018 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
2019 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2022 lpfc_cleanup_node(vport, ndlp);
2025 * We can get here with a non-NULL ndlp->rport because when we
2026 * unregister a rport we don't break the rport/node linkage. So if we
2027 * do, make sure we don't leaving any dangling pointers behind.
2030 rdata = ndlp->rport->dd_data;
2031 rdata->pnode = NULL;
2037 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2040 D_ID mydid, ndlpdid, matchdid;
2042 if (did == Bcast_DID)
2045 if (ndlp->nlp_DID == 0) {
2049 /* First check for Direct match */
2050 if (ndlp->nlp_DID == did)
2053 /* Next check for area/domain identically equals 0 match */
2054 mydid.un.word = vport->fc_myDID;
2055 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
2059 matchdid.un.word = did;
2060 ndlpdid.un.word = ndlp->nlp_DID;
2061 if (matchdid.un.b.id == ndlpdid.un.b.id) {
2062 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
2063 (mydid.un.b.area == matchdid.un.b.area)) {
2064 if ((ndlpdid.un.b.domain == 0) &&
2065 (ndlpdid.un.b.area == 0)) {
2066 if (ndlpdid.un.b.id)
2072 matchdid.un.word = ndlp->nlp_DID;
2073 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
2074 (mydid.un.b.area == ndlpdid.un.b.area)) {
2075 if ((matchdid.un.b.domain == 0) &&
2076 (matchdid.un.b.area == 0)) {
2077 if (matchdid.un.b.id)
2085 /* Search for a nodelist entry */
2086 static struct lpfc_nodelist *
2087 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
2089 struct lpfc_hba *phba = vport->phba;
2090 struct lpfc_nodelist *ndlp;
2093 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2094 if (lpfc_matchdid(vport, ndlp, did)) {
2095 data1 = (((uint32_t) ndlp->nlp_state << 24) |
2096 ((uint32_t) ndlp->nlp_xri << 16) |
2097 ((uint32_t) ndlp->nlp_type << 8) |
2098 ((uint32_t) ndlp->nlp_rpi & 0xff));
2099 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
2100 "%d (%d):0929 FIND node DID "
2101 " Data: x%p x%x x%x x%x\n",
2102 phba->brd_no, vport->vpi,
2103 ndlp, ndlp->nlp_DID,
2104 ndlp->nlp_flag, data1);
2109 /* FIND node did <did> NOT FOUND */
2110 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
2111 "%d (%d):0932 FIND node did x%x NOT FOUND.\n",
2112 phba->brd_no, vport->vpi, did);
2116 struct lpfc_nodelist *
2117 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
2119 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2120 struct lpfc_nodelist *ndlp;
2122 spin_lock_irq(shost->host_lock);
2123 ndlp = __lpfc_findnode_did(vport, did);
2124 spin_unlock_irq(shost->host_lock);
2128 struct lpfc_nodelist *
2129 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
2131 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2132 struct lpfc_nodelist *ndlp;
2134 ndlp = lpfc_findnode_did(vport, did);
2136 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
2137 lpfc_rscn_payload_check(vport, did) == 0)
2139 ndlp = (struct lpfc_nodelist *)
2140 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
2143 lpfc_nlp_init(vport, ndlp, did);
2144 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2145 spin_lock_irq(shost->host_lock);
2146 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2147 spin_unlock_irq(shost->host_lock);
2150 if (vport->fc_flag & FC_RSCN_MODE) {
2151 if (lpfc_rscn_payload_check(vport, did)) {
2152 spin_lock_irq(shost->host_lock);
2153 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2154 spin_unlock_irq(shost->host_lock);
2156 /* Since this node is marked for discovery,
2157 * delay timeout is not needed.
2159 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2160 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2164 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
2165 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
2167 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2168 spin_lock_irq(shost->host_lock);
2169 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2170 spin_unlock_irq(shost->host_lock);
2175 /* Build a list of nodes to discover based on the loopmap */
2177 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
2179 struct lpfc_hba *phba = vport->phba;
2181 uint32_t alpa, index;
2183 if (!lpfc_is_link_up(phba))
2186 if (phba->fc_topology != TOPOLOGY_LOOP)
2189 /* Check for loop map present or not */
2190 if (phba->alpa_map[0]) {
2191 for (j = 1; j <= phba->alpa_map[0]; j++) {
2192 alpa = phba->alpa_map[j];
2193 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
2195 lpfc_setup_disc_node(vport, alpa);
2198 /* No alpamap, so try all alpa's */
2199 for (j = 0; j < FC_MAXLOOP; j++) {
2200 /* If cfg_scan_down is set, start from highest
2201 * ALPA (0xef) to lowest (0x1).
2203 if (phba->cfg_scan_down)
2206 index = FC_MAXLOOP - j - 1;
2207 alpa = lpfcAlpaArray[index];
2208 if ((vport->fc_myDID & 0xff) == alpa)
2210 lpfc_setup_disc_node(vport, alpa);
2217 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
2220 struct lpfc_sli *psli = &phba->sli;
2221 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
2222 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
2223 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
2227 * if it's not a physical port or if we already send
2228 * clear_la then don't send it.
2230 if ((phba->link_state >= LPFC_CLEAR_LA) ||
2231 (vport->port_type != LPFC_PHYSICAL_PORT))
2234 /* Link up discovery */
2235 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
2236 phba->link_state = LPFC_CLEAR_LA;
2237 lpfc_clear_la(phba, mbox);
2238 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2239 mbox->vport = vport;
2240 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
2242 if (rc == MBX_NOT_FINISHED) {
2243 mempool_free(mbox, phba->mbox_mem_pool);
2244 lpfc_disc_flush_list(vport);
2245 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2246 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2247 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2248 phba->link_state = LPFC_HBA_ERROR;
2253 /* Reg_vpi to tell firmware to resume normal operations */
2255 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
2257 LPFC_MBOXQ_t *regvpimbox;
2259 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2261 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
2262 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
2263 regvpimbox->vport = vport;
2264 if (lpfc_sli_issue_mbox(phba, regvpimbox,
2265 (MBX_NOWAIT | MBX_STOP_IOCB))
2266 == MBX_NOT_FINISHED) {
2267 mempool_free(regvpimbox, phba->mbox_mem_pool);
2272 /* Start Link up / RSCN discovery on NPR nodes */
2274 lpfc_disc_start(struct lpfc_vport *vport)
2276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2277 struct lpfc_hba *phba = vport->phba;
2279 uint32_t clear_la_pending;
2282 if (!lpfc_is_link_up(phba))
2285 if (phba->link_state == LPFC_CLEAR_LA)
2286 clear_la_pending = 1;
2288 clear_la_pending = 0;
2290 if (vport->port_state < LPFC_VPORT_READY)
2291 vport->port_state = LPFC_DISC_AUTH;
2293 lpfc_set_disctmo(vport);
2295 if (vport->fc_prevDID == vport->fc_myDID)
2300 vport->fc_prevDID = vport->fc_myDID;
2301 vport->num_disc_nodes = 0;
2303 /* Start Discovery state <hba_state> */
2304 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2305 "%d (%d):0202 Start Discovery hba state x%x "
2306 "Data: x%x x%x x%x\n",
2307 phba->brd_no, vport->vpi, vport->port_state,
2308 vport->fc_flag, vport->fc_plogi_cnt,
2309 vport->fc_adisc_cnt);
2311 /* First do ADISCs - if any */
2312 num_sent = lpfc_els_disc_adisc(vport);
2318 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2319 * continue discovery.
2321 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2322 !(vport->fc_flag & FC_RSCN_MODE)) {
2323 lpfc_issue_reg_vpi(phba, vport);
2328 * For SLI2, we need to set port_state to READY and continue
2331 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
2332 /* If we get here, there is nothing to ADISC */
2333 if (vport->port_type == LPFC_PHYSICAL_PORT)
2334 lpfc_issue_clear_la(phba, vport);
2336 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2337 vport->num_disc_nodes = 0;
2338 /* go thru NPR nodes and issue ELS PLOGIs */
2339 if (vport->fc_npr_cnt)
2340 lpfc_els_disc_plogi(vport);
2342 if (!vport->num_disc_nodes) {
2343 spin_lock_irq(shost->host_lock);
2344 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2345 spin_unlock_irq(shost->host_lock);
2346 lpfc_can_disctmo(vport);
2349 vport->port_state = LPFC_VPORT_READY;
2351 /* Next do PLOGIs - if any */
2352 num_sent = lpfc_els_disc_plogi(vport);
2357 if (vport->fc_flag & FC_RSCN_MODE) {
2358 /* Check to see if more RSCNs came in while we
2359 * were processing this one.
2361 if ((vport->fc_rscn_id_cnt == 0) &&
2362 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
2363 spin_lock_irq(shost->host_lock);
2364 vport->fc_flag &= ~FC_RSCN_MODE;
2365 spin_unlock_irq(shost->host_lock);
2366 lpfc_can_disctmo(vport);
2368 lpfc_els_handle_rscn(vport);
2375 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2376 * ring the match the sppecified nodelist.
2379 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
2381 LIST_HEAD(completions);
2382 struct lpfc_sli *psli;
2384 struct lpfc_iocbq *iocb, *next_iocb;
2385 struct lpfc_sli_ring *pring;
2388 pring = &psli->ring[LPFC_ELS_RING];
2390 /* Error matching iocb on txq or txcmplq
2391 * First check the txq.
2393 spin_lock_irq(&phba->hbalock);
2394 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2395 if (iocb->context1 != ndlp) {
2399 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2400 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2402 list_move_tail(&iocb->list, &completions);
2407 /* Next check the txcmplq */
2408 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2409 if (iocb->context1 != ndlp) {
2413 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
2414 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
2415 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2418 spin_unlock_irq(&phba->hbalock);
2420 while (!list_empty(&completions)) {
2421 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2422 list_del_init(&iocb->list);
2424 if (!iocb->iocb_cmpl)
2425 lpfc_sli_release_iocbq(phba, iocb);
2428 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2429 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2430 (iocb->iocb_cmpl) (phba, iocb, iocb);
2436 lpfc_disc_flush_list(struct lpfc_vport *vport)
2438 struct lpfc_nodelist *ndlp, *next_ndlp;
2439 struct lpfc_hba *phba = vport->phba;
2441 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2442 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
2444 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2445 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2446 lpfc_free_tx(phba, ndlp);
2454 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
2456 lpfc_els_flush_rscn(vport);
2457 lpfc_els_flush_cmd(vport);
2458 lpfc_disc_flush_list(vport);
2461 /*****************************************************************************/
2463 * NAME: lpfc_disc_timeout
2465 * FUNCTION: Fibre Channel driver discovery timeout routine.
2467 * EXECUTION ENVIRONMENT: interrupt only
2475 /*****************************************************************************/
2477 lpfc_disc_timeout(unsigned long ptr)
2479 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2480 struct lpfc_hba *phba = vport->phba;
2481 unsigned long flags = 0;
2483 if (unlikely(!phba))
2486 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
2487 spin_lock_irqsave(&vport->work_port_lock, flags);
2488 vport->work_port_events |= WORKER_DISC_TMO;
2489 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2491 spin_lock_irqsave(&phba->hbalock, flags);
2492 if (phba->work_wait)
2493 lpfc_worker_wake_up(phba);
2494 spin_unlock_irqrestore(&phba->hbalock, flags);
2500 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
2502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2503 struct lpfc_hba *phba = vport->phba;
2504 struct lpfc_sli *psli = &phba->sli;
2505 struct lpfc_nodelist *ndlp, *next_ndlp;
2506 LPFC_MBOXQ_t *initlinkmbox;
2507 int rc, clrlaerr = 0;
2509 if (!(vport->fc_flag & FC_DISC_TMO))
2512 spin_lock_irq(shost->host_lock);
2513 vport->fc_flag &= ~FC_DISC_TMO;
2514 spin_unlock_irq(shost->host_lock);
2516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2517 "disc timeout: state:x%x rtry:x%x flg:x%x",
2518 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
2520 switch (vport->port_state) {
2522 case LPFC_LOCAL_CFG_LINK:
2523 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2527 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
2528 "%d (%d):0221 FAN timeout\n",
2529 phba->brd_no, vport->vpi);
2531 /* Start discovery by sending FLOGI, clean up old rpis */
2532 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
2534 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2536 if (ndlp->nlp_type & NLP_FABRIC) {
2537 /* Clean up the ndlp on Fabric connections */
2538 lpfc_drop_node(vport, ndlp);
2539 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2540 /* Fail outstanding IO now since device
2541 * is marked for PLOGI.
2543 lpfc_unreg_rpi(vport, ndlp);
2546 if (vport->port_state != LPFC_FLOGI) {
2547 vport->port_state = LPFC_FLOGI;
2548 lpfc_set_disctmo(vport);
2549 lpfc_initial_flogi(vport);
2555 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2556 /* Initial FLOGI timeout */
2557 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2558 "%d (%d):0222 Initial %s timeout\n",
2559 phba->brd_no, vport->vpi,
2560 vport->vpi ? "FLOGI" : "FDISC");
2562 /* Assume no Fabric and go on with discovery.
2563 * Check for outstanding ELS FLOGI to abort.
2566 /* FLOGI failed, so just use loop map to make discovery list */
2567 lpfc_disc_list_loopmap(vport);
2569 /* Start discovery */
2570 lpfc_disc_start(vport);
2573 case LPFC_FABRIC_CFG_LINK:
2574 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2576 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2577 "%d (%d):0223 Timeout while waiting for "
2578 "NameServer login\n",
2579 phba->brd_no, vport->vpi);
2581 /* Next look for NameServer ndlp */
2582 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2585 /* Start discovery */
2586 lpfc_disc_start(vport);
2590 /* Check for wait for NameServer Rsp timeout */
2591 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2592 "%d (%d):0224 NameServer Query timeout "
2594 phba->brd_no, vport->vpi,
2595 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
2597 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2598 /* Try it one more time */
2599 vport->fc_ns_retry++;
2600 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
2601 vport->fc_ns_retry, 0);
2605 vport->fc_ns_retry = 0;
2608 * Discovery is over.
2609 * set port_state to PORT_READY if SLI2.
2610 * cmpl_reg_vpi will set port_state to READY for SLI3.
2612 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2613 lpfc_issue_reg_vpi(phba, vport);
2614 else { /* NPIV Not enabled */
2615 lpfc_issue_clear_la(phba, vport);
2616 vport->port_state = LPFC_VPORT_READY;
2619 /* Setup and issue mailbox INITIALIZE LINK command */
2620 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2621 if (!initlinkmbox) {
2622 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2623 "%d (%d):0206 Device Discovery "
2624 "completion error\n",
2625 phba->brd_no, vport->vpi);
2626 phba->link_state = LPFC_HBA_ERROR;
2630 lpfc_linkdown(phba);
2631 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2632 phba->cfg_link_speed);
2633 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2634 initlinkmbox->vport = vport;
2635 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2636 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2637 (MBX_NOWAIT | MBX_STOP_IOCB));
2638 lpfc_set_loopback_flag(phba);
2639 if (rc == MBX_NOT_FINISHED)
2640 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2644 case LPFC_DISC_AUTH:
2645 /* Node Authentication timeout */
2646 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2647 "%d (%d):0227 Node Authentication timeout\n",
2648 phba->brd_no, vport->vpi);
2649 lpfc_disc_flush_list(vport);
2652 * set port_state to PORT_READY if SLI2.
2653 * cmpl_reg_vpi will set port_state to READY for SLI3.
2655 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2656 lpfc_issue_reg_vpi(phba, vport);
2657 else { /* NPIV Not enabled */
2658 lpfc_issue_clear_la(phba, vport);
2659 vport->port_state = LPFC_VPORT_READY;
2663 case LPFC_VPORT_READY:
2664 if (vport->fc_flag & FC_RSCN_MODE) {
2665 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2666 "%d (%d):0231 RSCN timeout Data: x%x "
2668 phba->brd_no, vport->vpi,
2669 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
2671 /* Cleanup any outstanding ELS commands */
2672 lpfc_els_flush_cmd(vport);
2674 lpfc_els_flush_rscn(vport);
2675 lpfc_disc_flush_list(vport);
2680 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2681 "%d (%d):0229 Unexpected discovery timeout, "
2682 "vport State x%x\n",
2683 phba->brd_no, vport->vpi, vport->port_state);
2688 switch (phba->link_state) {
2690 /* CLEAR LA timeout */
2691 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2692 "%d (%d):0228 CLEAR LA timeout\n",
2693 phba->brd_no, vport->vpi);
2697 case LPFC_LINK_UNKNOWN:
2698 case LPFC_WARM_START:
2699 case LPFC_INIT_START:
2700 case LPFC_INIT_MBX_CMDS:
2701 case LPFC_LINK_DOWN:
2703 case LPFC_HBA_ERROR:
2704 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2705 "%d (%d):0230 Unexpected timeout, hba link "
2707 phba->brd_no, vport->vpi, phba->link_state);
2711 case LPFC_HBA_READY:
2716 lpfc_disc_flush_list(vport);
2717 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2718 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2719 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2720 vport->port_state = LPFC_VPORT_READY;
2727 * This routine handles processing a NameServer REG_LOGIN mailbox
2728 * command upon completion. It is setup in the LPFC_MBOXQ
2729 * as the completion routine when the command is
2730 * handed off to the SLI layer.
2733 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2735 MAILBOX_t *mb = &pmb->mb;
2736 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2737 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2738 struct lpfc_vport *vport = pmb->vport;
2740 pmb->context1 = NULL;
2742 ndlp->nlp_rpi = mb->un.varWords[0];
2743 ndlp->nlp_type |= NLP_FABRIC;
2744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2747 * Start issuing Fabric-Device Management Interface (FDMI) command to
2748 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2749 * fdmi-on=2 (supporting RPA/hostnmae)
2752 if (phba->cfg_fdmi_on == 1)
2753 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2755 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
2757 /* Mailbox took a reference to the node */
2759 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2761 mempool_free(pmb, phba->mbox_mem_pool);
2767 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2769 uint16_t *rpi = param;
2771 return ndlp->nlp_rpi == *rpi;
2775 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2777 return memcmp(&ndlp->nlp_portname, param,
2778 sizeof(ndlp->nlp_portname)) == 0;
2781 struct lpfc_nodelist *
2782 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
2784 struct lpfc_nodelist *ndlp;
2786 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2787 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2788 filter(ndlp, param))
2795 * Search node lists for a remote port matching filter criteria
2796 * Caller needs to hold host_lock before calling this routine.
2798 struct lpfc_nodelist *
2799 lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
2801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2802 struct lpfc_nodelist *ndlp;
2804 spin_lock_irq(shost->host_lock);
2805 ndlp = __lpfc_find_node(vport, filter, param);
2806 spin_unlock_irq(shost->host_lock);
2811 * This routine looks up the ndlp lists for the given RPI. If rpi found it
2812 * returns the node list element pointer else return NULL.
2814 struct lpfc_nodelist *
2815 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
2817 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
2820 struct lpfc_nodelist *
2821 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
2823 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2824 struct lpfc_nodelist *ndlp;
2826 spin_lock_irq(shost->host_lock);
2827 ndlp = __lpfc_findnode_rpi(vport, rpi);
2828 spin_unlock_irq(shost->host_lock);
2833 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
2834 * returns the node element list pointer else return NULL.
2836 struct lpfc_nodelist *
2837 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
2839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2840 struct lpfc_nodelist *ndlp;
2842 spin_lock_irq(shost->host_lock);
2843 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2844 spin_unlock_irq(shost->host_lock);
2849 lpfc_dev_loss_delay(unsigned long ptr)
2851 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2852 struct lpfc_vport *vport = ndlp->vport;
2853 struct lpfc_hba *phba = vport->phba;
2854 struct lpfc_work_evt *evtp = &ndlp->dev_loss_evt;
2855 unsigned long flags;
2857 evtp = &ndlp->dev_loss_evt;
2859 spin_lock_irqsave(&phba->hbalock, flags);
2860 if (!list_empty(&evtp->evt_listp)) {
2861 spin_unlock_irqrestore(&phba->hbalock, flags);
2865 evtp->evt_arg1 = ndlp;
2866 evtp->evt = LPFC_EVT_DEV_LOSS_DELAY;
2867 list_add_tail(&evtp->evt_listp, &phba->work_list);
2868 if (phba->work_wait)
2869 lpfc_worker_wake_up(phba);
2870 spin_unlock_irqrestore(&phba->hbalock, flags);
2875 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2878 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2879 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2880 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
2881 init_timer(&ndlp->nlp_delayfunc);
2882 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2883 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2884 ndlp->nlp_DID = did;
2885 ndlp->vport = vport;
2886 ndlp->nlp_sid = NLP_NO_SID;
2887 INIT_LIST_HEAD(&ndlp->nlp_listp);
2888 kref_init(&ndlp->kref);
2890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2891 "node init: did:x%x",
2892 ndlp->nlp_DID, 0, 0);
2898 lpfc_nlp_release(struct kref *kref)
2900 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2903 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
2904 "node release: did:x%x flg:x%x type:x%x",
2905 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
2907 lpfc_nlp_remove(ndlp->vport, ndlp);
2908 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
2911 struct lpfc_nodelist *
2912 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2915 kref_get(&ndlp->kref);
2920 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2922 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;