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_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
62 uint8_t *name = (uint8_t *)&ndlp->nlp_portname;
65 spin_lock_irq(phba->host->host_lock);
66 if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
67 spin_unlock_irq(phba->host->host_lock);
71 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
73 if (ndlp->nlp_sid != NLP_NO_SID) {
75 /* flush the target */
76 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
77 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
79 spin_unlock_irq(phba->host->host_lock);
82 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
83 "%d:0203 Nodev timeout on "
84 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
85 "NPort x%x Data: x%x x%x x%x\n",
87 *name, *(name+1), *(name+2), *(name+3),
88 *(name+4), *(name+5), *(name+6), *(name+7),
89 ndlp->nlp_DID, ndlp->nlp_flag,
90 ndlp->nlp_state, ndlp->nlp_rpi);
92 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
93 "%d:0204 Nodev timeout on "
94 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
95 "NPort x%x Data: x%x x%x x%x\n",
97 *name, *(name+1), *(name+2), *(name+3),
98 *(name+4), *(name+5), *(name+6), *(name+7),
99 ndlp->nlp_DID, ndlp->nlp_flag,
100 ndlp->nlp_state, ndlp->nlp_rpi);
103 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
108 lpfc_work_list_done(struct lpfc_hba * phba)
110 struct lpfc_work_evt *evtp = NULL;
111 struct lpfc_nodelist *ndlp;
114 spin_lock_irq(phba->host->host_lock);
115 while(!list_empty(&phba->work_list)) {
116 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
118 spin_unlock_irq(phba->host->host_lock);
121 case LPFC_EVT_NODEV_TMO:
122 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
123 lpfc_process_nodev_timeout(phba, ndlp);
126 case LPFC_EVT_ELS_RETRY:
127 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
128 lpfc_els_retry_delay_handler(ndlp);
131 case LPFC_EVT_ONLINE:
132 if (phba->hba_state < LPFC_LINK_DOWN)
133 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
135 *(int *)(evtp->evt_arg1) = 0;
136 complete((struct completion *)(evtp->evt_arg2));
138 case LPFC_EVT_OFFLINE:
139 if (phba->hba_state >= LPFC_LINK_DOWN)
141 lpfc_sli_brdrestart(phba);
142 *(int *)(evtp->evt_arg1) =
143 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
144 complete((struct completion *)(evtp->evt_arg2));
146 case LPFC_EVT_WARM_START:
147 if (phba->hba_state >= LPFC_LINK_DOWN)
149 lpfc_sli_brdreset(phba);
150 lpfc_hba_down_post(phba);
151 *(int *)(evtp->evt_arg1) =
152 lpfc_sli_brdready(phba, HS_MBRDY);
153 complete((struct completion *)(evtp->evt_arg2));
156 if (phba->hba_state >= LPFC_LINK_DOWN)
158 *(int *)(evtp->evt_arg1) = lpfc_sli_brdkill(phba);
159 complete((struct completion *)(evtp->evt_arg2));
164 spin_lock_irq(phba->host->host_lock);
166 spin_unlock_irq(phba->host->host_lock);
171 lpfc_work_done(struct lpfc_hba * phba)
173 struct lpfc_sli_ring *pring;
177 uint32_t work_hba_events;
179 spin_lock_irq(phba->host->host_lock);
180 ha_copy = phba->work_ha;
182 work_hba_events=phba->work_hba_events;
183 spin_unlock_irq(phba->host->host_lock);
185 if (ha_copy & HA_ERATT)
186 lpfc_handle_eratt(phba);
188 if (ha_copy & HA_MBATT)
189 lpfc_sli_handle_mb_event(phba);
191 if (ha_copy & HA_LATT)
192 lpfc_handle_latt(phba);
194 if (work_hba_events & WORKER_DISC_TMO)
195 lpfc_disc_timeout_handler(phba);
197 if (work_hba_events & WORKER_ELS_TMO)
198 lpfc_els_timeout_handler(phba);
200 if (work_hba_events & WORKER_MBOX_TMO)
201 lpfc_mbox_timeout_handler(phba);
203 if (work_hba_events & WORKER_FDMI_TMO)
204 lpfc_fdmi_tmo_handler(phba);
206 spin_lock_irq(phba->host->host_lock);
207 phba->work_hba_events &= ~work_hba_events;
208 spin_unlock_irq(phba->host->host_lock);
210 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
211 pring = &phba->sli.ring[i];
212 if ((ha_copy & HA_RXATT)
213 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
214 if (pring->flag & LPFC_STOP_IOCB_MASK) {
215 pring->flag |= LPFC_DEFERRED_RING_EVENT;
217 lpfc_sli_handle_slow_ring_event(phba, pring,
220 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
223 * Turn on Ring interrupts
225 spin_lock_irq(phba->host->host_lock);
226 control = readl(phba->HCregaddr);
227 control |= (HC_R0INT_ENA << i);
228 writel(control, phba->HCregaddr);
229 readl(phba->HCregaddr); /* flush */
230 spin_unlock_irq(phba->host->host_lock);
234 lpfc_work_list_done (phba);
239 check_work_wait_done(struct lpfc_hba *phba) {
241 spin_lock_irq(phba->host->host_lock);
243 phba->work_hba_events ||
244 (!list_empty(&phba->work_list)) ||
245 kthread_should_stop()) {
246 spin_unlock_irq(phba->host->host_lock);
249 spin_unlock_irq(phba->host->host_lock);
255 lpfc_do_work(void *p)
257 struct lpfc_hba *phba = p;
259 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
261 set_user_nice(current, -20);
262 phba->work_wait = &work_waitq;
266 rc = wait_event_interruptible(work_waitq,
267 check_work_wait_done(phba));
270 if (kthread_should_stop())
273 lpfc_work_done(phba);
276 phba->work_wait = NULL;
281 * This is only called to handle FC worker events. Since this a rare
282 * occurance, we allocate a struct lpfc_work_evt structure here instead of
283 * embedding it in the IOCB.
286 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
289 struct lpfc_work_evt *evtp;
292 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
293 * be queued to worker thread for processing
295 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
299 evtp->evt_arg1 = arg1;
300 evtp->evt_arg2 = arg2;
303 list_add_tail(&evtp->evt_listp, &phba->work_list);
304 spin_lock_irq(phba->host->host_lock);
306 wake_up(phba->work_wait);
307 spin_unlock_irq(phba->host->host_lock);
313 lpfc_linkdown(struct lpfc_hba * phba)
315 struct lpfc_sli *psli;
316 struct lpfc_nodelist *ndlp, *next_ndlp;
317 struct list_head *listp, *node_list[7];
322 /* sysfs or selective reset may call this routine to clean up */
323 if (phba->hba_state >= LPFC_LINK_DOWN) {
324 if (phba->hba_state == LPFC_LINK_DOWN)
327 spin_lock_irq(phba->host->host_lock);
328 phba->hba_state = LPFC_LINK_DOWN;
329 spin_unlock_irq(phba->host->host_lock);
332 /* Clean up any firmware default rpi's */
333 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
334 lpfc_unreg_did(phba, 0xffffffff, mb);
335 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
336 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
337 == MBX_NOT_FINISHED) {
338 mempool_free( mb, phba->mbox_mem_pool);
342 /* Cleanup any outstanding RSCN activity */
343 lpfc_els_flush_rscn(phba);
345 /* Cleanup any outstanding ELS commands */
346 lpfc_els_flush_cmd(phba);
348 /* Issue a LINK DOWN event to all nodes */
349 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
350 node_list[1] = &phba->fc_nlpmap_list;
351 node_list[2] = &phba->fc_nlpunmap_list;
352 node_list[3] = &phba->fc_prli_list;
353 node_list[4] = &phba->fc_reglogin_list;
354 node_list[5] = &phba->fc_adisc_list;
355 node_list[6] = &phba->fc_plogi_list;
356 for (i = 0; i < 7; i++) {
357 listp = node_list[i];
358 if (list_empty(listp))
361 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
363 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
364 NLP_EVT_DEVICE_RECOVERY);
366 /* Check config parameter use-adisc or FCP-2 */
367 if ((rc != NLP_STE_FREED_NODE) &&
368 (phba->cfg_use_adisc == 0) &&
369 !(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) {
370 /* We know we will have to relogin, so
371 * unreglogin the rpi right now to fail
372 * any outstanding I/Os quickly.
374 lpfc_unreg_rpi(phba, ndlp);
379 /* free any ndlp's on unused list */
380 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
382 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
385 /* Setup myDID for link up if we are in pt2pt mode */
386 if (phba->fc_flag & FC_PT2PT) {
388 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
389 lpfc_config_link(phba, mb);
390 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
391 if (lpfc_sli_issue_mbox
392 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
393 == MBX_NOT_FINISHED) {
394 mempool_free( mb, phba->mbox_mem_pool);
397 spin_lock_irq(phba->host->host_lock);
398 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
399 spin_unlock_irq(phba->host->host_lock);
401 spin_lock_irq(phba->host->host_lock);
402 phba->fc_flag &= ~FC_LBIT;
403 spin_unlock_irq(phba->host->host_lock);
405 /* Turn off discovery timer if its running */
406 lpfc_can_disctmo(phba);
408 /* Must process IOCBs on all rings to handle ABORTed I/Os */
413 lpfc_linkup(struct lpfc_hba * phba)
415 struct lpfc_nodelist *ndlp, *next_ndlp;
416 struct list_head *listp, *node_list[7];
419 spin_lock_irq(phba->host->host_lock);
420 phba->hba_state = LPFC_LINK_UP;
421 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
422 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
423 phba->fc_flag |= FC_NDISC_ACTIVE;
424 phba->fc_ns_retry = 0;
425 spin_unlock_irq(phba->host->host_lock);
428 node_list[0] = &phba->fc_plogi_list;
429 node_list[1] = &phba->fc_adisc_list;
430 node_list[2] = &phba->fc_reglogin_list;
431 node_list[3] = &phba->fc_prli_list;
432 node_list[4] = &phba->fc_nlpunmap_list;
433 node_list[5] = &phba->fc_nlpmap_list;
434 node_list[6] = &phba->fc_npr_list;
435 for (i = 0; i < 7; i++) {
436 listp = node_list[i];
437 if (list_empty(listp))
440 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
441 if (phba->fc_flag & FC_LBIT) {
442 if (ndlp->nlp_type & NLP_FABRIC) {
443 /* On Linkup its safe to clean up the
444 * ndlp from Fabric connections.
446 lpfc_nlp_list(phba, ndlp,
448 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
449 /* Fail outstanding IO now since device
450 * is marked for PLOGI.
452 lpfc_unreg_rpi(phba, ndlp);
458 /* free any ndlp's on unused list */
459 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
461 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
468 * This routine handles processing a CLEAR_LA mailbox
469 * command upon completion. It is setup in the LPFC_MBOXQ
470 * as the completion routine when the command is
471 * handed off to the SLI layer.
474 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
476 struct lpfc_sli *psli;
482 /* Since we don't do discovery right now, turn these off here */
483 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
484 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
485 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
487 /* Check for error */
488 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
489 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
490 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
491 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
493 phba->brd_no, mb->mbxStatus, phba->hba_state);
495 phba->hba_state = LPFC_HBA_ERROR;
499 if (phba->fc_flag & FC_ABORT_DISCOVERY)
502 phba->num_disc_nodes = 0;
503 /* go thru NPR list and issue ELS PLOGIs */
504 if (phba->fc_npr_cnt) {
505 lpfc_els_disc_plogi(phba);
508 if (!phba->num_disc_nodes) {
509 spin_lock_irq(phba->host->host_lock);
510 phba->fc_flag &= ~FC_NDISC_ACTIVE;
511 spin_unlock_irq(phba->host->host_lock);
514 phba->hba_state = LPFC_HBA_READY;
517 /* Device Discovery completes */
518 lpfc_printf_log(phba,
521 "%d:0225 Device Discovery completes\n",
524 mempool_free( pmb, phba->mbox_mem_pool);
526 spin_lock_irq(phba->host->host_lock);
527 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
528 if (phba->fc_flag & FC_ESTABLISH_LINK) {
529 phba->fc_flag &= ~FC_ESTABLISH_LINK;
531 spin_unlock_irq(phba->host->host_lock);
533 del_timer_sync(&phba->fc_estabtmo);
535 lpfc_can_disctmo(phba);
537 /* turn on Link Attention interrupts */
538 spin_lock_irq(phba->host->host_lock);
539 psli->sli_flag |= LPFC_PROCESS_LA;
540 control = readl(phba->HCregaddr);
541 control |= HC_LAINT_ENA;
542 writel(control, phba->HCregaddr);
543 readl(phba->HCregaddr); /* flush */
544 spin_unlock_irq(phba->host->host_lock);
550 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
552 struct lpfc_sli *psli = &phba->sli;
555 if (pmb->mb.mbxStatus)
558 mempool_free(pmb, phba->mbox_mem_pool);
560 if (phba->fc_topology == TOPOLOGY_LOOP &&
561 phba->fc_flag & FC_PUBLIC_LOOP &&
562 !(phba->fc_flag & FC_LBIT)) {
563 /* Need to wait for FAN - use discovery timer
564 * for timeout. hba_state is identically
565 * LPFC_LOCAL_CFG_LINK while waiting for FAN
567 lpfc_set_disctmo(phba);
571 /* Start discovery by sending a FLOGI. hba_state is identically
572 * LPFC_FLOGI while waiting for FLOGI cmpl
574 phba->hba_state = LPFC_FLOGI;
575 lpfc_set_disctmo(phba);
576 lpfc_initial_flogi(phba);
580 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
581 "%d:0306 CONFIG_LINK mbxStatus error x%x "
583 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
587 phba->hba_state = LPFC_HBA_ERROR;
589 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
590 "%d:0200 CONFIG_LINK bad hba state x%x\n",
591 phba->brd_no, phba->hba_state);
593 lpfc_clear_la(phba, pmb);
594 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
595 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
596 if (rc == MBX_NOT_FINISHED) {
597 mempool_free(pmb, phba->mbox_mem_pool);
598 lpfc_disc_flush_list(phba);
599 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
600 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
601 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
602 phba->hba_state = LPFC_HBA_READY;
608 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
610 struct lpfc_sli *psli = &phba->sli;
611 MAILBOX_t *mb = &pmb->mb;
612 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
615 /* Check for error */
617 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
618 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
619 "%d:0319 READ_SPARAM mbxStatus error x%x "
621 phba->brd_no, mb->mbxStatus, phba->hba_state);
624 phba->hba_state = LPFC_HBA_ERROR;
628 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
629 sizeof (struct serv_parm));
630 memcpy((uint8_t *) & phba->fc_nodename,
631 (uint8_t *) & phba->fc_sparam.nodeName,
632 sizeof (struct lpfc_name));
633 memcpy((uint8_t *) & phba->fc_portname,
634 (uint8_t *) & phba->fc_sparam.portName,
635 sizeof (struct lpfc_name));
636 lpfc_mbuf_free(phba, mp->virt, mp->phys);
638 mempool_free( pmb, phba->mbox_mem_pool);
642 pmb->context1 = NULL;
643 lpfc_mbuf_free(phba, mp->virt, mp->phys);
645 if (phba->hba_state != LPFC_CLEAR_LA) {
646 lpfc_clear_la(phba, pmb);
647 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
648 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
649 == MBX_NOT_FINISHED) {
650 mempool_free( pmb, phba->mbox_mem_pool);
651 lpfc_disc_flush_list(phba);
652 psli->ring[(psli->ip_ring)].flag &=
653 ~LPFC_STOP_IOCB_EVENT;
654 psli->ring[(psli->fcp_ring)].flag &=
655 ~LPFC_STOP_IOCB_EVENT;
656 psli->ring[(psli->next_ring)].flag &=
657 ~LPFC_STOP_IOCB_EVENT;
658 phba->hba_state = LPFC_HBA_READY;
661 mempool_free( pmb, phba->mbox_mem_pool);
667 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
670 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
671 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
672 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
674 spin_lock_irq(phba->host->host_lock);
675 switch (la->UlnkSpeed) {
677 phba->fc_linkspeed = LA_1GHZ_LINK;
680 phba->fc_linkspeed = LA_2GHZ_LINK;
683 phba->fc_linkspeed = LA_4GHZ_LINK;
686 phba->fc_linkspeed = LA_UNKNW_LINK;
690 phba->fc_topology = la->topology;
692 if (phba->fc_topology == TOPOLOGY_LOOP) {
693 /* Get Loop Map information */
696 phba->fc_flag |= FC_LBIT;
698 phba->fc_myDID = la->granted_AL_PA;
699 i = la->un.lilpBde64.tus.f.bdeSize;
702 phba->alpa_map[0] = 0;
704 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
715 numalpa = phba->alpa_map[0];
717 while (j < numalpa) {
718 memset(un.pamap, 0, 16);
719 for (k = 1; j < numalpa; k++) {
721 phba->alpa_map[j + 1];
726 /* Link Up Event ALPA map */
727 lpfc_printf_log(phba,
730 "%d:1304 Link Up Event "
731 "ALPA map Data: x%x "
734 un.pa.wd1, un.pa.wd2,
735 un.pa.wd3, un.pa.wd4);
740 phba->fc_myDID = phba->fc_pref_DID;
741 phba->fc_flag |= FC_LBIT;
743 spin_unlock_irq(phba->host->host_lock);
747 lpfc_read_sparam(phba, sparam_mbox);
748 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
749 lpfc_sli_issue_mbox(phba, sparam_mbox,
750 (MBX_NOWAIT | MBX_STOP_IOCB));
754 phba->hba_state = LPFC_LOCAL_CFG_LINK;
755 lpfc_config_link(phba, cfglink_mbox);
756 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
757 lpfc_sli_issue_mbox(phba, cfglink_mbox,
758 (MBX_NOWAIT | MBX_STOP_IOCB));
763 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
765 struct lpfc_sli *psli = &phba->sli;
769 /* turn on Link Attention interrupts - no CLEAR_LA needed */
770 spin_lock_irq(phba->host->host_lock);
771 psli->sli_flag |= LPFC_PROCESS_LA;
772 control = readl(phba->HCregaddr);
773 control |= HC_LAINT_ENA;
774 writel(control, phba->HCregaddr);
775 readl(phba->HCregaddr); /* flush */
776 spin_unlock_irq(phba->host->host_lock);
780 * This routine handles processing a READ_LA mailbox
781 * command upon completion. It is setup in the LPFC_MBOXQ
782 * as the completion routine when the command is
783 * handed off to the SLI layer.
786 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
789 MAILBOX_t *mb = &pmb->mb;
790 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
792 /* Check for error */
794 lpfc_printf_log(phba,
797 "%d:1307 READ_LA mbox error x%x state x%x\n",
799 mb->mbxStatus, phba->hba_state);
800 lpfc_mbx_issue_link_down(phba);
801 phba->hba_state = LPFC_HBA_ERROR;
802 goto lpfc_mbx_cmpl_read_la_free_mbuf;
805 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
807 memcpy(&phba->alpa_map[0], mp->virt, 128);
809 spin_lock_irq(phba->host->host_lock);
811 phba->fc_flag |= FC_BYPASSED_MODE;
813 phba->fc_flag &= ~FC_BYPASSED_MODE;
814 spin_unlock_irq(phba->host->host_lock);
816 if (((phba->fc_eventTag + 1) < la->eventTag) ||
817 (phba->fc_eventTag == la->eventTag)) {
818 phba->fc_stat.LinkMultiEvent++;
819 if (la->attType == AT_LINK_UP) {
820 if (phba->fc_eventTag != 0)
825 phba->fc_eventTag = la->eventTag;
827 if (la->attType == AT_LINK_UP) {
828 phba->fc_stat.LinkUp++;
829 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
830 "%d:1303 Link Up Event x%x received "
831 "Data: x%x x%x x%x x%x\n",
832 phba->brd_no, la->eventTag, phba->fc_eventTag,
833 la->granted_AL_PA, la->UlnkSpeed,
835 lpfc_mbx_process_link_up(phba, la);
837 phba->fc_stat.LinkDown++;
838 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
839 "%d:1305 Link Down Event x%x received "
840 "Data: x%x x%x x%x\n",
841 phba->brd_no, la->eventTag, phba->fc_eventTag,
842 phba->hba_state, phba->fc_flag);
843 lpfc_mbx_issue_link_down(phba);
846 lpfc_mbx_cmpl_read_la_free_mbuf:
847 lpfc_mbuf_free(phba, mp->virt, mp->phys);
849 mempool_free(pmb, phba->mbox_mem_pool);
854 * This routine handles processing a REG_LOGIN mailbox
855 * command upon completion. It is setup in the LPFC_MBOXQ
856 * as the completion routine when the command is
857 * handed off to the SLI layer.
860 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
862 struct lpfc_sli *psli;
864 struct lpfc_dmabuf *mp;
865 struct lpfc_nodelist *ndlp;
870 ndlp = (struct lpfc_nodelist *) pmb->context2;
871 mp = (struct lpfc_dmabuf *) (pmb->context1);
873 pmb->context1 = NULL;
875 /* Good status, call state machine */
876 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
877 lpfc_mbuf_free(phba, mp->virt, mp->phys);
879 mempool_free( pmb, phba->mbox_mem_pool);
885 * This routine handles processing a Fabric REG_LOGIN mailbox
886 * command upon completion. It is setup in the LPFC_MBOXQ
887 * as the completion routine when the command is
888 * handed off to the SLI layer.
891 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
893 struct lpfc_sli *psli;
895 struct lpfc_dmabuf *mp;
896 struct lpfc_nodelist *ndlp;
897 struct lpfc_nodelist *ndlp_fdmi;
903 ndlp = (struct lpfc_nodelist *) pmb->context2;
904 mp = (struct lpfc_dmabuf *) (pmb->context1);
907 lpfc_mbuf_free(phba, mp->virt, mp->phys);
909 mempool_free( pmb, phba->mbox_mem_pool);
910 mempool_free( ndlp, phba->nlp_mem_pool);
912 /* FLOGI failed, so just use loop map to make discovery list */
913 lpfc_disc_list_loopmap(phba);
915 /* Start discovery */
916 lpfc_disc_start(phba);
920 pmb->context1 = NULL;
922 ndlp->nlp_rpi = mb->un.varWords[0];
923 ndlp->nlp_type |= NLP_FABRIC;
924 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
925 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
927 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
928 /* This NPort has been assigned an NPort_ID by the fabric as a
929 * result of the completed fabric login. Issue a State Change
930 * Registration (SCR) ELS request to the fabric controller
931 * (SCR_DID) so that this NPort gets RSCN events from the
934 lpfc_issue_els_scr(phba, SCR_DID, 0);
936 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
938 /* Allocate a new node instance. If the pool is empty,
939 * start the discovery process and skip the Nameserver
940 * login process. This is attempted again later on.
941 * Otherwise, issue a Port Login (PLOGI) to NameServer.
943 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
945 lpfc_disc_start(phba);
946 lpfc_mbuf_free(phba, mp->virt, mp->phys);
948 mempool_free( pmb, phba->mbox_mem_pool);
951 lpfc_nlp_init(phba, ndlp, NameServer_DID);
952 ndlp->nlp_type |= NLP_FABRIC;
955 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
956 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
957 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
958 if (phba->cfg_fdmi_on) {
959 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
962 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
963 ndlp_fdmi->nlp_type |= NLP_FABRIC;
964 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
965 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
970 lpfc_mbuf_free(phba, mp->virt, mp->phys);
972 mempool_free( pmb, phba->mbox_mem_pool);
977 * This routine handles processing a NameServer REG_LOGIN mailbox
978 * command upon completion. It is setup in the LPFC_MBOXQ
979 * as the completion routine when the command is
980 * handed off to the SLI layer.
983 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
985 struct lpfc_sli *psli;
987 struct lpfc_dmabuf *mp;
988 struct lpfc_nodelist *ndlp;
993 ndlp = (struct lpfc_nodelist *) pmb->context2;
994 mp = (struct lpfc_dmabuf *) (pmb->context1);
997 lpfc_mbuf_free(phba, mp->virt, mp->phys);
999 mempool_free( pmb, phba->mbox_mem_pool);
1000 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1002 /* RegLogin failed, so just use loop map to make discovery
1004 lpfc_disc_list_loopmap(phba);
1006 /* Start discovery */
1007 lpfc_disc_start(phba);
1011 pmb->context1 = NULL;
1013 ndlp->nlp_rpi = mb->un.varWords[0];
1014 ndlp->nlp_type |= NLP_FABRIC;
1015 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1016 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1018 if (phba->hba_state < LPFC_HBA_READY) {
1019 /* Link up discovery requires Fabrib registration. */
1020 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1021 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1022 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1025 phba->fc_ns_retry = 0;
1026 /* Good status, issue CT Request to NameServer */
1027 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1028 /* Cannot issue NameServer Query, so finish up discovery */
1029 lpfc_disc_start(phba);
1032 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1034 mempool_free( pmb, phba->mbox_mem_pool);
1040 lpfc_register_remote_port(struct lpfc_hba * phba,
1041 struct lpfc_nodelist * ndlp)
1043 struct fc_rport *rport;
1044 struct lpfc_rport_data *rdata;
1045 struct fc_rport_identifiers rport_ids;
1047 /* Remote port has reappeared. Re-register w/ FC transport */
1048 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1049 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1050 rport_ids.port_id = ndlp->nlp_DID;
1051 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1053 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1055 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1056 "Warning: fc_remote_port_add failed\n");
1060 /* initialize static port data */
1061 rport->maxframe_size = ndlp->nlp_maxframe;
1062 rport->supported_classes = ndlp->nlp_class_sup;
1063 if ((rport->scsi_target_id != -1) &&
1064 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1065 ndlp->nlp_sid = rport->scsi_target_id;
1067 rdata = rport->dd_data;
1068 rdata->pnode = ndlp;
1070 if (ndlp->nlp_type & NLP_FCP_TARGET)
1071 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1072 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1073 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1076 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1077 fc_remote_port_rolechg(rport, rport_ids.roles);
1084 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1085 struct lpfc_nodelist * ndlp)
1087 struct fc_rport *rport = ndlp->rport;
1088 struct lpfc_rport_data *rdata = rport->dd_data;
1091 rdata->pnode = NULL;
1092 fc_remote_port_delete(rport);
1098 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1100 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1101 struct lpfc_sli *psli;
1104 /* Sanity check to ensure we are not moving to / from the same list */
1105 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1106 if (list != NLP_NO_LIST)
1109 spin_lock_irq(phba->host->host_lock);
1110 switch (nlp->nlp_flag & NLP_LIST_MASK) {
1111 case NLP_NO_LIST: /* Not on any list */
1113 case NLP_UNUSED_LIST:
1114 phba->fc_unused_cnt--;
1115 list_del(&nlp->nlp_listp);
1117 case NLP_PLOGI_LIST:
1118 phba->fc_plogi_cnt--;
1119 list_del(&nlp->nlp_listp);
1121 case NLP_ADISC_LIST:
1122 phba->fc_adisc_cnt--;
1123 list_del(&nlp->nlp_listp);
1125 case NLP_REGLOGIN_LIST:
1126 phba->fc_reglogin_cnt--;
1127 list_del(&nlp->nlp_listp);
1130 phba->fc_prli_cnt--;
1131 list_del(&nlp->nlp_listp);
1133 case NLP_UNMAPPED_LIST:
1134 phba->fc_unmap_cnt--;
1135 list_del(&nlp->nlp_listp);
1136 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1137 nlp->nlp_type &= ~NLP_FC_NODE;
1138 phba->nport_event_cnt++;
1140 rport_del = unmapped;
1142 case NLP_MAPPED_LIST:
1144 list_del(&nlp->nlp_listp);
1145 phba->nport_event_cnt++;
1151 list_del(&nlp->nlp_listp);
1152 /* Stop delay tmo if taking node off NPR list */
1153 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1154 (list != NLP_NPR_LIST)) {
1155 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1156 nlp->nlp_last_elscmd = 0;
1157 spin_unlock_irq(phba->host->host_lock);
1158 del_timer_sync(&nlp->nlp_delayfunc);
1159 spin_lock_irq(phba->host->host_lock);
1160 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1161 list_del_init(&nlp->els_retry_evt.evt_listp);
1166 nlp->nlp_flag &= ~NLP_LIST_MASK;
1168 /* Add NPort <did> to <num> list */
1169 lpfc_printf_log(phba,
1172 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1174 nlp->nlp_DID, list, nlp->nlp_flag);
1177 case NLP_NO_LIST: /* No list, just remove it */
1178 spin_unlock_irq(phba->host->host_lock);
1179 lpfc_nlp_remove(phba, nlp);
1180 spin_lock_irq(phba->host->host_lock);
1181 /* as node removed - stop further transport calls */
1184 case NLP_UNUSED_LIST:
1185 nlp->nlp_flag |= list;
1186 /* Put it at the end of the unused list */
1187 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1188 phba->fc_unused_cnt++;
1190 case NLP_PLOGI_LIST:
1191 nlp->nlp_flag |= list;
1192 /* Put it at the end of the plogi list */
1193 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1194 phba->fc_plogi_cnt++;
1196 case NLP_ADISC_LIST:
1197 nlp->nlp_flag |= list;
1198 /* Put it at the end of the adisc list */
1199 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1200 phba->fc_adisc_cnt++;
1202 case NLP_REGLOGIN_LIST:
1203 nlp->nlp_flag |= list;
1204 /* Put it at the end of the reglogin list */
1205 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1206 phba->fc_reglogin_cnt++;
1209 nlp->nlp_flag |= list;
1210 /* Put it at the end of the prli list */
1211 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1212 phba->fc_prli_cnt++;
1214 case NLP_UNMAPPED_LIST:
1215 rport_add = unmapped;
1216 /* ensure all vestiges of "mapped" significance are gone */
1217 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1218 nlp->nlp_flag |= list;
1219 /* Put it at the end of the unmap list */
1220 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1221 phba->fc_unmap_cnt++;
1222 phba->nport_event_cnt++;
1223 /* stop nodev tmo if running */
1224 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1225 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1226 spin_unlock_irq(phba->host->host_lock);
1227 del_timer_sync(&nlp->nlp_tmofunc);
1228 spin_lock_irq(phba->host->host_lock);
1229 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1230 list_del_init(&nlp->nodev_timeout_evt.
1234 nlp->nlp_type |= NLP_FC_NODE;
1236 case NLP_MAPPED_LIST:
1238 nlp->nlp_flag |= list;
1239 /* Put it at the end of the map list */
1240 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1242 phba->nport_event_cnt++;
1243 /* stop nodev tmo if running */
1244 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1245 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1246 spin_unlock_irq(phba->host->host_lock);
1247 del_timer_sync(&nlp->nlp_tmofunc);
1248 spin_lock_irq(phba->host->host_lock);
1249 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1250 list_del_init(&nlp->nodev_timeout_evt.
1256 nlp->nlp_flag |= list;
1257 /* Put it at the end of the npr list */
1258 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1261 if (!(nlp->nlp_flag & NLP_NODEV_TMO))
1262 mod_timer(&nlp->nlp_tmofunc,
1263 jiffies + HZ * phba->cfg_nodev_tmo);
1265 nlp->nlp_flag |= NLP_NODEV_TMO;
1266 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1272 spin_unlock_irq(phba->host->host_lock);
1275 * We make all the calls into the transport after we have
1276 * moved the node between lists. This so that we don't
1277 * release the lock while in-between lists.
1280 /* Don't upcall midlayer if we're unloading */
1281 if (!(phba->fc_flag & FC_UNLOADING)) {
1283 * We revalidate the rport pointer as the "add" function
1284 * may have removed the remote port.
1286 if ((rport_del != none) && nlp->rport)
1287 lpfc_unregister_remote_port(phba, nlp);
1289 if (rport_add != none) {
1291 * Tell the fc transport about the port, if we haven't
1292 * already. If we have, and it's a scsi entity, be
1293 * sure to unblock any attached scsi devices
1296 lpfc_register_remote_port(phba, nlp);
1299 * if we added to Mapped list, but the remote port
1300 * registration failed or assigned a target id outside
1301 * our presentable range - move the node to the
1304 if ((rport_add == mapped) &&
1306 (nlp->rport->scsi_target_id == -1) ||
1307 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1308 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1309 spin_lock_irq(phba->host->host_lock);
1310 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1311 spin_unlock_irq(phba->host->host_lock);
1312 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1320 * Start / ReStart rescue timer for Discovery / RSCN handling
1323 lpfc_set_disctmo(struct lpfc_hba * phba)
1327 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1328 /* For FAN, timeout should be greater then edtov */
1329 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1331 /* Normal discovery timeout should be > then ELS/CT timeout
1332 * FC spec states we need 3 * ratov for CT requests
1334 tmo = ((phba->fc_ratov * 3) + 3);
1337 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1338 spin_lock_irq(phba->host->host_lock);
1339 phba->fc_flag |= FC_DISC_TMO;
1340 spin_unlock_irq(phba->host->host_lock);
1342 /* Start Discovery Timer state <hba_state> */
1343 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1344 "%d:0247 Start Discovery Timer state x%x "
1345 "Data: x%x x%lx x%x x%x\n",
1347 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1348 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1354 * Cancel rescue timer for Discovery / RSCN handling
1357 lpfc_can_disctmo(struct lpfc_hba * phba)
1359 /* Turn off discovery timer if its running */
1360 if (phba->fc_flag & FC_DISC_TMO) {
1361 spin_lock_irq(phba->host->host_lock);
1362 phba->fc_flag &= ~FC_DISC_TMO;
1363 spin_unlock_irq(phba->host->host_lock);
1364 del_timer_sync(&phba->fc_disctmo);
1365 phba->work_hba_events &= ~WORKER_DISC_TMO;
1368 /* Cancel Discovery Timer state <hba_state> */
1369 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1370 "%d:0248 Cancel Discovery Timer state x%x "
1371 "Data: x%x x%x x%x\n",
1372 phba->brd_no, phba->hba_state, phba->fc_flag,
1373 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1379 * Check specified ring for outstanding IOCB on the SLI queue
1380 * Return true if iocb matches the specified nport
1383 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1384 struct lpfc_sli_ring * pring,
1385 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1387 struct lpfc_sli *psli;
1392 if (pring->ringno == LPFC_ELS_RING) {
1393 switch (icmd->ulpCommand) {
1394 case CMD_GEN_REQUEST64_CR:
1395 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1397 case CMD_ELS_REQUEST64_CR:
1398 case CMD_XMIT_ELS_RSP64_CX:
1399 if (iocb->context1 == (uint8_t *) ndlp)
1402 } else if (pring->ringno == psli->ip_ring) {
1404 } else if (pring->ringno == psli->fcp_ring) {
1405 /* Skip match check if waiting to relogin to FCP target */
1406 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1407 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1410 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1413 } else if (pring->ringno == psli->next_ring) {
1420 * Free resources / clean up outstanding I/Os
1421 * associated with nlp_rpi in the LPFC_NODELIST entry.
1424 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1426 struct lpfc_sli *psli;
1427 struct lpfc_sli_ring *pring;
1428 struct lpfc_iocbq *iocb, *next_iocb;
1433 * Everything that matches on txcmplq will be returned
1434 * by firmware with a no rpi error.
1437 rpi = ndlp->nlp_rpi;
1439 /* Now process each ring */
1440 for (i = 0; i < psli->num_rings; i++) {
1441 pring = &psli->ring[i];
1443 spin_lock_irq(phba->host->host_lock);
1444 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1447 * Check to see if iocb matches the nport we are
1450 if ((lpfc_check_sli_ndlp
1451 (phba, pring, iocb, ndlp))) {
1452 /* It matches, so deque and call compl
1454 list_del(&iocb->list);
1456 if (iocb->iocb_cmpl) {
1459 IOSTAT_LOCAL_REJECT;
1460 icmd->un.ulpWord[4] =
1462 spin_unlock_irq(phba->host->
1464 (iocb->iocb_cmpl) (phba,
1466 spin_lock_irq(phba->host->
1469 lpfc_sli_release_iocbq(phba,
1473 spin_unlock_irq(phba->host->host_lock);
1481 * Free rpi associated with LPFC_NODELIST entry.
1482 * This routine is called from lpfc_freenode(), when we are removing
1483 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1484 * LOGO that completes successfully, and we are waiting to PLOGI back
1485 * to the remote NPort. In addition, it is called after we receive
1486 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1487 * we are waiting to PLOGI back to the remote NPort.
1490 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1495 if (ndlp->nlp_rpi) {
1496 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1497 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1498 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1499 rc = lpfc_sli_issue_mbox
1500 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1501 if (rc == MBX_NOT_FINISHED)
1502 mempool_free( mbox, phba->mbox_mem_pool);
1504 lpfc_no_rpi(phba, ndlp);
1512 * Free resources associated with LPFC_NODELIST entry
1513 * so it can be freed.
1516 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1519 LPFC_MBOXQ_t *nextmb;
1520 struct lpfc_dmabuf *mp;
1522 /* Cleanup node for NPort <nlp_DID> */
1523 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1524 "%d:0900 Cleanup node for NPort x%x "
1525 "Data: x%x x%x x%x\n",
1526 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1527 ndlp->nlp_state, ndlp->nlp_rpi);
1529 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1532 * if unloading the driver - just leave the remote port in place.
1533 * The driver unload will force the attached devices to detach
1534 * and flush cache's w/o generating flush errors.
1536 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1537 lpfc_unregister_remote_port(phba, ndlp);
1538 ndlp->nlp_sid = NLP_NO_SID;
1541 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1542 if ((mb = phba->sli.mbox_active)) {
1543 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1544 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1545 mb->context2 = NULL;
1546 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1549 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1550 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1551 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1552 mp = (struct lpfc_dmabuf *) (mb->context1);
1554 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1557 list_del(&mb->list);
1558 mempool_free(mb, phba->mbox_mem_pool);
1562 lpfc_els_abort(phba,ndlp,0);
1563 spin_lock_irq(phba->host->host_lock);
1564 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1565 spin_unlock_irq(phba->host->host_lock);
1566 del_timer_sync(&ndlp->nlp_tmofunc);
1568 ndlp->nlp_last_elscmd = 0;
1569 del_timer_sync(&ndlp->nlp_delayfunc);
1571 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1572 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1573 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1574 list_del_init(&ndlp->els_retry_evt.evt_listp);
1576 lpfc_unreg_rpi(phba, ndlp);
1582 * Check to see if we can free the nlp back to the freelist.
1583 * If we are in the middle of using the nlp in the discovery state
1584 * machine, defer the free till we reach the end of the state machine.
1587 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1589 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1590 spin_lock_irq(phba->host->host_lock);
1591 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1592 spin_unlock_irq(phba->host->host_lock);
1593 del_timer_sync(&ndlp->nlp_tmofunc);
1594 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1595 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1600 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1601 spin_lock_irq(phba->host->host_lock);
1602 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1603 spin_unlock_irq(phba->host->host_lock);
1604 ndlp->nlp_last_elscmd = 0;
1605 del_timer_sync(&ndlp->nlp_delayfunc);
1606 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1607 list_del_init(&ndlp->els_retry_evt.evt_listp);
1610 if (ndlp->nlp_disc_refcnt) {
1611 spin_lock_irq(phba->host->host_lock);
1612 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1613 spin_unlock_irq(phba->host->host_lock);
1615 lpfc_freenode(phba, ndlp);
1616 mempool_free( ndlp, phba->nlp_mem_pool);
1622 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1628 if (did == Bcast_DID)
1631 if (ndlp->nlp_DID == 0) {
1635 /* First check for Direct match */
1636 if (ndlp->nlp_DID == did)
1639 /* Next check for area/domain identically equals 0 match */
1640 mydid.un.word = phba->fc_myDID;
1641 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1645 matchdid.un.word = did;
1646 ndlpdid.un.word = ndlp->nlp_DID;
1647 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1648 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1649 (mydid.un.b.area == matchdid.un.b.area)) {
1650 if ((ndlpdid.un.b.domain == 0) &&
1651 (ndlpdid.un.b.area == 0)) {
1652 if (ndlpdid.un.b.id)
1658 matchdid.un.word = ndlp->nlp_DID;
1659 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1660 (mydid.un.b.area == ndlpdid.un.b.area)) {
1661 if ((matchdid.un.b.domain == 0) &&
1662 (matchdid.un.b.area == 0)) {
1663 if (matchdid.un.b.id)
1671 /* Search for a nodelist entry on a specific list */
1672 struct lpfc_nodelist *
1673 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1675 struct lpfc_nodelist *ndlp, *next_ndlp;
1678 spin_lock_irq(phba->host->host_lock);
1679 if (order & NLP_SEARCH_UNMAPPED) {
1680 list_for_each_entry_safe(ndlp, next_ndlp,
1681 &phba->fc_nlpunmap_list, nlp_listp) {
1682 if (lpfc_matchdid(phba, ndlp, did)) {
1683 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1684 ((uint32_t) ndlp->nlp_xri << 16) |
1685 ((uint32_t) ndlp->nlp_type << 8) |
1686 ((uint32_t) ndlp->nlp_rpi & 0xff));
1687 /* FIND node DID unmapped */
1688 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1689 "%d:0929 FIND node DID unmapped"
1690 " Data: x%p x%x x%x x%x\n",
1692 ndlp, ndlp->nlp_DID,
1693 ndlp->nlp_flag, data1);
1694 spin_unlock_irq(phba->host->host_lock);
1700 if (order & NLP_SEARCH_MAPPED) {
1701 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1703 if (lpfc_matchdid(phba, ndlp, did)) {
1705 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1706 ((uint32_t) ndlp->nlp_xri << 16) |
1707 ((uint32_t) ndlp->nlp_type << 8) |
1708 ((uint32_t) ndlp->nlp_rpi & 0xff));
1709 /* FIND node DID mapped */
1710 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1711 "%d:0930 FIND node DID mapped "
1712 "Data: x%p x%x x%x x%x\n",
1714 ndlp, ndlp->nlp_DID,
1715 ndlp->nlp_flag, data1);
1716 spin_unlock_irq(phba->host->host_lock);
1722 if (order & NLP_SEARCH_PLOGI) {
1723 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1725 if (lpfc_matchdid(phba, ndlp, did)) {
1727 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1728 ((uint32_t) ndlp->nlp_xri << 16) |
1729 ((uint32_t) ndlp->nlp_type << 8) |
1730 ((uint32_t) ndlp->nlp_rpi & 0xff));
1731 /* LOG change to PLOGI */
1732 /* FIND node DID plogi */
1733 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1734 "%d:0908 FIND node DID plogi "
1735 "Data: x%p x%x x%x x%x\n",
1737 ndlp, ndlp->nlp_DID,
1738 ndlp->nlp_flag, data1);
1739 spin_unlock_irq(phba->host->host_lock);
1745 if (order & NLP_SEARCH_ADISC) {
1746 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1748 if (lpfc_matchdid(phba, ndlp, did)) {
1750 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1751 ((uint32_t) ndlp->nlp_xri << 16) |
1752 ((uint32_t) ndlp->nlp_type << 8) |
1753 ((uint32_t) ndlp->nlp_rpi & 0xff));
1754 /* LOG change to ADISC */
1755 /* FIND node DID adisc */
1756 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1757 "%d:0931 FIND node DID adisc "
1758 "Data: x%p x%x x%x x%x\n",
1760 ndlp, ndlp->nlp_DID,
1761 ndlp->nlp_flag, data1);
1767 if (order & NLP_SEARCH_REGLOGIN) {
1768 list_for_each_entry_safe(ndlp, next_ndlp,
1769 &phba->fc_reglogin_list, nlp_listp) {
1770 if (lpfc_matchdid(phba, ndlp, did)) {
1772 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1773 ((uint32_t) ndlp->nlp_xri << 16) |
1774 ((uint32_t) ndlp->nlp_type << 8) |
1775 ((uint32_t) ndlp->nlp_rpi & 0xff));
1776 /* LOG change to REGLOGIN */
1777 /* FIND node DID reglogin */
1778 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1779 "%d:0931 FIND node DID reglogin"
1780 " Data: x%p x%x x%x x%x\n",
1782 ndlp, ndlp->nlp_DID,
1783 ndlp->nlp_flag, data1);
1784 spin_unlock_irq(phba->host->host_lock);
1790 if (order & NLP_SEARCH_PRLI) {
1791 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1793 if (lpfc_matchdid(phba, ndlp, did)) {
1795 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1796 ((uint32_t) ndlp->nlp_xri << 16) |
1797 ((uint32_t) ndlp->nlp_type << 8) |
1798 ((uint32_t) ndlp->nlp_rpi & 0xff));
1799 /* LOG change to PRLI */
1800 /* FIND node DID prli */
1801 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1802 "%d:0931 FIND node DID prli "
1803 "Data: x%p x%x x%x x%x\n",
1805 ndlp, ndlp->nlp_DID,
1806 ndlp->nlp_flag, data1);
1812 if (order & NLP_SEARCH_NPR) {
1813 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1815 if (lpfc_matchdid(phba, ndlp, did)) {
1817 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1818 ((uint32_t) ndlp->nlp_xri << 16) |
1819 ((uint32_t) ndlp->nlp_type << 8) |
1820 ((uint32_t) ndlp->nlp_rpi & 0xff));
1821 /* LOG change to NPR */
1822 /* FIND node DID npr */
1823 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1824 "%d:0931 FIND node DID npr "
1825 "Data: x%p x%x x%x x%x\n",
1827 ndlp, ndlp->nlp_DID,
1828 ndlp->nlp_flag, data1);
1829 spin_unlock_irq(phba->host->host_lock);
1835 if (order & NLP_SEARCH_UNUSED) {
1836 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1838 if (lpfc_matchdid(phba, ndlp, did)) {
1840 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1841 ((uint32_t) ndlp->nlp_xri << 16) |
1842 ((uint32_t) ndlp->nlp_type << 8) |
1843 ((uint32_t) ndlp->nlp_rpi & 0xff));
1844 /* LOG change to UNUSED */
1845 /* FIND node DID unused */
1846 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1847 "%d:0931 FIND node DID unused "
1848 "Data: x%p x%x x%x x%x\n",
1850 ndlp, ndlp->nlp_DID,
1851 ndlp->nlp_flag, data1);
1852 spin_unlock_irq(phba->host->host_lock);
1858 spin_unlock_irq(phba->host->host_lock);
1860 /* FIND node did <did> NOT FOUND */
1861 lpfc_printf_log(phba,
1864 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1865 phba->brd_no, did, order);
1867 /* no match found */
1871 struct lpfc_nodelist *
1872 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1874 struct lpfc_nodelist *ndlp;
1877 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1879 if ((phba->fc_flag & FC_RSCN_MODE) &&
1880 ((lpfc_rscn_payload_check(phba, did) == 0)))
1882 ndlp = (struct lpfc_nodelist *)
1883 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1886 lpfc_nlp_init(phba, ndlp, did);
1887 ndlp->nlp_state = NLP_STE_NPR_NODE;
1888 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1889 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1892 if (phba->fc_flag & FC_RSCN_MODE) {
1893 if (lpfc_rscn_payload_check(phba, did)) {
1894 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1896 /* Since this node is marked for discovery,
1897 * delay timeout is not needed.
1899 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1900 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1901 del_timer_sync(&ndlp->nlp_delayfunc);
1902 if (!list_empty(&ndlp->els_retry_evt.
1904 list_del_init(&ndlp->els_retry_evt.
1908 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
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:0226 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:0226 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 lpfc_nodev_timeout(unsigned long ptr)
2428 struct lpfc_hba *phba;
2429 struct lpfc_nodelist *ndlp;
2430 unsigned long iflag;
2431 struct lpfc_work_evt *evtp;
2433 ndlp = (struct lpfc_nodelist *)ptr;
2434 phba = ndlp->nlp_phba;
2435 evtp = &ndlp->nodev_timeout_evt;
2436 spin_lock_irqsave(phba->host->host_lock, iflag);
2438 if (!list_empty(&evtp->evt_listp)) {
2439 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2442 evtp->evt_arg1 = ndlp;
2443 evtp->evt = LPFC_EVT_NODEV_TMO;
2444 list_add_tail(&evtp->evt_listp, &phba->work_list);
2445 if (phba->work_wait)
2446 wake_up(phba->work_wait);
2448 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2454 * This routine handles processing a NameServer REG_LOGIN mailbox
2455 * command upon completion. It is setup in the LPFC_MBOXQ
2456 * as the completion routine when the command is
2457 * handed off to the SLI layer.
2460 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2462 struct lpfc_sli *psli;
2464 struct lpfc_dmabuf *mp;
2465 struct lpfc_nodelist *ndlp;
2470 ndlp = (struct lpfc_nodelist *) pmb->context2;
2471 mp = (struct lpfc_dmabuf *) (pmb->context1);
2473 pmb->context1 = NULL;
2475 ndlp->nlp_rpi = mb->un.varWords[0];
2476 ndlp->nlp_type |= NLP_FABRIC;
2477 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2478 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2480 /* Start issuing Fabric-Device Management Interface (FDMI)
2481 * command to 0xfffffa (FDMI well known port)
2483 if (phba->cfg_fdmi_on == 1) {
2484 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2487 * Delay issuing FDMI command if fdmi-on=2
2488 * (supporting RPA/hostnmae)
2490 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2493 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2495 mempool_free( pmb, phba->mbox_mem_pool);
2501 * This routine looks up the ndlp lists
2502 * for the given RPI. If rpi found
2503 * it return the node list pointer
2506 struct lpfc_nodelist *
2507 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2509 struct lpfc_nodelist *ndlp;
2510 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2511 &phba->fc_nlpmap_list,
2512 &phba->fc_plogi_list,
2513 &phba->fc_adisc_list,
2514 &phba->fc_reglogin_list};
2517 spin_lock_irq(phba->host->host_lock);
2518 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2519 list_for_each_entry(ndlp, lists[i], nlp_listp)
2520 if (ndlp->nlp_rpi == rpi) {
2521 spin_unlock_irq(phba->host->host_lock);
2524 spin_unlock_irq(phba->host->host_lock);
2529 * This routine looks up the ndlp lists
2530 * for the given WWPN. If WWPN found
2531 * it return the node list pointer
2534 struct lpfc_nodelist *
2535 lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2536 struct lpfc_name * wwpn)
2538 struct lpfc_nodelist *ndlp;
2539 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2540 &phba->fc_nlpmap_list,
2542 &phba->fc_plogi_list,
2543 &phba->fc_adisc_list,
2544 &phba->fc_reglogin_list,
2545 &phba->fc_prli_list};
2546 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2551 NLP_SEARCH_REGLOGIN,
2555 spin_lock_irq(phba->host->host_lock);
2556 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2557 if (!(order & search[i]))
2559 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2560 if (memcmp(&ndlp->nlp_portname, wwpn,
2561 sizeof(struct lpfc_name)) == 0) {
2562 spin_unlock_irq(phba->host->host_lock);
2567 spin_unlock_irq(phba->host->host_lock);
2572 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2575 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2576 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2577 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2578 init_timer(&ndlp->nlp_tmofunc);
2579 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2580 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2581 init_timer(&ndlp->nlp_delayfunc);
2582 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2583 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2584 ndlp->nlp_DID = did;
2585 ndlp->nlp_phba = phba;
2586 ndlp->nlp_sid = NLP_NO_SID;