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)
64 spin_lock_irq(phba->host->host_lock);
65 if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
66 spin_unlock_irq(phba->host->host_lock);
70 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
72 if (ndlp->nlp_sid != NLP_NO_SID) {
74 /* flush the target */
75 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
76 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
78 spin_unlock_irq(phba->host->host_lock);
81 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
82 "%d:0203 Nodev timeout on NPort x%x "
83 "Data: x%x x%x x%x\n",
84 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
85 ndlp->nlp_state, ndlp->nlp_rpi);
87 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
88 "%d:0204 Nodev timeout on NPort x%x "
89 "Data: x%x x%x x%x\n",
90 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
91 ndlp->nlp_state, ndlp->nlp_rpi);
94 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
99 lpfc_work_list_done(struct lpfc_hba * phba)
101 struct lpfc_work_evt *evtp = NULL;
102 struct lpfc_nodelist *ndlp;
105 spin_lock_irq(phba->host->host_lock);
106 while(!list_empty(&phba->work_list)) {
107 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
109 spin_unlock_irq(phba->host->host_lock);
112 case LPFC_EVT_NODEV_TMO:
113 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
114 lpfc_process_nodev_timeout(phba, ndlp);
117 case LPFC_EVT_ELS_RETRY:
118 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
119 lpfc_els_retry_delay_handler(ndlp);
122 case LPFC_EVT_ONLINE:
123 if (phba->hba_state < LPFC_LINK_DOWN)
124 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
126 *(int *)(evtp->evt_arg1) = 0;
127 complete((struct completion *)(evtp->evt_arg2));
129 case LPFC_EVT_OFFLINE:
130 if (phba->hba_state >= LPFC_LINK_DOWN)
132 lpfc_sli_brdrestart(phba);
133 *(int *)(evtp->evt_arg1) =
134 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
135 complete((struct completion *)(evtp->evt_arg2));
137 case LPFC_EVT_WARM_START:
138 if (phba->hba_state >= LPFC_LINK_DOWN)
140 lpfc_sli_brdreset(phba);
141 lpfc_hba_down_post(phba);
142 *(int *)(evtp->evt_arg1) =
143 lpfc_sli_brdready(phba, HS_MBRDY);
144 complete((struct completion *)(evtp->evt_arg2));
147 if (phba->hba_state >= LPFC_LINK_DOWN)
149 *(int *)(evtp->evt_arg1) = lpfc_sli_brdkill(phba);
150 complete((struct completion *)(evtp->evt_arg2));
155 spin_lock_irq(phba->host->host_lock);
157 spin_unlock_irq(phba->host->host_lock);
162 lpfc_work_done(struct lpfc_hba * phba)
164 struct lpfc_sli_ring *pring;
168 uint32_t work_hba_events;
170 spin_lock_irq(phba->host->host_lock);
171 ha_copy = phba->work_ha;
173 work_hba_events=phba->work_hba_events;
174 spin_unlock_irq(phba->host->host_lock);
176 if (ha_copy & HA_ERATT)
177 lpfc_handle_eratt(phba);
179 if (ha_copy & HA_MBATT)
180 lpfc_sli_handle_mb_event(phba);
182 if (ha_copy & HA_LATT)
183 lpfc_handle_latt(phba);
185 if (work_hba_events & WORKER_DISC_TMO)
186 lpfc_disc_timeout_handler(phba);
188 if (work_hba_events & WORKER_ELS_TMO)
189 lpfc_els_timeout_handler(phba);
191 if (work_hba_events & WORKER_MBOX_TMO)
192 lpfc_mbox_timeout_handler(phba);
194 if (work_hba_events & WORKER_FDMI_TMO)
195 lpfc_fdmi_tmo_handler(phba);
197 spin_lock_irq(phba->host->host_lock);
198 phba->work_hba_events &= ~work_hba_events;
199 spin_unlock_irq(phba->host->host_lock);
201 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
202 pring = &phba->sli.ring[i];
203 if ((ha_copy & HA_RXATT)
204 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
205 if (pring->flag & LPFC_STOP_IOCB_MASK) {
206 pring->flag |= LPFC_DEFERRED_RING_EVENT;
208 lpfc_sli_handle_slow_ring_event(phba, pring,
211 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
214 * Turn on Ring interrupts
216 spin_lock_irq(phba->host->host_lock);
217 control = readl(phba->HCregaddr);
218 control |= (HC_R0INT_ENA << i);
219 writel(control, phba->HCregaddr);
220 readl(phba->HCregaddr); /* flush */
221 spin_unlock_irq(phba->host->host_lock);
225 lpfc_work_list_done (phba);
230 check_work_wait_done(struct lpfc_hba *phba) {
232 spin_lock_irq(phba->host->host_lock);
234 phba->work_hba_events ||
235 (!list_empty(&phba->work_list)) ||
236 kthread_should_stop()) {
237 spin_unlock_irq(phba->host->host_lock);
240 spin_unlock_irq(phba->host->host_lock);
246 lpfc_do_work(void *p)
248 struct lpfc_hba *phba = p;
250 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
252 set_user_nice(current, -20);
253 phba->work_wait = &work_waitq;
257 rc = wait_event_interruptible(work_waitq,
258 check_work_wait_done(phba));
261 if (kthread_should_stop())
264 lpfc_work_done(phba);
267 phba->work_wait = NULL;
272 * This is only called to handle FC worker events. Since this a rare
273 * occurance, we allocate a struct lpfc_work_evt structure here instead of
274 * embedding it in the IOCB.
277 lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
280 struct lpfc_work_evt *evtp;
283 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
284 * be queued to worker thread for processing
286 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
290 evtp->evt_arg1 = arg1;
291 evtp->evt_arg2 = arg2;
294 list_add_tail(&evtp->evt_listp, &phba->work_list);
295 spin_lock_irq(phba->host->host_lock);
297 wake_up(phba->work_wait);
298 spin_unlock_irq(phba->host->host_lock);
304 lpfc_linkdown(struct lpfc_hba * phba)
306 struct lpfc_sli *psli;
307 struct lpfc_nodelist *ndlp, *next_ndlp;
308 struct list_head *listp, *node_list[7];
313 /* sysfs or selective reset may call this routine to clean up */
314 if (phba->hba_state >= LPFC_LINK_DOWN) {
315 if (phba->hba_state == LPFC_LINK_DOWN)
318 spin_lock_irq(phba->host->host_lock);
319 phba->hba_state = LPFC_LINK_DOWN;
320 spin_unlock_irq(phba->host->host_lock);
323 /* Clean up any firmware default rpi's */
324 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
325 lpfc_unreg_did(phba, 0xffffffff, mb);
326 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
327 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
328 == MBX_NOT_FINISHED) {
329 mempool_free( mb, phba->mbox_mem_pool);
333 /* Cleanup any outstanding RSCN activity */
334 lpfc_els_flush_rscn(phba);
336 /* Cleanup any outstanding ELS commands */
337 lpfc_els_flush_cmd(phba);
339 /* Issue a LINK DOWN event to all nodes */
340 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
341 node_list[1] = &phba->fc_nlpmap_list;
342 node_list[2] = &phba->fc_nlpunmap_list;
343 node_list[3] = &phba->fc_prli_list;
344 node_list[4] = &phba->fc_reglogin_list;
345 node_list[5] = &phba->fc_adisc_list;
346 node_list[6] = &phba->fc_plogi_list;
347 for (i = 0; i < 7; i++) {
348 listp = node_list[i];
349 if (list_empty(listp))
352 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
354 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
355 NLP_EVT_DEVICE_RECOVERY);
357 /* Check config parameter use-adisc or FCP-2 */
358 if ((rc != NLP_STE_FREED_NODE) &&
359 (phba->cfg_use_adisc == 0) &&
360 !(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) {
361 /* We know we will have to relogin, so
362 * unreglogin the rpi right now to fail
363 * any outstanding I/Os quickly.
365 lpfc_unreg_rpi(phba, ndlp);
370 /* free any ndlp's on unused list */
371 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
373 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
376 /* Setup myDID for link up if we are in pt2pt mode */
377 if (phba->fc_flag & FC_PT2PT) {
379 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
380 lpfc_config_link(phba, mb);
381 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
382 if (lpfc_sli_issue_mbox
383 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
384 == MBX_NOT_FINISHED) {
385 mempool_free( mb, phba->mbox_mem_pool);
388 spin_lock_irq(phba->host->host_lock);
389 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
390 spin_unlock_irq(phba->host->host_lock);
392 spin_lock_irq(phba->host->host_lock);
393 phba->fc_flag &= ~FC_LBIT;
394 spin_unlock_irq(phba->host->host_lock);
396 /* Turn off discovery timer if its running */
397 lpfc_can_disctmo(phba);
399 /* Must process IOCBs on all rings to handle ABORTed I/Os */
404 lpfc_linkup(struct lpfc_hba * phba)
406 struct lpfc_nodelist *ndlp, *next_ndlp;
407 struct list_head *listp, *node_list[7];
410 spin_lock_irq(phba->host->host_lock);
411 phba->hba_state = LPFC_LINK_UP;
412 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
413 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
414 phba->fc_flag |= FC_NDISC_ACTIVE;
415 phba->fc_ns_retry = 0;
416 spin_unlock_irq(phba->host->host_lock);
419 node_list[0] = &phba->fc_plogi_list;
420 node_list[1] = &phba->fc_adisc_list;
421 node_list[2] = &phba->fc_reglogin_list;
422 node_list[3] = &phba->fc_prli_list;
423 node_list[4] = &phba->fc_nlpunmap_list;
424 node_list[5] = &phba->fc_nlpmap_list;
425 node_list[6] = &phba->fc_npr_list;
426 for (i = 0; i < 7; i++) {
427 listp = node_list[i];
428 if (list_empty(listp))
431 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
432 if (phba->fc_flag & FC_LBIT) {
433 if (ndlp->nlp_type & NLP_FABRIC) {
434 /* On Linkup its safe to clean up the
435 * ndlp from Fabric connections.
437 lpfc_nlp_list(phba, ndlp,
439 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
440 /* Fail outstanding IO now since device
441 * is marked for PLOGI.
443 lpfc_unreg_rpi(phba, ndlp);
449 /* free any ndlp's on unused list */
450 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
452 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
459 * This routine handles processing a CLEAR_LA mailbox
460 * command upon completion. It is setup in the LPFC_MBOXQ
461 * as the completion routine when the command is
462 * handed off to the SLI layer.
465 lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
467 struct lpfc_sli *psli;
473 /* Since we don't do discovery right now, turn these off here */
474 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
475 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
476 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
478 /* Check for error */
479 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
480 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
481 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
482 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
484 phba->brd_no, mb->mbxStatus, phba->hba_state);
486 phba->hba_state = LPFC_HBA_ERROR;
490 if (phba->fc_flag & FC_ABORT_DISCOVERY)
493 phba->num_disc_nodes = 0;
494 /* go thru NPR list and issue ELS PLOGIs */
495 if (phba->fc_npr_cnt) {
496 lpfc_els_disc_plogi(phba);
499 if (!phba->num_disc_nodes) {
500 spin_lock_irq(phba->host->host_lock);
501 phba->fc_flag &= ~FC_NDISC_ACTIVE;
502 spin_unlock_irq(phba->host->host_lock);
505 phba->hba_state = LPFC_HBA_READY;
508 /* Device Discovery completes */
509 lpfc_printf_log(phba,
512 "%d:0225 Device Discovery completes\n",
515 mempool_free( pmb, phba->mbox_mem_pool);
517 spin_lock_irq(phba->host->host_lock);
518 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
519 if (phba->fc_flag & FC_ESTABLISH_LINK) {
520 phba->fc_flag &= ~FC_ESTABLISH_LINK;
522 spin_unlock_irq(phba->host->host_lock);
524 del_timer_sync(&phba->fc_estabtmo);
526 lpfc_can_disctmo(phba);
528 /* turn on Link Attention interrupts */
529 spin_lock_irq(phba->host->host_lock);
530 psli->sli_flag |= LPFC_PROCESS_LA;
531 control = readl(phba->HCregaddr);
532 control |= HC_LAINT_ENA;
533 writel(control, phba->HCregaddr);
534 readl(phba->HCregaddr); /* flush */
535 spin_unlock_irq(phba->host->host_lock);
541 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
543 struct lpfc_sli *psli = &phba->sli;
546 if (pmb->mb.mbxStatus)
549 mempool_free(pmb, phba->mbox_mem_pool);
551 if (phba->fc_topology == TOPOLOGY_LOOP &&
552 phba->fc_flag & FC_PUBLIC_LOOP &&
553 !(phba->fc_flag & FC_LBIT)) {
554 /* Need to wait for FAN - use discovery timer
555 * for timeout. hba_state is identically
556 * LPFC_LOCAL_CFG_LINK while waiting for FAN
558 lpfc_set_disctmo(phba);
562 /* Start discovery by sending a FLOGI. hba_state is identically
563 * LPFC_FLOGI while waiting for FLOGI cmpl
565 phba->hba_state = LPFC_FLOGI;
566 lpfc_set_disctmo(phba);
567 lpfc_initial_flogi(phba);
571 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
572 "%d:0306 CONFIG_LINK mbxStatus error x%x "
574 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
578 phba->hba_state = LPFC_HBA_ERROR;
580 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
581 "%d:0200 CONFIG_LINK bad hba state x%x\n",
582 phba->brd_no, phba->hba_state);
584 lpfc_clear_la(phba, pmb);
585 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
586 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
587 if (rc == MBX_NOT_FINISHED) {
588 mempool_free(pmb, phba->mbox_mem_pool);
589 lpfc_disc_flush_list(phba);
590 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
591 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
592 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
593 phba->hba_state = LPFC_HBA_READY;
599 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
601 struct lpfc_sli *psli = &phba->sli;
602 MAILBOX_t *mb = &pmb->mb;
603 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
606 /* Check for error */
608 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
609 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
610 "%d:0319 READ_SPARAM mbxStatus error x%x "
612 phba->brd_no, mb->mbxStatus, phba->hba_state);
615 phba->hba_state = LPFC_HBA_ERROR;
619 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
620 sizeof (struct serv_parm));
621 memcpy((uint8_t *) & phba->fc_nodename,
622 (uint8_t *) & phba->fc_sparam.nodeName,
623 sizeof (struct lpfc_name));
624 memcpy((uint8_t *) & phba->fc_portname,
625 (uint8_t *) & phba->fc_sparam.portName,
626 sizeof (struct lpfc_name));
627 lpfc_mbuf_free(phba, mp->virt, mp->phys);
629 mempool_free( pmb, phba->mbox_mem_pool);
633 pmb->context1 = NULL;
634 lpfc_mbuf_free(phba, mp->virt, mp->phys);
636 if (phba->hba_state != LPFC_CLEAR_LA) {
637 lpfc_clear_la(phba, pmb);
638 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
639 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
640 == MBX_NOT_FINISHED) {
641 mempool_free( pmb, phba->mbox_mem_pool);
642 lpfc_disc_flush_list(phba);
643 psli->ring[(psli->ip_ring)].flag &=
644 ~LPFC_STOP_IOCB_EVENT;
645 psli->ring[(psli->fcp_ring)].flag &=
646 ~LPFC_STOP_IOCB_EVENT;
647 psli->ring[(psli->next_ring)].flag &=
648 ~LPFC_STOP_IOCB_EVENT;
649 phba->hba_state = LPFC_HBA_READY;
652 mempool_free( pmb, phba->mbox_mem_pool);
658 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
661 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
662 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
663 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
665 spin_lock_irq(phba->host->host_lock);
666 switch (la->UlnkSpeed) {
668 phba->fc_linkspeed = LA_1GHZ_LINK;
671 phba->fc_linkspeed = LA_2GHZ_LINK;
674 phba->fc_linkspeed = LA_4GHZ_LINK;
677 phba->fc_linkspeed = LA_UNKNW_LINK;
681 phba->fc_topology = la->topology;
683 if (phba->fc_topology == TOPOLOGY_LOOP) {
684 /* Get Loop Map information */
687 phba->fc_flag |= FC_LBIT;
689 phba->fc_myDID = la->granted_AL_PA;
690 i = la->un.lilpBde64.tus.f.bdeSize;
693 phba->alpa_map[0] = 0;
695 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
706 numalpa = phba->alpa_map[0];
708 while (j < numalpa) {
709 memset(un.pamap, 0, 16);
710 for (k = 1; j < numalpa; k++) {
712 phba->alpa_map[j + 1];
717 /* Link Up Event ALPA map */
718 lpfc_printf_log(phba,
721 "%d:1304 Link Up Event "
722 "ALPA map Data: x%x "
725 un.pa.wd1, un.pa.wd2,
726 un.pa.wd3, un.pa.wd4);
731 phba->fc_myDID = phba->fc_pref_DID;
732 phba->fc_flag |= FC_LBIT;
734 spin_unlock_irq(phba->host->host_lock);
738 lpfc_read_sparam(phba, sparam_mbox);
739 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
740 lpfc_sli_issue_mbox(phba, sparam_mbox,
741 (MBX_NOWAIT | MBX_STOP_IOCB));
745 phba->hba_state = LPFC_LOCAL_CFG_LINK;
746 lpfc_config_link(phba, cfglink_mbox);
747 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
748 lpfc_sli_issue_mbox(phba, cfglink_mbox,
749 (MBX_NOWAIT | MBX_STOP_IOCB));
754 lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
756 struct lpfc_sli *psli = &phba->sli;
760 /* turn on Link Attention interrupts - no CLEAR_LA needed */
761 spin_lock_irq(phba->host->host_lock);
762 psli->sli_flag |= LPFC_PROCESS_LA;
763 control = readl(phba->HCregaddr);
764 control |= HC_LAINT_ENA;
765 writel(control, phba->HCregaddr);
766 readl(phba->HCregaddr); /* flush */
767 spin_unlock_irq(phba->host->host_lock);
771 * This routine handles processing a READ_LA mailbox
772 * command upon completion. It is setup in the LPFC_MBOXQ
773 * as the completion routine when the command is
774 * handed off to the SLI layer.
777 lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
780 MAILBOX_t *mb = &pmb->mb;
781 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
783 /* Check for error */
785 lpfc_printf_log(phba,
788 "%d:1307 READ_LA mbox error x%x state x%x\n",
790 mb->mbxStatus, phba->hba_state);
791 lpfc_mbx_issue_link_down(phba);
792 phba->hba_state = LPFC_HBA_ERROR;
793 goto lpfc_mbx_cmpl_read_la_free_mbuf;
796 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
798 memcpy(&phba->alpa_map[0], mp->virt, 128);
800 spin_lock_irq(phba->host->host_lock);
802 phba->fc_flag |= FC_BYPASSED_MODE;
804 phba->fc_flag &= ~FC_BYPASSED_MODE;
805 spin_unlock_irq(phba->host->host_lock);
807 if (((phba->fc_eventTag + 1) < la->eventTag) ||
808 (phba->fc_eventTag == la->eventTag)) {
809 phba->fc_stat.LinkMultiEvent++;
810 if (la->attType == AT_LINK_UP) {
811 if (phba->fc_eventTag != 0)
816 phba->fc_eventTag = la->eventTag;
818 if (la->attType == AT_LINK_UP) {
819 phba->fc_stat.LinkUp++;
820 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
821 "%d:1303 Link Up Event x%x received "
822 "Data: x%x x%x x%x x%x\n",
823 phba->brd_no, la->eventTag, phba->fc_eventTag,
824 la->granted_AL_PA, la->UlnkSpeed,
826 lpfc_mbx_process_link_up(phba, la);
828 phba->fc_stat.LinkDown++;
829 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
830 "%d:1305 Link Down Event x%x received "
831 "Data: x%x x%x x%x\n",
832 phba->brd_no, la->eventTag, phba->fc_eventTag,
833 phba->hba_state, phba->fc_flag);
834 lpfc_mbx_issue_link_down(phba);
837 lpfc_mbx_cmpl_read_la_free_mbuf:
838 lpfc_mbuf_free(phba, mp->virt, mp->phys);
840 mempool_free(pmb, phba->mbox_mem_pool);
845 * This routine handles processing a REG_LOGIN mailbox
846 * command upon completion. It is setup in the LPFC_MBOXQ
847 * as the completion routine when the command is
848 * handed off to the SLI layer.
851 lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
853 struct lpfc_sli *psli;
855 struct lpfc_dmabuf *mp;
856 struct lpfc_nodelist *ndlp;
861 ndlp = (struct lpfc_nodelist *) pmb->context2;
862 mp = (struct lpfc_dmabuf *) (pmb->context1);
864 pmb->context1 = NULL;
866 /* Good status, call state machine */
867 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
868 lpfc_mbuf_free(phba, mp->virt, mp->phys);
870 mempool_free( pmb, phba->mbox_mem_pool);
876 * This routine handles processing a Fabric REG_LOGIN mailbox
877 * command upon completion. It is setup in the LPFC_MBOXQ
878 * as the completion routine when the command is
879 * handed off to the SLI layer.
882 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
884 struct lpfc_sli *psli;
886 struct lpfc_dmabuf *mp;
887 struct lpfc_nodelist *ndlp;
888 struct lpfc_nodelist *ndlp_fdmi;
894 ndlp = (struct lpfc_nodelist *) pmb->context2;
895 mp = (struct lpfc_dmabuf *) (pmb->context1);
898 lpfc_mbuf_free(phba, mp->virt, mp->phys);
900 mempool_free( pmb, phba->mbox_mem_pool);
901 mempool_free( ndlp, phba->nlp_mem_pool);
903 /* FLOGI failed, so just use loop map to make discovery list */
904 lpfc_disc_list_loopmap(phba);
906 /* Start discovery */
907 lpfc_disc_start(phba);
911 pmb->context1 = NULL;
913 ndlp->nlp_rpi = mb->un.varWords[0];
914 ndlp->nlp_type |= NLP_FABRIC;
915 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
916 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
918 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
919 /* This NPort has been assigned an NPort_ID by the fabric as a
920 * result of the completed fabric login. Issue a State Change
921 * Registration (SCR) ELS request to the fabric controller
922 * (SCR_DID) so that this NPort gets RSCN events from the
925 lpfc_issue_els_scr(phba, SCR_DID, 0);
927 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
929 /* Allocate a new node instance. If the pool is empty,
930 * start the discovery process and skip the Nameserver
931 * login process. This is attempted again later on.
932 * Otherwise, issue a Port Login (PLOGI) to NameServer.
934 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
936 lpfc_disc_start(phba);
937 lpfc_mbuf_free(phba, mp->virt, mp->phys);
939 mempool_free( pmb, phba->mbox_mem_pool);
942 lpfc_nlp_init(phba, ndlp, NameServer_DID);
943 ndlp->nlp_type |= NLP_FABRIC;
946 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
947 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
948 lpfc_issue_els_plogi(phba, ndlp, 0);
949 if (phba->cfg_fdmi_on) {
950 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
953 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
954 ndlp_fdmi->nlp_type |= NLP_FABRIC;
955 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
956 lpfc_issue_els_plogi(phba, ndlp_fdmi, 0);
961 lpfc_mbuf_free(phba, mp->virt, mp->phys);
963 mempool_free( pmb, phba->mbox_mem_pool);
968 * This routine handles processing a NameServer REG_LOGIN mailbox
969 * command upon completion. It is setup in the LPFC_MBOXQ
970 * as the completion routine when the command is
971 * handed off to the SLI layer.
974 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
976 struct lpfc_sli *psli;
978 struct lpfc_dmabuf *mp;
979 struct lpfc_nodelist *ndlp;
984 ndlp = (struct lpfc_nodelist *) pmb->context2;
985 mp = (struct lpfc_dmabuf *) (pmb->context1);
988 lpfc_mbuf_free(phba, mp->virt, mp->phys);
990 mempool_free( pmb, phba->mbox_mem_pool);
991 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
993 /* RegLogin failed, so just use loop map to make discovery
995 lpfc_disc_list_loopmap(phba);
997 /* Start discovery */
998 lpfc_disc_start(phba);
1002 pmb->context1 = NULL;
1004 ndlp->nlp_rpi = mb->un.varWords[0];
1005 ndlp->nlp_type |= NLP_FABRIC;
1006 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1007 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1009 if (phba->hba_state < LPFC_HBA_READY) {
1010 /* Link up discovery requires Fabrib registration. */
1011 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1012 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1013 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1016 phba->fc_ns_retry = 0;
1017 /* Good status, issue CT Request to NameServer */
1018 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1019 /* Cannot issue NameServer Query, so finish up discovery */
1020 lpfc_disc_start(phba);
1023 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1025 mempool_free( pmb, phba->mbox_mem_pool);
1031 lpfc_register_remote_port(struct lpfc_hba * phba,
1032 struct lpfc_nodelist * ndlp)
1034 struct fc_rport *rport;
1035 struct lpfc_rport_data *rdata;
1036 struct fc_rport_identifiers rport_ids;
1038 /* Remote port has reappeared. Re-register w/ FC transport */
1039 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1040 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1041 rport_ids.port_id = ndlp->nlp_DID;
1042 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1044 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1046 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1047 "Warning: fc_remote_port_add failed\n");
1051 /* initialize static port data */
1052 rport->maxframe_size = ndlp->nlp_maxframe;
1053 rport->supported_classes = ndlp->nlp_class_sup;
1054 if ((rport->scsi_target_id != -1) &&
1055 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1056 ndlp->nlp_sid = rport->scsi_target_id;
1058 rdata = rport->dd_data;
1059 rdata->pnode = ndlp;
1061 if (ndlp->nlp_type & NLP_FCP_TARGET)
1062 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1063 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1064 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1067 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1068 fc_remote_port_rolechg(rport, rport_ids.roles);
1075 lpfc_unregister_remote_port(struct lpfc_hba * phba,
1076 struct lpfc_nodelist * ndlp)
1078 struct fc_rport *rport = ndlp->rport;
1079 struct lpfc_rport_data *rdata = rport->dd_data;
1082 rdata->pnode = NULL;
1083 fc_remote_port_delete(rport);
1089 lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1091 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1092 struct lpfc_sli *psli;
1095 /* Sanity check to ensure we are not moving to / from the same list */
1096 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1097 if (list != NLP_NO_LIST)
1100 spin_lock_irq(phba->host->host_lock);
1101 switch (nlp->nlp_flag & NLP_LIST_MASK) {
1102 case NLP_NO_LIST: /* Not on any list */
1104 case NLP_UNUSED_LIST:
1105 phba->fc_unused_cnt--;
1106 list_del(&nlp->nlp_listp);
1108 case NLP_PLOGI_LIST:
1109 phba->fc_plogi_cnt--;
1110 list_del(&nlp->nlp_listp);
1112 case NLP_ADISC_LIST:
1113 phba->fc_adisc_cnt--;
1114 list_del(&nlp->nlp_listp);
1116 case NLP_REGLOGIN_LIST:
1117 phba->fc_reglogin_cnt--;
1118 list_del(&nlp->nlp_listp);
1121 phba->fc_prli_cnt--;
1122 list_del(&nlp->nlp_listp);
1124 case NLP_UNMAPPED_LIST:
1125 phba->fc_unmap_cnt--;
1126 list_del(&nlp->nlp_listp);
1127 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1128 nlp->nlp_type &= ~NLP_FC_NODE;
1129 phba->nport_event_cnt++;
1131 rport_del = unmapped;
1133 case NLP_MAPPED_LIST:
1135 list_del(&nlp->nlp_listp);
1136 phba->nport_event_cnt++;
1142 list_del(&nlp->nlp_listp);
1143 /* Stop delay tmo if taking node off NPR list */
1144 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1145 (list != NLP_NPR_LIST)) {
1146 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1147 nlp->nlp_last_elscmd = 0;
1148 spin_unlock_irq(phba->host->host_lock);
1149 del_timer_sync(&nlp->nlp_delayfunc);
1150 spin_lock_irq(phba->host->host_lock);
1151 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1152 list_del_init(&nlp->els_retry_evt.evt_listp);
1157 nlp->nlp_flag &= ~NLP_LIST_MASK;
1159 /* Add NPort <did> to <num> list */
1160 lpfc_printf_log(phba,
1163 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1165 nlp->nlp_DID, list, nlp->nlp_flag);
1168 case NLP_NO_LIST: /* No list, just remove it */
1169 spin_unlock_irq(phba->host->host_lock);
1170 lpfc_nlp_remove(phba, nlp);
1171 spin_lock_irq(phba->host->host_lock);
1172 /* as node removed - stop further transport calls */
1175 case NLP_UNUSED_LIST:
1176 nlp->nlp_flag |= list;
1177 /* Put it at the end of the unused list */
1178 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1179 phba->fc_unused_cnt++;
1181 case NLP_PLOGI_LIST:
1182 nlp->nlp_flag |= list;
1183 /* Put it at the end of the plogi list */
1184 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1185 phba->fc_plogi_cnt++;
1187 case NLP_ADISC_LIST:
1188 nlp->nlp_flag |= list;
1189 /* Put it at the end of the adisc list */
1190 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1191 phba->fc_adisc_cnt++;
1193 case NLP_REGLOGIN_LIST:
1194 nlp->nlp_flag |= list;
1195 /* Put it at the end of the reglogin list */
1196 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1197 phba->fc_reglogin_cnt++;
1200 nlp->nlp_flag |= list;
1201 /* Put it at the end of the prli list */
1202 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1203 phba->fc_prli_cnt++;
1205 case NLP_UNMAPPED_LIST:
1206 rport_add = unmapped;
1207 /* ensure all vestiges of "mapped" significance are gone */
1208 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1209 nlp->nlp_flag |= list;
1210 /* Put it at the end of the unmap list */
1211 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1212 phba->fc_unmap_cnt++;
1213 phba->nport_event_cnt++;
1214 /* stop nodev tmo if running */
1215 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1216 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1217 spin_unlock_irq(phba->host->host_lock);
1218 del_timer_sync(&nlp->nlp_tmofunc);
1219 spin_lock_irq(phba->host->host_lock);
1220 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1221 list_del_init(&nlp->nodev_timeout_evt.
1225 nlp->nlp_type |= NLP_FC_NODE;
1227 case NLP_MAPPED_LIST:
1229 nlp->nlp_flag |= list;
1230 /* Put it at the end of the map list */
1231 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1233 phba->nport_event_cnt++;
1234 /* stop nodev tmo if running */
1235 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1236 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1237 spin_unlock_irq(phba->host->host_lock);
1238 del_timer_sync(&nlp->nlp_tmofunc);
1239 spin_lock_irq(phba->host->host_lock);
1240 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1241 list_del_init(&nlp->nodev_timeout_evt.
1247 nlp->nlp_flag |= list;
1248 /* Put it at the end of the npr list */
1249 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1252 if (!(nlp->nlp_flag & NLP_NODEV_TMO))
1253 mod_timer(&nlp->nlp_tmofunc,
1254 jiffies + HZ * phba->cfg_nodev_tmo);
1256 nlp->nlp_flag |= NLP_NODEV_TMO;
1257 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1263 spin_unlock_irq(phba->host->host_lock);
1266 * We make all the calls into the transport after we have
1267 * moved the node between lists. This so that we don't
1268 * release the lock while in-between lists.
1271 /* Don't upcall midlayer if we're unloading */
1272 if (!(phba->fc_flag & FC_UNLOADING)) {
1274 * We revalidate the rport pointer as the "add" function
1275 * may have removed the remote port.
1277 if ((rport_del != none) && nlp->rport)
1278 lpfc_unregister_remote_port(phba, nlp);
1280 if (rport_add != none) {
1282 * Tell the fc transport about the port, if we haven't
1283 * already. If we have, and it's a scsi entity, be
1284 * sure to unblock any attached scsi devices
1287 lpfc_register_remote_port(phba, nlp);
1290 * if we added to Mapped list, but the remote port
1291 * registration failed or assigned a target id outside
1292 * our presentable range - move the node to the
1295 if ((rport_add == mapped) &&
1297 (nlp->rport->scsi_target_id == -1) ||
1298 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1299 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1300 spin_lock_irq(phba->host->host_lock);
1301 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1302 spin_unlock_irq(phba->host->host_lock);
1303 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1311 * Start / ReStart rescue timer for Discovery / RSCN handling
1314 lpfc_set_disctmo(struct lpfc_hba * phba)
1318 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1319 /* For FAN, timeout should be greater then edtov */
1320 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1322 /* Normal discovery timeout should be > then ELS/CT timeout
1323 * FC spec states we need 3 * ratov for CT requests
1325 tmo = ((phba->fc_ratov * 3) + 3);
1328 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1329 spin_lock_irq(phba->host->host_lock);
1330 phba->fc_flag |= FC_DISC_TMO;
1331 spin_unlock_irq(phba->host->host_lock);
1333 /* Start Discovery Timer state <hba_state> */
1334 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1335 "%d:0247 Start Discovery Timer state x%x "
1336 "Data: x%x x%lx x%x x%x\n",
1338 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1339 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1345 * Cancel rescue timer for Discovery / RSCN handling
1348 lpfc_can_disctmo(struct lpfc_hba * phba)
1350 /* Turn off discovery timer if its running */
1351 if (phba->fc_flag & FC_DISC_TMO) {
1352 spin_lock_irq(phba->host->host_lock);
1353 phba->fc_flag &= ~FC_DISC_TMO;
1354 spin_unlock_irq(phba->host->host_lock);
1355 del_timer_sync(&phba->fc_disctmo);
1356 phba->work_hba_events &= ~WORKER_DISC_TMO;
1359 /* Cancel Discovery Timer state <hba_state> */
1360 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1361 "%d:0248 Cancel Discovery Timer state x%x "
1362 "Data: x%x x%x x%x\n",
1363 phba->brd_no, phba->hba_state, phba->fc_flag,
1364 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1370 * Check specified ring for outstanding IOCB on the SLI queue
1371 * Return true if iocb matches the specified nport
1374 lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1375 struct lpfc_sli_ring * pring,
1376 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1378 struct lpfc_sli *psli;
1383 if (pring->ringno == LPFC_ELS_RING) {
1384 switch (icmd->ulpCommand) {
1385 case CMD_GEN_REQUEST64_CR:
1386 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
1388 case CMD_ELS_REQUEST64_CR:
1389 case CMD_XMIT_ELS_RSP64_CX:
1390 if (iocb->context1 == (uint8_t *) ndlp)
1393 } else if (pring->ringno == psli->ip_ring) {
1395 } else if (pring->ringno == psli->fcp_ring) {
1396 /* Skip match check if waiting to relogin to FCP target */
1397 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1398 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
1401 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
1404 } else if (pring->ringno == psli->next_ring) {
1411 * Free resources / clean up outstanding I/Os
1412 * associated with nlp_rpi in the LPFC_NODELIST entry.
1415 lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1417 struct lpfc_sli *psli;
1418 struct lpfc_sli_ring *pring;
1419 struct lpfc_iocbq *iocb, *next_iocb;
1424 * Everything that matches on txcmplq will be returned
1425 * by firmware with a no rpi error.
1428 rpi = ndlp->nlp_rpi;
1430 /* Now process each ring */
1431 for (i = 0; i < psli->num_rings; i++) {
1432 pring = &psli->ring[i];
1434 spin_lock_irq(phba->host->host_lock);
1435 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1438 * Check to see if iocb matches the nport we are
1441 if ((lpfc_check_sli_ndlp
1442 (phba, pring, iocb, ndlp))) {
1443 /* It matches, so deque and call compl
1445 list_del(&iocb->list);
1447 if (iocb->iocb_cmpl) {
1450 IOSTAT_LOCAL_REJECT;
1451 icmd->un.ulpWord[4] =
1453 spin_unlock_irq(phba->host->
1455 (iocb->iocb_cmpl) (phba,
1457 spin_lock_irq(phba->host->
1460 lpfc_sli_release_iocbq(phba,
1464 spin_unlock_irq(phba->host->host_lock);
1472 * Free rpi associated with LPFC_NODELIST entry.
1473 * This routine is called from lpfc_freenode(), when we are removing
1474 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1475 * LOGO that completes successfully, and we are waiting to PLOGI back
1476 * to the remote NPort. In addition, it is called after we receive
1477 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1478 * we are waiting to PLOGI back to the remote NPort.
1481 lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1486 if (ndlp->nlp_rpi) {
1487 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1488 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1489 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1490 rc = lpfc_sli_issue_mbox
1491 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1492 if (rc == MBX_NOT_FINISHED)
1493 mempool_free( mbox, phba->mbox_mem_pool);
1495 lpfc_no_rpi(phba, ndlp);
1503 * Free resources associated with LPFC_NODELIST entry
1504 * so it can be freed.
1507 lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1510 LPFC_MBOXQ_t *nextmb;
1511 struct lpfc_dmabuf *mp;
1513 /* Cleanup node for NPort <nlp_DID> */
1514 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1515 "%d:0900 Cleanup node for NPort x%x "
1516 "Data: x%x x%x x%x\n",
1517 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1518 ndlp->nlp_state, ndlp->nlp_rpi);
1520 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1523 * if unloading the driver - just leave the remote port in place.
1524 * The driver unload will force the attached devices to detach
1525 * and flush cache's w/o generating flush errors.
1527 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1528 lpfc_unregister_remote_port(phba, ndlp);
1529 ndlp->nlp_sid = NLP_NO_SID;
1532 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1533 if ((mb = phba->sli.mbox_active)) {
1534 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1535 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1536 mb->context2 = NULL;
1537 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1540 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1541 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1542 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1543 mp = (struct lpfc_dmabuf *) (mb->context1);
1545 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1548 list_del(&mb->list);
1549 mempool_free(mb, phba->mbox_mem_pool);
1553 lpfc_els_abort(phba,ndlp,0);
1554 spin_lock_irq(phba->host->host_lock);
1555 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1556 spin_unlock_irq(phba->host->host_lock);
1557 del_timer_sync(&ndlp->nlp_tmofunc);
1559 ndlp->nlp_last_elscmd = 0;
1560 del_timer_sync(&ndlp->nlp_delayfunc);
1562 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1563 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1564 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1565 list_del_init(&ndlp->els_retry_evt.evt_listp);
1567 lpfc_unreg_rpi(phba, ndlp);
1573 * Check to see if we can free the nlp back to the freelist.
1574 * If we are in the middle of using the nlp in the discovery state
1575 * machine, defer the free till we reach the end of the state machine.
1578 lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1580 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1581 spin_lock_irq(phba->host->host_lock);
1582 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1583 spin_unlock_irq(phba->host->host_lock);
1584 del_timer_sync(&ndlp->nlp_tmofunc);
1585 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1586 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1591 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1592 spin_lock_irq(phba->host->host_lock);
1593 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1594 spin_unlock_irq(phba->host->host_lock);
1595 ndlp->nlp_last_elscmd = 0;
1596 del_timer_sync(&ndlp->nlp_delayfunc);
1597 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1598 list_del_init(&ndlp->els_retry_evt.evt_listp);
1601 if (ndlp->nlp_disc_refcnt) {
1602 spin_lock_irq(phba->host->host_lock);
1603 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1604 spin_unlock_irq(phba->host->host_lock);
1606 lpfc_freenode(phba, ndlp);
1607 mempool_free( ndlp, phba->nlp_mem_pool);
1613 lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1619 if (did == Bcast_DID)
1622 if (ndlp->nlp_DID == 0) {
1626 /* First check for Direct match */
1627 if (ndlp->nlp_DID == did)
1630 /* Next check for area/domain identically equals 0 match */
1631 mydid.un.word = phba->fc_myDID;
1632 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
1636 matchdid.un.word = did;
1637 ndlpdid.un.word = ndlp->nlp_DID;
1638 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1639 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1640 (mydid.un.b.area == matchdid.un.b.area)) {
1641 if ((ndlpdid.un.b.domain == 0) &&
1642 (ndlpdid.un.b.area == 0)) {
1643 if (ndlpdid.un.b.id)
1649 matchdid.un.word = ndlp->nlp_DID;
1650 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1651 (mydid.un.b.area == ndlpdid.un.b.area)) {
1652 if ((matchdid.un.b.domain == 0) &&
1653 (matchdid.un.b.area == 0)) {
1654 if (matchdid.un.b.id)
1662 /* Search for a nodelist entry on a specific list */
1663 struct lpfc_nodelist *
1664 lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1666 struct lpfc_nodelist *ndlp, *next_ndlp;
1669 spin_lock_irq(phba->host->host_lock);
1670 if (order & NLP_SEARCH_UNMAPPED) {
1671 list_for_each_entry_safe(ndlp, next_ndlp,
1672 &phba->fc_nlpunmap_list, nlp_listp) {
1673 if (lpfc_matchdid(phba, ndlp, did)) {
1674 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1675 ((uint32_t) ndlp->nlp_xri << 16) |
1676 ((uint32_t) ndlp->nlp_type << 8) |
1677 ((uint32_t) ndlp->nlp_rpi & 0xff));
1678 /* FIND node DID unmapped */
1679 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1680 "%d:0929 FIND node DID unmapped"
1681 " Data: x%p x%x x%x x%x\n",
1683 ndlp, ndlp->nlp_DID,
1684 ndlp->nlp_flag, data1);
1685 spin_unlock_irq(phba->host->host_lock);
1691 if (order & NLP_SEARCH_MAPPED) {
1692 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1694 if (lpfc_matchdid(phba, ndlp, did)) {
1696 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1697 ((uint32_t) ndlp->nlp_xri << 16) |
1698 ((uint32_t) ndlp->nlp_type << 8) |
1699 ((uint32_t) ndlp->nlp_rpi & 0xff));
1700 /* FIND node DID mapped */
1701 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1702 "%d:0930 FIND node DID mapped "
1703 "Data: x%p x%x x%x x%x\n",
1705 ndlp, ndlp->nlp_DID,
1706 ndlp->nlp_flag, data1);
1707 spin_unlock_irq(phba->host->host_lock);
1713 if (order & NLP_SEARCH_PLOGI) {
1714 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1716 if (lpfc_matchdid(phba, ndlp, did)) {
1718 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1719 ((uint32_t) ndlp->nlp_xri << 16) |
1720 ((uint32_t) ndlp->nlp_type << 8) |
1721 ((uint32_t) ndlp->nlp_rpi & 0xff));
1722 /* LOG change to PLOGI */
1723 /* FIND node DID plogi */
1724 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1725 "%d:0908 FIND node DID plogi "
1726 "Data: x%p x%x x%x x%x\n",
1728 ndlp, ndlp->nlp_DID,
1729 ndlp->nlp_flag, data1);
1730 spin_unlock_irq(phba->host->host_lock);
1736 if (order & NLP_SEARCH_ADISC) {
1737 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1739 if (lpfc_matchdid(phba, ndlp, did)) {
1741 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1742 ((uint32_t) ndlp->nlp_xri << 16) |
1743 ((uint32_t) ndlp->nlp_type << 8) |
1744 ((uint32_t) ndlp->nlp_rpi & 0xff));
1745 /* LOG change to ADISC */
1746 /* FIND node DID adisc */
1747 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1748 "%d:0931 FIND node DID adisc "
1749 "Data: x%p x%x x%x x%x\n",
1751 ndlp, ndlp->nlp_DID,
1752 ndlp->nlp_flag, data1);
1758 if (order & NLP_SEARCH_REGLOGIN) {
1759 list_for_each_entry_safe(ndlp, next_ndlp,
1760 &phba->fc_reglogin_list, nlp_listp) {
1761 if (lpfc_matchdid(phba, ndlp, did)) {
1763 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1764 ((uint32_t) ndlp->nlp_xri << 16) |
1765 ((uint32_t) ndlp->nlp_type << 8) |
1766 ((uint32_t) ndlp->nlp_rpi & 0xff));
1767 /* LOG change to REGLOGIN */
1768 /* FIND node DID reglogin */
1769 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1770 "%d:0931 FIND node DID reglogin"
1771 " Data: x%p x%x x%x x%x\n",
1773 ndlp, ndlp->nlp_DID,
1774 ndlp->nlp_flag, data1);
1775 spin_unlock_irq(phba->host->host_lock);
1781 if (order & NLP_SEARCH_PRLI) {
1782 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1784 if (lpfc_matchdid(phba, ndlp, did)) {
1786 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1787 ((uint32_t) ndlp->nlp_xri << 16) |
1788 ((uint32_t) ndlp->nlp_type << 8) |
1789 ((uint32_t) ndlp->nlp_rpi & 0xff));
1790 /* LOG change to PRLI */
1791 /* FIND node DID prli */
1792 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1793 "%d:0931 FIND node DID prli "
1794 "Data: x%p x%x x%x x%x\n",
1796 ndlp, ndlp->nlp_DID,
1797 ndlp->nlp_flag, data1);
1803 if (order & NLP_SEARCH_NPR) {
1804 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1806 if (lpfc_matchdid(phba, ndlp, did)) {
1808 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1809 ((uint32_t) ndlp->nlp_xri << 16) |
1810 ((uint32_t) ndlp->nlp_type << 8) |
1811 ((uint32_t) ndlp->nlp_rpi & 0xff));
1812 /* LOG change to NPR */
1813 /* FIND node DID npr */
1814 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1815 "%d:0931 FIND node DID npr "
1816 "Data: x%p x%x x%x x%x\n",
1818 ndlp, ndlp->nlp_DID,
1819 ndlp->nlp_flag, data1);
1820 spin_unlock_irq(phba->host->host_lock);
1826 if (order & NLP_SEARCH_UNUSED) {
1827 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1829 if (lpfc_matchdid(phba, ndlp, did)) {
1831 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1832 ((uint32_t) ndlp->nlp_xri << 16) |
1833 ((uint32_t) ndlp->nlp_type << 8) |
1834 ((uint32_t) ndlp->nlp_rpi & 0xff));
1835 /* LOG change to UNUSED */
1836 /* FIND node DID unused */
1837 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1838 "%d:0931 FIND node DID unused "
1839 "Data: x%p x%x x%x x%x\n",
1841 ndlp, ndlp->nlp_DID,
1842 ndlp->nlp_flag, data1);
1843 spin_unlock_irq(phba->host->host_lock);
1849 spin_unlock_irq(phba->host->host_lock);
1851 /* FIND node did <did> NOT FOUND */
1852 lpfc_printf_log(phba,
1855 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1856 phba->brd_no, did, order);
1858 /* no match found */
1862 struct lpfc_nodelist *
1863 lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1865 struct lpfc_nodelist *ndlp;
1868 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1870 if ((phba->fc_flag & FC_RSCN_MODE) &&
1871 ((lpfc_rscn_payload_check(phba, did) == 0)))
1873 ndlp = (struct lpfc_nodelist *)
1874 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1877 lpfc_nlp_init(phba, ndlp, did);
1878 ndlp->nlp_state = NLP_STE_NPR_NODE;
1879 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1880 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1883 if (phba->fc_flag & FC_RSCN_MODE) {
1884 if (lpfc_rscn_payload_check(phba, did)) {
1885 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1887 /* Since this node is marked for discovery,
1888 * delay timeout is not needed.
1890 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1891 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1892 del_timer_sync(&ndlp->nlp_delayfunc);
1893 if (!list_empty(&ndlp->els_retry_evt.
1895 list_del_init(&ndlp->els_retry_evt.
1899 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1903 flg = ndlp->nlp_flag & NLP_LIST_MASK;
1904 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
1906 ndlp->nlp_state = NLP_STE_NPR_NODE;
1907 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1908 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1913 /* Build a list of nodes to discover based on the loopmap */
1915 lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1918 uint32_t alpa, index;
1920 if (phba->hba_state <= LPFC_LINK_DOWN) {
1923 if (phba->fc_topology != TOPOLOGY_LOOP) {
1927 /* Check for loop map present or not */
1928 if (phba->alpa_map[0]) {
1929 for (j = 1; j <= phba->alpa_map[0]; j++) {
1930 alpa = phba->alpa_map[j];
1932 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1935 lpfc_setup_disc_node(phba, alpa);
1938 /* No alpamap, so try all alpa's */
1939 for (j = 0; j < FC_MAXLOOP; j++) {
1940 /* If cfg_scan_down is set, start from highest
1941 * ALPA (0xef) to lowest (0x1).
1943 if (phba->cfg_scan_down)
1946 index = FC_MAXLOOP - j - 1;
1947 alpa = lpfcAlpaArray[index];
1948 if ((phba->fc_myDID & 0xff) == alpa) {
1952 lpfc_setup_disc_node(phba, alpa);
1958 /* Start Link up / RSCN discovery on NPR list */
1960 lpfc_disc_start(struct lpfc_hba * phba)
1962 struct lpfc_sli *psli;
1964 struct lpfc_nodelist *ndlp, *next_ndlp;
1965 uint32_t did_changed, num_sent;
1966 uint32_t clear_la_pending;
1971 if (phba->hba_state <= LPFC_LINK_DOWN) {
1974 if (phba->hba_state == LPFC_CLEAR_LA)
1975 clear_la_pending = 1;
1977 clear_la_pending = 0;
1979 if (phba->hba_state < LPFC_HBA_READY) {
1980 phba->hba_state = LPFC_DISC_AUTH;
1982 lpfc_set_disctmo(phba);
1984 if (phba->fc_prevDID == phba->fc_myDID) {
1989 phba->fc_prevDID = phba->fc_myDID;
1990 phba->num_disc_nodes = 0;
1992 /* Start Discovery state <hba_state> */
1993 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1994 "%d:0202 Start Discovery hba state x%x "
1995 "Data: x%x x%x x%x\n",
1996 phba->brd_no, phba->hba_state, phba->fc_flag,
1997 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1999 /* If our did changed, we MUST do PLOGI */
2000 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2002 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2004 spin_lock_irq(phba->host->host_lock);
2005 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2006 spin_unlock_irq(phba->host->host_lock);
2011 /* First do ADISCs - if any */
2012 num_sent = lpfc_els_disc_adisc(phba);
2017 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2018 /* If we get here, there is nothing to ADISC */
2019 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2020 phba->hba_state = LPFC_CLEAR_LA;
2021 lpfc_clear_la(phba, mbox);
2022 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2023 rc = lpfc_sli_issue_mbox(phba, mbox,
2024 (MBX_NOWAIT | MBX_STOP_IOCB));
2025 if (rc == MBX_NOT_FINISHED) {
2026 mempool_free( mbox, phba->mbox_mem_pool);
2027 lpfc_disc_flush_list(phba);
2028 psli->ring[(psli->ip_ring)].flag &=
2029 ~LPFC_STOP_IOCB_EVENT;
2030 psli->ring[(psli->fcp_ring)].flag &=
2031 ~LPFC_STOP_IOCB_EVENT;
2032 psli->ring[(psli->next_ring)].flag &=
2033 ~LPFC_STOP_IOCB_EVENT;
2034 phba->hba_state = LPFC_HBA_READY;
2038 /* Next do PLOGIs - if any */
2039 num_sent = lpfc_els_disc_plogi(phba);
2044 if (phba->fc_flag & FC_RSCN_MODE) {
2045 /* Check to see if more RSCNs came in while we
2046 * were processing this one.
2048 if ((phba->fc_rscn_id_cnt == 0) &&
2049 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2050 spin_lock_irq(phba->host->host_lock);
2051 phba->fc_flag &= ~FC_RSCN_MODE;
2052 spin_unlock_irq(phba->host->host_lock);
2054 lpfc_els_handle_rscn(phba);
2061 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2062 * ring the match the sppecified nodelist.
2065 lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2067 struct lpfc_sli *psli;
2069 struct lpfc_iocbq *iocb, *next_iocb;
2070 struct lpfc_sli_ring *pring;
2071 struct lpfc_dmabuf *mp;
2074 pring = &psli->ring[LPFC_ELS_RING];
2076 /* Error matching iocb on txq or txcmplq
2077 * First check the txq.
2079 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2080 if (iocb->context1 != ndlp) {
2084 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2085 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2087 list_del(&iocb->list);
2089 lpfc_els_free_iocb(phba, iocb);
2093 /* Next check the txcmplq */
2094 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2095 if (iocb->context1 != ndlp) {
2099 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2100 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2102 iocb->iocb_cmpl = NULL;
2103 /* context2 = cmd, context2->next = rsp, context3 =
2105 if (iocb->context2) {
2106 /* Free the response IOCB before handling the
2109 mp = (struct lpfc_dmabuf *) (iocb->context2);
2110 mp = list_get_first(&mp->list,
2114 /* Delay before releasing rsp buffer to
2115 * give UNREG mbox a chance to take
2119 &phba->freebufList);
2121 lpfc_mbuf_free(phba,
2122 ((struct lpfc_dmabuf *)
2123 iocb->context2)->virt,
2124 ((struct lpfc_dmabuf *)
2125 iocb->context2)->phys);
2126 kfree(iocb->context2);
2129 if (iocb->context3) {
2130 lpfc_mbuf_free(phba,
2131 ((struct lpfc_dmabuf *)
2132 iocb->context3)->virt,
2133 ((struct lpfc_dmabuf *)
2134 iocb->context3)->phys);
2135 kfree(iocb->context3);
2144 lpfc_disc_flush_list(struct lpfc_hba * phba)
2146 struct lpfc_nodelist *ndlp, *next_ndlp;
2148 if (phba->fc_plogi_cnt) {
2149 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2151 lpfc_free_tx(phba, ndlp);
2152 lpfc_nlp_remove(phba, ndlp);
2155 if (phba->fc_adisc_cnt) {
2156 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2158 lpfc_free_tx(phba, ndlp);
2159 lpfc_nlp_remove(phba, ndlp);
2165 /*****************************************************************************/
2167 * NAME: lpfc_disc_timeout
2169 * FUNCTION: Fibre Channel driver discovery timeout routine.
2171 * EXECUTION ENVIRONMENT: interrupt only
2179 /*****************************************************************************/
2181 lpfc_disc_timeout(unsigned long ptr)
2183 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2184 unsigned long flags = 0;
2186 if (unlikely(!phba))
2189 spin_lock_irqsave(phba->host->host_lock, flags);
2190 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2191 phba->work_hba_events |= WORKER_DISC_TMO;
2192 if (phba->work_wait)
2193 wake_up(phba->work_wait);
2195 spin_unlock_irqrestore(phba->host->host_lock, flags);
2200 lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2202 struct lpfc_sli *psli;
2203 struct lpfc_nodelist *ndlp, *next_ndlp;
2204 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2205 int rc, clrlaerr = 0;
2207 if (unlikely(!phba))
2210 if (!(phba->fc_flag & FC_DISC_TMO))
2215 spin_lock_irq(phba->host->host_lock);
2216 phba->fc_flag &= ~FC_DISC_TMO;
2217 spin_unlock_irq(phba->host->host_lock);
2219 switch (phba->hba_state) {
2221 case LPFC_LOCAL_CFG_LINK:
2222 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2224 lpfc_printf_log(phba,
2227 "%d:0221 FAN timeout\n",
2230 /* Start discovery by sending FLOGI, clean up old rpis */
2231 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2233 if (ndlp->nlp_type & NLP_FABRIC) {
2234 /* Clean up the ndlp on Fabric connections */
2235 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2236 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2237 /* Fail outstanding IO now since device
2238 * is marked for PLOGI.
2240 lpfc_unreg_rpi(phba, ndlp);
2243 phba->hba_state = LPFC_FLOGI;
2244 lpfc_set_disctmo(phba);
2245 lpfc_initial_flogi(phba);
2249 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2250 /* Initial FLOGI timeout */
2251 lpfc_printf_log(phba,
2254 "%d:0222 Initial FLOGI timeout\n",
2257 /* Assume no Fabric and go on with discovery.
2258 * Check for outstanding ELS FLOGI to abort.
2261 /* FLOGI failed, so just use loop map to make discovery list */
2262 lpfc_disc_list_loopmap(phba);
2264 /* Start discovery */
2265 lpfc_disc_start(phba);
2268 case LPFC_FABRIC_CFG_LINK:
2269 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2271 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2272 "%d:0223 Timeout while waiting for NameServer "
2273 "login\n", phba->brd_no);
2275 /* Next look for NameServer ndlp */
2276 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2278 lpfc_nlp_remove(phba, ndlp);
2279 /* Start discovery */
2280 lpfc_disc_start(phba);
2284 /* Check for wait for NameServer Rsp timeout */
2285 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2286 "%d:0224 NameServer Query timeout "
2289 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2291 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2294 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2295 /* Try it one more time */
2296 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2300 phba->fc_ns_retry = 0;
2303 /* Nothing to authenticate, so CLEAR_LA right now */
2304 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2307 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2308 "%d:0226 Device Discovery "
2309 "completion error\n",
2311 phba->hba_state = LPFC_HBA_ERROR;
2315 phba->hba_state = LPFC_CLEAR_LA;
2316 lpfc_clear_la(phba, clearlambox);
2317 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2318 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2319 (MBX_NOWAIT | MBX_STOP_IOCB));
2320 if (rc == MBX_NOT_FINISHED) {
2321 mempool_free(clearlambox, phba->mbox_mem_pool);
2326 /* Setup and issue mailbox INITIALIZE LINK command */
2327 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2328 if (!initlinkmbox) {
2329 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2330 "%d:0226 Device Discovery "
2331 "completion error\n",
2333 phba->hba_state = LPFC_HBA_ERROR;
2337 lpfc_linkdown(phba);
2338 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2339 phba->cfg_link_speed);
2340 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2341 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2342 (MBX_NOWAIT | MBX_STOP_IOCB));
2343 if (rc == MBX_NOT_FINISHED)
2344 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2348 case LPFC_DISC_AUTH:
2349 /* Node Authentication timeout */
2350 lpfc_printf_log(phba,
2353 "%d:0227 Node Authentication timeout\n",
2355 lpfc_disc_flush_list(phba);
2356 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2359 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2360 "%d:0226 Device Discovery "
2361 "completion error\n",
2363 phba->hba_state = LPFC_HBA_ERROR;
2366 phba->hba_state = LPFC_CLEAR_LA;
2367 lpfc_clear_la(phba, clearlambox);
2368 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2369 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2370 (MBX_NOWAIT | MBX_STOP_IOCB));
2371 if (rc == MBX_NOT_FINISHED) {
2372 mempool_free(clearlambox, phba->mbox_mem_pool);
2378 /* CLEAR LA timeout */
2379 lpfc_printf_log(phba,
2382 "%d:0228 CLEAR LA timeout\n",
2387 case LPFC_HBA_READY:
2388 if (phba->fc_flag & FC_RSCN_MODE) {
2389 lpfc_printf_log(phba,
2392 "%d:0231 RSCN timeout Data: x%x x%x\n",
2394 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2396 /* Cleanup any outstanding ELS commands */
2397 lpfc_els_flush_cmd(phba);
2399 lpfc_els_flush_rscn(phba);
2400 lpfc_disc_flush_list(phba);
2406 lpfc_disc_flush_list(phba);
2407 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2408 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2409 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2410 phba->hba_state = LPFC_HBA_READY;
2417 lpfc_nodev_timeout(unsigned long ptr)
2419 struct lpfc_hba *phba;
2420 struct lpfc_nodelist *ndlp;
2421 unsigned long iflag;
2422 struct lpfc_work_evt *evtp;
2424 ndlp = (struct lpfc_nodelist *)ptr;
2425 phba = ndlp->nlp_phba;
2426 evtp = &ndlp->nodev_timeout_evt;
2427 spin_lock_irqsave(phba->host->host_lock, iflag);
2429 if (!list_empty(&evtp->evt_listp)) {
2430 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2433 evtp->evt_arg1 = ndlp;
2434 evtp->evt = LPFC_EVT_NODEV_TMO;
2435 list_add_tail(&evtp->evt_listp, &phba->work_list);
2436 if (phba->work_wait)
2437 wake_up(phba->work_wait);
2439 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2445 * This routine handles processing a NameServer REG_LOGIN mailbox
2446 * command upon completion. It is setup in the LPFC_MBOXQ
2447 * as the completion routine when the command is
2448 * handed off to the SLI layer.
2451 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2453 struct lpfc_sli *psli;
2455 struct lpfc_dmabuf *mp;
2456 struct lpfc_nodelist *ndlp;
2461 ndlp = (struct lpfc_nodelist *) pmb->context2;
2462 mp = (struct lpfc_dmabuf *) (pmb->context1);
2464 pmb->context1 = NULL;
2466 ndlp->nlp_rpi = mb->un.varWords[0];
2467 ndlp->nlp_type |= NLP_FABRIC;
2468 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2469 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2471 /* Start issuing Fabric-Device Management Interface (FDMI)
2472 * command to 0xfffffa (FDMI well known port)
2474 if (phba->cfg_fdmi_on == 1) {
2475 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2478 * Delay issuing FDMI command if fdmi-on=2
2479 * (supporting RPA/hostnmae)
2481 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2484 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2486 mempool_free( pmb, phba->mbox_mem_pool);
2492 * This routine looks up the ndlp lists
2493 * for the given RPI. If rpi found
2494 * it return the node list pointer
2497 struct lpfc_nodelist *
2498 lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2500 struct lpfc_nodelist *ndlp;
2501 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2502 &phba->fc_nlpmap_list,
2503 &phba->fc_plogi_list,
2504 &phba->fc_adisc_list,
2505 &phba->fc_reglogin_list};
2508 spin_lock_irq(phba->host->host_lock);
2509 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2510 list_for_each_entry(ndlp, lists[i], nlp_listp)
2511 if (ndlp->nlp_rpi == rpi) {
2512 spin_unlock_irq(phba->host->host_lock);
2515 spin_unlock_irq(phba->host->host_lock);
2520 lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2523 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2524 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2525 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2526 init_timer(&ndlp->nlp_tmofunc);
2527 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2528 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2529 init_timer(&ndlp->nlp_delayfunc);
2530 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2531 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2532 ndlp->nlp_DID = did;
2533 ndlp->nlp_phba = phba;
2534 ndlp->nlp_sid = NLP_NO_SID;