1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/interrupt.h>
30 #include <linux/lockdep.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_disc.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* AlpaArray for assignment of scsid for scan-down and bind_method */
54 static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
70 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
71 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
72 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
73 static int lpfc_fcf_inuse(struct lpfc_hba *);
76 lpfc_terminate_rport_io(struct fc_rport *rport)
78 struct lpfc_rport_data *rdata;
79 struct lpfc_nodelist * ndlp;
80 struct lpfc_hba *phba;
82 rdata = rport->dd_data;
85 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
86 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
87 printk(KERN_ERR "Cannot find remote node"
88 " to terminate I/O Data x%x\n",
95 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
96 "rport terminate: sid:x%x did:x%x flg:x%x",
97 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
99 if (ndlp->nlp_sid != NLP_NO_SID) {
100 lpfc_sli_abort_iocb(ndlp->vport,
101 &phba->sli.sli3_ring[LPFC_FCP_RING],
102 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
107 * This function will be called when dev_loss_tmo fire.
110 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
112 struct lpfc_rport_data *rdata;
113 struct lpfc_nodelist * ndlp;
114 struct lpfc_vport *vport;
115 struct Scsi_Host *shost;
116 struct lpfc_hba *phba;
117 struct lpfc_work_evt *evtp;
120 unsigned long iflags;
122 rdata = rport->dd_data;
124 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
131 "rport devlosscb: sid:x%x did:x%x flg:x%x",
132 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
134 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
135 "3181 dev_loss_callbk x%06x, rport x%px flg x%x\n",
136 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
138 /* Don't defer this if we are in the process of deleting the vport
139 * or unloading the driver. The unload will cleanup the node
140 * appropriately we just need to cleanup the ndlp rport info here.
142 if (vport->load_flag & FC_UNLOADING) {
143 put_node = rdata->pnode != NULL;
144 put_rport = ndlp->rport != NULL;
150 put_device(&rport->dev);
154 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
157 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
158 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
159 "6789 rport name %llx != node port name %llx",
161 wwn_to_u64(ndlp->nlp_portname.u.wwn));
163 evtp = &ndlp->dev_loss_evt;
165 if (!list_empty(&evtp->evt_listp)) {
166 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
167 "6790 rport name %llx dev_loss_evt pending",
172 shost = lpfc_shost_from_vport(vport);
173 spin_lock_irqsave(shost->host_lock, iflags);
174 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
175 spin_unlock_irqrestore(shost->host_lock, iflags);
177 /* We need to hold the node by incrementing the reference
178 * count until this queued work is done
180 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
182 spin_lock_irqsave(&phba->hbalock, iflags);
183 if (evtp->evt_arg1) {
184 evtp->evt = LPFC_EVT_DEV_LOSS;
185 list_add_tail(&evtp->evt_listp, &phba->work_list);
186 lpfc_worker_wake_up(phba);
188 spin_unlock_irqrestore(&phba->hbalock, iflags);
194 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
195 * @ndlp: Pointer to remote node object.
197 * This function is called from the worker thread when devloss timeout timer
198 * expires. For SLI4 host, this routine shall return 1 when at lease one
199 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
200 * routine shall return 0 when there is no remote node is still in use of FCF
201 * when devloss timeout happened to this @ndlp.
204 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
206 struct lpfc_rport_data *rdata;
207 struct fc_rport *rport;
208 struct lpfc_vport *vport;
209 struct lpfc_hba *phba;
210 struct Scsi_Host *shost;
215 unsigned long iflags;
219 shost = lpfc_shost_from_vport(vport);
221 spin_lock_irqsave(shost->host_lock, iflags);
222 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
223 spin_unlock_irqrestore(shost->host_lock, iflags);
228 name = (uint8_t *) &ndlp->nlp_portname;
231 if (phba->sli_rev == LPFC_SLI_REV4)
232 fcf_inuse = lpfc_fcf_inuse(phba);
234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
235 "rport devlosstmo:did:x%x type:x%x id:x%x",
236 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
238 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
239 "3182 dev_loss_tmo_handler x%06x, rport x%px flg x%x\n",
240 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
243 * lpfc_nlp_remove if reached with dangling rport drops the
244 * reference. To make sure that does not happen clear rport
245 * pointer in ndlp before lpfc_nlp_put.
247 rdata = rport->dd_data;
249 /* Don't defer this if we are in the process of deleting the vport
250 * or unloading the driver. The unload will cleanup the node
251 * appropriately we just need to cleanup the ndlp rport info here.
253 if (vport->load_flag & FC_UNLOADING) {
254 if (ndlp->nlp_sid != NLP_NO_SID) {
255 /* flush the target */
256 lpfc_sli_abort_iocb(vport,
257 &phba->sli.sli3_ring[LPFC_FCP_RING],
258 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
260 put_node = rdata->pnode != NULL;
265 put_device(&rport->dev);
270 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
271 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
272 "0284 Devloss timeout Ignored on "
273 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
275 *name, *(name+1), *(name+2), *(name+3),
276 *(name+4), *(name+5), *(name+6), *(name+7),
281 put_node = rdata->pnode != NULL;
286 put_device(&rport->dev);
288 if (ndlp->nlp_type & NLP_FABRIC)
291 if (ndlp->nlp_sid != NLP_NO_SID) {
293 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
294 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
298 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
299 "0203 Devloss timeout on "
300 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
301 "NPort x%06x Data: x%x x%x x%x\n",
302 *name, *(name+1), *(name+2), *(name+3),
303 *(name+4), *(name+5), *(name+6), *(name+7),
304 ndlp->nlp_DID, ndlp->nlp_flag,
305 ndlp->nlp_state, ndlp->nlp_rpi);
307 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
308 "0204 Devloss timeout on "
309 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
310 "NPort x%06x Data: x%x x%x x%x\n",
311 *name, *(name+1), *(name+2), *(name+3),
312 *(name+4), *(name+5), *(name+6), *(name+7),
313 ndlp->nlp_DID, ndlp->nlp_flag,
314 ndlp->nlp_state, ndlp->nlp_rpi);
317 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
318 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
319 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
320 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
321 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
322 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
328 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
329 * @phba: Pointer to hba context object.
330 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
331 * @nlp_did: remote node identifer with devloss timeout.
333 * This function is called from the worker thread after invoking devloss
334 * timeout handler and releasing the reference count for the ndlp with
335 * which the devloss timeout was handled for SLI4 host. For the devloss
336 * timeout of the last remote node which had been in use of FCF, when this
337 * routine is invoked, it shall be guaranteed that none of the remote are
338 * in-use of FCF. When devloss timeout to the last remote using the FCF,
339 * if the FIP engine is neither in FCF table scan process nor roundrobin
340 * failover process, the in-use FCF shall be unregistered. If the FIP
341 * engine is in FCF discovery process, the devloss timeout state shall
342 * be set for either the FCF table scan process or roundrobin failover
343 * process to unregister the in-use FCF.
346 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
349 /* If devloss timeout happened to a remote node when FCF had no
350 * longer been in-use, do nothing.
355 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
356 spin_lock_irq(&phba->hbalock);
357 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
358 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
359 spin_unlock_irq(&phba->hbalock);
362 phba->hba_flag |= HBA_DEVLOSS_TMO;
363 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
364 "2847 Last remote node (x%x) using "
365 "FCF devloss tmo\n", nlp_did);
367 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
368 spin_unlock_irq(&phba->hbalock);
369 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
370 "2868 Devloss tmo to FCF rediscovery "
374 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
375 spin_unlock_irq(&phba->hbalock);
376 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
377 "2869 Devloss tmo to idle FIP engine, "
378 "unreg in-use FCF and rescan.\n");
379 /* Unregister in-use FCF and rescan */
380 lpfc_unregister_fcf_rescan(phba);
383 spin_unlock_irq(&phba->hbalock);
384 if (phba->hba_flag & FCF_TS_INPROG)
385 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
386 "2870 FCF table scan in progress\n");
387 if (phba->hba_flag & FCF_RR_INPROG)
388 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
389 "2871 FLOGI roundrobin FCF failover "
392 lpfc_unregister_unused_fcf(phba);
396 * lpfc_alloc_fast_evt - Allocates data structure for posting event
397 * @phba: Pointer to hba context object.
399 * This function is called from the functions which need to post
400 * events from interrupt context. This function allocates data
401 * structure required for posting event. It also keeps track of
402 * number of events pending and prevent event storm when there are
405 struct lpfc_fast_path_event *
406 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
407 struct lpfc_fast_path_event *ret;
409 /* If there are lot of fast event do not exhaust memory due to this */
410 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
413 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
416 atomic_inc(&phba->fast_event_count);
417 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
418 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
424 * lpfc_free_fast_evt - Frees event data structure
425 * @phba: Pointer to hba context object.
426 * @evt: Event object which need to be freed.
428 * This function frees the data structure required for posting
432 lpfc_free_fast_evt(struct lpfc_hba *phba,
433 struct lpfc_fast_path_event *evt) {
435 atomic_dec(&phba->fast_event_count);
440 * lpfc_send_fastpath_evt - Posts events generated from fast path
441 * @phba: Pointer to hba context object.
442 * @evtp: Event data structure.
444 * This function is called from worker thread, when the interrupt
445 * context need to post an event. This function posts the event
446 * to fc transport netlink interface.
449 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
450 struct lpfc_work_evt *evtp)
452 unsigned long evt_category, evt_sub_category;
453 struct lpfc_fast_path_event *fast_evt_data;
455 uint32_t evt_data_size;
456 struct Scsi_Host *shost;
458 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
461 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
462 evt_sub_category = (unsigned long) fast_evt_data->un.
463 fabric_evt.subcategory;
464 shost = lpfc_shost_from_vport(fast_evt_data->vport);
465 if (evt_category == FC_REG_FABRIC_EVENT) {
466 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
467 evt_data = (char *) &fast_evt_data->un.read_check_error;
468 evt_data_size = sizeof(fast_evt_data->un.
470 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
471 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
472 evt_data = (char *) &fast_evt_data->un.fabric_evt;
473 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
475 lpfc_free_fast_evt(phba, fast_evt_data);
478 } else if (evt_category == FC_REG_SCSI_EVENT) {
479 switch (evt_sub_category) {
480 case LPFC_EVENT_QFULL:
481 case LPFC_EVENT_DEVBSY:
482 evt_data = (char *) &fast_evt_data->un.scsi_evt;
483 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
485 case LPFC_EVENT_CHECK_COND:
486 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
487 evt_data_size = sizeof(fast_evt_data->un.
490 case LPFC_EVENT_VARQUEDEPTH:
491 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
492 evt_data_size = sizeof(fast_evt_data->un.
496 lpfc_free_fast_evt(phba, fast_evt_data);
500 lpfc_free_fast_evt(phba, fast_evt_data);
504 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
505 fc_host_post_vendor_event(shost,
506 fc_get_event_number(),
511 lpfc_free_fast_evt(phba, fast_evt_data);
516 lpfc_work_list_done(struct lpfc_hba *phba)
518 struct lpfc_work_evt *evtp = NULL;
519 struct lpfc_nodelist *ndlp;
524 spin_lock_irq(&phba->hbalock);
525 while (!list_empty(&phba->work_list)) {
526 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
528 spin_unlock_irq(&phba->hbalock);
531 case LPFC_EVT_ELS_RETRY:
532 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
533 lpfc_els_retry_delay_handler(ndlp);
534 free_evt = 0; /* evt is part of ndlp */
535 /* decrement the node reference count held
536 * for this queued work
540 case LPFC_EVT_DEV_LOSS:
541 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
542 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
544 /* decrement the node reference count held for
547 nlp_did = ndlp->nlp_DID;
549 if (phba->sli_rev == LPFC_SLI_REV4)
550 lpfc_sli4_post_dev_loss_tmo_handler(phba,
554 case LPFC_EVT_ONLINE:
555 if (phba->link_state < LPFC_LINK_DOWN)
556 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
558 *(int *) (evtp->evt_arg1) = 0;
559 complete((struct completion *)(evtp->evt_arg2));
561 case LPFC_EVT_OFFLINE_PREP:
562 if (phba->link_state >= LPFC_LINK_DOWN)
563 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
564 *(int *)(evtp->evt_arg1) = 0;
565 complete((struct completion *)(evtp->evt_arg2));
567 case LPFC_EVT_OFFLINE:
569 lpfc_sli_brdrestart(phba);
570 *(int *)(evtp->evt_arg1) =
571 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
572 lpfc_unblock_mgmt_io(phba);
573 complete((struct completion *)(evtp->evt_arg2));
575 case LPFC_EVT_WARM_START:
577 lpfc_reset_barrier(phba);
578 lpfc_sli_brdreset(phba);
579 lpfc_hba_down_post(phba);
580 *(int *)(evtp->evt_arg1) =
581 lpfc_sli_brdready(phba, HS_MBRDY);
582 lpfc_unblock_mgmt_io(phba);
583 complete((struct completion *)(evtp->evt_arg2));
587 *(int *)(evtp->evt_arg1)
588 = (phba->pport->stopped)
589 ? 0 : lpfc_sli_brdkill(phba);
590 lpfc_unblock_mgmt_io(phba);
591 complete((struct completion *)(evtp->evt_arg2));
593 case LPFC_EVT_FASTPATH_MGMT_EVT:
594 lpfc_send_fastpath_evt(phba, evtp);
597 case LPFC_EVT_RESET_HBA:
598 if (!(phba->pport->load_flag & FC_UNLOADING))
599 lpfc_reset_hba(phba);
604 spin_lock_irq(&phba->hbalock);
606 spin_unlock_irq(&phba->hbalock);
611 lpfc_work_done(struct lpfc_hba *phba)
613 struct lpfc_sli_ring *pring;
614 uint32_t ha_copy, status, control, work_port_events;
615 struct lpfc_vport **vports;
616 struct lpfc_vport *vport;
619 spin_lock_irq(&phba->hbalock);
620 ha_copy = phba->work_ha;
622 spin_unlock_irq(&phba->hbalock);
624 /* First, try to post the next mailbox command to SLI4 device */
625 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
626 lpfc_sli4_post_async_mbox(phba);
628 if (ha_copy & HA_ERATT)
629 /* Handle the error attention event */
630 lpfc_handle_eratt(phba);
632 if (ha_copy & HA_MBATT)
633 lpfc_sli_handle_mb_event(phba);
635 if (ha_copy & HA_LATT)
636 lpfc_handle_latt(phba);
638 /* Process SLI4 events */
639 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
640 if (phba->hba_flag & HBA_RRQ_ACTIVE)
641 lpfc_handle_rrq_active(phba);
642 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
643 lpfc_sli4_els_xri_abort_event_proc(phba);
644 if (phba->hba_flag & ASYNC_EVENT)
645 lpfc_sli4_async_event_proc(phba);
646 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
647 spin_lock_irq(&phba->hbalock);
648 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
649 spin_unlock_irq(&phba->hbalock);
650 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
652 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
653 lpfc_sli4_fcf_redisc_event_proc(phba);
656 vports = lpfc_create_vport_work_array(phba);
658 for (i = 0; i <= phba->max_vports; i++) {
660 * We could have no vports in array if unloading, so if
661 * this happens then just use the pport
663 if (vports[i] == NULL && i == 0)
669 spin_lock_irq(&vport->work_port_lock);
670 work_port_events = vport->work_port_events;
671 vport->work_port_events &= ~work_port_events;
672 spin_unlock_irq(&vport->work_port_lock);
673 if (work_port_events & WORKER_DISC_TMO)
674 lpfc_disc_timeout_handler(vport);
675 if (work_port_events & WORKER_ELS_TMO)
676 lpfc_els_timeout_handler(vport);
677 if (work_port_events & WORKER_HB_TMO)
678 lpfc_hb_timeout_handler(phba);
679 if (work_port_events & WORKER_MBOX_TMO)
680 lpfc_mbox_timeout_handler(phba);
681 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
682 lpfc_unblock_fabric_iocbs(phba);
683 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
684 lpfc_ramp_down_queue_handler(phba);
685 if (work_port_events & WORKER_DELAYED_DISC_TMO)
686 lpfc_delayed_disc_timeout_handler(vport);
688 lpfc_destroy_vport_work_array(phba, vports);
690 pring = lpfc_phba_elsring(phba);
691 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
692 status >>= (4*LPFC_ELS_RING);
693 if (pring && (status & HA_RXMASK ||
694 pring->flag & LPFC_DEFERRED_RING_EVENT ||
695 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
696 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
697 pring->flag |= LPFC_DEFERRED_RING_EVENT;
698 /* Preserve legacy behavior. */
699 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
700 set_bit(LPFC_DATA_READY, &phba->data_flags);
702 /* Driver could have abort request completed in queue
703 * when link goes down. Allow for this transition.
705 if (phba->link_state >= LPFC_LINK_DOWN ||
706 phba->link_flag & LS_MDS_LOOPBACK) {
707 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
708 lpfc_sli_handle_slow_ring_event(phba, pring,
713 if (phba->sli_rev == LPFC_SLI_REV4)
714 lpfc_drain_txq(phba);
716 * Turn on Ring interrupts
718 if (phba->sli_rev <= LPFC_SLI_REV3) {
719 spin_lock_irq(&phba->hbalock);
720 control = readl(phba->HCregaddr);
721 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
722 lpfc_debugfs_slow_ring_trc(phba,
723 "WRK Enable ring: cntl:x%x hacopy:x%x",
724 control, ha_copy, 0);
726 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
727 writel(control, phba->HCregaddr);
728 readl(phba->HCregaddr); /* flush */
730 lpfc_debugfs_slow_ring_trc(phba,
731 "WRK Ring ok: cntl:x%x hacopy:x%x",
732 control, ha_copy, 0);
734 spin_unlock_irq(&phba->hbalock);
737 lpfc_work_list_done(phba);
741 lpfc_do_work(void *p)
743 struct lpfc_hba *phba = p;
746 set_user_nice(current, MIN_NICE);
747 current->flags |= PF_NOFREEZE;
748 phba->data_flags = 0;
750 while (!kthread_should_stop()) {
751 /* wait and check worker queue activities */
752 rc = wait_event_interruptible(phba->work_waitq,
753 (test_and_clear_bit(LPFC_DATA_READY,
755 || kthread_should_stop()));
756 /* Signal wakeup shall terminate the worker thread */
758 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
759 "0433 Wakeup on signal: rc=x%x\n", rc);
763 /* Attend pending lpfc data processing */
764 lpfc_work_done(phba);
766 phba->worker_thread = NULL;
767 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
768 "0432 Worker thread stopped.\n");
773 * This is only called to handle FC worker events. Since this a rare
774 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
775 * embedding it in the IOCB.
778 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
781 struct lpfc_work_evt *evtp;
785 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
786 * be queued to worker thread for processing
788 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
792 evtp->evt_arg1 = arg1;
793 evtp->evt_arg2 = arg2;
796 spin_lock_irqsave(&phba->hbalock, flags);
797 list_add_tail(&evtp->evt_listp, &phba->work_list);
798 spin_unlock_irqrestore(&phba->hbalock, flags);
800 lpfc_worker_wake_up(phba);
806 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
808 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
809 struct lpfc_hba *phba = vport->phba;
810 struct lpfc_nodelist *ndlp, *next_ndlp;
812 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
813 if (!NLP_CHK_NODE_ACT(ndlp))
815 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
817 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
818 ((vport->port_type == LPFC_NPIV_PORT) &&
819 (ndlp->nlp_DID == NameServer_DID)))
820 lpfc_unreg_rpi(vport, ndlp);
822 /* Leave Fabric nodes alone on link down */
823 if ((phba->sli_rev < LPFC_SLI_REV4) &&
824 (!remove && ndlp->nlp_type & NLP_FABRIC))
827 /* Notify transport of connectivity loss to trigger cleanup. */
828 if (phba->nvmet_support &&
829 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
830 lpfc_nvmet_invalidate_host(phba, ndlp);
832 lpfc_disc_state_machine(vport, ndlp, NULL,
835 : NLP_EVT_DEVICE_RECOVERY);
837 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
838 if (phba->sli_rev == LPFC_SLI_REV4)
839 lpfc_sli4_unreg_all_rpis(vport);
840 lpfc_mbx_unreg_vpi(vport);
841 spin_lock_irq(shost->host_lock);
842 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
843 spin_unlock_irq(shost->host_lock);
848 lpfc_port_link_failure(struct lpfc_vport *vport)
850 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
852 /* Cleanup any outstanding received buffers */
853 lpfc_cleanup_rcv_buffers(vport);
855 /* Cleanup any outstanding RSCN activity */
856 lpfc_els_flush_rscn(vport);
858 /* Cleanup any outstanding ELS commands */
859 lpfc_els_flush_cmd(vport);
861 lpfc_cleanup_rpis(vport, 0);
863 /* Turn off discovery timer if its running */
864 lpfc_can_disctmo(vport);
868 lpfc_linkdown_port(struct lpfc_vport *vport)
870 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
872 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
873 fc_host_post_event(shost, fc_get_event_number(),
874 FCH_EVT_LINKDOWN, 0);
876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
877 "Link Down: state:x%x rtry:x%x flg:x%x",
878 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
880 lpfc_port_link_failure(vport);
882 /* Stop delayed Nport discovery */
883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag &= ~FC_DISC_DELAYED;
885 spin_unlock_irq(shost->host_lock);
886 del_timer_sync(&vport->delayed_disc_tmo);
890 lpfc_linkdown(struct lpfc_hba *phba)
892 struct lpfc_vport *vport = phba->pport;
893 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
894 struct lpfc_vport **vports;
898 if (phba->link_state == LPFC_LINK_DOWN)
901 /* Block all SCSI stack I/Os */
902 lpfc_scsi_dev_block(phba);
904 phba->defer_flogi_acc_flag = false;
906 spin_lock_irq(&phba->hbalock);
907 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
908 spin_unlock_irq(&phba->hbalock);
909 if (phba->link_state > LPFC_LINK_DOWN) {
910 phba->link_state = LPFC_LINK_DOWN;
911 if (phba->sli4_hba.conf_trunk) {
912 phba->trunk_link.link0.state = 0;
913 phba->trunk_link.link1.state = 0;
914 phba->trunk_link.link2.state = 0;
915 phba->trunk_link.link3.state = 0;
916 phba->sli4_hba.link_state.logical_speed =
917 LPFC_LINK_SPEED_UNKNOWN;
919 spin_lock_irq(shost->host_lock);
920 phba->pport->fc_flag &= ~FC_LBIT;
921 spin_unlock_irq(shost->host_lock);
923 vports = lpfc_create_vport_work_array(phba);
924 if (vports != NULL) {
925 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
926 /* Issue a LINK DOWN event to all nodes */
927 lpfc_linkdown_port(vports[i]);
929 vports[i]->fc_myDID = 0;
931 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
932 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
933 if (phba->nvmet_support)
934 lpfc_nvmet_update_targetport(phba);
936 lpfc_nvme_update_localport(vports[i]);
940 lpfc_destroy_vport_work_array(phba, vports);
942 /* Clean up any SLI3 firmware default rpi's */
943 if (phba->sli_rev > LPFC_SLI_REV3)
946 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
948 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
950 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
951 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
952 == MBX_NOT_FINISHED) {
953 mempool_free(mb, phba->mbox_mem_pool);
958 /* Setup myDID for link up if we are in pt2pt mode */
959 if (phba->pport->fc_flag & FC_PT2PT) {
960 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
962 lpfc_config_link(phba, mb);
963 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
965 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
966 == MBX_NOT_FINISHED) {
967 mempool_free(mb, phba->mbox_mem_pool);
970 spin_lock_irq(shost->host_lock);
971 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
972 phba->pport->rcv_flogi_cnt = 0;
973 spin_unlock_irq(shost->host_lock);
979 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
981 struct lpfc_nodelist *ndlp;
983 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
984 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
985 if (!NLP_CHK_NODE_ACT(ndlp))
987 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
989 if (ndlp->nlp_type & NLP_FABRIC) {
990 /* On Linkup its safe to clean up the ndlp
991 * from Fabric connections.
993 if (ndlp->nlp_DID != Fabric_DID)
994 lpfc_unreg_rpi(vport, ndlp);
995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
996 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
997 /* Fail outstanding IO now since device is
1000 lpfc_unreg_rpi(vport, ndlp);
1006 lpfc_linkup_port(struct lpfc_vport *vport)
1008 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1009 struct lpfc_hba *phba = vport->phba;
1011 if ((vport->load_flag & FC_UNLOADING) != 0)
1014 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1015 "Link Up: top:x%x speed:x%x flg:x%x",
1016 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1018 /* If NPIV is not enabled, only bring the physical port up */
1019 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1020 (vport != phba->pport))
1023 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1024 fc_host_post_event(shost, fc_get_event_number(),
1027 spin_lock_irq(shost->host_lock);
1028 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1029 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1030 vport->fc_flag |= FC_NDISC_ACTIVE;
1031 vport->fc_ns_retry = 0;
1032 spin_unlock_irq(shost->host_lock);
1034 if (vport->fc_flag & FC_LBIT)
1035 lpfc_linkup_cleanup_nodes(vport);
1040 lpfc_linkup(struct lpfc_hba *phba)
1042 struct lpfc_vport **vports;
1044 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1046 phba->link_state = LPFC_LINK_UP;
1048 /* Unblock fabric iocbs if they are blocked */
1049 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1050 del_timer_sync(&phba->fabric_block_timer);
1052 vports = lpfc_create_vport_work_array(phba);
1054 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1055 lpfc_linkup_port(vports[i]);
1056 lpfc_destroy_vport_work_array(phba, vports);
1058 /* Clear the pport flogi counter in case the link down was
1059 * absorbed without an ACQE. No lock here - in worker thread
1060 * and discovery is synchronized.
1062 spin_lock_irq(shost->host_lock);
1063 phba->pport->rcv_flogi_cnt = 0;
1064 spin_unlock_irq(shost->host_lock);
1066 /* reinitialize initial FLOGI flag */
1067 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1068 phba->defer_flogi_acc_flag = false;
1074 * This routine handles processing a CLEAR_LA mailbox
1075 * command upon completion. It is setup in the LPFC_MBOXQ
1076 * as the completion routine when the command is
1077 * handed off to the SLI layer. SLI3 only.
1080 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1082 struct lpfc_vport *vport = pmb->vport;
1083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1084 struct lpfc_sli *psli = &phba->sli;
1085 MAILBOX_t *mb = &pmb->u.mb;
1088 /* Since we don't do discovery right now, turn these off here */
1089 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1090 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1092 /* Check for error */
1093 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1094 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1095 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1096 "0320 CLEAR_LA mbxStatus error x%x hba "
1098 mb->mbxStatus, vport->port_state);
1099 phba->link_state = LPFC_HBA_ERROR;
1103 if (vport->port_type == LPFC_PHYSICAL_PORT)
1104 phba->link_state = LPFC_HBA_READY;
1106 spin_lock_irq(&phba->hbalock);
1107 psli->sli_flag |= LPFC_PROCESS_LA;
1108 control = readl(phba->HCregaddr);
1109 control |= HC_LAINT_ENA;
1110 writel(control, phba->HCregaddr);
1111 readl(phba->HCregaddr); /* flush */
1112 spin_unlock_irq(&phba->hbalock);
1113 mempool_free(pmb, phba->mbox_mem_pool);
1117 /* Device Discovery completes */
1118 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1119 "0225 Device Discovery completes\n");
1120 mempool_free(pmb, phba->mbox_mem_pool);
1122 spin_lock_irq(shost->host_lock);
1123 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1124 spin_unlock_irq(shost->host_lock);
1126 lpfc_can_disctmo(vport);
1128 /* turn on Link Attention interrupts */
1130 spin_lock_irq(&phba->hbalock);
1131 psli->sli_flag |= LPFC_PROCESS_LA;
1132 control = readl(phba->HCregaddr);
1133 control |= HC_LAINT_ENA;
1134 writel(control, phba->HCregaddr);
1135 readl(phba->HCregaddr); /* flush */
1136 spin_unlock_irq(&phba->hbalock);
1143 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1145 struct lpfc_vport *vport = pmb->vport;
1147 if (pmb->u.mb.mbxStatus)
1150 mempool_free(pmb, phba->mbox_mem_pool);
1152 /* don't perform discovery for SLI4 loopback diagnostic test */
1153 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1154 !(phba->hba_flag & HBA_FCOE_MODE) &&
1155 (phba->link_flag & LS_LOOPBACK_MODE))
1158 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1159 vport->fc_flag & FC_PUBLIC_LOOP &&
1160 !(vport->fc_flag & FC_LBIT)) {
1161 /* Need to wait for FAN - use discovery timer
1162 * for timeout. port_state is identically
1163 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1165 lpfc_set_disctmo(vport);
1169 /* Start discovery by sending a FLOGI. port_state is identically
1170 * LPFC_FLOGI while waiting for FLOGI cmpl. Check if sending
1171 * the FLOGI is being deferred till after MBX_READ_SPARAM completes.
1173 if (vport->port_state != LPFC_FLOGI) {
1174 if (!(phba->hba_flag & HBA_DEFER_FLOGI))
1175 lpfc_initial_flogi(vport);
1177 if (vport->fc_flag & FC_PT2PT)
1178 lpfc_disc_start(vport);
1183 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1184 "0306 CONFIG_LINK mbxStatus error x%x "
1186 pmb->u.mb.mbxStatus, vport->port_state);
1187 mempool_free(pmb, phba->mbox_mem_pool);
1189 lpfc_linkdown(phba);
1191 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1192 "0200 CONFIG_LINK bad hba state x%x\n",
1195 lpfc_issue_clear_la(phba, vport);
1200 * lpfc_sli4_clear_fcf_rr_bmask
1201 * @phba: pointer to the struct lpfc_hba for this port.
1202 * This fucnction resets the round robin bit mask and clears the
1203 * fcf priority list. The list deletions are done while holding the
1204 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1205 * from the lpfc_fcf_pri record.
1208 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1210 struct lpfc_fcf_pri *fcf_pri;
1211 struct lpfc_fcf_pri *next_fcf_pri;
1212 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1213 spin_lock_irq(&phba->hbalock);
1214 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1215 &phba->fcf.fcf_pri_list, list) {
1216 list_del_init(&fcf_pri->list);
1217 fcf_pri->fcf_rec.flag = 0;
1219 spin_unlock_irq(&phba->hbalock);
1222 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1224 struct lpfc_vport *vport = mboxq->vport;
1226 if (mboxq->u.mb.mbxStatus) {
1227 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1228 "2017 REG_FCFI mbxStatus error x%x "
1229 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1234 /* Start FCoE discovery by sending a FLOGI. */
1235 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1236 /* Set the FCFI registered flag */
1237 spin_lock_irq(&phba->hbalock);
1238 phba->fcf.fcf_flag |= FCF_REGISTERED;
1239 spin_unlock_irq(&phba->hbalock);
1241 /* If there is a pending FCoE event, restart FCF table scan. */
1242 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1243 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1246 /* Mark successful completion of FCF table scan */
1247 spin_lock_irq(&phba->hbalock);
1248 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1249 phba->hba_flag &= ~FCF_TS_INPROG;
1250 if (vport->port_state != LPFC_FLOGI) {
1251 phba->hba_flag |= FCF_RR_INPROG;
1252 spin_unlock_irq(&phba->hbalock);
1253 lpfc_issue_init_vfi(vport);
1256 spin_unlock_irq(&phba->hbalock);
1260 spin_lock_irq(&phba->hbalock);
1261 phba->hba_flag &= ~FCF_RR_INPROG;
1262 spin_unlock_irq(&phba->hbalock);
1264 mempool_free(mboxq, phba->mbox_mem_pool);
1268 * lpfc_fab_name_match - Check if the fcf fabric name match.
1269 * @fab_name: pointer to fabric name.
1270 * @new_fcf_record: pointer to fcf record.
1272 * This routine compare the fcf record's fabric name with provided
1273 * fabric name. If the fabric name are identical this function
1274 * returns 1 else return 0.
1277 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1279 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1281 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1283 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1285 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1287 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1289 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1291 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1293 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1299 * lpfc_sw_name_match - Check if the fcf switch name match.
1300 * @sw_name: pointer to switch name.
1301 * @new_fcf_record: pointer to fcf record.
1303 * This routine compare the fcf record's switch name with provided
1304 * switch name. If the switch name are identical this function
1305 * returns 1 else return 0.
1308 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1310 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1312 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1314 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1316 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1318 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1320 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1322 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1324 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1330 * lpfc_mac_addr_match - Check if the fcf mac address match.
1331 * @mac_addr: pointer to mac address.
1332 * @new_fcf_record: pointer to fcf record.
1334 * This routine compare the fcf record's mac address with HBA's
1335 * FCF mac address. If the mac addresses are identical this function
1336 * returns 1 else return 0.
1339 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1341 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1343 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1345 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1347 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1349 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1351 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1357 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1359 return (curr_vlan_id == new_vlan_id);
1363 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1364 * @phba: pointer to lpfc hba data structure.
1365 * @fcf_index: Index for the lpfc_fcf_record.
1366 * @new_fcf_record: pointer to hba fcf record.
1368 * This routine updates the driver FCF priority record from the new HBA FCF
1369 * record. The hbalock is asserted held in the code path calling this
1373 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1374 struct fcf_record *new_fcf_record
1377 struct lpfc_fcf_pri *fcf_pri;
1379 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1380 fcf_pri->fcf_rec.fcf_index = fcf_index;
1381 /* FCF record priority */
1382 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1387 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1388 * @fcf_rec: pointer to driver fcf record.
1389 * @new_fcf_record: pointer to fcf record.
1391 * This routine copies the FCF information from the FCF
1392 * record to lpfc_hba data structure.
1395 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1396 struct fcf_record *new_fcf_record)
1399 fcf_rec->fabric_name[0] =
1400 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1401 fcf_rec->fabric_name[1] =
1402 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1403 fcf_rec->fabric_name[2] =
1404 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1405 fcf_rec->fabric_name[3] =
1406 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1407 fcf_rec->fabric_name[4] =
1408 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1409 fcf_rec->fabric_name[5] =
1410 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1411 fcf_rec->fabric_name[6] =
1412 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1413 fcf_rec->fabric_name[7] =
1414 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1416 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1417 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1418 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1419 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1420 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1421 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1422 /* FCF record index */
1423 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1424 /* FCF record priority */
1425 fcf_rec->priority = new_fcf_record->fip_priority;
1427 fcf_rec->switch_name[0] =
1428 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1429 fcf_rec->switch_name[1] =
1430 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1431 fcf_rec->switch_name[2] =
1432 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1433 fcf_rec->switch_name[3] =
1434 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1435 fcf_rec->switch_name[4] =
1436 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1437 fcf_rec->switch_name[5] =
1438 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1439 fcf_rec->switch_name[6] =
1440 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1441 fcf_rec->switch_name[7] =
1442 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1446 * lpfc_update_fcf_record - Update driver fcf record
1447 * @phba: pointer to lpfc hba data structure.
1448 * @fcf_rec: pointer to driver fcf record.
1449 * @new_fcf_record: pointer to hba fcf record.
1450 * @addr_mode: address mode to be set to the driver fcf record.
1451 * @vlan_id: vlan tag to be set to the driver fcf record.
1452 * @flag: flag bits to be set to the driver fcf record.
1454 * This routine updates the driver FCF record from the new HBA FCF record
1455 * together with the address mode, vlan_id, and other informations. This
1456 * routine is called with the hbalock held.
1459 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1460 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1461 uint16_t vlan_id, uint32_t flag)
1463 lockdep_assert_held(&phba->hbalock);
1465 /* Copy the fields from the HBA's FCF record */
1466 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1467 /* Update other fields of driver FCF record */
1468 fcf_rec->addr_mode = addr_mode;
1469 fcf_rec->vlan_id = vlan_id;
1470 fcf_rec->flag |= (flag | RECORD_VALID);
1471 __lpfc_update_fcf_record_pri(phba,
1472 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1477 * lpfc_register_fcf - Register the FCF with hba.
1478 * @phba: pointer to lpfc hba data structure.
1480 * This routine issues a register fcfi mailbox command to register
1484 lpfc_register_fcf(struct lpfc_hba *phba)
1486 LPFC_MBOXQ_t *fcf_mbxq;
1489 spin_lock_irq(&phba->hbalock);
1490 /* If the FCF is not available do nothing. */
1491 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1492 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1493 spin_unlock_irq(&phba->hbalock);
1497 /* The FCF is already registered, start discovery */
1498 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1499 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1500 phba->hba_flag &= ~FCF_TS_INPROG;
1501 if (phba->pport->port_state != LPFC_FLOGI &&
1502 phba->pport->fc_flag & FC_FABRIC) {
1503 phba->hba_flag |= FCF_RR_INPROG;
1504 spin_unlock_irq(&phba->hbalock);
1505 lpfc_initial_flogi(phba->pport);
1508 spin_unlock_irq(&phba->hbalock);
1511 spin_unlock_irq(&phba->hbalock);
1513 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1515 spin_lock_irq(&phba->hbalock);
1516 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1517 spin_unlock_irq(&phba->hbalock);
1521 lpfc_reg_fcfi(phba, fcf_mbxq);
1522 fcf_mbxq->vport = phba->pport;
1523 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1524 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1525 if (rc == MBX_NOT_FINISHED) {
1526 spin_lock_irq(&phba->hbalock);
1527 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1528 spin_unlock_irq(&phba->hbalock);
1529 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1536 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1537 * @phba: pointer to lpfc hba data structure.
1538 * @new_fcf_record: pointer to fcf record.
1539 * @boot_flag: Indicates if this record used by boot bios.
1540 * @addr_mode: The address mode to be used by this FCF
1541 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1543 * This routine compare the fcf record with connect list obtained from the
1544 * config region to decide if this FCF can be used for SAN discovery. It returns
1545 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1546 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1547 * is used by boot bios and addr_mode will indicate the addressing mode to be
1548 * used for this FCF when the function returns.
1549 * If the FCF record need to be used with a particular vlan id, the vlan is
1550 * set in the vlan_id on return of the function. If not VLAN tagging need to
1551 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1554 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1555 struct fcf_record *new_fcf_record,
1556 uint32_t *boot_flag, uint32_t *addr_mode,
1559 struct lpfc_fcf_conn_entry *conn_entry;
1560 int i, j, fcf_vlan_id = 0;
1562 /* Find the lowest VLAN id in the FCF record */
1563 for (i = 0; i < 512; i++) {
1564 if (new_fcf_record->vlan_bitmap[i]) {
1565 fcf_vlan_id = i * 8;
1567 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1575 /* FCF not valid/available or solicitation in progress */
1576 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1577 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1578 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1581 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1583 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1585 if (phba->valid_vlan)
1586 *vlan_id = phba->vlan_id;
1588 *vlan_id = LPFC_FCOE_NULL_VID;
1593 * If there are no FCF connection table entry, driver connect to all
1596 if (list_empty(&phba->fcf_conn_rec_list)) {
1598 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1602 * When there are no FCF connect entries, use driver's default
1603 * addressing mode - FPMA.
1605 if (*addr_mode & LPFC_FCF_FPMA)
1606 *addr_mode = LPFC_FCF_FPMA;
1608 /* If FCF record report a vlan id use that vlan id */
1610 *vlan_id = fcf_vlan_id;
1612 *vlan_id = LPFC_FCOE_NULL_VID;
1616 list_for_each_entry(conn_entry,
1617 &phba->fcf_conn_rec_list, list) {
1618 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1621 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1622 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1625 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1626 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1629 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1631 * If the vlan bit map does not have the bit set for the
1632 * vlan id to be used, then it is not a match.
1634 if (!(new_fcf_record->vlan_bitmap
1635 [conn_entry->conn_rec.vlan_tag / 8] &
1636 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1641 * If connection record does not support any addressing mode,
1642 * skip the FCF record.
1644 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1645 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1649 * Check if the connection record specifies a required
1652 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1653 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1656 * If SPMA required but FCF not support this continue.
1658 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1659 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1660 new_fcf_record) & LPFC_FCF_SPMA))
1664 * If FPMA required but FCF not support this continue.
1666 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1667 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1668 new_fcf_record) & LPFC_FCF_FPMA))
1673 * This fcf record matches filtering criteria.
1675 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1681 * If user did not specify any addressing mode, or if the
1682 * preferred addressing mode specified by user is not supported
1683 * by FCF, allow fabric to pick the addressing mode.
1685 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1688 * If the user specified a required address mode, assign that
1691 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1692 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1693 *addr_mode = (conn_entry->conn_rec.flags &
1695 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1697 * If the user specified a preferred address mode, use the
1698 * addr mode only if FCF support the addr_mode.
1700 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1701 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1702 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1703 (*addr_mode & LPFC_FCF_SPMA))
1704 *addr_mode = LPFC_FCF_SPMA;
1705 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1706 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1707 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1708 (*addr_mode & LPFC_FCF_FPMA))
1709 *addr_mode = LPFC_FCF_FPMA;
1711 /* If matching connect list has a vlan id, use it */
1712 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1713 *vlan_id = conn_entry->conn_rec.vlan_tag;
1715 * If no vlan id is specified in connect list, use the vlan id
1718 else if (fcf_vlan_id)
1719 *vlan_id = fcf_vlan_id;
1721 *vlan_id = LPFC_FCOE_NULL_VID;
1730 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1731 * @phba: pointer to lpfc hba data structure.
1732 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1734 * This function check if there is any fcoe event pending while driver
1735 * scan FCF entries. If there is any pending event, it will restart the
1736 * FCF saning and return 1 else return 0.
1739 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1742 * If the Link is up and no FCoE events while in the
1743 * FCF discovery, no need to restart FCF discovery.
1745 if ((phba->link_state >= LPFC_LINK_UP) &&
1746 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1749 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1750 "2768 Pending link or FCF event during current "
1751 "handling of the previous event: link_state:x%x, "
1752 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1753 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1754 phba->fcoe_eventtag);
1756 spin_lock_irq(&phba->hbalock);
1757 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1758 spin_unlock_irq(&phba->hbalock);
1760 if (phba->link_state >= LPFC_LINK_UP) {
1761 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1762 "2780 Restart FCF table scan due to "
1763 "pending FCF event:evt_tag_at_scan:x%x, "
1764 "evt_tag_current:x%x\n",
1765 phba->fcoe_eventtag_at_fcf_scan,
1766 phba->fcoe_eventtag);
1767 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1770 * Do not continue FCF discovery and clear FCF_TS_INPROG
1773 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1774 "2833 Stop FCF discovery process due to link "
1775 "state change (x%x)\n", phba->link_state);
1776 spin_lock_irq(&phba->hbalock);
1777 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1778 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1779 spin_unlock_irq(&phba->hbalock);
1782 /* Unregister the currently registered FCF if required */
1784 spin_lock_irq(&phba->hbalock);
1785 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1786 spin_unlock_irq(&phba->hbalock);
1787 lpfc_sli4_unregister_fcf(phba);
1793 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1794 * @phba: pointer to lpfc hba data structure.
1795 * @fcf_cnt: number of eligible fcf record seen so far.
1797 * This function makes an running random selection decision on FCF record to
1798 * use through a sequence of @fcf_cnt eligible FCF records with equal
1799 * probability. To perform integer manunipulation of random numbers with
1800 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1801 * from prandom_u32() are taken as the random random number generated.
1803 * Returns true when outcome is for the newly read FCF record should be
1804 * chosen; otherwise, return false when outcome is for keeping the previously
1805 * chosen FCF record.
1808 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1812 /* Get 16-bit uniform random number */
1813 rand_num = 0xFFFF & prandom_u32();
1815 /* Decision with probability 1/fcf_cnt */
1816 if ((fcf_cnt * rand_num) < 0xFFFF)
1823 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1824 * @phba: pointer to lpfc hba data structure.
1825 * @mboxq: pointer to mailbox object.
1826 * @next_fcf_index: pointer to holder of next fcf index.
1828 * This routine parses the non-embedded fcf mailbox command by performing the
1829 * necessarily error checking, non-embedded read FCF record mailbox command
1830 * SGE parsing, and endianness swapping.
1832 * Returns the pointer to the new FCF record in the non-embedded mailbox
1833 * command DMA memory if successfully, other NULL.
1835 static struct fcf_record *
1836 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1837 uint16_t *next_fcf_index)
1840 struct lpfc_mbx_sge sge;
1841 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1842 uint32_t shdr_status, shdr_add_status, if_type;
1843 union lpfc_sli4_cfg_shdr *shdr;
1844 struct fcf_record *new_fcf_record;
1846 /* Get the first SGE entry from the non-embedded DMA memory. This
1847 * routine only uses a single SGE.
1849 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1850 if (unlikely(!mboxq->sge_array)) {
1851 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1852 "2524 Failed to get the non-embedded SGE "
1853 "virtual address\n");
1856 virt_addr = mboxq->sge_array->addr[0];
1858 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1859 lpfc_sli_pcimem_bcopy(shdr, shdr,
1860 sizeof(union lpfc_sli4_cfg_shdr));
1861 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1862 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1863 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1864 if (shdr_status || shdr_add_status) {
1865 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1866 if_type == LPFC_SLI_INTF_IF_TYPE_2)
1867 lpfc_printf_log(phba, KERN_ERR,
1869 "2726 READ_FCF_RECORD Indicates empty "
1872 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1873 "2521 READ_FCF_RECORD mailbox failed "
1874 "with status x%x add_status x%x, "
1875 "mbx\n", shdr_status, shdr_add_status);
1879 /* Interpreting the returned information of the FCF record */
1880 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1881 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1882 sizeof(struct lpfc_mbx_read_fcf_tbl));
1883 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1884 new_fcf_record = (struct fcf_record *)(virt_addr +
1885 sizeof(struct lpfc_mbx_read_fcf_tbl));
1886 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1887 offsetof(struct fcf_record, vlan_bitmap));
1888 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1889 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1891 return new_fcf_record;
1895 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1896 * @phba: pointer to lpfc hba data structure.
1897 * @fcf_record: pointer to the fcf record.
1898 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1899 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1901 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1905 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1906 struct fcf_record *fcf_record,
1908 uint16_t next_fcf_index)
1910 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1911 "2764 READ_FCF_RECORD:\n"
1912 "\tFCF_Index : x%x\n"
1913 "\tFCF_Avail : x%x\n"
1914 "\tFCF_Valid : x%x\n"
1916 "\tFIP_Priority : x%x\n"
1917 "\tMAC_Provider : x%x\n"
1918 "\tLowest VLANID : x%x\n"
1919 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1920 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1921 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1922 "\tNext_FCF_Index: x%x\n",
1923 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1924 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1925 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1926 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1927 fcf_record->fip_priority,
1928 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1930 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1931 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1932 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1933 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1934 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1935 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1936 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1937 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1938 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1939 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1940 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1941 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1942 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1943 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1944 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1945 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1946 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1947 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1948 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1949 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1950 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1951 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1956 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1957 * @phba: pointer to lpfc hba data structure.
1958 * @fcf_rec: pointer to an existing FCF record.
1959 * @new_fcf_record: pointer to a new FCF record.
1960 * @new_vlan_id: vlan id from the new FCF record.
1962 * This function performs matching test of a new FCF record against an existing
1963 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1964 * will not be used as part of the FCF record matching criteria.
1966 * Returns true if all the fields matching, otherwise returns false.
1969 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1970 struct lpfc_fcf_rec *fcf_rec,
1971 struct fcf_record *new_fcf_record,
1972 uint16_t new_vlan_id)
1974 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1975 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1977 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1979 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1981 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1983 if (fcf_rec->priority != new_fcf_record->fip_priority)
1989 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1990 * @vport: Pointer to vport object.
1991 * @fcf_index: index to next fcf.
1993 * This function processing the roundrobin fcf failover to next fcf index.
1994 * When this function is invoked, there will be a current fcf registered
1996 * Return: 0 for continue retrying flogi on currently registered fcf;
1997 * 1 for stop flogi on currently registered fcf;
1999 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2001 struct lpfc_hba *phba = vport->phba;
2004 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2005 spin_lock_irq(&phba->hbalock);
2006 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2007 spin_unlock_irq(&phba->hbalock);
2008 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2009 "2872 Devloss tmo with no eligible "
2010 "FCF, unregister in-use FCF (x%x) "
2011 "and rescan FCF table\n",
2012 phba->fcf.current_rec.fcf_indx);
2013 lpfc_unregister_fcf_rescan(phba);
2014 goto stop_flogi_current_fcf;
2016 /* Mark the end to FLOGI roundrobin failover */
2017 phba->hba_flag &= ~FCF_RR_INPROG;
2018 /* Allow action to new fcf asynchronous event */
2019 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2020 spin_unlock_irq(&phba->hbalock);
2021 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2022 "2865 No FCF available, stop roundrobin FCF "
2023 "failover and change port state:x%x/x%x\n",
2024 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2025 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2027 if (!phba->fcf.fcf_redisc_attempted) {
2028 lpfc_unregister_fcf(phba);
2030 rc = lpfc_sli4_redisc_fcf_table(phba);
2032 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2033 "3195 Rediscover FCF table\n");
2034 phba->fcf.fcf_redisc_attempted = 1;
2035 lpfc_sli4_clear_fcf_rr_bmask(phba);
2037 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2038 "3196 Rediscover FCF table "
2039 "failed. Status:x%x\n", rc);
2042 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2043 "3197 Already rediscover FCF table "
2044 "attempted. No more retry\n");
2046 goto stop_flogi_current_fcf;
2048 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2049 "2794 Try FLOGI roundrobin FCF failover to "
2050 "(x%x)\n", fcf_index);
2051 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2053 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2054 "2761 FLOGI roundrobin FCF failover "
2055 "failed (rc:x%x) to read FCF (x%x)\n",
2056 rc, phba->fcf.current_rec.fcf_indx);
2058 goto stop_flogi_current_fcf;
2062 stop_flogi_current_fcf:
2063 lpfc_can_disctmo(vport);
2068 * lpfc_sli4_fcf_pri_list_del
2069 * @phba: pointer to lpfc hba data structure.
2070 * @fcf_index: the index of the fcf record to delete
2071 * This routine checks the on list flag of the fcf_index to be deleted.
2072 * If it is one the list then it is removed from the list, and the flag
2073 * is cleared. This routine grab the hbalock before removing the fcf
2074 * record from the list.
2076 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2079 struct lpfc_fcf_pri *new_fcf_pri;
2081 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2082 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2083 "3058 deleting idx x%x pri x%x flg x%x\n",
2084 fcf_index, new_fcf_pri->fcf_rec.priority,
2085 new_fcf_pri->fcf_rec.flag);
2086 spin_lock_irq(&phba->hbalock);
2087 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2088 if (phba->fcf.current_rec.priority ==
2089 new_fcf_pri->fcf_rec.priority)
2090 phba->fcf.eligible_fcf_cnt--;
2091 list_del_init(&new_fcf_pri->list);
2092 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2094 spin_unlock_irq(&phba->hbalock);
2098 * lpfc_sli4_set_fcf_flogi_fail
2099 * @phba: pointer to lpfc hba data structure.
2100 * @fcf_index: the index of the fcf record to update
2101 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2102 * flag so the the round robin slection for the particular priority level
2103 * will try a different fcf record that does not have this bit set.
2104 * If the fcf record is re-read for any reason this flag is cleared brfore
2105 * adding it to the priority list.
2108 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2110 struct lpfc_fcf_pri *new_fcf_pri;
2111 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2112 spin_lock_irq(&phba->hbalock);
2113 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2114 spin_unlock_irq(&phba->hbalock);
2118 * lpfc_sli4_fcf_pri_list_add
2119 * @phba: pointer to lpfc hba data structure.
2120 * @fcf_index: the index of the fcf record to add
2121 * @new_fcf_record: pointer to a new FCF record.
2122 * This routine checks the priority of the fcf_index to be added.
2123 * If it is a lower priority than the current head of the fcf_pri list
2124 * then it is added to the list in the right order.
2125 * If it is the same priority as the current head of the list then it
2126 * is added to the head of the list and its bit in the rr_bmask is set.
2127 * If the fcf_index to be added is of a higher priority than the current
2128 * head of the list then the rr_bmask is cleared, its bit is set in the
2129 * rr_bmask and it is added to the head of the list.
2131 * 0=success 1=failure
2133 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2135 struct fcf_record *new_fcf_record)
2137 uint16_t current_fcf_pri;
2138 uint16_t last_index;
2139 struct lpfc_fcf_pri *fcf_pri;
2140 struct lpfc_fcf_pri *next_fcf_pri;
2141 struct lpfc_fcf_pri *new_fcf_pri;
2144 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2145 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2146 "3059 adding idx x%x pri x%x flg x%x\n",
2147 fcf_index, new_fcf_record->fip_priority,
2148 new_fcf_pri->fcf_rec.flag);
2149 spin_lock_irq(&phba->hbalock);
2150 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2151 list_del_init(&new_fcf_pri->list);
2152 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2153 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2154 if (list_empty(&phba->fcf.fcf_pri_list)) {
2155 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2156 ret = lpfc_sli4_fcf_rr_index_set(phba,
2157 new_fcf_pri->fcf_rec.fcf_index);
2161 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2162 LPFC_SLI4_FCF_TBL_INDX_MAX);
2163 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2164 ret = 0; /* Empty rr list */
2167 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2168 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2169 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2170 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2171 memset(phba->fcf.fcf_rr_bmask, 0,
2172 sizeof(*phba->fcf.fcf_rr_bmask));
2173 /* fcfs_at_this_priority_level = 1; */
2174 phba->fcf.eligible_fcf_cnt = 1;
2176 /* fcfs_at_this_priority_level++; */
2177 phba->fcf.eligible_fcf_cnt++;
2178 ret = lpfc_sli4_fcf_rr_index_set(phba,
2179 new_fcf_pri->fcf_rec.fcf_index);
2183 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2184 &phba->fcf.fcf_pri_list, list) {
2185 if (new_fcf_pri->fcf_rec.priority <=
2186 fcf_pri->fcf_rec.priority) {
2187 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2188 list_add(&new_fcf_pri->list,
2189 &phba->fcf.fcf_pri_list);
2191 list_add(&new_fcf_pri->list,
2192 &((struct lpfc_fcf_pri *)
2193 fcf_pri->list.prev)->list);
2196 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2197 || new_fcf_pri->fcf_rec.priority <
2198 next_fcf_pri->fcf_rec.priority) {
2199 list_add(&new_fcf_pri->list, &fcf_pri->list);
2203 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2209 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2210 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2211 spin_unlock_irq(&phba->hbalock);
2216 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2217 * @phba: pointer to lpfc hba data structure.
2218 * @mboxq: pointer to mailbox object.
2220 * This function iterates through all the fcf records available in
2221 * HBA and chooses the optimal FCF record for discovery. After finding
2222 * the FCF for discovery it registers the FCF record and kicks start
2224 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2225 * use an FCF record which matches fabric name and mac address of the
2226 * currently used FCF record.
2227 * If the driver supports only one FCF, it will try to use the FCF record
2228 * used by BOOT_BIOS.
2231 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2233 struct fcf_record *new_fcf_record;
2234 uint32_t boot_flag, addr_mode;
2235 uint16_t fcf_index, next_fcf_index;
2236 struct lpfc_fcf_rec *fcf_rec = NULL;
2237 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2238 bool select_new_fcf;
2241 /* If there is pending FCoE event restart FCF table scan */
2242 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2243 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2247 /* Parse the FCF record from the non-embedded mailbox command */
2248 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2250 if (!new_fcf_record) {
2251 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2252 "2765 Mailbox command READ_FCF_RECORD "
2253 "failed to retrieve a FCF record.\n");
2254 /* Let next new FCF event trigger fast failover */
2255 spin_lock_irq(&phba->hbalock);
2256 phba->hba_flag &= ~FCF_TS_INPROG;
2257 spin_unlock_irq(&phba->hbalock);
2258 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2262 /* Check the FCF record against the connection list */
2263 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2264 &addr_mode, &vlan_id);
2266 /* Log the FCF record information if turned on */
2267 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2271 * If the fcf record does not match with connect list entries
2272 * read the next entry; otherwise, this is an eligible FCF
2273 * record for roundrobin FCF failover.
2276 lpfc_sli4_fcf_pri_list_del(phba,
2277 bf_get(lpfc_fcf_record_fcf_index,
2279 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2280 "2781 FCF (x%x) failed connection "
2281 "list check: (x%x/x%x/%x)\n",
2282 bf_get(lpfc_fcf_record_fcf_index,
2284 bf_get(lpfc_fcf_record_fcf_avail,
2286 bf_get(lpfc_fcf_record_fcf_valid,
2288 bf_get(lpfc_fcf_record_fcf_sol,
2290 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2291 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2292 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2293 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2294 phba->fcf.current_rec.fcf_indx) {
2295 lpfc_printf_log(phba, KERN_ERR,
2297 "2862 FCF (x%x) matches property "
2298 "of in-use FCF (x%x)\n",
2299 bf_get(lpfc_fcf_record_fcf_index,
2301 phba->fcf.current_rec.fcf_indx);
2305 * In case the current in-use FCF record becomes
2306 * invalid/unavailable during FCF discovery that
2307 * was not triggered by fast FCF failover process,
2308 * treat it as fast FCF failover.
2310 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2311 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2312 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2313 "2835 Invalid in-use FCF "
2314 "(x%x), enter FCF failover "
2316 phba->fcf.current_rec.fcf_indx);
2317 spin_lock_irq(&phba->hbalock);
2318 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2319 spin_unlock_irq(&phba->hbalock);
2320 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2321 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2322 LPFC_FCOE_FCF_GET_FIRST);
2328 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2329 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2336 * If this is not the first FCF discovery of the HBA, use last
2337 * FCF record for the discovery. The condition that a rescan
2338 * matches the in-use FCF record: fabric name, switch name, mac
2339 * address, and vlan_id.
2341 spin_lock_irq(&phba->hbalock);
2342 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2343 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2344 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2345 new_fcf_record, vlan_id)) {
2346 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2347 phba->fcf.current_rec.fcf_indx) {
2348 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2349 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2350 /* Stop FCF redisc wait timer */
2351 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2353 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2354 /* Fast failover, mark completed */
2355 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2356 spin_unlock_irq(&phba->hbalock);
2357 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2358 "2836 New FCF matches in-use "
2359 "FCF (x%x), port_state:x%x, "
2361 phba->fcf.current_rec.fcf_indx,
2362 phba->pport->port_state,
2363 phba->pport->fc_flag);
2366 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2367 "2863 New FCF (x%x) matches "
2368 "property of in-use FCF (x%x)\n",
2369 bf_get(lpfc_fcf_record_fcf_index,
2371 phba->fcf.current_rec.fcf_indx);
2374 * Read next FCF record from HBA searching for the matching
2375 * with in-use record only if not during the fast failover
2376 * period. In case of fast failover period, it shall try to
2377 * determine whether the FCF record just read should be the
2380 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2381 spin_unlock_irq(&phba->hbalock);
2386 * Update on failover FCF record only if it's in FCF fast-failover
2387 * period; otherwise, update on current FCF record.
2389 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2390 fcf_rec = &phba->fcf.failover_rec;
2392 fcf_rec = &phba->fcf.current_rec;
2394 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2396 * If the driver FCF record does not have boot flag
2397 * set and new hba fcf record has boot flag set, use
2398 * the new hba fcf record.
2400 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2401 /* Choose this FCF record */
2402 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2403 "2837 Update current FCF record "
2404 "(x%x) with new FCF record (x%x)\n",
2406 bf_get(lpfc_fcf_record_fcf_index,
2408 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2409 addr_mode, vlan_id, BOOT_ENABLE);
2410 spin_unlock_irq(&phba->hbalock);
2414 * If the driver FCF record has boot flag set and the
2415 * new hba FCF record does not have boot flag, read
2416 * the next FCF record.
2418 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2419 spin_unlock_irq(&phba->hbalock);
2423 * If the new hba FCF record has lower priority value
2424 * than the driver FCF record, use the new record.
2426 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2427 /* Choose the new FCF record with lower priority */
2428 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2429 "2838 Update current FCF record "
2430 "(x%x) with new FCF record (x%x)\n",
2432 bf_get(lpfc_fcf_record_fcf_index,
2434 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2435 addr_mode, vlan_id, 0);
2436 /* Reset running random FCF selection count */
2437 phba->fcf.eligible_fcf_cnt = 1;
2438 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2439 /* Update running random FCF selection count */
2440 phba->fcf.eligible_fcf_cnt++;
2441 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2442 phba->fcf.eligible_fcf_cnt);
2443 if (select_new_fcf) {
2444 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2445 "2839 Update current FCF record "
2446 "(x%x) with new FCF record (x%x)\n",
2448 bf_get(lpfc_fcf_record_fcf_index,
2450 /* Choose the new FCF by random selection */
2451 __lpfc_update_fcf_record(phba, fcf_rec,
2453 addr_mode, vlan_id, 0);
2456 spin_unlock_irq(&phba->hbalock);
2460 * This is the first suitable FCF record, choose this record for
2461 * initial best-fit FCF.
2464 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2465 "2840 Update initial FCF candidate "
2467 bf_get(lpfc_fcf_record_fcf_index,
2469 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2470 addr_mode, vlan_id, (boot_flag ?
2472 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2473 /* Setup initial running random FCF selection count */
2474 phba->fcf.eligible_fcf_cnt = 1;
2476 spin_unlock_irq(&phba->hbalock);
2480 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2481 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2482 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2484 * Case of FCF fast failover scan
2488 * It has not found any suitable FCF record, cancel
2489 * FCF scan inprogress, and do nothing
2491 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2492 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2493 "2782 No suitable FCF found: "
2495 phba->fcoe_eventtag_at_fcf_scan,
2496 bf_get(lpfc_fcf_record_fcf_index,
2498 spin_lock_irq(&phba->hbalock);
2499 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2500 phba->hba_flag &= ~FCF_TS_INPROG;
2501 spin_unlock_irq(&phba->hbalock);
2502 /* Unregister in-use FCF and rescan */
2503 lpfc_printf_log(phba, KERN_INFO,
2505 "2864 On devloss tmo "
2506 "unreg in-use FCF and "
2507 "rescan FCF table\n");
2508 lpfc_unregister_fcf_rescan(phba);
2512 * Let next new FCF event trigger fast failover
2514 phba->hba_flag &= ~FCF_TS_INPROG;
2515 spin_unlock_irq(&phba->hbalock);
2519 * It has found a suitable FCF record that is not
2520 * the same as in-use FCF record, unregister the
2521 * in-use FCF record, replace the in-use FCF record
2522 * with the new FCF record, mark FCF fast failover
2523 * completed, and then start register the new FCF
2527 /* Unregister the current in-use FCF record */
2528 lpfc_unregister_fcf(phba);
2530 /* Replace in-use record with the new record */
2531 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2532 "2842 Replace in-use FCF (x%x) "
2533 "with failover FCF (x%x)\n",
2534 phba->fcf.current_rec.fcf_indx,
2535 phba->fcf.failover_rec.fcf_indx);
2536 memcpy(&phba->fcf.current_rec,
2537 &phba->fcf.failover_rec,
2538 sizeof(struct lpfc_fcf_rec));
2540 * Mark the fast FCF failover rediscovery completed
2541 * and the start of the first round of the roundrobin
2544 spin_lock_irq(&phba->hbalock);
2545 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2546 spin_unlock_irq(&phba->hbalock);
2547 /* Register to the new FCF record */
2548 lpfc_register_fcf(phba);
2551 * In case of transaction period to fast FCF failover,
2552 * do nothing when search to the end of the FCF table.
2554 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2555 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2558 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2559 phba->fcf.fcf_flag & FCF_IN_USE) {
2561 * In case the current in-use FCF record no
2562 * longer existed during FCF discovery that
2563 * was not triggered by fast FCF failover
2564 * process, treat it as fast FCF failover.
2566 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2567 "2841 In-use FCF record (x%x) "
2568 "not reported, entering fast "
2569 "FCF failover mode scanning.\n",
2570 phba->fcf.current_rec.fcf_indx);
2571 spin_lock_irq(&phba->hbalock);
2572 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2573 spin_unlock_irq(&phba->hbalock);
2574 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2575 LPFC_FCOE_FCF_GET_FIRST);
2578 /* Register to the new FCF record */
2579 lpfc_register_fcf(phba);
2582 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2586 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2587 lpfc_register_fcf(phba);
2593 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2594 * @phba: pointer to lpfc hba data structure.
2595 * @mboxq: pointer to mailbox object.
2597 * This is the callback function for FLOGI failure roundrobin FCF failover
2598 * read FCF record mailbox command from the eligible FCF record bmask for
2599 * performing the failover. If the FCF read back is not valid/available, it
2600 * fails through to retrying FLOGI to the currently registered FCF again.
2601 * Otherwise, if the FCF read back is valid and available, it will set the
2602 * newly read FCF record to the failover FCF record, unregister currently
2603 * registered FCF record, copy the failover FCF record to the current
2604 * FCF record, and then register the current FCF record before proceeding
2605 * to trying FLOGI on the new failover FCF.
2608 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2610 struct fcf_record *new_fcf_record;
2611 uint32_t boot_flag, addr_mode;
2612 uint16_t next_fcf_index, fcf_index;
2613 uint16_t current_fcf_index;
2617 /* If link state is not up, stop the roundrobin failover process */
2618 if (phba->link_state < LPFC_LINK_UP) {
2619 spin_lock_irq(&phba->hbalock);
2620 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2621 phba->hba_flag &= ~FCF_RR_INPROG;
2622 spin_unlock_irq(&phba->hbalock);
2626 /* Parse the FCF record from the non-embedded mailbox command */
2627 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2629 if (!new_fcf_record) {
2630 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2631 "2766 Mailbox command READ_FCF_RECORD "
2632 "failed to retrieve a FCF record. "
2633 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2634 phba->fcf.fcf_flag);
2635 lpfc_unregister_fcf_rescan(phba);
2639 /* Get the needed parameters from FCF record */
2640 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2641 &addr_mode, &vlan_id);
2643 /* Log the FCF record information if turned on */
2644 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2647 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2649 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2650 "2848 Remove ineligible FCF (x%x) from "
2651 "from roundrobin bmask\n", fcf_index);
2652 /* Clear roundrobin bmask bit for ineligible FCF */
2653 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2654 /* Perform next round of roundrobin FCF failover */
2655 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2656 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2662 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2663 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2664 "2760 Perform FLOGI roundrobin FCF failover: "
2665 "FCF (x%x) back to FCF (x%x)\n",
2666 phba->fcf.current_rec.fcf_indx, fcf_index);
2667 /* Wait 500 ms before retrying FLOGI to current FCF */
2669 lpfc_issue_init_vfi(phba->pport);
2673 /* Upload new FCF record to the failover FCF record */
2674 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2675 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2676 phba->fcf.failover_rec.fcf_indx, fcf_index);
2677 spin_lock_irq(&phba->hbalock);
2678 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2679 new_fcf_record, addr_mode, vlan_id,
2680 (boot_flag ? BOOT_ENABLE : 0));
2681 spin_unlock_irq(&phba->hbalock);
2683 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2685 /* Unregister the current in-use FCF record */
2686 lpfc_unregister_fcf(phba);
2688 /* Replace in-use record with the new record */
2689 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2690 sizeof(struct lpfc_fcf_rec));
2692 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2693 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2694 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2697 lpfc_register_fcf(phba);
2699 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2703 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2704 * @phba: pointer to lpfc hba data structure.
2705 * @mboxq: pointer to mailbox object.
2707 * This is the callback function of read FCF record mailbox command for
2708 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2709 * failover when a new FCF event happened. If the FCF read back is
2710 * valid/available and it passes the connection list check, it updates
2711 * the bmask for the eligible FCF record for roundrobin failover.
2714 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2716 struct fcf_record *new_fcf_record;
2717 uint32_t boot_flag, addr_mode;
2718 uint16_t fcf_index, next_fcf_index;
2722 /* If link state is not up, no need to proceed */
2723 if (phba->link_state < LPFC_LINK_UP)
2726 /* If FCF discovery period is over, no need to proceed */
2727 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2730 /* Parse the FCF record from the non-embedded mailbox command */
2731 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2733 if (!new_fcf_record) {
2734 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2735 "2767 Mailbox command READ_FCF_RECORD "
2736 "failed to retrieve a FCF record.\n");
2740 /* Check the connection list for eligibility */
2741 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2742 &addr_mode, &vlan_id);
2744 /* Log the FCF record information if turned on */
2745 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2751 /* Update the eligible FCF record index bmask */
2752 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2754 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2757 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2761 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2762 * @phba: pointer to lpfc hba data structure.
2763 * @mboxq: pointer to mailbox data structure.
2765 * This function handles completion of init vfi mailbox command.
2768 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2770 struct lpfc_vport *vport = mboxq->vport;
2773 * VFI not supported on interface type 0, just do the flogi
2774 * Also continue if the VFI is in use - just use the same one.
2776 if (mboxq->u.mb.mbxStatus &&
2777 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2778 LPFC_SLI_INTF_IF_TYPE_0) &&
2779 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2780 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2781 "2891 Init VFI mailbox failed 0x%x\n",
2782 mboxq->u.mb.mbxStatus);
2783 mempool_free(mboxq, phba->mbox_mem_pool);
2784 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2788 lpfc_initial_flogi(vport);
2789 mempool_free(mboxq, phba->mbox_mem_pool);
2794 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2795 * @vport: pointer to lpfc_vport data structure.
2797 * This function issue a init_vfi mailbox command to initialize the VFI and
2798 * VPI for the physical port.
2801 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2803 LPFC_MBOXQ_t *mboxq;
2805 struct lpfc_hba *phba = vport->phba;
2807 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2809 lpfc_printf_vlog(vport, KERN_ERR,
2810 LOG_TRACE_EVENT, "2892 Failed to allocate "
2811 "init_vfi mailbox\n");
2814 lpfc_init_vfi(mboxq, vport);
2815 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2816 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2817 if (rc == MBX_NOT_FINISHED) {
2818 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2819 "2893 Failed to issue init_vfi mailbox\n");
2820 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2825 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2826 * @phba: pointer to lpfc hba data structure.
2827 * @mboxq: pointer to mailbox data structure.
2829 * This function handles completion of init vpi mailbox command.
2832 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2834 struct lpfc_vport *vport = mboxq->vport;
2835 struct lpfc_nodelist *ndlp;
2836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2838 if (mboxq->u.mb.mbxStatus) {
2839 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2840 "2609 Init VPI mailbox failed 0x%x\n",
2841 mboxq->u.mb.mbxStatus);
2842 mempool_free(mboxq, phba->mbox_mem_pool);
2843 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2846 spin_lock_irq(shost->host_lock);
2847 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2848 spin_unlock_irq(shost->host_lock);
2850 /* If this port is physical port or FDISC is done, do reg_vpi */
2851 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2852 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2854 lpfc_printf_vlog(vport, KERN_ERR,
2856 "2731 Cannot find fabric "
2857 "controller node\n");
2859 lpfc_register_new_vport(phba, vport, ndlp);
2860 mempool_free(mboxq, phba->mbox_mem_pool);
2864 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2865 lpfc_initial_fdisc(vport);
2867 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2868 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2869 "2606 No NPIV Fabric support\n");
2871 mempool_free(mboxq, phba->mbox_mem_pool);
2876 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2877 * @vport: pointer to lpfc_vport data structure.
2879 * This function issue a init_vpi mailbox command to initialize
2880 * VPI for the vport.
2883 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2885 LPFC_MBOXQ_t *mboxq;
2888 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2889 vpi = lpfc_alloc_vpi(vport->phba);
2891 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2892 "3303 Failed to obtain vport vpi\n");
2893 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2899 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2901 lpfc_printf_vlog(vport, KERN_ERR,
2902 LOG_TRACE_EVENT, "2607 Failed to allocate "
2903 "init_vpi mailbox\n");
2906 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2907 mboxq->vport = vport;
2908 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2909 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2910 if (rc == MBX_NOT_FINISHED) {
2911 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2912 "2608 Failed to issue init_vpi mailbox\n");
2913 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2918 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2919 * @phba: pointer to lpfc hba data structure.
2921 * This function loops through the list of vports on the @phba and issues an
2922 * FDISC if possible.
2925 lpfc_start_fdiscs(struct lpfc_hba *phba)
2927 struct lpfc_vport **vports;
2930 vports = lpfc_create_vport_work_array(phba);
2931 if (vports != NULL) {
2932 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2933 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2935 /* There are no vpi for this vport */
2936 if (vports[i]->vpi > phba->max_vpi) {
2937 lpfc_vport_set_state(vports[i],
2941 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2942 lpfc_vport_set_state(vports[i],
2946 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2947 lpfc_issue_init_vpi(vports[i]);
2950 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2951 lpfc_initial_fdisc(vports[i]);
2953 lpfc_vport_set_state(vports[i],
2954 FC_VPORT_NO_FABRIC_SUPP);
2955 lpfc_printf_vlog(vports[i], KERN_ERR,
2958 "Fabric support\n");
2962 lpfc_destroy_vport_work_array(phba, vports);
2966 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2968 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
2969 struct lpfc_vport *vport = mboxq->vport;
2970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2973 * VFI not supported for interface type 0, so ignore any mailbox
2974 * error (except VFI in use) and continue with the discovery.
2976 if (mboxq->u.mb.mbxStatus &&
2977 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2978 LPFC_SLI_INTF_IF_TYPE_0) &&
2979 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2980 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2981 "2018 REG_VFI mbxStatus error x%x "
2983 mboxq->u.mb.mbxStatus, vport->port_state);
2984 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2985 /* FLOGI failed, use loop map to make discovery list */
2986 lpfc_disc_list_loopmap(vport);
2987 /* Start discovery */
2988 lpfc_disc_start(vport);
2991 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2995 /* If the VFI is already registered, there is nothing else to do
2996 * Unless this was a VFI update and we are in PT2PT mode, then
2997 * we should drop through to set the port state to ready.
2999 if (vport->fc_flag & FC_VFI_REGISTERED)
3000 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3001 vport->fc_flag & FC_PT2PT))
3004 /* The VPI is implicitly registered when the VFI is registered */
3005 spin_lock_irq(shost->host_lock);
3006 vport->vpi_state |= LPFC_VPI_REGISTERED;
3007 vport->fc_flag |= FC_VFI_REGISTERED;
3008 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3009 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3010 spin_unlock_irq(shost->host_lock);
3012 /* In case SLI4 FC loopback test, we are ready */
3013 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3014 (phba->link_flag & LS_LOOPBACK_MODE)) {
3015 phba->link_state = LPFC_HBA_READY;
3019 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3020 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3021 "alpacnt:%d LinkState:%x topology:%x\n",
3022 vport->port_state, vport->fc_flag, vport->fc_myDID,
3023 vport->phba->alpa_map[0],
3024 phba->link_state, phba->fc_topology);
3026 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3028 * For private loop or for NPort pt2pt,
3029 * just start discovery and we are done.
3031 if ((vport->fc_flag & FC_PT2PT) ||
3032 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3033 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3035 /* Use loop map to make discovery list */
3036 lpfc_disc_list_loopmap(vport);
3037 /* Start discovery */
3038 if (vport->fc_flag & FC_PT2PT)
3039 vport->port_state = LPFC_VPORT_READY;
3041 lpfc_disc_start(vport);
3043 lpfc_start_fdiscs(phba);
3044 lpfc_do_scr_ns_plogi(phba, vport);
3049 mempool_free(mboxq, phba->mbox_mem_pool);
3051 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3058 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3060 MAILBOX_t *mb = &pmb->u.mb;
3061 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3062 struct lpfc_vport *vport = pmb->vport;
3063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3064 struct serv_parm *sp = &vport->fc_sparam;
3067 /* Check for error */
3068 if (mb->mbxStatus) {
3069 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3070 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3071 "0319 READ_SPARAM mbxStatus error x%x "
3073 mb->mbxStatus, vport->port_state);
3074 lpfc_linkdown(phba);
3078 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3079 sizeof (struct serv_parm));
3081 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3082 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3083 ed_tov = (ed_tov + 999999) / 1000000;
3085 phba->fc_edtov = ed_tov;
3086 phba->fc_ratov = (2 * ed_tov) / 1000;
3087 if (phba->fc_ratov < FF_DEF_RATOV) {
3088 /* RA_TOV should be atleast 10sec for initial flogi */
3089 phba->fc_ratov = FF_DEF_RATOV;
3092 lpfc_update_vport_wwn(vport);
3093 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3094 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3095 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3096 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3099 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3101 mempool_free(pmb, phba->mbox_mem_pool);
3103 /* Check if sending the FLOGI is being deferred to after we get
3104 * up to date CSPs from MBX_READ_SPARAM.
3106 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3107 lpfc_initial_flogi(vport);
3108 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3113 pmb->ctx_buf = NULL;
3114 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3116 lpfc_issue_clear_la(phba, vport);
3117 mempool_free(pmb, phba->mbox_mem_pool);
3122 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3124 struct lpfc_vport *vport = phba->pport;
3125 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3126 struct Scsi_Host *shost;
3128 struct lpfc_dmabuf *mp;
3130 struct fcf_record *fcf_record;
3131 uint32_t fc_flags = 0;
3132 unsigned long iflags;
3134 spin_lock_irqsave(&phba->hbalock, iflags);
3135 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3137 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3138 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3139 case LPFC_LINK_SPEED_1GHZ:
3140 case LPFC_LINK_SPEED_2GHZ:
3141 case LPFC_LINK_SPEED_4GHZ:
3142 case LPFC_LINK_SPEED_8GHZ:
3143 case LPFC_LINK_SPEED_10GHZ:
3144 case LPFC_LINK_SPEED_16GHZ:
3145 case LPFC_LINK_SPEED_32GHZ:
3146 case LPFC_LINK_SPEED_64GHZ:
3147 case LPFC_LINK_SPEED_128GHZ:
3150 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3155 if (phba->fc_topology &&
3156 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3157 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3158 "3314 Toplogy changed was 0x%x is 0x%x\n",
3160 bf_get(lpfc_mbx_read_top_topology, la));
3161 phba->fc_topology_changed = 1;
3164 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3165 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
3167 shost = lpfc_shost_from_vport(vport);
3168 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3169 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3171 /* if npiv is enabled and this adapter supports npiv log
3172 * a message that npiv is not supported in this topology
3174 if (phba->cfg_enable_npiv && phba->max_vpi)
3175 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3176 "1309 Link Up Event npiv not supported in loop "
3178 /* Get Loop Map information */
3179 if (bf_get(lpfc_mbx_read_top_il, la))
3180 fc_flags |= FC_LBIT;
3182 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3183 i = la->lilpBde64.tus.f.bdeSize;
3186 phba->alpa_map[0] = 0;
3188 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3199 numalpa = phba->alpa_map[0];
3201 while (j < numalpa) {
3202 memset(un.pamap, 0, 16);
3203 for (k = 1; j < numalpa; k++) {
3205 phba->alpa_map[j + 1];
3210 /* Link Up Event ALPA map */
3211 lpfc_printf_log(phba,
3214 "1304 Link Up Event "
3215 "ALPA map Data: x%x "
3217 un.pa.wd1, un.pa.wd2,
3218 un.pa.wd3, un.pa.wd4);
3223 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3224 if (phba->max_vpi && phba->cfg_enable_npiv &&
3225 (phba->sli_rev >= LPFC_SLI_REV3))
3226 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3228 vport->fc_myDID = phba->fc_pref_DID;
3229 fc_flags |= FC_LBIT;
3231 spin_unlock_irqrestore(&phba->hbalock, iflags);
3234 spin_lock_irqsave(shost->host_lock, iflags);
3235 vport->fc_flag |= fc_flags;
3236 spin_unlock_irqrestore(shost->host_lock, iflags);
3242 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3243 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3246 vport->port_state = LPFC_LOCAL_CFG_LINK;
3247 lpfc_config_link(phba, cfglink_mbox);
3248 cfglink_mbox->vport = vport;
3249 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3250 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3251 if (rc == MBX_NOT_FINISHED) {
3252 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3257 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3261 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3263 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3266 sparam_mbox->vport = vport;
3267 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3268 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3269 if (rc == MBX_NOT_FINISHED) {
3270 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3271 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3273 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3277 if (phba->hba_flag & HBA_FCOE_MODE) {
3278 vport->port_state = LPFC_VPORT_UNKNOWN;
3280 * Add the driver's default FCF record at FCF index 0 now. This
3281 * is phase 1 implementation that support FCF index 0 and driver
3284 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3285 fcf_record = kzalloc(sizeof(struct fcf_record),
3287 if (unlikely(!fcf_record)) {
3288 lpfc_printf_log(phba, KERN_ERR,
3290 "2554 Could not allocate memory for "
3296 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3297 LPFC_FCOE_FCF_DEF_INDEX);
3298 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3300 lpfc_printf_log(phba, KERN_ERR,
3302 "2013 Could not manually add FCF "
3303 "record 0, status %d\n", rc);
3311 * The driver is expected to do FIP/FCF. Call the port
3312 * and get the FCF Table.
3314 spin_lock_irqsave(&phba->hbalock, iflags);
3315 if (phba->hba_flag & FCF_TS_INPROG) {
3316 spin_unlock_irqrestore(&phba->hbalock, iflags);
3319 /* This is the initial FCF discovery scan */
3320 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3321 spin_unlock_irqrestore(&phba->hbalock, iflags);
3322 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3323 "2778 Start FCF table scan at linkup\n");
3324 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3325 LPFC_FCOE_FCF_GET_FIRST);
3327 spin_lock_irqsave(&phba->hbalock, iflags);
3328 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3329 spin_unlock_irqrestore(&phba->hbalock, iflags);
3332 /* Reset FCF roundrobin bmask for new discovery */
3333 lpfc_sli4_clear_fcf_rr_bmask(phba);
3335 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
3336 !(phba->link_flag & LS_LOOPBACK_MODE))
3337 phba->hba_flag |= HBA_DEFER_FLOGI;
3340 /* Prepare for LINK up registrations */
3341 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3342 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3343 init_utsname()->nodename);
3346 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3347 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3348 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3349 vport->port_state, sparam_mbox, cfglink_mbox);
3350 lpfc_issue_clear_la(phba, vport);
3355 lpfc_enable_la(struct lpfc_hba *phba)
3358 struct lpfc_sli *psli = &phba->sli;
3359 spin_lock_irq(&phba->hbalock);
3360 psli->sli_flag |= LPFC_PROCESS_LA;
3361 if (phba->sli_rev <= LPFC_SLI_REV3) {
3362 control = readl(phba->HCregaddr);
3363 control |= HC_LAINT_ENA;
3364 writel(control, phba->HCregaddr);
3365 readl(phba->HCregaddr); /* flush */
3367 spin_unlock_irq(&phba->hbalock);
3371 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3373 lpfc_linkdown(phba);
3374 lpfc_enable_la(phba);
3375 lpfc_unregister_unused_fcf(phba);
3376 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3381 * This routine handles processing a READ_TOPOLOGY mailbox
3382 * command upon completion. It is setup in the LPFC_MBOXQ
3383 * as the completion routine when the command is
3384 * handed off to the SLI layer. SLI4 only.
3387 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3389 struct lpfc_vport *vport = pmb->vport;
3390 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3391 struct lpfc_mbx_read_top *la;
3392 struct lpfc_sli_ring *pring;
3393 MAILBOX_t *mb = &pmb->u.mb;
3394 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3396 unsigned long iflags;
3398 /* Unblock ELS traffic */
3399 pring = lpfc_phba_elsring(phba);
3401 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3403 /* Check for error */
3404 if (mb->mbxStatus) {
3405 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3406 "1307 READ_LA mbox error x%x state x%x\n",
3407 mb->mbxStatus, vport->port_state);
3408 lpfc_mbx_issue_link_down(phba);
3409 phba->link_state = LPFC_HBA_ERROR;
3410 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3413 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3414 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3416 memcpy(&phba->alpa_map[0], mp->virt, 128);
3418 spin_lock_irqsave(shost->host_lock, iflags);
3419 if (bf_get(lpfc_mbx_read_top_pb, la))
3420 vport->fc_flag |= FC_BYPASSED_MODE;
3422 vport->fc_flag &= ~FC_BYPASSED_MODE;
3423 spin_unlock_irqrestore(shost->host_lock, iflags);
3425 if (phba->fc_eventTag <= la->eventTag) {
3426 phba->fc_stat.LinkMultiEvent++;
3427 if (attn_type == LPFC_ATT_LINK_UP)
3428 if (phba->fc_eventTag != 0)
3429 lpfc_linkdown(phba);
3432 phba->fc_eventTag = la->eventTag;
3433 if (phba->sli_rev < LPFC_SLI_REV4) {
3434 spin_lock_irqsave(&phba->hbalock, iflags);
3435 if (bf_get(lpfc_mbx_read_top_mm, la))
3436 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3438 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3439 spin_unlock_irqrestore(&phba->hbalock, iflags);
3442 phba->link_events++;
3443 if ((attn_type == LPFC_ATT_LINK_UP) &&
3444 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3445 phba->fc_stat.LinkUp++;
3446 if (phba->link_flag & LS_LOOPBACK_MODE) {
3447 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3448 "1306 Link Up Event in loop back mode "
3449 "x%x received Data: x%x x%x x%x x%x\n",
3450 la->eventTag, phba->fc_eventTag,
3451 bf_get(lpfc_mbx_read_top_alpa_granted,
3453 bf_get(lpfc_mbx_read_top_link_spd, la),
3456 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3457 "1303 Link Up Event x%x received "
3458 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3459 la->eventTag, phba->fc_eventTag,
3460 bf_get(lpfc_mbx_read_top_alpa_granted,
3462 bf_get(lpfc_mbx_read_top_link_spd, la),
3464 bf_get(lpfc_mbx_read_top_mm, la),
3465 bf_get(lpfc_mbx_read_top_fa, la),
3466 phba->wait_4_mlo_maint_flg);
3468 lpfc_mbx_process_link_up(phba, la);
3469 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3470 attn_type == LPFC_ATT_UNEXP_WWPN) {
3471 phba->fc_stat.LinkDown++;
3472 if (phba->link_flag & LS_LOOPBACK_MODE)
3473 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3474 "1308 Link Down Event in loop back mode "
3476 "Data: x%x x%x x%x\n",
3477 la->eventTag, phba->fc_eventTag,
3478 phba->pport->port_state, vport->fc_flag);
3479 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3480 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3481 "1313 Link Down Unexpected FA WWPN Event x%x "
3482 "received Data: x%x x%x x%x x%x x%x\n",
3483 la->eventTag, phba->fc_eventTag,
3484 phba->pport->port_state, vport->fc_flag,
3485 bf_get(lpfc_mbx_read_top_mm, la),
3486 bf_get(lpfc_mbx_read_top_fa, la));
3488 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3489 "1305 Link Down Event x%x received "
3490 "Data: x%x x%x x%x x%x x%x\n",
3491 la->eventTag, phba->fc_eventTag,
3492 phba->pport->port_state, vport->fc_flag,
3493 bf_get(lpfc_mbx_read_top_mm, la),
3494 bf_get(lpfc_mbx_read_top_fa, la));
3495 lpfc_mbx_issue_link_down(phba);
3497 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3498 attn_type == LPFC_ATT_LINK_UP) {
3499 if (phba->link_state != LPFC_LINK_DOWN) {
3500 phba->fc_stat.LinkDown++;
3501 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3502 "1312 Link Down Event x%x received "
3503 "Data: x%x x%x x%x\n",
3504 la->eventTag, phba->fc_eventTag,
3505 phba->pport->port_state, vport->fc_flag);
3506 lpfc_mbx_issue_link_down(phba);
3508 lpfc_enable_la(phba);
3510 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3511 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3512 "Data: x%x x%x x%x\n",
3513 la->eventTag, phba->fc_eventTag,
3514 phba->pport->port_state, vport->fc_flag);
3516 * The cmnd that triggered this will be waiting for this
3519 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3520 if (phba->wait_4_mlo_maint_flg) {
3521 phba->wait_4_mlo_maint_flg = 0;
3522 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3526 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3527 bf_get(lpfc_mbx_read_top_fa, la)) {
3528 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3529 lpfc_issue_clear_la(phba, vport);
3530 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3532 bf_get(lpfc_mbx_read_top_fa, la));
3535 lpfc_mbx_cmpl_read_topology_free_mbuf:
3536 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3538 mempool_free(pmb, phba->mbox_mem_pool);
3543 * This routine handles processing a REG_LOGIN mailbox
3544 * command upon completion. It is setup in the LPFC_MBOXQ
3545 * as the completion routine when the command is
3546 * handed off to the SLI layer.
3549 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3551 struct lpfc_vport *vport = pmb->vport;
3552 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3553 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3554 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3556 pmb->ctx_buf = NULL;
3557 pmb->ctx_ndlp = NULL;
3559 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3560 "0002 rpi:%x DID:%x flg:%x %d map:%x x%px\n",
3561 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3562 kref_read(&ndlp->kref),
3563 ndlp->nlp_usg_map, ndlp);
3564 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3565 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3567 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3568 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3569 /* We rcvd a rscn after issuing this
3570 * mbox reg login, we may have cycled
3571 * back through the state and be
3572 * back at reg login state so this
3573 * mbox needs to be ignored becase
3574 * there is another reg login in
3577 spin_lock_irq(shost->host_lock);
3578 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3579 spin_unlock_irq(shost->host_lock);
3582 * We cannot leave the RPI registered because
3583 * if we go thru discovery again for this ndlp
3584 * a subsequent REG_RPI will fail.
3586 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3587 lpfc_unreg_rpi(vport, ndlp);
3590 /* Call state machine */
3591 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3593 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3595 mempool_free(pmb, phba->mbox_mem_pool);
3596 /* decrement the node reference count held for this callback
3605 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3607 MAILBOX_t *mb = &pmb->u.mb;
3608 struct lpfc_vport *vport = pmb->vport;
3609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3611 switch (mb->mbxStatus) {
3614 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3615 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3618 /* If VPI is busy, reset the HBA */
3620 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3621 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3622 vport->vpi, mb->mbxStatus);
3623 if (!(phba->pport->load_flag & FC_UNLOADING))
3624 lpfc_workq_post_event(phba, NULL, NULL,
3625 LPFC_EVT_RESET_HBA);
3627 spin_lock_irq(shost->host_lock);
3628 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3629 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3630 spin_unlock_irq(shost->host_lock);
3631 vport->unreg_vpi_cmpl = VPORT_OK;
3632 mempool_free(pmb, phba->mbox_mem_pool);
3633 lpfc_cleanup_vports_rrqs(vport, NULL);
3635 * This shost reference might have been taken at the beginning of
3636 * lpfc_vport_delete()
3638 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3639 scsi_host_put(shost);
3643 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3645 struct lpfc_hba *phba = vport->phba;
3649 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3653 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3654 mbox->vport = vport;
3655 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3656 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3657 if (rc == MBX_NOT_FINISHED) {
3658 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3659 "1800 Could not issue unreg_vpi\n");
3660 mempool_free(mbox, phba->mbox_mem_pool);
3661 vport->unreg_vpi_cmpl = VPORT_ERROR;
3668 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3670 struct lpfc_vport *vport = pmb->vport;
3671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3672 MAILBOX_t *mb = &pmb->u.mb;
3674 switch (mb->mbxStatus) {
3678 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3679 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3681 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3682 spin_lock_irq(shost->host_lock);
3683 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3684 spin_unlock_irq(shost->host_lock);
3685 vport->fc_myDID = 0;
3687 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3688 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3689 if (phba->nvmet_support)
3690 lpfc_nvmet_update_targetport(phba);
3692 lpfc_nvme_update_localport(vport);
3697 spin_lock_irq(shost->host_lock);
3698 vport->vpi_state |= LPFC_VPI_REGISTERED;
3699 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3700 spin_unlock_irq(shost->host_lock);
3701 vport->num_disc_nodes = 0;
3702 /* go thru NPR list and issue ELS PLOGIs */
3703 if (vport->fc_npr_cnt)
3704 lpfc_els_disc_plogi(vport);
3706 if (!vport->num_disc_nodes) {
3707 spin_lock_irq(shost->host_lock);
3708 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3709 spin_unlock_irq(shost->host_lock);
3710 lpfc_can_disctmo(vport);
3712 vport->port_state = LPFC_VPORT_READY;
3715 mempool_free(pmb, phba->mbox_mem_pool);
3720 * lpfc_create_static_vport - Read HBA config region to create static vports.
3721 * @phba: pointer to lpfc hba data structure.
3723 * This routine issue a DUMP mailbox command for config region 22 to get
3724 * the list of static vports to be created. The function create vports
3725 * based on the information returned from the HBA.
3728 lpfc_create_static_vport(struct lpfc_hba *phba)
3730 LPFC_MBOXQ_t *pmb = NULL;
3732 struct static_vport_info *vport_info;
3733 int mbx_wait_rc = 0, i;
3734 struct fc_vport_identifiers vport_id;
3735 struct fc_vport *new_fc_vport;
3736 struct Scsi_Host *shost;
3737 struct lpfc_vport *vport;
3738 uint16_t offset = 0;
3739 uint8_t *vport_buff;
3740 struct lpfc_dmabuf *mp;
3741 uint32_t byte_count = 0;
3743 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3745 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3746 "0542 lpfc_create_static_vport failed to"
3747 " allocate mailbox memory\n");
3750 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3753 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3755 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3756 "0543 lpfc_create_static_vport failed to"
3757 " allocate vport_info\n");
3758 mempool_free(pmb, phba->mbox_mem_pool);
3762 vport_buff = (uint8_t *) vport_info;
3764 /* free dma buffer from previous round */
3766 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3767 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3770 if (lpfc_dump_static_vport(phba, pmb, offset))
3773 pmb->vport = phba->pport;
3774 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3777 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3778 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3779 "0544 lpfc_create_static_vport failed to"
3780 " issue dump mailbox command ret 0x%x "
3782 mbx_wait_rc, mb->mbxStatus);
3786 if (phba->sli_rev == LPFC_SLI_REV4) {
3787 byte_count = pmb->u.mqe.un.mb_words[5];
3788 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3789 if (byte_count > sizeof(struct static_vport_info) -
3791 byte_count = sizeof(struct static_vport_info)
3793 memcpy(vport_buff + offset, mp->virt, byte_count);
3794 offset += byte_count;
3796 if (mb->un.varDmp.word_cnt >
3797 sizeof(struct static_vport_info) - offset)
3798 mb->un.varDmp.word_cnt =
3799 sizeof(struct static_vport_info)
3801 byte_count = mb->un.varDmp.word_cnt;
3802 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3803 vport_buff + offset,
3806 offset += byte_count;
3809 } while (byte_count &&
3810 offset < sizeof(struct static_vport_info));
3813 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3814 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3815 != VPORT_INFO_REV)) {
3816 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3817 "0545 lpfc_create_static_vport bad"
3818 " information header 0x%x 0x%x\n",
3819 le32_to_cpu(vport_info->signature),
3820 le32_to_cpu(vport_info->rev) &
3821 VPORT_INFO_REV_MASK);
3826 shost = lpfc_shost_from_vport(phba->pport);
3828 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3829 memset(&vport_id, 0, sizeof(vport_id));
3830 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3831 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3832 if (!vport_id.port_name || !vport_id.node_name)
3835 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3836 vport_id.vport_type = FC_PORTTYPE_NPIV;
3837 vport_id.disable = false;
3838 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3840 if (!new_fc_vport) {
3841 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3842 "0546 lpfc_create_static_vport failed to"
3847 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3848 vport->vport_flag |= STATIC_VPORT;
3853 if (mbx_wait_rc != MBX_TIMEOUT) {
3855 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3856 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3859 mempool_free(pmb, phba->mbox_mem_pool);
3866 * This routine handles processing a Fabric REG_LOGIN mailbox
3867 * command upon completion. It is setup in the LPFC_MBOXQ
3868 * as the completion routine when the command is
3869 * handed off to the SLI layer.
3872 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3874 struct lpfc_vport *vport = pmb->vport;
3875 MAILBOX_t *mb = &pmb->u.mb;
3876 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3877 struct lpfc_nodelist *ndlp;
3878 struct Scsi_Host *shost;
3880 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3881 pmb->ctx_ndlp = NULL;
3882 pmb->ctx_buf = NULL;
3884 if (mb->mbxStatus) {
3885 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3886 "0258 Register Fabric login error: 0x%x\n",
3888 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3890 mempool_free(pmb, phba->mbox_mem_pool);
3892 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3893 /* FLOGI failed, use loop map to make discovery list */
3894 lpfc_disc_list_loopmap(vport);
3896 /* Start discovery */
3897 lpfc_disc_start(vport);
3898 /* Decrement the reference count to ndlp after the
3899 * reference to the ndlp are done.
3905 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3906 /* Decrement the reference count to ndlp after the reference
3907 * to the ndlp are done.
3913 if (phba->sli_rev < LPFC_SLI_REV4)
3914 ndlp->nlp_rpi = mb->un.varWords[0];
3915 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3916 ndlp->nlp_type |= NLP_FABRIC;
3917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3919 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3920 /* when physical port receive logo donot start
3921 * vport discovery */
3922 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3923 lpfc_start_fdiscs(phba);
3925 shost = lpfc_shost_from_vport(vport);
3926 spin_lock_irq(shost->host_lock);
3927 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3928 spin_unlock_irq(shost->host_lock);
3930 lpfc_do_scr_ns_plogi(phba, vport);
3933 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3935 mempool_free(pmb, phba->mbox_mem_pool);
3937 /* Drop the reference count from the mbox at the end after
3938 * all the current reference to the ndlp have been done.
3945 * This routine will issue a GID_FT for each FC4 Type supported
3946 * by the driver. ALL GID_FTs must complete before discovery is started.
3949 lpfc_issue_gidft(struct lpfc_vport *vport)
3951 /* Good status, issue CT Request to NameServer */
3952 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3953 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
3954 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3955 /* Cannot issue NameServer FCP Query, so finish up
3958 lpfc_printf_vlog(vport, KERN_ERR,
3960 "0604 %s FC TYPE %x %s\n",
3961 "Failed to issue GID_FT to ",
3963 "Finishing discovery.");
3969 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3970 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3971 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3972 /* Cannot issue NameServer NVME Query, so finish up
3975 lpfc_printf_vlog(vport, KERN_ERR,
3977 "0605 %s FC_TYPE %x %s %d\n",
3978 "Failed to issue GID_FT to ",
3980 "Finishing discovery: gidftinp ",
3982 if (vport->gidft_inp == 0)
3987 return vport->gidft_inp;
3991 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3992 * @vport: The virtual port for which this call is being executed.
3994 * This routine will issue a GID_PT to get a list of all N_Ports
3997 * 0 - Failure to issue a GID_PT
4001 lpfc_issue_gidpt(struct lpfc_vport *vport)
4003 /* Good status, issue CT Request to NameServer */
4004 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4005 /* Cannot issue NameServer FCP Query, so finish up
4008 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4009 "0606 %s Port TYPE %x %s\n",
4010 "Failed to issue GID_PT to ",
4012 "Finishing discovery.");
4020 * This routine handles processing a NameServer REG_LOGIN mailbox
4021 * command upon completion. It is setup in the LPFC_MBOXQ
4022 * as the completion routine when the command is
4023 * handed off to the SLI layer.
4026 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4028 MAILBOX_t *mb = &pmb->u.mb;
4029 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4030 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4031 struct lpfc_vport *vport = pmb->vport;
4033 pmb->ctx_buf = NULL;
4034 pmb->ctx_ndlp = NULL;
4035 vport->gidft_inp = 0;
4037 if (mb->mbxStatus) {
4038 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4039 "0260 Register NameServer error: 0x%x\n",
4043 /* decrement the node reference count held for this
4044 * callback function.
4047 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4049 mempool_free(pmb, phba->mbox_mem_pool);
4051 /* If no other thread is using the ndlp, free it */
4052 lpfc_nlp_not_used(ndlp);
4054 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4056 * RegLogin failed, use loop map to make discovery
4059 lpfc_disc_list_loopmap(vport);
4061 /* Start discovery */
4062 lpfc_disc_start(vport);
4065 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4069 if (phba->sli_rev < LPFC_SLI_REV4)
4070 ndlp->nlp_rpi = mb->un.varWords[0];
4071 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4072 ndlp->nlp_type |= NLP_FABRIC;
4073 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4074 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4075 "0003 rpi:%x DID:%x flg:%x %d map%x x%px\n",
4076 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4077 kref_read(&ndlp->kref),
4078 ndlp->nlp_usg_map, ndlp);
4080 if (vport->port_state < LPFC_VPORT_READY) {
4081 /* Link up discovery requires Fabric registration. */
4082 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4083 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4084 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4085 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4087 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4088 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4089 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4091 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4092 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4093 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4096 /* Issue SCR just before NameServer GID_FT Query */
4097 lpfc_issue_els_scr(vport, 0);
4099 lpfc_issue_els_rdf(vport, 0);
4102 vport->fc_ns_retry = 0;
4103 if (lpfc_issue_gidft(vport) == 0)
4107 * At this point in time we may need to wait for multiple
4108 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4110 * decrement the node reference count held for this
4111 * callback function.
4114 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4116 mempool_free(pmb, phba->mbox_mem_pool);
4122 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4124 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4125 struct fc_rport *rport;
4126 struct lpfc_rport_data *rdata;
4127 struct fc_rport_identifiers rport_ids;
4128 struct lpfc_hba *phba = vport->phba;
4130 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4133 /* Remote port has reappeared. Re-register w/ FC transport */
4134 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4135 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4136 rport_ids.port_id = ndlp->nlp_DID;
4137 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4140 * We leave our node pointer in rport->dd_data when we unregister a
4141 * FCP target port. But fc_remote_port_add zeros the space to which
4142 * rport->dd_data points. So, if we're reusing a previously
4143 * registered port, drop the reference that we took the last time we
4144 * registered the port.
4146 rport = ndlp->rport;
4148 rdata = rport->dd_data;
4149 /* break the link before dropping the ref */
4152 if (rdata->pnode == ndlp)
4154 rdata->pnode = NULL;
4156 /* drop reference for earlier registeration */
4157 put_device(&rport->dev);
4160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4161 "rport add: did:x%x flg:x%x type x%x",
4162 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4164 /* Don't add the remote port if unloading. */
4165 if (vport->load_flag & FC_UNLOADING)
4168 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4169 if (!rport || !get_device(&rport->dev)) {
4170 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4171 "Warning: fc_remote_port_add failed\n");
4175 /* initialize static port data */
4176 rport->maxframe_size = ndlp->nlp_maxframe;
4177 rport->supported_classes = ndlp->nlp_class_sup;
4178 rdata = rport->dd_data;
4179 rdata->pnode = lpfc_nlp_get(ndlp);
4181 if (ndlp->nlp_type & NLP_FCP_TARGET)
4182 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4183 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4184 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4185 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4186 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4187 if (ndlp->nlp_type & NLP_NVME_TARGET)
4188 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4189 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4190 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4192 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4193 fc_remote_port_rolechg(rport, rport_ids.roles);
4195 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4196 "3183 rport register x%06x, rport x%px role x%x\n",
4197 ndlp->nlp_DID, rport, rport_ids.roles);
4199 if ((rport->scsi_target_id != -1) &&
4200 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4201 ndlp->nlp_sid = rport->scsi_target_id;
4207 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4209 struct fc_rport *rport = ndlp->rport;
4210 struct lpfc_vport *vport = ndlp->vport;
4212 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4216 "rport delete: did:x%x flg:x%x type x%x",
4217 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4219 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4220 "3184 rport unregister x%06x, rport x%px\n",
4221 ndlp->nlp_DID, rport);
4223 fc_remote_port_delete(rport);
4229 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4231 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4232 unsigned long iflags;
4234 spin_lock_irqsave(shost->host_lock, iflags);
4236 case NLP_STE_UNUSED_NODE:
4237 vport->fc_unused_cnt += count;
4239 case NLP_STE_PLOGI_ISSUE:
4240 vport->fc_plogi_cnt += count;
4242 case NLP_STE_ADISC_ISSUE:
4243 vport->fc_adisc_cnt += count;
4245 case NLP_STE_REG_LOGIN_ISSUE:
4246 vport->fc_reglogin_cnt += count;
4248 case NLP_STE_PRLI_ISSUE:
4249 vport->fc_prli_cnt += count;
4251 case NLP_STE_UNMAPPED_NODE:
4252 vport->fc_unmap_cnt += count;
4254 case NLP_STE_MAPPED_NODE:
4255 vport->fc_map_cnt += count;
4257 case NLP_STE_NPR_NODE:
4258 if (vport->fc_npr_cnt == 0 && count == -1)
4259 vport->fc_npr_cnt = 0;
4261 vport->fc_npr_cnt += count;
4264 spin_unlock_irqrestore(shost->host_lock, iflags);
4268 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4269 int old_state, int new_state)
4271 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4273 if (new_state == NLP_STE_UNMAPPED_NODE) {
4274 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4275 ndlp->nlp_type |= NLP_FC_NODE;
4277 if (new_state == NLP_STE_MAPPED_NODE)
4278 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4279 if (new_state == NLP_STE_NPR_NODE)
4280 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4282 /* FCP and NVME Transport interface */
4283 if ((old_state == NLP_STE_MAPPED_NODE ||
4284 old_state == NLP_STE_UNMAPPED_NODE)) {
4286 vport->phba->nport_event_cnt++;
4287 lpfc_unregister_remote_port(ndlp);
4290 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4291 vport->phba->nport_event_cnt++;
4292 if (vport->phba->nvmet_support == 0) {
4293 /* Start devloss if target. */
4294 if (ndlp->nlp_type & NLP_NVME_TARGET)
4295 lpfc_nvme_unregister_port(vport, ndlp);
4297 /* NVMET has no upcall. */
4303 /* FCP and NVME Transport interfaces */
4305 if (new_state == NLP_STE_MAPPED_NODE ||
4306 new_state == NLP_STE_UNMAPPED_NODE) {
4307 if (ndlp->nlp_fc4_type ||
4308 ndlp->nlp_DID == Fabric_DID ||
4309 ndlp->nlp_DID == NameServer_DID ||
4310 ndlp->nlp_DID == FDMI_DID) {
4311 vport->phba->nport_event_cnt++;
4313 * Tell the fc transport about the port, if we haven't
4314 * already. If we have, and it's a scsi entity, be
4316 lpfc_register_remote_port(vport, ndlp);
4318 /* Notify the NVME transport of this new rport. */
4319 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4320 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4321 if (vport->phba->nvmet_support == 0) {
4322 /* Register this rport with the transport.
4323 * Only NVME Target Rports are registered with
4326 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4327 vport->phba->nport_event_cnt++;
4328 lpfc_nvme_register_port(vport, ndlp);
4331 /* Just take an NDLP ref count since the
4332 * target does not register rports.
4339 if ((new_state == NLP_STE_MAPPED_NODE) &&
4340 (vport->stat_data_enabled)) {
4342 * A new target is discovered, if there is no buffer for
4343 * statistical data collection allocate buffer.
4345 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4346 sizeof(struct lpfc_scsicmd_bkt),
4349 if (!ndlp->lat_data)
4350 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4351 "0286 lpfc_nlp_state_cleanup failed to "
4352 "allocate statistical data buffer DID "
4353 "0x%x\n", ndlp->nlp_DID);
4356 * If the node just added to Mapped list was an FCP target,
4357 * but the remote port registration failed or assigned a target
4358 * id outside the presentable range - move the node to the
4361 if ((new_state == NLP_STE_MAPPED_NODE) &&
4362 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4364 ndlp->rport->scsi_target_id == -1 ||
4365 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4366 spin_lock_irq(shost->host_lock);
4367 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4368 spin_unlock_irq(shost->host_lock);
4369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4374 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4376 static char *states[] = {
4377 [NLP_STE_UNUSED_NODE] = "UNUSED",
4378 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4379 [NLP_STE_ADISC_ISSUE] = "ADISC",
4380 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4381 [NLP_STE_PRLI_ISSUE] = "PRLI",
4382 [NLP_STE_LOGO_ISSUE] = "LOGO",
4383 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4384 [NLP_STE_MAPPED_NODE] = "MAPPED",
4385 [NLP_STE_NPR_NODE] = "NPR",
4388 if (state < NLP_STE_MAX_STATE && states[state])
4389 strlcpy(buffer, states[state], size);
4391 snprintf(buffer, size, "unknown (%d)", state);
4396 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4399 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4400 int old_state = ndlp->nlp_state;
4401 char name1[16], name2[16];
4403 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4404 "0904 NPort state transition x%06x, %s -> %s\n",
4406 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4407 lpfc_nlp_state_name(name2, sizeof(name2), state));
4409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4410 "node statechg did:x%x old:%d ste:%d",
4411 ndlp->nlp_DID, old_state, state);
4413 if (old_state == NLP_STE_NPR_NODE &&
4414 state != NLP_STE_NPR_NODE)
4415 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4416 if (old_state == NLP_STE_UNMAPPED_NODE) {
4417 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4418 ndlp->nlp_type &= ~NLP_FC_NODE;
4421 if (list_empty(&ndlp->nlp_listp)) {
4422 spin_lock_irq(shost->host_lock);
4423 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4424 spin_unlock_irq(shost->host_lock);
4425 } else if (old_state)
4426 lpfc_nlp_counters(vport, old_state, -1);
4428 ndlp->nlp_state = state;
4429 lpfc_nlp_counters(vport, state, 1);
4430 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4434 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4436 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4438 if (list_empty(&ndlp->nlp_listp)) {
4439 spin_lock_irq(shost->host_lock);
4440 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4441 spin_unlock_irq(shost->host_lock);
4446 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4448 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4450 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4451 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4452 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4453 spin_lock_irq(shost->host_lock);
4454 list_del_init(&ndlp->nlp_listp);
4455 spin_unlock_irq(shost->host_lock);
4456 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4457 NLP_STE_UNUSED_NODE);
4461 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4463 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4464 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4465 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4466 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4467 NLP_STE_UNUSED_NODE);
4470 * lpfc_initialize_node - Initialize all fields of node object
4471 * @vport: Pointer to Virtual Port object.
4472 * @ndlp: Pointer to FC node object.
4473 * @did: FC_ID of the node.
4475 * This function is always called when node object need to be initialized.
4476 * It initializes all the fields of the node object. Although the reference
4477 * to phba from @ndlp can be obtained indirectly through it's reference to
4478 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4479 * to the life-span of the @ndlp might go beyond the existence of @vport as
4480 * the final release of ndlp is determined by its reference count. And, the
4481 * operation on @ndlp needs the reference to phba.
4484 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4487 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4488 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4489 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4490 ndlp->nlp_DID = did;
4491 ndlp->vport = vport;
4492 ndlp->phba = vport->phba;
4493 ndlp->nlp_sid = NLP_NO_SID;
4494 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4495 kref_init(&ndlp->kref);
4496 NLP_INT_NODE_ACT(ndlp);
4497 atomic_set(&ndlp->cmd_pending, 0);
4498 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4499 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4502 struct lpfc_nodelist *
4503 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4506 struct lpfc_hba *phba = vport->phba;
4508 unsigned long flags;
4509 unsigned long *active_rrqs_xri_bitmap = NULL;
4510 int rpi = LPFC_RPI_ALLOC_ERROR;
4511 uint32_t defer_did = 0;
4516 if (phba->sli_rev == LPFC_SLI_REV4) {
4517 if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)
4518 rpi = lpfc_sli4_alloc_rpi(vport->phba);
4520 rpi = ndlp->nlp_rpi;
4522 if (rpi == LPFC_RPI_ALLOC_ERROR) {
4523 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4524 "0359 %s: ndlp:x%px "
4525 "usgmap:x%x refcnt:%d FAILED RPI "
4528 (void *)ndlp, ndlp->nlp_usg_map,
4529 kref_read(&ndlp->kref));
4534 spin_lock_irqsave(&phba->ndlp_lock, flags);
4535 /* The ndlp should not be in memory free mode */
4536 if (NLP_CHK_FREE_REQ(ndlp)) {
4537 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4538 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4539 "0277 %s: ndlp:x%px "
4540 "usgmap:x%x refcnt:%d\n",
4541 __func__, (void *)ndlp, ndlp->nlp_usg_map,
4542 kref_read(&ndlp->kref));
4545 /* The ndlp should not already be in active mode */
4546 if (NLP_CHK_NODE_ACT(ndlp)) {
4547 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4548 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4549 "0278 %s: ndlp:x%px "
4550 "usgmap:x%x refcnt:%d\n",
4551 __func__, (void *)ndlp, ndlp->nlp_usg_map,
4552 kref_read(&ndlp->kref));
4556 /* First preserve the orginal DID, xri_bitmap and some flags */
4557 did = ndlp->nlp_DID;
4558 flag = (ndlp->nlp_flag & NLP_UNREG_INP);
4559 if (flag & NLP_UNREG_INP)
4560 defer_did = ndlp->nlp_defer_did;
4561 if (phba->sli_rev == LPFC_SLI_REV4)
4562 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
4564 /* Zero ndlp except of ndlp linked list pointer */
4565 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4566 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
4568 /* Next reinitialize and restore saved objects */
4569 lpfc_initialize_node(vport, ndlp, did);
4570 ndlp->nlp_flag |= flag;
4571 if (flag & NLP_UNREG_INP)
4572 ndlp->nlp_defer_did = defer_did;
4573 if (phba->sli_rev == LPFC_SLI_REV4)
4574 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4576 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4577 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4578 ndlp->nlp_rpi = rpi;
4579 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4580 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4581 "map:%x x%px\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4583 kref_read(&ndlp->kref),
4584 ndlp->nlp_usg_map, ndlp);
4588 if (state != NLP_STE_UNUSED_NODE)
4589 lpfc_nlp_set_state(vport, ndlp, state);
4591 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4592 "0013 rpi:%x DID:%x flg:%x refcnt:%d "
4593 "map:%x x%px STATE=UNUSED\n",
4594 ndlp->nlp_rpi, ndlp->nlp_DID,
4596 kref_read(&ndlp->kref),
4597 ndlp->nlp_usg_map, ndlp);
4599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4600 "node enable: did:x%x",
4601 ndlp->nlp_DID, 0, 0);
4605 if (phba->sli_rev == LPFC_SLI_REV4) {
4606 lpfc_sli4_free_rpi(vport->phba, rpi);
4607 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4613 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4616 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4617 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4618 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4619 * until ALL other outstanding threads have completed. We check
4620 * that the ndlp not already in the UNUSED state before we proceed.
4622 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4625 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4626 lpfc_cleanup_vports_rrqs(vport, ndlp);
4627 lpfc_unreg_rpi(vport, ndlp);
4635 * Start / ReStart rescue timer for Discovery / RSCN handling
4638 lpfc_set_disctmo(struct lpfc_vport *vport)
4640 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4641 struct lpfc_hba *phba = vport->phba;
4644 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4645 /* For FAN, timeout should be greater than edtov */
4646 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4648 /* Normal discovery timeout should be > than ELS/CT timeout
4649 * FC spec states we need 3 * ratov for CT requests
4651 tmo = ((phba->fc_ratov * 3) + 3);
4655 if (!timer_pending(&vport->fc_disctmo)) {
4656 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4657 "set disc timer: tmo:x%x state:x%x flg:x%x",
4658 tmo, vport->port_state, vport->fc_flag);
4661 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4662 spin_lock_irq(shost->host_lock);
4663 vport->fc_flag |= FC_DISC_TMO;
4664 spin_unlock_irq(shost->host_lock);
4666 /* Start Discovery Timer state <hba_state> */
4667 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4668 "0247 Start Discovery Timer state x%x "
4669 "Data: x%x x%lx x%x x%x\n",
4670 vport->port_state, tmo,
4671 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4672 vport->fc_adisc_cnt);
4678 * Cancel rescue timer for Discovery / RSCN handling
4681 lpfc_can_disctmo(struct lpfc_vport *vport)
4683 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4684 unsigned long iflags;
4686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4687 "can disc timer: state:x%x rtry:x%x flg:x%x",
4688 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4690 /* Turn off discovery timer if its running */
4691 if (vport->fc_flag & FC_DISC_TMO) {
4692 spin_lock_irqsave(shost->host_lock, iflags);
4693 vport->fc_flag &= ~FC_DISC_TMO;
4694 spin_unlock_irqrestore(shost->host_lock, iflags);
4695 del_timer_sync(&vport->fc_disctmo);
4696 spin_lock_irqsave(&vport->work_port_lock, iflags);
4697 vport->work_port_events &= ~WORKER_DISC_TMO;
4698 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4701 /* Cancel Discovery Timer state <hba_state> */
4702 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4703 "0248 Cancel Discovery Timer state x%x "
4704 "Data: x%x x%x x%x\n",
4705 vport->port_state, vport->fc_flag,
4706 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4711 * Check specified ring for outstanding IOCB on the SLI queue
4712 * Return true if iocb matches the specified nport
4715 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4716 struct lpfc_sli_ring *pring,
4717 struct lpfc_iocbq *iocb,
4718 struct lpfc_nodelist *ndlp)
4720 IOCB_t *icmd = &iocb->iocb;
4721 struct lpfc_vport *vport = ndlp->vport;
4723 if (iocb->vport != vport)
4726 if (pring->ringno == LPFC_ELS_RING) {
4727 switch (icmd->ulpCommand) {
4728 case CMD_GEN_REQUEST64_CR:
4729 if (iocb->context_un.ndlp == ndlp)
4732 case CMD_ELS_REQUEST64_CR:
4733 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4736 case CMD_XMIT_ELS_RSP64_CX:
4737 if (iocb->context1 == (uint8_t *) ndlp)
4741 } else if (pring->ringno == LPFC_FCP_RING) {
4742 /* Skip match check if waiting to relogin to FCP target */
4743 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4744 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4747 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4755 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4756 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4757 struct list_head *dequeue_list)
4759 struct lpfc_iocbq *iocb, *next_iocb;
4761 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4762 /* Check to see if iocb matches the nport */
4763 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4764 /* match, dequeue */
4765 list_move_tail(&iocb->list, dequeue_list);
4770 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4771 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4773 struct lpfc_sli *psli = &phba->sli;
4776 spin_lock_irq(&phba->hbalock);
4777 for (i = 0; i < psli->num_rings; i++)
4778 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4780 spin_unlock_irq(&phba->hbalock);
4784 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4785 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4787 struct lpfc_sli_ring *pring;
4788 struct lpfc_queue *qp = NULL;
4790 spin_lock_irq(&phba->hbalock);
4791 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4795 spin_lock(&pring->ring_lock);
4796 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
4797 spin_unlock(&pring->ring_lock);
4799 spin_unlock_irq(&phba->hbalock);
4803 * Free resources / clean up outstanding I/Os
4804 * associated with nlp_rpi in the LPFC_NODELIST entry.
4807 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4809 LIST_HEAD(completions);
4811 lpfc_fabric_abort_nport(ndlp);
4814 * Everything that matches on txcmplq will be returned
4815 * by firmware with a no rpi error.
4817 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4818 if (phba->sli_rev != LPFC_SLI_REV4)
4819 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4821 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
4824 /* Cancel all the IOCBs from the completions list */
4825 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4832 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4833 * @phba: Pointer to HBA context object.
4834 * @pmb: Pointer to mailbox object.
4836 * This function will issue an ELS LOGO command after completing
4840 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4842 struct lpfc_vport *vport = pmb->vport;
4843 struct lpfc_nodelist *ndlp;
4845 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
4848 lpfc_issue_els_logo(vport, ndlp, 0);
4849 mempool_free(pmb, phba->mbox_mem_pool);
4851 /* Check to see if there are any deferred events to process */
4852 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4853 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4854 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4855 "1434 UNREG cmpl deferred logo x%x "
4856 "on NPort x%x Data: x%x x%px\n",
4857 ndlp->nlp_rpi, ndlp->nlp_DID,
4858 ndlp->nlp_defer_did, ndlp);
4860 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4861 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4862 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4864 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4865 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
4866 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
4867 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4869 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4874 * Sets the mailbox completion handler to be used for the
4875 * unreg_rpi command. The handler varies based on the state of
4876 * the port and what will be happening to the rpi next.
4879 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
4880 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
4882 unsigned long iflags;
4884 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4885 mbox->ctx_ndlp = ndlp;
4886 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4888 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
4889 (!(vport->load_flag & FC_UNLOADING)) &&
4890 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
4891 LPFC_SLI_INTF_IF_TYPE_2) &&
4892 (kref_read(&ndlp->kref) > 0)) {
4893 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4894 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
4896 if (vport->load_flag & FC_UNLOADING) {
4897 if (phba->sli_rev == LPFC_SLI_REV4) {
4898 spin_lock_irqsave(&vport->phba->ndlp_lock,
4900 ndlp->nlp_flag |= NLP_RELEASE_RPI;
4901 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
4906 mbox->ctx_ndlp = ndlp;
4907 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4912 * Free rpi associated with LPFC_NODELIST entry.
4913 * This routine is called from lpfc_freenode(), when we are removing
4914 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4915 * LOGO that completes successfully, and we are waiting to PLOGI back
4916 * to the remote NPort. In addition, it is called after we receive
4917 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4918 * we are waiting to PLOGI back to the remote NPort.
4921 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4923 struct lpfc_hba *phba = vport->phba;
4925 int rc, acc_plogi = 1;
4928 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4929 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4930 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4931 lpfc_printf_vlog(vport, KERN_INFO,
4932 LOG_NODE | LOG_DISCOVERY,
4933 "3366 RPI x%x needs to be "
4934 "unregistered nlp_flag x%x "
4936 ndlp->nlp_rpi, ndlp->nlp_flag,
4939 /* If there is already an UNREG in progress for this ndlp,
4940 * no need to queue up another one.
4942 if (ndlp->nlp_flag & NLP_UNREG_INP) {
4943 lpfc_printf_vlog(vport, KERN_INFO,
4944 LOG_NODE | LOG_DISCOVERY,
4945 "1436 unreg_rpi SKIP UNREG x%x on "
4946 "NPort x%x deferred x%x flg x%x "
4948 ndlp->nlp_rpi, ndlp->nlp_DID,
4949 ndlp->nlp_defer_did,
4950 ndlp->nlp_flag, ndlp);
4954 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4956 /* SLI4 ports require the physical rpi value. */
4957 rpi = ndlp->nlp_rpi;
4958 if (phba->sli_rev == LPFC_SLI_REV4)
4959 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4961 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4962 mbox->vport = vport;
4963 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
4964 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
4966 * accept PLOGIs after unreg_rpi_cmpl
4969 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4971 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4972 ndlp->nlp_flag |= NLP_UNREG_INP;
4974 lpfc_printf_vlog(vport, KERN_INFO,
4975 LOG_NODE | LOG_DISCOVERY,
4976 "1433 unreg_rpi UNREG x%x on "
4977 "NPort x%x deferred flg x%x "
4979 ndlp->nlp_rpi, ndlp->nlp_DID,
4980 ndlp->nlp_flag, ndlp);
4982 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4983 if (rc == MBX_NOT_FINISHED) {
4984 mempool_free(mbox, phba->mbox_mem_pool);
4988 lpfc_no_rpi(phba, ndlp);
4990 if (phba->sli_rev != LPFC_SLI_REV4)
4992 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4993 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4995 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4998 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5003 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5004 * @phba: pointer to lpfc hba data structure.
5006 * This routine is invoked to unregister all the currently registered RPIs
5010 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5012 struct lpfc_vport **vports;
5013 struct lpfc_nodelist *ndlp;
5014 struct Scsi_Host *shost;
5017 vports = lpfc_create_vport_work_array(phba);
5019 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5020 "2884 Vport array allocation failed \n");
5023 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5024 shost = lpfc_shost_from_vport(vports[i]);
5025 spin_lock_irq(shost->host_lock);
5026 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5027 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5028 /* The mempool_alloc might sleep */
5029 spin_unlock_irq(shost->host_lock);
5030 lpfc_unreg_rpi(vports[i], ndlp);
5031 spin_lock_irq(shost->host_lock);
5034 spin_unlock_irq(shost->host_lock);
5036 lpfc_destroy_vport_work_array(phba, vports);
5040 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5042 struct lpfc_hba *phba = vport->phba;
5046 if (phba->sli_rev == LPFC_SLI_REV4) {
5047 lpfc_sli4_unreg_all_rpis(vport);
5051 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5053 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5055 mbox->vport = vport;
5056 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5057 mbox->ctx_ndlp = NULL;
5058 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5059 if (rc != MBX_TIMEOUT)
5060 mempool_free(mbox, phba->mbox_mem_pool);
5062 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5063 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5064 "1836 Could not issue "
5065 "unreg_login(all_rpis) status %d\n",
5071 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5073 struct lpfc_hba *phba = vport->phba;
5077 /* Unreg DID is an SLI3 operation. */
5078 if (phba->sli_rev > LPFC_SLI_REV3)
5081 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5083 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5085 mbox->vport = vport;
5086 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5087 mbox->ctx_ndlp = NULL;
5088 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5089 if (rc != MBX_TIMEOUT)
5090 mempool_free(mbox, phba->mbox_mem_pool);
5092 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5093 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5094 "1815 Could not issue "
5095 "unreg_did (default rpis) status %d\n",
5101 * Free resources associated with LPFC_NODELIST entry
5102 * so it can be freed.
5105 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5107 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5108 struct lpfc_hba *phba = vport->phba;
5109 LPFC_MBOXQ_t *mb, *nextmb;
5110 struct lpfc_dmabuf *mp;
5111 unsigned long iflags;
5113 /* Cleanup node for NPort <nlp_DID> */
5114 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5115 "0900 Cleanup node for NPort x%x "
5116 "Data: x%x x%x x%x\n",
5117 ndlp->nlp_DID, ndlp->nlp_flag,
5118 ndlp->nlp_state, ndlp->nlp_rpi);
5119 if (NLP_CHK_FREE_REQ(ndlp)) {
5120 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5121 "0280 %s: ndlp:x%px "
5122 "usgmap:x%x refcnt:%d\n",
5123 __func__, (void *)ndlp, ndlp->nlp_usg_map,
5124 kref_read(&ndlp->kref));
5125 lpfc_dequeue_node(vport, ndlp);
5127 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5128 "0281 %s: ndlp:x%px "
5129 "usgmap:x%x refcnt:%d\n",
5130 __func__, (void *)ndlp, ndlp->nlp_usg_map,
5131 kref_read(&ndlp->kref));
5132 lpfc_disable_node(vport, ndlp);
5136 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5138 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5139 if ((mb = phba->sli.mbox_active)) {
5140 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5141 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5142 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5143 mb->ctx_ndlp = NULL;
5144 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5148 spin_lock_irq(&phba->hbalock);
5149 /* Cleanup REG_LOGIN completions which are not yet processed */
5150 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5151 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5152 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5153 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5156 mb->ctx_ndlp = NULL;
5157 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5160 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5161 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5162 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5163 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5164 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5166 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5169 list_del(&mb->list);
5170 mempool_free(mb, phba->mbox_mem_pool);
5171 /* We shall not invoke the lpfc_nlp_put to decrement
5172 * the ndlp reference count as we are in the process
5173 * of lpfc_nlp_release.
5177 spin_unlock_irq(&phba->hbalock);
5179 lpfc_els_abort(phba, ndlp);
5181 spin_lock_irq(shost->host_lock);
5182 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5183 spin_unlock_irq(shost->host_lock);
5185 ndlp->nlp_last_elscmd = 0;
5186 del_timer_sync(&ndlp->nlp_delayfunc);
5188 list_del_init(&ndlp->els_retry_evt.evt_listp);
5189 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5190 lpfc_cleanup_vports_rrqs(vport, ndlp);
5191 if (phba->sli_rev == LPFC_SLI_REV4)
5192 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5193 if (!lpfc_unreg_rpi(vport, ndlp)) {
5194 /* Clean up unregistered and non freed rpis */
5195 if ((ndlp->nlp_flag & NLP_RELEASE_RPI) &&
5196 !(ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)) {
5197 lpfc_sli4_free_rpi(vport->phba,
5199 spin_lock_irqsave(&vport->phba->ndlp_lock,
5201 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5202 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5203 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
5211 * Check to see if we can free the nlp back to the freelist.
5212 * If we are in the middle of using the nlp in the discovery state
5213 * machine, defer the free till we reach the end of the state machine.
5216 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5218 struct lpfc_hba *phba = vport->phba;
5219 struct lpfc_rport_data *rdata;
5220 struct fc_rport *rport;
5224 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5225 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
5226 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
5227 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5228 phba->sli_rev != LPFC_SLI_REV4) {
5229 /* For this case we need to cleanup the default rpi
5230 * allocated by the firmware.
5232 lpfc_printf_vlog(vport, KERN_INFO,
5233 LOG_NODE | LOG_DISCOVERY,
5234 "0005 Cleanup Default rpi:x%x DID:x%x flg:x%x "
5235 "ref %d map:x%x ndlp x%px\n",
5236 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5237 kref_read(&ndlp->kref),
5238 ndlp->nlp_usg_map, ndlp);
5239 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5241 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
5242 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
5244 mempool_free(mbox, phba->mbox_mem_pool);
5247 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5248 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5249 mbox->vport = vport;
5250 mbox->ctx_ndlp = ndlp;
5251 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5252 if (rc == MBX_NOT_FINISHED) {
5253 mempool_free(mbox, phba->mbox_mem_pool);
5258 lpfc_cleanup_node(vport, ndlp);
5261 * ndlp->rport must be set to NULL before it reaches here
5262 * i.e. break rport/node link before doing lpfc_nlp_put for
5263 * registered rport and then drop the reference of rport.
5267 * extra lpfc_nlp_put dropped the reference of ndlp
5268 * for registered rport so need to cleanup rport
5270 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5271 "0940 removed node x%px DID x%x "
5272 "rpi %d rport not null x%px\n",
5273 ndlp, ndlp->nlp_DID, ndlp->nlp_rpi,
5275 rport = ndlp->rport;
5276 rdata = rport->dd_data;
5277 rdata->pnode = NULL;
5279 put_device(&rport->dev);
5284 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5287 D_ID mydid, ndlpdid, matchdid;
5289 if (did == Bcast_DID)
5292 /* First check for Direct match */
5293 if (ndlp->nlp_DID == did)
5296 /* Next check for area/domain identically equals 0 match */
5297 mydid.un.word = vport->fc_myDID;
5298 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5302 matchdid.un.word = did;
5303 ndlpdid.un.word = ndlp->nlp_DID;
5304 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5305 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5306 (mydid.un.b.area == matchdid.un.b.area)) {
5307 /* This code is supposed to match the ID
5308 * for a private loop device that is
5309 * connect to fl_port. But we need to
5310 * check that the port did not just go
5311 * from pt2pt to fabric or we could end
5312 * up matching ndlp->nlp_DID 000001 to
5313 * fabric DID 0x20101
5315 if ((ndlpdid.un.b.domain == 0) &&
5316 (ndlpdid.un.b.area == 0)) {
5317 if (ndlpdid.un.b.id &&
5318 vport->phba->fc_topology ==
5325 matchdid.un.word = ndlp->nlp_DID;
5326 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5327 (mydid.un.b.area == ndlpdid.un.b.area)) {
5328 if ((matchdid.un.b.domain == 0) &&
5329 (matchdid.un.b.area == 0)) {
5330 if (matchdid.un.b.id)
5338 /* Search for a nodelist entry */
5339 static struct lpfc_nodelist *
5340 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5342 struct lpfc_nodelist *ndlp;
5345 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5346 if (lpfc_matchdid(vport, ndlp, did)) {
5347 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5348 ((uint32_t)ndlp->nlp_xri << 16) |
5349 ((uint32_t)ndlp->nlp_type << 8) |
5350 ((uint32_t)ndlp->nlp_usg_map & 0xff));
5351 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5352 "0929 FIND node DID "
5353 "Data: x%px x%x x%x x%x x%x x%px\n",
5354 ndlp, ndlp->nlp_DID,
5355 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5356 ndlp->active_rrqs_xri_bitmap);
5361 /* FIND node did <did> NOT FOUND */
5362 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5363 "0932 FIND node did x%x NOT FOUND.\n", did);
5367 struct lpfc_nodelist *
5368 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5370 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5371 struct lpfc_nodelist *ndlp;
5372 unsigned long iflags;
5374 spin_lock_irqsave(shost->host_lock, iflags);
5375 ndlp = __lpfc_findnode_did(vport, did);
5376 spin_unlock_irqrestore(shost->host_lock, iflags);
5380 struct lpfc_nodelist *
5381 lpfc_findnode_mapped(struct lpfc_vport *vport)
5383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5384 struct lpfc_nodelist *ndlp;
5386 unsigned long iflags;
5388 spin_lock_irqsave(shost->host_lock, iflags);
5390 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5391 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5392 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5393 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5394 ((uint32_t)ndlp->nlp_xri << 16) |
5395 ((uint32_t)ndlp->nlp_type << 8) |
5396 ((uint32_t)ndlp->nlp_rpi & 0xff));
5397 spin_unlock_irqrestore(shost->host_lock, iflags);
5398 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5399 "2025 FIND node DID "
5400 "Data: x%px x%x x%x x%x x%px\n",
5401 ndlp, ndlp->nlp_DID,
5402 ndlp->nlp_flag, data1,
5403 ndlp->active_rrqs_xri_bitmap);
5407 spin_unlock_irqrestore(shost->host_lock, iflags);
5409 /* FIND node did <did> NOT FOUND */
5410 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5411 "2026 FIND mapped did NOT FOUND.\n");
5415 struct lpfc_nodelist *
5416 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5419 struct lpfc_nodelist *ndlp;
5421 ndlp = lpfc_findnode_did(vport, did);
5423 if (vport->phba->nvmet_support)
5425 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5426 lpfc_rscn_payload_check(vport, did) == 0)
5428 ndlp = lpfc_nlp_init(vport, did);
5431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5433 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5434 "6453 Setup New Node 2B_DISC x%x "
5435 "Data:x%x x%x x%x\n",
5436 ndlp->nlp_DID, ndlp->nlp_flag,
5437 ndlp->nlp_state, vport->fc_flag);
5439 spin_lock_irq(shost->host_lock);
5440 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5441 spin_unlock_irq(shost->host_lock);
5443 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5444 if (vport->phba->nvmet_support)
5446 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
5448 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
5449 "0014 Could not enable ndlp\n");
5452 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5453 "6454 Setup Enabled Node 2B_DISC x%x "
5454 "Data:x%x x%x x%x\n",
5455 ndlp->nlp_DID, ndlp->nlp_flag,
5456 ndlp->nlp_state, vport->fc_flag);
5458 spin_lock_irq(shost->host_lock);
5459 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5460 spin_unlock_irq(shost->host_lock);
5464 /* The NVME Target does not want to actively manage an rport.
5465 * The goal is to allow the target to reset its state and clear
5466 * pending IO in preparation for the initiator to recover.
5468 if ((vport->fc_flag & FC_RSCN_MODE) &&
5469 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5470 if (lpfc_rscn_payload_check(vport, did)) {
5472 /* Since this node is marked for discovery,
5473 * delay timeout is not needed.
5475 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5477 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5478 "6455 Setup RSCN Node 2B_DISC x%x "
5479 "Data:x%x x%x x%x\n",
5480 ndlp->nlp_DID, ndlp->nlp_flag,
5481 ndlp->nlp_state, vport->fc_flag);
5483 /* NVME Target mode waits until rport is known to be
5484 * impacted by the RSCN before it transitions. No
5485 * active management - just go to NPR provided the
5486 * node had a valid login.
5488 if (vport->phba->nvmet_support)
5491 /* If we've already received a PLOGI from this NPort
5492 * we don't need to try to discover it again.
5494 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5496 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5499 ndlp->nlp_prev_state = ndlp->nlp_state;
5500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5502 spin_lock_irq(shost->host_lock);
5503 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5504 spin_unlock_irq(shost->host_lock);
5506 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5507 "6456 Skip Setup RSCN Node x%x "
5508 "Data:x%x x%x x%x\n",
5509 ndlp->nlp_DID, ndlp->nlp_flag,
5510 ndlp->nlp_state, vport->fc_flag);
5514 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5515 "6457 Setup Active Node 2B_DISC x%x "
5516 "Data:x%x x%x x%x\n",
5517 ndlp->nlp_DID, ndlp->nlp_flag,
5518 ndlp->nlp_state, vport->fc_flag);
5520 /* If the initiator received a PLOGI from this NPort or if the
5521 * initiator is already in the process of discovery on it,
5522 * there's no need to try to discover it again.
5524 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5525 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5526 (!vport->phba->nvmet_support &&
5527 ndlp->nlp_flag & NLP_RCV_PLOGI))
5530 if (vport->phba->nvmet_support)
5533 /* Moving to NPR state clears unsolicited flags and
5534 * allows for rediscovery
5536 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5538 spin_lock_irq(shost->host_lock);
5539 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5540 spin_unlock_irq(shost->host_lock);
5545 /* Build a list of nodes to discover based on the loopmap */
5547 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5549 struct lpfc_hba *phba = vport->phba;
5551 uint32_t alpa, index;
5553 if (!lpfc_is_link_up(phba))
5556 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5559 /* Check for loop map present or not */
5560 if (phba->alpa_map[0]) {
5561 for (j = 1; j <= phba->alpa_map[0]; j++) {
5562 alpa = phba->alpa_map[j];
5563 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5565 lpfc_setup_disc_node(vport, alpa);
5568 /* No alpamap, so try all alpa's */
5569 for (j = 0; j < FC_MAXLOOP; j++) {
5570 /* If cfg_scan_down is set, start from highest
5571 * ALPA (0xef) to lowest (0x1).
5573 if (vport->cfg_scan_down)
5576 index = FC_MAXLOOP - j - 1;
5577 alpa = lpfcAlpaArray[index];
5578 if ((vport->fc_myDID & 0xff) == alpa)
5580 lpfc_setup_disc_node(vport, alpa);
5588 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5591 struct lpfc_sli *psli = &phba->sli;
5592 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5593 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5597 * if it's not a physical port or if we already send
5598 * clear_la then don't send it.
5600 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5601 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5602 (phba->sli_rev == LPFC_SLI_REV4))
5605 /* Link up discovery */
5606 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5607 phba->link_state = LPFC_CLEAR_LA;
5608 lpfc_clear_la(phba, mbox);
5609 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5610 mbox->vport = vport;
5611 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5612 if (rc == MBX_NOT_FINISHED) {
5613 mempool_free(mbox, phba->mbox_mem_pool);
5614 lpfc_disc_flush_list(vport);
5615 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5616 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5617 phba->link_state = LPFC_HBA_ERROR;
5622 /* Reg_vpi to tell firmware to resume normal operations */
5624 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5626 LPFC_MBOXQ_t *regvpimbox;
5628 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5630 lpfc_reg_vpi(vport, regvpimbox);
5631 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5632 regvpimbox->vport = vport;
5633 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5634 == MBX_NOT_FINISHED) {
5635 mempool_free(regvpimbox, phba->mbox_mem_pool);
5640 /* Start Link up / RSCN discovery on NPR nodes */
5642 lpfc_disc_start(struct lpfc_vport *vport)
5644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5645 struct lpfc_hba *phba = vport->phba;
5647 uint32_t clear_la_pending;
5649 if (!lpfc_is_link_up(phba)) {
5650 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5651 "3315 Link is not up %x\n",
5656 if (phba->link_state == LPFC_CLEAR_LA)
5657 clear_la_pending = 1;
5659 clear_la_pending = 0;
5661 if (vport->port_state < LPFC_VPORT_READY)
5662 vport->port_state = LPFC_DISC_AUTH;
5664 lpfc_set_disctmo(vport);
5666 vport->fc_prevDID = vport->fc_myDID;
5667 vport->num_disc_nodes = 0;
5669 /* Start Discovery state <hba_state> */
5670 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5671 "0202 Start Discovery port state x%x "
5672 "flg x%x Data: x%x x%x x%x\n",
5673 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5674 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5676 /* First do ADISCs - if any */
5677 num_sent = lpfc_els_disc_adisc(vport);
5682 /* Register the VPI for SLI3, NPIV only. */
5683 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5684 !(vport->fc_flag & FC_PT2PT) &&
5685 !(vport->fc_flag & FC_RSCN_MODE) &&
5686 (phba->sli_rev < LPFC_SLI_REV4)) {
5687 lpfc_issue_clear_la(phba, vport);
5688 lpfc_issue_reg_vpi(phba, vport);
5693 * For SLI2, we need to set port_state to READY and continue
5696 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5697 /* If we get here, there is nothing to ADISC */
5698 lpfc_issue_clear_la(phba, vport);
5700 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5701 vport->num_disc_nodes = 0;
5702 /* go thru NPR nodes and issue ELS PLOGIs */
5703 if (vport->fc_npr_cnt)
5704 lpfc_els_disc_plogi(vport);
5706 if (!vport->num_disc_nodes) {
5707 spin_lock_irq(shost->host_lock);
5708 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5709 spin_unlock_irq(shost->host_lock);
5710 lpfc_can_disctmo(vport);
5713 vport->port_state = LPFC_VPORT_READY;
5715 /* Next do PLOGIs - if any */
5716 num_sent = lpfc_els_disc_plogi(vport);
5721 if (vport->fc_flag & FC_RSCN_MODE) {
5722 /* Check to see if more RSCNs came in while we
5723 * were processing this one.
5725 if ((vport->fc_rscn_id_cnt == 0) &&
5726 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5727 spin_lock_irq(shost->host_lock);
5728 vport->fc_flag &= ~FC_RSCN_MODE;
5729 spin_unlock_irq(shost->host_lock);
5730 lpfc_can_disctmo(vport);
5732 lpfc_els_handle_rscn(vport);
5739 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5740 * ring the match the sppecified nodelist.
5743 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5745 LIST_HEAD(completions);
5747 struct lpfc_iocbq *iocb, *next_iocb;
5748 struct lpfc_sli_ring *pring;
5750 pring = lpfc_phba_elsring(phba);
5751 if (unlikely(!pring))
5754 /* Error matching iocb on txq or txcmplq
5755 * First check the txq.
5757 spin_lock_irq(&phba->hbalock);
5758 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5759 if (iocb->context1 != ndlp) {
5763 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5764 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5766 list_move_tail(&iocb->list, &completions);
5770 /* Next check the txcmplq */
5771 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5772 if (iocb->context1 != ndlp) {
5776 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5777 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5778 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
5781 spin_unlock_irq(&phba->hbalock);
5783 /* Cancel all the IOCBs from the completions list */
5784 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5789 lpfc_disc_flush_list(struct lpfc_vport *vport)
5791 struct lpfc_nodelist *ndlp, *next_ndlp;
5792 struct lpfc_hba *phba = vport->phba;
5794 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5795 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5797 if (!NLP_CHK_NODE_ACT(ndlp))
5799 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5800 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5801 lpfc_free_tx(phba, ndlp);
5808 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5810 lpfc_els_flush_rscn(vport);
5811 lpfc_els_flush_cmd(vport);
5812 lpfc_disc_flush_list(vport);
5815 /*****************************************************************************/
5817 * NAME: lpfc_disc_timeout
5819 * FUNCTION: Fibre Channel driver discovery timeout routine.
5821 * EXECUTION ENVIRONMENT: interrupt only
5829 /*****************************************************************************/
5831 lpfc_disc_timeout(struct timer_list *t)
5833 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
5834 struct lpfc_hba *phba = vport->phba;
5835 uint32_t tmo_posted;
5836 unsigned long flags = 0;
5838 if (unlikely(!phba))
5841 spin_lock_irqsave(&vport->work_port_lock, flags);
5842 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5844 vport->work_port_events |= WORKER_DISC_TMO;
5845 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5848 lpfc_worker_wake_up(phba);
5853 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5856 struct lpfc_hba *phba = vport->phba;
5857 struct lpfc_sli *psli = &phba->sli;
5858 struct lpfc_nodelist *ndlp, *next_ndlp;
5859 LPFC_MBOXQ_t *initlinkmbox;
5860 int rc, clrlaerr = 0;
5862 if (!(vport->fc_flag & FC_DISC_TMO))
5865 spin_lock_irq(shost->host_lock);
5866 vport->fc_flag &= ~FC_DISC_TMO;
5867 spin_unlock_irq(shost->host_lock);
5869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5870 "disc timeout: state:x%x rtry:x%x flg:x%x",
5871 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5873 switch (vport->port_state) {
5875 case LPFC_LOCAL_CFG_LINK:
5877 * port_state is identically LPFC_LOCAL_CFG_LINK while
5878 * waiting for FAN timeout
5880 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5881 "0221 FAN timeout\n");
5883 /* Start discovery by sending FLOGI, clean up old rpis */
5884 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5886 if (!NLP_CHK_NODE_ACT(ndlp))
5888 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5890 if (ndlp->nlp_type & NLP_FABRIC) {
5891 /* Clean up the ndlp on Fabric connections */
5892 lpfc_drop_node(vport, ndlp);
5894 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5895 /* Fail outstanding IO now since device
5896 * is marked for PLOGI.
5898 lpfc_unreg_rpi(vport, ndlp);
5901 if (vport->port_state != LPFC_FLOGI) {
5902 if (phba->sli_rev <= LPFC_SLI_REV3)
5903 lpfc_initial_flogi(vport);
5905 lpfc_issue_init_vfi(vport);
5912 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5913 /* Initial FLOGI timeout */
5914 lpfc_printf_vlog(vport, KERN_ERR,
5916 "0222 Initial %s timeout\n",
5917 vport->vpi ? "FDISC" : "FLOGI");
5919 /* Assume no Fabric and go on with discovery.
5920 * Check for outstanding ELS FLOGI to abort.
5923 /* FLOGI failed, so just use loop map to make discovery list */
5924 lpfc_disc_list_loopmap(vport);
5926 /* Start discovery */
5927 lpfc_disc_start(vport);
5930 case LPFC_FABRIC_CFG_LINK:
5931 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5933 lpfc_printf_vlog(vport, KERN_ERR,
5935 "0223 Timeout while waiting for "
5936 "NameServer login\n");
5937 /* Next look for NameServer ndlp */
5938 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5939 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5940 lpfc_els_abort(phba, ndlp);
5942 /* ReStart discovery */
5946 /* Check for wait for NameServer Rsp timeout */
5947 lpfc_printf_vlog(vport, KERN_ERR,
5949 "0224 NameServer Query timeout "
5951 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5953 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5954 /* Try it one more time */
5955 vport->fc_ns_retry++;
5956 vport->gidft_inp = 0;
5957 rc = lpfc_issue_gidft(vport);
5961 vport->fc_ns_retry = 0;
5965 * Discovery is over.
5966 * set port_state to PORT_READY if SLI2.
5967 * cmpl_reg_vpi will set port_state to READY for SLI3.
5969 if (phba->sli_rev < LPFC_SLI_REV4) {
5970 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5971 lpfc_issue_reg_vpi(phba, vport);
5973 lpfc_issue_clear_la(phba, vport);
5974 vport->port_state = LPFC_VPORT_READY;
5978 /* Setup and issue mailbox INITIALIZE LINK command */
5979 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5980 if (!initlinkmbox) {
5981 lpfc_printf_vlog(vport, KERN_ERR,
5983 "0206 Device Discovery "
5984 "completion error\n");
5985 phba->link_state = LPFC_HBA_ERROR;
5989 lpfc_linkdown(phba);
5990 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5991 phba->cfg_link_speed);
5992 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5993 initlinkmbox->vport = vport;
5994 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5995 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5996 lpfc_set_loopback_flag(phba);
5997 if (rc == MBX_NOT_FINISHED)
5998 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6002 case LPFC_DISC_AUTH:
6003 /* Node Authentication timeout */
6004 lpfc_printf_vlog(vport, KERN_ERR,
6006 "0227 Node Authentication timeout\n");
6007 lpfc_disc_flush_list(vport);
6010 * set port_state to PORT_READY if SLI2.
6011 * cmpl_reg_vpi will set port_state to READY for SLI3.
6013 if (phba->sli_rev < LPFC_SLI_REV4) {
6014 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6015 lpfc_issue_reg_vpi(phba, vport);
6016 else { /* NPIV Not enabled */
6017 lpfc_issue_clear_la(phba, vport);
6018 vport->port_state = LPFC_VPORT_READY;
6023 case LPFC_VPORT_READY:
6024 if (vport->fc_flag & FC_RSCN_MODE) {
6025 lpfc_printf_vlog(vport, KERN_ERR,
6027 "0231 RSCN timeout Data: x%x "
6029 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6031 /* Cleanup any outstanding ELS commands */
6032 lpfc_els_flush_cmd(vport);
6034 lpfc_els_flush_rscn(vport);
6035 lpfc_disc_flush_list(vport);
6040 lpfc_printf_vlog(vport, KERN_ERR,
6042 "0273 Unexpected discovery timeout, "
6043 "vport State x%x\n", vport->port_state);
6047 switch (phba->link_state) {
6049 /* CLEAR LA timeout */
6050 lpfc_printf_vlog(vport, KERN_ERR,
6052 "0228 CLEAR LA timeout\n");
6057 lpfc_issue_clear_la(phba, vport);
6059 case LPFC_LINK_UNKNOWN:
6060 case LPFC_WARM_START:
6061 case LPFC_INIT_START:
6062 case LPFC_INIT_MBX_CMDS:
6063 case LPFC_LINK_DOWN:
6064 case LPFC_HBA_ERROR:
6065 lpfc_printf_vlog(vport, KERN_ERR,
6067 "0230 Unexpected timeout, hba link "
6068 "state x%x\n", phba->link_state);
6072 case LPFC_HBA_READY:
6077 lpfc_disc_flush_list(vport);
6078 if (phba->sli_rev != LPFC_SLI_REV4) {
6079 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6080 ~LPFC_STOP_IOCB_EVENT;
6081 psli->sli3_ring[LPFC_FCP_RING].flag &=
6082 ~LPFC_STOP_IOCB_EVENT;
6084 vport->port_state = LPFC_VPORT_READY;
6090 * This routine handles processing a NameServer REG_LOGIN mailbox
6091 * command upon completion. It is setup in the LPFC_MBOXQ
6092 * as the completion routine when the command is
6093 * handed off to the SLI layer.
6096 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6098 MAILBOX_t *mb = &pmb->u.mb;
6099 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6100 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6101 struct lpfc_vport *vport = pmb->vport;
6103 pmb->ctx_buf = NULL;
6104 pmb->ctx_ndlp = NULL;
6106 if (phba->sli_rev < LPFC_SLI_REV4)
6107 ndlp->nlp_rpi = mb->un.varWords[0];
6108 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6109 ndlp->nlp_type |= NLP_FABRIC;
6110 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6111 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6112 "0004 rpi:%x DID:%x flg:%x %d map:%x x%px\n",
6113 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6114 kref_read(&ndlp->kref),
6115 ndlp->nlp_usg_map, ndlp);
6117 * Start issuing Fabric-Device Management Interface (FDMI) command to
6118 * 0xfffffa (FDMI well known port).
6119 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6120 * DPRT -> RPRT (vports)
6122 if (vport->port_type == LPFC_PHYSICAL_PORT)
6123 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6125 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6128 /* decrement the node reference count held for this callback
6132 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6134 mempool_free(pmb, phba->mbox_mem_pool);
6140 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6142 uint16_t *rpi = param;
6144 /* check for active node */
6145 if (!NLP_CHK_NODE_ACT(ndlp))
6148 return ndlp->nlp_rpi == *rpi;
6152 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6154 return memcmp(&ndlp->nlp_portname, param,
6155 sizeof(ndlp->nlp_portname)) == 0;
6158 static struct lpfc_nodelist *
6159 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6161 struct lpfc_nodelist *ndlp;
6163 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6164 if (filter(ndlp, param)) {
6165 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6166 "3185 FIND node filter %ps DID "
6167 "ndlp x%px did x%x flg x%x st x%x "
6168 "xri x%x type x%x rpi x%x\n",
6169 filter, ndlp, ndlp->nlp_DID,
6170 ndlp->nlp_flag, ndlp->nlp_state,
6171 ndlp->nlp_xri, ndlp->nlp_type,
6176 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6177 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6182 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6183 * returns the node list element pointer else return NULL.
6185 struct lpfc_nodelist *
6186 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6188 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6192 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6193 * returns the node element list pointer else return NULL.
6195 struct lpfc_nodelist *
6196 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6198 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6199 struct lpfc_nodelist *ndlp;
6201 spin_lock_irq(shost->host_lock);
6202 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6203 spin_unlock_irq(shost->host_lock);
6208 * This routine looks up the ndlp lists for the given RPI. If the rpi
6209 * is found, the routine returns the node element list pointer else
6212 struct lpfc_nodelist *
6213 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6215 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6216 struct lpfc_nodelist *ndlp;
6217 unsigned long flags;
6219 spin_lock_irqsave(shost->host_lock, flags);
6220 ndlp = __lpfc_findnode_rpi(vport, rpi);
6221 spin_unlock_irqrestore(shost->host_lock, flags);
6226 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6227 * @phba: pointer to lpfc hba data structure.
6228 * @vpi: the physical host virtual N_Port identifier.
6230 * This routine finds a vport on a HBA (referred by @phba) through a
6231 * @vpi. The function walks the HBA's vport list and returns the address
6232 * of the vport with the matching @vpi.
6235 * NULL - No vport with the matching @vpi found
6236 * Otherwise - Address to the vport with the matching @vpi.
6239 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6241 struct lpfc_vport *vport;
6242 unsigned long flags;
6245 /* The physical ports are always vpi 0 - translate is unnecessary. */
6248 * Translate the physical vpi to the logical vpi. The
6249 * vport stores the logical vpi.
6251 for (i = 0; i < phba->max_vpi; i++) {
6252 if (vpi == phba->vpi_ids[i])
6256 if (i >= phba->max_vpi) {
6257 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6258 "2936 Could not find Vport mapped "
6259 "to vpi %d\n", vpi);
6264 spin_lock_irqsave(&phba->port_list_lock, flags);
6265 list_for_each_entry(vport, &phba->port_list, listentry) {
6266 if (vport->vpi == i) {
6267 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6271 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6275 struct lpfc_nodelist *
6276 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6278 struct lpfc_nodelist *ndlp;
6279 int rpi = LPFC_RPI_ALLOC_ERROR;
6281 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6282 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6283 if (rpi == LPFC_RPI_ALLOC_ERROR)
6287 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6289 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6290 lpfc_sli4_free_rpi(vport->phba, rpi);
6294 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6296 lpfc_initialize_node(vport, ndlp, did);
6297 INIT_LIST_HEAD(&ndlp->nlp_listp);
6298 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6299 ndlp->nlp_rpi = rpi;
6300 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6301 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6302 "flg:x%x refcnt:%d map:x%x\n",
6303 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6304 ndlp->nlp_flag, kref_read(&ndlp->kref),
6307 ndlp->active_rrqs_xri_bitmap =
6308 mempool_alloc(vport->phba->active_rrq_pool,
6310 if (ndlp->active_rrqs_xri_bitmap)
6311 memset(ndlp->active_rrqs_xri_bitmap, 0,
6312 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6317 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6318 "node init: did:x%x",
6319 ndlp->nlp_DID, 0, 0);
6324 /* This routine releases all resources associated with a specifc NPort's ndlp
6325 * and mempool_free's the nodelist.
6328 lpfc_nlp_release(struct kref *kref)
6330 struct lpfc_hba *phba;
6331 unsigned long flags;
6332 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6335 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6336 "node release: did:x%x flg:x%x type:x%x",
6337 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6339 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
6340 "0279 %s: ndlp:x%px did %x "
6341 "usgmap:x%x refcnt:%d rpi:%x\n",
6343 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
6344 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6346 /* remove ndlp from action. */
6347 lpfc_nlp_remove(ndlp->vport, ndlp);
6349 /* clear the ndlp active flag for all release cases */
6351 spin_lock_irqsave(&phba->ndlp_lock, flags);
6352 NLP_CLR_NODE_ACT(ndlp);
6353 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6355 /* free ndlp memory for final ndlp release */
6356 if (NLP_CHK_FREE_REQ(ndlp)) {
6357 kfree(ndlp->lat_data);
6358 if (phba->sli_rev == LPFC_SLI_REV4)
6359 mempool_free(ndlp->active_rrqs_xri_bitmap,
6360 ndlp->phba->active_rrq_pool);
6361 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6365 /* This routine bumps the reference count for a ndlp structure to ensure
6366 * that one discovery thread won't free a ndlp while another discovery thread
6369 struct lpfc_nodelist *
6370 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6372 struct lpfc_hba *phba;
6373 unsigned long flags;
6376 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6377 "node get: did:x%x flg:x%x refcnt:x%x",
6378 ndlp->nlp_DID, ndlp->nlp_flag,
6379 kref_read(&ndlp->kref));
6380 /* The check of ndlp usage to prevent incrementing the
6381 * ndlp reference count that is in the process of being
6385 spin_lock_irqsave(&phba->ndlp_lock, flags);
6386 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
6387 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6388 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6389 "0276 %s: ndlp:x%px "
6390 "usgmap:x%x refcnt:%d\n",
6391 __func__, (void *)ndlp, ndlp->nlp_usg_map,
6392 kref_read(&ndlp->kref));
6395 kref_get(&ndlp->kref);
6396 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6401 /* This routine decrements the reference count for a ndlp structure. If the
6402 * count goes to 0, this indicates the the associated nodelist should be
6403 * freed. Returning 1 indicates the ndlp resource has been released; on the
6404 * other hand, returning 0 indicates the ndlp resource has not been released
6408 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6410 struct lpfc_hba *phba;
6411 unsigned long flags;
6416 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6417 "node put: did:x%x flg:x%x refcnt:x%x",
6418 ndlp->nlp_DID, ndlp->nlp_flag,
6419 kref_read(&ndlp->kref));
6421 spin_lock_irqsave(&phba->ndlp_lock, flags);
6422 /* Check the ndlp memory free acknowledge flag to avoid the
6423 * possible race condition that kref_put got invoked again
6424 * after previous one has done ndlp memory free.
6426 if (NLP_CHK_FREE_ACK(ndlp)) {
6427 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6428 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6429 "0274 %s: ndlp:x%px "
6430 "usgmap:x%x refcnt:%d\n",
6431 __func__, (void *)ndlp, ndlp->nlp_usg_map,
6432 kref_read(&ndlp->kref));
6435 /* Check the ndlp inactivate log flag to avoid the possible
6436 * race condition that kref_put got invoked again after ndlp
6437 * is already in inactivating state.
6439 if (NLP_CHK_IACT_REQ(ndlp)) {
6440 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6441 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6442 "0275 %s: ndlp:x%px "
6443 "usgmap:x%x refcnt:%d\n",
6444 __func__, (void *)ndlp, ndlp->nlp_usg_map,
6445 kref_read(&ndlp->kref));
6448 /* For last put, mark the ndlp usage flags to make sure no
6449 * other kref_get and kref_put on the same ndlp shall get
6450 * in between the process when the final kref_put has been
6451 * invoked on this ndlp.
6453 if (kref_read(&ndlp->kref) == 1) {
6454 /* Indicate ndlp is put to inactive state. */
6455 NLP_SET_IACT_REQ(ndlp);
6456 /* Acknowledge ndlp memory free has been seen. */
6457 if (NLP_CHK_FREE_REQ(ndlp))
6458 NLP_SET_FREE_ACK(ndlp);
6460 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6461 /* Note, the kref_put returns 1 when decrementing a reference
6462 * count that was 1, it invokes the release callback function,
6463 * but it still left the reference count as 1 (not actually
6464 * performs the last decrementation). Otherwise, it actually
6465 * decrements the reference count and returns 0.
6467 return kref_put(&ndlp->kref, lpfc_nlp_release);
6470 /* This routine free's the specified nodelist if it is not in use
6471 * by any other discovery thread. This routine returns 1 if the
6472 * ndlp has been freed. A return value of 0 indicates the ndlp is
6473 * not yet been released.
6476 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6478 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6479 "node not used: did:x%x flg:x%x refcnt:x%x",
6480 ndlp->nlp_DID, ndlp->nlp_flag,
6481 kref_read(&ndlp->kref));
6482 if (kref_read(&ndlp->kref) == 1)
6483 if (lpfc_nlp_put(ndlp))
6489 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6490 * @phba: Pointer to hba context object.
6492 * This function iterate through all FC nodes associated
6493 * will all vports to check if there is any node with
6494 * fc_rports associated with it. If there is an fc_rport
6495 * associated with the node, then the node is either in
6496 * discovered state or its devloss_timer is pending.
6499 lpfc_fcf_inuse(struct lpfc_hba *phba)
6501 struct lpfc_vport **vports;
6503 struct lpfc_nodelist *ndlp;
6504 struct Scsi_Host *shost;
6506 vports = lpfc_create_vport_work_array(phba);
6508 /* If driver cannot allocate memory, indicate fcf is in use */
6512 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6513 shost = lpfc_shost_from_vport(vports[i]);
6514 spin_lock_irq(shost->host_lock);
6516 * IF the CVL_RCVD bit is not set then we have sent the
6518 * If dev_loss fires while we are waiting we do not want to
6521 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6522 spin_unlock_irq(shost->host_lock);
6526 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6527 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6528 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6530 spin_unlock_irq(shost->host_lock);
6532 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6534 lpfc_printf_log(phba, KERN_INFO,
6535 LOG_NODE | LOG_DISCOVERY,
6536 "2624 RPI %x DID %x flag %x "
6537 "still logged in\n",
6538 ndlp->nlp_rpi, ndlp->nlp_DID,
6542 spin_unlock_irq(shost->host_lock);
6545 lpfc_destroy_vport_work_array(phba, vports);
6550 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6551 * @phba: Pointer to hba context object.
6552 * @mboxq: Pointer to mailbox object.
6554 * This function frees memory associated with the mailbox command.
6557 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6559 struct lpfc_vport *vport = mboxq->vport;
6560 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6562 if (mboxq->u.mb.mbxStatus) {
6563 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6564 "2555 UNREG_VFI mbxStatus error x%x "
6566 mboxq->u.mb.mbxStatus, vport->port_state);
6568 spin_lock_irq(shost->host_lock);
6569 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6570 spin_unlock_irq(shost->host_lock);
6571 mempool_free(mboxq, phba->mbox_mem_pool);
6576 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6577 * @phba: Pointer to hba context object.
6578 * @mboxq: Pointer to mailbox object.
6580 * This function frees memory associated with the mailbox command.
6583 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6585 struct lpfc_vport *vport = mboxq->vport;
6587 if (mboxq->u.mb.mbxStatus) {
6588 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6589 "2550 UNREG_FCFI mbxStatus error x%x "
6591 mboxq->u.mb.mbxStatus, vport->port_state);
6593 mempool_free(mboxq, phba->mbox_mem_pool);
6598 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6599 * @phba: Pointer to hba context object.
6601 * This function prepare the HBA for unregistering the currently registered
6602 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6606 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6608 struct lpfc_vport **vports;
6609 struct lpfc_nodelist *ndlp;
6610 struct Scsi_Host *shost;
6613 /* Unregister RPIs */
6614 if (lpfc_fcf_inuse(phba))
6615 lpfc_unreg_hba_rpis(phba);
6617 /* At this point, all discovery is aborted */
6618 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6620 /* Unregister VPIs */
6621 vports = lpfc_create_vport_work_array(phba);
6622 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6623 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6624 /* Stop FLOGI/FDISC retries */
6625 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6627 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6628 lpfc_cleanup_pending_mbox(vports[i]);
6629 if (phba->sli_rev == LPFC_SLI_REV4)
6630 lpfc_sli4_unreg_all_rpis(vports[i]);
6631 lpfc_mbx_unreg_vpi(vports[i]);
6632 shost = lpfc_shost_from_vport(vports[i]);
6633 spin_lock_irq(shost->host_lock);
6634 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6635 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6636 spin_unlock_irq(shost->host_lock);
6638 lpfc_destroy_vport_work_array(phba, vports);
6639 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6640 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6642 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6643 lpfc_cleanup_pending_mbox(phba->pport);
6644 if (phba->sli_rev == LPFC_SLI_REV4)
6645 lpfc_sli4_unreg_all_rpis(phba->pport);
6646 lpfc_mbx_unreg_vpi(phba->pport);
6647 shost = lpfc_shost_from_vport(phba->pport);
6648 spin_lock_irq(shost->host_lock);
6649 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6650 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6651 spin_unlock_irq(shost->host_lock);
6654 /* Cleanup any outstanding ELS commands */
6655 lpfc_els_flush_all_cmd(phba);
6657 /* Unregister the physical port VFI */
6658 rc = lpfc_issue_unreg_vfi(phba->pport);
6663 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6664 * @phba: Pointer to hba context object.
6666 * This function issues synchronous unregister FCF mailbox command to HBA to
6667 * unregister the currently registered FCF record. The driver does not reset
6668 * the driver FCF usage state flags.
6670 * Return 0 if successfully issued, none-zero otherwise.
6673 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6678 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6680 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6681 "2551 UNREG_FCFI mbox allocation failed"
6682 "HBA state x%x\n", phba->pport->port_state);
6685 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6686 mbox->vport = phba->pport;
6687 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6688 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6690 if (rc == MBX_NOT_FINISHED) {
6691 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6692 "2552 Unregister FCFI command failed rc x%x "
6694 rc, phba->pport->port_state);
6701 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6702 * @phba: Pointer to hba context object.
6704 * This function unregisters the currently reigstered FCF. This function
6705 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6708 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6712 /* Preparation for unregistering fcf */
6713 rc = lpfc_unregister_fcf_prep(phba);
6715 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6716 "2748 Failed to prepare for unregistering "
6717 "HBA's FCF record: rc=%d\n", rc);
6721 /* Now, unregister FCF record and reset HBA FCF state */
6722 rc = lpfc_sli4_unregister_fcf(phba);
6725 /* Reset HBA FCF states after successful unregister FCF */
6726 phba->fcf.fcf_flag = 0;
6727 phba->fcf.current_rec.flag = 0;
6730 * If driver is not unloading, check if there is any other
6731 * FCF record that can be used for discovery.
6733 if ((phba->pport->load_flag & FC_UNLOADING) ||
6734 (phba->link_state < LPFC_LINK_UP))
6737 /* This is considered as the initial FCF discovery scan */
6738 spin_lock_irq(&phba->hbalock);
6739 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6740 spin_unlock_irq(&phba->hbalock);
6742 /* Reset FCF roundrobin bmask for new discovery */
6743 lpfc_sli4_clear_fcf_rr_bmask(phba);
6745 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6748 spin_lock_irq(&phba->hbalock);
6749 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6750 spin_unlock_irq(&phba->hbalock);
6751 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6752 "2553 lpfc_unregister_unused_fcf failed "
6753 "to read FCF record HBA state x%x\n",
6754 phba->pport->port_state);
6759 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6760 * @phba: Pointer to hba context object.
6762 * This function just unregisters the currently reigstered FCF. It does not
6763 * try to find another FCF for discovery.
6766 lpfc_unregister_fcf(struct lpfc_hba *phba)
6770 /* Preparation for unregistering fcf */
6771 rc = lpfc_unregister_fcf_prep(phba);
6773 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6774 "2749 Failed to prepare for unregistering "
6775 "HBA's FCF record: rc=%d\n", rc);
6779 /* Now, unregister FCF record and reset HBA FCF state */
6780 rc = lpfc_sli4_unregister_fcf(phba);
6783 /* Set proper HBA FCF states after successful unregister FCF */
6784 spin_lock_irq(&phba->hbalock);
6785 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6786 spin_unlock_irq(&phba->hbalock);
6790 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6791 * @phba: Pointer to hba context object.
6793 * This function check if there are any connected remote port for the FCF and
6794 * if all the devices are disconnected, this function unregister FCFI.
6795 * This function also tries to use another FCF for discovery.
6798 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6801 * If HBA is not running in FIP mode, if HBA does not support
6802 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6803 * registered, do nothing.
6805 spin_lock_irq(&phba->hbalock);
6806 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6807 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6808 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6809 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6810 (phba->pport->port_state == LPFC_FLOGI)) {
6811 spin_unlock_irq(&phba->hbalock);
6814 spin_unlock_irq(&phba->hbalock);
6816 if (lpfc_fcf_inuse(phba))
6819 lpfc_unregister_fcf_rescan(phba);
6823 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6824 * @phba: Pointer to hba context object.
6825 * @buff: Buffer containing the FCF connection table as in the config
6827 * This function create driver data structure for the FCF connection
6828 * record table read from config region 23.
6831 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6834 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6835 struct lpfc_fcf_conn_hdr *conn_hdr;
6836 struct lpfc_fcf_conn_rec *conn_rec;
6837 uint32_t record_count;
6840 /* Free the current connect table */
6841 list_for_each_entry_safe(conn_entry, next_conn_entry,
6842 &phba->fcf_conn_rec_list, list) {
6843 list_del_init(&conn_entry->list);
6847 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6848 record_count = conn_hdr->length * sizeof(uint32_t)/
6849 sizeof(struct lpfc_fcf_conn_rec);
6851 conn_rec = (struct lpfc_fcf_conn_rec *)
6852 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6854 for (i = 0; i < record_count; i++) {
6855 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6857 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6860 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6861 "2566 Failed to allocate connection"
6866 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6867 sizeof(struct lpfc_fcf_conn_rec));
6868 list_add_tail(&conn_entry->list,
6869 &phba->fcf_conn_rec_list);
6872 if (!list_empty(&phba->fcf_conn_rec_list)) {
6874 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6876 conn_rec = &conn_entry->conn_rec;
6877 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6878 "3345 FCF connection list rec[%02d]: "
6879 "flags:x%04x, vtag:x%04x, "
6880 "fabric_name:x%02x:%02x:%02x:%02x:"
6881 "%02x:%02x:%02x:%02x, "
6882 "switch_name:x%02x:%02x:%02x:%02x:"
6883 "%02x:%02x:%02x:%02x\n", i++,
6884 conn_rec->flags, conn_rec->vlan_tag,
6885 conn_rec->fabric_name[0],
6886 conn_rec->fabric_name[1],
6887 conn_rec->fabric_name[2],
6888 conn_rec->fabric_name[3],
6889 conn_rec->fabric_name[4],
6890 conn_rec->fabric_name[5],
6891 conn_rec->fabric_name[6],
6892 conn_rec->fabric_name[7],
6893 conn_rec->switch_name[0],
6894 conn_rec->switch_name[1],
6895 conn_rec->switch_name[2],
6896 conn_rec->switch_name[3],
6897 conn_rec->switch_name[4],
6898 conn_rec->switch_name[5],
6899 conn_rec->switch_name[6],
6900 conn_rec->switch_name[7]);
6906 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6907 * @phba: Pointer to hba context object.
6908 * @buff: Buffer containing the FCoE parameter data structure.
6910 * This function update driver data structure with config
6911 * parameters read from config region 23.
6914 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6917 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6918 struct lpfc_fcoe_params *fcoe_param;
6920 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6922 fcoe_param = (struct lpfc_fcoe_params *)
6923 (buff + sizeof(struct lpfc_fip_param_hdr));
6925 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6926 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6929 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6930 phba->valid_vlan = 1;
6931 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6935 phba->fc_map[0] = fcoe_param->fc_map[0];
6936 phba->fc_map[1] = fcoe_param->fc_map[1];
6937 phba->fc_map[2] = fcoe_param->fc_map[2];
6942 * lpfc_get_rec_conf23 - Get a record type in config region data.
6943 * @buff: Buffer containing config region 23 data.
6944 * @size: Size of the data buffer.
6945 * @rec_type: Record type to be searched.
6947 * This function searches config region data to find the beginning
6948 * of the record specified by record_type. If record found, this
6949 * function return pointer to the record else return NULL.
6952 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6954 uint32_t offset = 0, rec_length;
6956 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6957 (size < sizeof(uint32_t)))
6960 rec_length = buff[offset + 1];
6963 * One TLV record has one word header and number of data words
6964 * specified in the rec_length field of the record header.
6966 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6968 if (buff[offset] == rec_type)
6969 return &buff[offset];
6971 if (buff[offset] == LPFC_REGION23_LAST_REC)
6974 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6975 rec_length = buff[offset + 1];
6981 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6982 * @phba: Pointer to lpfc_hba data structure.
6983 * @buff: Buffer containing config region 23 data.
6984 * @size: Size of the data buffer.
6986 * This function parses the FCoE config parameters in config region 23 and
6987 * populate driver data structure with the parameters.
6990 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6994 uint32_t offset = 0;
6998 * If data size is less than 2 words signature and version cannot be
7001 if (size < 2*sizeof(uint32_t))
7004 /* Check the region signature first */
7005 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7006 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7007 "2567 Config region 23 has bad signature\n");
7013 /* Check the data structure version */
7014 if (buff[offset] != LPFC_REGION23_VERSION) {
7015 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7016 "2568 Config region 23 has bad version\n");
7021 /* Read FCoE param record */
7022 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7023 size - offset, FCOE_PARAM_TYPE);
7025 lpfc_read_fcoe_param(phba, rec_ptr);
7027 /* Read FCF connection table */
7028 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7029 size - offset, FCOE_CONN_TBL_TYPE);
7031 lpfc_read_fcf_conn_tbl(phba, rec_ptr);