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"
40 /* AlpaArray for assignment of scsid for scan-down and bind_method */
41 static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
57 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
60 lpfc_terminate_rport_io(struct fc_rport *rport)
62 struct lpfc_rport_data *rdata;
63 struct lpfc_nodelist * ndlp;
64 struct lpfc_hba *phba;
66 rdata = rport->dd_data;
70 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
71 printk(KERN_ERR "Cannot find remote node"
72 " to terminate I/O Data x%x\n",
77 phba = ndlp->vport->phba;
79 if (ndlp->nlp_sid != NLP_NO_SID) {
80 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
81 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
88 * This function will be called when dev_loss_tmo fire.
91 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
93 struct lpfc_rport_data *rdata;
94 struct lpfc_nodelist * ndlp;
97 struct lpfc_hba *phba;
98 struct lpfc_vport *vport;
100 rdata = rport->dd_data;
104 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
105 printk(KERN_ERR "Cannot find remote node"
106 " for rport in dev_loss_tmo_callbk x%x\n",
111 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
114 name = (uint8_t *)&ndlp->nlp_portname;
118 if (ndlp->nlp_sid != NLP_NO_SID) {
120 /* flush the target */
121 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
122 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
124 if (vport->load_flag & FC_UNLOADING)
128 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
129 "%d:0203 Devloss timeout on "
130 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
131 "NPort x%x Data: x%x x%x x%x\n",
133 *name, *(name+1), *(name+2), *(name+3),
134 *(name+4), *(name+5), *(name+6), *(name+7),
135 ndlp->nlp_DID, ndlp->nlp_flag,
136 ndlp->nlp_state, ndlp->nlp_rpi);
138 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
139 "%d:0204 Devloss timeout on "
140 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
141 "NPort x%x Data: x%x x%x x%x\n",
143 *name, *(name+1), *(name+2), *(name+3),
144 *(name+4), *(name+5), *(name+6), *(name+7),
145 ndlp->nlp_DID, ndlp->nlp_flag,
146 ndlp->nlp_state, ndlp->nlp_rpi);
149 if (!(vport->load_flag & FC_UNLOADING) &&
150 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
151 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
152 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
153 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
158 put_device(&rport->dev);
165 lpfc_work_list_done(struct lpfc_hba *phba)
167 struct lpfc_work_evt *evtp = NULL;
168 struct lpfc_nodelist *ndlp;
171 spin_lock_irq(&phba->hbalock);
172 while (!list_empty(&phba->work_list)) {
173 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
175 spin_unlock_irq(&phba->hbalock);
178 case LPFC_EVT_ELS_RETRY:
179 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
180 lpfc_els_retry_delay_handler(ndlp);
183 case LPFC_EVT_ONLINE:
184 if (phba->link_state < LPFC_LINK_DOWN)
185 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
187 *(int *) (evtp->evt_arg1) = 0;
188 complete((struct completion *)(evtp->evt_arg2));
190 case LPFC_EVT_OFFLINE_PREP:
191 if (phba->link_state >= LPFC_LINK_DOWN)
192 lpfc_offline_prep(phba);
193 *(int *)(evtp->evt_arg1) = 0;
194 complete((struct completion *)(evtp->evt_arg2));
196 case LPFC_EVT_OFFLINE:
198 lpfc_sli_brdrestart(phba);
199 *(int *)(evtp->evt_arg1) =
200 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
201 lpfc_unblock_mgmt_io(phba);
202 complete((struct completion *)(evtp->evt_arg2));
204 case LPFC_EVT_WARM_START:
206 lpfc_reset_barrier(phba);
207 lpfc_sli_brdreset(phba);
208 lpfc_hba_down_post(phba);
209 *(int *)(evtp->evt_arg1) =
210 lpfc_sli_brdready(phba, HS_MBRDY);
211 lpfc_unblock_mgmt_io(phba);
212 complete((struct completion *)(evtp->evt_arg2));
216 *(int *)(evtp->evt_arg1)
217 = (phba->pport->stopped)
218 ? 0 : lpfc_sli_brdkill(phba);
219 lpfc_unblock_mgmt_io(phba);
220 complete((struct completion *)(evtp->evt_arg2));
225 spin_lock_irq(&phba->hbalock);
227 spin_unlock_irq(&phba->hbalock);
232 lpfc_work_done(struct lpfc_hba *phba)
234 struct lpfc_sli_ring *pring;
235 uint32_t ha_copy, control, work_port_events;
236 struct lpfc_vport *vport;
239 spin_lock_irq(&phba->hbalock);
240 ha_copy = phba->work_ha;
242 spin_unlock_irq(&phba->hbalock);
244 if (ha_copy & HA_ERATT)
245 lpfc_handle_eratt(phba);
247 if (ha_copy & HA_MBATT)
248 lpfc_sli_handle_mb_event(phba);
250 if (ha_copy & HA_LATT)
251 lpfc_handle_latt(phba);
255 work_port_events = vport->work_port_events;
257 if (work_port_events & WORKER_DISC_TMO)
258 lpfc_disc_timeout_handler(vport);
260 if (work_port_events & WORKER_ELS_TMO)
261 lpfc_els_timeout_handler(vport);
263 if (work_port_events & WORKER_MBOX_TMO)
264 lpfc_mbox_timeout_handler(phba);
266 if (work_port_events & WORKER_FDMI_TMO)
267 lpfc_fdmi_timeout_handler(vport);
269 spin_lock_irq(&phba->hbalock);
270 vport->work_port_events &= ~work_port_events;
271 spin_unlock_irq(&phba->hbalock);
273 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
274 pring = &phba->sli.ring[i];
275 if ((ha_copy & HA_RXATT)
276 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
277 if (pring->flag & LPFC_STOP_IOCB_MASK) {
278 pring->flag |= LPFC_DEFERRED_RING_EVENT;
280 lpfc_sli_handle_slow_ring_event(phba, pring,
283 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
286 * Turn on Ring interrupts
288 spin_lock_irq(&phba->hbalock);
289 control = readl(phba->HCregaddr);
290 control |= (HC_R0INT_ENA << i);
291 writel(control, phba->HCregaddr);
292 readl(phba->HCregaddr); /* flush */
293 spin_unlock_irq(&phba->hbalock);
297 lpfc_work_list_done(phba);
301 check_work_wait_done(struct lpfc_hba *phba)
303 struct lpfc_vport *vport = phba->pport;
309 spin_lock_irq(&phba->hbalock);
312 vport->work_port_events ||
313 (!list_empty(&phba->work_list)) ||
314 kthread_should_stop())
317 spin_unlock_irq(&phba->hbalock);
322 lpfc_do_work(void *p)
324 struct lpfc_hba *phba = p;
326 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
328 set_user_nice(current, -20);
329 phba->work_wait = &work_waitq;
333 rc = wait_event_interruptible(work_waitq,
334 check_work_wait_done(phba));
337 if (kthread_should_stop())
340 lpfc_work_done(phba);
343 phba->work_wait = NULL;
348 * This is only called to handle FC worker events. Since this a rare
349 * occurance, we allocate a struct lpfc_work_evt structure here instead of
350 * embedding it in the IOCB.
353 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
356 struct lpfc_work_evt *evtp;
360 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
361 * be queued to worker thread for processing
363 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
367 evtp->evt_arg1 = arg1;
368 evtp->evt_arg2 = arg2;
371 spin_lock_irqsave(&phba->hbalock, flags);
372 list_add_tail(&evtp->evt_listp, &phba->work_list);
374 wake_up(phba->work_wait);
375 spin_unlock_irqrestore(&phba->hbalock, flags);
381 lpfc_linkdown(struct lpfc_hba *phba)
383 struct lpfc_vport *vport = phba->pport;
384 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
385 struct lpfc_sli *psli;
386 struct lpfc_nodelist *ndlp, *next_ndlp;
391 if (phba->link_state == LPFC_LINK_DOWN) {
394 spin_lock_irq(&phba->hbalock);
395 if (phba->link_state > LPFC_LINK_DOWN)
396 phba->link_state = LPFC_LINK_DOWN;
397 spin_unlock_irq(&phba->hbalock);
399 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
401 /* Clean up any firmware default rpi's */
402 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404 lpfc_unreg_did(phba, 0xffffffff, mb);
406 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
407 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
408 == MBX_NOT_FINISHED) {
409 mempool_free(mb, phba->mbox_mem_pool);
413 /* Cleanup any outstanding RSCN activity */
414 lpfc_els_flush_rscn(vport);
416 /* Cleanup any outstanding ELS commands */
417 lpfc_els_flush_cmd(vport);
420 * Issue a LINK DOWN event to all nodes.
422 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
423 /* free any ndlp's on unused state */
424 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
425 lpfc_drop_node(vport, ndlp);
426 else /* otherwise, force node recovery. */
427 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
428 NLP_EVT_DEVICE_RECOVERY);
431 /* Setup myDID for link up if we are in pt2pt mode */
432 if (vport->fc_flag & FC_PT2PT) {
434 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
436 lpfc_config_link(phba, mb);
437 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
439 if (lpfc_sli_issue_mbox(phba, mb,
440 (MBX_NOWAIT | MBX_STOP_IOCB))
441 == MBX_NOT_FINISHED) {
442 mempool_free(mb, phba->mbox_mem_pool);
445 spin_lock_irq(shost->host_lock);
446 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
447 spin_unlock_irq(shost->host_lock);
450 spin_lock_irq(shost->host_lock);
451 vport->fc_flag &= ~FC_LBIT;
452 spin_unlock_irq(shost->host_lock);
454 /* Turn off discovery timer if its running */
455 lpfc_can_disctmo(vport);
457 /* Must process IOCBs on all rings to handle ABORTed I/Os */
462 lpfc_linkup(struct lpfc_hba *phba)
464 struct lpfc_vport *vport = phba->pport;
465 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
466 struct lpfc_nodelist *ndlp, *next_ndlp;
468 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
470 spin_lock_irq(shost->host_lock);
471 phba->link_state = LPFC_LINK_UP;
472 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
473 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
474 vport->fc_flag |= FC_NDISC_ACTIVE;
475 vport->fc_ns_retry = 0;
476 spin_unlock_irq(shost->host_lock);
479 if (vport->fc_flag & FC_LBIT) {
480 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
481 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE) {
482 if (ndlp->nlp_type & NLP_FABRIC) {
484 * On Linkup its safe to clean up the
485 * ndlp from Fabric connections.
487 lpfc_nlp_set_state(vport, ndlp,
488 NLP_STE_UNUSED_NODE);
489 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
491 * Fail outstanding IO now since
492 * device is marked for PLOGI.
494 lpfc_unreg_rpi(vport, ndlp);
500 /* free any ndlp's in unused state */
501 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
503 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
504 lpfc_drop_node(vport, ndlp);
511 * This routine handles processing a CLEAR_LA mailbox
512 * command upon completion. It is setup in the LPFC_MBOXQ
513 * as the completion routine when the command is
514 * handed off to the SLI layer.
517 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
519 struct lpfc_vport *vport = pmb->vport;
520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
521 struct lpfc_sli *psli = &phba->sli;
522 MAILBOX_t *mb = &pmb->mb;
525 /* Since we don't do discovery right now, turn these off here */
526 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
527 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
528 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
530 /* Check for error */
531 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
532 /* CLEAR_LA mbox error <mbxStatus> state <port_state> */
533 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
534 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
536 phba->brd_no, mb->mbxStatus, vport->port_state);
538 phba->link_state = LPFC_HBA_ERROR;
542 if (vport->fc_flag & FC_ABORT_DISCOVERY)
545 vport->num_disc_nodes = 0;
546 /* go thru NPR nodes and issue ELS PLOGIs */
547 if (vport->fc_npr_cnt)
548 lpfc_els_disc_plogi(vport);
550 if (!vport->num_disc_nodes) {
551 spin_lock_irq(shost->host_lock);
552 vport->fc_flag &= ~FC_NDISC_ACTIVE;
553 spin_unlock_irq(shost->host_lock);
556 vport->port_state = LPFC_VPORT_READY;
559 /* Device Discovery completes */
560 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
561 "%d:0225 Device Discovery completes\n",
564 mempool_free(pmb, phba->mbox_mem_pool);
566 spin_lock_irq(shost->host_lock);
567 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
568 spin_unlock_irq(shost->host_lock);
570 del_timer_sync(&phba->fc_estabtmo);
572 lpfc_can_disctmo(vport);
574 /* turn on Link Attention interrupts */
576 spin_lock_irq(&phba->hbalock);
577 psli->sli_flag |= LPFC_PROCESS_LA;
578 control = readl(phba->HCregaddr);
579 control |= HC_LAINT_ENA;
580 writel(control, phba->HCregaddr);
581 readl(phba->HCregaddr); /* flush */
582 spin_unlock_irq(&phba->hbalock);
589 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
591 struct lpfc_vport *vport = pmb->vport;
592 struct lpfc_sli *psli = &phba->sli;
595 if (pmb->mb.mbxStatus)
598 mempool_free(pmb, phba->mbox_mem_pool);
600 if (phba->fc_topology == TOPOLOGY_LOOP &&
601 vport->fc_flag & FC_PUBLIC_LOOP &&
602 !(vport->fc_flag & FC_LBIT)) {
603 /* Need to wait for FAN - use discovery timer
604 * for timeout. port_state is identically
605 * LPFC_LOCAL_CFG_LINK while waiting for FAN
607 lpfc_set_disctmo(vport);
611 /* Start discovery by sending a FLOGI. port_state is identically
612 * LPFC_FLOGI while waiting for FLOGI cmpl
614 vport->port_state = LPFC_FLOGI;
615 lpfc_set_disctmo(vport);
616 lpfc_initial_flogi(vport);
620 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
621 "%d:0306 CONFIG_LINK mbxStatus error x%x "
623 phba->brd_no, pmb->mb.mbxStatus, vport->port_state);
627 phba->link_state = LPFC_HBA_ERROR;
629 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
630 "%d:0200 CONFIG_LINK bad hba state x%x\n",
631 phba->brd_no, vport->port_state);
633 lpfc_clear_la(phba, pmb);
634 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
636 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
637 if (rc == MBX_NOT_FINISHED) {
638 mempool_free(pmb, phba->mbox_mem_pool);
639 lpfc_disc_flush_list(vport);
640 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
641 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
642 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
643 vport->port_state = LPFC_VPORT_READY;
649 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
651 struct lpfc_sli *psli = &phba->sli;
652 MAILBOX_t *mb = &pmb->mb;
653 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
654 struct lpfc_vport *vport = pmb->vport;
657 /* Check for error */
659 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
660 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
661 "%d:0319 READ_SPARAM mbxStatus error x%x "
663 phba->brd_no, mb->mbxStatus, vport->port_state);
666 phba->link_state = LPFC_HBA_ERROR;
670 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
671 sizeof (struct serv_parm));
672 if (phba->cfg_soft_wwnn)
673 u64_to_wwn(phba->cfg_soft_wwnn,
674 vport->fc_sparam.nodeName.u.wwn);
675 if (phba->cfg_soft_wwpn)
676 u64_to_wwn(phba->cfg_soft_wwpn,
677 vport->fc_sparam.portName.u.wwn);
678 memcpy((uint8_t *) &vport->fc_nodename,
679 (uint8_t *) &vport->fc_sparam.nodeName,
680 sizeof (struct lpfc_name));
681 memcpy((uint8_t *) &vport->fc_portname,
682 (uint8_t *) &vport->fc_sparam.portName,
683 sizeof (struct lpfc_name));
684 lpfc_mbuf_free(phba, mp->virt, mp->phys);
686 mempool_free(pmb, phba->mbox_mem_pool);
690 pmb->context1 = NULL;
691 lpfc_mbuf_free(phba, mp->virt, mp->phys);
693 if (phba->link_state != LPFC_CLEAR_LA) {
694 struct lpfc_sli_ring *extra_ring =
695 &psli->ring[psli->extra_ring];
696 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
697 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
699 lpfc_clear_la(phba, pmb);
700 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
702 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
703 == MBX_NOT_FINISHED) {
704 mempool_free(pmb, phba->mbox_mem_pool);
705 lpfc_disc_flush_list(vport);
706 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
707 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
708 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
709 vport->port_state = LPFC_VPORT_READY;
712 mempool_free(pmb, phba->mbox_mem_pool);
718 lpfc_mbx_process_link_up(struct lpfc_vport *vport, READ_LA_VAR *la)
720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
721 struct lpfc_hba *phba = vport->phba;
722 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
724 struct lpfc_dmabuf *mp;
727 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
728 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
730 spin_lock_irq(shost->host_lock);
731 switch (la->UlnkSpeed) {
733 phba->fc_linkspeed = LA_1GHZ_LINK;
736 phba->fc_linkspeed = LA_2GHZ_LINK;
739 phba->fc_linkspeed = LA_4GHZ_LINK;
742 phba->fc_linkspeed = LA_8GHZ_LINK;
745 phba->fc_linkspeed = LA_UNKNW_LINK;
749 phba->fc_topology = la->topology;
751 if (phba->fc_topology == TOPOLOGY_LOOP) {
752 /* Get Loop Map information */
755 vport->fc_flag |= FC_LBIT;
757 vport->fc_myDID = la->granted_AL_PA;
758 i = la->un.lilpBde64.tus.f.bdeSize;
761 phba->alpa_map[0] = 0;
763 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
774 numalpa = phba->alpa_map[0];
776 while (j < numalpa) {
777 memset(un.pamap, 0, 16);
778 for (k = 1; j < numalpa; k++) {
780 phba->alpa_map[j + 1];
785 /* Link Up Event ALPA map */
786 lpfc_printf_log(phba,
789 "%d:1304 Link Up Event "
790 "ALPA map Data: x%x "
793 un.pa.wd1, un.pa.wd2,
794 un.pa.wd3, un.pa.wd4);
799 vport->fc_myDID = phba->fc_pref_DID;
800 vport->fc_flag |= FC_LBIT;
802 spin_unlock_irq(shost->host_lock);
806 lpfc_read_sparam(phba, sparam_mbox);
807 sparam_mbox->vport = vport;
808 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
809 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
810 (MBX_NOWAIT | MBX_STOP_IOCB));
811 if (rc == MBX_NOT_FINISHED) {
812 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
813 lpfc_mbuf_free(phba, mp->virt, mp->phys);
815 mempool_free(sparam_mbox, phba->mbox_mem_pool);
817 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
823 vport->port_state = LPFC_LOCAL_CFG_LINK;
824 lpfc_config_link(phba, cfglink_mbox);
825 cfglink_mbox->vport = vport;
826 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
827 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
828 (MBX_NOWAIT | MBX_STOP_IOCB));
829 if (rc == MBX_NOT_FINISHED)
830 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
835 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
838 struct lpfc_sli *psli = &phba->sli;
842 /* turn on Link Attention interrupts - no CLEAR_LA needed */
843 spin_lock_irq(&phba->hbalock);
844 psli->sli_flag |= LPFC_PROCESS_LA;
845 control = readl(phba->HCregaddr);
846 control |= HC_LAINT_ENA;
847 writel(control, phba->HCregaddr);
848 readl(phba->HCregaddr); /* flush */
849 spin_unlock_irq(&phba->hbalock);
853 * This routine handles processing a READ_LA mailbox
854 * command upon completion. It is setup in the LPFC_MBOXQ
855 * as the completion routine when the command is
856 * handed off to the SLI layer.
859 lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
861 struct lpfc_vport *vport = pmb->vport;
862 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
864 MAILBOX_t *mb = &pmb->mb;
865 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
867 /* Check for error */
869 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
870 "%d:1307 READ_LA mbox error x%x state x%x\n",
871 phba->brd_no, mb->mbxStatus, vport->port_state);
872 lpfc_mbx_issue_link_down(phba);
873 phba->link_state = LPFC_HBA_ERROR;
874 goto lpfc_mbx_cmpl_read_la_free_mbuf;
877 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
879 memcpy(&phba->alpa_map[0], mp->virt, 128);
881 spin_lock_irq(shost->host_lock);
883 vport->fc_flag |= FC_BYPASSED_MODE;
885 vport->fc_flag &= ~FC_BYPASSED_MODE;
886 spin_unlock_irq(shost->host_lock);
888 if (((phba->fc_eventTag + 1) < la->eventTag) ||
889 (phba->fc_eventTag == la->eventTag)) {
890 phba->fc_stat.LinkMultiEvent++;
891 if (la->attType == AT_LINK_UP)
892 if (phba->fc_eventTag != 0)
896 phba->fc_eventTag = la->eventTag;
898 if (la->attType == AT_LINK_UP) {
899 phba->fc_stat.LinkUp++;
900 if (phba->link_flag & LS_LOOPBACK_MODE) {
901 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
902 "%d:1306 Link Up Event in loop back mode "
903 "x%x received Data: x%x x%x x%x x%x\n",
904 phba->brd_no, la->eventTag, phba->fc_eventTag,
905 la->granted_AL_PA, la->UlnkSpeed,
908 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
909 "%d:1303 Link Up Event x%x received "
910 "Data: x%x x%x x%x x%x\n",
911 phba->brd_no, la->eventTag, phba->fc_eventTag,
912 la->granted_AL_PA, la->UlnkSpeed,
915 lpfc_mbx_process_link_up(vport, la);
917 phba->fc_stat.LinkDown++;
918 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
919 "%d:1305 Link Down Event x%x received "
920 "Data: x%x x%x x%x\n",
921 phba->brd_no, la->eventTag, phba->fc_eventTag,
922 phba->pport->port_state, vport->fc_flag);
923 lpfc_mbx_issue_link_down(phba);
926 lpfc_mbx_cmpl_read_la_free_mbuf:
927 lpfc_mbuf_free(phba, mp->virt, mp->phys);
929 mempool_free(pmb, phba->mbox_mem_pool);
934 * This routine handles processing a REG_LOGIN mailbox
935 * command upon completion. It is setup in the LPFC_MBOXQ
936 * as the completion routine when the command is
937 * handed off to the SLI layer.
940 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
942 struct lpfc_vport *vport = pmb->vport;
943 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
944 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
946 pmb->context1 = NULL;
948 /* Good status, call state machine */
949 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
950 lpfc_mbuf_free(phba, mp->virt, mp->phys);
952 mempool_free(pmb, phba->mbox_mem_pool);
959 * This routine handles processing a Fabric REG_LOGIN mailbox
960 * command upon completion. It is setup in the LPFC_MBOXQ
961 * as the completion routine when the command is
962 * handed off to the SLI layer.
965 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
967 struct lpfc_vport *vport = pmb->vport;
968 MAILBOX_t *mb = &pmb->mb;
969 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
970 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
971 ndlp = (struct lpfc_nodelist *) pmb->context2;
973 pmb->context1 = NULL;
974 pmb->context2 = NULL;
977 lpfc_mbuf_free(phba, mp->virt, mp->phys);
979 mempool_free(pmb, phba->mbox_mem_pool);
982 /* FLOGI failed, so just use loop map to make discovery list */
983 lpfc_disc_list_loopmap(vport);
985 /* Start discovery */
986 lpfc_disc_start(vport);
990 ndlp->nlp_rpi = mb->un.varWords[0];
991 ndlp->nlp_type |= NLP_FABRIC;
992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
994 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
996 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
997 /* This NPort has been assigned an NPort_ID by the fabric as a
998 * result of the completed fabric login. Issue a State Change
999 * Registration (SCR) ELS request to the fabric controller
1000 * (SCR_DID) so that this NPort gets RSCN events from the
1003 lpfc_issue_els_scr(vport, SCR_DID, 0);
1005 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1007 /* Allocate a new node instance. If the pool is empty,
1008 * start the discovery process and skip the Nameserver
1009 * login process. This is attempted again later on.
1010 * Otherwise, issue a Port Login (PLOGI) to
1013 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1015 lpfc_disc_start(vport);
1016 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1018 mempool_free(pmb, phba->mbox_mem_pool);
1021 lpfc_nlp_init(vport, ndlp, NameServer_DID);
1022 ndlp->nlp_type |= NLP_FABRIC;
1026 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1027 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
1028 if (phba->cfg_fdmi_on) {
1029 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1032 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
1033 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1034 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
1035 lpfc_issue_els_plogi(vport, FDMI_DID, 0);
1040 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1042 mempool_free(pmb, phba->mbox_mem_pool);
1047 * This routine handles processing a NameServer REG_LOGIN mailbox
1048 * command upon completion. It is setup in the LPFC_MBOXQ
1049 * as the completion routine when the command is
1050 * handed off to the SLI layer.
1053 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1055 MAILBOX_t *mb = &pmb->mb;
1056 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1057 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1058 struct lpfc_vport *vport = pmb->vport;
1060 if (mb->mbxStatus) {
1062 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1064 mempool_free(pmb, phba->mbox_mem_pool);
1065 lpfc_drop_node(vport, ndlp);
1068 * RegLogin failed, so just use loop map to make discovery
1071 lpfc_disc_list_loopmap(vport);
1073 /* Start discovery */
1074 lpfc_disc_start(vport);
1078 pmb->context1 = NULL;
1080 ndlp->nlp_rpi = mb->un.varWords[0];
1081 ndlp->nlp_type |= NLP_FABRIC;
1082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1084 if (vport->port_state < LPFC_VPORT_READY) {
1085 /* Link up discovery requires Fabric registration. */
1086 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RNN_ID);
1087 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RSNN_NN);
1088 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RFT_ID);
1089 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RFF_ID);
1092 vport->fc_ns_retry = 0;
1093 /* Good status, issue CT Request to NameServer */
1094 if (lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT)) {
1095 /* Cannot issue NameServer Query, so finish up discovery */
1096 lpfc_disc_start(vport);
1100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1102 mempool_free(pmb, phba->mbox_mem_pool);
1108 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1111 struct fc_rport *rport;
1112 struct lpfc_rport_data *rdata;
1113 struct fc_rport_identifiers rport_ids;
1114 struct lpfc_hba *phba = vport->phba;
1116 /* Remote port has reappeared. Re-register w/ FC transport */
1117 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1118 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1119 rport_ids.port_id = ndlp->nlp_DID;
1120 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1123 * We leave our node pointer in rport->dd_data when we unregister a
1124 * FCP target port. But fc_remote_port_add zeros the space to which
1125 * rport->dd_data points. So, if we're reusing a previously
1126 * registered port, drop the reference that we took the last time we
1127 * registered the port.
1129 if (ndlp->rport && ndlp->rport->dd_data &&
1130 *(struct lpfc_rport_data **) ndlp->rport->dd_data) {
1133 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
1134 if (!rport || !get_device(&rport->dev)) {
1135 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1136 "Warning: fc_remote_port_add failed\n");
1140 /* initialize static port data */
1141 rport->maxframe_size = ndlp->nlp_maxframe;
1142 rport->supported_classes = ndlp->nlp_class_sup;
1143 rdata = rport->dd_data;
1144 rdata->pnode = lpfc_nlp_get(ndlp);
1146 if (ndlp->nlp_type & NLP_FCP_TARGET)
1147 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1148 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1149 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1152 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1153 fc_remote_port_rolechg(rport, rport_ids.roles);
1155 if ((rport->scsi_target_id != -1) &&
1156 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1157 ndlp->nlp_sid = rport->scsi_target_id;
1164 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
1166 struct fc_rport *rport = ndlp->rport;
1167 struct lpfc_rport_data *rdata = rport->dd_data;
1169 if (rport->scsi_target_id == -1) {
1171 rdata->pnode = NULL;
1173 put_device(&rport->dev);
1176 fc_remote_port_delete(rport);
1182 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
1184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1186 spin_lock_irq(shost->host_lock);
1188 case NLP_STE_UNUSED_NODE:
1189 vport->fc_unused_cnt += count;
1191 case NLP_STE_PLOGI_ISSUE:
1192 vport->fc_plogi_cnt += count;
1194 case NLP_STE_ADISC_ISSUE:
1195 vport->fc_adisc_cnt += count;
1197 case NLP_STE_REG_LOGIN_ISSUE:
1198 vport->fc_reglogin_cnt += count;
1200 case NLP_STE_PRLI_ISSUE:
1201 vport->fc_prli_cnt += count;
1203 case NLP_STE_UNMAPPED_NODE:
1204 vport->fc_unmap_cnt += count;
1206 case NLP_STE_MAPPED_NODE:
1207 vport->fc_map_cnt += count;
1209 case NLP_STE_NPR_NODE:
1210 vport->fc_npr_cnt += count;
1213 spin_unlock_irq(shost->host_lock);
1217 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1218 int old_state, int new_state)
1220 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1222 if (new_state == NLP_STE_UNMAPPED_NODE) {
1223 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1224 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1225 ndlp->nlp_type |= NLP_FC_NODE;
1227 if (new_state == NLP_STE_MAPPED_NODE)
1228 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1229 if (new_state == NLP_STE_NPR_NODE)
1230 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1232 /* Transport interface */
1233 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1234 old_state == NLP_STE_UNMAPPED_NODE)) {
1235 vport->phba->nport_event_cnt++;
1236 lpfc_unregister_remote_port(ndlp);
1239 if (new_state == NLP_STE_MAPPED_NODE ||
1240 new_state == NLP_STE_UNMAPPED_NODE) {
1241 vport->phba->nport_event_cnt++;
1243 * Tell the fc transport about the port, if we haven't
1244 * already. If we have, and it's a scsi entity, be
1245 * sure to unblock any attached scsi devices
1247 lpfc_register_remote_port(vport, ndlp);
1251 * if we added to Mapped list, but the remote port
1252 * registration failed or assigned a target id outside
1253 * our presentable range - move the node to the
1256 if (new_state == NLP_STE_MAPPED_NODE &&
1258 ndlp->rport->scsi_target_id == -1 ||
1259 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1260 spin_lock_irq(shost->host_lock);
1261 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1262 spin_unlock_irq(shost->host_lock);
1263 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1268 lpfc_nlp_state_name(char *buffer, size_t size, int state)
1270 static char *states[] = {
1271 [NLP_STE_UNUSED_NODE] = "UNUSED",
1272 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1273 [NLP_STE_ADISC_ISSUE] = "ADISC",
1274 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1275 [NLP_STE_PRLI_ISSUE] = "PRLI",
1276 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1277 [NLP_STE_MAPPED_NODE] = "MAPPED",
1278 [NLP_STE_NPR_NODE] = "NPR",
1281 if (state < ARRAY_SIZE(states) && states[state])
1282 strlcpy(buffer, states[state], size);
1284 snprintf(buffer, size, "unknown (%d)", state);
1289 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1293 int old_state = ndlp->nlp_state;
1294 char name1[16], name2[16];
1296 lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
1297 "%d:0904 NPort state transition x%06x, %s -> %s\n",
1298 vport->phba->brd_no,
1300 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1301 lpfc_nlp_state_name(name2, sizeof(name2), state));
1302 if (old_state == NLP_STE_NPR_NODE &&
1303 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1304 state != NLP_STE_NPR_NODE)
1305 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1306 if (old_state == NLP_STE_UNMAPPED_NODE) {
1307 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1308 ndlp->nlp_type &= ~NLP_FC_NODE;
1311 if (list_empty(&ndlp->nlp_listp)) {
1312 spin_lock_irq(shost->host_lock);
1313 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1314 spin_unlock_irq(shost->host_lock);
1315 } else if (old_state)
1316 lpfc_nlp_counters(vport, old_state, -1);
1318 ndlp->nlp_state = state;
1319 lpfc_nlp_counters(vport, state, 1);
1320 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
1324 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1328 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1329 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1330 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1331 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1332 spin_lock_irq(shost->host_lock);
1333 list_del_init(&ndlp->nlp_listp);
1334 spin_unlock_irq(shost->host_lock);
1335 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, 0);
1339 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1341 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1343 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1344 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1345 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1346 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1347 spin_lock_irq(shost->host_lock);
1348 list_del_init(&ndlp->nlp_listp);
1349 spin_unlock_irq(shost->host_lock);
1354 * Start / ReStart rescue timer for Discovery / RSCN handling
1357 lpfc_set_disctmo(struct lpfc_vport *vport)
1359 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1360 struct lpfc_hba *phba = vport->phba;
1363 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
1364 /* For FAN, timeout should be greater then edtov */
1365 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1367 /* Normal discovery timeout should be > then ELS/CT timeout
1368 * FC spec states we need 3 * ratov for CT requests
1370 tmo = ((phba->fc_ratov * 3) + 3);
1373 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1374 spin_lock_irq(shost->host_lock);
1375 vport->fc_flag |= FC_DISC_TMO;
1376 spin_unlock_irq(shost->host_lock);
1378 /* Start Discovery Timer state <hba_state> */
1379 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1380 "%d:0247 Start Discovery Timer state x%x "
1381 "Data: x%x x%lx x%x x%x\n",
1382 phba->brd_no, vport->port_state, tmo,
1383 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1384 vport->fc_adisc_cnt);
1390 * Cancel rescue timer for Discovery / RSCN handling
1393 lpfc_can_disctmo(struct lpfc_vport *vport)
1395 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1396 struct lpfc_hba *phba = vport->phba;
1397 unsigned long iflags;
1399 /* Turn off discovery timer if its running */
1400 if (vport->fc_flag & FC_DISC_TMO) {
1401 spin_lock_irqsave(shost->host_lock, iflags);
1402 vport->fc_flag &= ~FC_DISC_TMO;
1403 spin_unlock_irqrestore(shost->host_lock, iflags);
1404 del_timer_sync(&vport->fc_disctmo);
1405 spin_lock_irqsave(&vport->work_port_lock, iflags);
1406 vport->work_port_events &= ~WORKER_DISC_TMO;
1407 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
1410 /* Cancel Discovery Timer state <hba_state> */
1411 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1412 "%d:0248 Cancel Discovery Timer state x%x "
1413 "Data: x%x x%x x%x\n",
1414 phba->brd_no, vport->port_state, vport->fc_flag,
1415 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
1421 * Check specified ring for outstanding IOCB on the SLI queue
1422 * Return true if iocb matches the specified nport
1425 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1426 struct lpfc_sli_ring *pring,
1427 struct lpfc_iocbq *iocb,
1428 struct lpfc_nodelist *ndlp)
1430 struct lpfc_sli *psli = &phba->sli;
1431 IOCB_t *icmd = &iocb->iocb;
1432 if (pring->ringno == LPFC_ELS_RING) {
1433 switch (icmd->ulpCommand) {
1434 case CMD_GEN_REQUEST64_CR:
1435 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1437 case CMD_ELS_REQUEST64_CR:
1438 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1440 case CMD_XMIT_ELS_RSP64_CX:
1441 if (iocb->context1 == (uint8_t *) ndlp)
1444 } else if (pring->ringno == psli->extra_ring) {
1446 } else if (pring->ringno == psli->fcp_ring) {
1447 /* Skip match check if waiting to relogin to FCP target */
1448 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1449 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1452 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1455 } else if (pring->ringno == psli->next_ring) {
1462 * Free resources / clean up outstanding I/Os
1463 * associated with nlp_rpi in the LPFC_NODELIST entry.
1466 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1468 LIST_HEAD(completions);
1469 struct lpfc_sli *psli;
1470 struct lpfc_sli_ring *pring;
1471 struct lpfc_iocbq *iocb, *next_iocb;
1476 * Everything that matches on txcmplq will be returned
1477 * by firmware with a no rpi error.
1480 rpi = ndlp->nlp_rpi;
1482 /* Now process each ring */
1483 for (i = 0; i < psli->num_rings; i++) {
1484 pring = &psli->ring[i];
1486 spin_lock_irq(&phba->hbalock);
1487 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1490 * Check to see if iocb matches the nport we are
1493 if ((lpfc_check_sli_ndlp
1494 (phba, pring, iocb, ndlp))) {
1495 /* It matches, so deque and call compl
1497 list_move_tail(&iocb->list,
1502 spin_unlock_irq(&phba->hbalock);
1506 while (!list_empty(&completions)) {
1507 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1508 list_del(&iocb->list);
1510 if (!iocb->iocb_cmpl)
1511 lpfc_sli_release_iocbq(phba, iocb);
1514 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1515 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1516 (iocb->iocb_cmpl)(phba, iocb, iocb);
1524 * Free rpi associated with LPFC_NODELIST entry.
1525 * This routine is called from lpfc_freenode(), when we are removing
1526 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1527 * LOGO that completes successfully, and we are waiting to PLOGI back
1528 * to the remote NPort. In addition, it is called after we receive
1529 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1530 * we are waiting to PLOGI back to the remote NPort.
1533 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1535 struct lpfc_hba *phba = vport->phba;
1539 if (ndlp->nlp_rpi) {
1540 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1542 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1543 mbox->vport = vport;
1544 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1545 rc = lpfc_sli_issue_mbox
1546 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1547 if (rc == MBX_NOT_FINISHED)
1548 mempool_free(mbox, phba->mbox_mem_pool);
1550 lpfc_no_rpi(phba, ndlp);
1558 * Free resources associated with LPFC_NODELIST entry
1559 * so it can be freed.
1562 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1565 struct lpfc_hba *phba = vport->phba;
1566 LPFC_MBOXQ_t *mb, *nextmb;
1567 struct lpfc_dmabuf *mp;
1569 /* Cleanup node for NPort <nlp_DID> */
1570 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1571 "%d:0900 Cleanup node for NPort x%x "
1572 "Data: x%x x%x x%x\n",
1573 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1574 ndlp->nlp_state, ndlp->nlp_rpi);
1576 lpfc_dequeue_node(vport, ndlp);
1578 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1579 if ((mb = phba->sli.mbox_active)) {
1580 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1581 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1582 mb->context2 = NULL;
1583 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1587 spin_lock_irq(&phba->hbalock);
1588 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1589 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1590 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1591 mp = (struct lpfc_dmabuf *) (mb->context1);
1593 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1596 list_del(&mb->list);
1597 mempool_free(mb, phba->mbox_mem_pool);
1601 spin_unlock_irq(&phba->hbalock);
1603 lpfc_els_abort(phba,ndlp);
1604 spin_lock_irq(shost->host_lock);
1605 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1606 spin_unlock_irq(shost->host_lock);
1608 ndlp->nlp_last_elscmd = 0;
1609 del_timer_sync(&ndlp->nlp_delayfunc);
1611 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1612 list_del_init(&ndlp->els_retry_evt.evt_listp);
1614 lpfc_unreg_rpi(vport, ndlp);
1620 * Check to see if we can free the nlp back to the freelist.
1621 * If we are in the middle of using the nlp in the discovery state
1622 * machine, defer the free till we reach the end of the state machine.
1625 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1627 struct lpfc_rport_data *rdata;
1629 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1630 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1633 lpfc_cleanup_node(vport, ndlp);
1636 * We should never get here with a non-NULL ndlp->rport. But
1637 * if we do, drop the reference to the rport. That seems the
1638 * intelligent thing to do.
1640 if (ndlp->rport && !(vport->load_flag & FC_UNLOADING)) {
1641 put_device(&ndlp->rport->dev);
1642 rdata = ndlp->rport->dd_data;
1643 rdata->pnode = NULL;
1649 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1652 D_ID mydid, ndlpdid, matchdid;
1654 if (did == Bcast_DID)
1657 if (ndlp->nlp_DID == 0) {
1661 /* First check for Direct match */
1662 if (ndlp->nlp_DID == did)
1665 /* Next check for area/domain identically equals 0 match */
1666 mydid.un.word = vport->fc_myDID;
1667 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1671 matchdid.un.word = did;
1672 ndlpdid.un.word = ndlp->nlp_DID;
1673 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1674 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1675 (mydid.un.b.area == matchdid.un.b.area)) {
1676 if ((ndlpdid.un.b.domain == 0) &&
1677 (ndlpdid.un.b.area == 0)) {
1678 if (ndlpdid.un.b.id)
1684 matchdid.un.word = ndlp->nlp_DID;
1685 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1686 (mydid.un.b.area == ndlpdid.un.b.area)) {
1687 if ((matchdid.un.b.domain == 0) &&
1688 (matchdid.un.b.area == 0)) {
1689 if (matchdid.un.b.id)
1697 /* Search for a nodelist entry */
1698 static struct lpfc_nodelist *
1699 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
1701 struct lpfc_hba *phba = vport->phba;
1702 struct lpfc_nodelist *ndlp;
1705 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1706 if (lpfc_matchdid(vport, ndlp, did)) {
1707 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1708 ((uint32_t) ndlp->nlp_xri << 16) |
1709 ((uint32_t) ndlp->nlp_type << 8) |
1710 ((uint32_t) ndlp->nlp_rpi & 0xff));
1711 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1712 "%d:0929 FIND node DID "
1713 " Data: x%p x%x x%x x%x\n",
1715 ndlp, ndlp->nlp_DID,
1716 ndlp->nlp_flag, data1);
1721 /* FIND node did <did> NOT FOUND */
1722 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1723 "%d:0932 FIND node did x%x NOT FOUND.\n",
1728 struct lpfc_nodelist *
1729 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
1731 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1732 struct lpfc_nodelist *ndlp;
1734 spin_lock_irq(shost->host_lock);
1735 ndlp = __lpfc_findnode_did(vport, did);
1736 spin_unlock_irq(shost->host_lock);
1740 struct lpfc_nodelist *
1741 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
1743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1744 struct lpfc_nodelist *ndlp;
1746 ndlp = lpfc_findnode_did(vport, did);
1748 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
1749 lpfc_rscn_payload_check(vport, did) == 0)
1751 ndlp = (struct lpfc_nodelist *)
1752 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
1755 lpfc_nlp_init(vport, ndlp, did);
1756 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1757 spin_lock_irq(shost->host_lock);
1758 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1759 spin_unlock_irq(shost->host_lock);
1762 if (vport->fc_flag & FC_RSCN_MODE) {
1763 if (lpfc_rscn_payload_check(vport, did)) {
1764 spin_lock_irq(shost->host_lock);
1765 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1766 spin_unlock_irq(shost->host_lock);
1768 /* Since this node is marked for discovery,
1769 * delay timeout is not needed.
1771 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1772 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1776 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
1777 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
1779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1780 spin_lock_irq(shost->host_lock);
1781 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1782 spin_unlock_irq(shost->host_lock);
1787 /* Build a list of nodes to discover based on the loopmap */
1789 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
1791 struct lpfc_hba *phba = vport->phba;
1793 uint32_t alpa, index;
1795 if (!lpfc_is_link_up(phba))
1798 if (phba->fc_topology != TOPOLOGY_LOOP)
1801 /* Check for loop map present or not */
1802 if (phba->alpa_map[0]) {
1803 for (j = 1; j <= phba->alpa_map[0]; j++) {
1804 alpa = phba->alpa_map[j];
1805 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
1807 lpfc_setup_disc_node(vport, alpa);
1810 /* No alpamap, so try all alpa's */
1811 for (j = 0; j < FC_MAXLOOP; j++) {
1812 /* If cfg_scan_down is set, start from highest
1813 * ALPA (0xef) to lowest (0x1).
1815 if (phba->cfg_scan_down)
1818 index = FC_MAXLOOP - j - 1;
1819 alpa = lpfcAlpaArray[index];
1820 if ((vport->fc_myDID & 0xff) == alpa)
1822 lpfc_setup_disc_node(vport, alpa);
1829 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
1832 struct lpfc_sli *psli = &phba->sli;
1833 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
1834 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
1835 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
1838 /* Link up discovery */
1839 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
1840 phba->link_state = LPFC_CLEAR_LA;
1841 lpfc_clear_la(phba, mbox);
1842 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1843 mbox->vport = vport;
1844 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
1846 if (rc == MBX_NOT_FINISHED) {
1847 mempool_free(mbox, phba->mbox_mem_pool);
1848 lpfc_disc_flush_list(vport);
1849 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1850 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1851 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1852 vport->port_state = LPFC_VPORT_READY;
1857 /* Start Link up / RSCN discovery on NPR nodes */
1859 lpfc_disc_start(struct lpfc_vport *vport)
1861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1862 struct lpfc_hba *phba = vport->phba;
1863 struct lpfc_nodelist *ndlp, *next_ndlp;
1865 uint32_t clear_la_pending;
1868 if (!lpfc_is_link_up(phba))
1871 if (phba->link_state == LPFC_CLEAR_LA)
1872 clear_la_pending = 1;
1874 clear_la_pending = 0;
1876 if (vport->port_state < LPFC_VPORT_READY)
1877 vport->port_state = LPFC_DISC_AUTH;
1879 lpfc_set_disctmo(vport);
1881 if (vport->fc_prevDID == vport->fc_myDID)
1886 vport->fc_prevDID = vport->fc_myDID;
1887 vport->num_disc_nodes = 0;
1889 /* Start Discovery state <hba_state> */
1890 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1891 "%d:0202 Start Discovery hba state x%x "
1892 "Data: x%x x%x x%x\n",
1893 phba->brd_no, vport->port_state, vport->fc_flag,
1894 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
1896 /* If our did changed, we MUST do PLOGI */
1897 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1898 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
1899 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
1901 spin_lock_irq(shost->host_lock);
1902 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1903 spin_unlock_irq(shost->host_lock);
1907 /* First do ADISCs - if any */
1908 num_sent = lpfc_els_disc_adisc(vport);
1913 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
1914 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1915 /* If we get here, there is nothing to ADISC */
1916 lpfc_issue_clear_la(phba, vport);
1917 } else if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1919 vport->num_disc_nodes = 0;
1920 /* go thru NPR nodes and issue ELS PLOGIs */
1921 if (vport->fc_npr_cnt)
1922 lpfc_els_disc_plogi(vport);
1924 if (!vport->num_disc_nodes) {
1925 spin_lock_irq(shost->host_lock);
1926 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1927 spin_unlock_irq(shost->host_lock);
1929 vport->port_state = LPFC_VPORT_READY;
1932 /* Next do PLOGIs - if any */
1933 num_sent = lpfc_els_disc_plogi(vport);
1938 if (vport->fc_flag & FC_RSCN_MODE) {
1939 /* Check to see if more RSCNs came in while we
1940 * were processing this one.
1942 if ((vport->fc_rscn_id_cnt == 0) &&
1943 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1944 spin_lock_irq(shost->host_lock);
1945 vport->fc_flag &= ~FC_RSCN_MODE;
1946 spin_unlock_irq(shost->host_lock);
1948 lpfc_els_handle_rscn(vport);
1955 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
1956 * ring the match the sppecified nodelist.
1959 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1961 LIST_HEAD(completions);
1962 struct lpfc_sli *psli;
1964 struct lpfc_iocbq *iocb, *next_iocb;
1965 struct lpfc_sli_ring *pring;
1968 pring = &psli->ring[LPFC_ELS_RING];
1970 /* Error matching iocb on txq or txcmplq
1971 * First check the txq.
1973 spin_lock_irq(&phba->hbalock);
1974 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1975 if (iocb->context1 != ndlp) {
1979 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
1980 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
1982 list_move_tail(&iocb->list, &completions);
1987 /* Next check the txcmplq */
1988 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1989 if (iocb->context1 != ndlp) {
1993 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
1994 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
1995 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1998 spin_unlock_irq(&phba->hbalock);
2000 while (!list_empty(&completions)) {
2001 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2002 list_del(&iocb->list);
2004 if (!iocb->iocb_cmpl)
2005 lpfc_sli_release_iocbq(phba, iocb);
2008 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2009 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2010 (iocb->iocb_cmpl) (phba, iocb, iocb);
2016 lpfc_disc_flush_list(struct lpfc_vport *vport)
2018 struct lpfc_nodelist *ndlp, *next_ndlp;
2019 struct lpfc_hba *phba = vport->phba;
2021 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2022 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
2024 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2025 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2026 lpfc_free_tx(phba, ndlp);
2033 /*****************************************************************************/
2035 * NAME: lpfc_disc_timeout
2037 * FUNCTION: Fibre Channel driver discovery timeout routine.
2039 * EXECUTION ENVIRONMENT: interrupt only
2047 /*****************************************************************************/
2049 lpfc_disc_timeout(unsigned long ptr)
2051 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2052 struct lpfc_hba *phba = vport->phba;
2053 unsigned long flags = 0;
2055 if (unlikely(!phba))
2058 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
2059 spin_lock_irqsave(&vport->work_port_lock, flags);
2060 vport->work_port_events |= WORKER_DISC_TMO;
2061 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2063 if (phba->work_wait)
2064 wake_up(phba->work_wait);
2070 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
2072 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2073 struct lpfc_hba *phba = vport->phba;
2074 struct lpfc_sli *psli = &phba->sli;
2075 struct lpfc_nodelist *ndlp, *next_ndlp;
2076 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2077 int rc, clrlaerr = 0;
2079 if (!(vport->fc_flag & FC_DISC_TMO))
2082 spin_lock_irq(shost->host_lock);
2083 vport->fc_flag &= ~FC_DISC_TMO;
2084 spin_unlock_irq(shost->host_lock);
2086 switch (vport->port_state) {
2088 case LPFC_LOCAL_CFG_LINK:
2089 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2093 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
2094 "%d:0221 FAN timeout\n",
2097 /* Start discovery by sending FLOGI, clean up old rpis */
2098 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
2100 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2102 if (ndlp->nlp_type & NLP_FABRIC) {
2103 /* Clean up the ndlp on Fabric connections */
2104 lpfc_drop_node(vport, ndlp);
2105 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2106 /* Fail outstanding IO now since device
2107 * is marked for PLOGI.
2109 lpfc_unreg_rpi(vport, ndlp);
2112 vport->port_state = LPFC_FLOGI;
2113 lpfc_set_disctmo(vport);
2114 lpfc_initial_flogi(vport);
2118 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2119 /* Initial FLOGI timeout */
2120 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2121 "%d:0222 Initial FLOGI timeout\n",
2124 /* Assume no Fabric and go on with discovery.
2125 * Check for outstanding ELS FLOGI to abort.
2128 /* FLOGI failed, so just use loop map to make discovery list */
2129 lpfc_disc_list_loopmap(vport);
2131 /* Start discovery */
2132 lpfc_disc_start(vport);
2135 case LPFC_FABRIC_CFG_LINK:
2136 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2138 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2139 "%d:0223 Timeout while waiting for NameServer "
2140 "login\n", phba->brd_no);
2142 /* Next look for NameServer ndlp */
2143 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2146 /* Start discovery */
2147 lpfc_disc_start(vport);
2151 /* Check for wait for NameServer Rsp timeout */
2152 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2153 "%d:0224 NameServer Query timeout "
2156 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
2158 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2159 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2160 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2161 /* Try it one more time */
2162 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
2166 vport->fc_ns_retry = 0;
2169 /* Nothing to authenticate, so CLEAR_LA right now */
2170 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2173 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2174 "%d:0226 Device Discovery "
2175 "completion error\n",
2177 phba->link_state = LPFC_HBA_ERROR;
2181 phba->link_state = LPFC_CLEAR_LA;
2182 lpfc_clear_la(phba, clearlambox);
2183 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2184 clearlambox->vport = vport;
2185 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2186 (MBX_NOWAIT | MBX_STOP_IOCB));
2187 if (rc == MBX_NOT_FINISHED) {
2188 mempool_free(clearlambox, phba->mbox_mem_pool);
2193 /* Setup and issue mailbox INITIALIZE LINK command */
2194 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2195 if (!initlinkmbox) {
2196 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2197 "%d:0206 Device Discovery "
2198 "completion error\n",
2200 phba->link_state = LPFC_HBA_ERROR;
2204 lpfc_linkdown(phba);
2205 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2206 phba->cfg_link_speed);
2207 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2208 initlinkmbox->vport = vport;
2209 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2210 (MBX_NOWAIT | MBX_STOP_IOCB));
2211 lpfc_set_loopback_flag(phba);
2212 if (rc == MBX_NOT_FINISHED)
2213 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2217 case LPFC_DISC_AUTH:
2218 /* Node Authentication timeout */
2219 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2220 "%d:0227 Node Authentication timeout\n",
2222 lpfc_disc_flush_list(vport);
2224 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2227 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2228 "%d:0207 Device Discovery "
2229 "completion error\n",
2231 phba->link_state = LPFC_HBA_ERROR;
2234 phba->link_state = LPFC_CLEAR_LA;
2235 lpfc_clear_la(phba, clearlambox);
2236 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2237 clearlambox->vport = vport;
2238 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2239 (MBX_NOWAIT | MBX_STOP_IOCB));
2240 if (rc == MBX_NOT_FINISHED) {
2241 mempool_free(clearlambox, phba->mbox_mem_pool);
2246 case LPFC_VPORT_READY:
2247 if (vport->fc_flag & FC_RSCN_MODE) {
2248 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2249 "%d:0231 RSCN timeout Data: x%x x%x\n",
2251 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
2253 /* Cleanup any outstanding ELS commands */
2254 lpfc_els_flush_cmd(vport);
2256 lpfc_els_flush_rscn(vport);
2257 lpfc_disc_flush_list(vport);
2261 case LPFC_STATE_UNKNOWN:
2263 case LPFC_BUILD_DISC_LIST:
2264 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2265 "%d:0229 Unexpected discovery timeout, vport "
2267 vport->port_state, phba->brd_no);
2272 switch (phba->link_state) {
2274 /* CLEAR LA timeout */
2275 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2276 "%d:0228 CLEAR LA timeout\n",
2281 case LPFC_LINK_UNKNOWN:
2282 case LPFC_WARM_START:
2283 case LPFC_INIT_START:
2284 case LPFC_INIT_MBX_CMDS:
2285 case LPFC_LINK_DOWN:
2287 case LPFC_HBA_ERROR:
2288 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2289 "%d:0230 Unexpected timeout, hba link "
2291 phba->brd_no, phba->link_state);
2297 lpfc_disc_flush_list(vport);
2298 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2299 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2300 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2301 vport->port_state = LPFC_VPORT_READY;
2308 * This routine handles processing a NameServer REG_LOGIN mailbox
2309 * command upon completion. It is setup in the LPFC_MBOXQ
2310 * as the completion routine when the command is
2311 * handed off to the SLI layer.
2314 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2316 MAILBOX_t *mb = &pmb->mb;
2317 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2318 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2319 struct lpfc_vport *vport = pmb->vport;
2321 pmb->context1 = NULL;
2323 ndlp->nlp_rpi = mb->un.varWords[0];
2324 ndlp->nlp_type |= NLP_FABRIC;
2325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2328 * Start issuing Fabric-Device Management Interface (FDMI) command to
2329 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2330 * fdmi-on=2 (supporting RPA/hostnmae)
2333 if (phba->cfg_fdmi_on == 1)
2334 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2336 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
2338 /* Mailbox took a reference to the node */
2340 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2342 mempool_free(pmb, phba->mbox_mem_pool);
2348 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2350 uint16_t *rpi = param;
2352 return ndlp->nlp_rpi == *rpi;
2356 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2358 return memcmp(&ndlp->nlp_portname, param,
2359 sizeof(ndlp->nlp_portname)) == 0;
2362 struct lpfc_nodelist *
2363 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
2365 struct lpfc_nodelist *ndlp;
2367 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2368 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2369 filter(ndlp, param))
2376 * Search node lists for a remote port matching filter criteria
2377 * This routine is used when the caller does NOT have host_lock.
2379 struct lpfc_nodelist *
2380 lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
2382 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2383 struct lpfc_nodelist *ndlp;
2385 spin_lock_irq(shost->host_lock);
2386 ndlp = __lpfc_find_node(vport, filter, param);
2387 spin_unlock_irq(shost->host_lock);
2392 * This routine looks up the ndlp lists for the given RPI. If rpi found it
2393 * returns the node list element pointer else return NULL.
2395 struct lpfc_nodelist *
2396 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
2398 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
2401 struct lpfc_nodelist *
2402 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
2404 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2405 struct lpfc_nodelist *ndlp;
2407 spin_lock_irq(shost->host_lock);
2408 ndlp = __lpfc_findnode_rpi(vport, rpi);
2409 spin_unlock_irq(shost->host_lock);
2414 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
2415 * returns the node element list pointer else return NULL.
2417 struct lpfc_nodelist *
2418 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
2420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2421 struct lpfc_nodelist *ndlp;
2423 spin_lock_irq(shost->host_lock);
2424 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2425 spin_unlock_irq(shost->host_lock);
2430 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2433 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2434 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2435 init_timer(&ndlp->nlp_delayfunc);
2436 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2437 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2438 ndlp->nlp_DID = did;
2439 ndlp->vport = vport;
2440 ndlp->nlp_sid = NLP_NO_SID;
2441 INIT_LIST_HEAD(&ndlp->nlp_listp);
2442 kref_init(&ndlp->kref);
2447 lpfc_nlp_release(struct kref *kref)
2449 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2451 lpfc_nlp_remove(ndlp->vport, ndlp);
2452 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
2455 struct lpfc_nodelist *
2456 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2459 kref_get(&ndlp->kref);
2464 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2466 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;