1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
40 /* AlpaArray for assignment of scsid for scan-down and bind_method */
41 static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
57 static void lpfc_disc_timeout_handler(struct lpfc_hba *);
60 lpfc_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->nlp_phba;
79 spin_lock_irq(phba->host->host_lock);
80 if (ndlp->nlp_sid != NLP_NO_SID) {
81 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
82 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
84 spin_unlock_irq(phba->host->host_lock);
90 * This function will be called when dev_loss_tmo fire.
93 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist * ndlp;
99 struct lpfc_hba *phba;
101 rdata = rport->dd_data;
105 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
106 printk(KERN_ERR "Cannot find remote node"
107 " for rport in dev_loss_tmo_callbk x%x\n",
112 name = (uint8_t *)&ndlp->nlp_portname;
113 phba = ndlp->nlp_phba;
115 spin_lock_irq(phba->host->host_lock);
117 if (ndlp->nlp_sid != NLP_NO_SID) {
119 /* flush the target */
120 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
121 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
123 if (phba->fc_flag & FC_UNLOADING)
126 spin_unlock_irq(phba->host->host_lock);
129 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
130 "%d:0203 Devloss timeout on "
131 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
132 "NPort x%x Data: x%x x%x x%x\n",
134 *name, *(name+1), *(name+2), *(name+3),
135 *(name+4), *(name+5), *(name+6), *(name+7),
136 ndlp->nlp_DID, ndlp->nlp_flag,
137 ndlp->nlp_state, ndlp->nlp_rpi);
139 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
140 "%d:0204 Devloss timeout on "
141 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
142 "NPort x%x Data: x%x x%x x%x\n",
144 *name, *(name+1), *(name+2), *(name+3),
145 *(name+4), *(name+5), *(name+6), *(name+7),
146 ndlp->nlp_DID, ndlp->nlp_flag,
147 ndlp->nlp_state, ndlp->nlp_rpi);
153 if (!(phba->fc_flag & FC_UNLOADING))
154 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
160 lpfc_work_list_done(struct lpfc_hba * phba)
162 struct lpfc_work_evt *evtp = NULL;
163 struct lpfc_nodelist *ndlp;
166 spin_lock_irq(phba->host->host_lock);
167 while(!list_empty(&phba->work_list)) {
168 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
170 spin_unlock_irq(phba->host->host_lock);
173 case LPFC_EVT_ELS_RETRY:
174 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
175 lpfc_els_retry_delay_handler(ndlp);
178 case LPFC_EVT_ONLINE:
179 if (phba->hba_state < LPFC_LINK_DOWN)
180 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
182 *(int *)(evtp->evt_arg1) = 0;
183 complete((struct completion *)(evtp->evt_arg2));
185 case LPFC_EVT_OFFLINE:
186 if (phba->hba_state >= LPFC_LINK_DOWN)
188 lpfc_sli_brdrestart(phba);
189 *(int *)(evtp->evt_arg1) =
190 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
191 complete((struct completion *)(evtp->evt_arg2));
193 case LPFC_EVT_WARM_START:
194 if (phba->hba_state >= LPFC_LINK_DOWN)
196 lpfc_reset_barrier(phba);
197 lpfc_sli_brdreset(phba);
198 lpfc_hba_down_post(phba);
199 *(int *)(evtp->evt_arg1) =
200 lpfc_sli_brdready(phba, HS_MBRDY);
201 complete((struct completion *)(evtp->evt_arg2));
204 if (phba->hba_state >= LPFC_LINK_DOWN)
206 *(int *)(evtp->evt_arg1)
207 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
208 complete((struct completion *)(evtp->evt_arg2));
213 spin_lock_irq(phba->host->host_lock);
215 spin_unlock_irq(phba->host->host_lock);
220 lpfc_work_done(struct lpfc_hba * phba)
222 struct lpfc_sli_ring *pring;
226 uint32_t work_hba_events;
228 spin_lock_irq(phba->host->host_lock);
229 ha_copy = phba->work_ha;
231 work_hba_events=phba->work_hba_events;
232 spin_unlock_irq(phba->host->host_lock);
234 if (ha_copy & HA_ERATT)
235 lpfc_handle_eratt(phba);
237 if (ha_copy & HA_MBATT)
238 lpfc_sli_handle_mb_event(phba);
240 if (ha_copy & HA_LATT)
241 lpfc_handle_latt(phba);
243 if (work_hba_events & WORKER_DISC_TMO)
244 lpfc_disc_timeout_handler(phba);
246 if (work_hba_events & WORKER_ELS_TMO)
247 lpfc_els_timeout_handler(phba);
249 if (work_hba_events & WORKER_MBOX_TMO)
250 lpfc_mbox_timeout_handler(phba);
252 if (work_hba_events & WORKER_FDMI_TMO)
253 lpfc_fdmi_tmo_handler(phba);
255 spin_lock_irq(phba->host->host_lock);
256 phba->work_hba_events &= ~work_hba_events;
257 spin_unlock_irq(phba->host->host_lock);
259 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
260 pring = &phba->sli.ring[i];
261 if ((ha_copy & HA_RXATT)
262 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
263 if (pring->flag & LPFC_STOP_IOCB_MASK) {
264 pring->flag |= LPFC_DEFERRED_RING_EVENT;
266 lpfc_sli_handle_slow_ring_event(phba, pring,
269 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
272 * Turn on Ring interrupts
274 spin_lock_irq(phba->host->host_lock);
275 control = readl(phba->HCregaddr);
276 control |= (HC_R0INT_ENA << i);
277 writel(control, phba->HCregaddr);
278 readl(phba->HCregaddr); /* flush */
279 spin_unlock_irq(phba->host->host_lock);
283 lpfc_work_list_done (phba);
288 check_work_wait_done(struct lpfc_hba *phba) {
290 spin_lock_irq(phba->host->host_lock);
292 phba->work_hba_events ||
293 (!list_empty(&phba->work_list)) ||
294 kthread_should_stop()) {
295 spin_unlock_irq(phba->host->host_lock);
298 spin_unlock_irq(phba->host->host_lock);
304 lpfc_do_work(void *p)
306 struct lpfc_hba *phba = p;
308 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
310 set_user_nice(current, -20);
311 phba->work_wait = &work_waitq;
315 rc = wait_event_interruptible(work_waitq,
316 check_work_wait_done(phba));
319 if (kthread_should_stop())
322 lpfc_work_done(phba);
325 phba->work_wait = NULL;
330 * This is only called to handle FC worker events. Since this a rare
331 * occurance, we allocate a struct lpfc_work_evt structure here instead of
332 * embedding it in the IOCB.
335 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
338 struct lpfc_work_evt *evtp;
341 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
342 * be queued to worker thread for processing
344 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
348 evtp->evt_arg1 = arg1;
349 evtp->evt_arg2 = arg2;
352 spin_lock_irq(phba->host->host_lock);
353 list_add_tail(&evtp->evt_listp, &phba->work_list);
355 wake_up(phba->work_wait);
356 spin_unlock_irq(phba->host->host_lock);
362 lpfc_linkdown(struct lpfc_hba * phba)
364 struct lpfc_sli *psli;
365 struct lpfc_nodelist *ndlp, *next_ndlp;
366 struct list_head *listp, *node_list[7];
371 /* sysfs or selective reset may call this routine to clean up */
372 if (phba->hba_state >= LPFC_LINK_DOWN) {
373 if (phba->hba_state == LPFC_LINK_DOWN)
376 spin_lock_irq(phba->host->host_lock);
377 phba->hba_state = LPFC_LINK_DOWN;
378 spin_unlock_irq(phba->host->host_lock);
381 fc_host_post_event(phba->host, fc_get_event_number(),
382 FCH_EVT_LINKDOWN, 0);
384 /* Clean up any firmware default rpi's */
385 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
386 lpfc_unreg_did(phba, 0xffffffff, mb);
387 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
388 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
389 == MBX_NOT_FINISHED) {
390 mempool_free( mb, phba->mbox_mem_pool);
394 /* Cleanup any outstanding RSCN activity */
395 lpfc_els_flush_rscn(phba);
397 /* Cleanup any outstanding ELS commands */
398 lpfc_els_flush_cmd(phba);
400 /* Issue a LINK DOWN event to all nodes */
401 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
402 node_list[1] = &phba->fc_nlpmap_list;
403 node_list[2] = &phba->fc_nlpunmap_list;
404 node_list[3] = &phba->fc_prli_list;
405 node_list[4] = &phba->fc_reglogin_list;
406 node_list[5] = &phba->fc_adisc_list;
407 node_list[6] = &phba->fc_plogi_list;
408 for (i = 0; i < 7; i++) {
409 listp = node_list[i];
410 if (list_empty(listp))
413 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
415 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
416 NLP_EVT_DEVICE_RECOVERY);
421 /* free any ndlp's on unused list */
422 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
424 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
427 /* Setup myDID for link up if we are in pt2pt mode */
428 if (phba->fc_flag & FC_PT2PT) {
430 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
431 lpfc_config_link(phba, mb);
432 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
433 if (lpfc_sli_issue_mbox
434 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
435 == MBX_NOT_FINISHED) {
436 mempool_free( mb, phba->mbox_mem_pool);
439 spin_lock_irq(phba->host->host_lock);
440 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
441 spin_unlock_irq(phba->host->host_lock);
443 spin_lock_irq(phba->host->host_lock);
444 phba->fc_flag &= ~FC_LBIT;
445 spin_unlock_irq(phba->host->host_lock);
447 /* Turn off discovery timer if its running */
448 lpfc_can_disctmo(phba);
450 /* Must process IOCBs on all rings to handle ABORTed I/Os */
455 lpfc_linkup(struct lpfc_hba * phba)
457 struct lpfc_nodelist *ndlp, *next_ndlp;
458 struct list_head *listp, *node_list[7];
461 fc_host_post_event(phba->host, fc_get_event_number(),
464 spin_lock_irq(phba->host->host_lock);
465 phba->hba_state = LPFC_LINK_UP;
466 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
467 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
468 phba->fc_flag |= FC_NDISC_ACTIVE;
469 phba->fc_ns_retry = 0;
470 spin_unlock_irq(phba->host->host_lock);
473 node_list[0] = &phba->fc_plogi_list;
474 node_list[1] = &phba->fc_adisc_list;
475 node_list[2] = &phba->fc_reglogin_list;
476 node_list[3] = &phba->fc_prli_list;
477 node_list[4] = &phba->fc_nlpunmap_list;
478 node_list[5] = &phba->fc_nlpmap_list;
479 node_list[6] = &phba->fc_npr_list;
480 for (i = 0; i < 7; i++) {
481 listp = node_list[i];
482 if (list_empty(listp))
485 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
486 if (phba->fc_flag & FC_LBIT) {
487 if (ndlp->nlp_type & NLP_FABRIC) {
488 /* On Linkup its safe to clean up the
489 * ndlp from Fabric connections.
491 lpfc_nlp_list(phba, ndlp,
493 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
494 /* Fail outstanding IO now since device
495 * is marked for PLOGI.
497 lpfc_unreg_rpi(phba, ndlp);
503 /* free any ndlp's on unused list */
504 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
506 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
513 * This routine handles processing a CLEAR_LA mailbox
514 * command upon completion. It is setup in the LPFC_MBOXQ
515 * as the completion routine when the command is
516 * handed off to the SLI layer.
519 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
521 struct lpfc_sli *psli;
527 /* Since we don't do discovery right now, turn these off here */
528 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
529 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
530 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
532 /* Check for error */
533 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
534 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
535 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
536 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
538 phba->brd_no, mb->mbxStatus, phba->hba_state);
540 phba->hba_state = LPFC_HBA_ERROR;
544 if (phba->fc_flag & FC_ABORT_DISCOVERY)
547 phba->num_disc_nodes = 0;
548 /* go thru NPR list and issue ELS PLOGIs */
549 if (phba->fc_npr_cnt) {
550 lpfc_els_disc_plogi(phba);
553 if (!phba->num_disc_nodes) {
554 spin_lock_irq(phba->host->host_lock);
555 phba->fc_flag &= ~FC_NDISC_ACTIVE;
556 spin_unlock_irq(phba->host->host_lock);
559 phba->hba_state = LPFC_HBA_READY;
562 /* Device Discovery completes */
563 lpfc_printf_log(phba,
566 "%d:0225 Device Discovery completes\n",
569 mempool_free( pmb, phba->mbox_mem_pool);
571 spin_lock_irq(phba->host->host_lock);
572 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
573 if (phba->fc_flag & FC_ESTABLISH_LINK) {
574 phba->fc_flag &= ~FC_ESTABLISH_LINK;
576 spin_unlock_irq(phba->host->host_lock);
578 del_timer_sync(&phba->fc_estabtmo);
580 lpfc_can_disctmo(phba);
582 /* turn on Link Attention interrupts */
583 spin_lock_irq(phba->host->host_lock);
584 psli->sli_flag |= LPFC_PROCESS_LA;
585 control = readl(phba->HCregaddr);
586 control |= HC_LAINT_ENA;
587 writel(control, phba->HCregaddr);
588 readl(phba->HCregaddr); /* flush */
589 spin_unlock_irq(phba->host->host_lock);
595 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
597 struct lpfc_sli *psli = &phba->sli;
600 if (pmb->mb.mbxStatus)
603 mempool_free(pmb, phba->mbox_mem_pool);
605 if (phba->fc_topology == TOPOLOGY_LOOP &&
606 phba->fc_flag & FC_PUBLIC_LOOP &&
607 !(phba->fc_flag & FC_LBIT)) {
608 /* Need to wait for FAN - use discovery timer
609 * for timeout. hba_state is identically
610 * LPFC_LOCAL_CFG_LINK while waiting for FAN
612 lpfc_set_disctmo(phba);
616 /* Start discovery by sending a FLOGI. hba_state is identically
617 * LPFC_FLOGI while waiting for FLOGI cmpl
619 phba->hba_state = LPFC_FLOGI;
620 lpfc_set_disctmo(phba);
621 lpfc_initial_flogi(phba);
625 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
626 "%d:0306 CONFIG_LINK mbxStatus error x%x "
628 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
632 phba->hba_state = LPFC_HBA_ERROR;
634 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
635 "%d:0200 CONFIG_LINK bad hba state x%x\n",
636 phba->brd_no, phba->hba_state);
638 lpfc_clear_la(phba, pmb);
639 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
640 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
641 if (rc == MBX_NOT_FINISHED) {
642 mempool_free(pmb, phba->mbox_mem_pool);
643 lpfc_disc_flush_list(phba);
644 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
645 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
646 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
647 phba->hba_state = LPFC_HBA_READY;
653 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
655 struct lpfc_sli *psli = &phba->sli;
656 MAILBOX_t *mb = &pmb->mb;
657 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
660 /* Check for error */
662 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
663 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
664 "%d:0319 READ_SPARAM mbxStatus error x%x "
666 phba->brd_no, mb->mbxStatus, phba->hba_state);
669 phba->hba_state = LPFC_HBA_ERROR;
673 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
674 sizeof (struct serv_parm));
675 if (phba->cfg_soft_wwpn)
676 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
677 memcpy((uint8_t *) & phba->fc_nodename,
678 (uint8_t *) & phba->fc_sparam.nodeName,
679 sizeof (struct lpfc_name));
680 memcpy((uint8_t *) & phba->fc_portname,
681 (uint8_t *) & phba->fc_sparam.portName,
682 sizeof (struct lpfc_name));
683 lpfc_mbuf_free(phba, mp->virt, mp->phys);
685 mempool_free( pmb, phba->mbox_mem_pool);
689 pmb->context1 = NULL;
690 lpfc_mbuf_free(phba, mp->virt, mp->phys);
692 if (phba->hba_state != LPFC_CLEAR_LA) {
693 lpfc_clear_la(phba, pmb);
694 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
695 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
696 == MBX_NOT_FINISHED) {
697 mempool_free( pmb, phba->mbox_mem_pool);
698 lpfc_disc_flush_list(phba);
699 psli->ring[(psli->ip_ring)].flag &=
700 ~LPFC_STOP_IOCB_EVENT;
701 psli->ring[(psli->fcp_ring)].flag &=
702 ~LPFC_STOP_IOCB_EVENT;
703 psli->ring[(psli->next_ring)].flag &=
704 ~LPFC_STOP_IOCB_EVENT;
705 phba->hba_state = LPFC_HBA_READY;
708 mempool_free( pmb, phba->mbox_mem_pool);
714 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
717 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
718 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
719 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
721 spin_lock_irq(phba->host->host_lock);
722 switch (la->UlnkSpeed) {
724 phba->fc_linkspeed = LA_1GHZ_LINK;
727 phba->fc_linkspeed = LA_2GHZ_LINK;
730 phba->fc_linkspeed = LA_4GHZ_LINK;
733 phba->fc_linkspeed = LA_UNKNW_LINK;
737 phba->fc_topology = la->topology;
739 if (phba->fc_topology == TOPOLOGY_LOOP) {
740 /* Get Loop Map information */
743 phba->fc_flag |= FC_LBIT;
745 phba->fc_myDID = la->granted_AL_PA;
746 i = la->un.lilpBde64.tus.f.bdeSize;
749 phba->alpa_map[0] = 0;
751 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
762 numalpa = phba->alpa_map[0];
764 while (j < numalpa) {
765 memset(un.pamap, 0, 16);
766 for (k = 1; j < numalpa; k++) {
768 phba->alpa_map[j + 1];
773 /* Link Up Event ALPA map */
774 lpfc_printf_log(phba,
777 "%d:1304 Link Up Event "
778 "ALPA map Data: x%x "
781 un.pa.wd1, un.pa.wd2,
782 un.pa.wd3, un.pa.wd4);
787 phba->fc_myDID = phba->fc_pref_DID;
788 phba->fc_flag |= FC_LBIT;
790 spin_unlock_irq(phba->host->host_lock);
794 lpfc_read_sparam(phba, sparam_mbox);
795 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
796 lpfc_sli_issue_mbox(phba, sparam_mbox,
797 (MBX_NOWAIT | MBX_STOP_IOCB));
801 phba->hba_state = LPFC_LOCAL_CFG_LINK;
802 lpfc_config_link(phba, cfglink_mbox);
803 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
804 lpfc_sli_issue_mbox(phba, cfglink_mbox,
805 (MBX_NOWAIT | MBX_STOP_IOCB));
810 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
812 struct lpfc_sli *psli = &phba->sli;
816 /* turn on Link Attention interrupts - no CLEAR_LA needed */
817 spin_lock_irq(phba->host->host_lock);
818 psli->sli_flag |= LPFC_PROCESS_LA;
819 control = readl(phba->HCregaddr);
820 control |= HC_LAINT_ENA;
821 writel(control, phba->HCregaddr);
822 readl(phba->HCregaddr); /* flush */
823 spin_unlock_irq(phba->host->host_lock);
827 * This routine handles processing a READ_LA mailbox
828 * command upon completion. It is setup in the LPFC_MBOXQ
829 * as the completion routine when the command is
830 * handed off to the SLI layer.
833 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
836 MAILBOX_t *mb = &pmb->mb;
837 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
839 /* Check for error */
841 lpfc_printf_log(phba,
844 "%d:1307 READ_LA mbox error x%x state x%x\n",
846 mb->mbxStatus, phba->hba_state);
847 lpfc_mbx_issue_link_down(phba);
848 phba->hba_state = LPFC_HBA_ERROR;
849 goto lpfc_mbx_cmpl_read_la_free_mbuf;
852 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
854 memcpy(&phba->alpa_map[0], mp->virt, 128);
856 spin_lock_irq(phba->host->host_lock);
858 phba->fc_flag |= FC_BYPASSED_MODE;
860 phba->fc_flag &= ~FC_BYPASSED_MODE;
861 spin_unlock_irq(phba->host->host_lock);
863 if (((phba->fc_eventTag + 1) < la->eventTag) ||
864 (phba->fc_eventTag == la->eventTag)) {
865 phba->fc_stat.LinkMultiEvent++;
866 if (la->attType == AT_LINK_UP) {
867 if (phba->fc_eventTag != 0)
872 phba->fc_eventTag = la->eventTag;
874 if (la->attType == AT_LINK_UP) {
875 phba->fc_stat.LinkUp++;
876 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
877 "%d:1303 Link Up Event x%x received "
878 "Data: x%x x%x x%x x%x\n",
879 phba->brd_no, la->eventTag, phba->fc_eventTag,
880 la->granted_AL_PA, la->UlnkSpeed,
882 lpfc_mbx_process_link_up(phba, la);
884 phba->fc_stat.LinkDown++;
885 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
886 "%d:1305 Link Down Event x%x received "
887 "Data: x%x x%x x%x\n",
888 phba->brd_no, la->eventTag, phba->fc_eventTag,
889 phba->hba_state, phba->fc_flag);
890 lpfc_mbx_issue_link_down(phba);
893 lpfc_mbx_cmpl_read_la_free_mbuf:
894 lpfc_mbuf_free(phba, mp->virt, mp->phys);
896 mempool_free(pmb, phba->mbox_mem_pool);
901 * This routine handles processing a REG_LOGIN mailbox
902 * command upon completion. It is setup in the LPFC_MBOXQ
903 * as the completion routine when the command is
904 * handed off to the SLI layer.
907 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
909 struct lpfc_sli *psli;
911 struct lpfc_dmabuf *mp;
912 struct lpfc_nodelist *ndlp;
917 ndlp = (struct lpfc_nodelist *) pmb->context2;
918 mp = (struct lpfc_dmabuf *) (pmb->context1);
920 pmb->context1 = NULL;
922 /* Good status, call state machine */
923 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
924 lpfc_mbuf_free(phba, mp->virt, mp->phys);
926 mempool_free( pmb, phba->mbox_mem_pool);
932 * This routine handles processing a Fabric REG_LOGIN mailbox
933 * command upon completion. It is setup in the LPFC_MBOXQ
934 * as the completion routine when the command is
935 * handed off to the SLI layer.
938 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
940 struct lpfc_sli *psli;
942 struct lpfc_dmabuf *mp;
943 struct lpfc_nodelist *ndlp;
944 struct lpfc_nodelist *ndlp_fdmi;
950 ndlp = (struct lpfc_nodelist *) pmb->context2;
951 mp = (struct lpfc_dmabuf *) (pmb->context1);
954 lpfc_mbuf_free(phba, mp->virt, mp->phys);
956 mempool_free( pmb, phba->mbox_mem_pool);
957 mempool_free( ndlp, phba->nlp_mem_pool);
959 /* FLOGI failed, so just use loop map to make discovery list */
960 lpfc_disc_list_loopmap(phba);
962 /* Start discovery */
963 lpfc_disc_start(phba);
967 pmb->context1 = NULL;
969 ndlp->nlp_rpi = mb->un.varWords[0];
970 ndlp->nlp_type |= NLP_FABRIC;
971 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
972 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
974 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
975 /* This NPort has been assigned an NPort_ID by the fabric as a
976 * result of the completed fabric login. Issue a State Change
977 * Registration (SCR) ELS request to the fabric controller
978 * (SCR_DID) so that this NPort gets RSCN events from the
981 lpfc_issue_els_scr(phba, SCR_DID, 0);
983 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
985 /* Allocate a new node instance. If the pool is empty,
986 * start the discovery process and skip the Nameserver
987 * login process. This is attempted again later on.
988 * Otherwise, issue a Port Login (PLOGI) to NameServer.
990 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
992 lpfc_disc_start(phba);
993 lpfc_mbuf_free(phba, mp->virt, mp->phys);
995 mempool_free( pmb, phba->mbox_mem_pool);
998 lpfc_nlp_init(phba, ndlp, NameServer_DID);
999 ndlp->nlp_type |= NLP_FABRIC;
1002 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1003 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1004 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
1005 if (phba->cfg_fdmi_on) {
1006 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1009 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
1010 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1011 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
1012 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
1017 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1019 mempool_free( pmb, phba->mbox_mem_pool);
1024 * This routine handles processing a NameServer REG_LOGIN mailbox
1025 * command upon completion. It is setup in the LPFC_MBOXQ
1026 * as the completion routine when the command is
1027 * handed off to the SLI layer.
1030 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1032 struct lpfc_sli *psli;
1034 struct lpfc_dmabuf *mp;
1035 struct lpfc_nodelist *ndlp;
1040 ndlp = (struct lpfc_nodelist *) pmb->context2;
1041 mp = (struct lpfc_dmabuf *) (pmb->context1);
1043 if (mb->mbxStatus) {
1044 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1046 mempool_free( pmb, phba->mbox_mem_pool);
1047 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1049 /* RegLogin failed, so just use loop map to make discovery
1051 lpfc_disc_list_loopmap(phba);
1053 /* Start discovery */
1054 lpfc_disc_start(phba);
1058 pmb->context1 = NULL;
1060 ndlp->nlp_rpi = mb->un.varWords[0];
1061 ndlp->nlp_type |= NLP_FABRIC;
1062 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1063 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1065 if (phba->hba_state < LPFC_HBA_READY) {
1066 /* Link up discovery requires Fabrib registration. */
1067 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1068 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1069 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1072 phba->fc_ns_retry = 0;
1073 /* Good status, issue CT Request to NameServer */
1074 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1075 /* Cannot issue NameServer Query, so finish up discovery */
1076 lpfc_disc_start(phba);
1079 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1081 mempool_free( pmb, phba->mbox_mem_pool);
1087 lpfc_register_remote_port(struct lpfc_hba * phba,
1088 struct lpfc_nodelist * ndlp)
1090 struct fc_rport *rport;
1091 struct lpfc_rport_data *rdata;
1092 struct fc_rport_identifiers rport_ids;
1094 /* Remote port has reappeared. Re-register w/ FC transport */
1095 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1096 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1097 rport_ids.port_id = ndlp->nlp_DID;
1098 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1100 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1102 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1103 "Warning: fc_remote_port_add failed\n");
1107 /* initialize static port data */
1108 rport->maxframe_size = ndlp->nlp_maxframe;
1109 rport->supported_classes = ndlp->nlp_class_sup;
1110 rdata = rport->dd_data;
1111 rdata->pnode = ndlp;
1113 if (ndlp->nlp_type & NLP_FCP_TARGET)
1114 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1115 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1116 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1119 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1120 fc_remote_port_rolechg(rport, rport_ids.roles);
1122 if ((rport->scsi_target_id != -1) &&
1123 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1124 ndlp->nlp_sid = rport->scsi_target_id;
1131 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1132 struct lpfc_nodelist * ndlp)
1134 struct fc_rport *rport = ndlp->rport;
1135 struct lpfc_rport_data *rdata = rport->dd_data;
1137 if (rport->scsi_target_id == -1) {
1139 rdata->pnode = NULL;
1142 fc_remote_port_delete(rport);
1148 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1150 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1151 struct lpfc_sli *psli;
1154 /* Sanity check to ensure we are not moving to / from the same list */
1155 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1156 if (list != NLP_NO_LIST)
1159 spin_lock_irq(phba->host->host_lock);
1160 switch (nlp->nlp_flag & NLP_LIST_MASK) {
1161 case NLP_NO_LIST: /* Not on any list */
1163 case NLP_UNUSED_LIST:
1164 phba->fc_unused_cnt--;
1165 list_del(&nlp->nlp_listp);
1167 case NLP_PLOGI_LIST:
1168 phba->fc_plogi_cnt--;
1169 list_del(&nlp->nlp_listp);
1171 case NLP_ADISC_LIST:
1172 phba->fc_adisc_cnt--;
1173 list_del(&nlp->nlp_listp);
1175 case NLP_REGLOGIN_LIST:
1176 phba->fc_reglogin_cnt--;
1177 list_del(&nlp->nlp_listp);
1180 phba->fc_prli_cnt--;
1181 list_del(&nlp->nlp_listp);
1183 case NLP_UNMAPPED_LIST:
1184 phba->fc_unmap_cnt--;
1185 list_del(&nlp->nlp_listp);
1186 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1187 nlp->nlp_type &= ~NLP_FC_NODE;
1188 phba->nport_event_cnt++;
1190 rport_del = unmapped;
1192 case NLP_MAPPED_LIST:
1194 list_del(&nlp->nlp_listp);
1195 phba->nport_event_cnt++;
1201 list_del(&nlp->nlp_listp);
1202 /* Stop delay tmo if taking node off NPR list */
1203 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1204 (list != NLP_NPR_LIST)) {
1205 spin_unlock_irq(phba->host->host_lock);
1206 lpfc_cancel_retry_delay_tmo(phba, nlp);
1207 spin_lock_irq(phba->host->host_lock);
1212 nlp->nlp_flag &= ~NLP_LIST_MASK;
1214 /* Add NPort <did> to <num> list */
1215 lpfc_printf_log(phba,
1218 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1220 nlp->nlp_DID, list, nlp->nlp_flag);
1223 case NLP_NO_LIST: /* No list, just remove it */
1224 spin_unlock_irq(phba->host->host_lock);
1225 lpfc_nlp_remove(phba, nlp);
1226 spin_lock_irq(phba->host->host_lock);
1227 /* as node removed - stop further transport calls */
1230 case NLP_UNUSED_LIST:
1231 nlp->nlp_flag |= list;
1232 /* Put it at the end of the unused list */
1233 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1234 phba->fc_unused_cnt++;
1236 case NLP_PLOGI_LIST:
1237 nlp->nlp_flag |= list;
1238 /* Put it at the end of the plogi list */
1239 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1240 phba->fc_plogi_cnt++;
1242 case NLP_ADISC_LIST:
1243 nlp->nlp_flag |= list;
1244 /* Put it at the end of the adisc list */
1245 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1246 phba->fc_adisc_cnt++;
1248 case NLP_REGLOGIN_LIST:
1249 nlp->nlp_flag |= list;
1250 /* Put it at the end of the reglogin list */
1251 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1252 phba->fc_reglogin_cnt++;
1255 nlp->nlp_flag |= list;
1256 /* Put it at the end of the prli list */
1257 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1258 phba->fc_prli_cnt++;
1260 case NLP_UNMAPPED_LIST:
1261 rport_add = unmapped;
1262 /* ensure all vestiges of "mapped" significance are gone */
1263 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1264 nlp->nlp_flag |= list;
1265 /* Put it at the end of the unmap list */
1266 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1267 phba->fc_unmap_cnt++;
1268 phba->nport_event_cnt++;
1269 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1270 nlp->nlp_type |= NLP_FC_NODE;
1272 case NLP_MAPPED_LIST:
1274 nlp->nlp_flag |= list;
1275 /* Put it at the end of the map list */
1276 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1278 phba->nport_event_cnt++;
1279 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1282 nlp->nlp_flag |= list;
1283 /* Put it at the end of the npr list */
1284 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1287 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1293 spin_unlock_irq(phba->host->host_lock);
1296 * We make all the calls into the transport after we have
1297 * moved the node between lists. This so that we don't
1298 * release the lock while in-between lists.
1301 /* Don't upcall midlayer if we're unloading */
1302 if (!(phba->fc_flag & FC_UNLOADING)) {
1304 * We revalidate the rport pointer as the "add" function
1305 * may have removed the remote port.
1307 if ((rport_del != none) && nlp->rport)
1308 lpfc_unregister_remote_port(phba, nlp);
1310 if (rport_add != none) {
1312 * Tell the fc transport about the port, if we haven't
1313 * already. If we have, and it's a scsi entity, be
1314 * sure to unblock any attached scsi devices
1316 if ((!nlp->rport) || (nlp->rport->port_state ==
1317 FC_PORTSTATE_BLOCKED))
1318 lpfc_register_remote_port(phba, nlp);
1321 * if we added to Mapped list, but the remote port
1322 * registration failed or assigned a target id outside
1323 * our presentable range - move the node to the
1326 if ((rport_add == mapped) &&
1328 (nlp->rport->scsi_target_id == -1) ||
1329 (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) {
1330 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1331 spin_lock_irq(phba->host->host_lock);
1332 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1333 spin_unlock_irq(phba->host->host_lock);
1334 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1342 * Start / ReStart rescue timer for Discovery / RSCN handling
1345 lpfc_set_disctmo(struct lpfc_hba * phba)
1349 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1350 /* For FAN, timeout should be greater then edtov */
1351 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1353 /* Normal discovery timeout should be > then ELS/CT timeout
1354 * FC spec states we need 3 * ratov for CT requests
1356 tmo = ((phba->fc_ratov * 3) + 3);
1359 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1360 spin_lock_irq(phba->host->host_lock);
1361 phba->fc_flag |= FC_DISC_TMO;
1362 spin_unlock_irq(phba->host->host_lock);
1364 /* Start Discovery Timer state <hba_state> */
1365 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1366 "%d:0247 Start Discovery Timer state x%x "
1367 "Data: x%x x%lx x%x x%x\n",
1369 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1370 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1376 * Cancel rescue timer for Discovery / RSCN handling
1379 lpfc_can_disctmo(struct lpfc_hba * phba)
1381 /* Turn off discovery timer if its running */
1382 if (phba->fc_flag & FC_DISC_TMO) {
1383 spin_lock_irq(phba->host->host_lock);
1384 phba->fc_flag &= ~FC_DISC_TMO;
1385 spin_unlock_irq(phba->host->host_lock);
1386 del_timer_sync(&phba->fc_disctmo);
1387 phba->work_hba_events &= ~WORKER_DISC_TMO;
1390 /* Cancel Discovery Timer state <hba_state> */
1391 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1392 "%d:0248 Cancel Discovery Timer state x%x "
1393 "Data: x%x x%x x%x\n",
1394 phba->brd_no, phba->hba_state, phba->fc_flag,
1395 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1401 * Check specified ring for outstanding IOCB on the SLI queue
1402 * Return true if iocb matches the specified nport
1405 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1406 struct lpfc_sli_ring * pring,
1407 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1409 struct lpfc_sli *psli;
1414 if (pring->ringno == LPFC_ELS_RING) {
1415 switch (icmd->ulpCommand) {
1416 case CMD_GEN_REQUEST64_CR:
1417 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1419 case CMD_ELS_REQUEST64_CR:
1420 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1422 case CMD_XMIT_ELS_RSP64_CX:
1423 if (iocb->context1 == (uint8_t *) ndlp)
1426 } else if (pring->ringno == psli->ip_ring) {
1428 } else if (pring->ringno == psli->fcp_ring) {
1429 /* Skip match check if waiting to relogin to FCP target */
1430 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1431 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1434 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1437 } else if (pring->ringno == psli->next_ring) {
1444 * Free resources / clean up outstanding I/Os
1445 * associated with nlp_rpi in the LPFC_NODELIST entry.
1448 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1450 struct lpfc_sli *psli;
1451 struct lpfc_sli_ring *pring;
1452 struct lpfc_iocbq *iocb, *next_iocb;
1457 * Everything that matches on txcmplq will be returned
1458 * by firmware with a no rpi error.
1461 rpi = ndlp->nlp_rpi;
1463 /* Now process each ring */
1464 for (i = 0; i < psli->num_rings; i++) {
1465 pring = &psli->ring[i];
1467 spin_lock_irq(phba->host->host_lock);
1468 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1471 * Check to see if iocb matches the nport we are
1474 if ((lpfc_check_sli_ndlp
1475 (phba, pring, iocb, ndlp))) {
1476 /* It matches, so deque and call compl
1478 list_del(&iocb->list);
1480 if (iocb->iocb_cmpl) {
1483 IOSTAT_LOCAL_REJECT;
1484 icmd->un.ulpWord[4] =
1486 spin_unlock_irq(phba->host->
1488 (iocb->iocb_cmpl) (phba,
1490 spin_lock_irq(phba->host->
1493 lpfc_sli_release_iocbq(phba,
1497 spin_unlock_irq(phba->host->host_lock);
1505 * Free rpi associated with LPFC_NODELIST entry.
1506 * This routine is called from lpfc_freenode(), when we are removing
1507 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1508 * LOGO that completes successfully, and we are waiting to PLOGI back
1509 * to the remote NPort. In addition, it is called after we receive
1510 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1511 * we are waiting to PLOGI back to the remote NPort.
1514 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1519 if (ndlp->nlp_rpi) {
1520 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1521 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1522 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1523 rc = lpfc_sli_issue_mbox
1524 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1525 if (rc == MBX_NOT_FINISHED)
1526 mempool_free( mbox, phba->mbox_mem_pool);
1528 lpfc_no_rpi(phba, ndlp);
1536 * Free resources associated with LPFC_NODELIST entry
1537 * so it can be freed.
1540 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1543 LPFC_MBOXQ_t *nextmb;
1544 struct lpfc_dmabuf *mp;
1546 /* Cleanup node for NPort <nlp_DID> */
1547 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1548 "%d:0900 Cleanup node for NPort x%x "
1549 "Data: x%x x%x x%x\n",
1550 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1551 ndlp->nlp_state, ndlp->nlp_rpi);
1553 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1556 * if unloading the driver - just leave the remote port in place.
1557 * The driver unload will force the attached devices to detach
1558 * and flush cache's w/o generating flush errors.
1560 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1561 lpfc_unregister_remote_port(phba, ndlp);
1562 ndlp->nlp_sid = NLP_NO_SID;
1565 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1566 if ((mb = phba->sli.mbox_active)) {
1567 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1568 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1569 mb->context2 = NULL;
1570 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1574 spin_lock_irq(phba->host->host_lock);
1575 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1576 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1577 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1578 mp = (struct lpfc_dmabuf *) (mb->context1);
1580 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1583 list_del(&mb->list);
1584 mempool_free(mb, phba->mbox_mem_pool);
1587 spin_unlock_irq(phba->host->host_lock);
1589 lpfc_els_abort(phba,ndlp,0);
1590 spin_lock_irq(phba->host->host_lock);
1591 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1592 spin_unlock_irq(phba->host->host_lock);
1594 ndlp->nlp_last_elscmd = 0;
1595 del_timer_sync(&ndlp->nlp_delayfunc);
1597 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1598 list_del_init(&ndlp->els_retry_evt.evt_listp);
1600 lpfc_unreg_rpi(phba, ndlp);
1606 * Check to see if we can free the nlp back to the freelist.
1607 * If we are in the middle of using the nlp in the discovery state
1608 * machine, defer the free till we reach the end of the state machine.
1611 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1614 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1615 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1618 if (ndlp->nlp_disc_refcnt) {
1619 spin_lock_irq(phba->host->host_lock);
1620 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1621 spin_unlock_irq(phba->host->host_lock);
1623 lpfc_freenode(phba, ndlp);
1624 mempool_free( ndlp, phba->nlp_mem_pool);
1630 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1636 if (did == Bcast_DID)
1639 if (ndlp->nlp_DID == 0) {
1643 /* First check for Direct match */
1644 if (ndlp->nlp_DID == did)
1647 /* Next check for area/domain identically equals 0 match */
1648 mydid.un.word = phba->fc_myDID;
1649 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1653 matchdid.un.word = did;
1654 ndlpdid.un.word = ndlp->nlp_DID;
1655 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1656 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1657 (mydid.un.b.area == matchdid.un.b.area)) {
1658 if ((ndlpdid.un.b.domain == 0) &&
1659 (ndlpdid.un.b.area == 0)) {
1660 if (ndlpdid.un.b.id)
1666 matchdid.un.word = ndlp->nlp_DID;
1667 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1668 (mydid.un.b.area == ndlpdid.un.b.area)) {
1669 if ((matchdid.un.b.domain == 0) &&
1670 (matchdid.un.b.area == 0)) {
1671 if (matchdid.un.b.id)
1679 /* Search for a nodelist entry on a specific list */
1680 struct lpfc_nodelist *
1681 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1683 struct lpfc_nodelist *ndlp, *next_ndlp;
1686 spin_lock_irq(phba->host->host_lock);
1687 if (order & NLP_SEARCH_UNMAPPED) {
1688 list_for_each_entry_safe(ndlp, next_ndlp,
1689 &phba->fc_nlpunmap_list, nlp_listp) {
1690 if (lpfc_matchdid(phba, ndlp, did)) {
1691 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1692 ((uint32_t) ndlp->nlp_xri << 16) |
1693 ((uint32_t) ndlp->nlp_type << 8) |
1694 ((uint32_t) ndlp->nlp_rpi & 0xff));
1695 /* FIND node DID unmapped */
1696 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1697 "%d:0929 FIND node DID unmapped"
1698 " Data: x%p x%x x%x x%x\n",
1700 ndlp, ndlp->nlp_DID,
1701 ndlp->nlp_flag, data1);
1702 spin_unlock_irq(phba->host->host_lock);
1708 if (order & NLP_SEARCH_MAPPED) {
1709 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1711 if (lpfc_matchdid(phba, ndlp, did)) {
1713 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1714 ((uint32_t) ndlp->nlp_xri << 16) |
1715 ((uint32_t) ndlp->nlp_type << 8) |
1716 ((uint32_t) ndlp->nlp_rpi & 0xff));
1717 /* FIND node DID mapped */
1718 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1719 "%d:0930 FIND node DID mapped "
1720 "Data: x%p x%x x%x x%x\n",
1722 ndlp, ndlp->nlp_DID,
1723 ndlp->nlp_flag, data1);
1724 spin_unlock_irq(phba->host->host_lock);
1730 if (order & NLP_SEARCH_PLOGI) {
1731 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1733 if (lpfc_matchdid(phba, ndlp, did)) {
1735 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1736 ((uint32_t) ndlp->nlp_xri << 16) |
1737 ((uint32_t) ndlp->nlp_type << 8) |
1738 ((uint32_t) ndlp->nlp_rpi & 0xff));
1739 /* LOG change to PLOGI */
1740 /* FIND node DID plogi */
1741 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1742 "%d:0908 FIND node DID plogi "
1743 "Data: x%p x%x x%x x%x\n",
1745 ndlp, ndlp->nlp_DID,
1746 ndlp->nlp_flag, data1);
1747 spin_unlock_irq(phba->host->host_lock);
1753 if (order & NLP_SEARCH_ADISC) {
1754 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1756 if (lpfc_matchdid(phba, ndlp, did)) {
1758 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1759 ((uint32_t) ndlp->nlp_xri << 16) |
1760 ((uint32_t) ndlp->nlp_type << 8) |
1761 ((uint32_t) ndlp->nlp_rpi & 0xff));
1762 /* LOG change to ADISC */
1763 /* FIND node DID adisc */
1764 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1765 "%d:0931 FIND node DID adisc "
1766 "Data: x%p x%x x%x x%x\n",
1768 ndlp, ndlp->nlp_DID,
1769 ndlp->nlp_flag, data1);
1770 spin_unlock_irq(phba->host->host_lock);
1776 if (order & NLP_SEARCH_REGLOGIN) {
1777 list_for_each_entry_safe(ndlp, next_ndlp,
1778 &phba->fc_reglogin_list, nlp_listp) {
1779 if (lpfc_matchdid(phba, ndlp, did)) {
1781 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1782 ((uint32_t) ndlp->nlp_xri << 16) |
1783 ((uint32_t) ndlp->nlp_type << 8) |
1784 ((uint32_t) ndlp->nlp_rpi & 0xff));
1785 /* LOG change to REGLOGIN */
1786 /* FIND node DID reglogin */
1787 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1788 "%d:0901 FIND node DID reglogin"
1789 " Data: x%p x%x x%x x%x\n",
1791 ndlp, ndlp->nlp_DID,
1792 ndlp->nlp_flag, data1);
1793 spin_unlock_irq(phba->host->host_lock);
1799 if (order & NLP_SEARCH_PRLI) {
1800 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1802 if (lpfc_matchdid(phba, ndlp, did)) {
1804 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1805 ((uint32_t) ndlp->nlp_xri << 16) |
1806 ((uint32_t) ndlp->nlp_type << 8) |
1807 ((uint32_t) ndlp->nlp_rpi & 0xff));
1808 /* LOG change to PRLI */
1809 /* FIND node DID prli */
1810 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1811 "%d:0902 FIND node DID prli "
1812 "Data: x%p x%x x%x x%x\n",
1814 ndlp, ndlp->nlp_DID,
1815 ndlp->nlp_flag, data1);
1816 spin_unlock_irq(phba->host->host_lock);
1822 if (order & NLP_SEARCH_NPR) {
1823 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1825 if (lpfc_matchdid(phba, ndlp, did)) {
1827 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1828 ((uint32_t) ndlp->nlp_xri << 16) |
1829 ((uint32_t) ndlp->nlp_type << 8) |
1830 ((uint32_t) ndlp->nlp_rpi & 0xff));
1831 /* LOG change to NPR */
1832 /* FIND node DID npr */
1833 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1834 "%d:0903 FIND node DID npr "
1835 "Data: x%p x%x x%x x%x\n",
1837 ndlp, ndlp->nlp_DID,
1838 ndlp->nlp_flag, data1);
1839 spin_unlock_irq(phba->host->host_lock);
1845 if (order & NLP_SEARCH_UNUSED) {
1846 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1848 if (lpfc_matchdid(phba, ndlp, did)) {
1850 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1851 ((uint32_t) ndlp->nlp_xri << 16) |
1852 ((uint32_t) ndlp->nlp_type << 8) |
1853 ((uint32_t) ndlp->nlp_rpi & 0xff));
1854 /* LOG change to UNUSED */
1855 /* FIND node DID unused */
1856 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1857 "%d:0905 FIND node DID unused "
1858 "Data: x%p x%x x%x x%x\n",
1860 ndlp, ndlp->nlp_DID,
1861 ndlp->nlp_flag, data1);
1862 spin_unlock_irq(phba->host->host_lock);
1868 spin_unlock_irq(phba->host->host_lock);
1870 /* FIND node did <did> NOT FOUND */
1871 lpfc_printf_log(phba,
1874 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1875 phba->brd_no, did, order);
1877 /* no match found */
1881 struct lpfc_nodelist *
1882 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1884 struct lpfc_nodelist *ndlp;
1887 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1889 if ((phba->fc_flag & FC_RSCN_MODE) &&
1890 ((lpfc_rscn_payload_check(phba, did) == 0)))
1892 ndlp = (struct lpfc_nodelist *)
1893 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1896 lpfc_nlp_init(phba, ndlp, did);
1897 ndlp->nlp_state = NLP_STE_NPR_NODE;
1898 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1899 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1902 if (phba->fc_flag & FC_RSCN_MODE) {
1903 if (lpfc_rscn_payload_check(phba, did)) {
1904 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1906 /* Since this node is marked for discovery,
1907 * delay timeout is not needed.
1909 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1910 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1914 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1915 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1917 ndlp->nlp_state = NLP_STE_NPR_NODE;
1918 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1919 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1924 /* Build a list of nodes to discover based on the loopmap */
1926 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1929 uint32_t alpa, index;
1931 if (phba->hba_state <= LPFC_LINK_DOWN) {
1934 if (phba->fc_topology != TOPOLOGY_LOOP) {
1938 /* Check for loop map present or not */
1939 if (phba->alpa_map[0]) {
1940 for (j = 1; j <= phba->alpa_map[0]; j++) {
1941 alpa = phba->alpa_map[j];
1943 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1946 lpfc_setup_disc_node(phba, alpa);
1949 /* No alpamap, so try all alpa's */
1950 for (j = 0; j < FC_MAXLOOP; j++) {
1951 /* If cfg_scan_down is set, start from highest
1952 * ALPA (0xef) to lowest (0x1).
1954 if (phba->cfg_scan_down)
1957 index = FC_MAXLOOP - j - 1;
1958 alpa = lpfcAlpaArray[index];
1959 if ((phba->fc_myDID & 0xff) == alpa) {
1963 lpfc_setup_disc_node(phba, alpa);
1969 /* Start Link up / RSCN discovery on NPR list */
1971 lpfc_disc_start(struct lpfc_hba * phba)
1973 struct lpfc_sli *psli;
1975 struct lpfc_nodelist *ndlp, *next_ndlp;
1976 uint32_t did_changed, num_sent;
1977 uint32_t clear_la_pending;
1982 if (phba->hba_state <= LPFC_LINK_DOWN) {
1985 if (phba->hba_state == LPFC_CLEAR_LA)
1986 clear_la_pending = 1;
1988 clear_la_pending = 0;
1990 if (phba->hba_state < LPFC_HBA_READY) {
1991 phba->hba_state = LPFC_DISC_AUTH;
1993 lpfc_set_disctmo(phba);
1995 if (phba->fc_prevDID == phba->fc_myDID) {
2000 phba->fc_prevDID = phba->fc_myDID;
2001 phba->num_disc_nodes = 0;
2003 /* Start Discovery state <hba_state> */
2004 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2005 "%d:0202 Start Discovery hba state x%x "
2006 "Data: x%x x%x x%x\n",
2007 phba->brd_no, phba->hba_state, phba->fc_flag,
2008 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2010 /* If our did changed, we MUST do PLOGI */
2011 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2013 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2015 spin_lock_irq(phba->host->host_lock);
2016 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2017 spin_unlock_irq(phba->host->host_lock);
2022 /* First do ADISCs - if any */
2023 num_sent = lpfc_els_disc_adisc(phba);
2028 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2029 /* If we get here, there is nothing to ADISC */
2030 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2031 phba->hba_state = LPFC_CLEAR_LA;
2032 lpfc_clear_la(phba, mbox);
2033 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2034 rc = lpfc_sli_issue_mbox(phba, mbox,
2035 (MBX_NOWAIT | MBX_STOP_IOCB));
2036 if (rc == MBX_NOT_FINISHED) {
2037 mempool_free( mbox, phba->mbox_mem_pool);
2038 lpfc_disc_flush_list(phba);
2039 psli->ring[(psli->ip_ring)].flag &=
2040 ~LPFC_STOP_IOCB_EVENT;
2041 psli->ring[(psli->fcp_ring)].flag &=
2042 ~LPFC_STOP_IOCB_EVENT;
2043 psli->ring[(psli->next_ring)].flag &=
2044 ~LPFC_STOP_IOCB_EVENT;
2045 phba->hba_state = LPFC_HBA_READY;
2049 /* Next do PLOGIs - if any */
2050 num_sent = lpfc_els_disc_plogi(phba);
2055 if (phba->fc_flag & FC_RSCN_MODE) {
2056 /* Check to see if more RSCNs came in while we
2057 * were processing this one.
2059 if ((phba->fc_rscn_id_cnt == 0) &&
2060 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2061 spin_lock_irq(phba->host->host_lock);
2062 phba->fc_flag &= ~FC_RSCN_MODE;
2063 spin_unlock_irq(phba->host->host_lock);
2065 lpfc_els_handle_rscn(phba);
2072 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2073 * ring the match the sppecified nodelist.
2076 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2078 struct lpfc_sli *psli;
2080 struct lpfc_iocbq *iocb, *next_iocb;
2081 struct lpfc_sli_ring *pring;
2082 struct lpfc_dmabuf *mp;
2085 pring = &psli->ring[LPFC_ELS_RING];
2087 /* Error matching iocb on txq or txcmplq
2088 * First check the txq.
2090 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2091 if (iocb->context1 != ndlp) {
2095 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2096 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2098 list_del(&iocb->list);
2100 lpfc_els_free_iocb(phba, iocb);
2104 /* Next check the txcmplq */
2105 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2106 if (iocb->context1 != ndlp) {
2110 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2111 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2113 iocb->iocb_cmpl = NULL;
2114 /* context2 = cmd, context2->next = rsp, context3 =
2116 if (iocb->context2) {
2117 /* Free the response IOCB before handling the
2120 mp = (struct lpfc_dmabuf *) (iocb->context2);
2121 mp = list_get_first(&mp->list,
2125 /* Delay before releasing rsp buffer to
2126 * give UNREG mbox a chance to take
2130 &phba->freebufList);
2132 lpfc_mbuf_free(phba,
2133 ((struct lpfc_dmabuf *)
2134 iocb->context2)->virt,
2135 ((struct lpfc_dmabuf *)
2136 iocb->context2)->phys);
2137 kfree(iocb->context2);
2140 if (iocb->context3) {
2141 lpfc_mbuf_free(phba,
2142 ((struct lpfc_dmabuf *)
2143 iocb->context3)->virt,
2144 ((struct lpfc_dmabuf *)
2145 iocb->context3)->phys);
2146 kfree(iocb->context3);
2155 lpfc_disc_flush_list(struct lpfc_hba * phba)
2157 struct lpfc_nodelist *ndlp, *next_ndlp;
2159 if (phba->fc_plogi_cnt) {
2160 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2162 lpfc_free_tx(phba, ndlp);
2163 lpfc_nlp_remove(phba, ndlp);
2166 if (phba->fc_adisc_cnt) {
2167 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2169 lpfc_free_tx(phba, ndlp);
2170 lpfc_nlp_remove(phba, ndlp);
2176 /*****************************************************************************/
2178 * NAME: lpfc_disc_timeout
2180 * FUNCTION: Fibre Channel driver discovery timeout routine.
2182 * EXECUTION ENVIRONMENT: interrupt only
2190 /*****************************************************************************/
2192 lpfc_disc_timeout(unsigned long ptr)
2194 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2195 unsigned long flags = 0;
2197 if (unlikely(!phba))
2200 spin_lock_irqsave(phba->host->host_lock, flags);
2201 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2202 phba->work_hba_events |= WORKER_DISC_TMO;
2203 if (phba->work_wait)
2204 wake_up(phba->work_wait);
2206 spin_unlock_irqrestore(phba->host->host_lock, flags);
2211 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2213 struct lpfc_sli *psli;
2214 struct lpfc_nodelist *ndlp, *next_ndlp;
2215 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2216 int rc, clrlaerr = 0;
2218 if (unlikely(!phba))
2221 if (!(phba->fc_flag & FC_DISC_TMO))
2226 spin_lock_irq(phba->host->host_lock);
2227 phba->fc_flag &= ~FC_DISC_TMO;
2228 spin_unlock_irq(phba->host->host_lock);
2230 switch (phba->hba_state) {
2232 case LPFC_LOCAL_CFG_LINK:
2233 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2235 lpfc_printf_log(phba,
2238 "%d:0221 FAN timeout\n",
2241 /* Start discovery by sending FLOGI, clean up old rpis */
2242 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2244 if (ndlp->nlp_type & NLP_FABRIC) {
2245 /* Clean up the ndlp on Fabric connections */
2246 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2247 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2248 /* Fail outstanding IO now since device
2249 * is marked for PLOGI.
2251 lpfc_unreg_rpi(phba, ndlp);
2254 phba->hba_state = LPFC_FLOGI;
2255 lpfc_set_disctmo(phba);
2256 lpfc_initial_flogi(phba);
2260 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2261 /* Initial FLOGI timeout */
2262 lpfc_printf_log(phba,
2265 "%d:0222 Initial FLOGI timeout\n",
2268 /* Assume no Fabric and go on with discovery.
2269 * Check for outstanding ELS FLOGI to abort.
2272 /* FLOGI failed, so just use loop map to make discovery list */
2273 lpfc_disc_list_loopmap(phba);
2275 /* Start discovery */
2276 lpfc_disc_start(phba);
2279 case LPFC_FABRIC_CFG_LINK:
2280 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2282 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2283 "%d:0223 Timeout while waiting for NameServer "
2284 "login\n", phba->brd_no);
2286 /* Next look for NameServer ndlp */
2287 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2289 lpfc_nlp_remove(phba, ndlp);
2290 /* Start discovery */
2291 lpfc_disc_start(phba);
2295 /* Check for wait for NameServer Rsp timeout */
2296 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2297 "%d:0224 NameServer Query timeout "
2300 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2302 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2305 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2306 /* Try it one more time */
2307 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2311 phba->fc_ns_retry = 0;
2314 /* Nothing to authenticate, so CLEAR_LA right now */
2315 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2318 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2319 "%d:0226 Device Discovery "
2320 "completion error\n",
2322 phba->hba_state = LPFC_HBA_ERROR;
2326 phba->hba_state = LPFC_CLEAR_LA;
2327 lpfc_clear_la(phba, clearlambox);
2328 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2329 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2330 (MBX_NOWAIT | MBX_STOP_IOCB));
2331 if (rc == MBX_NOT_FINISHED) {
2332 mempool_free(clearlambox, phba->mbox_mem_pool);
2337 /* Setup and issue mailbox INITIALIZE LINK command */
2338 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2339 if (!initlinkmbox) {
2340 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2341 "%d:0206 Device Discovery "
2342 "completion error\n",
2344 phba->hba_state = LPFC_HBA_ERROR;
2348 lpfc_linkdown(phba);
2349 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2350 phba->cfg_link_speed);
2351 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2352 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2353 (MBX_NOWAIT | MBX_STOP_IOCB));
2354 if (rc == MBX_NOT_FINISHED)
2355 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2359 case LPFC_DISC_AUTH:
2360 /* Node Authentication timeout */
2361 lpfc_printf_log(phba,
2364 "%d:0227 Node Authentication timeout\n",
2366 lpfc_disc_flush_list(phba);
2367 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2370 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2371 "%d:0207 Device Discovery "
2372 "completion error\n",
2374 phba->hba_state = LPFC_HBA_ERROR;
2377 phba->hba_state = LPFC_CLEAR_LA;
2378 lpfc_clear_la(phba, clearlambox);
2379 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2380 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2381 (MBX_NOWAIT | MBX_STOP_IOCB));
2382 if (rc == MBX_NOT_FINISHED) {
2383 mempool_free(clearlambox, phba->mbox_mem_pool);
2389 /* CLEAR LA timeout */
2390 lpfc_printf_log(phba,
2393 "%d:0228 CLEAR LA timeout\n",
2398 case LPFC_HBA_READY:
2399 if (phba->fc_flag & FC_RSCN_MODE) {
2400 lpfc_printf_log(phba,
2403 "%d:0231 RSCN timeout Data: x%x x%x\n",
2405 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2407 /* Cleanup any outstanding ELS commands */
2408 lpfc_els_flush_cmd(phba);
2410 lpfc_els_flush_rscn(phba);
2411 lpfc_disc_flush_list(phba);
2417 lpfc_disc_flush_list(phba);
2418 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2419 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2420 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2421 phba->hba_state = LPFC_HBA_READY;
2428 * This routine handles processing a NameServer REG_LOGIN mailbox
2429 * command upon completion. It is setup in the LPFC_MBOXQ
2430 * as the completion routine when the command is
2431 * handed off to the SLI layer.
2434 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2436 struct lpfc_sli *psli;
2438 struct lpfc_dmabuf *mp;
2439 struct lpfc_nodelist *ndlp;
2444 ndlp = (struct lpfc_nodelist *) pmb->context2;
2445 mp = (struct lpfc_dmabuf *) (pmb->context1);
2447 pmb->context1 = NULL;
2449 ndlp->nlp_rpi = mb->un.varWords[0];
2450 ndlp->nlp_type |= NLP_FABRIC;
2451 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2452 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2454 /* Start issuing Fabric-Device Management Interface (FDMI)
2455 * command to 0xfffffa (FDMI well known port)
2457 if (phba->cfg_fdmi_on == 1) {
2458 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2461 * Delay issuing FDMI command if fdmi-on=2
2462 * (supporting RPA/hostnmae)
2464 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2467 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2469 mempool_free( pmb, phba->mbox_mem_pool);
2475 * This routine looks up the ndlp lists
2476 * for the given RPI. If rpi found
2477 * it return the node list pointer
2480 struct lpfc_nodelist *
2481 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2483 struct lpfc_nodelist *ndlp;
2484 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2485 &phba->fc_nlpmap_list,
2486 &phba->fc_plogi_list,
2487 &phba->fc_adisc_list,
2488 &phba->fc_reglogin_list};
2491 spin_lock_irq(phba->host->host_lock);
2492 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2493 list_for_each_entry(ndlp, lists[i], nlp_listp)
2494 if (ndlp->nlp_rpi == rpi) {
2495 spin_unlock_irq(phba->host->host_lock);
2498 spin_unlock_irq(phba->host->host_lock);
2503 * This routine looks up the ndlp lists
2504 * for the given WWPN. If WWPN found
2505 * it return the node list pointer
2508 struct lpfc_nodelist *
2509 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2510 struct lpfc_name * wwpn)
2512 struct lpfc_nodelist *ndlp;
2513 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2514 &phba->fc_nlpmap_list,
2516 &phba->fc_plogi_list,
2517 &phba->fc_adisc_list,
2518 &phba->fc_reglogin_list,
2519 &phba->fc_prli_list};
2520 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2525 NLP_SEARCH_REGLOGIN,
2529 spin_lock_irq(phba->host->host_lock);
2530 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2531 if (!(order & search[i]))
2533 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2534 if (memcmp(&ndlp->nlp_portname, wwpn,
2535 sizeof(struct lpfc_name)) == 0) {
2536 spin_unlock_irq(phba->host->host_lock);
2541 spin_unlock_irq(phba->host->host_lock);
2546 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2549 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2550 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2551 init_timer(&ndlp->nlp_delayfunc);
2552 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2553 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2554 ndlp->nlp_DID = did;
2555 ndlp->nlp_phba = phba;
2556 ndlp->nlp_sid = NLP_NO_SID;