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>
39 #include <linux/nvme-fc-driver.h>
44 #include "lpfc_disc.h"
46 #include "lpfc_sli4.h"
48 #include "lpfc_scsi.h"
49 #include "lpfc_nvme.h"
50 #include "lpfc_logmsg.h"
51 #include "lpfc_crtn.h"
52 #include "lpfc_vport.h"
53 #include "lpfc_debugfs.h"
55 /* AlpaArray for assignment of scsid for scan-down and bind_method */
56 static uint8_t lpfcAlpaArray[] = {
57 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
58 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
59 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
60 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
61 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
62 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
63 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
64 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
65 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
66 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
67 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
68 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
69 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
72 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
73 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
74 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
75 static int lpfc_fcf_inuse(struct lpfc_hba *);
78 lpfc_terminate_rport_io(struct fc_rport *rport)
80 struct lpfc_rport_data *rdata;
81 struct lpfc_nodelist * ndlp;
82 struct lpfc_hba *phba;
84 rdata = rport->dd_data;
87 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
88 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
89 printk(KERN_ERR "Cannot find remote node"
90 " to terminate I/O Data x%x\n",
97 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
98 "rport terminate: sid:x%x did:x%x flg:x%x",
99 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
101 if (ndlp->nlp_sid != NLP_NO_SID) {
102 lpfc_sli_abort_iocb(ndlp->vport,
103 &phba->sli.sli3_ring[LPFC_FCP_RING],
104 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
109 * This function will be called when dev_loss_tmo fire.
112 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
114 struct lpfc_rport_data *rdata;
115 struct lpfc_nodelist * ndlp;
116 struct lpfc_vport *vport;
117 struct Scsi_Host *shost;
118 struct lpfc_hba *phba;
119 struct lpfc_work_evt *evtp;
122 unsigned long iflags;
124 rdata = rport->dd_data;
126 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
133 "rport devlosscb: sid:x%x did:x%x flg:x%x",
134 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
136 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
137 "3181 dev_loss_callbk x%06x, rport x%px flg x%x\n",
138 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
140 /* Don't defer this if we are in the process of deleting the vport
141 * or unloading the driver. The unload will cleanup the node
142 * appropriately we just need to cleanup the ndlp rport info here.
144 if (vport->load_flag & FC_UNLOADING) {
145 put_node = rdata->pnode != NULL;
146 put_rport = ndlp->rport != NULL;
152 put_device(&rport->dev);
156 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
159 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
160 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
161 "6789 rport name %llx != node port name %llx",
163 wwn_to_u64(ndlp->nlp_portname.u.wwn));
165 evtp = &ndlp->dev_loss_evt;
167 if (!list_empty(&evtp->evt_listp)) {
168 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
169 "6790 rport name %llx dev_loss_evt pending",
174 shost = lpfc_shost_from_vport(vport);
175 spin_lock_irqsave(shost->host_lock, iflags);
176 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
177 spin_unlock_irqrestore(shost->host_lock, iflags);
179 /* We need to hold the node by incrementing the reference
180 * count until this queued work is done
182 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
184 spin_lock_irqsave(&phba->hbalock, iflags);
185 if (evtp->evt_arg1) {
186 evtp->evt = LPFC_EVT_DEV_LOSS;
187 list_add_tail(&evtp->evt_listp, &phba->work_list);
188 lpfc_worker_wake_up(phba);
190 spin_unlock_irqrestore(&phba->hbalock, iflags);
196 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
197 * @ndlp: Pointer to remote node object.
199 * This function is called from the worker thread when devloss timeout timer
200 * expires. For SLI4 host, this routine shall return 1 when at lease one
201 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
202 * routine shall return 0 when there is no remote node is still in use of FCF
203 * when devloss timeout happened to this @ndlp.
206 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
208 struct lpfc_rport_data *rdata;
209 struct fc_rport *rport;
210 struct lpfc_vport *vport;
211 struct lpfc_hba *phba;
212 struct Scsi_Host *shost;
217 unsigned long iflags;
221 shost = lpfc_shost_from_vport(vport);
223 spin_lock_irqsave(shost->host_lock, iflags);
224 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
225 spin_unlock_irqrestore(shost->host_lock, iflags);
230 name = (uint8_t *) &ndlp->nlp_portname;
233 if (phba->sli_rev == LPFC_SLI_REV4)
234 fcf_inuse = lpfc_fcf_inuse(phba);
236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
237 "rport devlosstmo:did:x%x type:x%x id:x%x",
238 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
240 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
241 "3182 dev_loss_tmo_handler x%06x, rport x%px flg x%x\n",
242 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
245 * lpfc_nlp_remove if reached with dangling rport drops the
246 * reference. To make sure that does not happen clear rport
247 * pointer in ndlp before lpfc_nlp_put.
249 rdata = rport->dd_data;
251 /* Don't defer this if we are in the process of deleting the vport
252 * or unloading the driver. The unload will cleanup the node
253 * appropriately we just need to cleanup the ndlp rport info here.
255 if (vport->load_flag & FC_UNLOADING) {
256 if (ndlp->nlp_sid != NLP_NO_SID) {
257 /* flush the target */
258 lpfc_sli_abort_iocb(vport,
259 &phba->sli.sli3_ring[LPFC_FCP_RING],
260 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
262 put_node = rdata->pnode != NULL;
267 put_device(&rport->dev);
272 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
273 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
274 "0284 Devloss timeout Ignored on "
275 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
277 *name, *(name+1), *(name+2), *(name+3),
278 *(name+4), *(name+5), *(name+6), *(name+7),
283 put_node = rdata->pnode != NULL;
288 put_device(&rport->dev);
290 if (ndlp->nlp_type & NLP_FABRIC)
293 if (ndlp->nlp_sid != NLP_NO_SID) {
295 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
296 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
300 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
301 "0203 Devloss timeout on "
302 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
303 "NPort x%06x Data: x%x x%x x%x\n",
304 *name, *(name+1), *(name+2), *(name+3),
305 *(name+4), *(name+5), *(name+6), *(name+7),
306 ndlp->nlp_DID, ndlp->nlp_flag,
307 ndlp->nlp_state, ndlp->nlp_rpi);
309 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
310 "0204 Devloss timeout on "
311 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
312 "NPort x%06x Data: x%x x%x x%x\n",
313 *name, *(name+1), *(name+2), *(name+3),
314 *(name+4), *(name+5), *(name+6), *(name+7),
315 ndlp->nlp_DID, ndlp->nlp_flag,
316 ndlp->nlp_state, ndlp->nlp_rpi);
319 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
320 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
321 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
322 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
323 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
324 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
330 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
331 * @phba: Pointer to hba context object.
332 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
333 * @nlp_did: remote node identifer with devloss timeout.
335 * This function is called from the worker thread after invoking devloss
336 * timeout handler and releasing the reference count for the ndlp with
337 * which the devloss timeout was handled for SLI4 host. For the devloss
338 * timeout of the last remote node which had been in use of FCF, when this
339 * routine is invoked, it shall be guaranteed that none of the remote are
340 * in-use of FCF. When devloss timeout to the last remote using the FCF,
341 * if the FIP engine is neither in FCF table scan process nor roundrobin
342 * failover process, the in-use FCF shall be unregistered. If the FIP
343 * engine is in FCF discovery process, the devloss timeout state shall
344 * be set for either the FCF table scan process or roundrobin failover
345 * process to unregister the in-use FCF.
348 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
351 /* If devloss timeout happened to a remote node when FCF had no
352 * longer been in-use, do nothing.
357 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
358 spin_lock_irq(&phba->hbalock);
359 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
360 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
361 spin_unlock_irq(&phba->hbalock);
364 phba->hba_flag |= HBA_DEVLOSS_TMO;
365 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
366 "2847 Last remote node (x%x) using "
367 "FCF devloss tmo\n", nlp_did);
369 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
370 spin_unlock_irq(&phba->hbalock);
371 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
372 "2868 Devloss tmo to FCF rediscovery "
376 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
377 spin_unlock_irq(&phba->hbalock);
378 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
379 "2869 Devloss tmo to idle FIP engine, "
380 "unreg in-use FCF and rescan.\n");
381 /* Unregister in-use FCF and rescan */
382 lpfc_unregister_fcf_rescan(phba);
385 spin_unlock_irq(&phba->hbalock);
386 if (phba->hba_flag & FCF_TS_INPROG)
387 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
388 "2870 FCF table scan in progress\n");
389 if (phba->hba_flag & FCF_RR_INPROG)
390 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
391 "2871 FLOGI roundrobin FCF failover "
394 lpfc_unregister_unused_fcf(phba);
398 * lpfc_alloc_fast_evt - Allocates data structure for posting event
399 * @phba: Pointer to hba context object.
401 * This function is called from the functions which need to post
402 * events from interrupt context. This function allocates data
403 * structure required for posting event. It also keeps track of
404 * number of events pending and prevent event storm when there are
407 struct lpfc_fast_path_event *
408 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
409 struct lpfc_fast_path_event *ret;
411 /* If there are lot of fast event do not exhaust memory due to this */
412 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
415 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
418 atomic_inc(&phba->fast_event_count);
419 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
420 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
426 * lpfc_free_fast_evt - Frees event data structure
427 * @phba: Pointer to hba context object.
428 * @evt: Event object which need to be freed.
430 * This function frees the data structure required for posting
434 lpfc_free_fast_evt(struct lpfc_hba *phba,
435 struct lpfc_fast_path_event *evt) {
437 atomic_dec(&phba->fast_event_count);
442 * lpfc_send_fastpath_evt - Posts events generated from fast path
443 * @phba: Pointer to hba context object.
444 * @evtp: Event data structure.
446 * This function is called from worker thread, when the interrupt
447 * context need to post an event. This function posts the event
448 * to fc transport netlink interface.
451 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
452 struct lpfc_work_evt *evtp)
454 unsigned long evt_category, evt_sub_category;
455 struct lpfc_fast_path_event *fast_evt_data;
457 uint32_t evt_data_size;
458 struct Scsi_Host *shost;
460 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
463 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
464 evt_sub_category = (unsigned long) fast_evt_data->un.
465 fabric_evt.subcategory;
466 shost = lpfc_shost_from_vport(fast_evt_data->vport);
467 if (evt_category == FC_REG_FABRIC_EVENT) {
468 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
469 evt_data = (char *) &fast_evt_data->un.read_check_error;
470 evt_data_size = sizeof(fast_evt_data->un.
472 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
473 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
474 evt_data = (char *) &fast_evt_data->un.fabric_evt;
475 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
477 lpfc_free_fast_evt(phba, fast_evt_data);
480 } else if (evt_category == FC_REG_SCSI_EVENT) {
481 switch (evt_sub_category) {
482 case LPFC_EVENT_QFULL:
483 case LPFC_EVENT_DEVBSY:
484 evt_data = (char *) &fast_evt_data->un.scsi_evt;
485 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
487 case LPFC_EVENT_CHECK_COND:
488 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
489 evt_data_size = sizeof(fast_evt_data->un.
492 case LPFC_EVENT_VARQUEDEPTH:
493 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
494 evt_data_size = sizeof(fast_evt_data->un.
498 lpfc_free_fast_evt(phba, fast_evt_data);
502 lpfc_free_fast_evt(phba, fast_evt_data);
506 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
507 fc_host_post_vendor_event(shost,
508 fc_get_event_number(),
513 lpfc_free_fast_evt(phba, fast_evt_data);
518 lpfc_work_list_done(struct lpfc_hba *phba)
520 struct lpfc_work_evt *evtp = NULL;
521 struct lpfc_nodelist *ndlp;
526 spin_lock_irq(&phba->hbalock);
527 while (!list_empty(&phba->work_list)) {
528 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
530 spin_unlock_irq(&phba->hbalock);
533 case LPFC_EVT_ELS_RETRY:
534 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
535 lpfc_els_retry_delay_handler(ndlp);
536 free_evt = 0; /* evt is part of ndlp */
537 /* decrement the node reference count held
538 * for this queued work
542 case LPFC_EVT_DEV_LOSS:
543 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
544 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
546 /* decrement the node reference count held for
549 nlp_did = ndlp->nlp_DID;
551 if (phba->sli_rev == LPFC_SLI_REV4)
552 lpfc_sli4_post_dev_loss_tmo_handler(phba,
556 case LPFC_EVT_ONLINE:
557 if (phba->link_state < LPFC_LINK_DOWN)
558 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
560 *(int *) (evtp->evt_arg1) = 0;
561 complete((struct completion *)(evtp->evt_arg2));
563 case LPFC_EVT_OFFLINE_PREP:
564 if (phba->link_state >= LPFC_LINK_DOWN)
565 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
566 *(int *)(evtp->evt_arg1) = 0;
567 complete((struct completion *)(evtp->evt_arg2));
569 case LPFC_EVT_OFFLINE:
571 lpfc_sli_brdrestart(phba);
572 *(int *)(evtp->evt_arg1) =
573 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
574 lpfc_unblock_mgmt_io(phba);
575 complete((struct completion *)(evtp->evt_arg2));
577 case LPFC_EVT_WARM_START:
579 lpfc_reset_barrier(phba);
580 lpfc_sli_brdreset(phba);
581 lpfc_hba_down_post(phba);
582 *(int *)(evtp->evt_arg1) =
583 lpfc_sli_brdready(phba, HS_MBRDY);
584 lpfc_unblock_mgmt_io(phba);
585 complete((struct completion *)(evtp->evt_arg2));
589 *(int *)(evtp->evt_arg1)
590 = (phba->pport->stopped)
591 ? 0 : lpfc_sli_brdkill(phba);
592 lpfc_unblock_mgmt_io(phba);
593 complete((struct completion *)(evtp->evt_arg2));
595 case LPFC_EVT_FASTPATH_MGMT_EVT:
596 lpfc_send_fastpath_evt(phba, evtp);
599 case LPFC_EVT_RESET_HBA:
600 if (!(phba->pport->load_flag & FC_UNLOADING))
601 lpfc_reset_hba(phba);
606 spin_lock_irq(&phba->hbalock);
608 spin_unlock_irq(&phba->hbalock);
613 lpfc_work_done(struct lpfc_hba *phba)
615 struct lpfc_sli_ring *pring;
616 uint32_t ha_copy, status, control, work_port_events;
617 struct lpfc_vport **vports;
618 struct lpfc_vport *vport;
621 spin_lock_irq(&phba->hbalock);
622 ha_copy = phba->work_ha;
624 spin_unlock_irq(&phba->hbalock);
626 /* First, try to post the next mailbox command to SLI4 device */
627 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
628 lpfc_sli4_post_async_mbox(phba);
630 if (ha_copy & HA_ERATT)
631 /* Handle the error attention event */
632 lpfc_handle_eratt(phba);
634 if (ha_copy & HA_MBATT)
635 lpfc_sli_handle_mb_event(phba);
637 if (ha_copy & HA_LATT)
638 lpfc_handle_latt(phba);
640 /* Process SLI4 events */
641 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
642 if (phba->hba_flag & HBA_RRQ_ACTIVE)
643 lpfc_handle_rrq_active(phba);
644 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
645 lpfc_sli4_els_xri_abort_event_proc(phba);
646 if (phba->hba_flag & ASYNC_EVENT)
647 lpfc_sli4_async_event_proc(phba);
648 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
649 spin_lock_irq(&phba->hbalock);
650 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
651 spin_unlock_irq(&phba->hbalock);
652 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
654 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
655 lpfc_sli4_fcf_redisc_event_proc(phba);
658 vports = lpfc_create_vport_work_array(phba);
660 for (i = 0; i <= phba->max_vports; i++) {
662 * We could have no vports in array if unloading, so if
663 * this happens then just use the pport
665 if (vports[i] == NULL && i == 0)
671 spin_lock_irq(&vport->work_port_lock);
672 work_port_events = vport->work_port_events;
673 vport->work_port_events &= ~work_port_events;
674 spin_unlock_irq(&vport->work_port_lock);
675 if (work_port_events & WORKER_DISC_TMO)
676 lpfc_disc_timeout_handler(vport);
677 if (work_port_events & WORKER_ELS_TMO)
678 lpfc_els_timeout_handler(vport);
679 if (work_port_events & WORKER_HB_TMO)
680 lpfc_hb_timeout_handler(phba);
681 if (work_port_events & WORKER_MBOX_TMO)
682 lpfc_mbox_timeout_handler(phba);
683 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
684 lpfc_unblock_fabric_iocbs(phba);
685 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
686 lpfc_ramp_down_queue_handler(phba);
687 if (work_port_events & WORKER_DELAYED_DISC_TMO)
688 lpfc_delayed_disc_timeout_handler(vport);
690 lpfc_destroy_vport_work_array(phba, vports);
692 pring = lpfc_phba_elsring(phba);
693 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
694 status >>= (4*LPFC_ELS_RING);
695 if (pring && (status & HA_RXMASK ||
696 pring->flag & LPFC_DEFERRED_RING_EVENT ||
697 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
698 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
699 pring->flag |= LPFC_DEFERRED_RING_EVENT;
700 /* Preserve legacy behavior. */
701 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
702 set_bit(LPFC_DATA_READY, &phba->data_flags);
704 /* Driver could have abort request completed in queue
705 * when link goes down. Allow for this transition.
707 if (phba->link_state >= LPFC_LINK_DOWN ||
708 phba->link_flag & LS_MDS_LOOPBACK) {
709 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
710 lpfc_sli_handle_slow_ring_event(phba, pring,
715 if (phba->sli_rev == LPFC_SLI_REV4)
716 lpfc_drain_txq(phba);
718 * Turn on Ring interrupts
720 if (phba->sli_rev <= LPFC_SLI_REV3) {
721 spin_lock_irq(&phba->hbalock);
722 control = readl(phba->HCregaddr);
723 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
724 lpfc_debugfs_slow_ring_trc(phba,
725 "WRK Enable ring: cntl:x%x hacopy:x%x",
726 control, ha_copy, 0);
728 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
729 writel(control, phba->HCregaddr);
730 readl(phba->HCregaddr); /* flush */
732 lpfc_debugfs_slow_ring_trc(phba,
733 "WRK Ring ok: cntl:x%x hacopy:x%x",
734 control, ha_copy, 0);
736 spin_unlock_irq(&phba->hbalock);
739 lpfc_work_list_done(phba);
743 lpfc_do_work(void *p)
745 struct lpfc_hba *phba = p;
748 set_user_nice(current, MIN_NICE);
749 current->flags |= PF_NOFREEZE;
750 phba->data_flags = 0;
752 while (!kthread_should_stop()) {
753 /* wait and check worker queue activities */
754 rc = wait_event_interruptible(phba->work_waitq,
755 (test_and_clear_bit(LPFC_DATA_READY,
757 || kthread_should_stop()));
758 /* Signal wakeup shall terminate the worker thread */
760 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
761 "0433 Wakeup on signal: rc=x%x\n", rc);
765 /* Attend pending lpfc data processing */
766 lpfc_work_done(phba);
768 phba->worker_thread = NULL;
769 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
770 "0432 Worker thread stopped.\n");
775 * This is only called to handle FC worker events. Since this a rare
776 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
777 * embedding it in the IOCB.
780 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
783 struct lpfc_work_evt *evtp;
787 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
788 * be queued to worker thread for processing
790 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
794 evtp->evt_arg1 = arg1;
795 evtp->evt_arg2 = arg2;
798 spin_lock_irqsave(&phba->hbalock, flags);
799 list_add_tail(&evtp->evt_listp, &phba->work_list);
800 spin_unlock_irqrestore(&phba->hbalock, flags);
802 lpfc_worker_wake_up(phba);
808 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
810 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
811 struct lpfc_hba *phba = vport->phba;
812 struct lpfc_nodelist *ndlp, *next_ndlp;
814 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
815 if (!NLP_CHK_NODE_ACT(ndlp))
817 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
819 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
820 ((vport->port_type == LPFC_NPIV_PORT) &&
821 (ndlp->nlp_DID == NameServer_DID)))
822 lpfc_unreg_rpi(vport, ndlp);
824 /* Leave Fabric nodes alone on link down */
825 if ((phba->sli_rev < LPFC_SLI_REV4) &&
826 (!remove && ndlp->nlp_type & NLP_FABRIC))
828 lpfc_disc_state_machine(vport, ndlp, NULL,
831 : NLP_EVT_DEVICE_RECOVERY);
833 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
834 if (phba->sli_rev == LPFC_SLI_REV4)
835 lpfc_sli4_unreg_all_rpis(vport);
836 lpfc_mbx_unreg_vpi(vport);
837 spin_lock_irq(shost->host_lock);
838 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
839 spin_unlock_irq(shost->host_lock);
844 lpfc_port_link_failure(struct lpfc_vport *vport)
846 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
848 /* Cleanup any outstanding received buffers */
849 lpfc_cleanup_rcv_buffers(vport);
851 /* Cleanup any outstanding RSCN activity */
852 lpfc_els_flush_rscn(vport);
854 /* Cleanup any outstanding ELS commands */
855 lpfc_els_flush_cmd(vport);
857 lpfc_cleanup_rpis(vport, 0);
859 /* Turn off discovery timer if its running */
860 lpfc_can_disctmo(vport);
864 lpfc_linkdown_port(struct lpfc_vport *vport)
866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
868 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
869 fc_host_post_event(shost, fc_get_event_number(),
870 FCH_EVT_LINKDOWN, 0);
872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
873 "Link Down: state:x%x rtry:x%x flg:x%x",
874 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
876 lpfc_port_link_failure(vport);
878 /* Stop delayed Nport discovery */
879 spin_lock_irq(shost->host_lock);
880 vport->fc_flag &= ~FC_DISC_DELAYED;
881 spin_unlock_irq(shost->host_lock);
882 del_timer_sync(&vport->delayed_disc_tmo);
886 lpfc_linkdown(struct lpfc_hba *phba)
888 struct lpfc_vport *vport = phba->pport;
889 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
890 struct lpfc_vport **vports;
894 if (phba->link_state == LPFC_LINK_DOWN)
897 /* Block all SCSI stack I/Os */
898 lpfc_scsi_dev_block(phba);
900 phba->defer_flogi_acc_flag = false;
902 spin_lock_irq(&phba->hbalock);
903 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
904 spin_unlock_irq(&phba->hbalock);
905 if (phba->link_state > LPFC_LINK_DOWN) {
906 phba->link_state = LPFC_LINK_DOWN;
907 if (phba->sli4_hba.conf_trunk) {
908 phba->trunk_link.link0.state = 0;
909 phba->trunk_link.link1.state = 0;
910 phba->trunk_link.link2.state = 0;
911 phba->trunk_link.link3.state = 0;
912 phba->sli4_hba.link_state.logical_speed =
913 LPFC_LINK_SPEED_UNKNOWN;
915 spin_lock_irq(shost->host_lock);
916 phba->pport->fc_flag &= ~FC_LBIT;
917 spin_unlock_irq(shost->host_lock);
919 vports = lpfc_create_vport_work_array(phba);
920 if (vports != NULL) {
921 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
922 /* Issue a LINK DOWN event to all nodes */
923 lpfc_linkdown_port(vports[i]);
925 vports[i]->fc_myDID = 0;
927 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
928 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
929 if (phba->nvmet_support)
930 lpfc_nvmet_update_targetport(phba);
932 lpfc_nvme_update_localport(vports[i]);
936 lpfc_destroy_vport_work_array(phba, vports);
938 /* Clean up any SLI3 firmware default rpi's */
939 if (phba->sli_rev > LPFC_SLI_REV3)
942 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
944 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
946 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
947 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
948 == MBX_NOT_FINISHED) {
949 mempool_free(mb, phba->mbox_mem_pool);
954 /* Setup myDID for link up if we are in pt2pt mode */
955 if (phba->pport->fc_flag & FC_PT2PT) {
956 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
958 lpfc_config_link(phba, mb);
959 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
961 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
962 == MBX_NOT_FINISHED) {
963 mempool_free(mb, phba->mbox_mem_pool);
966 spin_lock_irq(shost->host_lock);
967 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
968 phba->pport->rcv_flogi_cnt = 0;
969 spin_unlock_irq(shost->host_lock);
975 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
977 struct lpfc_nodelist *ndlp;
979 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
980 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
981 if (!NLP_CHK_NODE_ACT(ndlp))
983 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
985 if (ndlp->nlp_type & NLP_FABRIC) {
986 /* On Linkup its safe to clean up the ndlp
987 * from Fabric connections.
989 if (ndlp->nlp_DID != Fabric_DID)
990 lpfc_unreg_rpi(vport, ndlp);
991 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
992 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
993 /* Fail outstanding IO now since device is
996 lpfc_unreg_rpi(vport, ndlp);
1002 lpfc_linkup_port(struct lpfc_vport *vport)
1004 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1005 struct lpfc_hba *phba = vport->phba;
1007 if ((vport->load_flag & FC_UNLOADING) != 0)
1010 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1011 "Link Up: top:x%x speed:x%x flg:x%x",
1012 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1014 /* If NPIV is not enabled, only bring the physical port up */
1015 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1016 (vport != phba->pport))
1019 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1020 fc_host_post_event(shost, fc_get_event_number(),
1023 spin_lock_irq(shost->host_lock);
1024 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1025 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1026 vport->fc_flag |= FC_NDISC_ACTIVE;
1027 vport->fc_ns_retry = 0;
1028 spin_unlock_irq(shost->host_lock);
1030 if (vport->fc_flag & FC_LBIT)
1031 lpfc_linkup_cleanup_nodes(vport);
1036 lpfc_linkup(struct lpfc_hba *phba)
1038 struct lpfc_vport **vports;
1040 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1042 phba->link_state = LPFC_LINK_UP;
1044 /* Unblock fabric iocbs if they are blocked */
1045 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1046 del_timer_sync(&phba->fabric_block_timer);
1048 vports = lpfc_create_vport_work_array(phba);
1050 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1051 lpfc_linkup_port(vports[i]);
1052 lpfc_destroy_vport_work_array(phba, vports);
1054 /* Clear the pport flogi counter in case the link down was
1055 * absorbed without an ACQE. No lock here - in worker thread
1056 * and discovery is synchronized.
1058 spin_lock_irq(shost->host_lock);
1059 phba->pport->rcv_flogi_cnt = 0;
1060 spin_unlock_irq(shost->host_lock);
1062 /* reinitialize initial FLOGI flag */
1063 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1064 phba->defer_flogi_acc_flag = false;
1070 * This routine handles processing a CLEAR_LA mailbox
1071 * command upon completion. It is setup in the LPFC_MBOXQ
1072 * as the completion routine when the command is
1073 * handed off to the SLI layer. SLI3 only.
1076 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1078 struct lpfc_vport *vport = pmb->vport;
1079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1080 struct lpfc_sli *psli = &phba->sli;
1081 MAILBOX_t *mb = &pmb->u.mb;
1084 /* Since we don't do discovery right now, turn these off here */
1085 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1086 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1088 /* Check for error */
1089 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1090 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1091 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1092 "0320 CLEAR_LA mbxStatus error x%x hba "
1094 mb->mbxStatus, vport->port_state);
1095 phba->link_state = LPFC_HBA_ERROR;
1099 if (vport->port_type == LPFC_PHYSICAL_PORT)
1100 phba->link_state = LPFC_HBA_READY;
1102 spin_lock_irq(&phba->hbalock);
1103 psli->sli_flag |= LPFC_PROCESS_LA;
1104 control = readl(phba->HCregaddr);
1105 control |= HC_LAINT_ENA;
1106 writel(control, phba->HCregaddr);
1107 readl(phba->HCregaddr); /* flush */
1108 spin_unlock_irq(&phba->hbalock);
1109 mempool_free(pmb, phba->mbox_mem_pool);
1113 /* Device Discovery completes */
1114 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1115 "0225 Device Discovery completes\n");
1116 mempool_free(pmb, phba->mbox_mem_pool);
1118 spin_lock_irq(shost->host_lock);
1119 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1120 spin_unlock_irq(shost->host_lock);
1122 lpfc_can_disctmo(vport);
1124 /* turn on Link Attention interrupts */
1126 spin_lock_irq(&phba->hbalock);
1127 psli->sli_flag |= LPFC_PROCESS_LA;
1128 control = readl(phba->HCregaddr);
1129 control |= HC_LAINT_ENA;
1130 writel(control, phba->HCregaddr);
1131 readl(phba->HCregaddr); /* flush */
1132 spin_unlock_irq(&phba->hbalock);
1139 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1141 struct lpfc_vport *vport = pmb->vport;
1143 if (pmb->u.mb.mbxStatus)
1146 mempool_free(pmb, phba->mbox_mem_pool);
1148 /* don't perform discovery for SLI4 loopback diagnostic test */
1149 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1150 !(phba->hba_flag & HBA_FCOE_MODE) &&
1151 (phba->link_flag & LS_LOOPBACK_MODE))
1154 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1155 vport->fc_flag & FC_PUBLIC_LOOP &&
1156 !(vport->fc_flag & FC_LBIT)) {
1157 /* Need to wait for FAN - use discovery timer
1158 * for timeout. port_state is identically
1159 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1161 lpfc_set_disctmo(vport);
1165 /* Start discovery by sending a FLOGI. port_state is identically
1166 * LPFC_FLOGI while waiting for FLOGI cmpl. Check if sending
1167 * the FLOGI is being deferred till after MBX_READ_SPARAM completes.
1169 if (vport->port_state != LPFC_FLOGI) {
1170 if (!(phba->hba_flag & HBA_DEFER_FLOGI))
1171 lpfc_initial_flogi(vport);
1173 if (vport->fc_flag & FC_PT2PT)
1174 lpfc_disc_start(vport);
1179 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1180 "0306 CONFIG_LINK mbxStatus error x%x "
1182 pmb->u.mb.mbxStatus, vport->port_state);
1183 mempool_free(pmb, phba->mbox_mem_pool);
1185 lpfc_linkdown(phba);
1187 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1188 "0200 CONFIG_LINK bad hba state x%x\n",
1191 lpfc_issue_clear_la(phba, vport);
1196 * lpfc_sli4_clear_fcf_rr_bmask
1197 * @phba pointer to the struct lpfc_hba for this port.
1198 * This fucnction resets the round robin bit mask and clears the
1199 * fcf priority list. The list deletions are done while holding the
1200 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1201 * from the lpfc_fcf_pri record.
1204 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1206 struct lpfc_fcf_pri *fcf_pri;
1207 struct lpfc_fcf_pri *next_fcf_pri;
1208 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1209 spin_lock_irq(&phba->hbalock);
1210 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1211 &phba->fcf.fcf_pri_list, list) {
1212 list_del_init(&fcf_pri->list);
1213 fcf_pri->fcf_rec.flag = 0;
1215 spin_unlock_irq(&phba->hbalock);
1218 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1220 struct lpfc_vport *vport = mboxq->vport;
1222 if (mboxq->u.mb.mbxStatus) {
1223 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1224 "2017 REG_FCFI mbxStatus error x%x "
1226 mboxq->u.mb.mbxStatus, vport->port_state);
1230 /* Start FCoE discovery by sending a FLOGI. */
1231 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1232 /* Set the FCFI registered flag */
1233 spin_lock_irq(&phba->hbalock);
1234 phba->fcf.fcf_flag |= FCF_REGISTERED;
1235 spin_unlock_irq(&phba->hbalock);
1237 /* If there is a pending FCoE event, restart FCF table scan. */
1238 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1239 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1242 /* Mark successful completion of FCF table scan */
1243 spin_lock_irq(&phba->hbalock);
1244 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1245 phba->hba_flag &= ~FCF_TS_INPROG;
1246 if (vport->port_state != LPFC_FLOGI) {
1247 phba->hba_flag |= FCF_RR_INPROG;
1248 spin_unlock_irq(&phba->hbalock);
1249 lpfc_issue_init_vfi(vport);
1252 spin_unlock_irq(&phba->hbalock);
1256 spin_lock_irq(&phba->hbalock);
1257 phba->hba_flag &= ~FCF_RR_INPROG;
1258 spin_unlock_irq(&phba->hbalock);
1260 mempool_free(mboxq, phba->mbox_mem_pool);
1264 * lpfc_fab_name_match - Check if the fcf fabric name match.
1265 * @fab_name: pointer to fabric name.
1266 * @new_fcf_record: pointer to fcf record.
1268 * This routine compare the fcf record's fabric name with provided
1269 * fabric name. If the fabric name are identical this function
1270 * returns 1 else return 0.
1273 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1275 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1277 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1279 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1281 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1283 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1285 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1287 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1289 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1295 * lpfc_sw_name_match - Check if the fcf switch name match.
1296 * @fab_name: pointer to fabric name.
1297 * @new_fcf_record: pointer to fcf record.
1299 * This routine compare the fcf record's switch name with provided
1300 * switch name. If the switch name are identical this function
1301 * returns 1 else return 0.
1304 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1306 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1308 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1310 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1312 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1314 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1316 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1318 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1320 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1326 * lpfc_mac_addr_match - Check if the fcf mac address match.
1327 * @mac_addr: pointer to mac address.
1328 * @new_fcf_record: pointer to fcf record.
1330 * This routine compare the fcf record's mac address with HBA's
1331 * FCF mac address. If the mac addresses are identical this function
1332 * returns 1 else return 0.
1335 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1337 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1339 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1341 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1343 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1345 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1347 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1353 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1355 return (curr_vlan_id == new_vlan_id);
1359 * lpfc_update_fcf_record - Update driver fcf record
1360 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1361 * @phba: pointer to lpfc hba data structure.
1362 * @fcf_index: Index for the lpfc_fcf_record.
1363 * @new_fcf_record: pointer to hba fcf record.
1365 * This routine updates the driver FCF priority record from the new HBA FCF
1366 * record. This routine is called with the host lock held.
1369 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1370 struct fcf_record *new_fcf_record
1373 struct lpfc_fcf_pri *fcf_pri;
1375 lockdep_assert_held(&phba->hbalock);
1377 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1378 fcf_pri->fcf_rec.fcf_index = fcf_index;
1379 /* FCF record priority */
1380 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1385 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1386 * @fcf: pointer to driver fcf record.
1387 * @new_fcf_record: pointer to fcf record.
1389 * This routine copies the FCF information from the FCF
1390 * record to lpfc_hba data structure.
1393 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1394 struct fcf_record *new_fcf_record)
1397 fcf_rec->fabric_name[0] =
1398 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1399 fcf_rec->fabric_name[1] =
1400 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1401 fcf_rec->fabric_name[2] =
1402 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1403 fcf_rec->fabric_name[3] =
1404 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1405 fcf_rec->fabric_name[4] =
1406 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1407 fcf_rec->fabric_name[5] =
1408 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1409 fcf_rec->fabric_name[6] =
1410 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1411 fcf_rec->fabric_name[7] =
1412 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1414 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1415 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1416 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1417 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1418 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1419 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1420 /* FCF record index */
1421 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1422 /* FCF record priority */
1423 fcf_rec->priority = new_fcf_record->fip_priority;
1425 fcf_rec->switch_name[0] =
1426 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1427 fcf_rec->switch_name[1] =
1428 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1429 fcf_rec->switch_name[2] =
1430 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1431 fcf_rec->switch_name[3] =
1432 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1433 fcf_rec->switch_name[4] =
1434 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1435 fcf_rec->switch_name[5] =
1436 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1437 fcf_rec->switch_name[6] =
1438 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1439 fcf_rec->switch_name[7] =
1440 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1444 * lpfc_update_fcf_record - Update driver fcf record
1445 * @phba: pointer to lpfc hba data structure.
1446 * @fcf_rec: pointer to driver fcf record.
1447 * @new_fcf_record: pointer to hba fcf record.
1448 * @addr_mode: address mode to be set to the driver fcf record.
1449 * @vlan_id: vlan tag to be set to the driver fcf record.
1450 * @flag: flag bits to be set to the driver fcf record.
1452 * This routine updates the driver FCF record from the new HBA FCF record
1453 * together with the address mode, vlan_id, and other informations. This
1454 * routine is called with the host lock held.
1457 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1458 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1459 uint16_t vlan_id, uint32_t flag)
1461 lockdep_assert_held(&phba->hbalock);
1463 /* Copy the fields from the HBA's FCF record */
1464 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1465 /* Update other fields of driver FCF record */
1466 fcf_rec->addr_mode = addr_mode;
1467 fcf_rec->vlan_id = vlan_id;
1468 fcf_rec->flag |= (flag | RECORD_VALID);
1469 __lpfc_update_fcf_record_pri(phba,
1470 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1475 * lpfc_register_fcf - Register the FCF with hba.
1476 * @phba: pointer to lpfc hba data structure.
1478 * This routine issues a register fcfi mailbox command to register
1482 lpfc_register_fcf(struct lpfc_hba *phba)
1484 LPFC_MBOXQ_t *fcf_mbxq;
1487 spin_lock_irq(&phba->hbalock);
1488 /* If the FCF is not available do nothing. */
1489 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1490 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1491 spin_unlock_irq(&phba->hbalock);
1495 /* The FCF is already registered, start discovery */
1496 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1497 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1498 phba->hba_flag &= ~FCF_TS_INPROG;
1499 if (phba->pport->port_state != LPFC_FLOGI &&
1500 phba->pport->fc_flag & FC_FABRIC) {
1501 phba->hba_flag |= FCF_RR_INPROG;
1502 spin_unlock_irq(&phba->hbalock);
1503 lpfc_initial_flogi(phba->pport);
1506 spin_unlock_irq(&phba->hbalock);
1509 spin_unlock_irq(&phba->hbalock);
1511 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1513 spin_lock_irq(&phba->hbalock);
1514 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1515 spin_unlock_irq(&phba->hbalock);
1519 lpfc_reg_fcfi(phba, fcf_mbxq);
1520 fcf_mbxq->vport = phba->pport;
1521 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1522 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1523 if (rc == MBX_NOT_FINISHED) {
1524 spin_lock_irq(&phba->hbalock);
1525 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1526 spin_unlock_irq(&phba->hbalock);
1527 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1534 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1535 * @phba: pointer to lpfc hba data structure.
1536 * @new_fcf_record: pointer to fcf record.
1537 * @boot_flag: Indicates if this record used by boot bios.
1538 * @addr_mode: The address mode to be used by this FCF
1539 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1541 * This routine compare the fcf record with connect list obtained from the
1542 * config region to decide if this FCF can be used for SAN discovery. It returns
1543 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1544 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1545 * is used by boot bios and addr_mode will indicate the addressing mode to be
1546 * used for this FCF when the function returns.
1547 * If the FCF record need to be used with a particular vlan id, the vlan is
1548 * set in the vlan_id on return of the function. If not VLAN tagging need to
1549 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1552 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1553 struct fcf_record *new_fcf_record,
1554 uint32_t *boot_flag, uint32_t *addr_mode,
1557 struct lpfc_fcf_conn_entry *conn_entry;
1558 int i, j, fcf_vlan_id = 0;
1560 /* Find the lowest VLAN id in the FCF record */
1561 for (i = 0; i < 512; i++) {
1562 if (new_fcf_record->vlan_bitmap[i]) {
1563 fcf_vlan_id = i * 8;
1565 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1573 /* FCF not valid/available or solicitation in progress */
1574 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1575 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1576 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1579 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1581 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1583 if (phba->valid_vlan)
1584 *vlan_id = phba->vlan_id;
1586 *vlan_id = LPFC_FCOE_NULL_VID;
1591 * If there are no FCF connection table entry, driver connect to all
1594 if (list_empty(&phba->fcf_conn_rec_list)) {
1596 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1600 * When there are no FCF connect entries, use driver's default
1601 * addressing mode - FPMA.
1603 if (*addr_mode & LPFC_FCF_FPMA)
1604 *addr_mode = LPFC_FCF_FPMA;
1606 /* If FCF record report a vlan id use that vlan id */
1608 *vlan_id = fcf_vlan_id;
1610 *vlan_id = LPFC_FCOE_NULL_VID;
1614 list_for_each_entry(conn_entry,
1615 &phba->fcf_conn_rec_list, list) {
1616 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1619 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1620 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1623 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1624 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1627 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1629 * If the vlan bit map does not have the bit set for the
1630 * vlan id to be used, then it is not a match.
1632 if (!(new_fcf_record->vlan_bitmap
1633 [conn_entry->conn_rec.vlan_tag / 8] &
1634 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1639 * If connection record does not support any addressing mode,
1640 * skip the FCF record.
1642 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1643 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1647 * Check if the connection record specifies a required
1650 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1651 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1654 * If SPMA required but FCF not support this continue.
1656 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1657 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1658 new_fcf_record) & LPFC_FCF_SPMA))
1662 * If FPMA required but FCF not support this continue.
1664 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1665 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1666 new_fcf_record) & LPFC_FCF_FPMA))
1671 * This fcf record matches filtering criteria.
1673 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1679 * If user did not specify any addressing mode, or if the
1680 * preferred addressing mode specified by user is not supported
1681 * by FCF, allow fabric to pick the addressing mode.
1683 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1686 * If the user specified a required address mode, assign that
1689 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1690 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1691 *addr_mode = (conn_entry->conn_rec.flags &
1693 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1695 * If the user specified a preferred address mode, use the
1696 * addr mode only if FCF support the addr_mode.
1698 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1699 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1700 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1701 (*addr_mode & LPFC_FCF_SPMA))
1702 *addr_mode = LPFC_FCF_SPMA;
1703 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1704 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1705 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1706 (*addr_mode & LPFC_FCF_FPMA))
1707 *addr_mode = LPFC_FCF_FPMA;
1709 /* If matching connect list has a vlan id, use it */
1710 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1711 *vlan_id = conn_entry->conn_rec.vlan_tag;
1713 * If no vlan id is specified in connect list, use the vlan id
1716 else if (fcf_vlan_id)
1717 *vlan_id = fcf_vlan_id;
1719 *vlan_id = LPFC_FCOE_NULL_VID;
1728 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1729 * @phba: pointer to lpfc hba data structure.
1730 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1732 * This function check if there is any fcoe event pending while driver
1733 * scan FCF entries. If there is any pending event, it will restart the
1734 * FCF saning and return 1 else return 0.
1737 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1740 * If the Link is up and no FCoE events while in the
1741 * FCF discovery, no need to restart FCF discovery.
1743 if ((phba->link_state >= LPFC_LINK_UP) &&
1744 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1747 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1748 "2768 Pending link or FCF event during current "
1749 "handling of the previous event: link_state:x%x, "
1750 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1751 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1752 phba->fcoe_eventtag);
1754 spin_lock_irq(&phba->hbalock);
1755 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1756 spin_unlock_irq(&phba->hbalock);
1758 if (phba->link_state >= LPFC_LINK_UP) {
1759 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1760 "2780 Restart FCF table scan due to "
1761 "pending FCF event:evt_tag_at_scan:x%x, "
1762 "evt_tag_current:x%x\n",
1763 phba->fcoe_eventtag_at_fcf_scan,
1764 phba->fcoe_eventtag);
1765 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1768 * Do not continue FCF discovery and clear FCF_TS_INPROG
1771 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1772 "2833 Stop FCF discovery process due to link "
1773 "state change (x%x)\n", phba->link_state);
1774 spin_lock_irq(&phba->hbalock);
1775 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1776 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1777 spin_unlock_irq(&phba->hbalock);
1780 /* Unregister the currently registered FCF if required */
1782 spin_lock_irq(&phba->hbalock);
1783 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1784 spin_unlock_irq(&phba->hbalock);
1785 lpfc_sli4_unregister_fcf(phba);
1791 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1792 * @phba: pointer to lpfc hba data structure.
1793 * @fcf_cnt: number of eligible fcf record seen so far.
1795 * This function makes an running random selection decision on FCF record to
1796 * use through a sequence of @fcf_cnt eligible FCF records with equal
1797 * probability. To perform integer manunipulation of random numbers with
1798 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1799 * from prandom_u32() are taken as the random random number generated.
1801 * Returns true when outcome is for the newly read FCF record should be
1802 * chosen; otherwise, return false when outcome is for keeping the previously
1803 * chosen FCF record.
1806 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1810 /* Get 16-bit uniform random number */
1811 rand_num = 0xFFFF & prandom_u32();
1813 /* Decision with probability 1/fcf_cnt */
1814 if ((fcf_cnt * rand_num) < 0xFFFF)
1821 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1822 * @phba: pointer to lpfc hba data structure.
1823 * @mboxq: pointer to mailbox object.
1824 * @next_fcf_index: pointer to holder of next fcf index.
1826 * This routine parses the non-embedded fcf mailbox command by performing the
1827 * necessarily error checking, non-embedded read FCF record mailbox command
1828 * SGE parsing, and endianness swapping.
1830 * Returns the pointer to the new FCF record in the non-embedded mailbox
1831 * command DMA memory if successfully, other NULL.
1833 static struct fcf_record *
1834 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1835 uint16_t *next_fcf_index)
1838 struct lpfc_mbx_sge sge;
1839 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1840 uint32_t shdr_status, shdr_add_status, if_type;
1841 union lpfc_sli4_cfg_shdr *shdr;
1842 struct fcf_record *new_fcf_record;
1844 /* Get the first SGE entry from the non-embedded DMA memory. This
1845 * routine only uses a single SGE.
1847 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1848 if (unlikely(!mboxq->sge_array)) {
1849 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1850 "2524 Failed to get the non-embedded SGE "
1851 "virtual address\n");
1854 virt_addr = mboxq->sge_array->addr[0];
1856 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1857 lpfc_sli_pcimem_bcopy(shdr, shdr,
1858 sizeof(union lpfc_sli4_cfg_shdr));
1859 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1860 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1861 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1862 if (shdr_status || shdr_add_status) {
1863 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1864 if_type == LPFC_SLI_INTF_IF_TYPE_2)
1865 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1866 "2726 READ_FCF_RECORD Indicates empty "
1869 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1870 "2521 READ_FCF_RECORD mailbox failed "
1871 "with status x%x add_status x%x, "
1872 "mbx\n", shdr_status, shdr_add_status);
1876 /* Interpreting the returned information of the FCF record */
1877 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1878 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1879 sizeof(struct lpfc_mbx_read_fcf_tbl));
1880 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1881 new_fcf_record = (struct fcf_record *)(virt_addr +
1882 sizeof(struct lpfc_mbx_read_fcf_tbl));
1883 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1884 offsetof(struct fcf_record, vlan_bitmap));
1885 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1886 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1888 return new_fcf_record;
1892 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1893 * @phba: pointer to lpfc hba data structure.
1894 * @fcf_record: pointer to the fcf record.
1895 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1896 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1898 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1902 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1903 struct fcf_record *fcf_record,
1905 uint16_t next_fcf_index)
1907 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1908 "2764 READ_FCF_RECORD:\n"
1909 "\tFCF_Index : x%x\n"
1910 "\tFCF_Avail : x%x\n"
1911 "\tFCF_Valid : x%x\n"
1913 "\tFIP_Priority : x%x\n"
1914 "\tMAC_Provider : x%x\n"
1915 "\tLowest VLANID : x%x\n"
1916 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1917 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1918 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1919 "\tNext_FCF_Index: x%x\n",
1920 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1921 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1922 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1923 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1924 fcf_record->fip_priority,
1925 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1927 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1928 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1929 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1930 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1931 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1932 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1933 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1934 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1935 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1936 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1937 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1938 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1939 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1940 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1941 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1942 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1943 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1944 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1945 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1946 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1947 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1948 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1953 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1954 * @phba: pointer to lpfc hba data structure.
1955 * @fcf_rec: pointer to an existing FCF record.
1956 * @new_fcf_record: pointer to a new FCF record.
1957 * @new_vlan_id: vlan id from the new FCF record.
1959 * This function performs matching test of a new FCF record against an existing
1960 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1961 * will not be used as part of the FCF record matching criteria.
1963 * Returns true if all the fields matching, otherwise returns false.
1966 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1967 struct lpfc_fcf_rec *fcf_rec,
1968 struct fcf_record *new_fcf_record,
1969 uint16_t new_vlan_id)
1971 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1972 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1974 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1976 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1978 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1980 if (fcf_rec->priority != new_fcf_record->fip_priority)
1986 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1987 * @vport: Pointer to vport object.
1988 * @fcf_index: index to next fcf.
1990 * This function processing the roundrobin fcf failover to next fcf index.
1991 * When this function is invoked, there will be a current fcf registered
1993 * Return: 0 for continue retrying flogi on currently registered fcf;
1994 * 1 for stop flogi on currently registered fcf;
1996 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1998 struct lpfc_hba *phba = vport->phba;
2001 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2002 spin_lock_irq(&phba->hbalock);
2003 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2004 spin_unlock_irq(&phba->hbalock);
2005 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2006 "2872 Devloss tmo with no eligible "
2007 "FCF, unregister in-use FCF (x%x) "
2008 "and rescan FCF table\n",
2009 phba->fcf.current_rec.fcf_indx);
2010 lpfc_unregister_fcf_rescan(phba);
2011 goto stop_flogi_current_fcf;
2013 /* Mark the end to FLOGI roundrobin failover */
2014 phba->hba_flag &= ~FCF_RR_INPROG;
2015 /* Allow action to new fcf asynchronous event */
2016 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2017 spin_unlock_irq(&phba->hbalock);
2018 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2019 "2865 No FCF available, stop roundrobin FCF "
2020 "failover and change port state:x%x/x%x\n",
2021 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2022 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2024 if (!phba->fcf.fcf_redisc_attempted) {
2025 lpfc_unregister_fcf(phba);
2027 rc = lpfc_sli4_redisc_fcf_table(phba);
2029 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2030 "3195 Rediscover FCF table\n");
2031 phba->fcf.fcf_redisc_attempted = 1;
2032 lpfc_sli4_clear_fcf_rr_bmask(phba);
2034 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2035 "3196 Rediscover FCF table "
2036 "failed. Status:x%x\n", rc);
2039 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2040 "3197 Already rediscover FCF table "
2041 "attempted. No more retry\n");
2043 goto stop_flogi_current_fcf;
2045 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2046 "2794 Try FLOGI roundrobin FCF failover to "
2047 "(x%x)\n", fcf_index);
2048 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2050 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2051 "2761 FLOGI roundrobin FCF failover "
2052 "failed (rc:x%x) to read FCF (x%x)\n",
2053 rc, phba->fcf.current_rec.fcf_indx);
2055 goto stop_flogi_current_fcf;
2059 stop_flogi_current_fcf:
2060 lpfc_can_disctmo(vport);
2065 * lpfc_sli4_fcf_pri_list_del
2066 * @phba: pointer to lpfc hba data structure.
2067 * @fcf_index the index of the fcf record to delete
2068 * This routine checks the on list flag of the fcf_index to be deleted.
2069 * If it is one the list then it is removed from the list, and the flag
2070 * is cleared. This routine grab the hbalock before removing the fcf
2071 * record from the list.
2073 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2076 struct lpfc_fcf_pri *new_fcf_pri;
2078 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2079 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2080 "3058 deleting idx x%x pri x%x flg x%x\n",
2081 fcf_index, new_fcf_pri->fcf_rec.priority,
2082 new_fcf_pri->fcf_rec.flag);
2083 spin_lock_irq(&phba->hbalock);
2084 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2085 if (phba->fcf.current_rec.priority ==
2086 new_fcf_pri->fcf_rec.priority)
2087 phba->fcf.eligible_fcf_cnt--;
2088 list_del_init(&new_fcf_pri->list);
2089 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2091 spin_unlock_irq(&phba->hbalock);
2095 * lpfc_sli4_set_fcf_flogi_fail
2096 * @phba: pointer to lpfc hba data structure.
2097 * @fcf_index the index of the fcf record to update
2098 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2099 * flag so the the round robin slection for the particular priority level
2100 * will try a different fcf record that does not have this bit set.
2101 * If the fcf record is re-read for any reason this flag is cleared brfore
2102 * adding it to the priority list.
2105 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2107 struct lpfc_fcf_pri *new_fcf_pri;
2108 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2109 spin_lock_irq(&phba->hbalock);
2110 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2111 spin_unlock_irq(&phba->hbalock);
2115 * lpfc_sli4_fcf_pri_list_add
2116 * @phba: pointer to lpfc hba data structure.
2117 * @fcf_index the index of the fcf record to add
2118 * This routine checks the priority of the fcf_index to be added.
2119 * If it is a lower priority than the current head of the fcf_pri list
2120 * then it is added to the list in the right order.
2121 * If it is the same priority as the current head of the list then it
2122 * is added to the head of the list and its bit in the rr_bmask is set.
2123 * If the fcf_index to be added is of a higher priority than the current
2124 * head of the list then the rr_bmask is cleared, its bit is set in the
2125 * rr_bmask and it is added to the head of the list.
2127 * 0=success 1=failure
2129 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2131 struct fcf_record *new_fcf_record)
2133 uint16_t current_fcf_pri;
2134 uint16_t last_index;
2135 struct lpfc_fcf_pri *fcf_pri;
2136 struct lpfc_fcf_pri *next_fcf_pri;
2137 struct lpfc_fcf_pri *new_fcf_pri;
2140 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2141 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2142 "3059 adding idx x%x pri x%x flg x%x\n",
2143 fcf_index, new_fcf_record->fip_priority,
2144 new_fcf_pri->fcf_rec.flag);
2145 spin_lock_irq(&phba->hbalock);
2146 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2147 list_del_init(&new_fcf_pri->list);
2148 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2149 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2150 if (list_empty(&phba->fcf.fcf_pri_list)) {
2151 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2152 ret = lpfc_sli4_fcf_rr_index_set(phba,
2153 new_fcf_pri->fcf_rec.fcf_index);
2157 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2158 LPFC_SLI4_FCF_TBL_INDX_MAX);
2159 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2160 ret = 0; /* Empty rr list */
2163 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2164 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2165 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2166 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2167 memset(phba->fcf.fcf_rr_bmask, 0,
2168 sizeof(*phba->fcf.fcf_rr_bmask));
2169 /* fcfs_at_this_priority_level = 1; */
2170 phba->fcf.eligible_fcf_cnt = 1;
2172 /* fcfs_at_this_priority_level++; */
2173 phba->fcf.eligible_fcf_cnt++;
2174 ret = lpfc_sli4_fcf_rr_index_set(phba,
2175 new_fcf_pri->fcf_rec.fcf_index);
2179 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2180 &phba->fcf.fcf_pri_list, list) {
2181 if (new_fcf_pri->fcf_rec.priority <=
2182 fcf_pri->fcf_rec.priority) {
2183 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2184 list_add(&new_fcf_pri->list,
2185 &phba->fcf.fcf_pri_list);
2187 list_add(&new_fcf_pri->list,
2188 &((struct lpfc_fcf_pri *)
2189 fcf_pri->list.prev)->list);
2192 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2193 || new_fcf_pri->fcf_rec.priority <
2194 next_fcf_pri->fcf_rec.priority) {
2195 list_add(&new_fcf_pri->list, &fcf_pri->list);
2199 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2205 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2206 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2207 spin_unlock_irq(&phba->hbalock);
2212 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2213 * @phba: pointer to lpfc hba data structure.
2214 * @mboxq: pointer to mailbox object.
2216 * This function iterates through all the fcf records available in
2217 * HBA and chooses the optimal FCF record for discovery. After finding
2218 * the FCF for discovery it registers the FCF record and kicks start
2220 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2221 * use an FCF record which matches fabric name and mac address of the
2222 * currently used FCF record.
2223 * If the driver supports only one FCF, it will try to use the FCF record
2224 * used by BOOT_BIOS.
2227 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2229 struct fcf_record *new_fcf_record;
2230 uint32_t boot_flag, addr_mode;
2231 uint16_t fcf_index, next_fcf_index;
2232 struct lpfc_fcf_rec *fcf_rec = NULL;
2233 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2234 bool select_new_fcf;
2237 /* If there is pending FCoE event restart FCF table scan */
2238 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2239 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2243 /* Parse the FCF record from the non-embedded mailbox command */
2244 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2246 if (!new_fcf_record) {
2247 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2248 "2765 Mailbox command READ_FCF_RECORD "
2249 "failed to retrieve a FCF record.\n");
2250 /* Let next new FCF event trigger fast failover */
2251 spin_lock_irq(&phba->hbalock);
2252 phba->hba_flag &= ~FCF_TS_INPROG;
2253 spin_unlock_irq(&phba->hbalock);
2254 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2258 /* Check the FCF record against the connection list */
2259 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2260 &addr_mode, &vlan_id);
2262 /* Log the FCF record information if turned on */
2263 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2267 * If the fcf record does not match with connect list entries
2268 * read the next entry; otherwise, this is an eligible FCF
2269 * record for roundrobin FCF failover.
2272 lpfc_sli4_fcf_pri_list_del(phba,
2273 bf_get(lpfc_fcf_record_fcf_index,
2275 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2276 "2781 FCF (x%x) failed connection "
2277 "list check: (x%x/x%x/%x)\n",
2278 bf_get(lpfc_fcf_record_fcf_index,
2280 bf_get(lpfc_fcf_record_fcf_avail,
2282 bf_get(lpfc_fcf_record_fcf_valid,
2284 bf_get(lpfc_fcf_record_fcf_sol,
2286 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2287 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2288 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2289 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2290 phba->fcf.current_rec.fcf_indx) {
2291 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2292 "2862 FCF (x%x) matches property "
2293 "of in-use FCF (x%x)\n",
2294 bf_get(lpfc_fcf_record_fcf_index,
2296 phba->fcf.current_rec.fcf_indx);
2300 * In case the current in-use FCF record becomes
2301 * invalid/unavailable during FCF discovery that
2302 * was not triggered by fast FCF failover process,
2303 * treat it as fast FCF failover.
2305 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2306 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2307 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2308 "2835 Invalid in-use FCF "
2309 "(x%x), enter FCF failover "
2311 phba->fcf.current_rec.fcf_indx);
2312 spin_lock_irq(&phba->hbalock);
2313 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2314 spin_unlock_irq(&phba->hbalock);
2315 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2316 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2317 LPFC_FCOE_FCF_GET_FIRST);
2323 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2324 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2331 * If this is not the first FCF discovery of the HBA, use last
2332 * FCF record for the discovery. The condition that a rescan
2333 * matches the in-use FCF record: fabric name, switch name, mac
2334 * address, and vlan_id.
2336 spin_lock_irq(&phba->hbalock);
2337 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2338 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2339 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2340 new_fcf_record, vlan_id)) {
2341 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2342 phba->fcf.current_rec.fcf_indx) {
2343 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2344 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2345 /* Stop FCF redisc wait timer */
2346 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2348 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2349 /* Fast failover, mark completed */
2350 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2351 spin_unlock_irq(&phba->hbalock);
2352 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2353 "2836 New FCF matches in-use "
2354 "FCF (x%x), port_state:x%x, "
2356 phba->fcf.current_rec.fcf_indx,
2357 phba->pport->port_state,
2358 phba->pport->fc_flag);
2361 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2362 "2863 New FCF (x%x) matches "
2363 "property of in-use FCF (x%x)\n",
2364 bf_get(lpfc_fcf_record_fcf_index,
2366 phba->fcf.current_rec.fcf_indx);
2369 * Read next FCF record from HBA searching for the matching
2370 * with in-use record only if not during the fast failover
2371 * period. In case of fast failover period, it shall try to
2372 * determine whether the FCF record just read should be the
2375 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2376 spin_unlock_irq(&phba->hbalock);
2381 * Update on failover FCF record only if it's in FCF fast-failover
2382 * period; otherwise, update on current FCF record.
2384 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2385 fcf_rec = &phba->fcf.failover_rec;
2387 fcf_rec = &phba->fcf.current_rec;
2389 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2391 * If the driver FCF record does not have boot flag
2392 * set and new hba fcf record has boot flag set, use
2393 * the new hba fcf record.
2395 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2396 /* Choose this FCF record */
2397 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2398 "2837 Update current FCF record "
2399 "(x%x) with new FCF record (x%x)\n",
2401 bf_get(lpfc_fcf_record_fcf_index,
2403 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2404 addr_mode, vlan_id, BOOT_ENABLE);
2405 spin_unlock_irq(&phba->hbalock);
2409 * If the driver FCF record has boot flag set and the
2410 * new hba FCF record does not have boot flag, read
2411 * the next FCF record.
2413 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2414 spin_unlock_irq(&phba->hbalock);
2418 * If the new hba FCF record has lower priority value
2419 * than the driver FCF record, use the new record.
2421 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2422 /* Choose the new FCF record with lower priority */
2423 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2424 "2838 Update current FCF record "
2425 "(x%x) with new FCF record (x%x)\n",
2427 bf_get(lpfc_fcf_record_fcf_index,
2429 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2430 addr_mode, vlan_id, 0);
2431 /* Reset running random FCF selection count */
2432 phba->fcf.eligible_fcf_cnt = 1;
2433 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2434 /* Update running random FCF selection count */
2435 phba->fcf.eligible_fcf_cnt++;
2436 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2437 phba->fcf.eligible_fcf_cnt);
2438 if (select_new_fcf) {
2439 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2440 "2839 Update current FCF record "
2441 "(x%x) with new FCF record (x%x)\n",
2443 bf_get(lpfc_fcf_record_fcf_index,
2445 /* Choose the new FCF by random selection */
2446 __lpfc_update_fcf_record(phba, fcf_rec,
2448 addr_mode, vlan_id, 0);
2451 spin_unlock_irq(&phba->hbalock);
2455 * This is the first suitable FCF record, choose this record for
2456 * initial best-fit FCF.
2459 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2460 "2840 Update initial FCF candidate "
2462 bf_get(lpfc_fcf_record_fcf_index,
2464 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2465 addr_mode, vlan_id, (boot_flag ?
2467 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2468 /* Setup initial running random FCF selection count */
2469 phba->fcf.eligible_fcf_cnt = 1;
2471 spin_unlock_irq(&phba->hbalock);
2475 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2476 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2477 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2479 * Case of FCF fast failover scan
2483 * It has not found any suitable FCF record, cancel
2484 * FCF scan inprogress, and do nothing
2486 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2487 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2488 "2782 No suitable FCF found: "
2490 phba->fcoe_eventtag_at_fcf_scan,
2491 bf_get(lpfc_fcf_record_fcf_index,
2493 spin_lock_irq(&phba->hbalock);
2494 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2495 phba->hba_flag &= ~FCF_TS_INPROG;
2496 spin_unlock_irq(&phba->hbalock);
2497 /* Unregister in-use FCF and rescan */
2498 lpfc_printf_log(phba, KERN_INFO,
2500 "2864 On devloss tmo "
2501 "unreg in-use FCF and "
2502 "rescan FCF table\n");
2503 lpfc_unregister_fcf_rescan(phba);
2507 * Let next new FCF event trigger fast failover
2509 phba->hba_flag &= ~FCF_TS_INPROG;
2510 spin_unlock_irq(&phba->hbalock);
2514 * It has found a suitable FCF record that is not
2515 * the same as in-use FCF record, unregister the
2516 * in-use FCF record, replace the in-use FCF record
2517 * with the new FCF record, mark FCF fast failover
2518 * completed, and then start register the new FCF
2522 /* Unregister the current in-use FCF record */
2523 lpfc_unregister_fcf(phba);
2525 /* Replace in-use record with the new record */
2526 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2527 "2842 Replace in-use FCF (x%x) "
2528 "with failover FCF (x%x)\n",
2529 phba->fcf.current_rec.fcf_indx,
2530 phba->fcf.failover_rec.fcf_indx);
2531 memcpy(&phba->fcf.current_rec,
2532 &phba->fcf.failover_rec,
2533 sizeof(struct lpfc_fcf_rec));
2535 * Mark the fast FCF failover rediscovery completed
2536 * and the start of the first round of the roundrobin
2539 spin_lock_irq(&phba->hbalock);
2540 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2541 spin_unlock_irq(&phba->hbalock);
2542 /* Register to the new FCF record */
2543 lpfc_register_fcf(phba);
2546 * In case of transaction period to fast FCF failover,
2547 * do nothing when search to the end of the FCF table.
2549 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2550 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2553 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2554 phba->fcf.fcf_flag & FCF_IN_USE) {
2556 * In case the current in-use FCF record no
2557 * longer existed during FCF discovery that
2558 * was not triggered by fast FCF failover
2559 * process, treat it as fast FCF failover.
2561 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2562 "2841 In-use FCF record (x%x) "
2563 "not reported, entering fast "
2564 "FCF failover mode scanning.\n",
2565 phba->fcf.current_rec.fcf_indx);
2566 spin_lock_irq(&phba->hbalock);
2567 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2568 spin_unlock_irq(&phba->hbalock);
2569 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2570 LPFC_FCOE_FCF_GET_FIRST);
2573 /* Register to the new FCF record */
2574 lpfc_register_fcf(phba);
2577 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2581 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2582 lpfc_register_fcf(phba);
2588 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2589 * @phba: pointer to lpfc hba data structure.
2590 * @mboxq: pointer to mailbox object.
2592 * This is the callback function for FLOGI failure roundrobin FCF failover
2593 * read FCF record mailbox command from the eligible FCF record bmask for
2594 * performing the failover. If the FCF read back is not valid/available, it
2595 * fails through to retrying FLOGI to the currently registered FCF again.
2596 * Otherwise, if the FCF read back is valid and available, it will set the
2597 * newly read FCF record to the failover FCF record, unregister currently
2598 * registered FCF record, copy the failover FCF record to the current
2599 * FCF record, and then register the current FCF record before proceeding
2600 * to trying FLOGI on the new failover FCF.
2603 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2605 struct fcf_record *new_fcf_record;
2606 uint32_t boot_flag, addr_mode;
2607 uint16_t next_fcf_index, fcf_index;
2608 uint16_t current_fcf_index;
2612 /* If link state is not up, stop the roundrobin failover process */
2613 if (phba->link_state < LPFC_LINK_UP) {
2614 spin_lock_irq(&phba->hbalock);
2615 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2616 phba->hba_flag &= ~FCF_RR_INPROG;
2617 spin_unlock_irq(&phba->hbalock);
2621 /* Parse the FCF record from the non-embedded mailbox command */
2622 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2624 if (!new_fcf_record) {
2625 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2626 "2766 Mailbox command READ_FCF_RECORD "
2627 "failed to retrieve a FCF record. "
2628 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2629 phba->fcf.fcf_flag);
2630 lpfc_unregister_fcf_rescan(phba);
2634 /* Get the needed parameters from FCF record */
2635 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2636 &addr_mode, &vlan_id);
2638 /* Log the FCF record information if turned on */
2639 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2642 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2644 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2645 "2848 Remove ineligible FCF (x%x) from "
2646 "from roundrobin bmask\n", fcf_index);
2647 /* Clear roundrobin bmask bit for ineligible FCF */
2648 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2649 /* Perform next round of roundrobin FCF failover */
2650 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2651 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2657 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2658 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2659 "2760 Perform FLOGI roundrobin FCF failover: "
2660 "FCF (x%x) back to FCF (x%x)\n",
2661 phba->fcf.current_rec.fcf_indx, fcf_index);
2662 /* Wait 500 ms before retrying FLOGI to current FCF */
2664 lpfc_issue_init_vfi(phba->pport);
2668 /* Upload new FCF record to the failover FCF record */
2669 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2670 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2671 phba->fcf.failover_rec.fcf_indx, fcf_index);
2672 spin_lock_irq(&phba->hbalock);
2673 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2674 new_fcf_record, addr_mode, vlan_id,
2675 (boot_flag ? BOOT_ENABLE : 0));
2676 spin_unlock_irq(&phba->hbalock);
2678 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2680 /* Unregister the current in-use FCF record */
2681 lpfc_unregister_fcf(phba);
2683 /* Replace in-use record with the new record */
2684 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2685 sizeof(struct lpfc_fcf_rec));
2687 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2688 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2689 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2692 lpfc_register_fcf(phba);
2694 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2698 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2699 * @phba: pointer to lpfc hba data structure.
2700 * @mboxq: pointer to mailbox object.
2702 * This is the callback function of read FCF record mailbox command for
2703 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2704 * failover when a new FCF event happened. If the FCF read back is
2705 * valid/available and it passes the connection list check, it updates
2706 * the bmask for the eligible FCF record for roundrobin failover.
2709 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2711 struct fcf_record *new_fcf_record;
2712 uint32_t boot_flag, addr_mode;
2713 uint16_t fcf_index, next_fcf_index;
2717 /* If link state is not up, no need to proceed */
2718 if (phba->link_state < LPFC_LINK_UP)
2721 /* If FCF discovery period is over, no need to proceed */
2722 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2725 /* Parse the FCF record from the non-embedded mailbox command */
2726 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2728 if (!new_fcf_record) {
2729 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2730 "2767 Mailbox command READ_FCF_RECORD "
2731 "failed to retrieve a FCF record.\n");
2735 /* Check the connection list for eligibility */
2736 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2737 &addr_mode, &vlan_id);
2739 /* Log the FCF record information if turned on */
2740 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2746 /* Update the eligible FCF record index bmask */
2747 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2749 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2752 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2756 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2757 * @phba: pointer to lpfc hba data structure.
2758 * @mboxq: pointer to mailbox data structure.
2760 * This function handles completion of init vfi mailbox command.
2763 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2765 struct lpfc_vport *vport = mboxq->vport;
2768 * VFI not supported on interface type 0, just do the flogi
2769 * Also continue if the VFI is in use - just use the same one.
2771 if (mboxq->u.mb.mbxStatus &&
2772 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2773 LPFC_SLI_INTF_IF_TYPE_0) &&
2774 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2775 lpfc_printf_vlog(vport, KERN_ERR,
2777 "2891 Init VFI mailbox failed 0x%x\n",
2778 mboxq->u.mb.mbxStatus);
2779 mempool_free(mboxq, phba->mbox_mem_pool);
2780 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2784 lpfc_initial_flogi(vport);
2785 mempool_free(mboxq, phba->mbox_mem_pool);
2790 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2791 * @vport: pointer to lpfc_vport data structure.
2793 * This function issue a init_vfi mailbox command to initialize the VFI and
2794 * VPI for the physical port.
2797 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2799 LPFC_MBOXQ_t *mboxq;
2801 struct lpfc_hba *phba = vport->phba;
2803 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2805 lpfc_printf_vlog(vport, KERN_ERR,
2806 LOG_MBOX, "2892 Failed to allocate "
2807 "init_vfi mailbox\n");
2810 lpfc_init_vfi(mboxq, vport);
2811 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2812 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2813 if (rc == MBX_NOT_FINISHED) {
2814 lpfc_printf_vlog(vport, KERN_ERR,
2815 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2816 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2821 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2822 * @phba: pointer to lpfc hba data structure.
2823 * @mboxq: pointer to mailbox data structure.
2825 * This function handles completion of init vpi mailbox command.
2828 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2830 struct lpfc_vport *vport = mboxq->vport;
2831 struct lpfc_nodelist *ndlp;
2832 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2834 if (mboxq->u.mb.mbxStatus) {
2835 lpfc_printf_vlog(vport, KERN_ERR,
2837 "2609 Init VPI mailbox failed 0x%x\n",
2838 mboxq->u.mb.mbxStatus);
2839 mempool_free(mboxq, phba->mbox_mem_pool);
2840 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2843 spin_lock_irq(shost->host_lock);
2844 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2845 spin_unlock_irq(shost->host_lock);
2847 /* If this port is physical port or FDISC is done, do reg_vpi */
2848 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2849 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2851 lpfc_printf_vlog(vport, KERN_ERR,
2853 "2731 Cannot find fabric "
2854 "controller node\n");
2856 lpfc_register_new_vport(phba, vport, ndlp);
2857 mempool_free(mboxq, phba->mbox_mem_pool);
2861 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2862 lpfc_initial_fdisc(vport);
2864 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2865 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2866 "2606 No NPIV Fabric support\n");
2868 mempool_free(mboxq, phba->mbox_mem_pool);
2873 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2874 * @vport: pointer to lpfc_vport data structure.
2876 * This function issue a init_vpi mailbox command to initialize
2877 * VPI for the vport.
2880 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2882 LPFC_MBOXQ_t *mboxq;
2885 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2886 vpi = lpfc_alloc_vpi(vport->phba);
2888 lpfc_printf_vlog(vport, KERN_ERR,
2890 "3303 Failed to obtain vport vpi\n");
2891 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2897 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2899 lpfc_printf_vlog(vport, KERN_ERR,
2900 LOG_MBOX, "2607 Failed to allocate "
2901 "init_vpi mailbox\n");
2904 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2905 mboxq->vport = vport;
2906 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2907 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2908 if (rc == MBX_NOT_FINISHED) {
2909 lpfc_printf_vlog(vport, KERN_ERR,
2910 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2911 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2916 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2917 * @phba: pointer to lpfc hba data structure.
2919 * This function loops through the list of vports on the @phba and issues an
2920 * FDISC if possible.
2923 lpfc_start_fdiscs(struct lpfc_hba *phba)
2925 struct lpfc_vport **vports;
2928 vports = lpfc_create_vport_work_array(phba);
2929 if (vports != NULL) {
2930 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2931 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2933 /* There are no vpi for this vport */
2934 if (vports[i]->vpi > phba->max_vpi) {
2935 lpfc_vport_set_state(vports[i],
2939 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2940 lpfc_vport_set_state(vports[i],
2944 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2945 lpfc_issue_init_vpi(vports[i]);
2948 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2949 lpfc_initial_fdisc(vports[i]);
2951 lpfc_vport_set_state(vports[i],
2952 FC_VPORT_NO_FABRIC_SUPP);
2953 lpfc_printf_vlog(vports[i], KERN_ERR,
2956 "Fabric support\n");
2960 lpfc_destroy_vport_work_array(phba, vports);
2964 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2966 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
2967 struct lpfc_vport *vport = mboxq->vport;
2968 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2971 * VFI not supported for interface type 0, so ignore any mailbox
2972 * error (except VFI in use) and continue with the discovery.
2974 if (mboxq->u.mb.mbxStatus &&
2975 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2976 LPFC_SLI_INTF_IF_TYPE_0) &&
2977 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2978 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2979 "2018 REG_VFI mbxStatus error x%x "
2981 mboxq->u.mb.mbxStatus, vport->port_state);
2982 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2983 /* FLOGI failed, use loop map to make discovery list */
2984 lpfc_disc_list_loopmap(vport);
2985 /* Start discovery */
2986 lpfc_disc_start(vport);
2989 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2993 /* If the VFI is already registered, there is nothing else to do
2994 * Unless this was a VFI update and we are in PT2PT mode, then
2995 * we should drop through to set the port state to ready.
2997 if (vport->fc_flag & FC_VFI_REGISTERED)
2998 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2999 vport->fc_flag & FC_PT2PT))
3002 /* The VPI is implicitly registered when the VFI is registered */
3003 spin_lock_irq(shost->host_lock);
3004 vport->vpi_state |= LPFC_VPI_REGISTERED;
3005 vport->fc_flag |= FC_VFI_REGISTERED;
3006 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3007 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3008 spin_unlock_irq(shost->host_lock);
3010 /* In case SLI4 FC loopback test, we are ready */
3011 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3012 (phba->link_flag & LS_LOOPBACK_MODE)) {
3013 phba->link_state = LPFC_HBA_READY;
3017 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3018 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3019 "alpacnt:%d LinkState:%x topology:%x\n",
3020 vport->port_state, vport->fc_flag, vport->fc_myDID,
3021 vport->phba->alpa_map[0],
3022 phba->link_state, phba->fc_topology);
3024 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3026 * For private loop or for NPort pt2pt,
3027 * just start discovery and we are done.
3029 if ((vport->fc_flag & FC_PT2PT) ||
3030 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3031 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3033 /* Use loop map to make discovery list */
3034 lpfc_disc_list_loopmap(vport);
3035 /* Start discovery */
3036 if (vport->fc_flag & FC_PT2PT)
3037 vport->port_state = LPFC_VPORT_READY;
3039 lpfc_disc_start(vport);
3041 lpfc_start_fdiscs(phba);
3042 lpfc_do_scr_ns_plogi(phba, vport);
3047 mempool_free(mboxq, phba->mbox_mem_pool);
3049 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3056 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3058 MAILBOX_t *mb = &pmb->u.mb;
3059 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3060 struct lpfc_vport *vport = pmb->vport;
3061 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3062 struct serv_parm *sp = &vport->fc_sparam;
3065 /* Check for error */
3066 if (mb->mbxStatus) {
3067 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3068 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3069 "0319 READ_SPARAM mbxStatus error x%x "
3071 mb->mbxStatus, vport->port_state);
3072 lpfc_linkdown(phba);
3076 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3077 sizeof (struct serv_parm));
3079 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3080 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3081 ed_tov = (ed_tov + 999999) / 1000000;
3083 phba->fc_edtov = ed_tov;
3084 phba->fc_ratov = (2 * ed_tov) / 1000;
3085 if (phba->fc_ratov < FF_DEF_RATOV) {
3086 /* RA_TOV should be atleast 10sec for initial flogi */
3087 phba->fc_ratov = FF_DEF_RATOV;
3090 lpfc_update_vport_wwn(vport);
3091 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3092 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3093 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3094 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3097 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3099 mempool_free(pmb, phba->mbox_mem_pool);
3101 /* Check if sending the FLOGI is being deferred to after we get
3102 * up to date CSPs from MBX_READ_SPARAM.
3104 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3105 lpfc_initial_flogi(vport);
3106 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3111 pmb->ctx_buf = NULL;
3112 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3114 lpfc_issue_clear_la(phba, vport);
3115 mempool_free(pmb, phba->mbox_mem_pool);
3120 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3122 struct lpfc_vport *vport = phba->pport;
3123 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3124 struct Scsi_Host *shost;
3126 struct lpfc_dmabuf *mp;
3128 struct fcf_record *fcf_record;
3129 uint32_t fc_flags = 0;
3130 unsigned long iflags;
3132 spin_lock_irqsave(&phba->hbalock, iflags);
3133 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3135 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3136 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3137 case LPFC_LINK_SPEED_1GHZ:
3138 case LPFC_LINK_SPEED_2GHZ:
3139 case LPFC_LINK_SPEED_4GHZ:
3140 case LPFC_LINK_SPEED_8GHZ:
3141 case LPFC_LINK_SPEED_10GHZ:
3142 case LPFC_LINK_SPEED_16GHZ:
3143 case LPFC_LINK_SPEED_32GHZ:
3144 case LPFC_LINK_SPEED_64GHZ:
3145 case LPFC_LINK_SPEED_128GHZ:
3148 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3153 if (phba->fc_topology &&
3154 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3155 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3156 "3314 Toplogy changed was 0x%x is 0x%x\n",
3158 bf_get(lpfc_mbx_read_top_topology, la));
3159 phba->fc_topology_changed = 1;
3162 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3163 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
3165 shost = lpfc_shost_from_vport(vport);
3166 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3167 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3169 /* if npiv is enabled and this adapter supports npiv log
3170 * a message that npiv is not supported in this topology
3172 if (phba->cfg_enable_npiv && phba->max_vpi)
3173 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3174 "1309 Link Up Event npiv not supported in loop "
3176 /* Get Loop Map information */
3177 if (bf_get(lpfc_mbx_read_top_il, la))
3178 fc_flags |= FC_LBIT;
3180 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3181 i = la->lilpBde64.tus.f.bdeSize;
3184 phba->alpa_map[0] = 0;
3186 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3197 numalpa = phba->alpa_map[0];
3199 while (j < numalpa) {
3200 memset(un.pamap, 0, 16);
3201 for (k = 1; j < numalpa; k++) {
3203 phba->alpa_map[j + 1];
3208 /* Link Up Event ALPA map */
3209 lpfc_printf_log(phba,
3212 "1304 Link Up Event "
3213 "ALPA map Data: x%x "
3215 un.pa.wd1, un.pa.wd2,
3216 un.pa.wd3, un.pa.wd4);
3221 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3222 if (phba->max_vpi && phba->cfg_enable_npiv &&
3223 (phba->sli_rev >= LPFC_SLI_REV3))
3224 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3226 vport->fc_myDID = phba->fc_pref_DID;
3227 fc_flags |= FC_LBIT;
3229 spin_unlock_irqrestore(&phba->hbalock, iflags);
3232 spin_lock_irqsave(shost->host_lock, iflags);
3233 vport->fc_flag |= fc_flags;
3234 spin_unlock_irqrestore(shost->host_lock, iflags);
3240 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3241 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3244 vport->port_state = LPFC_LOCAL_CFG_LINK;
3245 lpfc_config_link(phba, cfglink_mbox);
3246 cfglink_mbox->vport = vport;
3247 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3248 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3249 if (rc == MBX_NOT_FINISHED) {
3250 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3255 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3259 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3261 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3264 sparam_mbox->vport = vport;
3265 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3266 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3267 if (rc == MBX_NOT_FINISHED) {
3268 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3269 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3271 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3275 if (phba->hba_flag & HBA_FCOE_MODE) {
3276 vport->port_state = LPFC_VPORT_UNKNOWN;
3278 * Add the driver's default FCF record at FCF index 0 now. This
3279 * is phase 1 implementation that support FCF index 0 and driver
3282 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3283 fcf_record = kzalloc(sizeof(struct fcf_record),
3285 if (unlikely(!fcf_record)) {
3286 lpfc_printf_log(phba, KERN_ERR,
3288 "2554 Could not allocate memory for "
3294 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3295 LPFC_FCOE_FCF_DEF_INDEX);
3296 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3298 lpfc_printf_log(phba, KERN_ERR,
3300 "2013 Could not manually add FCF "
3301 "record 0, status %d\n", rc);
3309 * The driver is expected to do FIP/FCF. Call the port
3310 * and get the FCF Table.
3312 spin_lock_irqsave(&phba->hbalock, iflags);
3313 if (phba->hba_flag & FCF_TS_INPROG) {
3314 spin_unlock_irqrestore(&phba->hbalock, iflags);
3317 /* This is the initial FCF discovery scan */
3318 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3319 spin_unlock_irqrestore(&phba->hbalock, iflags);
3320 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3321 "2778 Start FCF table scan at linkup\n");
3322 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3323 LPFC_FCOE_FCF_GET_FIRST);
3325 spin_lock_irqsave(&phba->hbalock, iflags);
3326 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3327 spin_unlock_irqrestore(&phba->hbalock, iflags);
3330 /* Reset FCF roundrobin bmask for new discovery */
3331 lpfc_sli4_clear_fcf_rr_bmask(phba);
3333 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
3334 !(phba->link_flag & LS_LOOPBACK_MODE))
3335 phba->hba_flag |= HBA_DEFER_FLOGI;
3338 /* Prepare for LINK up registrations */
3339 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3340 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3341 init_utsname()->nodename);
3344 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3345 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3346 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3347 vport->port_state, sparam_mbox, cfglink_mbox);
3348 lpfc_issue_clear_la(phba, vport);
3353 lpfc_enable_la(struct lpfc_hba *phba)
3356 struct lpfc_sli *psli = &phba->sli;
3357 spin_lock_irq(&phba->hbalock);
3358 psli->sli_flag |= LPFC_PROCESS_LA;
3359 if (phba->sli_rev <= LPFC_SLI_REV3) {
3360 control = readl(phba->HCregaddr);
3361 control |= HC_LAINT_ENA;
3362 writel(control, phba->HCregaddr);
3363 readl(phba->HCregaddr); /* flush */
3365 spin_unlock_irq(&phba->hbalock);
3369 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3371 lpfc_linkdown(phba);
3372 lpfc_enable_la(phba);
3373 lpfc_unregister_unused_fcf(phba);
3374 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3379 * This routine handles processing a READ_TOPOLOGY mailbox
3380 * command upon completion. It is setup in the LPFC_MBOXQ
3381 * as the completion routine when the command is
3382 * handed off to the SLI layer. SLI4 only.
3385 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3387 struct lpfc_vport *vport = pmb->vport;
3388 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3389 struct lpfc_mbx_read_top *la;
3390 struct lpfc_sli_ring *pring;
3391 MAILBOX_t *mb = &pmb->u.mb;
3392 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3394 unsigned long iflags;
3396 /* Unblock ELS traffic */
3397 pring = lpfc_phba_elsring(phba);
3399 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3401 /* Check for error */
3402 if (mb->mbxStatus) {
3403 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3404 "1307 READ_LA mbox error x%x state x%x\n",
3405 mb->mbxStatus, vport->port_state);
3406 lpfc_mbx_issue_link_down(phba);
3407 phba->link_state = LPFC_HBA_ERROR;
3408 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3411 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3412 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3414 memcpy(&phba->alpa_map[0], mp->virt, 128);
3416 spin_lock_irqsave(shost->host_lock, iflags);
3417 if (bf_get(lpfc_mbx_read_top_pb, la))
3418 vport->fc_flag |= FC_BYPASSED_MODE;
3420 vport->fc_flag &= ~FC_BYPASSED_MODE;
3421 spin_unlock_irqrestore(shost->host_lock, iflags);
3423 if (phba->fc_eventTag <= la->eventTag) {
3424 phba->fc_stat.LinkMultiEvent++;
3425 if (attn_type == LPFC_ATT_LINK_UP)
3426 if (phba->fc_eventTag != 0)
3427 lpfc_linkdown(phba);
3430 phba->fc_eventTag = la->eventTag;
3431 if (phba->sli_rev < LPFC_SLI_REV4) {
3432 spin_lock_irqsave(&phba->hbalock, iflags);
3433 if (bf_get(lpfc_mbx_read_top_mm, la))
3434 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3436 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3437 spin_unlock_irqrestore(&phba->hbalock, iflags);
3440 phba->link_events++;
3441 if ((attn_type == LPFC_ATT_LINK_UP) &&
3442 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3443 phba->fc_stat.LinkUp++;
3444 if (phba->link_flag & LS_LOOPBACK_MODE) {
3445 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3446 "1306 Link Up Event in loop back mode "
3447 "x%x received Data: x%x x%x x%x x%x\n",
3448 la->eventTag, phba->fc_eventTag,
3449 bf_get(lpfc_mbx_read_top_alpa_granted,
3451 bf_get(lpfc_mbx_read_top_link_spd, la),
3454 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3455 "1303 Link Up Event x%x received "
3456 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3457 la->eventTag, phba->fc_eventTag,
3458 bf_get(lpfc_mbx_read_top_alpa_granted,
3460 bf_get(lpfc_mbx_read_top_link_spd, la),
3462 bf_get(lpfc_mbx_read_top_mm, la),
3463 bf_get(lpfc_mbx_read_top_fa, la),
3464 phba->wait_4_mlo_maint_flg);
3466 lpfc_mbx_process_link_up(phba, la);
3467 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3468 attn_type == LPFC_ATT_UNEXP_WWPN) {
3469 phba->fc_stat.LinkDown++;
3470 if (phba->link_flag & LS_LOOPBACK_MODE)
3471 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3472 "1308 Link Down Event in loop back mode "
3474 "Data: x%x x%x x%x\n",
3475 la->eventTag, phba->fc_eventTag,
3476 phba->pport->port_state, vport->fc_flag);
3477 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3478 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3479 "1313 Link Down Unexpected FA WWPN Event x%x "
3480 "received Data: x%x x%x x%x x%x x%x\n",
3481 la->eventTag, phba->fc_eventTag,
3482 phba->pport->port_state, vport->fc_flag,
3483 bf_get(lpfc_mbx_read_top_mm, la),
3484 bf_get(lpfc_mbx_read_top_fa, la));
3486 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3487 "1305 Link Down Event x%x received "
3488 "Data: x%x x%x x%x x%x x%x\n",
3489 la->eventTag, phba->fc_eventTag,
3490 phba->pport->port_state, vport->fc_flag,
3491 bf_get(lpfc_mbx_read_top_mm, la),
3492 bf_get(lpfc_mbx_read_top_fa, la));
3493 lpfc_mbx_issue_link_down(phba);
3495 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3496 attn_type == LPFC_ATT_LINK_UP) {
3497 if (phba->link_state != LPFC_LINK_DOWN) {
3498 phba->fc_stat.LinkDown++;
3499 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3500 "1312 Link Down Event x%x received "
3501 "Data: x%x x%x x%x\n",
3502 la->eventTag, phba->fc_eventTag,
3503 phba->pport->port_state, vport->fc_flag);
3504 lpfc_mbx_issue_link_down(phba);
3506 lpfc_enable_la(phba);
3508 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3509 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3510 "Data: x%x x%x x%x\n",
3511 la->eventTag, phba->fc_eventTag,
3512 phba->pport->port_state, vport->fc_flag);
3514 * The cmnd that triggered this will be waiting for this
3517 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3518 if (phba->wait_4_mlo_maint_flg) {
3519 phba->wait_4_mlo_maint_flg = 0;
3520 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3524 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3525 bf_get(lpfc_mbx_read_top_fa, la)) {
3526 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3527 lpfc_issue_clear_la(phba, vport);
3528 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3530 bf_get(lpfc_mbx_read_top_fa, la));
3533 lpfc_mbx_cmpl_read_topology_free_mbuf:
3534 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3536 mempool_free(pmb, phba->mbox_mem_pool);
3541 * This routine handles processing a REG_LOGIN mailbox
3542 * command upon completion. It is setup in the LPFC_MBOXQ
3543 * as the completion routine when the command is
3544 * handed off to the SLI layer.
3547 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3549 struct lpfc_vport *vport = pmb->vport;
3550 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3551 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3554 pmb->ctx_buf = NULL;
3555 pmb->ctx_ndlp = NULL;
3557 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3558 "0002 rpi:%x DID:%x flg:%x %d map:%x x%px\n",
3559 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3560 kref_read(&ndlp->kref),
3561 ndlp->nlp_usg_map, ndlp);
3562 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3563 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3565 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3566 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3567 /* We rcvd a rscn after issuing this
3568 * mbox reg login, we may have cycled
3569 * back through the state and be
3570 * back at reg login state so this
3571 * mbox needs to be ignored becase
3572 * there is another reg login in
3575 spin_lock_irq(shost->host_lock);
3576 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3577 spin_unlock_irq(shost->host_lock);
3580 * We cannot leave the RPI registered because
3581 * if we go thru discovery again for this ndlp
3582 * a subsequent REG_RPI will fail.
3584 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3585 lpfc_unreg_rpi(vport, ndlp);
3588 /* Call state machine */
3589 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3591 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3593 mempool_free(pmb, phba->mbox_mem_pool);
3594 /* decrement the node reference count held for this callback
3603 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3605 MAILBOX_t *mb = &pmb->u.mb;
3606 struct lpfc_vport *vport = pmb->vport;
3607 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3609 switch (mb->mbxStatus) {
3612 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3613 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3616 /* If VPI is busy, reset the HBA */
3618 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3619 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3620 vport->vpi, mb->mbxStatus);
3621 if (!(phba->pport->load_flag & FC_UNLOADING))
3622 lpfc_workq_post_event(phba, NULL, NULL,
3623 LPFC_EVT_RESET_HBA);
3625 spin_lock_irq(shost->host_lock);
3626 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3627 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3628 spin_unlock_irq(shost->host_lock);
3629 vport->unreg_vpi_cmpl = VPORT_OK;
3630 mempool_free(pmb, phba->mbox_mem_pool);
3631 lpfc_cleanup_vports_rrqs(vport, NULL);
3633 * This shost reference might have been taken at the beginning of
3634 * lpfc_vport_delete()
3636 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3637 scsi_host_put(shost);
3641 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3643 struct lpfc_hba *phba = vport->phba;
3647 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3651 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3652 mbox->vport = vport;
3653 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3654 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3655 if (rc == MBX_NOT_FINISHED) {
3656 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3657 "1800 Could not issue unreg_vpi\n");
3658 mempool_free(mbox, phba->mbox_mem_pool);
3659 vport->unreg_vpi_cmpl = VPORT_ERROR;
3666 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3668 struct lpfc_vport *vport = pmb->vport;
3669 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3670 MAILBOX_t *mb = &pmb->u.mb;
3672 switch (mb->mbxStatus) {
3676 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3677 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3679 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3680 spin_lock_irq(shost->host_lock);
3681 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3682 spin_unlock_irq(shost->host_lock);
3683 vport->fc_myDID = 0;
3685 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3686 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3687 if (phba->nvmet_support)
3688 lpfc_nvmet_update_targetport(phba);
3690 lpfc_nvme_update_localport(vport);
3695 spin_lock_irq(shost->host_lock);
3696 vport->vpi_state |= LPFC_VPI_REGISTERED;
3697 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3698 spin_unlock_irq(shost->host_lock);
3699 vport->num_disc_nodes = 0;
3700 /* go thru NPR list and issue ELS PLOGIs */
3701 if (vport->fc_npr_cnt)
3702 lpfc_els_disc_plogi(vport);
3704 if (!vport->num_disc_nodes) {
3705 spin_lock_irq(shost->host_lock);
3706 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3707 spin_unlock_irq(shost->host_lock);
3708 lpfc_can_disctmo(vport);
3710 vport->port_state = LPFC_VPORT_READY;
3713 mempool_free(pmb, phba->mbox_mem_pool);
3718 * lpfc_create_static_vport - Read HBA config region to create static vports.
3719 * @phba: pointer to lpfc hba data structure.
3721 * This routine issue a DUMP mailbox command for config region 22 to get
3722 * the list of static vports to be created. The function create vports
3723 * based on the information returned from the HBA.
3726 lpfc_create_static_vport(struct lpfc_hba *phba)
3728 LPFC_MBOXQ_t *pmb = NULL;
3730 struct static_vport_info *vport_info;
3731 int mbx_wait_rc = 0, i;
3732 struct fc_vport_identifiers vport_id;
3733 struct fc_vport *new_fc_vport;
3734 struct Scsi_Host *shost;
3735 struct lpfc_vport *vport;
3736 uint16_t offset = 0;
3737 uint8_t *vport_buff;
3738 struct lpfc_dmabuf *mp;
3739 uint32_t byte_count = 0;
3741 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3744 "0542 lpfc_create_static_vport failed to"
3745 " allocate mailbox memory\n");
3748 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3751 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3754 "0543 lpfc_create_static_vport failed to"
3755 " allocate vport_info\n");
3756 mempool_free(pmb, phba->mbox_mem_pool);
3760 vport_buff = (uint8_t *) vport_info;
3762 /* free dma buffer from previous round */
3764 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3765 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3768 if (lpfc_dump_static_vport(phba, pmb, offset))
3771 pmb->vport = phba->pport;
3772 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3775 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3776 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3777 "0544 lpfc_create_static_vport failed to"
3778 " issue dump mailbox command ret 0x%x "
3780 mbx_wait_rc, mb->mbxStatus);
3784 if (phba->sli_rev == LPFC_SLI_REV4) {
3785 byte_count = pmb->u.mqe.un.mb_words[5];
3786 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3787 if (byte_count > sizeof(struct static_vport_info) -
3789 byte_count = sizeof(struct static_vport_info)
3791 memcpy(vport_buff + offset, mp->virt, byte_count);
3792 offset += byte_count;
3794 if (mb->un.varDmp.word_cnt >
3795 sizeof(struct static_vport_info) - offset)
3796 mb->un.varDmp.word_cnt =
3797 sizeof(struct static_vport_info)
3799 byte_count = mb->un.varDmp.word_cnt;
3800 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3801 vport_buff + offset,
3804 offset += byte_count;
3807 } while (byte_count &&
3808 offset < sizeof(struct static_vport_info));
3811 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3812 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3813 != VPORT_INFO_REV)) {
3814 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3815 "0545 lpfc_create_static_vport bad"
3816 " information header 0x%x 0x%x\n",
3817 le32_to_cpu(vport_info->signature),
3818 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3823 shost = lpfc_shost_from_vport(phba->pport);
3825 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3826 memset(&vport_id, 0, sizeof(vport_id));
3827 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3828 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3829 if (!vport_id.port_name || !vport_id.node_name)
3832 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3833 vport_id.vport_type = FC_PORTTYPE_NPIV;
3834 vport_id.disable = false;
3835 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3837 if (!new_fc_vport) {
3838 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3839 "0546 lpfc_create_static_vport failed to"
3844 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3845 vport->vport_flag |= STATIC_VPORT;
3850 if (mbx_wait_rc != MBX_TIMEOUT) {
3852 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3853 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3856 mempool_free(pmb, phba->mbox_mem_pool);
3863 * This routine handles processing a Fabric REG_LOGIN mailbox
3864 * command upon completion. It is setup in the LPFC_MBOXQ
3865 * as the completion routine when the command is
3866 * handed off to the SLI layer.
3869 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3871 struct lpfc_vport *vport = pmb->vport;
3872 MAILBOX_t *mb = &pmb->u.mb;
3873 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3874 struct lpfc_nodelist *ndlp;
3875 struct Scsi_Host *shost;
3877 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3878 pmb->ctx_ndlp = NULL;
3879 pmb->ctx_buf = NULL;
3881 if (mb->mbxStatus) {
3882 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3883 "0258 Register Fabric login error: 0x%x\n",
3885 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3887 mempool_free(pmb, phba->mbox_mem_pool);
3889 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3890 /* FLOGI failed, use loop map to make discovery list */
3891 lpfc_disc_list_loopmap(vport);
3893 /* Start discovery */
3894 lpfc_disc_start(vport);
3895 /* Decrement the reference count to ndlp after the
3896 * reference to the ndlp are done.
3902 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3903 /* Decrement the reference count to ndlp after the reference
3904 * to the ndlp are done.
3910 if (phba->sli_rev < LPFC_SLI_REV4)
3911 ndlp->nlp_rpi = mb->un.varWords[0];
3912 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3913 ndlp->nlp_type |= NLP_FABRIC;
3914 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3916 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3917 /* when physical port receive logo donot start
3918 * vport discovery */
3919 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3920 lpfc_start_fdiscs(phba);
3922 shost = lpfc_shost_from_vport(vport);
3923 spin_lock_irq(shost->host_lock);
3924 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3925 spin_unlock_irq(shost->host_lock);
3927 lpfc_do_scr_ns_plogi(phba, vport);
3930 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3932 mempool_free(pmb, phba->mbox_mem_pool);
3934 /* Drop the reference count from the mbox at the end after
3935 * all the current reference to the ndlp have been done.
3942 * This routine will issue a GID_FT for each FC4 Type supported
3943 * by the driver. ALL GID_FTs must complete before discovery is started.
3946 lpfc_issue_gidft(struct lpfc_vport *vport)
3948 /* Good status, issue CT Request to NameServer */
3949 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3950 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
3951 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3952 /* Cannot issue NameServer FCP Query, so finish up
3955 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3956 "0604 %s FC TYPE %x %s\n",
3957 "Failed to issue GID_FT to ",
3959 "Finishing discovery.");
3965 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3966 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3967 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3968 /* Cannot issue NameServer NVME Query, so finish up
3971 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3972 "0605 %s FC_TYPE %x %s %d\n",
3973 "Failed to issue GID_FT to ",
3975 "Finishing discovery: gidftinp ",
3977 if (vport->gidft_inp == 0)
3982 return vport->gidft_inp;
3986 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3987 * @vport: The virtual port for which this call is being executed.
3989 * This routine will issue a GID_PT to get a list of all N_Ports
3992 * 0 - Failure to issue a GID_PT
3996 lpfc_issue_gidpt(struct lpfc_vport *vport)
3998 /* Good status, issue CT Request to NameServer */
3999 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4000 /* Cannot issue NameServer FCP Query, so finish up
4003 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
4004 "0606 %s Port TYPE %x %s\n",
4005 "Failed to issue GID_PT to ",
4007 "Finishing discovery.");
4015 * This routine handles processing a NameServer REG_LOGIN mailbox
4016 * command upon completion. It is setup in the LPFC_MBOXQ
4017 * as the completion routine when the command is
4018 * handed off to the SLI layer.
4021 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4023 MAILBOX_t *mb = &pmb->u.mb;
4024 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4025 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4026 struct lpfc_vport *vport = pmb->vport;
4028 pmb->ctx_buf = NULL;
4029 pmb->ctx_ndlp = NULL;
4030 vport->gidft_inp = 0;
4032 if (mb->mbxStatus) {
4033 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4034 "0260 Register NameServer error: 0x%x\n",
4038 /* decrement the node reference count held for this
4039 * callback function.
4042 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4044 mempool_free(pmb, phba->mbox_mem_pool);
4046 /* If no other thread is using the ndlp, free it */
4047 lpfc_nlp_not_used(ndlp);
4049 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4051 * RegLogin failed, use loop map to make discovery
4054 lpfc_disc_list_loopmap(vport);
4056 /* Start discovery */
4057 lpfc_disc_start(vport);
4060 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4064 if (phba->sli_rev < LPFC_SLI_REV4)
4065 ndlp->nlp_rpi = mb->un.varWords[0];
4066 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4067 ndlp->nlp_type |= NLP_FABRIC;
4068 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4069 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4070 "0003 rpi:%x DID:%x flg:%x %d map%x x%px\n",
4071 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4072 kref_read(&ndlp->kref),
4073 ndlp->nlp_usg_map, ndlp);
4075 if (vport->port_state < LPFC_VPORT_READY) {
4076 /* Link up discovery requires Fabric registration. */
4077 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4078 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4079 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4080 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4082 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4083 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4084 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4086 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4087 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4088 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4091 /* Issue SCR just before NameServer GID_FT Query */
4092 lpfc_issue_els_scr(vport, 0);
4094 lpfc_issue_els_rdf(vport, 0);
4097 vport->fc_ns_retry = 0;
4098 if (lpfc_issue_gidft(vport) == 0)
4102 * At this point in time we may need to wait for multiple
4103 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4105 * decrement the node reference count held for this
4106 * callback function.
4109 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4111 mempool_free(pmb, phba->mbox_mem_pool);
4117 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4119 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4120 struct fc_rport *rport;
4121 struct lpfc_rport_data *rdata;
4122 struct fc_rport_identifiers rport_ids;
4123 struct lpfc_hba *phba = vport->phba;
4125 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4128 /* Remote port has reappeared. Re-register w/ FC transport */
4129 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4130 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4131 rport_ids.port_id = ndlp->nlp_DID;
4132 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4135 * We leave our node pointer in rport->dd_data when we unregister a
4136 * FCP target port. But fc_remote_port_add zeros the space to which
4137 * rport->dd_data points. So, if we're reusing a previously
4138 * registered port, drop the reference that we took the last time we
4139 * registered the port.
4141 rport = ndlp->rport;
4143 rdata = rport->dd_data;
4144 /* break the link before dropping the ref */
4147 if (rdata->pnode == ndlp)
4149 rdata->pnode = NULL;
4151 /* drop reference for earlier registeration */
4152 put_device(&rport->dev);
4155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4156 "rport add: did:x%x flg:x%x type x%x",
4157 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4159 /* Don't add the remote port if unloading. */
4160 if (vport->load_flag & FC_UNLOADING)
4163 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4164 if (!rport || !get_device(&rport->dev)) {
4165 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4166 "Warning: fc_remote_port_add failed\n");
4170 /* initialize static port data */
4171 rport->maxframe_size = ndlp->nlp_maxframe;
4172 rport->supported_classes = ndlp->nlp_class_sup;
4173 rdata = rport->dd_data;
4174 rdata->pnode = lpfc_nlp_get(ndlp);
4176 if (ndlp->nlp_type & NLP_FCP_TARGET)
4177 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4178 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4179 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4180 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4181 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4182 if (ndlp->nlp_type & NLP_NVME_TARGET)
4183 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4184 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4185 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4187 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4188 fc_remote_port_rolechg(rport, rport_ids.roles);
4190 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4191 "3183 rport register x%06x, rport x%px role x%x\n",
4192 ndlp->nlp_DID, rport, rport_ids.roles);
4194 if ((rport->scsi_target_id != -1) &&
4195 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4196 ndlp->nlp_sid = rport->scsi_target_id;
4202 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4204 struct fc_rport *rport = ndlp->rport;
4205 struct lpfc_vport *vport = ndlp->vport;
4207 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4211 "rport delete: did:x%x flg:x%x type x%x",
4212 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4214 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4215 "3184 rport unregister x%06x, rport x%px\n",
4216 ndlp->nlp_DID, rport);
4218 fc_remote_port_delete(rport);
4224 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4227 unsigned long iflags;
4229 spin_lock_irqsave(shost->host_lock, iflags);
4231 case NLP_STE_UNUSED_NODE:
4232 vport->fc_unused_cnt += count;
4234 case NLP_STE_PLOGI_ISSUE:
4235 vport->fc_plogi_cnt += count;
4237 case NLP_STE_ADISC_ISSUE:
4238 vport->fc_adisc_cnt += count;
4240 case NLP_STE_REG_LOGIN_ISSUE:
4241 vport->fc_reglogin_cnt += count;
4243 case NLP_STE_PRLI_ISSUE:
4244 vport->fc_prli_cnt += count;
4246 case NLP_STE_UNMAPPED_NODE:
4247 vport->fc_unmap_cnt += count;
4249 case NLP_STE_MAPPED_NODE:
4250 vport->fc_map_cnt += count;
4252 case NLP_STE_NPR_NODE:
4253 if (vport->fc_npr_cnt == 0 && count == -1)
4254 vport->fc_npr_cnt = 0;
4256 vport->fc_npr_cnt += count;
4259 spin_unlock_irqrestore(shost->host_lock, iflags);
4263 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4264 int old_state, int new_state)
4266 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4268 if (new_state == NLP_STE_UNMAPPED_NODE) {
4269 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4270 ndlp->nlp_type |= NLP_FC_NODE;
4272 if (new_state == NLP_STE_MAPPED_NODE)
4273 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4274 if (new_state == NLP_STE_NPR_NODE)
4275 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4277 /* FCP and NVME Transport interface */
4278 if ((old_state == NLP_STE_MAPPED_NODE ||
4279 old_state == NLP_STE_UNMAPPED_NODE)) {
4281 vport->phba->nport_event_cnt++;
4282 lpfc_unregister_remote_port(ndlp);
4285 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4286 vport->phba->nport_event_cnt++;
4287 if (vport->phba->nvmet_support == 0) {
4288 /* Start devloss if target. */
4289 if (ndlp->nlp_type & NLP_NVME_TARGET)
4290 lpfc_nvme_unregister_port(vport, ndlp);
4292 /* NVMET has no upcall. */
4298 /* FCP and NVME Transport interfaces */
4300 if (new_state == NLP_STE_MAPPED_NODE ||
4301 new_state == NLP_STE_UNMAPPED_NODE) {
4302 if (ndlp->nlp_fc4_type ||
4303 ndlp->nlp_DID == Fabric_DID ||
4304 ndlp->nlp_DID == NameServer_DID ||
4305 ndlp->nlp_DID == FDMI_DID) {
4306 vport->phba->nport_event_cnt++;
4308 * Tell the fc transport about the port, if we haven't
4309 * already. If we have, and it's a scsi entity, be
4311 lpfc_register_remote_port(vport, ndlp);
4313 /* Notify the NVME transport of this new rport. */
4314 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4315 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4316 if (vport->phba->nvmet_support == 0) {
4317 /* Register this rport with the transport.
4318 * Only NVME Target Rports are registered with
4321 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4322 vport->phba->nport_event_cnt++;
4323 lpfc_nvme_register_port(vport, ndlp);
4326 /* Just take an NDLP ref count since the
4327 * target does not register rports.
4334 if ((new_state == NLP_STE_MAPPED_NODE) &&
4335 (vport->stat_data_enabled)) {
4337 * A new target is discovered, if there is no buffer for
4338 * statistical data collection allocate buffer.
4340 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4341 sizeof(struct lpfc_scsicmd_bkt),
4344 if (!ndlp->lat_data)
4345 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4346 "0286 lpfc_nlp_state_cleanup failed to "
4347 "allocate statistical data buffer DID "
4348 "0x%x\n", ndlp->nlp_DID);
4351 * If the node just added to Mapped list was an FCP target,
4352 * but the remote port registration failed or assigned a target
4353 * id outside the presentable range - move the node to the
4356 if ((new_state == NLP_STE_MAPPED_NODE) &&
4357 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4359 ndlp->rport->scsi_target_id == -1 ||
4360 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4361 spin_lock_irq(shost->host_lock);
4362 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4363 spin_unlock_irq(shost->host_lock);
4364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4369 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4371 static char *states[] = {
4372 [NLP_STE_UNUSED_NODE] = "UNUSED",
4373 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4374 [NLP_STE_ADISC_ISSUE] = "ADISC",
4375 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4376 [NLP_STE_PRLI_ISSUE] = "PRLI",
4377 [NLP_STE_LOGO_ISSUE] = "LOGO",
4378 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4379 [NLP_STE_MAPPED_NODE] = "MAPPED",
4380 [NLP_STE_NPR_NODE] = "NPR",
4383 if (state < NLP_STE_MAX_STATE && states[state])
4384 strlcpy(buffer, states[state], size);
4386 snprintf(buffer, size, "unknown (%d)", state);
4391 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4394 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4395 int old_state = ndlp->nlp_state;
4396 char name1[16], name2[16];
4398 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4399 "0904 NPort state transition x%06x, %s -> %s\n",
4401 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4402 lpfc_nlp_state_name(name2, sizeof(name2), state));
4404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4405 "node statechg did:x%x old:%d ste:%d",
4406 ndlp->nlp_DID, old_state, state);
4408 if (old_state == NLP_STE_NPR_NODE &&
4409 state != NLP_STE_NPR_NODE)
4410 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4411 if (old_state == NLP_STE_UNMAPPED_NODE) {
4412 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4413 ndlp->nlp_type &= ~NLP_FC_NODE;
4416 if (list_empty(&ndlp->nlp_listp)) {
4417 spin_lock_irq(shost->host_lock);
4418 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4419 spin_unlock_irq(shost->host_lock);
4420 } else if (old_state)
4421 lpfc_nlp_counters(vport, old_state, -1);
4423 ndlp->nlp_state = state;
4424 lpfc_nlp_counters(vport, state, 1);
4425 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4429 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4431 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4433 if (list_empty(&ndlp->nlp_listp)) {
4434 spin_lock_irq(shost->host_lock);
4435 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4436 spin_unlock_irq(shost->host_lock);
4441 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4445 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4446 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4447 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4448 spin_lock_irq(shost->host_lock);
4449 list_del_init(&ndlp->nlp_listp);
4450 spin_unlock_irq(shost->host_lock);
4451 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4452 NLP_STE_UNUSED_NODE);
4456 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4458 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4459 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4460 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4461 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4462 NLP_STE_UNUSED_NODE);
4465 * lpfc_initialize_node - Initialize all fields of node object
4466 * @vport: Pointer to Virtual Port object.
4467 * @ndlp: Pointer to FC node object.
4468 * @did: FC_ID of the node.
4470 * This function is always called when node object need to be initialized.
4471 * It initializes all the fields of the node object. Although the reference
4472 * to phba from @ndlp can be obtained indirectly through it's reference to
4473 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4474 * to the life-span of the @ndlp might go beyond the existence of @vport as
4475 * the final release of ndlp is determined by its reference count. And, the
4476 * operation on @ndlp needs the reference to phba.
4479 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4482 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4483 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4484 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4485 ndlp->nlp_DID = did;
4486 ndlp->vport = vport;
4487 ndlp->phba = vport->phba;
4488 ndlp->nlp_sid = NLP_NO_SID;
4489 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4490 kref_init(&ndlp->kref);
4491 NLP_INT_NODE_ACT(ndlp);
4492 atomic_set(&ndlp->cmd_pending, 0);
4493 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4494 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4497 struct lpfc_nodelist *
4498 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4501 struct lpfc_hba *phba = vport->phba;
4503 unsigned long flags;
4504 unsigned long *active_rrqs_xri_bitmap = NULL;
4505 int rpi = LPFC_RPI_ALLOC_ERROR;
4506 uint32_t defer_did = 0;
4511 if (phba->sli_rev == LPFC_SLI_REV4) {
4512 if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)
4513 rpi = lpfc_sli4_alloc_rpi(vport->phba);
4515 rpi = ndlp->nlp_rpi;
4517 if (rpi == LPFC_RPI_ALLOC_ERROR) {
4518 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4519 "0359 %s: ndlp:x%px "
4520 "usgmap:x%x refcnt:%d FAILED RPI "
4523 (void *)ndlp, ndlp->nlp_usg_map,
4524 kref_read(&ndlp->kref));
4529 spin_lock_irqsave(&phba->ndlp_lock, flags);
4530 /* The ndlp should not be in memory free mode */
4531 if (NLP_CHK_FREE_REQ(ndlp)) {
4532 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4533 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4534 "0277 %s: ndlp:x%px "
4535 "usgmap:x%x refcnt:%d\n",
4536 __func__, (void *)ndlp, ndlp->nlp_usg_map,
4537 kref_read(&ndlp->kref));
4540 /* The ndlp should not already be in active mode */
4541 if (NLP_CHK_NODE_ACT(ndlp)) {
4542 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4543 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4544 "0278 %s: ndlp:x%px "
4545 "usgmap:x%x refcnt:%d\n",
4546 __func__, (void *)ndlp, ndlp->nlp_usg_map,
4547 kref_read(&ndlp->kref));
4551 /* First preserve the orginal DID, xri_bitmap and some flags */
4552 did = ndlp->nlp_DID;
4553 flag = (ndlp->nlp_flag & NLP_UNREG_INP);
4554 if (flag & NLP_UNREG_INP)
4555 defer_did = ndlp->nlp_defer_did;
4556 if (phba->sli_rev == LPFC_SLI_REV4)
4557 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
4559 /* Zero ndlp except of ndlp linked list pointer */
4560 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4561 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
4563 /* Next reinitialize and restore saved objects */
4564 lpfc_initialize_node(vport, ndlp, did);
4565 ndlp->nlp_flag |= flag;
4566 if (flag & NLP_UNREG_INP)
4567 ndlp->nlp_defer_did = defer_did;
4568 if (phba->sli_rev == LPFC_SLI_REV4)
4569 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4571 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4572 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4573 ndlp->nlp_rpi = rpi;
4574 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4575 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4576 "map:%x x%px\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4578 kref_read(&ndlp->kref),
4579 ndlp->nlp_usg_map, ndlp);
4583 if (state != NLP_STE_UNUSED_NODE)
4584 lpfc_nlp_set_state(vport, ndlp, state);
4586 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4587 "0013 rpi:%x DID:%x flg:%x refcnt:%d "
4588 "map:%x x%px STATE=UNUSED\n",
4589 ndlp->nlp_rpi, ndlp->nlp_DID,
4591 kref_read(&ndlp->kref),
4592 ndlp->nlp_usg_map, ndlp);
4594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4595 "node enable: did:x%x",
4596 ndlp->nlp_DID, 0, 0);
4600 if (phba->sli_rev == LPFC_SLI_REV4) {
4601 lpfc_sli4_free_rpi(vport->phba, rpi);
4602 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4608 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4611 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4612 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4613 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4614 * until ALL other outstanding threads have completed. We check
4615 * that the ndlp not already in the UNUSED state before we proceed.
4617 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4619 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4620 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4621 lpfc_cleanup_vports_rrqs(vport, ndlp);
4622 lpfc_unreg_rpi(vport, ndlp);
4630 * Start / ReStart rescue timer for Discovery / RSCN handling
4633 lpfc_set_disctmo(struct lpfc_vport *vport)
4635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4636 struct lpfc_hba *phba = vport->phba;
4639 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4640 /* For FAN, timeout should be greater than edtov */
4641 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4643 /* Normal discovery timeout should be > than ELS/CT timeout
4644 * FC spec states we need 3 * ratov for CT requests
4646 tmo = ((phba->fc_ratov * 3) + 3);
4650 if (!timer_pending(&vport->fc_disctmo)) {
4651 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4652 "set disc timer: tmo:x%x state:x%x flg:x%x",
4653 tmo, vport->port_state, vport->fc_flag);
4656 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4657 spin_lock_irq(shost->host_lock);
4658 vport->fc_flag |= FC_DISC_TMO;
4659 spin_unlock_irq(shost->host_lock);
4661 /* Start Discovery Timer state <hba_state> */
4662 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4663 "0247 Start Discovery Timer state x%x "
4664 "Data: x%x x%lx x%x x%x\n",
4665 vport->port_state, tmo,
4666 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4667 vport->fc_adisc_cnt);
4673 * Cancel rescue timer for Discovery / RSCN handling
4676 lpfc_can_disctmo(struct lpfc_vport *vport)
4678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4679 unsigned long iflags;
4681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4682 "can disc timer: state:x%x rtry:x%x flg:x%x",
4683 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4685 /* Turn off discovery timer if its running */
4686 if (vport->fc_flag & FC_DISC_TMO) {
4687 spin_lock_irqsave(shost->host_lock, iflags);
4688 vport->fc_flag &= ~FC_DISC_TMO;
4689 spin_unlock_irqrestore(shost->host_lock, iflags);
4690 del_timer_sync(&vport->fc_disctmo);
4691 spin_lock_irqsave(&vport->work_port_lock, iflags);
4692 vport->work_port_events &= ~WORKER_DISC_TMO;
4693 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4696 /* Cancel Discovery Timer state <hba_state> */
4697 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4698 "0248 Cancel Discovery Timer state x%x "
4699 "Data: x%x x%x x%x\n",
4700 vport->port_state, vport->fc_flag,
4701 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4706 * Check specified ring for outstanding IOCB on the SLI queue
4707 * Return true if iocb matches the specified nport
4710 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4711 struct lpfc_sli_ring *pring,
4712 struct lpfc_iocbq *iocb,
4713 struct lpfc_nodelist *ndlp)
4715 IOCB_t *icmd = &iocb->iocb;
4716 struct lpfc_vport *vport = ndlp->vport;
4718 if (iocb->vport != vport)
4721 if (pring->ringno == LPFC_ELS_RING) {
4722 switch (icmd->ulpCommand) {
4723 case CMD_GEN_REQUEST64_CR:
4724 if (iocb->context_un.ndlp == ndlp)
4727 case CMD_ELS_REQUEST64_CR:
4728 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4731 case CMD_XMIT_ELS_RSP64_CX:
4732 if (iocb->context1 == (uint8_t *) ndlp)
4736 } else if (pring->ringno == LPFC_FCP_RING) {
4737 /* Skip match check if waiting to relogin to FCP target */
4738 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4739 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4742 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4750 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4751 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4752 struct list_head *dequeue_list)
4754 struct lpfc_iocbq *iocb, *next_iocb;
4756 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4757 /* Check to see if iocb matches the nport */
4758 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4759 /* match, dequeue */
4760 list_move_tail(&iocb->list, dequeue_list);
4765 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4766 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4768 struct lpfc_sli *psli = &phba->sli;
4771 spin_lock_irq(&phba->hbalock);
4772 for (i = 0; i < psli->num_rings; i++)
4773 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4775 spin_unlock_irq(&phba->hbalock);
4779 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4780 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4782 struct lpfc_sli_ring *pring;
4783 struct lpfc_queue *qp = NULL;
4785 spin_lock_irq(&phba->hbalock);
4786 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4790 spin_lock(&pring->ring_lock);
4791 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
4792 spin_unlock(&pring->ring_lock);
4794 spin_unlock_irq(&phba->hbalock);
4798 * Free resources / clean up outstanding I/Os
4799 * associated with nlp_rpi in the LPFC_NODELIST entry.
4802 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4804 LIST_HEAD(completions);
4806 lpfc_fabric_abort_nport(ndlp);
4809 * Everything that matches on txcmplq will be returned
4810 * by firmware with a no rpi error.
4812 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4813 if (phba->sli_rev != LPFC_SLI_REV4)
4814 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4816 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
4819 /* Cancel all the IOCBs from the completions list */
4820 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4827 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4828 * @phba: Pointer to HBA context object.
4829 * @pmb: Pointer to mailbox object.
4831 * This function will issue an ELS LOGO command after completing
4835 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4837 struct lpfc_vport *vport = pmb->vport;
4838 struct lpfc_nodelist *ndlp;
4840 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
4843 lpfc_issue_els_logo(vport, ndlp, 0);
4844 mempool_free(pmb, phba->mbox_mem_pool);
4846 /* Check to see if there are any deferred events to process */
4847 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4848 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4849 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4850 "1434 UNREG cmpl deferred logo x%x "
4851 "on NPort x%x Data: x%x x%px\n",
4852 ndlp->nlp_rpi, ndlp->nlp_DID,
4853 ndlp->nlp_defer_did, ndlp);
4855 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4856 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4857 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4859 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4860 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
4861 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
4862 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4864 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4869 * Sets the mailbox completion handler to be used for the
4870 * unreg_rpi command. The handler varies based on the state of
4871 * the port and what will be happening to the rpi next.
4874 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
4875 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
4877 unsigned long iflags;
4879 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4880 mbox->ctx_ndlp = ndlp;
4881 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4883 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
4884 (!(vport->load_flag & FC_UNLOADING)) &&
4885 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
4886 LPFC_SLI_INTF_IF_TYPE_2) &&
4887 (kref_read(&ndlp->kref) > 0)) {
4888 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4889 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
4891 if (vport->load_flag & FC_UNLOADING) {
4892 if (phba->sli_rev == LPFC_SLI_REV4) {
4893 spin_lock_irqsave(&vport->phba->ndlp_lock,
4895 ndlp->nlp_flag |= NLP_RELEASE_RPI;
4896 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
4901 mbox->ctx_ndlp = ndlp;
4902 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4907 * Free rpi associated with LPFC_NODELIST entry.
4908 * This routine is called from lpfc_freenode(), when we are removing
4909 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4910 * LOGO that completes successfully, and we are waiting to PLOGI back
4911 * to the remote NPort. In addition, it is called after we receive
4912 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4913 * we are waiting to PLOGI back to the remote NPort.
4916 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4918 struct lpfc_hba *phba = vport->phba;
4920 int rc, acc_plogi = 1;
4923 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4924 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4925 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4926 lpfc_printf_vlog(vport, KERN_INFO,
4927 LOG_NODE | LOG_DISCOVERY,
4928 "3366 RPI x%x needs to be "
4929 "unregistered nlp_flag x%x "
4931 ndlp->nlp_rpi, ndlp->nlp_flag,
4934 /* If there is already an UNREG in progress for this ndlp,
4935 * no need to queue up another one.
4937 if (ndlp->nlp_flag & NLP_UNREG_INP) {
4938 lpfc_printf_vlog(vport, KERN_INFO,
4939 LOG_NODE | LOG_DISCOVERY,
4940 "1436 unreg_rpi SKIP UNREG x%x on "
4941 "NPort x%x deferred x%x flg x%x "
4943 ndlp->nlp_rpi, ndlp->nlp_DID,
4944 ndlp->nlp_defer_did,
4945 ndlp->nlp_flag, ndlp);
4949 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4951 /* SLI4 ports require the physical rpi value. */
4952 rpi = ndlp->nlp_rpi;
4953 if (phba->sli_rev == LPFC_SLI_REV4)
4954 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4956 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4957 mbox->vport = vport;
4958 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
4959 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
4961 * accept PLOGIs after unreg_rpi_cmpl
4964 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4966 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4967 ndlp->nlp_flag |= NLP_UNREG_INP;
4969 lpfc_printf_vlog(vport, KERN_INFO,
4970 LOG_NODE | LOG_DISCOVERY,
4971 "1433 unreg_rpi UNREG x%x on "
4972 "NPort x%x deferred flg x%x "
4974 ndlp->nlp_rpi, ndlp->nlp_DID,
4975 ndlp->nlp_flag, ndlp);
4977 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4978 if (rc == MBX_NOT_FINISHED) {
4979 mempool_free(mbox, phba->mbox_mem_pool);
4983 lpfc_no_rpi(phba, ndlp);
4985 if (phba->sli_rev != LPFC_SLI_REV4)
4987 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4988 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4990 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4993 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4998 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4999 * @phba: pointer to lpfc hba data structure.
5001 * This routine is invoked to unregister all the currently registered RPIs
5005 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5007 struct lpfc_vport **vports;
5008 struct lpfc_nodelist *ndlp;
5009 struct Scsi_Host *shost;
5012 vports = lpfc_create_vport_work_array(phba);
5014 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5015 "2884 Vport array allocation failed \n");
5018 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5019 shost = lpfc_shost_from_vport(vports[i]);
5020 spin_lock_irq(shost->host_lock);
5021 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5022 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5023 /* The mempool_alloc might sleep */
5024 spin_unlock_irq(shost->host_lock);
5025 lpfc_unreg_rpi(vports[i], ndlp);
5026 spin_lock_irq(shost->host_lock);
5029 spin_unlock_irq(shost->host_lock);
5031 lpfc_destroy_vport_work_array(phba, vports);
5035 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5037 struct lpfc_hba *phba = vport->phba;
5041 if (phba->sli_rev == LPFC_SLI_REV4) {
5042 lpfc_sli4_unreg_all_rpis(vport);
5046 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5048 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5050 mbox->vport = vport;
5051 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5052 mbox->ctx_ndlp = NULL;
5053 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5054 if (rc != MBX_TIMEOUT)
5055 mempool_free(mbox, phba->mbox_mem_pool);
5057 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5058 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5059 "1836 Could not issue "
5060 "unreg_login(all_rpis) status %d\n", rc);
5065 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5067 struct lpfc_hba *phba = vport->phba;
5071 /* Unreg DID is an SLI3 operation. */
5072 if (phba->sli_rev > LPFC_SLI_REV3)
5075 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5077 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5079 mbox->vport = vport;
5080 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5081 mbox->ctx_ndlp = NULL;
5082 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5083 if (rc != MBX_TIMEOUT)
5084 mempool_free(mbox, phba->mbox_mem_pool);
5086 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5087 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5088 "1815 Could not issue "
5089 "unreg_did (default rpis) status %d\n",
5095 * Free resources associated with LPFC_NODELIST entry
5096 * so it can be freed.
5099 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5102 struct lpfc_hba *phba = vport->phba;
5103 LPFC_MBOXQ_t *mb, *nextmb;
5104 struct lpfc_dmabuf *mp;
5105 unsigned long iflags;
5107 /* Cleanup node for NPort <nlp_DID> */
5108 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5109 "0900 Cleanup node for NPort x%x "
5110 "Data: x%x x%x x%x\n",
5111 ndlp->nlp_DID, ndlp->nlp_flag,
5112 ndlp->nlp_state, ndlp->nlp_rpi);
5113 if (NLP_CHK_FREE_REQ(ndlp)) {
5114 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5115 "0280 %s: ndlp:x%px "
5116 "usgmap:x%x refcnt:%d\n",
5117 __func__, (void *)ndlp, ndlp->nlp_usg_map,
5118 kref_read(&ndlp->kref));
5119 lpfc_dequeue_node(vport, ndlp);
5121 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5122 "0281 %s: ndlp:x%px "
5123 "usgmap:x%x refcnt:%d\n",
5124 __func__, (void *)ndlp, ndlp->nlp_usg_map,
5125 kref_read(&ndlp->kref));
5126 lpfc_disable_node(vport, ndlp);
5130 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5132 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5133 if ((mb = phba->sli.mbox_active)) {
5134 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5135 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5136 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5137 mb->ctx_ndlp = NULL;
5138 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5142 spin_lock_irq(&phba->hbalock);
5143 /* Cleanup REG_LOGIN completions which are not yet processed */
5144 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5145 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5146 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5147 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5150 mb->ctx_ndlp = NULL;
5151 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5154 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5155 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5156 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5157 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5158 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5160 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5163 list_del(&mb->list);
5164 mempool_free(mb, phba->mbox_mem_pool);
5165 /* We shall not invoke the lpfc_nlp_put to decrement
5166 * the ndlp reference count as we are in the process
5167 * of lpfc_nlp_release.
5171 spin_unlock_irq(&phba->hbalock);
5173 lpfc_els_abort(phba, ndlp);
5175 spin_lock_irq(shost->host_lock);
5176 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5177 spin_unlock_irq(shost->host_lock);
5179 ndlp->nlp_last_elscmd = 0;
5180 del_timer_sync(&ndlp->nlp_delayfunc);
5182 list_del_init(&ndlp->els_retry_evt.evt_listp);
5183 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5184 lpfc_cleanup_vports_rrqs(vport, ndlp);
5185 if (phba->sli_rev == LPFC_SLI_REV4)
5186 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5187 if (!lpfc_unreg_rpi(vport, ndlp)) {
5188 /* Clean up unregistered and non freed rpis */
5189 if ((ndlp->nlp_flag & NLP_RELEASE_RPI) &&
5190 !(ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)) {
5191 lpfc_sli4_free_rpi(vport->phba,
5193 spin_lock_irqsave(&vport->phba->ndlp_lock,
5195 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5196 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5197 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
5205 * Check to see if we can free the nlp back to the freelist.
5206 * If we are in the middle of using the nlp in the discovery state
5207 * machine, defer the free till we reach the end of the state machine.
5210 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5212 struct lpfc_hba *phba = vport->phba;
5213 struct lpfc_rport_data *rdata;
5214 struct fc_rport *rport;
5218 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5219 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
5220 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
5221 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5222 phba->sli_rev != LPFC_SLI_REV4) {
5223 /* For this case we need to cleanup the default rpi
5224 * allocated by the firmware.
5226 lpfc_printf_vlog(vport, KERN_INFO,
5227 LOG_NODE | LOG_DISCOVERY,
5228 "0005 Cleanup Default rpi:x%x DID:x%x flg:x%x "
5229 "ref %d map:x%x ndlp x%px\n",
5230 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5231 kref_read(&ndlp->kref),
5232 ndlp->nlp_usg_map, ndlp);
5233 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5235 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
5236 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
5238 mempool_free(mbox, phba->mbox_mem_pool);
5241 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5242 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5243 mbox->vport = vport;
5244 mbox->ctx_ndlp = ndlp;
5245 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5246 if (rc == MBX_NOT_FINISHED) {
5247 mempool_free(mbox, phba->mbox_mem_pool);
5252 lpfc_cleanup_node(vport, ndlp);
5255 * ndlp->rport must be set to NULL before it reaches here
5256 * i.e. break rport/node link before doing lpfc_nlp_put for
5257 * registered rport and then drop the reference of rport.
5261 * extra lpfc_nlp_put dropped the reference of ndlp
5262 * for registered rport so need to cleanup rport
5264 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5265 "0940 removed node x%px DID x%x "
5266 "rpi %d rport not null x%px\n",
5267 ndlp, ndlp->nlp_DID, ndlp->nlp_rpi,
5269 rport = ndlp->rport;
5270 rdata = rport->dd_data;
5271 rdata->pnode = NULL;
5273 put_device(&rport->dev);
5278 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5281 D_ID mydid, ndlpdid, matchdid;
5283 if (did == Bcast_DID)
5286 /* First check for Direct match */
5287 if (ndlp->nlp_DID == did)
5290 /* Next check for area/domain identically equals 0 match */
5291 mydid.un.word = vport->fc_myDID;
5292 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5296 matchdid.un.word = did;
5297 ndlpdid.un.word = ndlp->nlp_DID;
5298 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5299 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5300 (mydid.un.b.area == matchdid.un.b.area)) {
5301 /* This code is supposed to match the ID
5302 * for a private loop device that is
5303 * connect to fl_port. But we need to
5304 * check that the port did not just go
5305 * from pt2pt to fabric or we could end
5306 * up matching ndlp->nlp_DID 000001 to
5307 * fabric DID 0x20101
5309 if ((ndlpdid.un.b.domain == 0) &&
5310 (ndlpdid.un.b.area == 0)) {
5311 if (ndlpdid.un.b.id &&
5312 vport->phba->fc_topology ==
5319 matchdid.un.word = ndlp->nlp_DID;
5320 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5321 (mydid.un.b.area == ndlpdid.un.b.area)) {
5322 if ((matchdid.un.b.domain == 0) &&
5323 (matchdid.un.b.area == 0)) {
5324 if (matchdid.un.b.id)
5332 /* Search for a nodelist entry */
5333 static struct lpfc_nodelist *
5334 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5336 struct lpfc_nodelist *ndlp;
5339 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5340 if (lpfc_matchdid(vport, ndlp, did)) {
5341 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5342 ((uint32_t)ndlp->nlp_xri << 16) |
5343 ((uint32_t)ndlp->nlp_type << 8) |
5344 ((uint32_t)ndlp->nlp_usg_map & 0xff));
5345 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5346 "0929 FIND node DID "
5347 "Data: x%px x%x x%x x%x x%x x%px\n",
5348 ndlp, ndlp->nlp_DID,
5349 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5350 ndlp->active_rrqs_xri_bitmap);
5355 /* FIND node did <did> NOT FOUND */
5356 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5357 "0932 FIND node did x%x NOT FOUND.\n", did);
5361 struct lpfc_nodelist *
5362 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5364 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5365 struct lpfc_nodelist *ndlp;
5366 unsigned long iflags;
5368 spin_lock_irqsave(shost->host_lock, iflags);
5369 ndlp = __lpfc_findnode_did(vport, did);
5370 spin_unlock_irqrestore(shost->host_lock, iflags);
5374 struct lpfc_nodelist *
5375 lpfc_findnode_mapped(struct lpfc_vport *vport)
5377 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5378 struct lpfc_nodelist *ndlp;
5380 unsigned long iflags;
5382 spin_lock_irqsave(shost->host_lock, iflags);
5384 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5385 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5386 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5387 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5388 ((uint32_t)ndlp->nlp_xri << 16) |
5389 ((uint32_t)ndlp->nlp_type << 8) |
5390 ((uint32_t)ndlp->nlp_rpi & 0xff));
5391 spin_unlock_irqrestore(shost->host_lock, iflags);
5392 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5393 "2025 FIND node DID "
5394 "Data: x%px x%x x%x x%x x%px\n",
5395 ndlp, ndlp->nlp_DID,
5396 ndlp->nlp_flag, data1,
5397 ndlp->active_rrqs_xri_bitmap);
5401 spin_unlock_irqrestore(shost->host_lock, iflags);
5403 /* FIND node did <did> NOT FOUND */
5404 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5405 "2026 FIND mapped did NOT FOUND.\n");
5409 struct lpfc_nodelist *
5410 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5413 struct lpfc_nodelist *ndlp;
5415 ndlp = lpfc_findnode_did(vport, did);
5417 if (vport->phba->nvmet_support)
5419 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5420 lpfc_rscn_payload_check(vport, did) == 0)
5422 ndlp = lpfc_nlp_init(vport, did);
5425 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5427 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5428 "6453 Setup New Node 2B_DISC x%x "
5429 "Data:x%x x%x x%x\n",
5430 ndlp->nlp_DID, ndlp->nlp_flag,
5431 ndlp->nlp_state, vport->fc_flag);
5433 spin_lock_irq(shost->host_lock);
5434 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5435 spin_unlock_irq(shost->host_lock);
5437 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5438 if (vport->phba->nvmet_support)
5440 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
5442 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
5443 "0014 Could not enable ndlp\n");
5446 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5447 "6454 Setup Enabled Node 2B_DISC x%x "
5448 "Data:x%x x%x x%x\n",
5449 ndlp->nlp_DID, ndlp->nlp_flag,
5450 ndlp->nlp_state, vport->fc_flag);
5452 spin_lock_irq(shost->host_lock);
5453 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5454 spin_unlock_irq(shost->host_lock);
5458 /* The NVME Target does not want to actively manage an rport.
5459 * The goal is to allow the target to reset its state and clear
5460 * pending IO in preparation for the initiator to recover.
5462 if ((vport->fc_flag & FC_RSCN_MODE) &&
5463 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5464 if (lpfc_rscn_payload_check(vport, did)) {
5466 /* Since this node is marked for discovery,
5467 * delay timeout is not needed.
5469 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5471 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5472 "6455 Setup RSCN Node 2B_DISC x%x "
5473 "Data:x%x x%x x%x\n",
5474 ndlp->nlp_DID, ndlp->nlp_flag,
5475 ndlp->nlp_state, vport->fc_flag);
5477 /* NVME Target mode waits until rport is known to be
5478 * impacted by the RSCN before it transitions. No
5479 * active management - just go to NPR provided the
5480 * node had a valid login.
5482 if (vport->phba->nvmet_support)
5485 /* If we've already received a PLOGI from this NPort
5486 * we don't need to try to discover it again.
5488 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5490 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5493 ndlp->nlp_prev_state = ndlp->nlp_state;
5494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5496 spin_lock_irq(shost->host_lock);
5497 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5498 spin_unlock_irq(shost->host_lock);
5500 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5501 "6456 Skip Setup RSCN Node x%x "
5502 "Data:x%x x%x x%x\n",
5503 ndlp->nlp_DID, ndlp->nlp_flag,
5504 ndlp->nlp_state, vport->fc_flag);
5508 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5509 "6457 Setup Active Node 2B_DISC x%x "
5510 "Data:x%x x%x x%x\n",
5511 ndlp->nlp_DID, ndlp->nlp_flag,
5512 ndlp->nlp_state, vport->fc_flag);
5514 /* If the initiator received a PLOGI from this NPort or if the
5515 * initiator is already in the process of discovery on it,
5516 * there's no need to try to discover it again.
5518 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5519 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5520 (!vport->phba->nvmet_support &&
5521 ndlp->nlp_flag & NLP_RCV_PLOGI))
5524 if (vport->phba->nvmet_support)
5527 /* Moving to NPR state clears unsolicited flags and
5528 * allows for rediscovery
5530 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5532 spin_lock_irq(shost->host_lock);
5533 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5534 spin_unlock_irq(shost->host_lock);
5539 /* Build a list of nodes to discover based on the loopmap */
5541 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5543 struct lpfc_hba *phba = vport->phba;
5545 uint32_t alpa, index;
5547 if (!lpfc_is_link_up(phba))
5550 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5553 /* Check for loop map present or not */
5554 if (phba->alpa_map[0]) {
5555 for (j = 1; j <= phba->alpa_map[0]; j++) {
5556 alpa = phba->alpa_map[j];
5557 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5559 lpfc_setup_disc_node(vport, alpa);
5562 /* No alpamap, so try all alpa's */
5563 for (j = 0; j < FC_MAXLOOP; j++) {
5564 /* If cfg_scan_down is set, start from highest
5565 * ALPA (0xef) to lowest (0x1).
5567 if (vport->cfg_scan_down)
5570 index = FC_MAXLOOP - j - 1;
5571 alpa = lpfcAlpaArray[index];
5572 if ((vport->fc_myDID & 0xff) == alpa)
5574 lpfc_setup_disc_node(vport, alpa);
5582 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5585 struct lpfc_sli *psli = &phba->sli;
5586 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5587 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5591 * if it's not a physical port or if we already send
5592 * clear_la then don't send it.
5594 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5595 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5596 (phba->sli_rev == LPFC_SLI_REV4))
5599 /* Link up discovery */
5600 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5601 phba->link_state = LPFC_CLEAR_LA;
5602 lpfc_clear_la(phba, mbox);
5603 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5604 mbox->vport = vport;
5605 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5606 if (rc == MBX_NOT_FINISHED) {
5607 mempool_free(mbox, phba->mbox_mem_pool);
5608 lpfc_disc_flush_list(vport);
5609 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5610 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5611 phba->link_state = LPFC_HBA_ERROR;
5616 /* Reg_vpi to tell firmware to resume normal operations */
5618 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5620 LPFC_MBOXQ_t *regvpimbox;
5622 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5624 lpfc_reg_vpi(vport, regvpimbox);
5625 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5626 regvpimbox->vport = vport;
5627 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5628 == MBX_NOT_FINISHED) {
5629 mempool_free(regvpimbox, phba->mbox_mem_pool);
5634 /* Start Link up / RSCN discovery on NPR nodes */
5636 lpfc_disc_start(struct lpfc_vport *vport)
5638 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5639 struct lpfc_hba *phba = vport->phba;
5641 uint32_t clear_la_pending;
5643 if (!lpfc_is_link_up(phba)) {
5644 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5645 "3315 Link is not up %x\n",
5650 if (phba->link_state == LPFC_CLEAR_LA)
5651 clear_la_pending = 1;
5653 clear_la_pending = 0;
5655 if (vport->port_state < LPFC_VPORT_READY)
5656 vport->port_state = LPFC_DISC_AUTH;
5658 lpfc_set_disctmo(vport);
5660 vport->fc_prevDID = vport->fc_myDID;
5661 vport->num_disc_nodes = 0;
5663 /* Start Discovery state <hba_state> */
5664 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5665 "0202 Start Discovery port state x%x "
5666 "flg x%x Data: x%x x%x x%x\n",
5667 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5668 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5670 /* First do ADISCs - if any */
5671 num_sent = lpfc_els_disc_adisc(vport);
5676 /* Register the VPI for SLI3, NPIV only. */
5677 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5678 !(vport->fc_flag & FC_PT2PT) &&
5679 !(vport->fc_flag & FC_RSCN_MODE) &&
5680 (phba->sli_rev < LPFC_SLI_REV4)) {
5681 lpfc_issue_clear_la(phba, vport);
5682 lpfc_issue_reg_vpi(phba, vport);
5687 * For SLI2, we need to set port_state to READY and continue
5690 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5691 /* If we get here, there is nothing to ADISC */
5692 lpfc_issue_clear_la(phba, vport);
5694 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5695 vport->num_disc_nodes = 0;
5696 /* go thru NPR nodes and issue ELS PLOGIs */
5697 if (vport->fc_npr_cnt)
5698 lpfc_els_disc_plogi(vport);
5700 if (!vport->num_disc_nodes) {
5701 spin_lock_irq(shost->host_lock);
5702 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5703 spin_unlock_irq(shost->host_lock);
5704 lpfc_can_disctmo(vport);
5707 vport->port_state = LPFC_VPORT_READY;
5709 /* Next do PLOGIs - if any */
5710 num_sent = lpfc_els_disc_plogi(vport);
5715 if (vport->fc_flag & FC_RSCN_MODE) {
5716 /* Check to see if more RSCNs came in while we
5717 * were processing this one.
5719 if ((vport->fc_rscn_id_cnt == 0) &&
5720 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5721 spin_lock_irq(shost->host_lock);
5722 vport->fc_flag &= ~FC_RSCN_MODE;
5723 spin_unlock_irq(shost->host_lock);
5724 lpfc_can_disctmo(vport);
5726 lpfc_els_handle_rscn(vport);
5733 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5734 * ring the match the sppecified nodelist.
5737 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5739 LIST_HEAD(completions);
5741 struct lpfc_iocbq *iocb, *next_iocb;
5742 struct lpfc_sli_ring *pring;
5744 pring = lpfc_phba_elsring(phba);
5745 if (unlikely(!pring))
5748 /* Error matching iocb on txq or txcmplq
5749 * First check the txq.
5751 spin_lock_irq(&phba->hbalock);
5752 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5753 if (iocb->context1 != ndlp) {
5757 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5758 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5760 list_move_tail(&iocb->list, &completions);
5764 /* Next check the txcmplq */
5765 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5766 if (iocb->context1 != ndlp) {
5770 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5771 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5772 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
5775 spin_unlock_irq(&phba->hbalock);
5777 /* Cancel all the IOCBs from the completions list */
5778 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5783 lpfc_disc_flush_list(struct lpfc_vport *vport)
5785 struct lpfc_nodelist *ndlp, *next_ndlp;
5786 struct lpfc_hba *phba = vport->phba;
5788 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5789 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5791 if (!NLP_CHK_NODE_ACT(ndlp))
5793 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5794 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5795 lpfc_free_tx(phba, ndlp);
5802 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5804 lpfc_els_flush_rscn(vport);
5805 lpfc_els_flush_cmd(vport);
5806 lpfc_disc_flush_list(vport);
5809 /*****************************************************************************/
5811 * NAME: lpfc_disc_timeout
5813 * FUNCTION: Fibre Channel driver discovery timeout routine.
5815 * EXECUTION ENVIRONMENT: interrupt only
5823 /*****************************************************************************/
5825 lpfc_disc_timeout(struct timer_list *t)
5827 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
5828 struct lpfc_hba *phba = vport->phba;
5829 uint32_t tmo_posted;
5830 unsigned long flags = 0;
5832 if (unlikely(!phba))
5835 spin_lock_irqsave(&vport->work_port_lock, flags);
5836 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5838 vport->work_port_events |= WORKER_DISC_TMO;
5839 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5842 lpfc_worker_wake_up(phba);
5847 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5850 struct lpfc_hba *phba = vport->phba;
5851 struct lpfc_sli *psli = &phba->sli;
5852 struct lpfc_nodelist *ndlp, *next_ndlp;
5853 LPFC_MBOXQ_t *initlinkmbox;
5854 int rc, clrlaerr = 0;
5856 if (!(vport->fc_flag & FC_DISC_TMO))
5859 spin_lock_irq(shost->host_lock);
5860 vport->fc_flag &= ~FC_DISC_TMO;
5861 spin_unlock_irq(shost->host_lock);
5863 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5864 "disc timeout: state:x%x rtry:x%x flg:x%x",
5865 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5867 switch (vport->port_state) {
5869 case LPFC_LOCAL_CFG_LINK:
5871 * port_state is identically LPFC_LOCAL_CFG_LINK while
5872 * waiting for FAN timeout
5874 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5875 "0221 FAN timeout\n");
5877 /* Start discovery by sending FLOGI, clean up old rpis */
5878 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5880 if (!NLP_CHK_NODE_ACT(ndlp))
5882 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5884 if (ndlp->nlp_type & NLP_FABRIC) {
5885 /* Clean up the ndlp on Fabric connections */
5886 lpfc_drop_node(vport, ndlp);
5888 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5889 /* Fail outstanding IO now since device
5890 * is marked for PLOGI.
5892 lpfc_unreg_rpi(vport, ndlp);
5895 if (vport->port_state != LPFC_FLOGI) {
5896 if (phba->sli_rev <= LPFC_SLI_REV3)
5897 lpfc_initial_flogi(vport);
5899 lpfc_issue_init_vfi(vport);
5906 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5907 /* Initial FLOGI timeout */
5908 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5909 "0222 Initial %s timeout\n",
5910 vport->vpi ? "FDISC" : "FLOGI");
5912 /* Assume no Fabric and go on with discovery.
5913 * Check for outstanding ELS FLOGI to abort.
5916 /* FLOGI failed, so just use loop map to make discovery list */
5917 lpfc_disc_list_loopmap(vport);
5919 /* Start discovery */
5920 lpfc_disc_start(vport);
5923 case LPFC_FABRIC_CFG_LINK:
5924 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5926 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5927 "0223 Timeout while waiting for "
5928 "NameServer login\n");
5929 /* Next look for NameServer ndlp */
5930 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5931 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5932 lpfc_els_abort(phba, ndlp);
5934 /* ReStart discovery */
5938 /* Check for wait for NameServer Rsp timeout */
5939 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5940 "0224 NameServer Query timeout "
5942 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5944 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5945 /* Try it one more time */
5946 vport->fc_ns_retry++;
5947 vport->gidft_inp = 0;
5948 rc = lpfc_issue_gidft(vport);
5952 vport->fc_ns_retry = 0;
5956 * Discovery is over.
5957 * set port_state to PORT_READY if SLI2.
5958 * cmpl_reg_vpi will set port_state to READY for SLI3.
5960 if (phba->sli_rev < LPFC_SLI_REV4) {
5961 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5962 lpfc_issue_reg_vpi(phba, vport);
5964 lpfc_issue_clear_la(phba, vport);
5965 vport->port_state = LPFC_VPORT_READY;
5969 /* Setup and issue mailbox INITIALIZE LINK command */
5970 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5971 if (!initlinkmbox) {
5972 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5973 "0206 Device Discovery "
5974 "completion error\n");
5975 phba->link_state = LPFC_HBA_ERROR;
5979 lpfc_linkdown(phba);
5980 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5981 phba->cfg_link_speed);
5982 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5983 initlinkmbox->vport = vport;
5984 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5985 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5986 lpfc_set_loopback_flag(phba);
5987 if (rc == MBX_NOT_FINISHED)
5988 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5992 case LPFC_DISC_AUTH:
5993 /* Node Authentication timeout */
5994 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5995 "0227 Node Authentication timeout\n");
5996 lpfc_disc_flush_list(vport);
5999 * set port_state to PORT_READY if SLI2.
6000 * cmpl_reg_vpi will set port_state to READY for SLI3.
6002 if (phba->sli_rev < LPFC_SLI_REV4) {
6003 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6004 lpfc_issue_reg_vpi(phba, vport);
6005 else { /* NPIV Not enabled */
6006 lpfc_issue_clear_la(phba, vport);
6007 vport->port_state = LPFC_VPORT_READY;
6012 case LPFC_VPORT_READY:
6013 if (vport->fc_flag & FC_RSCN_MODE) {
6014 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6015 "0231 RSCN timeout Data: x%x "
6017 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6019 /* Cleanup any outstanding ELS commands */
6020 lpfc_els_flush_cmd(vport);
6022 lpfc_els_flush_rscn(vport);
6023 lpfc_disc_flush_list(vport);
6028 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6029 "0273 Unexpected discovery timeout, "
6030 "vport State x%x\n", vport->port_state);
6034 switch (phba->link_state) {
6036 /* CLEAR LA timeout */
6037 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6038 "0228 CLEAR LA timeout\n");
6043 lpfc_issue_clear_la(phba, vport);
6045 case LPFC_LINK_UNKNOWN:
6046 case LPFC_WARM_START:
6047 case LPFC_INIT_START:
6048 case LPFC_INIT_MBX_CMDS:
6049 case LPFC_LINK_DOWN:
6050 case LPFC_HBA_ERROR:
6051 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6052 "0230 Unexpected timeout, hba link "
6053 "state x%x\n", phba->link_state);
6057 case LPFC_HBA_READY:
6062 lpfc_disc_flush_list(vport);
6063 if (phba->sli_rev != LPFC_SLI_REV4) {
6064 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6065 ~LPFC_STOP_IOCB_EVENT;
6066 psli->sli3_ring[LPFC_FCP_RING].flag &=
6067 ~LPFC_STOP_IOCB_EVENT;
6069 vport->port_state = LPFC_VPORT_READY;
6075 * This routine handles processing a NameServer REG_LOGIN mailbox
6076 * command upon completion. It is setup in the LPFC_MBOXQ
6077 * as the completion routine when the command is
6078 * handed off to the SLI layer.
6081 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6083 MAILBOX_t *mb = &pmb->u.mb;
6084 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6085 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6086 struct lpfc_vport *vport = pmb->vport;
6088 pmb->ctx_buf = NULL;
6089 pmb->ctx_ndlp = NULL;
6091 if (phba->sli_rev < LPFC_SLI_REV4)
6092 ndlp->nlp_rpi = mb->un.varWords[0];
6093 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6094 ndlp->nlp_type |= NLP_FABRIC;
6095 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6096 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6097 "0004 rpi:%x DID:%x flg:%x %d map:%x x%px\n",
6098 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6099 kref_read(&ndlp->kref),
6100 ndlp->nlp_usg_map, ndlp);
6102 * Start issuing Fabric-Device Management Interface (FDMI) command to
6103 * 0xfffffa (FDMI well known port).
6104 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6105 * DPRT -> RPRT (vports)
6107 if (vport->port_type == LPFC_PHYSICAL_PORT)
6108 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6110 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6113 /* decrement the node reference count held for this callback
6117 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6119 mempool_free(pmb, phba->mbox_mem_pool);
6125 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6127 uint16_t *rpi = param;
6129 /* check for active node */
6130 if (!NLP_CHK_NODE_ACT(ndlp))
6133 return ndlp->nlp_rpi == *rpi;
6137 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6139 return memcmp(&ndlp->nlp_portname, param,
6140 sizeof(ndlp->nlp_portname)) == 0;
6143 static struct lpfc_nodelist *
6144 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6146 struct lpfc_nodelist *ndlp;
6148 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6149 if (filter(ndlp, param)) {
6150 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6151 "3185 FIND node filter %ps DID "
6152 "ndlp x%px did x%x flg x%x st x%x "
6153 "xri x%x type x%x rpi x%x\n",
6154 filter, ndlp, ndlp->nlp_DID,
6155 ndlp->nlp_flag, ndlp->nlp_state,
6156 ndlp->nlp_xri, ndlp->nlp_type,
6161 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6162 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6167 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6168 * returns the node list element pointer else return NULL.
6170 struct lpfc_nodelist *
6171 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6173 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6177 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6178 * returns the node element list pointer else return NULL.
6180 struct lpfc_nodelist *
6181 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6184 struct lpfc_nodelist *ndlp;
6186 spin_lock_irq(shost->host_lock);
6187 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6188 spin_unlock_irq(shost->host_lock);
6193 * This routine looks up the ndlp lists for the given RPI. If the rpi
6194 * is found, the routine returns the node element list pointer else
6197 struct lpfc_nodelist *
6198 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6200 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6201 struct lpfc_nodelist *ndlp;
6202 unsigned long flags;
6204 spin_lock_irqsave(shost->host_lock, flags);
6205 ndlp = __lpfc_findnode_rpi(vport, rpi);
6206 spin_unlock_irqrestore(shost->host_lock, flags);
6211 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6212 * @phba: pointer to lpfc hba data structure.
6213 * @vpi: the physical host virtual N_Port identifier.
6215 * This routine finds a vport on a HBA (referred by @phba) through a
6216 * @vpi. The function walks the HBA's vport list and returns the address
6217 * of the vport with the matching @vpi.
6220 * NULL - No vport with the matching @vpi found
6221 * Otherwise - Address to the vport with the matching @vpi.
6224 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6226 struct lpfc_vport *vport;
6227 unsigned long flags;
6230 /* The physical ports are always vpi 0 - translate is unnecessary. */
6233 * Translate the physical vpi to the logical vpi. The
6234 * vport stores the logical vpi.
6236 for (i = 0; i < phba->max_vpi; i++) {
6237 if (vpi == phba->vpi_ids[i])
6241 if (i >= phba->max_vpi) {
6242 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6243 "2936 Could not find Vport mapped "
6244 "to vpi %d\n", vpi);
6249 spin_lock_irqsave(&phba->port_list_lock, flags);
6250 list_for_each_entry(vport, &phba->port_list, listentry) {
6251 if (vport->vpi == i) {
6252 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6256 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6260 struct lpfc_nodelist *
6261 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6263 struct lpfc_nodelist *ndlp;
6264 int rpi = LPFC_RPI_ALLOC_ERROR;
6266 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6267 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6268 if (rpi == LPFC_RPI_ALLOC_ERROR)
6272 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6274 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6275 lpfc_sli4_free_rpi(vport->phba, rpi);
6279 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6281 lpfc_initialize_node(vport, ndlp, did);
6282 INIT_LIST_HEAD(&ndlp->nlp_listp);
6283 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6284 ndlp->nlp_rpi = rpi;
6285 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6286 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6287 "flg:x%x refcnt:%d map:x%x\n",
6288 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6289 ndlp->nlp_flag, kref_read(&ndlp->kref),
6292 ndlp->active_rrqs_xri_bitmap =
6293 mempool_alloc(vport->phba->active_rrq_pool,
6295 if (ndlp->active_rrqs_xri_bitmap)
6296 memset(ndlp->active_rrqs_xri_bitmap, 0,
6297 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6303 "node init: did:x%x",
6304 ndlp->nlp_DID, 0, 0);
6309 /* This routine releases all resources associated with a specifc NPort's ndlp
6310 * and mempool_free's the nodelist.
6313 lpfc_nlp_release(struct kref *kref)
6315 struct lpfc_hba *phba;
6316 unsigned long flags;
6317 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6320 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6321 "node release: did:x%x flg:x%x type:x%x",
6322 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6324 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
6325 "0279 %s: ndlp:x%px did %x "
6326 "usgmap:x%x refcnt:%d rpi:%x\n",
6328 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
6329 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6331 /* remove ndlp from action. */
6332 lpfc_nlp_remove(ndlp->vport, ndlp);
6334 /* clear the ndlp active flag for all release cases */
6336 spin_lock_irqsave(&phba->ndlp_lock, flags);
6337 NLP_CLR_NODE_ACT(ndlp);
6338 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6340 /* free ndlp memory for final ndlp release */
6341 if (NLP_CHK_FREE_REQ(ndlp)) {
6342 kfree(ndlp->lat_data);
6343 if (phba->sli_rev == LPFC_SLI_REV4)
6344 mempool_free(ndlp->active_rrqs_xri_bitmap,
6345 ndlp->phba->active_rrq_pool);
6346 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6350 /* This routine bumps the reference count for a ndlp structure to ensure
6351 * that one discovery thread won't free a ndlp while another discovery thread
6354 struct lpfc_nodelist *
6355 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6357 struct lpfc_hba *phba;
6358 unsigned long flags;
6361 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6362 "node get: did:x%x flg:x%x refcnt:x%x",
6363 ndlp->nlp_DID, ndlp->nlp_flag,
6364 kref_read(&ndlp->kref));
6365 /* The check of ndlp usage to prevent incrementing the
6366 * ndlp reference count that is in the process of being
6370 spin_lock_irqsave(&phba->ndlp_lock, flags);
6371 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
6372 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6373 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6374 "0276 %s: ndlp:x%px "
6375 "usgmap:x%x refcnt:%d\n",
6376 __func__, (void *)ndlp, ndlp->nlp_usg_map,
6377 kref_read(&ndlp->kref));
6380 kref_get(&ndlp->kref);
6381 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6386 /* This routine decrements the reference count for a ndlp structure. If the
6387 * count goes to 0, this indicates the the associated nodelist should be
6388 * freed. Returning 1 indicates the ndlp resource has been released; on the
6389 * other hand, returning 0 indicates the ndlp resource has not been released
6393 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6395 struct lpfc_hba *phba;
6396 unsigned long flags;
6401 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6402 "node put: did:x%x flg:x%x refcnt:x%x",
6403 ndlp->nlp_DID, ndlp->nlp_flag,
6404 kref_read(&ndlp->kref));
6406 spin_lock_irqsave(&phba->ndlp_lock, flags);
6407 /* Check the ndlp memory free acknowledge flag to avoid the
6408 * possible race condition that kref_put got invoked again
6409 * after previous one has done ndlp memory free.
6411 if (NLP_CHK_FREE_ACK(ndlp)) {
6412 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6413 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6414 "0274 %s: ndlp:x%px "
6415 "usgmap:x%x refcnt:%d\n",
6416 __func__, (void *)ndlp, ndlp->nlp_usg_map,
6417 kref_read(&ndlp->kref));
6420 /* Check the ndlp inactivate log flag to avoid the possible
6421 * race condition that kref_put got invoked again after ndlp
6422 * is already in inactivating state.
6424 if (NLP_CHK_IACT_REQ(ndlp)) {
6425 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6426 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6427 "0275 %s: ndlp:x%px "
6428 "usgmap:x%x refcnt:%d\n",
6429 __func__, (void *)ndlp, ndlp->nlp_usg_map,
6430 kref_read(&ndlp->kref));
6433 /* For last put, mark the ndlp usage flags to make sure no
6434 * other kref_get and kref_put on the same ndlp shall get
6435 * in between the process when the final kref_put has been
6436 * invoked on this ndlp.
6438 if (kref_read(&ndlp->kref) == 1) {
6439 /* Indicate ndlp is put to inactive state. */
6440 NLP_SET_IACT_REQ(ndlp);
6441 /* Acknowledge ndlp memory free has been seen. */
6442 if (NLP_CHK_FREE_REQ(ndlp))
6443 NLP_SET_FREE_ACK(ndlp);
6445 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6446 /* Note, the kref_put returns 1 when decrementing a reference
6447 * count that was 1, it invokes the release callback function,
6448 * but it still left the reference count as 1 (not actually
6449 * performs the last decrementation). Otherwise, it actually
6450 * decrements the reference count and returns 0.
6452 return kref_put(&ndlp->kref, lpfc_nlp_release);
6455 /* This routine free's the specified nodelist if it is not in use
6456 * by any other discovery thread. This routine returns 1 if the
6457 * ndlp has been freed. A return value of 0 indicates the ndlp is
6458 * not yet been released.
6461 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6463 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6464 "node not used: did:x%x flg:x%x refcnt:x%x",
6465 ndlp->nlp_DID, ndlp->nlp_flag,
6466 kref_read(&ndlp->kref));
6467 if (kref_read(&ndlp->kref) == 1)
6468 if (lpfc_nlp_put(ndlp))
6474 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6475 * @phba: Pointer to hba context object.
6477 * This function iterate through all FC nodes associated
6478 * will all vports to check if there is any node with
6479 * fc_rports associated with it. If there is an fc_rport
6480 * associated with the node, then the node is either in
6481 * discovered state or its devloss_timer is pending.
6484 lpfc_fcf_inuse(struct lpfc_hba *phba)
6486 struct lpfc_vport **vports;
6488 struct lpfc_nodelist *ndlp;
6489 struct Scsi_Host *shost;
6491 vports = lpfc_create_vport_work_array(phba);
6493 /* If driver cannot allocate memory, indicate fcf is in use */
6497 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6498 shost = lpfc_shost_from_vport(vports[i]);
6499 spin_lock_irq(shost->host_lock);
6501 * IF the CVL_RCVD bit is not set then we have sent the
6503 * If dev_loss fires while we are waiting we do not want to
6506 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6507 spin_unlock_irq(shost->host_lock);
6511 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6512 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6513 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6515 spin_unlock_irq(shost->host_lock);
6517 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6519 lpfc_printf_log(phba, KERN_INFO,
6520 LOG_NODE | LOG_DISCOVERY,
6521 "2624 RPI %x DID %x flag %x "
6522 "still logged in\n",
6523 ndlp->nlp_rpi, ndlp->nlp_DID,
6527 spin_unlock_irq(shost->host_lock);
6530 lpfc_destroy_vport_work_array(phba, vports);
6535 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6536 * @phba: Pointer to hba context object.
6537 * @mboxq: Pointer to mailbox object.
6539 * This function frees memory associated with the mailbox command.
6542 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6544 struct lpfc_vport *vport = mboxq->vport;
6545 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6547 if (mboxq->u.mb.mbxStatus) {
6548 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6549 "2555 UNREG_VFI mbxStatus error x%x "
6551 mboxq->u.mb.mbxStatus, vport->port_state);
6553 spin_lock_irq(shost->host_lock);
6554 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6555 spin_unlock_irq(shost->host_lock);
6556 mempool_free(mboxq, phba->mbox_mem_pool);
6561 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6562 * @phba: Pointer to hba context object.
6563 * @mboxq: Pointer to mailbox object.
6565 * This function frees memory associated with the mailbox command.
6568 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6570 struct lpfc_vport *vport = mboxq->vport;
6572 if (mboxq->u.mb.mbxStatus) {
6573 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6574 "2550 UNREG_FCFI mbxStatus error x%x "
6576 mboxq->u.mb.mbxStatus, vport->port_state);
6578 mempool_free(mboxq, phba->mbox_mem_pool);
6583 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6584 * @phba: Pointer to hba context object.
6586 * This function prepare the HBA for unregistering the currently registered
6587 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6591 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6593 struct lpfc_vport **vports;
6594 struct lpfc_nodelist *ndlp;
6595 struct Scsi_Host *shost;
6598 /* Unregister RPIs */
6599 if (lpfc_fcf_inuse(phba))
6600 lpfc_unreg_hba_rpis(phba);
6602 /* At this point, all discovery is aborted */
6603 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6605 /* Unregister VPIs */
6606 vports = lpfc_create_vport_work_array(phba);
6607 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6608 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6609 /* Stop FLOGI/FDISC retries */
6610 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6612 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6613 lpfc_cleanup_pending_mbox(vports[i]);
6614 if (phba->sli_rev == LPFC_SLI_REV4)
6615 lpfc_sli4_unreg_all_rpis(vports[i]);
6616 lpfc_mbx_unreg_vpi(vports[i]);
6617 shost = lpfc_shost_from_vport(vports[i]);
6618 spin_lock_irq(shost->host_lock);
6619 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6620 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6621 spin_unlock_irq(shost->host_lock);
6623 lpfc_destroy_vport_work_array(phba, vports);
6624 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6625 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6627 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6628 lpfc_cleanup_pending_mbox(phba->pport);
6629 if (phba->sli_rev == LPFC_SLI_REV4)
6630 lpfc_sli4_unreg_all_rpis(phba->pport);
6631 lpfc_mbx_unreg_vpi(phba->pport);
6632 shost = lpfc_shost_from_vport(phba->pport);
6633 spin_lock_irq(shost->host_lock);
6634 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6635 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6636 spin_unlock_irq(shost->host_lock);
6639 /* Cleanup any outstanding ELS commands */
6640 lpfc_els_flush_all_cmd(phba);
6642 /* Unregister the physical port VFI */
6643 rc = lpfc_issue_unreg_vfi(phba->pport);
6648 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6649 * @phba: Pointer to hba context object.
6651 * This function issues synchronous unregister FCF mailbox command to HBA to
6652 * unregister the currently registered FCF record. The driver does not reset
6653 * the driver FCF usage state flags.
6655 * Return 0 if successfully issued, none-zero otherwise.
6658 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6663 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6665 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6666 "2551 UNREG_FCFI mbox allocation failed"
6667 "HBA state x%x\n", phba->pport->port_state);
6670 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6671 mbox->vport = phba->pport;
6672 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6673 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6675 if (rc == MBX_NOT_FINISHED) {
6676 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6677 "2552 Unregister FCFI command failed rc x%x "
6679 rc, phba->pport->port_state);
6686 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6687 * @phba: Pointer to hba context object.
6689 * This function unregisters the currently reigstered FCF. This function
6690 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6693 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6697 /* Preparation for unregistering fcf */
6698 rc = lpfc_unregister_fcf_prep(phba);
6700 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6701 "2748 Failed to prepare for unregistering "
6702 "HBA's FCF record: rc=%d\n", rc);
6706 /* Now, unregister FCF record and reset HBA FCF state */
6707 rc = lpfc_sli4_unregister_fcf(phba);
6710 /* Reset HBA FCF states after successful unregister FCF */
6711 phba->fcf.fcf_flag = 0;
6712 phba->fcf.current_rec.flag = 0;
6715 * If driver is not unloading, check if there is any other
6716 * FCF record that can be used for discovery.
6718 if ((phba->pport->load_flag & FC_UNLOADING) ||
6719 (phba->link_state < LPFC_LINK_UP))
6722 /* This is considered as the initial FCF discovery scan */
6723 spin_lock_irq(&phba->hbalock);
6724 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6725 spin_unlock_irq(&phba->hbalock);
6727 /* Reset FCF roundrobin bmask for new discovery */
6728 lpfc_sli4_clear_fcf_rr_bmask(phba);
6730 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6733 spin_lock_irq(&phba->hbalock);
6734 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6735 spin_unlock_irq(&phba->hbalock);
6736 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6737 "2553 lpfc_unregister_unused_fcf failed "
6738 "to read FCF record HBA state x%x\n",
6739 phba->pport->port_state);
6744 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6745 * @phba: Pointer to hba context object.
6747 * This function just unregisters the currently reigstered FCF. It does not
6748 * try to find another FCF for discovery.
6751 lpfc_unregister_fcf(struct lpfc_hba *phba)
6755 /* Preparation for unregistering fcf */
6756 rc = lpfc_unregister_fcf_prep(phba);
6758 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6759 "2749 Failed to prepare for unregistering "
6760 "HBA's FCF record: rc=%d\n", rc);
6764 /* Now, unregister FCF record and reset HBA FCF state */
6765 rc = lpfc_sli4_unregister_fcf(phba);
6768 /* Set proper HBA FCF states after successful unregister FCF */
6769 spin_lock_irq(&phba->hbalock);
6770 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6771 spin_unlock_irq(&phba->hbalock);
6775 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6776 * @phba: Pointer to hba context object.
6778 * This function check if there are any connected remote port for the FCF and
6779 * if all the devices are disconnected, this function unregister FCFI.
6780 * This function also tries to use another FCF for discovery.
6783 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6786 * If HBA is not running in FIP mode, if HBA does not support
6787 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6788 * registered, do nothing.
6790 spin_lock_irq(&phba->hbalock);
6791 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6792 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6793 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6794 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6795 (phba->pport->port_state == LPFC_FLOGI)) {
6796 spin_unlock_irq(&phba->hbalock);
6799 spin_unlock_irq(&phba->hbalock);
6801 if (lpfc_fcf_inuse(phba))
6804 lpfc_unregister_fcf_rescan(phba);
6808 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6809 * @phba: Pointer to hba context object.
6810 * @buff: Buffer containing the FCF connection table as in the config
6812 * This function create driver data structure for the FCF connection
6813 * record table read from config region 23.
6816 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6819 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6820 struct lpfc_fcf_conn_hdr *conn_hdr;
6821 struct lpfc_fcf_conn_rec *conn_rec;
6822 uint32_t record_count;
6825 /* Free the current connect table */
6826 list_for_each_entry_safe(conn_entry, next_conn_entry,
6827 &phba->fcf_conn_rec_list, list) {
6828 list_del_init(&conn_entry->list);
6832 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6833 record_count = conn_hdr->length * sizeof(uint32_t)/
6834 sizeof(struct lpfc_fcf_conn_rec);
6836 conn_rec = (struct lpfc_fcf_conn_rec *)
6837 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6839 for (i = 0; i < record_count; i++) {
6840 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6842 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6845 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6846 "2566 Failed to allocate connection"
6851 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6852 sizeof(struct lpfc_fcf_conn_rec));
6853 list_add_tail(&conn_entry->list,
6854 &phba->fcf_conn_rec_list);
6857 if (!list_empty(&phba->fcf_conn_rec_list)) {
6859 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6861 conn_rec = &conn_entry->conn_rec;
6862 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6863 "3345 FCF connection list rec[%02d]: "
6864 "flags:x%04x, vtag:x%04x, "
6865 "fabric_name:x%02x:%02x:%02x:%02x:"
6866 "%02x:%02x:%02x:%02x, "
6867 "switch_name:x%02x:%02x:%02x:%02x:"
6868 "%02x:%02x:%02x:%02x\n", i++,
6869 conn_rec->flags, conn_rec->vlan_tag,
6870 conn_rec->fabric_name[0],
6871 conn_rec->fabric_name[1],
6872 conn_rec->fabric_name[2],
6873 conn_rec->fabric_name[3],
6874 conn_rec->fabric_name[4],
6875 conn_rec->fabric_name[5],
6876 conn_rec->fabric_name[6],
6877 conn_rec->fabric_name[7],
6878 conn_rec->switch_name[0],
6879 conn_rec->switch_name[1],
6880 conn_rec->switch_name[2],
6881 conn_rec->switch_name[3],
6882 conn_rec->switch_name[4],
6883 conn_rec->switch_name[5],
6884 conn_rec->switch_name[6],
6885 conn_rec->switch_name[7]);
6891 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6892 * @phba: Pointer to hba context object.
6893 * @buff: Buffer containing the FCoE parameter data structure.
6895 * This function update driver data structure with config
6896 * parameters read from config region 23.
6899 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6902 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6903 struct lpfc_fcoe_params *fcoe_param;
6905 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6907 fcoe_param = (struct lpfc_fcoe_params *)
6908 (buff + sizeof(struct lpfc_fip_param_hdr));
6910 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6911 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6914 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6915 phba->valid_vlan = 1;
6916 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6920 phba->fc_map[0] = fcoe_param->fc_map[0];
6921 phba->fc_map[1] = fcoe_param->fc_map[1];
6922 phba->fc_map[2] = fcoe_param->fc_map[2];
6927 * lpfc_get_rec_conf23 - Get a record type in config region data.
6928 * @buff: Buffer containing config region 23 data.
6929 * @size: Size of the data buffer.
6930 * @rec_type: Record type to be searched.
6932 * This function searches config region data to find the beginning
6933 * of the record specified by record_type. If record found, this
6934 * function return pointer to the record else return NULL.
6937 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6939 uint32_t offset = 0, rec_length;
6941 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6942 (size < sizeof(uint32_t)))
6945 rec_length = buff[offset + 1];
6948 * One TLV record has one word header and number of data words
6949 * specified in the rec_length field of the record header.
6951 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6953 if (buff[offset] == rec_type)
6954 return &buff[offset];
6956 if (buff[offset] == LPFC_REGION23_LAST_REC)
6959 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6960 rec_length = buff[offset + 1];
6966 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6967 * @phba: Pointer to lpfc_hba data structure.
6968 * @buff: Buffer containing config region 23 data.
6969 * @size: Size of the data buffer.
6971 * This function parses the FCoE config parameters in config region 23 and
6972 * populate driver data structure with the parameters.
6975 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6979 uint32_t offset = 0;
6983 * If data size is less than 2 words signature and version cannot be
6986 if (size < 2*sizeof(uint32_t))
6989 /* Check the region signature first */
6990 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6991 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6992 "2567 Config region 23 has bad signature\n");
6998 /* Check the data structure version */
6999 if (buff[offset] != LPFC_REGION23_VERSION) {
7000 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7001 "2568 Config region 23 has bad version\n");
7006 /* Read FCoE param record */
7007 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7008 size - offset, FCOE_PARAM_TYPE);
7010 lpfc_read_fcoe_param(phba, rec_ptr);
7012 /* Read FCF connection table */
7013 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7014 size - offset, FCOE_CONN_TBL_TYPE);
7016 lpfc_read_fcf_conn_tbl(phba, rec_ptr);