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 memcpy((uint8_t *) & phba->fc_nodename,
676 (uint8_t *) & phba->fc_sparam.nodeName,
677 sizeof (struct lpfc_name));
678 memcpy((uint8_t *) & phba->fc_portname,
679 (uint8_t *) & phba->fc_sparam.portName,
680 sizeof (struct lpfc_name));
681 lpfc_mbuf_free(phba, mp->virt, mp->phys);
683 mempool_free( pmb, phba->mbox_mem_pool);
687 pmb->context1 = NULL;
688 lpfc_mbuf_free(phba, mp->virt, mp->phys);
690 if (phba->hba_state != LPFC_CLEAR_LA) {
691 lpfc_clear_la(phba, pmb);
692 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
693 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
694 == MBX_NOT_FINISHED) {
695 mempool_free( pmb, phba->mbox_mem_pool);
696 lpfc_disc_flush_list(phba);
697 psli->ring[(psli->ip_ring)].flag &=
698 ~LPFC_STOP_IOCB_EVENT;
699 psli->ring[(psli->fcp_ring)].flag &=
700 ~LPFC_STOP_IOCB_EVENT;
701 psli->ring[(psli->next_ring)].flag &=
702 ~LPFC_STOP_IOCB_EVENT;
703 phba->hba_state = LPFC_HBA_READY;
706 mempool_free( pmb, phba->mbox_mem_pool);
712 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
715 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
716 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
717 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
719 spin_lock_irq(phba->host->host_lock);
720 switch (la->UlnkSpeed) {
722 phba->fc_linkspeed = LA_1GHZ_LINK;
725 phba->fc_linkspeed = LA_2GHZ_LINK;
728 phba->fc_linkspeed = LA_4GHZ_LINK;
731 phba->fc_linkspeed = LA_UNKNW_LINK;
735 phba->fc_topology = la->topology;
737 if (phba->fc_topology == TOPOLOGY_LOOP) {
738 /* Get Loop Map information */
741 phba->fc_flag |= FC_LBIT;
743 phba->fc_myDID = la->granted_AL_PA;
744 i = la->un.lilpBde64.tus.f.bdeSize;
747 phba->alpa_map[0] = 0;
749 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
760 numalpa = phba->alpa_map[0];
762 while (j < numalpa) {
763 memset(un.pamap, 0, 16);
764 for (k = 1; j < numalpa; k++) {
766 phba->alpa_map[j + 1];
771 /* Link Up Event ALPA map */
772 lpfc_printf_log(phba,
775 "%d:1304 Link Up Event "
776 "ALPA map Data: x%x "
779 un.pa.wd1, un.pa.wd2,
780 un.pa.wd3, un.pa.wd4);
785 phba->fc_myDID = phba->fc_pref_DID;
786 phba->fc_flag |= FC_LBIT;
788 spin_unlock_irq(phba->host->host_lock);
792 lpfc_read_sparam(phba, sparam_mbox);
793 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
794 lpfc_sli_issue_mbox(phba, sparam_mbox,
795 (MBX_NOWAIT | MBX_STOP_IOCB));
799 phba->hba_state = LPFC_LOCAL_CFG_LINK;
800 lpfc_config_link(phba, cfglink_mbox);
801 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
802 lpfc_sli_issue_mbox(phba, cfglink_mbox,
803 (MBX_NOWAIT | MBX_STOP_IOCB));
808 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
810 struct lpfc_sli *psli = &phba->sli;
814 /* turn on Link Attention interrupts - no CLEAR_LA needed */
815 spin_lock_irq(phba->host->host_lock);
816 psli->sli_flag |= LPFC_PROCESS_LA;
817 control = readl(phba->HCregaddr);
818 control |= HC_LAINT_ENA;
819 writel(control, phba->HCregaddr);
820 readl(phba->HCregaddr); /* flush */
821 spin_unlock_irq(phba->host->host_lock);
825 * This routine handles processing a READ_LA mailbox
826 * command upon completion. It is setup in the LPFC_MBOXQ
827 * as the completion routine when the command is
828 * handed off to the SLI layer.
831 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
834 MAILBOX_t *mb = &pmb->mb;
835 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
837 /* Check for error */
839 lpfc_printf_log(phba,
842 "%d:1307 READ_LA mbox error x%x state x%x\n",
844 mb->mbxStatus, phba->hba_state);
845 lpfc_mbx_issue_link_down(phba);
846 phba->hba_state = LPFC_HBA_ERROR;
847 goto lpfc_mbx_cmpl_read_la_free_mbuf;
850 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
852 memcpy(&phba->alpa_map[0], mp->virt, 128);
854 spin_lock_irq(phba->host->host_lock);
856 phba->fc_flag |= FC_BYPASSED_MODE;
858 phba->fc_flag &= ~FC_BYPASSED_MODE;
859 spin_unlock_irq(phba->host->host_lock);
861 if (((phba->fc_eventTag + 1) < la->eventTag) ||
862 (phba->fc_eventTag == la->eventTag)) {
863 phba->fc_stat.LinkMultiEvent++;
864 if (la->attType == AT_LINK_UP) {
865 if (phba->fc_eventTag != 0)
870 phba->fc_eventTag = la->eventTag;
872 if (la->attType == AT_LINK_UP) {
873 phba->fc_stat.LinkUp++;
874 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
875 "%d:1303 Link Up Event x%x received "
876 "Data: x%x x%x x%x x%x\n",
877 phba->brd_no, la->eventTag, phba->fc_eventTag,
878 la->granted_AL_PA, la->UlnkSpeed,
880 lpfc_mbx_process_link_up(phba, la);
882 phba->fc_stat.LinkDown++;
883 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
884 "%d:1305 Link Down Event x%x received "
885 "Data: x%x x%x x%x\n",
886 phba->brd_no, la->eventTag, phba->fc_eventTag,
887 phba->hba_state, phba->fc_flag);
888 lpfc_mbx_issue_link_down(phba);
891 lpfc_mbx_cmpl_read_la_free_mbuf:
892 lpfc_mbuf_free(phba, mp->virt, mp->phys);
894 mempool_free(pmb, phba->mbox_mem_pool);
899 * This routine handles processing a REG_LOGIN mailbox
900 * command upon completion. It is setup in the LPFC_MBOXQ
901 * as the completion routine when the command is
902 * handed off to the SLI layer.
905 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
907 struct lpfc_sli *psli;
909 struct lpfc_dmabuf *mp;
910 struct lpfc_nodelist *ndlp;
915 ndlp = (struct lpfc_nodelist *) pmb->context2;
916 mp = (struct lpfc_dmabuf *) (pmb->context1);
918 pmb->context1 = NULL;
920 /* Good status, call state machine */
921 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
922 lpfc_mbuf_free(phba, mp->virt, mp->phys);
924 mempool_free( pmb, phba->mbox_mem_pool);
930 * This routine handles processing a Fabric REG_LOGIN mailbox
931 * command upon completion. It is setup in the LPFC_MBOXQ
932 * as the completion routine when the command is
933 * handed off to the SLI layer.
936 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
938 struct lpfc_sli *psli;
940 struct lpfc_dmabuf *mp;
941 struct lpfc_nodelist *ndlp;
942 struct lpfc_nodelist *ndlp_fdmi;
948 ndlp = (struct lpfc_nodelist *) pmb->context2;
949 mp = (struct lpfc_dmabuf *) (pmb->context1);
952 lpfc_mbuf_free(phba, mp->virt, mp->phys);
954 mempool_free( pmb, phba->mbox_mem_pool);
955 mempool_free( ndlp, phba->nlp_mem_pool);
957 /* FLOGI failed, so just use loop map to make discovery list */
958 lpfc_disc_list_loopmap(phba);
960 /* Start discovery */
961 lpfc_disc_start(phba);
965 pmb->context1 = NULL;
967 ndlp->nlp_rpi = mb->un.varWords[0];
968 ndlp->nlp_type |= NLP_FABRIC;
969 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
970 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
972 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
973 /* This NPort has been assigned an NPort_ID by the fabric as a
974 * result of the completed fabric login. Issue a State Change
975 * Registration (SCR) ELS request to the fabric controller
976 * (SCR_DID) so that this NPort gets RSCN events from the
979 lpfc_issue_els_scr(phba, SCR_DID, 0);
981 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
983 /* Allocate a new node instance. If the pool is empty,
984 * start the discovery process and skip the Nameserver
985 * login process. This is attempted again later on.
986 * Otherwise, issue a Port Login (PLOGI) to NameServer.
988 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
990 lpfc_disc_start(phba);
991 lpfc_mbuf_free(phba, mp->virt, mp->phys);
993 mempool_free( pmb, phba->mbox_mem_pool);
996 lpfc_nlp_init(phba, ndlp, NameServer_DID);
997 ndlp->nlp_type |= NLP_FABRIC;
1000 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1001 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1002 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
1003 if (phba->cfg_fdmi_on) {
1004 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
1007 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
1008 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1009 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
1010 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
1015 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1017 mempool_free( pmb, phba->mbox_mem_pool);
1022 * This routine handles processing a NameServer REG_LOGIN mailbox
1023 * command upon completion. It is setup in the LPFC_MBOXQ
1024 * as the completion routine when the command is
1025 * handed off to the SLI layer.
1028 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1030 struct lpfc_sli *psli;
1032 struct lpfc_dmabuf *mp;
1033 struct lpfc_nodelist *ndlp;
1038 ndlp = (struct lpfc_nodelist *) pmb->context2;
1039 mp = (struct lpfc_dmabuf *) (pmb->context1);
1041 if (mb->mbxStatus) {
1042 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1044 mempool_free( pmb, phba->mbox_mem_pool);
1045 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1047 /* RegLogin failed, so just use loop map to make discovery
1049 lpfc_disc_list_loopmap(phba);
1051 /* Start discovery */
1052 lpfc_disc_start(phba);
1056 pmb->context1 = NULL;
1058 ndlp->nlp_rpi = mb->un.varWords[0];
1059 ndlp->nlp_type |= NLP_FABRIC;
1060 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1061 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1063 if (phba->hba_state < LPFC_HBA_READY) {
1064 /* Link up discovery requires Fabrib registration. */
1065 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1066 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1067 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1070 phba->fc_ns_retry = 0;
1071 /* Good status, issue CT Request to NameServer */
1072 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1073 /* Cannot issue NameServer Query, so finish up discovery */
1074 lpfc_disc_start(phba);
1077 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1079 mempool_free( pmb, phba->mbox_mem_pool);
1085 lpfc_register_remote_port(struct lpfc_hba * phba,
1086 struct lpfc_nodelist * ndlp)
1088 struct fc_rport *rport;
1089 struct lpfc_rport_data *rdata;
1090 struct fc_rport_identifiers rport_ids;
1092 /* Remote port has reappeared. Re-register w/ FC transport */
1093 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1094 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1095 rport_ids.port_id = ndlp->nlp_DID;
1096 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1098 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1100 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1101 "Warning: fc_remote_port_add failed\n");
1105 /* initialize static port data */
1106 rport->maxframe_size = ndlp->nlp_maxframe;
1107 rport->supported_classes = ndlp->nlp_class_sup;
1108 rdata = rport->dd_data;
1109 rdata->pnode = ndlp;
1111 if (ndlp->nlp_type & NLP_FCP_TARGET)
1112 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1113 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1114 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1117 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1118 fc_remote_port_rolechg(rport, rport_ids.roles);
1120 if ((rport->scsi_target_id != -1) &&
1121 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1122 ndlp->nlp_sid = rport->scsi_target_id;
1129 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1130 struct lpfc_nodelist * ndlp)
1132 struct fc_rport *rport = ndlp->rport;
1133 struct lpfc_rport_data *rdata = rport->dd_data;
1135 if (rport->scsi_target_id == -1) {
1137 rdata->pnode = NULL;
1140 fc_remote_port_delete(rport);
1146 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1148 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1149 struct lpfc_sli *psli;
1152 /* Sanity check to ensure we are not moving to / from the same list */
1153 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1154 if (list != NLP_NO_LIST)
1157 spin_lock_irq(phba->host->host_lock);
1158 switch (nlp->nlp_flag & NLP_LIST_MASK) {
1159 case NLP_NO_LIST: /* Not on any list */
1161 case NLP_UNUSED_LIST:
1162 phba->fc_unused_cnt--;
1163 list_del(&nlp->nlp_listp);
1165 case NLP_PLOGI_LIST:
1166 phba->fc_plogi_cnt--;
1167 list_del(&nlp->nlp_listp);
1169 case NLP_ADISC_LIST:
1170 phba->fc_adisc_cnt--;
1171 list_del(&nlp->nlp_listp);
1173 case NLP_REGLOGIN_LIST:
1174 phba->fc_reglogin_cnt--;
1175 list_del(&nlp->nlp_listp);
1178 phba->fc_prli_cnt--;
1179 list_del(&nlp->nlp_listp);
1181 case NLP_UNMAPPED_LIST:
1182 phba->fc_unmap_cnt--;
1183 list_del(&nlp->nlp_listp);
1184 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1185 nlp->nlp_type &= ~NLP_FC_NODE;
1186 phba->nport_event_cnt++;
1188 rport_del = unmapped;
1190 case NLP_MAPPED_LIST:
1192 list_del(&nlp->nlp_listp);
1193 phba->nport_event_cnt++;
1199 list_del(&nlp->nlp_listp);
1200 /* Stop delay tmo if taking node off NPR list */
1201 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1202 (list != NLP_NPR_LIST)) {
1203 spin_unlock_irq(phba->host->host_lock);
1204 lpfc_cancel_retry_delay_tmo(phba, nlp);
1205 spin_lock_irq(phba->host->host_lock);
1210 nlp->nlp_flag &= ~NLP_LIST_MASK;
1212 /* Add NPort <did> to <num> list */
1213 lpfc_printf_log(phba,
1216 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1218 nlp->nlp_DID, list, nlp->nlp_flag);
1221 case NLP_NO_LIST: /* No list, just remove it */
1222 spin_unlock_irq(phba->host->host_lock);
1223 lpfc_nlp_remove(phba, nlp);
1224 spin_lock_irq(phba->host->host_lock);
1225 /* as node removed - stop further transport calls */
1228 case NLP_UNUSED_LIST:
1229 nlp->nlp_flag |= list;
1230 /* Put it at the end of the unused list */
1231 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1232 phba->fc_unused_cnt++;
1234 case NLP_PLOGI_LIST:
1235 nlp->nlp_flag |= list;
1236 /* Put it at the end of the plogi list */
1237 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1238 phba->fc_plogi_cnt++;
1240 case NLP_ADISC_LIST:
1241 nlp->nlp_flag |= list;
1242 /* Put it at the end of the adisc list */
1243 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1244 phba->fc_adisc_cnt++;
1246 case NLP_REGLOGIN_LIST:
1247 nlp->nlp_flag |= list;
1248 /* Put it at the end of the reglogin list */
1249 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1250 phba->fc_reglogin_cnt++;
1253 nlp->nlp_flag |= list;
1254 /* Put it at the end of the prli list */
1255 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1256 phba->fc_prli_cnt++;
1258 case NLP_UNMAPPED_LIST:
1259 rport_add = unmapped;
1260 /* ensure all vestiges of "mapped" significance are gone */
1261 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1262 nlp->nlp_flag |= list;
1263 /* Put it at the end of the unmap list */
1264 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1265 phba->fc_unmap_cnt++;
1266 phba->nport_event_cnt++;
1267 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1268 nlp->nlp_type |= NLP_FC_NODE;
1270 case NLP_MAPPED_LIST:
1272 nlp->nlp_flag |= list;
1273 /* Put it at the end of the map list */
1274 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1276 phba->nport_event_cnt++;
1277 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1280 nlp->nlp_flag |= list;
1281 /* Put it at the end of the npr list */
1282 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1285 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1291 spin_unlock_irq(phba->host->host_lock);
1294 * We make all the calls into the transport after we have
1295 * moved the node between lists. This so that we don't
1296 * release the lock while in-between lists.
1299 /* Don't upcall midlayer if we're unloading */
1300 if (!(phba->fc_flag & FC_UNLOADING)) {
1302 * We revalidate the rport pointer as the "add" function
1303 * may have removed the remote port.
1305 if ((rport_del != none) && nlp->rport)
1306 lpfc_unregister_remote_port(phba, nlp);
1308 if (rport_add != none) {
1310 * Tell the fc transport about the port, if we haven't
1311 * already. If we have, and it's a scsi entity, be
1312 * sure to unblock any attached scsi devices
1314 if ((!nlp->rport) || (nlp->rport->port_state ==
1315 FC_PORTSTATE_BLOCKED))
1316 lpfc_register_remote_port(phba, nlp);
1319 * if we added to Mapped list, but the remote port
1320 * registration failed or assigned a target id outside
1321 * our presentable range - move the node to the
1324 if ((rport_add == mapped) &&
1326 (nlp->rport->scsi_target_id == -1) ||
1327 (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) {
1328 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1329 spin_lock_irq(phba->host->host_lock);
1330 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1331 spin_unlock_irq(phba->host->host_lock);
1332 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1340 * Start / ReStart rescue timer for Discovery / RSCN handling
1343 lpfc_set_disctmo(struct lpfc_hba * phba)
1347 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1348 /* For FAN, timeout should be greater then edtov */
1349 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1351 /* Normal discovery timeout should be > then ELS/CT timeout
1352 * FC spec states we need 3 * ratov for CT requests
1354 tmo = ((phba->fc_ratov * 3) + 3);
1357 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1358 spin_lock_irq(phba->host->host_lock);
1359 phba->fc_flag |= FC_DISC_TMO;
1360 spin_unlock_irq(phba->host->host_lock);
1362 /* Start Discovery Timer state <hba_state> */
1363 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1364 "%d:0247 Start Discovery Timer state x%x "
1365 "Data: x%x x%lx x%x x%x\n",
1367 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1368 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1374 * Cancel rescue timer for Discovery / RSCN handling
1377 lpfc_can_disctmo(struct lpfc_hba * phba)
1379 /* Turn off discovery timer if its running */
1380 if (phba->fc_flag & FC_DISC_TMO) {
1381 spin_lock_irq(phba->host->host_lock);
1382 phba->fc_flag &= ~FC_DISC_TMO;
1383 spin_unlock_irq(phba->host->host_lock);
1384 del_timer_sync(&phba->fc_disctmo);
1385 phba->work_hba_events &= ~WORKER_DISC_TMO;
1388 /* Cancel Discovery Timer state <hba_state> */
1389 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1390 "%d:0248 Cancel Discovery Timer state x%x "
1391 "Data: x%x x%x x%x\n",
1392 phba->brd_no, phba->hba_state, phba->fc_flag,
1393 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1399 * Check specified ring for outstanding IOCB on the SLI queue
1400 * Return true if iocb matches the specified nport
1403 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1404 struct lpfc_sli_ring * pring,
1405 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1407 struct lpfc_sli *psli;
1412 if (pring->ringno == LPFC_ELS_RING) {
1413 switch (icmd->ulpCommand) {
1414 case CMD_GEN_REQUEST64_CR:
1415 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1417 case CMD_ELS_REQUEST64_CR:
1418 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1420 case CMD_XMIT_ELS_RSP64_CX:
1421 if (iocb->context1 == (uint8_t *) ndlp)
1424 } else if (pring->ringno == psli->ip_ring) {
1426 } else if (pring->ringno == psli->fcp_ring) {
1427 /* Skip match check if waiting to relogin to FCP target */
1428 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1429 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1432 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1435 } else if (pring->ringno == psli->next_ring) {
1442 * Free resources / clean up outstanding I/Os
1443 * associated with nlp_rpi in the LPFC_NODELIST entry.
1446 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1448 struct lpfc_sli *psli;
1449 struct lpfc_sli_ring *pring;
1450 struct lpfc_iocbq *iocb, *next_iocb;
1455 * Everything that matches on txcmplq will be returned
1456 * by firmware with a no rpi error.
1459 rpi = ndlp->nlp_rpi;
1461 /* Now process each ring */
1462 for (i = 0; i < psli->num_rings; i++) {
1463 pring = &psli->ring[i];
1465 spin_lock_irq(phba->host->host_lock);
1466 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1469 * Check to see if iocb matches the nport we are
1472 if ((lpfc_check_sli_ndlp
1473 (phba, pring, iocb, ndlp))) {
1474 /* It matches, so deque and call compl
1476 list_del(&iocb->list);
1478 if (iocb->iocb_cmpl) {
1481 IOSTAT_LOCAL_REJECT;
1482 icmd->un.ulpWord[4] =
1484 spin_unlock_irq(phba->host->
1486 (iocb->iocb_cmpl) (phba,
1488 spin_lock_irq(phba->host->
1491 lpfc_sli_release_iocbq(phba,
1495 spin_unlock_irq(phba->host->host_lock);
1503 * Free rpi associated with LPFC_NODELIST entry.
1504 * This routine is called from lpfc_freenode(), when we are removing
1505 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1506 * LOGO that completes successfully, and we are waiting to PLOGI back
1507 * to the remote NPort. In addition, it is called after we receive
1508 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1509 * we are waiting to PLOGI back to the remote NPort.
1512 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1517 if (ndlp->nlp_rpi) {
1518 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1519 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1520 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1521 rc = lpfc_sli_issue_mbox
1522 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1523 if (rc == MBX_NOT_FINISHED)
1524 mempool_free( mbox, phba->mbox_mem_pool);
1526 lpfc_no_rpi(phba, ndlp);
1534 * Free resources associated with LPFC_NODELIST entry
1535 * so it can be freed.
1538 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1541 LPFC_MBOXQ_t *nextmb;
1542 struct lpfc_dmabuf *mp;
1544 /* Cleanup node for NPort <nlp_DID> */
1545 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1546 "%d:0900 Cleanup node for NPort x%x "
1547 "Data: x%x x%x x%x\n",
1548 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1549 ndlp->nlp_state, ndlp->nlp_rpi);
1551 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1554 * if unloading the driver - just leave the remote port in place.
1555 * The driver unload will force the attached devices to detach
1556 * and flush cache's w/o generating flush errors.
1558 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1559 lpfc_unregister_remote_port(phba, ndlp);
1560 ndlp->nlp_sid = NLP_NO_SID;
1563 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1564 if ((mb = phba->sli.mbox_active)) {
1565 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1566 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1567 mb->context2 = NULL;
1568 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1572 spin_lock_irq(phba->host->host_lock);
1573 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1574 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1575 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1576 mp = (struct lpfc_dmabuf *) (mb->context1);
1578 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1581 list_del(&mb->list);
1582 mempool_free(mb, phba->mbox_mem_pool);
1585 spin_unlock_irq(phba->host->host_lock);
1587 lpfc_els_abort(phba,ndlp,0);
1588 spin_lock_irq(phba->host->host_lock);
1589 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1590 spin_unlock_irq(phba->host->host_lock);
1592 ndlp->nlp_last_elscmd = 0;
1593 del_timer_sync(&ndlp->nlp_delayfunc);
1595 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1596 list_del_init(&ndlp->els_retry_evt.evt_listp);
1598 lpfc_unreg_rpi(phba, ndlp);
1604 * Check to see if we can free the nlp back to the freelist.
1605 * If we are in the middle of using the nlp in the discovery state
1606 * machine, defer the free till we reach the end of the state machine.
1609 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1612 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1613 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1616 if (ndlp->nlp_disc_refcnt) {
1617 spin_lock_irq(phba->host->host_lock);
1618 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1619 spin_unlock_irq(phba->host->host_lock);
1621 lpfc_freenode(phba, ndlp);
1622 mempool_free( ndlp, phba->nlp_mem_pool);
1628 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1634 if (did == Bcast_DID)
1637 if (ndlp->nlp_DID == 0) {
1641 /* First check for Direct match */
1642 if (ndlp->nlp_DID == did)
1645 /* Next check for area/domain identically equals 0 match */
1646 mydid.un.word = phba->fc_myDID;
1647 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1651 matchdid.un.word = did;
1652 ndlpdid.un.word = ndlp->nlp_DID;
1653 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1654 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1655 (mydid.un.b.area == matchdid.un.b.area)) {
1656 if ((ndlpdid.un.b.domain == 0) &&
1657 (ndlpdid.un.b.area == 0)) {
1658 if (ndlpdid.un.b.id)
1664 matchdid.un.word = ndlp->nlp_DID;
1665 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1666 (mydid.un.b.area == ndlpdid.un.b.area)) {
1667 if ((matchdid.un.b.domain == 0) &&
1668 (matchdid.un.b.area == 0)) {
1669 if (matchdid.un.b.id)
1677 /* Search for a nodelist entry on a specific list */
1678 struct lpfc_nodelist *
1679 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1681 struct lpfc_nodelist *ndlp, *next_ndlp;
1684 spin_lock_irq(phba->host->host_lock);
1685 if (order & NLP_SEARCH_UNMAPPED) {
1686 list_for_each_entry_safe(ndlp, next_ndlp,
1687 &phba->fc_nlpunmap_list, nlp_listp) {
1688 if (lpfc_matchdid(phba, ndlp, did)) {
1689 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1690 ((uint32_t) ndlp->nlp_xri << 16) |
1691 ((uint32_t) ndlp->nlp_type << 8) |
1692 ((uint32_t) ndlp->nlp_rpi & 0xff));
1693 /* FIND node DID unmapped */
1694 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1695 "%d:0929 FIND node DID unmapped"
1696 " Data: x%p x%x x%x x%x\n",
1698 ndlp, ndlp->nlp_DID,
1699 ndlp->nlp_flag, data1);
1700 spin_unlock_irq(phba->host->host_lock);
1706 if (order & NLP_SEARCH_MAPPED) {
1707 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1709 if (lpfc_matchdid(phba, ndlp, did)) {
1711 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1712 ((uint32_t) ndlp->nlp_xri << 16) |
1713 ((uint32_t) ndlp->nlp_type << 8) |
1714 ((uint32_t) ndlp->nlp_rpi & 0xff));
1715 /* FIND node DID mapped */
1716 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1717 "%d:0930 FIND node DID mapped "
1718 "Data: x%p x%x x%x x%x\n",
1720 ndlp, ndlp->nlp_DID,
1721 ndlp->nlp_flag, data1);
1722 spin_unlock_irq(phba->host->host_lock);
1728 if (order & NLP_SEARCH_PLOGI) {
1729 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1731 if (lpfc_matchdid(phba, ndlp, did)) {
1733 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1734 ((uint32_t) ndlp->nlp_xri << 16) |
1735 ((uint32_t) ndlp->nlp_type << 8) |
1736 ((uint32_t) ndlp->nlp_rpi & 0xff));
1737 /* LOG change to PLOGI */
1738 /* FIND node DID plogi */
1739 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1740 "%d:0908 FIND node DID plogi "
1741 "Data: x%p x%x x%x x%x\n",
1743 ndlp, ndlp->nlp_DID,
1744 ndlp->nlp_flag, data1);
1745 spin_unlock_irq(phba->host->host_lock);
1751 if (order & NLP_SEARCH_ADISC) {
1752 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1754 if (lpfc_matchdid(phba, ndlp, did)) {
1756 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1757 ((uint32_t) ndlp->nlp_xri << 16) |
1758 ((uint32_t) ndlp->nlp_type << 8) |
1759 ((uint32_t) ndlp->nlp_rpi & 0xff));
1760 /* LOG change to ADISC */
1761 /* FIND node DID adisc */
1762 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1763 "%d:0931 FIND node DID adisc "
1764 "Data: x%p x%x x%x x%x\n",
1766 ndlp, ndlp->nlp_DID,
1767 ndlp->nlp_flag, data1);
1768 spin_unlock_irq(phba->host->host_lock);
1774 if (order & NLP_SEARCH_REGLOGIN) {
1775 list_for_each_entry_safe(ndlp, next_ndlp,
1776 &phba->fc_reglogin_list, nlp_listp) {
1777 if (lpfc_matchdid(phba, ndlp, did)) {
1779 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1780 ((uint32_t) ndlp->nlp_xri << 16) |
1781 ((uint32_t) ndlp->nlp_type << 8) |
1782 ((uint32_t) ndlp->nlp_rpi & 0xff));
1783 /* LOG change to REGLOGIN */
1784 /* FIND node DID reglogin */
1785 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1786 "%d:0901 FIND node DID reglogin"
1787 " Data: x%p x%x x%x x%x\n",
1789 ndlp, ndlp->nlp_DID,
1790 ndlp->nlp_flag, data1);
1791 spin_unlock_irq(phba->host->host_lock);
1797 if (order & NLP_SEARCH_PRLI) {
1798 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1800 if (lpfc_matchdid(phba, ndlp, did)) {
1802 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1803 ((uint32_t) ndlp->nlp_xri << 16) |
1804 ((uint32_t) ndlp->nlp_type << 8) |
1805 ((uint32_t) ndlp->nlp_rpi & 0xff));
1806 /* LOG change to PRLI */
1807 /* FIND node DID prli */
1808 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1809 "%d:0902 FIND node DID prli "
1810 "Data: x%p x%x x%x x%x\n",
1812 ndlp, ndlp->nlp_DID,
1813 ndlp->nlp_flag, data1);
1814 spin_unlock_irq(phba->host->host_lock);
1820 if (order & NLP_SEARCH_NPR) {
1821 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1823 if (lpfc_matchdid(phba, ndlp, did)) {
1825 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1826 ((uint32_t) ndlp->nlp_xri << 16) |
1827 ((uint32_t) ndlp->nlp_type << 8) |
1828 ((uint32_t) ndlp->nlp_rpi & 0xff));
1829 /* LOG change to NPR */
1830 /* FIND node DID npr */
1831 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1832 "%d:0903 FIND node DID npr "
1833 "Data: x%p x%x x%x x%x\n",
1835 ndlp, ndlp->nlp_DID,
1836 ndlp->nlp_flag, data1);
1837 spin_unlock_irq(phba->host->host_lock);
1843 if (order & NLP_SEARCH_UNUSED) {
1844 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1846 if (lpfc_matchdid(phba, ndlp, did)) {
1848 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1849 ((uint32_t) ndlp->nlp_xri << 16) |
1850 ((uint32_t) ndlp->nlp_type << 8) |
1851 ((uint32_t) ndlp->nlp_rpi & 0xff));
1852 /* LOG change to UNUSED */
1853 /* FIND node DID unused */
1854 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1855 "%d:0905 FIND node DID unused "
1856 "Data: x%p x%x x%x x%x\n",
1858 ndlp, ndlp->nlp_DID,
1859 ndlp->nlp_flag, data1);
1860 spin_unlock_irq(phba->host->host_lock);
1866 spin_unlock_irq(phba->host->host_lock);
1868 /* FIND node did <did> NOT FOUND */
1869 lpfc_printf_log(phba,
1872 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1873 phba->brd_no, did, order);
1875 /* no match found */
1879 struct lpfc_nodelist *
1880 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1882 struct lpfc_nodelist *ndlp;
1885 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1887 if ((phba->fc_flag & FC_RSCN_MODE) &&
1888 ((lpfc_rscn_payload_check(phba, did) == 0)))
1890 ndlp = (struct lpfc_nodelist *)
1891 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1894 lpfc_nlp_init(phba, ndlp, did);
1895 ndlp->nlp_state = NLP_STE_NPR_NODE;
1896 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1897 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1900 if (phba->fc_flag & FC_RSCN_MODE) {
1901 if (lpfc_rscn_payload_check(phba, did)) {
1902 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1904 /* Since this node is marked for discovery,
1905 * delay timeout is not needed.
1907 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1908 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1912 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1913 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1915 ndlp->nlp_state = NLP_STE_NPR_NODE;
1916 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1917 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1922 /* Build a list of nodes to discover based on the loopmap */
1924 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1927 uint32_t alpa, index;
1929 if (phba->hba_state <= LPFC_LINK_DOWN) {
1932 if (phba->fc_topology != TOPOLOGY_LOOP) {
1936 /* Check for loop map present or not */
1937 if (phba->alpa_map[0]) {
1938 for (j = 1; j <= phba->alpa_map[0]; j++) {
1939 alpa = phba->alpa_map[j];
1941 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1944 lpfc_setup_disc_node(phba, alpa);
1947 /* No alpamap, so try all alpa's */
1948 for (j = 0; j < FC_MAXLOOP; j++) {
1949 /* If cfg_scan_down is set, start from highest
1950 * ALPA (0xef) to lowest (0x1).
1952 if (phba->cfg_scan_down)
1955 index = FC_MAXLOOP - j - 1;
1956 alpa = lpfcAlpaArray[index];
1957 if ((phba->fc_myDID & 0xff) == alpa) {
1961 lpfc_setup_disc_node(phba, alpa);
1967 /* Start Link up / RSCN discovery on NPR list */
1969 lpfc_disc_start(struct lpfc_hba * phba)
1971 struct lpfc_sli *psli;
1973 struct lpfc_nodelist *ndlp, *next_ndlp;
1974 uint32_t did_changed, num_sent;
1975 uint32_t clear_la_pending;
1980 if (phba->hba_state <= LPFC_LINK_DOWN) {
1983 if (phba->hba_state == LPFC_CLEAR_LA)
1984 clear_la_pending = 1;
1986 clear_la_pending = 0;
1988 if (phba->hba_state < LPFC_HBA_READY) {
1989 phba->hba_state = LPFC_DISC_AUTH;
1991 lpfc_set_disctmo(phba);
1993 if (phba->fc_prevDID == phba->fc_myDID) {
1998 phba->fc_prevDID = phba->fc_myDID;
1999 phba->num_disc_nodes = 0;
2001 /* Start Discovery state <hba_state> */
2002 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2003 "%d:0202 Start Discovery hba state x%x "
2004 "Data: x%x x%x x%x\n",
2005 phba->brd_no, phba->hba_state, phba->fc_flag,
2006 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2008 /* If our did changed, we MUST do PLOGI */
2009 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2011 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2013 spin_lock_irq(phba->host->host_lock);
2014 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2015 spin_unlock_irq(phba->host->host_lock);
2020 /* First do ADISCs - if any */
2021 num_sent = lpfc_els_disc_adisc(phba);
2026 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2027 /* If we get here, there is nothing to ADISC */
2028 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2029 phba->hba_state = LPFC_CLEAR_LA;
2030 lpfc_clear_la(phba, mbox);
2031 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2032 rc = lpfc_sli_issue_mbox(phba, mbox,
2033 (MBX_NOWAIT | MBX_STOP_IOCB));
2034 if (rc == MBX_NOT_FINISHED) {
2035 mempool_free( mbox, phba->mbox_mem_pool);
2036 lpfc_disc_flush_list(phba);
2037 psli->ring[(psli->ip_ring)].flag &=
2038 ~LPFC_STOP_IOCB_EVENT;
2039 psli->ring[(psli->fcp_ring)].flag &=
2040 ~LPFC_STOP_IOCB_EVENT;
2041 psli->ring[(psli->next_ring)].flag &=
2042 ~LPFC_STOP_IOCB_EVENT;
2043 phba->hba_state = LPFC_HBA_READY;
2047 /* Next do PLOGIs - if any */
2048 num_sent = lpfc_els_disc_plogi(phba);
2053 if (phba->fc_flag & FC_RSCN_MODE) {
2054 /* Check to see if more RSCNs came in while we
2055 * were processing this one.
2057 if ((phba->fc_rscn_id_cnt == 0) &&
2058 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2059 spin_lock_irq(phba->host->host_lock);
2060 phba->fc_flag &= ~FC_RSCN_MODE;
2061 spin_unlock_irq(phba->host->host_lock);
2063 lpfc_els_handle_rscn(phba);
2070 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2071 * ring the match the sppecified nodelist.
2074 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2076 struct lpfc_sli *psli;
2078 struct lpfc_iocbq *iocb, *next_iocb;
2079 struct lpfc_sli_ring *pring;
2080 struct lpfc_dmabuf *mp;
2083 pring = &psli->ring[LPFC_ELS_RING];
2085 /* Error matching iocb on txq or txcmplq
2086 * First check the txq.
2088 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2089 if (iocb->context1 != ndlp) {
2093 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2094 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2096 list_del(&iocb->list);
2098 lpfc_els_free_iocb(phba, iocb);
2102 /* Next check the txcmplq */
2103 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2104 if (iocb->context1 != ndlp) {
2108 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2109 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2111 iocb->iocb_cmpl = NULL;
2112 /* context2 = cmd, context2->next = rsp, context3 =
2114 if (iocb->context2) {
2115 /* Free the response IOCB before handling the
2118 mp = (struct lpfc_dmabuf *) (iocb->context2);
2119 mp = list_get_first(&mp->list,
2123 /* Delay before releasing rsp buffer to
2124 * give UNREG mbox a chance to take
2128 &phba->freebufList);
2130 lpfc_mbuf_free(phba,
2131 ((struct lpfc_dmabuf *)
2132 iocb->context2)->virt,
2133 ((struct lpfc_dmabuf *)
2134 iocb->context2)->phys);
2135 kfree(iocb->context2);
2138 if (iocb->context3) {
2139 lpfc_mbuf_free(phba,
2140 ((struct lpfc_dmabuf *)
2141 iocb->context3)->virt,
2142 ((struct lpfc_dmabuf *)
2143 iocb->context3)->phys);
2144 kfree(iocb->context3);
2153 lpfc_disc_flush_list(struct lpfc_hba * phba)
2155 struct lpfc_nodelist *ndlp, *next_ndlp;
2157 if (phba->fc_plogi_cnt) {
2158 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2160 lpfc_free_tx(phba, ndlp);
2161 lpfc_nlp_remove(phba, ndlp);
2164 if (phba->fc_adisc_cnt) {
2165 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2167 lpfc_free_tx(phba, ndlp);
2168 lpfc_nlp_remove(phba, ndlp);
2174 /*****************************************************************************/
2176 * NAME: lpfc_disc_timeout
2178 * FUNCTION: Fibre Channel driver discovery timeout routine.
2180 * EXECUTION ENVIRONMENT: interrupt only
2188 /*****************************************************************************/
2190 lpfc_disc_timeout(unsigned long ptr)
2192 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2193 unsigned long flags = 0;
2195 if (unlikely(!phba))
2198 spin_lock_irqsave(phba->host->host_lock, flags);
2199 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2200 phba->work_hba_events |= WORKER_DISC_TMO;
2201 if (phba->work_wait)
2202 wake_up(phba->work_wait);
2204 spin_unlock_irqrestore(phba->host->host_lock, flags);
2209 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2211 struct lpfc_sli *psli;
2212 struct lpfc_nodelist *ndlp, *next_ndlp;
2213 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2214 int rc, clrlaerr = 0;
2216 if (unlikely(!phba))
2219 if (!(phba->fc_flag & FC_DISC_TMO))
2224 spin_lock_irq(phba->host->host_lock);
2225 phba->fc_flag &= ~FC_DISC_TMO;
2226 spin_unlock_irq(phba->host->host_lock);
2228 switch (phba->hba_state) {
2230 case LPFC_LOCAL_CFG_LINK:
2231 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2233 lpfc_printf_log(phba,
2236 "%d:0221 FAN timeout\n",
2239 /* Start discovery by sending FLOGI, clean up old rpis */
2240 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2242 if (ndlp->nlp_type & NLP_FABRIC) {
2243 /* Clean up the ndlp on Fabric connections */
2244 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2245 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2246 /* Fail outstanding IO now since device
2247 * is marked for PLOGI.
2249 lpfc_unreg_rpi(phba, ndlp);
2252 phba->hba_state = LPFC_FLOGI;
2253 lpfc_set_disctmo(phba);
2254 lpfc_initial_flogi(phba);
2258 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2259 /* Initial FLOGI timeout */
2260 lpfc_printf_log(phba,
2263 "%d:0222 Initial FLOGI timeout\n",
2266 /* Assume no Fabric and go on with discovery.
2267 * Check for outstanding ELS FLOGI to abort.
2270 /* FLOGI failed, so just use loop map to make discovery list */
2271 lpfc_disc_list_loopmap(phba);
2273 /* Start discovery */
2274 lpfc_disc_start(phba);
2277 case LPFC_FABRIC_CFG_LINK:
2278 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2280 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2281 "%d:0223 Timeout while waiting for NameServer "
2282 "login\n", phba->brd_no);
2284 /* Next look for NameServer ndlp */
2285 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2287 lpfc_nlp_remove(phba, ndlp);
2288 /* Start discovery */
2289 lpfc_disc_start(phba);
2293 /* Check for wait for NameServer Rsp timeout */
2294 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2295 "%d:0224 NameServer Query timeout "
2298 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2300 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2303 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2304 /* Try it one more time */
2305 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2309 phba->fc_ns_retry = 0;
2312 /* Nothing to authenticate, so CLEAR_LA right now */
2313 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2316 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2317 "%d:0226 Device Discovery "
2318 "completion error\n",
2320 phba->hba_state = LPFC_HBA_ERROR;
2324 phba->hba_state = LPFC_CLEAR_LA;
2325 lpfc_clear_la(phba, clearlambox);
2326 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2327 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2328 (MBX_NOWAIT | MBX_STOP_IOCB));
2329 if (rc == MBX_NOT_FINISHED) {
2330 mempool_free(clearlambox, phba->mbox_mem_pool);
2335 /* Setup and issue mailbox INITIALIZE LINK command */
2336 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2337 if (!initlinkmbox) {
2338 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2339 "%d:0206 Device Discovery "
2340 "completion error\n",
2342 phba->hba_state = LPFC_HBA_ERROR;
2346 lpfc_linkdown(phba);
2347 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2348 phba->cfg_link_speed);
2349 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2350 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2351 (MBX_NOWAIT | MBX_STOP_IOCB));
2352 if (rc == MBX_NOT_FINISHED)
2353 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2357 case LPFC_DISC_AUTH:
2358 /* Node Authentication timeout */
2359 lpfc_printf_log(phba,
2362 "%d:0227 Node Authentication timeout\n",
2364 lpfc_disc_flush_list(phba);
2365 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2368 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2369 "%d:0207 Device Discovery "
2370 "completion error\n",
2372 phba->hba_state = LPFC_HBA_ERROR;
2375 phba->hba_state = LPFC_CLEAR_LA;
2376 lpfc_clear_la(phba, clearlambox);
2377 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2378 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2379 (MBX_NOWAIT | MBX_STOP_IOCB));
2380 if (rc == MBX_NOT_FINISHED) {
2381 mempool_free(clearlambox, phba->mbox_mem_pool);
2387 /* CLEAR LA timeout */
2388 lpfc_printf_log(phba,
2391 "%d:0228 CLEAR LA timeout\n",
2396 case LPFC_HBA_READY:
2397 if (phba->fc_flag & FC_RSCN_MODE) {
2398 lpfc_printf_log(phba,
2401 "%d:0231 RSCN timeout Data: x%x x%x\n",
2403 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2405 /* Cleanup any outstanding ELS commands */
2406 lpfc_els_flush_cmd(phba);
2408 lpfc_els_flush_rscn(phba);
2409 lpfc_disc_flush_list(phba);
2415 lpfc_disc_flush_list(phba);
2416 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2417 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2418 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2419 phba->hba_state = LPFC_HBA_READY;
2426 * This routine handles processing a NameServer REG_LOGIN mailbox
2427 * command upon completion. It is setup in the LPFC_MBOXQ
2428 * as the completion routine when the command is
2429 * handed off to the SLI layer.
2432 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2434 struct lpfc_sli *psli;
2436 struct lpfc_dmabuf *mp;
2437 struct lpfc_nodelist *ndlp;
2442 ndlp = (struct lpfc_nodelist *) pmb->context2;
2443 mp = (struct lpfc_dmabuf *) (pmb->context1);
2445 pmb->context1 = NULL;
2447 ndlp->nlp_rpi = mb->un.varWords[0];
2448 ndlp->nlp_type |= NLP_FABRIC;
2449 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2450 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2452 /* Start issuing Fabric-Device Management Interface (FDMI)
2453 * command to 0xfffffa (FDMI well known port)
2455 if (phba->cfg_fdmi_on == 1) {
2456 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2459 * Delay issuing FDMI command if fdmi-on=2
2460 * (supporting RPA/hostnmae)
2462 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2465 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2467 mempool_free( pmb, phba->mbox_mem_pool);
2473 * This routine looks up the ndlp lists
2474 * for the given RPI. If rpi found
2475 * it return the node list pointer
2478 struct lpfc_nodelist *
2479 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2481 struct lpfc_nodelist *ndlp;
2482 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2483 &phba->fc_nlpmap_list,
2484 &phba->fc_plogi_list,
2485 &phba->fc_adisc_list,
2486 &phba->fc_reglogin_list};
2489 spin_lock_irq(phba->host->host_lock);
2490 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2491 list_for_each_entry(ndlp, lists[i], nlp_listp)
2492 if (ndlp->nlp_rpi == rpi) {
2493 spin_unlock_irq(phba->host->host_lock);
2496 spin_unlock_irq(phba->host->host_lock);
2501 * This routine looks up the ndlp lists
2502 * for the given WWPN. If WWPN found
2503 * it return the node list pointer
2506 struct lpfc_nodelist *
2507 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2508 struct lpfc_name * wwpn)
2510 struct lpfc_nodelist *ndlp;
2511 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2512 &phba->fc_nlpmap_list,
2514 &phba->fc_plogi_list,
2515 &phba->fc_adisc_list,
2516 &phba->fc_reglogin_list,
2517 &phba->fc_prli_list};
2518 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2523 NLP_SEARCH_REGLOGIN,
2527 spin_lock_irq(phba->host->host_lock);
2528 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2529 if (!(order & search[i]))
2531 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2532 if (memcmp(&ndlp->nlp_portname, wwpn,
2533 sizeof(struct lpfc_name)) == 0) {
2534 spin_unlock_irq(phba->host->host_lock);
2539 spin_unlock_irq(phba->host->host_lock);
2544 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2547 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2548 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2549 init_timer(&ndlp->nlp_delayfunc);
2550 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2551 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2552 ndlp->nlp_DID = did;
2553 ndlp->nlp_phba = phba;
2554 ndlp->nlp_sid = NLP_NO_SID;