1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/interrupt.h>
30 #include <linux/lockdep.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_disc.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* AlpaArray for assignment of scsid for scan-down and bind_method */
54 static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
70 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
71 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
72 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
73 static int lpfc_fcf_inuse(struct lpfc_hba *);
74 static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
77 lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
79 if (ndlp->nlp_fc4_type ||
80 ndlp->nlp_DID == Fabric_DID ||
81 ndlp->nlp_DID == NameServer_DID ||
82 ndlp->nlp_DID == FDMI_DID)
86 /* The source of a terminate rport I/O is either a dev_loss_tmo
87 * event or a call to fc_remove_host. While the rport should be
88 * valid during these downcalls, the transport can call twice
89 * in a single event. This routine provides somoe protection
90 * as the NDLP isn't really free, just released to the pool.
93 lpfc_rport_invalid(struct fc_rport *rport)
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist *ndlp;
99 pr_err("**** %s: NULL rport, exit.\n", __func__);
103 rdata = rport->dd_data;
105 pr_err("**** %s: NULL dd_data on rport %p SID x%x\n",
106 __func__, rport, rport->scsi_target_id);
112 pr_err("**** %s: NULL ndlp on rport %p SID x%x\n",
113 __func__, rport, rport->scsi_target_id);
118 pr_err("**** %s: Null vport on ndlp %p, DID x%x rport %p "
119 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
120 rport->scsi_target_id);
127 lpfc_terminate_rport_io(struct fc_rport *rport)
129 struct lpfc_rport_data *rdata;
130 struct lpfc_nodelist *ndlp;
131 struct lpfc_vport *vport;
133 if (lpfc_rport_invalid(rport))
136 rdata = rport->dd_data;
139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
140 "rport terminate: sid:x%x did:x%x flg:x%x",
141 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
143 if (ndlp->nlp_sid != NLP_NO_SID) {
144 lpfc_sli_abort_iocb(vport,
145 &vport->phba->sli.sli3_ring[LPFC_FCP_RING],
146 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
151 * This function will be called when dev_loss_tmo fire.
154 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
156 struct lpfc_nodelist *ndlp;
157 struct lpfc_vport *vport;
158 struct lpfc_hba *phba;
159 struct lpfc_work_evt *evtp;
160 unsigned long iflags;
162 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
169 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
170 "rport devlosscb: sid:x%x did:x%x flg:x%x",
171 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
173 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
174 "3181 dev_loss_callbk x%06x, rport %p flg x%x "
175 "load_flag x%x refcnt %d\n",
176 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
177 vport->load_flag, kref_read(&ndlp->kref));
179 /* Don't schedule a worker thread event if the vport is going down.
180 * The teardown process cleans up the node via lpfc_drop_node.
182 if (vport->load_flag & FC_UNLOADING) {
183 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
186 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
188 /* Remove the node reference from remote_port_add now.
189 * The driver will not call remote_port_delete.
195 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
198 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
199 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
200 "6789 rport name %llx != node port name %llx",
202 wwn_to_u64(ndlp->nlp_portname.u.wwn));
204 evtp = &ndlp->dev_loss_evt;
206 if (!list_empty(&evtp->evt_listp)) {
207 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
208 "6790 rport name %llx dev_loss_evt pending\n",
213 spin_lock_irqsave(&ndlp->lock, iflags);
214 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
215 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
218 * The backend does not expect any more calls associated with this
219 * rport. Remove the association between rport and ndlp.
221 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
222 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
224 spin_unlock_irqrestore(&ndlp->lock, iflags);
226 /* We need to hold the node by incrementing the reference
227 * count until this queued work is done
229 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
231 spin_lock_irqsave(&phba->hbalock, iflags);
232 if (evtp->evt_arg1) {
233 evtp->evt = LPFC_EVT_DEV_LOSS;
234 list_add_tail(&evtp->evt_listp, &phba->work_list);
235 lpfc_worker_wake_up(phba);
237 spin_unlock_irqrestore(&phba->hbalock, iflags);
243 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
244 * @ndlp: Pointer to remote node object.
246 * This function is called from the worker thread when devloss timeout timer
247 * expires. For SLI4 host, this routine shall return 1 when at lease one
248 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
249 * routine shall return 0 when there is no remote node is still in use of FCF
250 * when devloss timeout happened to this @ndlp.
253 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
255 struct lpfc_vport *vport;
256 struct lpfc_hba *phba;
260 unsigned long iflags;
263 name = (uint8_t *)&ndlp->nlp_portname;
266 spin_lock_irqsave(&ndlp->lock, iflags);
267 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
268 spin_unlock_irqrestore(&ndlp->lock, iflags);
270 if (phba->sli_rev == LPFC_SLI_REV4)
271 fcf_inuse = lpfc_fcf_inuse(phba);
273 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
274 "rport devlosstmo:did:x%x type:x%x id:x%x",
275 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
277 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
278 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
279 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
280 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
282 /* If the driver is recovering the rport, ignore devloss. */
283 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
284 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
285 "0284 Devloss timeout Ignored on "
286 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
288 *name, *(name+1), *(name+2), *(name+3),
289 *(name+4), *(name+5), *(name+6), *(name+7),
294 /* Fabric nodes are done. */
295 if (ndlp->nlp_type & NLP_FABRIC) {
300 if (ndlp->nlp_sid != NLP_NO_SID) {
302 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
303 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
307 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
308 "0203 Devloss timeout on "
309 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
310 "NPort x%06x Data: x%x x%x x%x\n",
311 *name, *(name+1), *(name+2), *(name+3),
312 *(name+4), *(name+5), *(name+6), *(name+7),
313 ndlp->nlp_DID, ndlp->nlp_flag,
314 ndlp->nlp_state, ndlp->nlp_rpi);
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
317 "0204 Devloss timeout on "
318 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
319 "NPort x%06x Data: x%x x%x x%x\n",
320 *name, *(name+1), *(name+2), *(name+3),
321 *(name+4), *(name+5), *(name+6), *(name+7),
322 ndlp->nlp_DID, ndlp->nlp_flag,
323 ndlp->nlp_state, ndlp->nlp_rpi);
326 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
327 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
333 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
334 * @phba: Pointer to hba context object.
335 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
336 * @nlp_did: remote node identifer with devloss timeout.
338 * This function is called from the worker thread after invoking devloss
339 * timeout handler and releasing the reference count for the ndlp with
340 * which the devloss timeout was handled for SLI4 host. For the devloss
341 * timeout of the last remote node which had been in use of FCF, when this
342 * routine is invoked, it shall be guaranteed that none of the remote are
343 * in-use of FCF. When devloss timeout to the last remote using the FCF,
344 * if the FIP engine is neither in FCF table scan process nor roundrobin
345 * failover process, the in-use FCF shall be unregistered. If the FIP
346 * engine is in FCF discovery process, the devloss timeout state shall
347 * be set for either the FCF table scan process or roundrobin failover
348 * process to unregister the in-use FCF.
351 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
354 /* If devloss timeout happened to a remote node when FCF had no
355 * longer been in-use, do nothing.
360 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
361 spin_lock_irq(&phba->hbalock);
362 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
363 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
364 spin_unlock_irq(&phba->hbalock);
367 phba->hba_flag |= HBA_DEVLOSS_TMO;
368 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
369 "2847 Last remote node (x%x) using "
370 "FCF devloss tmo\n", nlp_did);
372 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
373 spin_unlock_irq(&phba->hbalock);
374 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
375 "2868 Devloss tmo to FCF rediscovery "
379 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
380 spin_unlock_irq(&phba->hbalock);
381 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
382 "2869 Devloss tmo to idle FIP engine, "
383 "unreg in-use FCF and rescan.\n");
384 /* Unregister in-use FCF and rescan */
385 lpfc_unregister_fcf_rescan(phba);
388 spin_unlock_irq(&phba->hbalock);
389 if (phba->hba_flag & FCF_TS_INPROG)
390 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
391 "2870 FCF table scan in progress\n");
392 if (phba->hba_flag & FCF_RR_INPROG)
393 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
394 "2871 FLOGI roundrobin FCF failover "
397 lpfc_unregister_unused_fcf(phba);
401 * lpfc_alloc_fast_evt - Allocates data structure for posting event
402 * @phba: Pointer to hba context object.
404 * This function is called from the functions which need to post
405 * events from interrupt context. This function allocates data
406 * structure required for posting event. It also keeps track of
407 * number of events pending and prevent event storm when there are
410 struct lpfc_fast_path_event *
411 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
412 struct lpfc_fast_path_event *ret;
414 /* If there are lot of fast event do not exhaust memory due to this */
415 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
418 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
421 atomic_inc(&phba->fast_event_count);
422 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
423 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
429 * lpfc_free_fast_evt - Frees event data structure
430 * @phba: Pointer to hba context object.
431 * @evt: Event object which need to be freed.
433 * This function frees the data structure required for posting
437 lpfc_free_fast_evt(struct lpfc_hba *phba,
438 struct lpfc_fast_path_event *evt) {
440 atomic_dec(&phba->fast_event_count);
445 * lpfc_send_fastpath_evt - Posts events generated from fast path
446 * @phba: Pointer to hba context object.
447 * @evtp: Event data structure.
449 * This function is called from worker thread, when the interrupt
450 * context need to post an event. This function posts the event
451 * to fc transport netlink interface.
454 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
455 struct lpfc_work_evt *evtp)
457 unsigned long evt_category, evt_sub_category;
458 struct lpfc_fast_path_event *fast_evt_data;
460 uint32_t evt_data_size;
461 struct Scsi_Host *shost;
463 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
466 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
467 evt_sub_category = (unsigned long) fast_evt_data->un.
468 fabric_evt.subcategory;
469 shost = lpfc_shost_from_vport(fast_evt_data->vport);
470 if (evt_category == FC_REG_FABRIC_EVENT) {
471 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
472 evt_data = (char *) &fast_evt_data->un.read_check_error;
473 evt_data_size = sizeof(fast_evt_data->un.
475 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
476 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
477 evt_data = (char *) &fast_evt_data->un.fabric_evt;
478 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
480 lpfc_free_fast_evt(phba, fast_evt_data);
483 } else if (evt_category == FC_REG_SCSI_EVENT) {
484 switch (evt_sub_category) {
485 case LPFC_EVENT_QFULL:
486 case LPFC_EVENT_DEVBSY:
487 evt_data = (char *) &fast_evt_data->un.scsi_evt;
488 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
490 case LPFC_EVENT_CHECK_COND:
491 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
492 evt_data_size = sizeof(fast_evt_data->un.
495 case LPFC_EVENT_VARQUEDEPTH:
496 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
497 evt_data_size = sizeof(fast_evt_data->un.
501 lpfc_free_fast_evt(phba, fast_evt_data);
505 lpfc_free_fast_evt(phba, fast_evt_data);
509 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
510 fc_host_post_vendor_event(shost,
511 fc_get_event_number(),
516 lpfc_free_fast_evt(phba, fast_evt_data);
521 lpfc_work_list_done(struct lpfc_hba *phba)
523 struct lpfc_work_evt *evtp = NULL;
524 struct lpfc_nodelist *ndlp;
529 spin_lock_irq(&phba->hbalock);
530 while (!list_empty(&phba->work_list)) {
531 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
533 spin_unlock_irq(&phba->hbalock);
536 case LPFC_EVT_ELS_RETRY:
537 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
538 lpfc_els_retry_delay_handler(ndlp);
539 free_evt = 0; /* evt is part of ndlp */
540 /* decrement the node reference count held
541 * for this queued work
545 case LPFC_EVT_DEV_LOSS:
546 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
547 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
549 /* decrement the node reference count held for
552 nlp_did = ndlp->nlp_DID;
554 if (phba->sli_rev == LPFC_SLI_REV4)
555 lpfc_sli4_post_dev_loss_tmo_handler(phba,
559 case LPFC_EVT_RECOVER_PORT:
560 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
561 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
563 /* decrement the node reference count held for
568 case LPFC_EVT_ONLINE:
569 if (phba->link_state < LPFC_LINK_DOWN)
570 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
572 *(int *) (evtp->evt_arg1) = 0;
573 complete((struct completion *)(evtp->evt_arg2));
575 case LPFC_EVT_OFFLINE_PREP:
576 if (phba->link_state >= LPFC_LINK_DOWN)
577 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
578 *(int *)(evtp->evt_arg1) = 0;
579 complete((struct completion *)(evtp->evt_arg2));
581 case LPFC_EVT_OFFLINE:
583 lpfc_sli_brdrestart(phba);
584 *(int *)(evtp->evt_arg1) =
585 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
586 lpfc_unblock_mgmt_io(phba);
587 complete((struct completion *)(evtp->evt_arg2));
589 case LPFC_EVT_WARM_START:
591 lpfc_reset_barrier(phba);
592 lpfc_sli_brdreset(phba);
593 lpfc_hba_down_post(phba);
594 *(int *)(evtp->evt_arg1) =
595 lpfc_sli_brdready(phba, HS_MBRDY);
596 lpfc_unblock_mgmt_io(phba);
597 complete((struct completion *)(evtp->evt_arg2));
601 *(int *)(evtp->evt_arg1)
602 = (phba->pport->stopped)
603 ? 0 : lpfc_sli_brdkill(phba);
604 lpfc_unblock_mgmt_io(phba);
605 complete((struct completion *)(evtp->evt_arg2));
607 case LPFC_EVT_FASTPATH_MGMT_EVT:
608 lpfc_send_fastpath_evt(phba, evtp);
611 case LPFC_EVT_RESET_HBA:
612 if (!(phba->pport->load_flag & FC_UNLOADING))
613 lpfc_reset_hba(phba);
618 spin_lock_irq(&phba->hbalock);
620 spin_unlock_irq(&phba->hbalock);
625 lpfc_work_done(struct lpfc_hba *phba)
627 struct lpfc_sli_ring *pring;
628 uint32_t ha_copy, status, control, work_port_events;
629 struct lpfc_vport **vports;
630 struct lpfc_vport *vport;
633 spin_lock_irq(&phba->hbalock);
634 ha_copy = phba->work_ha;
636 spin_unlock_irq(&phba->hbalock);
638 /* First, try to post the next mailbox command to SLI4 device */
639 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
640 lpfc_sli4_post_async_mbox(phba);
642 if (ha_copy & HA_ERATT)
643 /* Handle the error attention event */
644 lpfc_handle_eratt(phba);
646 if (ha_copy & HA_MBATT)
647 lpfc_sli_handle_mb_event(phba);
649 if (ha_copy & HA_LATT)
650 lpfc_handle_latt(phba);
652 /* Process SLI4 events */
653 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
654 if (phba->hba_flag & HBA_RRQ_ACTIVE)
655 lpfc_handle_rrq_active(phba);
656 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
657 lpfc_sli4_els_xri_abort_event_proc(phba);
658 if (phba->hba_flag & ASYNC_EVENT)
659 lpfc_sli4_async_event_proc(phba);
660 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
661 spin_lock_irq(&phba->hbalock);
662 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
663 spin_unlock_irq(&phba->hbalock);
664 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
666 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
667 lpfc_sli4_fcf_redisc_event_proc(phba);
670 vports = lpfc_create_vport_work_array(phba);
672 for (i = 0; i <= phba->max_vports; i++) {
674 * We could have no vports in array if unloading, so if
675 * this happens then just use the pport
677 if (vports[i] == NULL && i == 0)
683 spin_lock_irq(&vport->work_port_lock);
684 work_port_events = vport->work_port_events;
685 vport->work_port_events &= ~work_port_events;
686 spin_unlock_irq(&vport->work_port_lock);
687 if (work_port_events & WORKER_DISC_TMO)
688 lpfc_disc_timeout_handler(vport);
689 if (work_port_events & WORKER_ELS_TMO)
690 lpfc_els_timeout_handler(vport);
691 if (work_port_events & WORKER_HB_TMO)
692 lpfc_hb_timeout_handler(phba);
693 if (work_port_events & WORKER_MBOX_TMO)
694 lpfc_mbox_timeout_handler(phba);
695 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
696 lpfc_unblock_fabric_iocbs(phba);
697 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
698 lpfc_ramp_down_queue_handler(phba);
699 if (work_port_events & WORKER_DELAYED_DISC_TMO)
700 lpfc_delayed_disc_timeout_handler(vport);
702 lpfc_destroy_vport_work_array(phba, vports);
704 pring = lpfc_phba_elsring(phba);
705 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
706 status >>= (4*LPFC_ELS_RING);
707 if (pring && (status & HA_RXMASK ||
708 pring->flag & LPFC_DEFERRED_RING_EVENT ||
709 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
710 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
711 pring->flag |= LPFC_DEFERRED_RING_EVENT;
712 /* Preserve legacy behavior. */
713 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
714 set_bit(LPFC_DATA_READY, &phba->data_flags);
716 /* Driver could have abort request completed in queue
717 * when link goes down. Allow for this transition.
719 if (phba->link_state >= LPFC_LINK_DOWN ||
720 phba->link_flag & LS_MDS_LOOPBACK) {
721 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
722 lpfc_sli_handle_slow_ring_event(phba, pring,
727 if (phba->sli_rev == LPFC_SLI_REV4)
728 lpfc_drain_txq(phba);
730 * Turn on Ring interrupts
732 if (phba->sli_rev <= LPFC_SLI_REV3) {
733 spin_lock_irq(&phba->hbalock);
734 control = readl(phba->HCregaddr);
735 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
736 lpfc_debugfs_slow_ring_trc(phba,
737 "WRK Enable ring: cntl:x%x hacopy:x%x",
738 control, ha_copy, 0);
740 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
741 writel(control, phba->HCregaddr);
742 readl(phba->HCregaddr); /* flush */
744 lpfc_debugfs_slow_ring_trc(phba,
745 "WRK Ring ok: cntl:x%x hacopy:x%x",
746 control, ha_copy, 0);
748 spin_unlock_irq(&phba->hbalock);
751 lpfc_work_list_done(phba);
755 lpfc_do_work(void *p)
757 struct lpfc_hba *phba = p;
760 set_user_nice(current, MIN_NICE);
761 current->flags |= PF_NOFREEZE;
762 phba->data_flags = 0;
764 while (!kthread_should_stop()) {
765 /* wait and check worker queue activities */
766 rc = wait_event_interruptible(phba->work_waitq,
767 (test_and_clear_bit(LPFC_DATA_READY,
769 || kthread_should_stop()));
770 /* Signal wakeup shall terminate the worker thread */
772 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
773 "0433 Wakeup on signal: rc=x%x\n", rc);
777 /* Attend pending lpfc data processing */
778 lpfc_work_done(phba);
780 phba->worker_thread = NULL;
781 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
782 "0432 Worker thread stopped.\n");
787 * This is only called to handle FC worker events. Since this a rare
788 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
789 * embedding it in the IOCB.
792 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
795 struct lpfc_work_evt *evtp;
799 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
800 * be queued to worker thread for processing
802 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
806 evtp->evt_arg1 = arg1;
807 evtp->evt_arg2 = arg2;
810 spin_lock_irqsave(&phba->hbalock, flags);
811 list_add_tail(&evtp->evt_listp, &phba->work_list);
812 spin_unlock_irqrestore(&phba->hbalock, flags);
814 lpfc_worker_wake_up(phba);
820 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
822 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
823 struct lpfc_hba *phba = vport->phba;
824 struct lpfc_nodelist *ndlp, *next_ndlp;
826 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
827 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
830 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
831 ((vport->port_type == LPFC_NPIV_PORT) &&
832 ((ndlp->nlp_DID == NameServer_DID) ||
833 (ndlp->nlp_DID == FDMI_DID))))
834 lpfc_unreg_rpi(vport, ndlp);
836 /* Leave Fabric nodes alone on link down */
837 if ((phba->sli_rev < LPFC_SLI_REV4) &&
838 (!remove && ndlp->nlp_type & NLP_FABRIC))
841 /* Notify transport of connectivity loss to trigger cleanup. */
842 if (phba->nvmet_support &&
843 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
844 lpfc_nvmet_invalidate_host(phba, ndlp);
846 lpfc_disc_state_machine(vport, ndlp, NULL,
849 : NLP_EVT_DEVICE_RECOVERY);
851 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
852 if (phba->sli_rev == LPFC_SLI_REV4)
853 lpfc_sli4_unreg_all_rpis(vport);
854 lpfc_mbx_unreg_vpi(vport);
855 spin_lock_irq(shost->host_lock);
856 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
857 spin_unlock_irq(shost->host_lock);
862 lpfc_port_link_failure(struct lpfc_vport *vport)
864 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
866 /* Cleanup any outstanding received buffers */
867 lpfc_cleanup_rcv_buffers(vport);
869 /* Cleanup any outstanding RSCN activity */
870 lpfc_els_flush_rscn(vport);
872 /* Cleanup any outstanding ELS commands */
873 lpfc_els_flush_cmd(vport);
875 lpfc_cleanup_rpis(vport, 0);
877 /* Turn off discovery timer if its running */
878 lpfc_can_disctmo(vport);
882 lpfc_linkdown_port(struct lpfc_vport *vport)
884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
886 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
887 fc_host_post_event(shost, fc_get_event_number(),
888 FCH_EVT_LINKDOWN, 0);
890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
891 "Link Down: state:x%x rtry:x%x flg:x%x",
892 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
894 lpfc_port_link_failure(vport);
896 /* Stop delayed Nport discovery */
897 spin_lock_irq(shost->host_lock);
898 vport->fc_flag &= ~FC_DISC_DELAYED;
899 spin_unlock_irq(shost->host_lock);
900 del_timer_sync(&vport->delayed_disc_tmo);
904 lpfc_linkdown(struct lpfc_hba *phba)
906 struct lpfc_vport *vport = phba->pport;
907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
908 struct lpfc_vport **vports;
912 if (phba->link_state == LPFC_LINK_DOWN)
915 /* Block all SCSI stack I/Os */
916 lpfc_scsi_dev_block(phba);
918 phba->defer_flogi_acc_flag = false;
920 spin_lock_irq(&phba->hbalock);
921 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
922 spin_unlock_irq(&phba->hbalock);
923 if (phba->link_state > LPFC_LINK_DOWN) {
924 phba->link_state = LPFC_LINK_DOWN;
925 if (phba->sli4_hba.conf_trunk) {
926 phba->trunk_link.link0.state = 0;
927 phba->trunk_link.link1.state = 0;
928 phba->trunk_link.link2.state = 0;
929 phba->trunk_link.link3.state = 0;
930 phba->sli4_hba.link_state.logical_speed =
931 LPFC_LINK_SPEED_UNKNOWN;
933 spin_lock_irq(shost->host_lock);
934 phba->pport->fc_flag &= ~FC_LBIT;
935 spin_unlock_irq(shost->host_lock);
937 vports = lpfc_create_vport_work_array(phba);
938 if (vports != NULL) {
939 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
940 /* Issue a LINK DOWN event to all nodes */
941 lpfc_linkdown_port(vports[i]);
943 vports[i]->fc_myDID = 0;
945 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
946 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
947 if (phba->nvmet_support)
948 lpfc_nvmet_update_targetport(phba);
950 lpfc_nvme_update_localport(vports[i]);
954 lpfc_destroy_vport_work_array(phba, vports);
956 /* Clean up any SLI3 firmware default rpi's */
957 if (phba->sli_rev > LPFC_SLI_REV3)
960 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
962 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
964 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
965 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
966 == MBX_NOT_FINISHED) {
967 mempool_free(mb, phba->mbox_mem_pool);
972 /* Setup myDID for link up if we are in pt2pt mode */
973 if (phba->pport->fc_flag & FC_PT2PT) {
974 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
976 lpfc_config_link(phba, mb);
977 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
979 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
980 == MBX_NOT_FINISHED) {
981 mempool_free(mb, phba->mbox_mem_pool);
984 spin_lock_irq(shost->host_lock);
985 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
986 phba->pport->rcv_flogi_cnt = 0;
987 spin_unlock_irq(shost->host_lock);
993 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
995 struct lpfc_nodelist *ndlp;
997 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
998 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1000 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1002 if (ndlp->nlp_type & NLP_FABRIC) {
1003 /* On Linkup its safe to clean up the ndlp
1004 * from Fabric connections.
1006 if (ndlp->nlp_DID != Fabric_DID)
1007 lpfc_unreg_rpi(vport, ndlp);
1008 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1009 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1010 /* Fail outstanding IO now since device is
1013 lpfc_unreg_rpi(vport, ndlp);
1019 lpfc_linkup_port(struct lpfc_vport *vport)
1021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1022 struct lpfc_hba *phba = vport->phba;
1024 if ((vport->load_flag & FC_UNLOADING) != 0)
1027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1028 "Link Up: top:x%x speed:x%x flg:x%x",
1029 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1031 /* If NPIV is not enabled, only bring the physical port up */
1032 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1033 (vport != phba->pport))
1036 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1037 fc_host_post_event(shost, fc_get_event_number(),
1040 spin_lock_irq(shost->host_lock);
1041 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1042 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1043 vport->fc_flag |= FC_NDISC_ACTIVE;
1044 vport->fc_ns_retry = 0;
1045 spin_unlock_irq(shost->host_lock);
1047 lpfc_linkup_cleanup_nodes(vport);
1051 lpfc_linkup(struct lpfc_hba *phba)
1053 struct lpfc_vport **vports;
1055 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1057 phba->link_state = LPFC_LINK_UP;
1059 /* Unblock fabric iocbs if they are blocked */
1060 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1061 del_timer_sync(&phba->fabric_block_timer);
1063 vports = lpfc_create_vport_work_array(phba);
1065 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1066 lpfc_linkup_port(vports[i]);
1067 lpfc_destroy_vport_work_array(phba, vports);
1069 /* Clear the pport flogi counter in case the link down was
1070 * absorbed without an ACQE. No lock here - in worker thread
1071 * and discovery is synchronized.
1073 spin_lock_irq(shost->host_lock);
1074 phba->pport->rcv_flogi_cnt = 0;
1075 spin_unlock_irq(shost->host_lock);
1077 /* reinitialize initial FLOGI flag */
1078 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1079 phba->defer_flogi_acc_flag = false;
1085 * This routine handles processing a CLEAR_LA mailbox
1086 * command upon completion. It is setup in the LPFC_MBOXQ
1087 * as the completion routine when the command is
1088 * handed off to the SLI layer. SLI3 only.
1091 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1093 struct lpfc_vport *vport = pmb->vport;
1094 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1095 struct lpfc_sli *psli = &phba->sli;
1096 MAILBOX_t *mb = &pmb->u.mb;
1099 /* Since we don't do discovery right now, turn these off here */
1100 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1101 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1103 /* Check for error */
1104 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1105 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1106 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1107 "0320 CLEAR_LA mbxStatus error x%x hba "
1109 mb->mbxStatus, vport->port_state);
1110 phba->link_state = LPFC_HBA_ERROR;
1114 if (vport->port_type == LPFC_PHYSICAL_PORT)
1115 phba->link_state = LPFC_HBA_READY;
1117 spin_lock_irq(&phba->hbalock);
1118 psli->sli_flag |= LPFC_PROCESS_LA;
1119 control = readl(phba->HCregaddr);
1120 control |= HC_LAINT_ENA;
1121 writel(control, phba->HCregaddr);
1122 readl(phba->HCregaddr); /* flush */
1123 spin_unlock_irq(&phba->hbalock);
1124 mempool_free(pmb, phba->mbox_mem_pool);
1128 /* Device Discovery completes */
1129 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1130 "0225 Device Discovery completes\n");
1131 mempool_free(pmb, phba->mbox_mem_pool);
1133 spin_lock_irq(shost->host_lock);
1134 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1135 spin_unlock_irq(shost->host_lock);
1137 lpfc_can_disctmo(vport);
1139 /* turn on Link Attention interrupts */
1141 spin_lock_irq(&phba->hbalock);
1142 psli->sli_flag |= LPFC_PROCESS_LA;
1143 control = readl(phba->HCregaddr);
1144 control |= HC_LAINT_ENA;
1145 writel(control, phba->HCregaddr);
1146 readl(phba->HCregaddr); /* flush */
1147 spin_unlock_irq(&phba->hbalock);
1153 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1155 struct lpfc_vport *vport = pmb->vport;
1156 LPFC_MBOXQ_t *sparam_mb;
1157 struct lpfc_dmabuf *sparam_mp;
1158 u16 status = pmb->u.mb.mbxStatus;
1161 mempool_free(pmb, phba->mbox_mem_pool);
1166 /* don't perform discovery for SLI4 loopback diagnostic test */
1167 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1168 !(phba->hba_flag & HBA_FCOE_MODE) &&
1169 (phba->link_flag & LS_LOOPBACK_MODE))
1172 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1173 vport->fc_flag & FC_PUBLIC_LOOP &&
1174 !(vport->fc_flag & FC_LBIT)) {
1175 /* Need to wait for FAN - use discovery timer
1176 * for timeout. port_state is identically
1177 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1179 lpfc_set_disctmo(vport);
1183 /* Start discovery by sending a FLOGI. port_state is identically
1184 * LPFC_FLOGI while waiting for FLOGI cmpl.
1186 if (vport->port_state != LPFC_FLOGI) {
1187 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1188 * bb-credit recovery is in place.
1190 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1191 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1192 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1197 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1199 mempool_free(sparam_mb, phba->mbox_mem_pool);
1202 sparam_mb->vport = vport;
1203 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1204 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1205 if (rc == MBX_NOT_FINISHED) {
1206 sparam_mp = (struct lpfc_dmabuf *)
1208 lpfc_mbuf_free(phba, sparam_mp->virt,
1211 sparam_mb->ctx_buf = NULL;
1212 mempool_free(sparam_mb, phba->mbox_mem_pool);
1216 phba->hba_flag |= HBA_DEFER_FLOGI;
1218 lpfc_initial_flogi(vport);
1221 if (vport->fc_flag & FC_PT2PT)
1222 lpfc_disc_start(vport);
1227 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1228 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1229 status, vport->port_state);
1232 lpfc_linkdown(phba);
1234 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1235 "0200 CONFIG_LINK bad hba state x%x\n",
1238 lpfc_issue_clear_la(phba, vport);
1243 * lpfc_sli4_clear_fcf_rr_bmask
1244 * @phba: pointer to the struct lpfc_hba for this port.
1245 * This fucnction resets the round robin bit mask and clears the
1246 * fcf priority list. The list deletions are done while holding the
1247 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1248 * from the lpfc_fcf_pri record.
1251 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1253 struct lpfc_fcf_pri *fcf_pri;
1254 struct lpfc_fcf_pri *next_fcf_pri;
1255 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1256 spin_lock_irq(&phba->hbalock);
1257 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1258 &phba->fcf.fcf_pri_list, list) {
1259 list_del_init(&fcf_pri->list);
1260 fcf_pri->fcf_rec.flag = 0;
1262 spin_unlock_irq(&phba->hbalock);
1265 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1267 struct lpfc_vport *vport = mboxq->vport;
1269 if (mboxq->u.mb.mbxStatus) {
1270 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1271 "2017 REG_FCFI mbxStatus error x%x "
1272 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1277 /* Start FCoE discovery by sending a FLOGI. */
1278 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1279 /* Set the FCFI registered flag */
1280 spin_lock_irq(&phba->hbalock);
1281 phba->fcf.fcf_flag |= FCF_REGISTERED;
1282 spin_unlock_irq(&phba->hbalock);
1284 /* If there is a pending FCoE event, restart FCF table scan. */
1285 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1286 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1289 /* Mark successful completion of FCF table scan */
1290 spin_lock_irq(&phba->hbalock);
1291 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1292 phba->hba_flag &= ~FCF_TS_INPROG;
1293 if (vport->port_state != LPFC_FLOGI) {
1294 phba->hba_flag |= FCF_RR_INPROG;
1295 spin_unlock_irq(&phba->hbalock);
1296 lpfc_issue_init_vfi(vport);
1299 spin_unlock_irq(&phba->hbalock);
1303 spin_lock_irq(&phba->hbalock);
1304 phba->hba_flag &= ~FCF_RR_INPROG;
1305 spin_unlock_irq(&phba->hbalock);
1307 mempool_free(mboxq, phba->mbox_mem_pool);
1311 * lpfc_fab_name_match - Check if the fcf fabric name match.
1312 * @fab_name: pointer to fabric name.
1313 * @new_fcf_record: pointer to fcf record.
1315 * This routine compare the fcf record's fabric name with provided
1316 * fabric name. If the fabric name are identical this function
1317 * returns 1 else return 0.
1320 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1322 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1324 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1326 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1328 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1330 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1332 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1334 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1336 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1342 * lpfc_sw_name_match - Check if the fcf switch name match.
1343 * @sw_name: pointer to switch name.
1344 * @new_fcf_record: pointer to fcf record.
1346 * This routine compare the fcf record's switch name with provided
1347 * switch name. If the switch name are identical this function
1348 * returns 1 else return 0.
1351 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1353 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1355 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1357 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1359 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1361 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1363 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1365 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1367 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1373 * lpfc_mac_addr_match - Check if the fcf mac address match.
1374 * @mac_addr: pointer to mac address.
1375 * @new_fcf_record: pointer to fcf record.
1377 * This routine compare the fcf record's mac address with HBA's
1378 * FCF mac address. If the mac addresses are identical this function
1379 * returns 1 else return 0.
1382 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1384 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1386 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1388 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1390 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1392 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1394 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1400 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1402 return (curr_vlan_id == new_vlan_id);
1406 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1407 * @phba: pointer to lpfc hba data structure.
1408 * @fcf_index: Index for the lpfc_fcf_record.
1409 * @new_fcf_record: pointer to hba fcf record.
1411 * This routine updates the driver FCF priority record from the new HBA FCF
1412 * record. The hbalock is asserted held in the code path calling this
1416 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1417 struct fcf_record *new_fcf_record
1420 struct lpfc_fcf_pri *fcf_pri;
1422 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1423 fcf_pri->fcf_rec.fcf_index = fcf_index;
1424 /* FCF record priority */
1425 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1430 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1431 * @fcf_rec: pointer to driver fcf record.
1432 * @new_fcf_record: pointer to fcf record.
1434 * This routine copies the FCF information from the FCF
1435 * record to lpfc_hba data structure.
1438 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1439 struct fcf_record *new_fcf_record)
1442 fcf_rec->fabric_name[0] =
1443 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1444 fcf_rec->fabric_name[1] =
1445 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1446 fcf_rec->fabric_name[2] =
1447 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1448 fcf_rec->fabric_name[3] =
1449 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1450 fcf_rec->fabric_name[4] =
1451 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1452 fcf_rec->fabric_name[5] =
1453 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1454 fcf_rec->fabric_name[6] =
1455 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1456 fcf_rec->fabric_name[7] =
1457 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1459 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1460 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1461 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1462 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1463 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1464 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1465 /* FCF record index */
1466 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1467 /* FCF record priority */
1468 fcf_rec->priority = new_fcf_record->fip_priority;
1470 fcf_rec->switch_name[0] =
1471 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1472 fcf_rec->switch_name[1] =
1473 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1474 fcf_rec->switch_name[2] =
1475 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1476 fcf_rec->switch_name[3] =
1477 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1478 fcf_rec->switch_name[4] =
1479 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1480 fcf_rec->switch_name[5] =
1481 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1482 fcf_rec->switch_name[6] =
1483 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1484 fcf_rec->switch_name[7] =
1485 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1489 * __lpfc_update_fcf_record - Update driver fcf record
1490 * @phba: pointer to lpfc hba data structure.
1491 * @fcf_rec: pointer to driver fcf record.
1492 * @new_fcf_record: pointer to hba fcf record.
1493 * @addr_mode: address mode to be set to the driver fcf record.
1494 * @vlan_id: vlan tag to be set to the driver fcf record.
1495 * @flag: flag bits to be set to the driver fcf record.
1497 * This routine updates the driver FCF record from the new HBA FCF record
1498 * together with the address mode, vlan_id, and other informations. This
1499 * routine is called with the hbalock held.
1502 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1503 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1504 uint16_t vlan_id, uint32_t flag)
1506 lockdep_assert_held(&phba->hbalock);
1508 /* Copy the fields from the HBA's FCF record */
1509 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1510 /* Update other fields of driver FCF record */
1511 fcf_rec->addr_mode = addr_mode;
1512 fcf_rec->vlan_id = vlan_id;
1513 fcf_rec->flag |= (flag | RECORD_VALID);
1514 __lpfc_update_fcf_record_pri(phba,
1515 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1520 * lpfc_register_fcf - Register the FCF with hba.
1521 * @phba: pointer to lpfc hba data structure.
1523 * This routine issues a register fcfi mailbox command to register
1527 lpfc_register_fcf(struct lpfc_hba *phba)
1529 LPFC_MBOXQ_t *fcf_mbxq;
1532 spin_lock_irq(&phba->hbalock);
1533 /* If the FCF is not available do nothing. */
1534 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1535 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1536 spin_unlock_irq(&phba->hbalock);
1540 /* The FCF is already registered, start discovery */
1541 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1542 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1543 phba->hba_flag &= ~FCF_TS_INPROG;
1544 if (phba->pport->port_state != LPFC_FLOGI &&
1545 phba->pport->fc_flag & FC_FABRIC) {
1546 phba->hba_flag |= FCF_RR_INPROG;
1547 spin_unlock_irq(&phba->hbalock);
1548 lpfc_initial_flogi(phba->pport);
1551 spin_unlock_irq(&phba->hbalock);
1554 spin_unlock_irq(&phba->hbalock);
1556 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1558 spin_lock_irq(&phba->hbalock);
1559 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1560 spin_unlock_irq(&phba->hbalock);
1564 lpfc_reg_fcfi(phba, fcf_mbxq);
1565 fcf_mbxq->vport = phba->pport;
1566 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1567 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1568 if (rc == MBX_NOT_FINISHED) {
1569 spin_lock_irq(&phba->hbalock);
1570 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1571 spin_unlock_irq(&phba->hbalock);
1572 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1579 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1580 * @phba: pointer to lpfc hba data structure.
1581 * @new_fcf_record: pointer to fcf record.
1582 * @boot_flag: Indicates if this record used by boot bios.
1583 * @addr_mode: The address mode to be used by this FCF
1584 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1586 * This routine compare the fcf record with connect list obtained from the
1587 * config region to decide if this FCF can be used for SAN discovery. It returns
1588 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1589 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1590 * is used by boot bios and addr_mode will indicate the addressing mode to be
1591 * used for this FCF when the function returns.
1592 * If the FCF record need to be used with a particular vlan id, the vlan is
1593 * set in the vlan_id on return of the function. If not VLAN tagging need to
1594 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1597 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1598 struct fcf_record *new_fcf_record,
1599 uint32_t *boot_flag, uint32_t *addr_mode,
1602 struct lpfc_fcf_conn_entry *conn_entry;
1603 int i, j, fcf_vlan_id = 0;
1605 /* Find the lowest VLAN id in the FCF record */
1606 for (i = 0; i < 512; i++) {
1607 if (new_fcf_record->vlan_bitmap[i]) {
1608 fcf_vlan_id = i * 8;
1610 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1618 /* FCF not valid/available or solicitation in progress */
1619 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1620 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1621 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1624 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1626 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1628 if (phba->valid_vlan)
1629 *vlan_id = phba->vlan_id;
1631 *vlan_id = LPFC_FCOE_NULL_VID;
1636 * If there are no FCF connection table entry, driver connect to all
1639 if (list_empty(&phba->fcf_conn_rec_list)) {
1641 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1645 * When there are no FCF connect entries, use driver's default
1646 * addressing mode - FPMA.
1648 if (*addr_mode & LPFC_FCF_FPMA)
1649 *addr_mode = LPFC_FCF_FPMA;
1651 /* If FCF record report a vlan id use that vlan id */
1653 *vlan_id = fcf_vlan_id;
1655 *vlan_id = LPFC_FCOE_NULL_VID;
1659 list_for_each_entry(conn_entry,
1660 &phba->fcf_conn_rec_list, list) {
1661 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1664 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1665 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1668 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1669 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1672 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1674 * If the vlan bit map does not have the bit set for the
1675 * vlan id to be used, then it is not a match.
1677 if (!(new_fcf_record->vlan_bitmap
1678 [conn_entry->conn_rec.vlan_tag / 8] &
1679 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1684 * If connection record does not support any addressing mode,
1685 * skip the FCF record.
1687 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1688 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1692 * Check if the connection record specifies a required
1695 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1696 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1699 * If SPMA required but FCF not support this continue.
1701 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1702 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1703 new_fcf_record) & LPFC_FCF_SPMA))
1707 * If FPMA required but FCF not support this continue.
1709 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1710 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1711 new_fcf_record) & LPFC_FCF_FPMA))
1716 * This fcf record matches filtering criteria.
1718 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1724 * If user did not specify any addressing mode, or if the
1725 * preferred addressing mode specified by user is not supported
1726 * by FCF, allow fabric to pick the addressing mode.
1728 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1731 * If the user specified a required address mode, assign that
1734 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1735 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1736 *addr_mode = (conn_entry->conn_rec.flags &
1738 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1740 * If the user specified a preferred address mode, use the
1741 * addr mode only if FCF support the addr_mode.
1743 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1744 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1745 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1746 (*addr_mode & LPFC_FCF_SPMA))
1747 *addr_mode = LPFC_FCF_SPMA;
1748 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1749 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1750 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1751 (*addr_mode & LPFC_FCF_FPMA))
1752 *addr_mode = LPFC_FCF_FPMA;
1754 /* If matching connect list has a vlan id, use it */
1755 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1756 *vlan_id = conn_entry->conn_rec.vlan_tag;
1758 * If no vlan id is specified in connect list, use the vlan id
1761 else if (fcf_vlan_id)
1762 *vlan_id = fcf_vlan_id;
1764 *vlan_id = LPFC_FCOE_NULL_VID;
1773 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1774 * @phba: pointer to lpfc hba data structure.
1775 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1777 * This function check if there is any fcoe event pending while driver
1778 * scan FCF entries. If there is any pending event, it will restart the
1779 * FCF saning and return 1 else return 0.
1782 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1785 * If the Link is up and no FCoE events while in the
1786 * FCF discovery, no need to restart FCF discovery.
1788 if ((phba->link_state >= LPFC_LINK_UP) &&
1789 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1792 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1793 "2768 Pending link or FCF event during current "
1794 "handling of the previous event: link_state:x%x, "
1795 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1796 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1797 phba->fcoe_eventtag);
1799 spin_lock_irq(&phba->hbalock);
1800 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1801 spin_unlock_irq(&phba->hbalock);
1803 if (phba->link_state >= LPFC_LINK_UP) {
1804 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1805 "2780 Restart FCF table scan due to "
1806 "pending FCF event:evt_tag_at_scan:x%x, "
1807 "evt_tag_current:x%x\n",
1808 phba->fcoe_eventtag_at_fcf_scan,
1809 phba->fcoe_eventtag);
1810 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1813 * Do not continue FCF discovery and clear FCF_TS_INPROG
1816 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1817 "2833 Stop FCF discovery process due to link "
1818 "state change (x%x)\n", phba->link_state);
1819 spin_lock_irq(&phba->hbalock);
1820 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1821 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1822 spin_unlock_irq(&phba->hbalock);
1825 /* Unregister the currently registered FCF if required */
1827 spin_lock_irq(&phba->hbalock);
1828 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1829 spin_unlock_irq(&phba->hbalock);
1830 lpfc_sli4_unregister_fcf(phba);
1836 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1837 * @phba: pointer to lpfc hba data structure.
1838 * @fcf_cnt: number of eligible fcf record seen so far.
1840 * This function makes an running random selection decision on FCF record to
1841 * use through a sequence of @fcf_cnt eligible FCF records with equal
1842 * probability. To perform integer manunipulation of random numbers with
1843 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1844 * from prandom_u32() are taken as the random random number generated.
1846 * Returns true when outcome is for the newly read FCF record should be
1847 * chosen; otherwise, return false when outcome is for keeping the previously
1848 * chosen FCF record.
1851 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1855 /* Get 16-bit uniform random number */
1856 rand_num = 0xFFFF & prandom_u32();
1858 /* Decision with probability 1/fcf_cnt */
1859 if ((fcf_cnt * rand_num) < 0xFFFF)
1866 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1867 * @phba: pointer to lpfc hba data structure.
1868 * @mboxq: pointer to mailbox object.
1869 * @next_fcf_index: pointer to holder of next fcf index.
1871 * This routine parses the non-embedded fcf mailbox command by performing the
1872 * necessarily error checking, non-embedded read FCF record mailbox command
1873 * SGE parsing, and endianness swapping.
1875 * Returns the pointer to the new FCF record in the non-embedded mailbox
1876 * command DMA memory if successfully, other NULL.
1878 static struct fcf_record *
1879 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1880 uint16_t *next_fcf_index)
1883 struct lpfc_mbx_sge sge;
1884 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1885 uint32_t shdr_status, shdr_add_status, if_type;
1886 union lpfc_sli4_cfg_shdr *shdr;
1887 struct fcf_record *new_fcf_record;
1889 /* Get the first SGE entry from the non-embedded DMA memory. This
1890 * routine only uses a single SGE.
1892 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1893 if (unlikely(!mboxq->sge_array)) {
1894 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1895 "2524 Failed to get the non-embedded SGE "
1896 "virtual address\n");
1899 virt_addr = mboxq->sge_array->addr[0];
1901 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1902 lpfc_sli_pcimem_bcopy(shdr, shdr,
1903 sizeof(union lpfc_sli4_cfg_shdr));
1904 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1905 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1906 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1907 if (shdr_status || shdr_add_status) {
1908 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1909 if_type == LPFC_SLI_INTF_IF_TYPE_2)
1910 lpfc_printf_log(phba, KERN_ERR,
1912 "2726 READ_FCF_RECORD Indicates empty "
1915 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1916 "2521 READ_FCF_RECORD mailbox failed "
1917 "with status x%x add_status x%x, "
1918 "mbx\n", shdr_status, shdr_add_status);
1922 /* Interpreting the returned information of the FCF record */
1923 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1924 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1925 sizeof(struct lpfc_mbx_read_fcf_tbl));
1926 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1927 new_fcf_record = (struct fcf_record *)(virt_addr +
1928 sizeof(struct lpfc_mbx_read_fcf_tbl));
1929 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1930 offsetof(struct fcf_record, vlan_bitmap));
1931 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1932 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1934 return new_fcf_record;
1938 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1939 * @phba: pointer to lpfc hba data structure.
1940 * @fcf_record: pointer to the fcf record.
1941 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1942 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1944 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1948 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1949 struct fcf_record *fcf_record,
1951 uint16_t next_fcf_index)
1953 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1954 "2764 READ_FCF_RECORD:\n"
1955 "\tFCF_Index : x%x\n"
1956 "\tFCF_Avail : x%x\n"
1957 "\tFCF_Valid : x%x\n"
1959 "\tFIP_Priority : x%x\n"
1960 "\tMAC_Provider : x%x\n"
1961 "\tLowest VLANID : x%x\n"
1962 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1963 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1964 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1965 "\tNext_FCF_Index: x%x\n",
1966 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1967 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1968 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1969 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1970 fcf_record->fip_priority,
1971 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1973 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1974 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1975 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1976 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1977 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1978 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1979 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1980 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1981 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1982 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1983 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1984 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1985 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1986 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1987 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1988 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1989 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1990 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1991 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1992 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1993 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1994 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1999 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2000 * @phba: pointer to lpfc hba data structure.
2001 * @fcf_rec: pointer to an existing FCF record.
2002 * @new_fcf_record: pointer to a new FCF record.
2003 * @new_vlan_id: vlan id from the new FCF record.
2005 * This function performs matching test of a new FCF record against an existing
2006 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2007 * will not be used as part of the FCF record matching criteria.
2009 * Returns true if all the fields matching, otherwise returns false.
2012 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2013 struct lpfc_fcf_rec *fcf_rec,
2014 struct fcf_record *new_fcf_record,
2015 uint16_t new_vlan_id)
2017 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2018 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2020 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2022 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2024 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2026 if (fcf_rec->priority != new_fcf_record->fip_priority)
2032 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2033 * @vport: Pointer to vport object.
2034 * @fcf_index: index to next fcf.
2036 * This function processing the roundrobin fcf failover to next fcf index.
2037 * When this function is invoked, there will be a current fcf registered
2039 * Return: 0 for continue retrying flogi on currently registered fcf;
2040 * 1 for stop flogi on currently registered fcf;
2042 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2044 struct lpfc_hba *phba = vport->phba;
2047 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2048 spin_lock_irq(&phba->hbalock);
2049 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2050 spin_unlock_irq(&phba->hbalock);
2051 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2052 "2872 Devloss tmo with no eligible "
2053 "FCF, unregister in-use FCF (x%x) "
2054 "and rescan FCF table\n",
2055 phba->fcf.current_rec.fcf_indx);
2056 lpfc_unregister_fcf_rescan(phba);
2057 goto stop_flogi_current_fcf;
2059 /* Mark the end to FLOGI roundrobin failover */
2060 phba->hba_flag &= ~FCF_RR_INPROG;
2061 /* Allow action to new fcf asynchronous event */
2062 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2063 spin_unlock_irq(&phba->hbalock);
2064 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2065 "2865 No FCF available, stop roundrobin FCF "
2066 "failover and change port state:x%x/x%x\n",
2067 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2068 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2070 if (!phba->fcf.fcf_redisc_attempted) {
2071 lpfc_unregister_fcf(phba);
2073 rc = lpfc_sli4_redisc_fcf_table(phba);
2075 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2076 "3195 Rediscover FCF table\n");
2077 phba->fcf.fcf_redisc_attempted = 1;
2078 lpfc_sli4_clear_fcf_rr_bmask(phba);
2080 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2081 "3196 Rediscover FCF table "
2082 "failed. Status:x%x\n", rc);
2085 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2086 "3197 Already rediscover FCF table "
2087 "attempted. No more retry\n");
2089 goto stop_flogi_current_fcf;
2091 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2092 "2794 Try FLOGI roundrobin FCF failover to "
2093 "(x%x)\n", fcf_index);
2094 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2096 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2097 "2761 FLOGI roundrobin FCF failover "
2098 "failed (rc:x%x) to read FCF (x%x)\n",
2099 rc, phba->fcf.current_rec.fcf_indx);
2101 goto stop_flogi_current_fcf;
2105 stop_flogi_current_fcf:
2106 lpfc_can_disctmo(vport);
2111 * lpfc_sli4_fcf_pri_list_del
2112 * @phba: pointer to lpfc hba data structure.
2113 * @fcf_index: the index of the fcf record to delete
2114 * This routine checks the on list flag of the fcf_index to be deleted.
2115 * If it is one the list then it is removed from the list, and the flag
2116 * is cleared. This routine grab the hbalock before removing the fcf
2117 * record from the list.
2119 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2122 struct lpfc_fcf_pri *new_fcf_pri;
2124 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2125 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2126 "3058 deleting idx x%x pri x%x flg x%x\n",
2127 fcf_index, new_fcf_pri->fcf_rec.priority,
2128 new_fcf_pri->fcf_rec.flag);
2129 spin_lock_irq(&phba->hbalock);
2130 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2131 if (phba->fcf.current_rec.priority ==
2132 new_fcf_pri->fcf_rec.priority)
2133 phba->fcf.eligible_fcf_cnt--;
2134 list_del_init(&new_fcf_pri->list);
2135 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2137 spin_unlock_irq(&phba->hbalock);
2141 * lpfc_sli4_set_fcf_flogi_fail
2142 * @phba: pointer to lpfc hba data structure.
2143 * @fcf_index: the index of the fcf record to update
2144 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2145 * flag so the the round robin slection for the particular priority level
2146 * will try a different fcf record that does not have this bit set.
2147 * If the fcf record is re-read for any reason this flag is cleared brfore
2148 * adding it to the priority list.
2151 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2153 struct lpfc_fcf_pri *new_fcf_pri;
2154 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2155 spin_lock_irq(&phba->hbalock);
2156 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2157 spin_unlock_irq(&phba->hbalock);
2161 * lpfc_sli4_fcf_pri_list_add
2162 * @phba: pointer to lpfc hba data structure.
2163 * @fcf_index: the index of the fcf record to add
2164 * @new_fcf_record: pointer to a new FCF record.
2165 * This routine checks the priority of the fcf_index to be added.
2166 * If it is a lower priority than the current head of the fcf_pri list
2167 * then it is added to the list in the right order.
2168 * If it is the same priority as the current head of the list then it
2169 * is added to the head of the list and its bit in the rr_bmask is set.
2170 * If the fcf_index to be added is of a higher priority than the current
2171 * head of the list then the rr_bmask is cleared, its bit is set in the
2172 * rr_bmask and it is added to the head of the list.
2174 * 0=success 1=failure
2176 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2178 struct fcf_record *new_fcf_record)
2180 uint16_t current_fcf_pri;
2181 uint16_t last_index;
2182 struct lpfc_fcf_pri *fcf_pri;
2183 struct lpfc_fcf_pri *next_fcf_pri;
2184 struct lpfc_fcf_pri *new_fcf_pri;
2187 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2188 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2189 "3059 adding idx x%x pri x%x flg x%x\n",
2190 fcf_index, new_fcf_record->fip_priority,
2191 new_fcf_pri->fcf_rec.flag);
2192 spin_lock_irq(&phba->hbalock);
2193 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2194 list_del_init(&new_fcf_pri->list);
2195 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2196 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2197 if (list_empty(&phba->fcf.fcf_pri_list)) {
2198 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2199 ret = lpfc_sli4_fcf_rr_index_set(phba,
2200 new_fcf_pri->fcf_rec.fcf_index);
2204 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2205 LPFC_SLI4_FCF_TBL_INDX_MAX);
2206 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2207 ret = 0; /* Empty rr list */
2210 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2211 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2212 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2213 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2214 memset(phba->fcf.fcf_rr_bmask, 0,
2215 sizeof(*phba->fcf.fcf_rr_bmask));
2216 /* fcfs_at_this_priority_level = 1; */
2217 phba->fcf.eligible_fcf_cnt = 1;
2219 /* fcfs_at_this_priority_level++; */
2220 phba->fcf.eligible_fcf_cnt++;
2221 ret = lpfc_sli4_fcf_rr_index_set(phba,
2222 new_fcf_pri->fcf_rec.fcf_index);
2226 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2227 &phba->fcf.fcf_pri_list, list) {
2228 if (new_fcf_pri->fcf_rec.priority <=
2229 fcf_pri->fcf_rec.priority) {
2230 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2231 list_add(&new_fcf_pri->list,
2232 &phba->fcf.fcf_pri_list);
2234 list_add(&new_fcf_pri->list,
2235 &((struct lpfc_fcf_pri *)
2236 fcf_pri->list.prev)->list);
2239 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2240 || new_fcf_pri->fcf_rec.priority <
2241 next_fcf_pri->fcf_rec.priority) {
2242 list_add(&new_fcf_pri->list, &fcf_pri->list);
2246 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2252 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2253 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2254 spin_unlock_irq(&phba->hbalock);
2259 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2260 * @phba: pointer to lpfc hba data structure.
2261 * @mboxq: pointer to mailbox object.
2263 * This function iterates through all the fcf records available in
2264 * HBA and chooses the optimal FCF record for discovery. After finding
2265 * the FCF for discovery it registers the FCF record and kicks start
2267 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2268 * use an FCF record which matches fabric name and mac address of the
2269 * currently used FCF record.
2270 * If the driver supports only one FCF, it will try to use the FCF record
2271 * used by BOOT_BIOS.
2274 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2276 struct fcf_record *new_fcf_record;
2277 uint32_t boot_flag, addr_mode;
2278 uint16_t fcf_index, next_fcf_index;
2279 struct lpfc_fcf_rec *fcf_rec = NULL;
2280 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2281 bool select_new_fcf;
2284 /* If there is pending FCoE event restart FCF table scan */
2285 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2286 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2290 /* Parse the FCF record from the non-embedded mailbox command */
2291 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2293 if (!new_fcf_record) {
2294 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2295 "2765 Mailbox command READ_FCF_RECORD "
2296 "failed to retrieve a FCF record.\n");
2297 /* Let next new FCF event trigger fast failover */
2298 spin_lock_irq(&phba->hbalock);
2299 phba->hba_flag &= ~FCF_TS_INPROG;
2300 spin_unlock_irq(&phba->hbalock);
2301 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2305 /* Check the FCF record against the connection list */
2306 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2307 &addr_mode, &vlan_id);
2309 /* Log the FCF record information if turned on */
2310 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2314 * If the fcf record does not match with connect list entries
2315 * read the next entry; otherwise, this is an eligible FCF
2316 * record for roundrobin FCF failover.
2319 lpfc_sli4_fcf_pri_list_del(phba,
2320 bf_get(lpfc_fcf_record_fcf_index,
2322 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2323 "2781 FCF (x%x) failed connection "
2324 "list check: (x%x/x%x/%x)\n",
2325 bf_get(lpfc_fcf_record_fcf_index,
2327 bf_get(lpfc_fcf_record_fcf_avail,
2329 bf_get(lpfc_fcf_record_fcf_valid,
2331 bf_get(lpfc_fcf_record_fcf_sol,
2333 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2334 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2335 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2336 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2337 phba->fcf.current_rec.fcf_indx) {
2338 lpfc_printf_log(phba, KERN_ERR,
2340 "2862 FCF (x%x) matches property "
2341 "of in-use FCF (x%x)\n",
2342 bf_get(lpfc_fcf_record_fcf_index,
2344 phba->fcf.current_rec.fcf_indx);
2348 * In case the current in-use FCF record becomes
2349 * invalid/unavailable during FCF discovery that
2350 * was not triggered by fast FCF failover process,
2351 * treat it as fast FCF failover.
2353 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2354 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2355 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2356 "2835 Invalid in-use FCF "
2357 "(x%x), enter FCF failover "
2359 phba->fcf.current_rec.fcf_indx);
2360 spin_lock_irq(&phba->hbalock);
2361 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2362 spin_unlock_irq(&phba->hbalock);
2363 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2364 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2365 LPFC_FCOE_FCF_GET_FIRST);
2371 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2372 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2379 * If this is not the first FCF discovery of the HBA, use last
2380 * FCF record for the discovery. The condition that a rescan
2381 * matches the in-use FCF record: fabric name, switch name, mac
2382 * address, and vlan_id.
2384 spin_lock_irq(&phba->hbalock);
2385 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2386 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2387 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2388 new_fcf_record, vlan_id)) {
2389 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2390 phba->fcf.current_rec.fcf_indx) {
2391 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2392 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2393 /* Stop FCF redisc wait timer */
2394 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2396 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2397 /* Fast failover, mark completed */
2398 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2399 spin_unlock_irq(&phba->hbalock);
2400 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2401 "2836 New FCF matches in-use "
2402 "FCF (x%x), port_state:x%x, "
2404 phba->fcf.current_rec.fcf_indx,
2405 phba->pport->port_state,
2406 phba->pport->fc_flag);
2409 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2410 "2863 New FCF (x%x) matches "
2411 "property of in-use FCF (x%x)\n",
2412 bf_get(lpfc_fcf_record_fcf_index,
2414 phba->fcf.current_rec.fcf_indx);
2417 * Read next FCF record from HBA searching for the matching
2418 * with in-use record only if not during the fast failover
2419 * period. In case of fast failover period, it shall try to
2420 * determine whether the FCF record just read should be the
2423 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2424 spin_unlock_irq(&phba->hbalock);
2429 * Update on failover FCF record only if it's in FCF fast-failover
2430 * period; otherwise, update on current FCF record.
2432 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2433 fcf_rec = &phba->fcf.failover_rec;
2435 fcf_rec = &phba->fcf.current_rec;
2437 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2439 * If the driver FCF record does not have boot flag
2440 * set and new hba fcf record has boot flag set, use
2441 * the new hba fcf record.
2443 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2444 /* Choose this FCF record */
2445 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2446 "2837 Update current FCF record "
2447 "(x%x) with new FCF record (x%x)\n",
2449 bf_get(lpfc_fcf_record_fcf_index,
2451 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2452 addr_mode, vlan_id, BOOT_ENABLE);
2453 spin_unlock_irq(&phba->hbalock);
2457 * If the driver FCF record has boot flag set and the
2458 * new hba FCF record does not have boot flag, read
2459 * the next FCF record.
2461 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2462 spin_unlock_irq(&phba->hbalock);
2466 * If the new hba FCF record has lower priority value
2467 * than the driver FCF record, use the new record.
2469 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2470 /* Choose the new FCF record with lower priority */
2471 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2472 "2838 Update current FCF record "
2473 "(x%x) with new FCF record (x%x)\n",
2475 bf_get(lpfc_fcf_record_fcf_index,
2477 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2478 addr_mode, vlan_id, 0);
2479 /* Reset running random FCF selection count */
2480 phba->fcf.eligible_fcf_cnt = 1;
2481 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2482 /* Update running random FCF selection count */
2483 phba->fcf.eligible_fcf_cnt++;
2484 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2485 phba->fcf.eligible_fcf_cnt);
2486 if (select_new_fcf) {
2487 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2488 "2839 Update current FCF record "
2489 "(x%x) with new FCF record (x%x)\n",
2491 bf_get(lpfc_fcf_record_fcf_index,
2493 /* Choose the new FCF by random selection */
2494 __lpfc_update_fcf_record(phba, fcf_rec,
2496 addr_mode, vlan_id, 0);
2499 spin_unlock_irq(&phba->hbalock);
2503 * This is the first suitable FCF record, choose this record for
2504 * initial best-fit FCF.
2507 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2508 "2840 Update initial FCF candidate "
2510 bf_get(lpfc_fcf_record_fcf_index,
2512 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2513 addr_mode, vlan_id, (boot_flag ?
2515 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2516 /* Setup initial running random FCF selection count */
2517 phba->fcf.eligible_fcf_cnt = 1;
2519 spin_unlock_irq(&phba->hbalock);
2523 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2524 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2525 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2527 * Case of FCF fast failover scan
2531 * It has not found any suitable FCF record, cancel
2532 * FCF scan inprogress, and do nothing
2534 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2535 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2536 "2782 No suitable FCF found: "
2538 phba->fcoe_eventtag_at_fcf_scan,
2539 bf_get(lpfc_fcf_record_fcf_index,
2541 spin_lock_irq(&phba->hbalock);
2542 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2543 phba->hba_flag &= ~FCF_TS_INPROG;
2544 spin_unlock_irq(&phba->hbalock);
2545 /* Unregister in-use FCF and rescan */
2546 lpfc_printf_log(phba, KERN_INFO,
2548 "2864 On devloss tmo "
2549 "unreg in-use FCF and "
2550 "rescan FCF table\n");
2551 lpfc_unregister_fcf_rescan(phba);
2555 * Let next new FCF event trigger fast failover
2557 phba->hba_flag &= ~FCF_TS_INPROG;
2558 spin_unlock_irq(&phba->hbalock);
2562 * It has found a suitable FCF record that is not
2563 * the same as in-use FCF record, unregister the
2564 * in-use FCF record, replace the in-use FCF record
2565 * with the new FCF record, mark FCF fast failover
2566 * completed, and then start register the new FCF
2570 /* Unregister the current in-use FCF record */
2571 lpfc_unregister_fcf(phba);
2573 /* Replace in-use record with the new record */
2574 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2575 "2842 Replace in-use FCF (x%x) "
2576 "with failover FCF (x%x)\n",
2577 phba->fcf.current_rec.fcf_indx,
2578 phba->fcf.failover_rec.fcf_indx);
2579 memcpy(&phba->fcf.current_rec,
2580 &phba->fcf.failover_rec,
2581 sizeof(struct lpfc_fcf_rec));
2583 * Mark the fast FCF failover rediscovery completed
2584 * and the start of the first round of the roundrobin
2587 spin_lock_irq(&phba->hbalock);
2588 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2589 spin_unlock_irq(&phba->hbalock);
2590 /* Register to the new FCF record */
2591 lpfc_register_fcf(phba);
2594 * In case of transaction period to fast FCF failover,
2595 * do nothing when search to the end of the FCF table.
2597 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2598 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2601 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2602 phba->fcf.fcf_flag & FCF_IN_USE) {
2604 * In case the current in-use FCF record no
2605 * longer existed during FCF discovery that
2606 * was not triggered by fast FCF failover
2607 * process, treat it as fast FCF failover.
2609 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2610 "2841 In-use FCF record (x%x) "
2611 "not reported, entering fast "
2612 "FCF failover mode scanning.\n",
2613 phba->fcf.current_rec.fcf_indx);
2614 spin_lock_irq(&phba->hbalock);
2615 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2616 spin_unlock_irq(&phba->hbalock);
2617 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2618 LPFC_FCOE_FCF_GET_FIRST);
2621 /* Register to the new FCF record */
2622 lpfc_register_fcf(phba);
2625 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2629 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2630 lpfc_register_fcf(phba);
2636 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2637 * @phba: pointer to lpfc hba data structure.
2638 * @mboxq: pointer to mailbox object.
2640 * This is the callback function for FLOGI failure roundrobin FCF failover
2641 * read FCF record mailbox command from the eligible FCF record bmask for
2642 * performing the failover. If the FCF read back is not valid/available, it
2643 * fails through to retrying FLOGI to the currently registered FCF again.
2644 * Otherwise, if the FCF read back is valid and available, it will set the
2645 * newly read FCF record to the failover FCF record, unregister currently
2646 * registered FCF record, copy the failover FCF record to the current
2647 * FCF record, and then register the current FCF record before proceeding
2648 * to trying FLOGI on the new failover FCF.
2651 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2653 struct fcf_record *new_fcf_record;
2654 uint32_t boot_flag, addr_mode;
2655 uint16_t next_fcf_index, fcf_index;
2656 uint16_t current_fcf_index;
2660 /* If link state is not up, stop the roundrobin failover process */
2661 if (phba->link_state < LPFC_LINK_UP) {
2662 spin_lock_irq(&phba->hbalock);
2663 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2664 phba->hba_flag &= ~FCF_RR_INPROG;
2665 spin_unlock_irq(&phba->hbalock);
2669 /* Parse the FCF record from the non-embedded mailbox command */
2670 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2672 if (!new_fcf_record) {
2673 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2674 "2766 Mailbox command READ_FCF_RECORD "
2675 "failed to retrieve a FCF record. "
2676 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2677 phba->fcf.fcf_flag);
2678 lpfc_unregister_fcf_rescan(phba);
2682 /* Get the needed parameters from FCF record */
2683 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2684 &addr_mode, &vlan_id);
2686 /* Log the FCF record information if turned on */
2687 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2690 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2692 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2693 "2848 Remove ineligible FCF (x%x) from "
2694 "from roundrobin bmask\n", fcf_index);
2695 /* Clear roundrobin bmask bit for ineligible FCF */
2696 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2697 /* Perform next round of roundrobin FCF failover */
2698 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2699 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2705 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2706 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2707 "2760 Perform FLOGI roundrobin FCF failover: "
2708 "FCF (x%x) back to FCF (x%x)\n",
2709 phba->fcf.current_rec.fcf_indx, fcf_index);
2710 /* Wait 500 ms before retrying FLOGI to current FCF */
2712 lpfc_issue_init_vfi(phba->pport);
2716 /* Upload new FCF record to the failover FCF record */
2717 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2718 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2719 phba->fcf.failover_rec.fcf_indx, fcf_index);
2720 spin_lock_irq(&phba->hbalock);
2721 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2722 new_fcf_record, addr_mode, vlan_id,
2723 (boot_flag ? BOOT_ENABLE : 0));
2724 spin_unlock_irq(&phba->hbalock);
2726 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2728 /* Unregister the current in-use FCF record */
2729 lpfc_unregister_fcf(phba);
2731 /* Replace in-use record with the new record */
2732 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2733 sizeof(struct lpfc_fcf_rec));
2735 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2736 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2737 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2740 lpfc_register_fcf(phba);
2742 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2746 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2747 * @phba: pointer to lpfc hba data structure.
2748 * @mboxq: pointer to mailbox object.
2750 * This is the callback function of read FCF record mailbox command for
2751 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2752 * failover when a new FCF event happened. If the FCF read back is
2753 * valid/available and it passes the connection list check, it updates
2754 * the bmask for the eligible FCF record for roundrobin failover.
2757 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2759 struct fcf_record *new_fcf_record;
2760 uint32_t boot_flag, addr_mode;
2761 uint16_t fcf_index, next_fcf_index;
2765 /* If link state is not up, no need to proceed */
2766 if (phba->link_state < LPFC_LINK_UP)
2769 /* If FCF discovery period is over, no need to proceed */
2770 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2773 /* Parse the FCF record from the non-embedded mailbox command */
2774 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2776 if (!new_fcf_record) {
2777 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2778 "2767 Mailbox command READ_FCF_RECORD "
2779 "failed to retrieve a FCF record.\n");
2783 /* Check the connection list for eligibility */
2784 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2785 &addr_mode, &vlan_id);
2787 /* Log the FCF record information if turned on */
2788 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2794 /* Update the eligible FCF record index bmask */
2795 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2797 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2800 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2804 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2805 * @phba: pointer to lpfc hba data structure.
2806 * @mboxq: pointer to mailbox data structure.
2808 * This function handles completion of init vfi mailbox command.
2811 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2813 struct lpfc_vport *vport = mboxq->vport;
2816 * VFI not supported on interface type 0, just do the flogi
2817 * Also continue if the VFI is in use - just use the same one.
2819 if (mboxq->u.mb.mbxStatus &&
2820 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2821 LPFC_SLI_INTF_IF_TYPE_0) &&
2822 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2823 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2824 "2891 Init VFI mailbox failed 0x%x\n",
2825 mboxq->u.mb.mbxStatus);
2826 mempool_free(mboxq, phba->mbox_mem_pool);
2827 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2831 lpfc_initial_flogi(vport);
2832 mempool_free(mboxq, phba->mbox_mem_pool);
2837 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2838 * @vport: pointer to lpfc_vport data structure.
2840 * This function issue a init_vfi mailbox command to initialize the VFI and
2841 * VPI for the physical port.
2844 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2846 LPFC_MBOXQ_t *mboxq;
2848 struct lpfc_hba *phba = vport->phba;
2850 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2852 lpfc_printf_vlog(vport, KERN_ERR,
2853 LOG_TRACE_EVENT, "2892 Failed to allocate "
2854 "init_vfi mailbox\n");
2857 lpfc_init_vfi(mboxq, vport);
2858 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2859 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2860 if (rc == MBX_NOT_FINISHED) {
2861 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2862 "2893 Failed to issue init_vfi mailbox\n");
2863 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2868 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2869 * @phba: pointer to lpfc hba data structure.
2870 * @mboxq: pointer to mailbox data structure.
2872 * This function handles completion of init vpi mailbox command.
2875 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2877 struct lpfc_vport *vport = mboxq->vport;
2878 struct lpfc_nodelist *ndlp;
2879 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2881 if (mboxq->u.mb.mbxStatus) {
2882 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2883 "2609 Init VPI mailbox failed 0x%x\n",
2884 mboxq->u.mb.mbxStatus);
2885 mempool_free(mboxq, phba->mbox_mem_pool);
2886 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2889 spin_lock_irq(shost->host_lock);
2890 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2891 spin_unlock_irq(shost->host_lock);
2893 /* If this port is physical port or FDISC is done, do reg_vpi */
2894 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2895 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2897 lpfc_printf_vlog(vport, KERN_ERR,
2899 "2731 Cannot find fabric "
2900 "controller node\n");
2902 lpfc_register_new_vport(phba, vport, ndlp);
2903 mempool_free(mboxq, phba->mbox_mem_pool);
2907 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2908 lpfc_initial_fdisc(vport);
2910 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2911 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2912 "2606 No NPIV Fabric support\n");
2914 mempool_free(mboxq, phba->mbox_mem_pool);
2919 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2920 * @vport: pointer to lpfc_vport data structure.
2922 * This function issue a init_vpi mailbox command to initialize
2923 * VPI for the vport.
2926 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2928 LPFC_MBOXQ_t *mboxq;
2931 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2932 vpi = lpfc_alloc_vpi(vport->phba);
2934 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2935 "3303 Failed to obtain vport vpi\n");
2936 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2942 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2944 lpfc_printf_vlog(vport, KERN_ERR,
2945 LOG_TRACE_EVENT, "2607 Failed to allocate "
2946 "init_vpi mailbox\n");
2949 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2950 mboxq->vport = vport;
2951 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2952 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2953 if (rc == MBX_NOT_FINISHED) {
2954 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2955 "2608 Failed to issue init_vpi mailbox\n");
2956 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2961 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2962 * @phba: pointer to lpfc hba data structure.
2964 * This function loops through the list of vports on the @phba and issues an
2965 * FDISC if possible.
2968 lpfc_start_fdiscs(struct lpfc_hba *phba)
2970 struct lpfc_vport **vports;
2973 vports = lpfc_create_vport_work_array(phba);
2974 if (vports != NULL) {
2975 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2976 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2978 /* There are no vpi for this vport */
2979 if (vports[i]->vpi > phba->max_vpi) {
2980 lpfc_vport_set_state(vports[i],
2984 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2985 lpfc_vport_set_state(vports[i],
2989 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2990 lpfc_issue_init_vpi(vports[i]);
2993 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2994 lpfc_initial_fdisc(vports[i]);
2996 lpfc_vport_set_state(vports[i],
2997 FC_VPORT_NO_FABRIC_SUPP);
2998 lpfc_printf_vlog(vports[i], KERN_ERR,
3001 "Fabric support\n");
3005 lpfc_destroy_vport_work_array(phba, vports);
3009 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3011 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
3012 struct lpfc_vport *vport = mboxq->vport;
3013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3016 * VFI not supported for interface type 0, so ignore any mailbox
3017 * error (except VFI in use) and continue with the discovery.
3019 if (mboxq->u.mb.mbxStatus &&
3020 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3021 LPFC_SLI_INTF_IF_TYPE_0) &&
3022 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3023 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3024 "2018 REG_VFI mbxStatus error x%x "
3026 mboxq->u.mb.mbxStatus, vport->port_state);
3027 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3028 /* FLOGI failed, use loop map to make discovery list */
3029 lpfc_disc_list_loopmap(vport);
3030 /* Start discovery */
3031 lpfc_disc_start(vport);
3034 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3038 /* If the VFI is already registered, there is nothing else to do
3039 * Unless this was a VFI update and we are in PT2PT mode, then
3040 * we should drop through to set the port state to ready.
3042 if (vport->fc_flag & FC_VFI_REGISTERED)
3043 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3044 vport->fc_flag & FC_PT2PT))
3047 /* The VPI is implicitly registered when the VFI is registered */
3048 spin_lock_irq(shost->host_lock);
3049 vport->vpi_state |= LPFC_VPI_REGISTERED;
3050 vport->fc_flag |= FC_VFI_REGISTERED;
3051 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3052 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3053 spin_unlock_irq(shost->host_lock);
3055 /* In case SLI4 FC loopback test, we are ready */
3056 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3057 (phba->link_flag & LS_LOOPBACK_MODE)) {
3058 phba->link_state = LPFC_HBA_READY;
3062 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3063 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3064 "alpacnt:%d LinkState:%x topology:%x\n",
3065 vport->port_state, vport->fc_flag, vport->fc_myDID,
3066 vport->phba->alpa_map[0],
3067 phba->link_state, phba->fc_topology);
3069 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3071 * For private loop or for NPort pt2pt,
3072 * just start discovery and we are done.
3074 if ((vport->fc_flag & FC_PT2PT) ||
3075 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3076 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3078 /* Use loop map to make discovery list */
3079 lpfc_disc_list_loopmap(vport);
3080 /* Start discovery */
3081 if (vport->fc_flag & FC_PT2PT)
3082 vport->port_state = LPFC_VPORT_READY;
3084 lpfc_disc_start(vport);
3086 lpfc_start_fdiscs(phba);
3087 lpfc_do_scr_ns_plogi(phba, vport);
3092 mempool_free(mboxq, phba->mbox_mem_pool);
3094 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3101 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3103 MAILBOX_t *mb = &pmb->u.mb;
3104 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3105 struct lpfc_vport *vport = pmb->vport;
3106 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3107 struct serv_parm *sp = &vport->fc_sparam;
3110 /* Check for error */
3111 if (mb->mbxStatus) {
3112 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3113 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3114 "0319 READ_SPARAM mbxStatus error x%x "
3116 mb->mbxStatus, vport->port_state);
3117 lpfc_linkdown(phba);
3121 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3122 sizeof (struct serv_parm));
3124 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3125 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3126 ed_tov = (ed_tov + 999999) / 1000000;
3128 phba->fc_edtov = ed_tov;
3129 phba->fc_ratov = (2 * ed_tov) / 1000;
3130 if (phba->fc_ratov < FF_DEF_RATOV) {
3131 /* RA_TOV should be atleast 10sec for initial flogi */
3132 phba->fc_ratov = FF_DEF_RATOV;
3135 lpfc_update_vport_wwn(vport);
3136 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3137 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3138 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3139 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3142 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3144 mempool_free(pmb, phba->mbox_mem_pool);
3146 /* Check if sending the FLOGI is being deferred to after we get
3147 * up to date CSPs from MBX_READ_SPARAM.
3149 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3150 lpfc_initial_flogi(vport);
3151 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3156 pmb->ctx_buf = NULL;
3157 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3159 lpfc_issue_clear_la(phba, vport);
3160 mempool_free(pmb, phba->mbox_mem_pool);
3165 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3167 struct lpfc_vport *vport = phba->pport;
3168 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3169 struct Scsi_Host *shost;
3171 struct lpfc_dmabuf *mp;
3173 struct fcf_record *fcf_record;
3174 uint32_t fc_flags = 0;
3175 unsigned long iflags;
3177 spin_lock_irqsave(&phba->hbalock, iflags);
3178 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3180 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3181 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3182 case LPFC_LINK_SPEED_1GHZ:
3183 case LPFC_LINK_SPEED_2GHZ:
3184 case LPFC_LINK_SPEED_4GHZ:
3185 case LPFC_LINK_SPEED_8GHZ:
3186 case LPFC_LINK_SPEED_10GHZ:
3187 case LPFC_LINK_SPEED_16GHZ:
3188 case LPFC_LINK_SPEED_32GHZ:
3189 case LPFC_LINK_SPEED_64GHZ:
3190 case LPFC_LINK_SPEED_128GHZ:
3193 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3198 if (phba->fc_topology &&
3199 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3200 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3201 "3314 Toplogy changed was 0x%x is 0x%x\n",
3203 bf_get(lpfc_mbx_read_top_topology, la));
3204 phba->fc_topology_changed = 1;
3207 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3208 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3210 shost = lpfc_shost_from_vport(vport);
3211 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3212 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3214 /* if npiv is enabled and this adapter supports npiv log
3215 * a message that npiv is not supported in this topology
3217 if (phba->cfg_enable_npiv && phba->max_vpi)
3218 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3219 "1309 Link Up Event npiv not supported in loop "
3221 /* Get Loop Map information */
3222 if (bf_get(lpfc_mbx_read_top_il, la))
3223 fc_flags |= FC_LBIT;
3225 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3226 i = la->lilpBde64.tus.f.bdeSize;
3229 phba->alpa_map[0] = 0;
3231 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3242 numalpa = phba->alpa_map[0];
3244 while (j < numalpa) {
3245 memset(un.pamap, 0, 16);
3246 for (k = 1; j < numalpa; k++) {
3248 phba->alpa_map[j + 1];
3253 /* Link Up Event ALPA map */
3254 lpfc_printf_log(phba,
3257 "1304 Link Up Event "
3258 "ALPA map Data: x%x "
3260 un.pa.wd1, un.pa.wd2,
3261 un.pa.wd3, un.pa.wd4);
3266 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3267 if (phba->max_vpi && phba->cfg_enable_npiv &&
3268 (phba->sli_rev >= LPFC_SLI_REV3))
3269 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3271 vport->fc_myDID = phba->fc_pref_DID;
3272 fc_flags |= FC_LBIT;
3274 spin_unlock_irqrestore(&phba->hbalock, iflags);
3277 spin_lock_irqsave(shost->host_lock, iflags);
3278 vport->fc_flag |= fc_flags;
3279 spin_unlock_irqrestore(shost->host_lock, iflags);
3285 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3289 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3291 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3294 sparam_mbox->vport = vport;
3295 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3296 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3297 if (rc == MBX_NOT_FINISHED) {
3298 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3299 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3301 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3305 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3306 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3309 vport->port_state = LPFC_LOCAL_CFG_LINK;
3310 lpfc_config_link(phba, cfglink_mbox);
3311 cfglink_mbox->vport = vport;
3312 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3313 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3314 if (rc == MBX_NOT_FINISHED) {
3315 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3319 vport->port_state = LPFC_VPORT_UNKNOWN;
3321 * Add the driver's default FCF record at FCF index 0 now. This
3322 * is phase 1 implementation that support FCF index 0 and driver
3325 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3326 fcf_record = kzalloc(sizeof(struct fcf_record),
3328 if (unlikely(!fcf_record)) {
3329 lpfc_printf_log(phba, KERN_ERR,
3331 "2554 Could not allocate memory for "
3337 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3338 LPFC_FCOE_FCF_DEF_INDEX);
3339 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3341 lpfc_printf_log(phba, KERN_ERR,
3343 "2013 Could not manually add FCF "
3344 "record 0, status %d\n", rc);
3352 * The driver is expected to do FIP/FCF. Call the port
3353 * and get the FCF Table.
3355 spin_lock_irqsave(&phba->hbalock, iflags);
3356 if (phba->hba_flag & FCF_TS_INPROG) {
3357 spin_unlock_irqrestore(&phba->hbalock, iflags);
3360 /* This is the initial FCF discovery scan */
3361 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3362 spin_unlock_irqrestore(&phba->hbalock, iflags);
3363 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3364 "2778 Start FCF table scan at linkup\n");
3365 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3366 LPFC_FCOE_FCF_GET_FIRST);
3368 spin_lock_irqsave(&phba->hbalock, iflags);
3369 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3370 spin_unlock_irqrestore(&phba->hbalock, iflags);
3373 /* Reset FCF roundrobin bmask for new discovery */
3374 lpfc_sli4_clear_fcf_rr_bmask(phba);
3377 /* Prepare for LINK up registrations */
3378 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3379 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3380 init_utsname()->nodename);
3383 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3384 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3385 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3386 vport->port_state, sparam_mbox, cfglink_mbox);
3387 lpfc_issue_clear_la(phba, vport);
3392 lpfc_enable_la(struct lpfc_hba *phba)
3395 struct lpfc_sli *psli = &phba->sli;
3396 spin_lock_irq(&phba->hbalock);
3397 psli->sli_flag |= LPFC_PROCESS_LA;
3398 if (phba->sli_rev <= LPFC_SLI_REV3) {
3399 control = readl(phba->HCregaddr);
3400 control |= HC_LAINT_ENA;
3401 writel(control, phba->HCregaddr);
3402 readl(phba->HCregaddr); /* flush */
3404 spin_unlock_irq(&phba->hbalock);
3408 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3410 lpfc_linkdown(phba);
3411 lpfc_enable_la(phba);
3412 lpfc_unregister_unused_fcf(phba);
3413 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3418 * This routine handles processing a READ_TOPOLOGY mailbox
3419 * command upon completion. It is setup in the LPFC_MBOXQ
3420 * as the completion routine when the command is
3421 * handed off to the SLI layer. SLI4 only.
3424 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3426 struct lpfc_vport *vport = pmb->vport;
3427 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3428 struct lpfc_mbx_read_top *la;
3429 struct lpfc_sli_ring *pring;
3430 MAILBOX_t *mb = &pmb->u.mb;
3431 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3433 unsigned long iflags;
3435 /* Unblock ELS traffic */
3436 pring = lpfc_phba_elsring(phba);
3438 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3440 /* Check for error */
3441 if (mb->mbxStatus) {
3442 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3443 "1307 READ_LA mbox error x%x state x%x\n",
3444 mb->mbxStatus, vport->port_state);
3445 lpfc_mbx_issue_link_down(phba);
3446 phba->link_state = LPFC_HBA_ERROR;
3447 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3450 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3451 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3453 memcpy(&phba->alpa_map[0], mp->virt, 128);
3455 spin_lock_irqsave(shost->host_lock, iflags);
3456 if (bf_get(lpfc_mbx_read_top_pb, la))
3457 vport->fc_flag |= FC_BYPASSED_MODE;
3459 vport->fc_flag &= ~FC_BYPASSED_MODE;
3460 spin_unlock_irqrestore(shost->host_lock, iflags);
3462 if (phba->fc_eventTag <= la->eventTag) {
3463 phba->fc_stat.LinkMultiEvent++;
3464 if (attn_type == LPFC_ATT_LINK_UP)
3465 if (phba->fc_eventTag != 0)
3466 lpfc_linkdown(phba);
3469 phba->fc_eventTag = la->eventTag;
3470 if (phba->sli_rev < LPFC_SLI_REV4) {
3471 spin_lock_irqsave(&phba->hbalock, iflags);
3472 if (bf_get(lpfc_mbx_read_top_mm, la))
3473 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3475 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3476 spin_unlock_irqrestore(&phba->hbalock, iflags);
3479 phba->link_events++;
3480 if ((attn_type == LPFC_ATT_LINK_UP) &&
3481 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3482 phba->fc_stat.LinkUp++;
3483 if (phba->link_flag & LS_LOOPBACK_MODE) {
3484 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3485 "1306 Link Up Event in loop back mode "
3486 "x%x received Data: x%x x%x x%x x%x\n",
3487 la->eventTag, phba->fc_eventTag,
3488 bf_get(lpfc_mbx_read_top_alpa_granted,
3490 bf_get(lpfc_mbx_read_top_link_spd, la),
3493 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3494 "1303 Link Up Event x%x received "
3495 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3496 la->eventTag, phba->fc_eventTag,
3497 bf_get(lpfc_mbx_read_top_alpa_granted,
3499 bf_get(lpfc_mbx_read_top_link_spd, la),
3501 bf_get(lpfc_mbx_read_top_mm, la),
3502 bf_get(lpfc_mbx_read_top_fa, la),
3503 phba->wait_4_mlo_maint_flg);
3505 lpfc_mbx_process_link_up(phba, la);
3506 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3507 attn_type == LPFC_ATT_UNEXP_WWPN) {
3508 phba->fc_stat.LinkDown++;
3509 if (phba->link_flag & LS_LOOPBACK_MODE)
3510 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3511 "1308 Link Down Event in loop back mode "
3513 "Data: x%x x%x x%x\n",
3514 la->eventTag, phba->fc_eventTag,
3515 phba->pport->port_state, vport->fc_flag);
3516 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3517 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3518 "1313 Link Down Unexpected FA WWPN Event x%x "
3519 "received Data: x%x x%x x%x x%x x%x\n",
3520 la->eventTag, phba->fc_eventTag,
3521 phba->pport->port_state, vport->fc_flag,
3522 bf_get(lpfc_mbx_read_top_mm, la),
3523 bf_get(lpfc_mbx_read_top_fa, la));
3525 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3526 "1305 Link Down Event x%x received "
3527 "Data: x%x x%x x%x x%x x%x\n",
3528 la->eventTag, phba->fc_eventTag,
3529 phba->pport->port_state, vport->fc_flag,
3530 bf_get(lpfc_mbx_read_top_mm, la),
3531 bf_get(lpfc_mbx_read_top_fa, la));
3532 lpfc_mbx_issue_link_down(phba);
3534 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3535 attn_type == LPFC_ATT_LINK_UP) {
3536 if (phba->link_state != LPFC_LINK_DOWN) {
3537 phba->fc_stat.LinkDown++;
3538 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3539 "1312 Link Down Event x%x received "
3540 "Data: x%x x%x x%x\n",
3541 la->eventTag, phba->fc_eventTag,
3542 phba->pport->port_state, vport->fc_flag);
3543 lpfc_mbx_issue_link_down(phba);
3545 lpfc_enable_la(phba);
3547 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3548 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3549 "Data: x%x x%x x%x\n",
3550 la->eventTag, phba->fc_eventTag,
3551 phba->pport->port_state, vport->fc_flag);
3553 * The cmnd that triggered this will be waiting for this
3556 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3557 if (phba->wait_4_mlo_maint_flg) {
3558 phba->wait_4_mlo_maint_flg = 0;
3559 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3563 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3564 bf_get(lpfc_mbx_read_top_fa, la)) {
3565 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3566 lpfc_issue_clear_la(phba, vport);
3567 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3569 bf_get(lpfc_mbx_read_top_fa, la));
3572 lpfc_mbx_cmpl_read_topology_free_mbuf:
3573 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3575 mempool_free(pmb, phba->mbox_mem_pool);
3580 * This routine handles processing a REG_LOGIN mailbox
3581 * command upon completion. It is setup in the LPFC_MBOXQ
3582 * as the completion routine when the command is
3583 * handed off to the SLI layer.
3586 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3588 struct lpfc_vport *vport = pmb->vport;
3589 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3590 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3592 pmb->ctx_buf = NULL;
3593 pmb->ctx_ndlp = NULL;
3595 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3596 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3597 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3598 kref_read(&ndlp->kref),
3600 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3601 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3603 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3604 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3605 /* We rcvd a rscn after issuing this
3606 * mbox reg login, we may have cycled
3607 * back through the state and be
3608 * back at reg login state so this
3609 * mbox needs to be ignored becase
3610 * there is another reg login in
3613 spin_lock_irq(&ndlp->lock);
3614 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3615 spin_unlock_irq(&ndlp->lock);
3618 * We cannot leave the RPI registered because
3619 * if we go thru discovery again for this ndlp
3620 * a subsequent REG_RPI will fail.
3622 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3623 lpfc_unreg_rpi(vport, ndlp);
3626 /* Call state machine */
3627 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3629 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3631 mempool_free(pmb, phba->mbox_mem_pool);
3632 /* decrement the node reference count held for this callback
3641 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3643 MAILBOX_t *mb = &pmb->u.mb;
3644 struct lpfc_vport *vport = pmb->vport;
3645 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3647 switch (mb->mbxStatus) {
3650 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3651 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3654 /* If VPI is busy, reset the HBA */
3656 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3657 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3658 vport->vpi, mb->mbxStatus);
3659 if (!(phba->pport->load_flag & FC_UNLOADING))
3660 lpfc_workq_post_event(phba, NULL, NULL,
3661 LPFC_EVT_RESET_HBA);
3663 spin_lock_irq(shost->host_lock);
3664 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3665 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3666 spin_unlock_irq(shost->host_lock);
3667 vport->unreg_vpi_cmpl = VPORT_OK;
3668 mempool_free(pmb, phba->mbox_mem_pool);
3669 lpfc_cleanup_vports_rrqs(vport, NULL);
3671 * This shost reference might have been taken at the beginning of
3672 * lpfc_vport_delete()
3674 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3675 scsi_host_put(shost);
3679 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3681 struct lpfc_hba *phba = vport->phba;
3685 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3689 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3690 mbox->vport = vport;
3691 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3692 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3693 if (rc == MBX_NOT_FINISHED) {
3694 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3695 "1800 Could not issue unreg_vpi\n");
3696 mempool_free(mbox, phba->mbox_mem_pool);
3697 vport->unreg_vpi_cmpl = VPORT_ERROR;
3704 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3706 struct lpfc_vport *vport = pmb->vport;
3707 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3708 MAILBOX_t *mb = &pmb->u.mb;
3710 switch (mb->mbxStatus) {
3714 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3715 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3717 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3718 spin_lock_irq(shost->host_lock);
3719 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3720 spin_unlock_irq(shost->host_lock);
3721 vport->fc_myDID = 0;
3723 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3724 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3725 if (phba->nvmet_support)
3726 lpfc_nvmet_update_targetport(phba);
3728 lpfc_nvme_update_localport(vport);
3733 spin_lock_irq(shost->host_lock);
3734 vport->vpi_state |= LPFC_VPI_REGISTERED;
3735 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3736 spin_unlock_irq(shost->host_lock);
3737 vport->num_disc_nodes = 0;
3738 /* go thru NPR list and issue ELS PLOGIs */
3739 if (vport->fc_npr_cnt)
3740 lpfc_els_disc_plogi(vport);
3742 if (!vport->num_disc_nodes) {
3743 spin_lock_irq(shost->host_lock);
3744 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3745 spin_unlock_irq(shost->host_lock);
3746 lpfc_can_disctmo(vport);
3748 vport->port_state = LPFC_VPORT_READY;
3751 mempool_free(pmb, phba->mbox_mem_pool);
3756 * lpfc_create_static_vport - Read HBA config region to create static vports.
3757 * @phba: pointer to lpfc hba data structure.
3759 * This routine issue a DUMP mailbox command for config region 22 to get
3760 * the list of static vports to be created. The function create vports
3761 * based on the information returned from the HBA.
3764 lpfc_create_static_vport(struct lpfc_hba *phba)
3766 LPFC_MBOXQ_t *pmb = NULL;
3768 struct static_vport_info *vport_info;
3769 int mbx_wait_rc = 0, i;
3770 struct fc_vport_identifiers vport_id;
3771 struct fc_vport *new_fc_vport;
3772 struct Scsi_Host *shost;
3773 struct lpfc_vport *vport;
3774 uint16_t offset = 0;
3775 uint8_t *vport_buff;
3776 struct lpfc_dmabuf *mp;
3777 uint32_t byte_count = 0;
3779 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3781 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3782 "0542 lpfc_create_static_vport failed to"
3783 " allocate mailbox memory\n");
3786 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3789 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3791 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3792 "0543 lpfc_create_static_vport failed to"
3793 " allocate vport_info\n");
3794 mempool_free(pmb, phba->mbox_mem_pool);
3798 vport_buff = (uint8_t *) vport_info;
3800 /* free dma buffer from previous round */
3802 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3803 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3806 if (lpfc_dump_static_vport(phba, pmb, offset))
3809 pmb->vport = phba->pport;
3810 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3813 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3814 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3815 "0544 lpfc_create_static_vport failed to"
3816 " issue dump mailbox command ret 0x%x "
3818 mbx_wait_rc, mb->mbxStatus);
3822 if (phba->sli_rev == LPFC_SLI_REV4) {
3823 byte_count = pmb->u.mqe.un.mb_words[5];
3824 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3825 if (byte_count > sizeof(struct static_vport_info) -
3827 byte_count = sizeof(struct static_vport_info)
3829 memcpy(vport_buff + offset, mp->virt, byte_count);
3830 offset += byte_count;
3832 if (mb->un.varDmp.word_cnt >
3833 sizeof(struct static_vport_info) - offset)
3834 mb->un.varDmp.word_cnt =
3835 sizeof(struct static_vport_info)
3837 byte_count = mb->un.varDmp.word_cnt;
3838 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3839 vport_buff + offset,
3842 offset += byte_count;
3845 } while (byte_count &&
3846 offset < sizeof(struct static_vport_info));
3849 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3850 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3851 != VPORT_INFO_REV)) {
3852 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3853 "0545 lpfc_create_static_vport bad"
3854 " information header 0x%x 0x%x\n",
3855 le32_to_cpu(vport_info->signature),
3856 le32_to_cpu(vport_info->rev) &
3857 VPORT_INFO_REV_MASK);
3862 shost = lpfc_shost_from_vport(phba->pport);
3864 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3865 memset(&vport_id, 0, sizeof(vport_id));
3866 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3867 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3868 if (!vport_id.port_name || !vport_id.node_name)
3871 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3872 vport_id.vport_type = FC_PORTTYPE_NPIV;
3873 vport_id.disable = false;
3874 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3876 if (!new_fc_vport) {
3877 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3878 "0546 lpfc_create_static_vport failed to"
3883 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3884 vport->vport_flag |= STATIC_VPORT;
3889 if (mbx_wait_rc != MBX_TIMEOUT) {
3891 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3892 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3895 mempool_free(pmb, phba->mbox_mem_pool);
3902 * This routine handles processing a Fabric REG_LOGIN mailbox
3903 * command upon completion. It is setup in the LPFC_MBOXQ
3904 * as the completion routine when the command is
3905 * handed off to the SLI layer.
3908 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3910 struct lpfc_vport *vport = pmb->vport;
3911 MAILBOX_t *mb = &pmb->u.mb;
3912 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3913 struct lpfc_nodelist *ndlp;
3914 struct Scsi_Host *shost;
3916 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3917 pmb->ctx_ndlp = NULL;
3918 pmb->ctx_buf = NULL;
3920 if (mb->mbxStatus) {
3921 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3922 "0258 Register Fabric login error: 0x%x\n",
3924 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3926 mempool_free(pmb, phba->mbox_mem_pool);
3928 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3929 /* FLOGI failed, use loop map to make discovery list */
3930 lpfc_disc_list_loopmap(vport);
3932 /* Start discovery */
3933 lpfc_disc_start(vport);
3934 /* Decrement the reference count to ndlp after the
3935 * reference to the ndlp are done.
3941 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3942 /* Decrement the reference count to ndlp after the reference
3943 * to the ndlp are done.
3949 if (phba->sli_rev < LPFC_SLI_REV4)
3950 ndlp->nlp_rpi = mb->un.varWords[0];
3951 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3952 ndlp->nlp_type |= NLP_FABRIC;
3953 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3955 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3956 /* when physical port receive logo donot start
3957 * vport discovery */
3958 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3959 lpfc_start_fdiscs(phba);
3961 shost = lpfc_shost_from_vport(vport);
3962 spin_lock_irq(shost->host_lock);
3963 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3964 spin_unlock_irq(shost->host_lock);
3966 lpfc_do_scr_ns_plogi(phba, vport);
3969 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3971 mempool_free(pmb, phba->mbox_mem_pool);
3973 /* Drop the reference count from the mbox at the end after
3974 * all the current reference to the ndlp have been done.
3981 * This routine will issue a GID_FT for each FC4 Type supported
3982 * by the driver. ALL GID_FTs must complete before discovery is started.
3985 lpfc_issue_gidft(struct lpfc_vport *vport)
3987 /* Good status, issue CT Request to NameServer */
3988 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3989 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
3990 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3991 /* Cannot issue NameServer FCP Query, so finish up
3994 lpfc_printf_vlog(vport, KERN_ERR,
3996 "0604 %s FC TYPE %x %s\n",
3997 "Failed to issue GID_FT to ",
3999 "Finishing discovery.");
4005 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4006 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4007 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4008 /* Cannot issue NameServer NVME Query, so finish up
4011 lpfc_printf_vlog(vport, KERN_ERR,
4013 "0605 %s FC_TYPE %x %s %d\n",
4014 "Failed to issue GID_FT to ",
4016 "Finishing discovery: gidftinp ",
4018 if (vport->gidft_inp == 0)
4023 return vport->gidft_inp;
4027 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4028 * @vport: The virtual port for which this call is being executed.
4030 * This routine will issue a GID_PT to get a list of all N_Ports
4033 * 0 - Failure to issue a GID_PT
4037 lpfc_issue_gidpt(struct lpfc_vport *vport)
4039 /* Good status, issue CT Request to NameServer */
4040 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4041 /* Cannot issue NameServer FCP Query, so finish up
4044 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4045 "0606 %s Port TYPE %x %s\n",
4046 "Failed to issue GID_PT to ",
4048 "Finishing discovery.");
4056 * This routine handles processing a NameServer REG_LOGIN mailbox
4057 * command upon completion. It is setup in the LPFC_MBOXQ
4058 * as the completion routine when the command is
4059 * handed off to the SLI layer.
4062 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4064 MAILBOX_t *mb = &pmb->u.mb;
4065 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4066 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4067 struct lpfc_vport *vport = pmb->vport;
4069 pmb->ctx_buf = NULL;
4070 pmb->ctx_ndlp = NULL;
4071 vport->gidft_inp = 0;
4073 if (mb->mbxStatus) {
4074 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4075 "0260 Register NameServer error: 0x%x\n",
4079 /* decrement the node reference count held for this
4080 * callback function.
4083 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4085 mempool_free(pmb, phba->mbox_mem_pool);
4087 /* If the node is not registered with the scsi or nvme
4088 * transport, remove the fabric node. The failed reg_login
4091 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4092 spin_lock_irq(&ndlp->lock);
4093 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4094 spin_unlock_irq(&ndlp->lock);
4095 lpfc_nlp_not_used(ndlp);
4098 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4100 * RegLogin failed, use loop map to make discovery
4103 lpfc_disc_list_loopmap(vport);
4105 /* Start discovery */
4106 lpfc_disc_start(vport);
4109 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4113 if (phba->sli_rev < LPFC_SLI_REV4)
4114 ndlp->nlp_rpi = mb->un.varWords[0];
4115 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4116 ndlp->nlp_type |= NLP_FABRIC;
4117 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4118 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4119 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4120 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4121 kref_read(&ndlp->kref),
4124 if (vport->port_state < LPFC_VPORT_READY) {
4125 /* Link up discovery requires Fabric registration. */
4126 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4127 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4128 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4129 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4131 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4132 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4133 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4135 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4136 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4137 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4140 /* Issue SCR just before NameServer GID_FT Query */
4141 lpfc_issue_els_scr(vport, 0);
4143 if (!phba->cfg_enable_mi ||
4144 phba->sli4_hba.pc_sli4_params.mi_ver < LPFC_MIB3_SUPPORT)
4145 lpfc_issue_els_rdf(vport, 0);
4148 vport->fc_ns_retry = 0;
4149 if (lpfc_issue_gidft(vport) == 0)
4153 * At this point in time we may need to wait for multiple
4154 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4156 * decrement the node reference count held for this
4157 * callback function.
4160 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4162 mempool_free(pmb, phba->mbox_mem_pool);
4168 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4170 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4171 struct fc_rport *rport;
4172 struct lpfc_rport_data *rdata;
4173 struct fc_rport_identifiers rport_ids;
4174 struct lpfc_hba *phba = vport->phba;
4175 unsigned long flags;
4177 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4180 /* Remote port has reappeared. Re-register w/ FC transport */
4181 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4182 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4183 rport_ids.port_id = ndlp->nlp_DID;
4184 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4188 "rport add: did:x%x flg:x%x type x%x",
4189 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4191 /* Don't add the remote port if unloading. */
4192 if (vport->load_flag & FC_UNLOADING)
4196 * Disassociate any older association between this ndlp and rport
4199 rdata = ndlp->rport->dd_data;
4200 rdata->pnode = NULL;
4203 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4205 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4206 "Warning: fc_remote_port_add failed\n");
4210 /* Successful port add. Complete initializing node data */
4211 rport->maxframe_size = ndlp->nlp_maxframe;
4212 rport->supported_classes = ndlp->nlp_class_sup;
4213 rdata = rport->dd_data;
4214 rdata->pnode = lpfc_nlp_get(ndlp);
4215 if (!rdata->pnode) {
4216 dev_warn(&phba->pcidev->dev,
4217 "Warning - node ref failed. Unreg rport\n");
4218 fc_remote_port_delete(rport);
4223 spin_lock_irqsave(&ndlp->lock, flags);
4224 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4225 spin_unlock_irqrestore(&ndlp->lock, flags);
4227 if (ndlp->nlp_type & NLP_FCP_TARGET)
4228 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4229 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4230 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4231 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4232 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4233 if (ndlp->nlp_type & NLP_NVME_TARGET)
4234 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4235 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4236 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4238 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4239 fc_remote_port_rolechg(rport, rport_ids.roles);
4241 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4242 "3183 %s rport x%px DID x%x, role x%x\n",
4243 __func__, rport, rport->port_id, rport->roles);
4245 if ((rport->scsi_target_id != -1) &&
4246 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4247 ndlp->nlp_sid = rport->scsi_target_id;
4254 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4256 struct fc_rport *rport = ndlp->rport;
4257 struct lpfc_vport *vport = ndlp->vport;
4259 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4262 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4263 "rport delete: did:x%x flg:x%x type x%x",
4264 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4266 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4267 "3184 rport unregister x%06x, rport x%px "
4269 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags);
4271 fc_remote_port_delete(rport);
4276 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4278 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4279 unsigned long iflags;
4281 spin_lock_irqsave(shost->host_lock, iflags);
4283 case NLP_STE_UNUSED_NODE:
4284 vport->fc_unused_cnt += count;
4286 case NLP_STE_PLOGI_ISSUE:
4287 vport->fc_plogi_cnt += count;
4289 case NLP_STE_ADISC_ISSUE:
4290 vport->fc_adisc_cnt += count;
4292 case NLP_STE_REG_LOGIN_ISSUE:
4293 vport->fc_reglogin_cnt += count;
4295 case NLP_STE_PRLI_ISSUE:
4296 vport->fc_prli_cnt += count;
4298 case NLP_STE_UNMAPPED_NODE:
4299 vport->fc_unmap_cnt += count;
4301 case NLP_STE_MAPPED_NODE:
4302 vport->fc_map_cnt += count;
4304 case NLP_STE_NPR_NODE:
4305 if (vport->fc_npr_cnt == 0 && count == -1)
4306 vport->fc_npr_cnt = 0;
4308 vport->fc_npr_cnt += count;
4311 spin_unlock_irqrestore(shost->host_lock, iflags);
4315 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4316 int old_state, int new_state)
4318 if (new_state == NLP_STE_UNMAPPED_NODE) {
4319 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4320 ndlp->nlp_type |= NLP_FC_NODE;
4322 if (new_state == NLP_STE_MAPPED_NODE)
4323 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4324 if (new_state == NLP_STE_NPR_NODE)
4325 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4327 /* FCP and NVME Transport interface */
4328 if ((old_state == NLP_STE_MAPPED_NODE ||
4329 old_state == NLP_STE_UNMAPPED_NODE)) {
4331 lpfc_valid_xpt_node(ndlp)) {
4332 vport->phba->nport_event_cnt++;
4333 lpfc_unregister_remote_port(ndlp);
4336 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4337 vport->phba->nport_event_cnt++;
4338 if (vport->phba->nvmet_support == 0) {
4339 /* Start devloss if target. */
4340 if (ndlp->nlp_type & NLP_NVME_TARGET)
4341 lpfc_nvme_unregister_port(vport, ndlp);
4343 /* NVMET has no upcall. */
4349 /* FCP and NVME Transport interfaces */
4351 if (new_state == NLP_STE_MAPPED_NODE ||
4352 new_state == NLP_STE_UNMAPPED_NODE) {
4353 if (lpfc_valid_xpt_node(ndlp)) {
4354 vport->phba->nport_event_cnt++;
4356 * Tell the fc transport about the port, if we haven't
4357 * already. If we have, and it's a scsi entity, be
4359 lpfc_register_remote_port(vport, ndlp);
4361 /* Notify the NVME transport of this new rport. */
4362 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4363 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4364 if (vport->phba->nvmet_support == 0) {
4365 /* Register this rport with the transport.
4366 * Only NVME Target Rports are registered with
4369 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4370 vport->phba->nport_event_cnt++;
4371 lpfc_nvme_register_port(vport, ndlp);
4374 /* Just take an NDLP ref count since the
4375 * target does not register rports.
4382 if ((new_state == NLP_STE_MAPPED_NODE) &&
4383 (vport->stat_data_enabled)) {
4385 * A new target is discovered, if there is no buffer for
4386 * statistical data collection allocate buffer.
4388 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4389 sizeof(struct lpfc_scsicmd_bkt),
4392 if (!ndlp->lat_data)
4393 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4394 "0286 lpfc_nlp_state_cleanup failed to "
4395 "allocate statistical data buffer DID "
4396 "0x%x\n", ndlp->nlp_DID);
4399 * If the node just added to Mapped list was an FCP target,
4400 * but the remote port registration failed or assigned a target
4401 * id outside the presentable range - move the node to the
4404 if ((new_state == NLP_STE_MAPPED_NODE) &&
4405 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4407 ndlp->rport->scsi_target_id == -1 ||
4408 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4409 spin_lock_irq(&ndlp->lock);
4410 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4411 spin_unlock_irq(&ndlp->lock);
4412 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4417 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4419 static char *states[] = {
4420 [NLP_STE_UNUSED_NODE] = "UNUSED",
4421 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4422 [NLP_STE_ADISC_ISSUE] = "ADISC",
4423 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4424 [NLP_STE_PRLI_ISSUE] = "PRLI",
4425 [NLP_STE_LOGO_ISSUE] = "LOGO",
4426 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4427 [NLP_STE_MAPPED_NODE] = "MAPPED",
4428 [NLP_STE_NPR_NODE] = "NPR",
4431 if (state < NLP_STE_MAX_STATE && states[state])
4432 strlcpy(buffer, states[state], size);
4434 snprintf(buffer, size, "unknown (%d)", state);
4439 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4442 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4443 int old_state = ndlp->nlp_state;
4444 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4445 char name1[16], name2[16];
4447 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4448 "0904 NPort state transition x%06x, %s -> %s\n",
4450 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4451 lpfc_nlp_state_name(name2, sizeof(name2), state));
4453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4454 "node statechg did:x%x old:%d ste:%d",
4455 ndlp->nlp_DID, old_state, state);
4457 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4458 state != NLP_STE_UNUSED_NODE) {
4459 ndlp->nlp_flag &= ~NLP_DROPPED;
4463 if (old_state == NLP_STE_NPR_NODE &&
4464 state != NLP_STE_NPR_NODE)
4465 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4466 if (old_state == NLP_STE_UNMAPPED_NODE) {
4467 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4468 ndlp->nlp_type &= ~NLP_FC_NODE;
4471 if (list_empty(&ndlp->nlp_listp)) {
4472 spin_lock_irq(shost->host_lock);
4473 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4474 spin_unlock_irq(shost->host_lock);
4475 } else if (old_state)
4476 lpfc_nlp_counters(vport, old_state, -1);
4478 ndlp->nlp_state = state;
4479 lpfc_nlp_counters(vport, state, 1);
4480 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4484 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4486 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4488 if (list_empty(&ndlp->nlp_listp)) {
4489 spin_lock_irq(shost->host_lock);
4490 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4491 spin_unlock_irq(shost->host_lock);
4496 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4500 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4501 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4502 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4503 spin_lock_irq(shost->host_lock);
4504 list_del_init(&ndlp->nlp_listp);
4505 spin_unlock_irq(shost->host_lock);
4506 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4507 NLP_STE_UNUSED_NODE);
4511 * lpfc_initialize_node - Initialize all fields of node object
4512 * @vport: Pointer to Virtual Port object.
4513 * @ndlp: Pointer to FC node object.
4514 * @did: FC_ID of the node.
4516 * This function is always called when node object need to be initialized.
4517 * It initializes all the fields of the node object. Although the reference
4518 * to phba from @ndlp can be obtained indirectly through it's reference to
4519 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4520 * to the life-span of the @ndlp might go beyond the existence of @vport as
4521 * the final release of ndlp is determined by its reference count. And, the
4522 * operation on @ndlp needs the reference to phba.
4525 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4528 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4529 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4530 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4531 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4533 ndlp->nlp_DID = did;
4534 ndlp->vport = vport;
4535 ndlp->phba = vport->phba;
4536 ndlp->nlp_sid = NLP_NO_SID;
4537 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4538 kref_init(&ndlp->kref);
4539 atomic_set(&ndlp->cmd_pending, 0);
4540 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4541 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4545 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4548 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4549 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4550 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4551 * until ALL other outstanding threads have completed. We check
4552 * that the ndlp not already in the UNUSED state before we proceed.
4554 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4556 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4557 ndlp->nlp_flag |= NLP_DROPPED;
4558 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4559 lpfc_cleanup_vports_rrqs(vport, ndlp);
4560 lpfc_unreg_rpi(vport, ndlp);
4568 * Start / ReStart rescue timer for Discovery / RSCN handling
4571 lpfc_set_disctmo(struct lpfc_vport *vport)
4573 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4574 struct lpfc_hba *phba = vport->phba;
4577 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4578 /* For FAN, timeout should be greater than edtov */
4579 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4581 /* Normal discovery timeout should be > than ELS/CT timeout
4582 * FC spec states we need 3 * ratov for CT requests
4584 tmo = ((phba->fc_ratov * 3) + 3);
4588 if (!timer_pending(&vport->fc_disctmo)) {
4589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4590 "set disc timer: tmo:x%x state:x%x flg:x%x",
4591 tmo, vport->port_state, vport->fc_flag);
4594 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4595 spin_lock_irq(shost->host_lock);
4596 vport->fc_flag |= FC_DISC_TMO;
4597 spin_unlock_irq(shost->host_lock);
4599 /* Start Discovery Timer state <hba_state> */
4600 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4601 "0247 Start Discovery Timer state x%x "
4602 "Data: x%x x%lx x%x x%x\n",
4603 vport->port_state, tmo,
4604 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4605 vport->fc_adisc_cnt);
4611 * Cancel rescue timer for Discovery / RSCN handling
4614 lpfc_can_disctmo(struct lpfc_vport *vport)
4616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4617 unsigned long iflags;
4619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4620 "can disc timer: state:x%x rtry:x%x flg:x%x",
4621 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4623 /* Turn off discovery timer if its running */
4624 if (vport->fc_flag & FC_DISC_TMO) {
4625 spin_lock_irqsave(shost->host_lock, iflags);
4626 vport->fc_flag &= ~FC_DISC_TMO;
4627 spin_unlock_irqrestore(shost->host_lock, iflags);
4628 del_timer_sync(&vport->fc_disctmo);
4629 spin_lock_irqsave(&vport->work_port_lock, iflags);
4630 vport->work_port_events &= ~WORKER_DISC_TMO;
4631 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4634 /* Cancel Discovery Timer state <hba_state> */
4635 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4636 "0248 Cancel Discovery Timer state x%x "
4637 "Data: x%x x%x x%x\n",
4638 vport->port_state, vport->fc_flag,
4639 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4644 * Check specified ring for outstanding IOCB on the SLI queue
4645 * Return true if iocb matches the specified nport
4648 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4649 struct lpfc_sli_ring *pring,
4650 struct lpfc_iocbq *iocb,
4651 struct lpfc_nodelist *ndlp)
4653 IOCB_t *icmd = &iocb->iocb;
4654 struct lpfc_vport *vport = ndlp->vport;
4656 if (iocb->vport != vport)
4659 if (pring->ringno == LPFC_ELS_RING) {
4660 switch (icmd->ulpCommand) {
4661 case CMD_GEN_REQUEST64_CR:
4662 if (iocb->context_un.ndlp == ndlp)
4665 case CMD_ELS_REQUEST64_CR:
4666 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4669 case CMD_XMIT_ELS_RSP64_CX:
4670 if (iocb->context1 == (uint8_t *) ndlp)
4673 } else if (pring->ringno == LPFC_FCP_RING) {
4674 /* Skip match check if waiting to relogin to FCP target */
4675 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4676 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4679 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4687 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4688 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4689 struct list_head *dequeue_list)
4691 struct lpfc_iocbq *iocb, *next_iocb;
4693 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4694 /* Check to see if iocb matches the nport */
4695 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4696 /* match, dequeue */
4697 list_move_tail(&iocb->list, dequeue_list);
4702 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4703 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4705 struct lpfc_sli *psli = &phba->sli;
4708 spin_lock_irq(&phba->hbalock);
4709 for (i = 0; i < psli->num_rings; i++)
4710 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4712 spin_unlock_irq(&phba->hbalock);
4716 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4717 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4719 struct lpfc_sli_ring *pring;
4720 struct lpfc_queue *qp = NULL;
4722 spin_lock_irq(&phba->hbalock);
4723 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4727 spin_lock(&pring->ring_lock);
4728 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
4729 spin_unlock(&pring->ring_lock);
4731 spin_unlock_irq(&phba->hbalock);
4735 * Free resources / clean up outstanding I/Os
4736 * associated with nlp_rpi in the LPFC_NODELIST entry.
4739 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4741 LIST_HEAD(completions);
4743 lpfc_fabric_abort_nport(ndlp);
4746 * Everything that matches on txcmplq will be returned
4747 * by firmware with a no rpi error.
4749 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4750 if (phba->sli_rev != LPFC_SLI_REV4)
4751 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4753 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
4756 /* Cancel all the IOCBs from the completions list */
4757 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4764 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4765 * @phba: Pointer to HBA context object.
4766 * @pmb: Pointer to mailbox object.
4768 * This function will issue an ELS LOGO command after completing
4772 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4774 struct lpfc_vport *vport = pmb->vport;
4775 struct lpfc_nodelist *ndlp;
4777 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
4780 lpfc_issue_els_logo(vport, ndlp, 0);
4781 mempool_free(pmb, phba->mbox_mem_pool);
4783 /* Check to see if there are any deferred events to process */
4784 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4785 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4786 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4787 "1434 UNREG cmpl deferred logo x%x "
4788 "on NPort x%x Data: x%x x%px\n",
4789 ndlp->nlp_rpi, ndlp->nlp_DID,
4790 ndlp->nlp_defer_did, ndlp);
4792 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4793 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4794 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4796 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4797 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
4798 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
4799 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4801 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4806 * Sets the mailbox completion handler to be used for the
4807 * unreg_rpi command. The handler varies based on the state of
4808 * the port and what will be happening to the rpi next.
4811 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
4812 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
4814 unsigned long iflags;
4816 /* Driver always gets a reference on the mailbox job
4817 * in support of async jobs.
4819 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4820 if (!mbox->ctx_ndlp)
4823 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4824 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4826 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
4827 (!(vport->load_flag & FC_UNLOADING)) &&
4828 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
4829 LPFC_SLI_INTF_IF_TYPE_2) &&
4830 (kref_read(&ndlp->kref) > 0)) {
4831 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
4833 if (vport->load_flag & FC_UNLOADING) {
4834 if (phba->sli_rev == LPFC_SLI_REV4) {
4835 spin_lock_irqsave(&ndlp->lock, iflags);
4836 ndlp->nlp_flag |= NLP_RELEASE_RPI;
4837 spin_unlock_irqrestore(&ndlp->lock, iflags);
4840 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4845 * Free rpi associated with LPFC_NODELIST entry.
4846 * This routine is called from lpfc_freenode(), when we are removing
4847 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4848 * LOGO that completes successfully, and we are waiting to PLOGI back
4849 * to the remote NPort. In addition, it is called after we receive
4850 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4851 * we are waiting to PLOGI back to the remote NPort.
4854 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4856 struct lpfc_hba *phba = vport->phba;
4858 int rc, acc_plogi = 1;
4861 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4862 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4863 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4864 lpfc_printf_vlog(vport, KERN_INFO,
4865 LOG_NODE | LOG_DISCOVERY,
4866 "3366 RPI x%x needs to be "
4867 "unregistered nlp_flag x%x "
4869 ndlp->nlp_rpi, ndlp->nlp_flag,
4872 /* If there is already an UNREG in progress for this ndlp,
4873 * no need to queue up another one.
4875 if (ndlp->nlp_flag & NLP_UNREG_INP) {
4876 lpfc_printf_vlog(vport, KERN_INFO,
4877 LOG_NODE | LOG_DISCOVERY,
4878 "1436 unreg_rpi SKIP UNREG x%x on "
4879 "NPort x%x deferred x%x flg x%x "
4881 ndlp->nlp_rpi, ndlp->nlp_DID,
4882 ndlp->nlp_defer_did,
4883 ndlp->nlp_flag, ndlp);
4887 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4889 /* SLI4 ports require the physical rpi value. */
4890 rpi = ndlp->nlp_rpi;
4891 if (phba->sli_rev == LPFC_SLI_REV4)
4892 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4894 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4895 mbox->vport = vport;
4896 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
4897 if (!mbox->ctx_ndlp) {
4898 mempool_free(mbox, phba->mbox_mem_pool);
4902 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
4904 * accept PLOGIs after unreg_rpi_cmpl
4907 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4909 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4910 ndlp->nlp_flag |= NLP_UNREG_INP;
4912 lpfc_printf_vlog(vport, KERN_INFO,
4913 LOG_NODE | LOG_DISCOVERY,
4914 "1433 unreg_rpi UNREG x%x on "
4915 "NPort x%x deferred flg x%x "
4917 ndlp->nlp_rpi, ndlp->nlp_DID,
4918 ndlp->nlp_flag, ndlp);
4920 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4921 if (rc == MBX_NOT_FINISHED) {
4922 mempool_free(mbox, phba->mbox_mem_pool);
4926 lpfc_printf_vlog(vport, KERN_INFO,
4927 LOG_NODE | LOG_DISCOVERY,
4928 "1444 Failed to allocate mempool "
4929 "unreg_rpi UNREG x%x, "
4930 "DID x%x, flag x%x, "
4932 ndlp->nlp_rpi, ndlp->nlp_DID,
4933 ndlp->nlp_flag, ndlp);
4935 /* Because mempool_alloc failed, we
4936 * will issue a LOGO here and keep the rpi alive if
4939 if (!(vport->load_flag & FC_UNLOADING)) {
4940 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4941 lpfc_issue_els_logo(vport, ndlp, 0);
4942 ndlp->nlp_prev_state = ndlp->nlp_state;
4943 lpfc_nlp_set_state(vport, ndlp,
4949 lpfc_no_rpi(phba, ndlp);
4951 if (phba->sli_rev != LPFC_SLI_REV4)
4953 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4954 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4956 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4959 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4964 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4965 * @phba: pointer to lpfc hba data structure.
4967 * This routine is invoked to unregister all the currently registered RPIs
4971 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4973 struct lpfc_vport **vports;
4974 struct lpfc_nodelist *ndlp;
4975 struct Scsi_Host *shost;
4978 vports = lpfc_create_vport_work_array(phba);
4980 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4981 "2884 Vport array allocation failed \n");
4984 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4985 shost = lpfc_shost_from_vport(vports[i]);
4986 spin_lock_irq(shost->host_lock);
4987 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4988 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4989 /* The mempool_alloc might sleep */
4990 spin_unlock_irq(shost->host_lock);
4991 lpfc_unreg_rpi(vports[i], ndlp);
4992 spin_lock_irq(shost->host_lock);
4995 spin_unlock_irq(shost->host_lock);
4997 lpfc_destroy_vport_work_array(phba, vports);
5001 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5003 struct lpfc_hba *phba = vport->phba;
5007 if (phba->sli_rev == LPFC_SLI_REV4) {
5008 lpfc_sli4_unreg_all_rpis(vport);
5012 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5014 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5016 mbox->vport = vport;
5017 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5018 mbox->ctx_ndlp = NULL;
5019 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5020 if (rc != MBX_TIMEOUT)
5021 mempool_free(mbox, phba->mbox_mem_pool);
5023 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5024 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5025 "1836 Could not issue "
5026 "unreg_login(all_rpis) status %d\n",
5032 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5034 struct lpfc_hba *phba = vport->phba;
5038 /* Unreg DID is an SLI3 operation. */
5039 if (phba->sli_rev > LPFC_SLI_REV3)
5042 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5044 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5046 mbox->vport = vport;
5047 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5048 mbox->ctx_ndlp = NULL;
5049 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5050 if (rc != MBX_TIMEOUT)
5051 mempool_free(mbox, phba->mbox_mem_pool);
5053 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5054 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5055 "1815 Could not issue "
5056 "unreg_did (default rpis) status %d\n",
5062 * Free resources associated with LPFC_NODELIST entry
5063 * so it can be freed.
5066 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5068 struct lpfc_hba *phba = vport->phba;
5069 LPFC_MBOXQ_t *mb, *nextmb;
5070 struct lpfc_dmabuf *mp;
5072 /* Cleanup node for NPort <nlp_DID> */
5073 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5074 "0900 Cleanup node for NPort x%x "
5075 "Data: x%x x%x x%x\n",
5076 ndlp->nlp_DID, ndlp->nlp_flag,
5077 ndlp->nlp_state, ndlp->nlp_rpi);
5078 lpfc_dequeue_node(vport, ndlp);
5080 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5082 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5083 if ((mb = phba->sli.mbox_active)) {
5084 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5085 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5086 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5087 mb->ctx_ndlp = NULL;
5088 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5092 spin_lock_irq(&phba->hbalock);
5093 /* Cleanup REG_LOGIN completions which are not yet processed */
5094 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5095 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5096 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5097 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5100 mb->ctx_ndlp = NULL;
5101 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5104 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5105 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5106 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5107 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5108 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5110 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5113 list_del(&mb->list);
5114 mempool_free(mb, phba->mbox_mem_pool);
5115 /* We shall not invoke the lpfc_nlp_put to decrement
5116 * the ndlp reference count as we are in the process
5117 * of lpfc_nlp_release.
5121 spin_unlock_irq(&phba->hbalock);
5123 lpfc_els_abort(phba, ndlp);
5125 spin_lock_irq(&ndlp->lock);
5126 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5127 spin_unlock_irq(&ndlp->lock);
5129 ndlp->nlp_last_elscmd = 0;
5130 del_timer_sync(&ndlp->nlp_delayfunc);
5132 list_del_init(&ndlp->els_retry_evt.evt_listp);
5133 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5134 list_del_init(&ndlp->recovery_evt.evt_listp);
5135 lpfc_cleanup_vports_rrqs(vport, ndlp);
5136 if (phba->sli_rev == LPFC_SLI_REV4)
5137 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5142 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5145 D_ID mydid, ndlpdid, matchdid;
5147 if (did == Bcast_DID)
5150 /* First check for Direct match */
5151 if (ndlp->nlp_DID == did)
5154 /* Next check for area/domain identically equals 0 match */
5155 mydid.un.word = vport->fc_myDID;
5156 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5160 matchdid.un.word = did;
5161 ndlpdid.un.word = ndlp->nlp_DID;
5162 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5163 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5164 (mydid.un.b.area == matchdid.un.b.area)) {
5165 /* This code is supposed to match the ID
5166 * for a private loop device that is
5167 * connect to fl_port. But we need to
5168 * check that the port did not just go
5169 * from pt2pt to fabric or we could end
5170 * up matching ndlp->nlp_DID 000001 to
5171 * fabric DID 0x20101
5173 if ((ndlpdid.un.b.domain == 0) &&
5174 (ndlpdid.un.b.area == 0)) {
5175 if (ndlpdid.un.b.id &&
5176 vport->phba->fc_topology ==
5183 matchdid.un.word = ndlp->nlp_DID;
5184 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5185 (mydid.un.b.area == ndlpdid.un.b.area)) {
5186 if ((matchdid.un.b.domain == 0) &&
5187 (matchdid.un.b.area == 0)) {
5188 if (matchdid.un.b.id)
5196 /* Search for a nodelist entry */
5197 static struct lpfc_nodelist *
5198 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5200 struct lpfc_nodelist *ndlp;
5203 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5204 if (lpfc_matchdid(vport, ndlp, did)) {
5205 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5206 ((uint32_t)ndlp->nlp_xri << 16) |
5207 ((uint32_t)ndlp->nlp_type << 8)
5209 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5210 "0929 FIND node DID "
5211 "Data: x%px x%x x%x x%x x%x x%px\n",
5212 ndlp, ndlp->nlp_DID,
5213 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5214 ndlp->active_rrqs_xri_bitmap);
5219 /* FIND node did <did> NOT FOUND */
5220 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5221 "0932 FIND node did x%x NOT FOUND.\n", did);
5225 struct lpfc_nodelist *
5226 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5228 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5229 struct lpfc_nodelist *ndlp;
5230 unsigned long iflags;
5232 spin_lock_irqsave(shost->host_lock, iflags);
5233 ndlp = __lpfc_findnode_did(vport, did);
5234 spin_unlock_irqrestore(shost->host_lock, iflags);
5238 struct lpfc_nodelist *
5239 lpfc_findnode_mapped(struct lpfc_vport *vport)
5241 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5242 struct lpfc_nodelist *ndlp;
5244 unsigned long iflags;
5246 spin_lock_irqsave(shost->host_lock, iflags);
5248 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5249 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5250 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5251 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5252 ((uint32_t)ndlp->nlp_xri << 16) |
5253 ((uint32_t)ndlp->nlp_type << 8) |
5254 ((uint32_t)ndlp->nlp_rpi & 0xff));
5255 spin_unlock_irqrestore(shost->host_lock, iflags);
5256 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5257 "2025 FIND node DID "
5258 "Data: x%px x%x x%x x%x x%px\n",
5259 ndlp, ndlp->nlp_DID,
5260 ndlp->nlp_flag, data1,
5261 ndlp->active_rrqs_xri_bitmap);
5265 spin_unlock_irqrestore(shost->host_lock, iflags);
5267 /* FIND node did <did> NOT FOUND */
5268 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5269 "2026 FIND mapped did NOT FOUND.\n");
5273 struct lpfc_nodelist *
5274 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5276 struct lpfc_nodelist *ndlp;
5278 ndlp = lpfc_findnode_did(vport, did);
5280 if (vport->phba->nvmet_support)
5282 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5283 lpfc_rscn_payload_check(vport, did) == 0)
5285 ndlp = lpfc_nlp_init(vport, did);
5288 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5290 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5291 "6453 Setup New Node 2B_DISC x%x "
5292 "Data:x%x x%x x%x\n",
5293 ndlp->nlp_DID, ndlp->nlp_flag,
5294 ndlp->nlp_state, vport->fc_flag);
5296 spin_lock_irq(&ndlp->lock);
5297 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5298 spin_unlock_irq(&ndlp->lock);
5302 /* The NVME Target does not want to actively manage an rport.
5303 * The goal is to allow the target to reset its state and clear
5304 * pending IO in preparation for the initiator to recover.
5306 if ((vport->fc_flag & FC_RSCN_MODE) &&
5307 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5308 if (lpfc_rscn_payload_check(vport, did)) {
5310 /* Since this node is marked for discovery,
5311 * delay timeout is not needed.
5313 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5315 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5316 "6455 Setup RSCN Node 2B_DISC x%x "
5317 "Data:x%x x%x x%x\n",
5318 ndlp->nlp_DID, ndlp->nlp_flag,
5319 ndlp->nlp_state, vport->fc_flag);
5321 /* NVME Target mode waits until rport is known to be
5322 * impacted by the RSCN before it transitions. No
5323 * active management - just go to NPR provided the
5324 * node had a valid login.
5326 if (vport->phba->nvmet_support)
5329 /* If we've already received a PLOGI from this NPort
5330 * we don't need to try to discover it again.
5332 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5334 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5337 ndlp->nlp_prev_state = ndlp->nlp_state;
5338 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5340 spin_lock_irq(&ndlp->lock);
5341 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5342 spin_unlock_irq(&ndlp->lock);
5344 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5345 "6456 Skip Setup RSCN Node x%x "
5346 "Data:x%x x%x x%x\n",
5347 ndlp->nlp_DID, ndlp->nlp_flag,
5348 ndlp->nlp_state, vport->fc_flag);
5352 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5353 "6457 Setup Active Node 2B_DISC x%x "
5354 "Data:x%x x%x x%x\n",
5355 ndlp->nlp_DID, ndlp->nlp_flag,
5356 ndlp->nlp_state, vport->fc_flag);
5358 /* If the initiator received a PLOGI from this NPort or if the
5359 * initiator is already in the process of discovery on it,
5360 * there's no need to try to discover it again.
5362 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5363 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5364 (!vport->phba->nvmet_support &&
5365 ndlp->nlp_flag & NLP_RCV_PLOGI))
5368 if (vport->phba->nvmet_support)
5371 /* Moving to NPR state clears unsolicited flags and
5372 * allows for rediscovery
5374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5376 spin_lock_irq(&ndlp->lock);
5377 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5378 spin_unlock_irq(&ndlp->lock);
5383 /* Build a list of nodes to discover based on the loopmap */
5385 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5387 struct lpfc_hba *phba = vport->phba;
5389 uint32_t alpa, index;
5391 if (!lpfc_is_link_up(phba))
5394 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5397 /* Check for loop map present or not */
5398 if (phba->alpa_map[0]) {
5399 for (j = 1; j <= phba->alpa_map[0]; j++) {
5400 alpa = phba->alpa_map[j];
5401 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5403 lpfc_setup_disc_node(vport, alpa);
5406 /* No alpamap, so try all alpa's */
5407 for (j = 0; j < FC_MAXLOOP; j++) {
5408 /* If cfg_scan_down is set, start from highest
5409 * ALPA (0xef) to lowest (0x1).
5411 if (vport->cfg_scan_down)
5414 index = FC_MAXLOOP - j - 1;
5415 alpa = lpfcAlpaArray[index];
5416 if ((vport->fc_myDID & 0xff) == alpa)
5418 lpfc_setup_disc_node(vport, alpa);
5426 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5429 struct lpfc_sli *psli = &phba->sli;
5430 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5431 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5435 * if it's not a physical port or if we already send
5436 * clear_la then don't send it.
5438 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5439 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5440 (phba->sli_rev == LPFC_SLI_REV4))
5443 /* Link up discovery */
5444 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5445 phba->link_state = LPFC_CLEAR_LA;
5446 lpfc_clear_la(phba, mbox);
5447 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5448 mbox->vport = vport;
5449 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5450 if (rc == MBX_NOT_FINISHED) {
5451 mempool_free(mbox, phba->mbox_mem_pool);
5452 lpfc_disc_flush_list(vport);
5453 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5454 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5455 phba->link_state = LPFC_HBA_ERROR;
5460 /* Reg_vpi to tell firmware to resume normal operations */
5462 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5464 LPFC_MBOXQ_t *regvpimbox;
5466 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5468 lpfc_reg_vpi(vport, regvpimbox);
5469 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5470 regvpimbox->vport = vport;
5471 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5472 == MBX_NOT_FINISHED) {
5473 mempool_free(regvpimbox, phba->mbox_mem_pool);
5478 /* Start Link up / RSCN discovery on NPR nodes */
5480 lpfc_disc_start(struct lpfc_vport *vport)
5482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5483 struct lpfc_hba *phba = vport->phba;
5485 uint32_t clear_la_pending;
5487 if (!lpfc_is_link_up(phba)) {
5488 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5489 "3315 Link is not up %x\n",
5494 if (phba->link_state == LPFC_CLEAR_LA)
5495 clear_la_pending = 1;
5497 clear_la_pending = 0;
5499 if (vport->port_state < LPFC_VPORT_READY)
5500 vport->port_state = LPFC_DISC_AUTH;
5502 lpfc_set_disctmo(vport);
5504 vport->fc_prevDID = vport->fc_myDID;
5505 vport->num_disc_nodes = 0;
5507 /* Start Discovery state <hba_state> */
5508 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5509 "0202 Start Discovery port state x%x "
5510 "flg x%x Data: x%x x%x x%x\n",
5511 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5512 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5514 /* First do ADISCs - if any */
5515 num_sent = lpfc_els_disc_adisc(vport);
5520 /* Register the VPI for SLI3, NPIV only. */
5521 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5522 !(vport->fc_flag & FC_PT2PT) &&
5523 !(vport->fc_flag & FC_RSCN_MODE) &&
5524 (phba->sli_rev < LPFC_SLI_REV4)) {
5525 lpfc_issue_clear_la(phba, vport);
5526 lpfc_issue_reg_vpi(phba, vport);
5531 * For SLI2, we need to set port_state to READY and continue
5534 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5535 /* If we get here, there is nothing to ADISC */
5536 lpfc_issue_clear_la(phba, vport);
5538 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5539 vport->num_disc_nodes = 0;
5540 /* go thru NPR nodes and issue ELS PLOGIs */
5541 if (vport->fc_npr_cnt)
5542 lpfc_els_disc_plogi(vport);
5544 if (!vport->num_disc_nodes) {
5545 spin_lock_irq(shost->host_lock);
5546 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5547 spin_unlock_irq(shost->host_lock);
5548 lpfc_can_disctmo(vport);
5551 vport->port_state = LPFC_VPORT_READY;
5553 /* Next do PLOGIs - if any */
5554 num_sent = lpfc_els_disc_plogi(vport);
5559 if (vport->fc_flag & FC_RSCN_MODE) {
5560 /* Check to see if more RSCNs came in while we
5561 * were processing this one.
5563 if ((vport->fc_rscn_id_cnt == 0) &&
5564 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5565 spin_lock_irq(shost->host_lock);
5566 vport->fc_flag &= ~FC_RSCN_MODE;
5567 spin_unlock_irq(shost->host_lock);
5568 lpfc_can_disctmo(vport);
5570 lpfc_els_handle_rscn(vport);
5577 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5578 * ring the match the sppecified nodelist.
5581 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5583 LIST_HEAD(completions);
5585 struct lpfc_iocbq *iocb, *next_iocb;
5586 struct lpfc_sli_ring *pring;
5588 pring = lpfc_phba_elsring(phba);
5589 if (unlikely(!pring))
5592 /* Error matching iocb on txq or txcmplq
5593 * First check the txq.
5595 spin_lock_irq(&phba->hbalock);
5596 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5597 if (iocb->context1 != ndlp) {
5601 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5602 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5604 list_move_tail(&iocb->list, &completions);
5608 /* Next check the txcmplq */
5609 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5610 if (iocb->context1 != ndlp) {
5614 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5615 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5616 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
5619 spin_unlock_irq(&phba->hbalock);
5621 /* Make sure HBA is alive */
5622 lpfc_issue_hb_tmo(phba);
5624 /* Cancel all the IOCBs from the completions list */
5625 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5630 lpfc_disc_flush_list(struct lpfc_vport *vport)
5632 struct lpfc_nodelist *ndlp, *next_ndlp;
5633 struct lpfc_hba *phba = vport->phba;
5635 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5636 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5638 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5639 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5640 lpfc_free_tx(phba, ndlp);
5647 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5649 lpfc_els_flush_rscn(vport);
5650 lpfc_els_flush_cmd(vport);
5651 lpfc_disc_flush_list(vport);
5654 /*****************************************************************************/
5656 * NAME: lpfc_disc_timeout
5658 * FUNCTION: Fibre Channel driver discovery timeout routine.
5660 * EXECUTION ENVIRONMENT: interrupt only
5668 /*****************************************************************************/
5670 lpfc_disc_timeout(struct timer_list *t)
5672 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
5673 struct lpfc_hba *phba = vport->phba;
5674 uint32_t tmo_posted;
5675 unsigned long flags = 0;
5677 if (unlikely(!phba))
5680 spin_lock_irqsave(&vport->work_port_lock, flags);
5681 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5683 vport->work_port_events |= WORKER_DISC_TMO;
5684 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5687 lpfc_worker_wake_up(phba);
5692 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5695 struct lpfc_hba *phba = vport->phba;
5696 struct lpfc_sli *psli = &phba->sli;
5697 struct lpfc_nodelist *ndlp, *next_ndlp;
5698 LPFC_MBOXQ_t *initlinkmbox;
5699 int rc, clrlaerr = 0;
5701 if (!(vport->fc_flag & FC_DISC_TMO))
5704 spin_lock_irq(shost->host_lock);
5705 vport->fc_flag &= ~FC_DISC_TMO;
5706 spin_unlock_irq(shost->host_lock);
5708 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5709 "disc timeout: state:x%x rtry:x%x flg:x%x",
5710 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5712 switch (vport->port_state) {
5714 case LPFC_LOCAL_CFG_LINK:
5716 * port_state is identically LPFC_LOCAL_CFG_LINK while
5717 * waiting for FAN timeout
5719 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5720 "0221 FAN timeout\n");
5722 /* Start discovery by sending FLOGI, clean up old rpis */
5723 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5725 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5727 if (ndlp->nlp_type & NLP_FABRIC) {
5728 /* Clean up the ndlp on Fabric connections */
5729 lpfc_drop_node(vport, ndlp);
5731 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5732 /* Fail outstanding IO now since device
5733 * is marked for PLOGI.
5735 lpfc_unreg_rpi(vport, ndlp);
5738 if (vport->port_state != LPFC_FLOGI) {
5739 if (phba->sli_rev <= LPFC_SLI_REV3)
5740 lpfc_initial_flogi(vport);
5742 lpfc_issue_init_vfi(vport);
5749 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5750 /* Initial FLOGI timeout */
5751 lpfc_printf_vlog(vport, KERN_ERR,
5753 "0222 Initial %s timeout\n",
5754 vport->vpi ? "FDISC" : "FLOGI");
5756 /* Assume no Fabric and go on with discovery.
5757 * Check for outstanding ELS FLOGI to abort.
5760 /* FLOGI failed, so just use loop map to make discovery list */
5761 lpfc_disc_list_loopmap(vport);
5763 /* Start discovery */
5764 lpfc_disc_start(vport);
5767 case LPFC_FABRIC_CFG_LINK:
5768 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5770 lpfc_printf_vlog(vport, KERN_ERR,
5772 "0223 Timeout while waiting for "
5773 "NameServer login\n");
5774 /* Next look for NameServer ndlp */
5775 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5777 lpfc_els_abort(phba, ndlp);
5779 /* ReStart discovery */
5783 /* Check for wait for NameServer Rsp timeout */
5784 lpfc_printf_vlog(vport, KERN_ERR,
5786 "0224 NameServer Query timeout "
5788 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5790 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5791 /* Try it one more time */
5792 vport->fc_ns_retry++;
5793 vport->gidft_inp = 0;
5794 rc = lpfc_issue_gidft(vport);
5798 vport->fc_ns_retry = 0;
5802 * Discovery is over.
5803 * set port_state to PORT_READY if SLI2.
5804 * cmpl_reg_vpi will set port_state to READY for SLI3.
5806 if (phba->sli_rev < LPFC_SLI_REV4) {
5807 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5808 lpfc_issue_reg_vpi(phba, vport);
5810 lpfc_issue_clear_la(phba, vport);
5811 vport->port_state = LPFC_VPORT_READY;
5815 /* Setup and issue mailbox INITIALIZE LINK command */
5816 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5817 if (!initlinkmbox) {
5818 lpfc_printf_vlog(vport, KERN_ERR,
5820 "0206 Device Discovery "
5821 "completion error\n");
5822 phba->link_state = LPFC_HBA_ERROR;
5826 lpfc_linkdown(phba);
5827 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5828 phba->cfg_link_speed);
5829 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5830 initlinkmbox->vport = vport;
5831 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5832 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5833 lpfc_set_loopback_flag(phba);
5834 if (rc == MBX_NOT_FINISHED)
5835 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5839 case LPFC_DISC_AUTH:
5840 /* Node Authentication timeout */
5841 lpfc_printf_vlog(vport, KERN_ERR,
5843 "0227 Node Authentication timeout\n");
5844 lpfc_disc_flush_list(vport);
5847 * set port_state to PORT_READY if SLI2.
5848 * cmpl_reg_vpi will set port_state to READY for SLI3.
5850 if (phba->sli_rev < LPFC_SLI_REV4) {
5851 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5852 lpfc_issue_reg_vpi(phba, vport);
5853 else { /* NPIV Not enabled */
5854 lpfc_issue_clear_la(phba, vport);
5855 vport->port_state = LPFC_VPORT_READY;
5860 case LPFC_VPORT_READY:
5861 if (vport->fc_flag & FC_RSCN_MODE) {
5862 lpfc_printf_vlog(vport, KERN_ERR,
5864 "0231 RSCN timeout Data: x%x "
5866 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5868 /* Cleanup any outstanding ELS commands */
5869 lpfc_els_flush_cmd(vport);
5871 lpfc_els_flush_rscn(vport);
5872 lpfc_disc_flush_list(vport);
5877 lpfc_printf_vlog(vport, KERN_ERR,
5879 "0273 Unexpected discovery timeout, "
5880 "vport State x%x\n", vport->port_state);
5884 switch (phba->link_state) {
5886 /* CLEAR LA timeout */
5887 lpfc_printf_vlog(vport, KERN_ERR,
5889 "0228 CLEAR LA timeout\n");
5894 lpfc_issue_clear_la(phba, vport);
5896 case LPFC_LINK_UNKNOWN:
5897 case LPFC_WARM_START:
5898 case LPFC_INIT_START:
5899 case LPFC_INIT_MBX_CMDS:
5900 case LPFC_LINK_DOWN:
5901 case LPFC_HBA_ERROR:
5902 lpfc_printf_vlog(vport, KERN_ERR,
5904 "0230 Unexpected timeout, hba link "
5905 "state x%x\n", phba->link_state);
5909 case LPFC_HBA_READY:
5914 lpfc_disc_flush_list(vport);
5915 if (phba->sli_rev != LPFC_SLI_REV4) {
5916 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5917 ~LPFC_STOP_IOCB_EVENT;
5918 psli->sli3_ring[LPFC_FCP_RING].flag &=
5919 ~LPFC_STOP_IOCB_EVENT;
5921 vport->port_state = LPFC_VPORT_READY;
5927 * This routine handles processing a NameServer REG_LOGIN mailbox
5928 * command upon completion. It is setup in the LPFC_MBOXQ
5929 * as the completion routine when the command is
5930 * handed off to the SLI layer.
5933 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5935 MAILBOX_t *mb = &pmb->u.mb;
5936 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5937 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
5938 struct lpfc_vport *vport = pmb->vport;
5940 pmb->ctx_buf = NULL;
5941 pmb->ctx_ndlp = NULL;
5943 if (phba->sli_rev < LPFC_SLI_REV4)
5944 ndlp->nlp_rpi = mb->un.varWords[0];
5945 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
5946 ndlp->nlp_type |= NLP_FABRIC;
5947 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
5948 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
5949 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
5950 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5951 kref_read(&ndlp->kref),
5954 * Start issuing Fabric-Device Management Interface (FDMI) command to
5955 * 0xfffffa (FDMI well known port).
5956 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5957 * DPRT -> RPRT (vports)
5959 if (vport->port_type == LPFC_PHYSICAL_PORT)
5960 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
5962 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
5965 /* decrement the node reference count held for this callback
5969 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5971 mempool_free(pmb, phba->mbox_mem_pool);
5977 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5979 uint16_t *rpi = param;
5981 return ndlp->nlp_rpi == *rpi;
5985 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5987 return memcmp(&ndlp->nlp_portname, param,
5988 sizeof(ndlp->nlp_portname)) == 0;
5991 static struct lpfc_nodelist *
5992 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
5994 struct lpfc_nodelist *ndlp;
5996 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5997 if (filter(ndlp, param)) {
5998 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5999 "3185 FIND node filter %ps DID "
6000 "ndlp x%px did x%x flg x%x st x%x "
6001 "xri x%x type x%x rpi x%x\n",
6002 filter, ndlp, ndlp->nlp_DID,
6003 ndlp->nlp_flag, ndlp->nlp_state,
6004 ndlp->nlp_xri, ndlp->nlp_type,
6009 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6010 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6015 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6016 * returns the node list element pointer else return NULL.
6018 struct lpfc_nodelist *
6019 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6021 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6025 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6026 * returns the node element list pointer else return NULL.
6028 struct lpfc_nodelist *
6029 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6032 struct lpfc_nodelist *ndlp;
6034 spin_lock_irq(shost->host_lock);
6035 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6036 spin_unlock_irq(shost->host_lock);
6041 * This routine looks up the ndlp lists for the given RPI. If the rpi
6042 * is found, the routine returns the node element list pointer else
6045 struct lpfc_nodelist *
6046 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6048 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6049 struct lpfc_nodelist *ndlp;
6050 unsigned long flags;
6052 spin_lock_irqsave(shost->host_lock, flags);
6053 ndlp = __lpfc_findnode_rpi(vport, rpi);
6054 spin_unlock_irqrestore(shost->host_lock, flags);
6059 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6060 * @phba: pointer to lpfc hba data structure.
6061 * @vpi: the physical host virtual N_Port identifier.
6063 * This routine finds a vport on a HBA (referred by @phba) through a
6064 * @vpi. The function walks the HBA's vport list and returns the address
6065 * of the vport with the matching @vpi.
6068 * NULL - No vport with the matching @vpi found
6069 * Otherwise - Address to the vport with the matching @vpi.
6072 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6074 struct lpfc_vport *vport;
6075 unsigned long flags;
6078 /* The physical ports are always vpi 0 - translate is unnecessary. */
6081 * Translate the physical vpi to the logical vpi. The
6082 * vport stores the logical vpi.
6084 for (i = 0; i <= phba->max_vpi; i++) {
6085 if (vpi == phba->vpi_ids[i])
6089 if (i > phba->max_vpi) {
6090 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6091 "2936 Could not find Vport mapped "
6092 "to vpi %d\n", vpi);
6097 spin_lock_irqsave(&phba->port_list_lock, flags);
6098 list_for_each_entry(vport, &phba->port_list, listentry) {
6099 if (vport->vpi == i) {
6100 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6104 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6108 struct lpfc_nodelist *
6109 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6111 struct lpfc_nodelist *ndlp;
6112 int rpi = LPFC_RPI_ALLOC_ERROR;
6114 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6115 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6116 if (rpi == LPFC_RPI_ALLOC_ERROR)
6120 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6122 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6123 lpfc_sli4_free_rpi(vport->phba, rpi);
6127 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6129 spin_lock_init(&ndlp->lock);
6131 lpfc_initialize_node(vport, ndlp, did);
6132 INIT_LIST_HEAD(&ndlp->nlp_listp);
6133 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6134 ndlp->nlp_rpi = rpi;
6135 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6136 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6137 "flg:x%x refcnt:%d\n",
6138 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6139 ndlp->nlp_flag, kref_read(&ndlp->kref));
6141 ndlp->active_rrqs_xri_bitmap =
6142 mempool_alloc(vport->phba->active_rrq_pool,
6144 if (ndlp->active_rrqs_xri_bitmap)
6145 memset(ndlp->active_rrqs_xri_bitmap, 0,
6146 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6151 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6152 "node init: did:x%x",
6153 ndlp->nlp_DID, 0, 0);
6158 /* This routine releases all resources associated with a specifc NPort's ndlp
6159 * and mempool_free's the nodelist.
6162 lpfc_nlp_release(struct kref *kref)
6164 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6166 struct lpfc_vport *vport = ndlp->vport;
6168 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6169 "node release: did:x%x flg:x%x type:x%x",
6170 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6172 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6173 "0279 %s: ndlp:%p did %x refcnt:%d rpi:%x\n",
6174 __func__, ndlp, ndlp->nlp_DID,
6175 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6177 /* remove ndlp from action. */
6178 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6179 lpfc_cleanup_node(vport, ndlp);
6181 /* Clear Node key fields to give other threads notice
6182 * that this node memory is not valid anymore.
6185 ndlp->nlp_state = NLP_STE_FREED_NODE;
6187 ndlp->fc4_xpt_flags = 0;
6189 /* free ndlp memory for final ndlp release */
6190 kfree(ndlp->lat_data);
6191 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6192 mempool_free(ndlp->active_rrqs_xri_bitmap,
6193 ndlp->phba->active_rrq_pool);
6194 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6197 /* This routine bumps the reference count for a ndlp structure to ensure
6198 * that one discovery thread won't free a ndlp while another discovery thread
6201 struct lpfc_nodelist *
6202 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6204 unsigned long flags;
6207 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6208 "node get: did:x%x flg:x%x refcnt:x%x",
6209 ndlp->nlp_DID, ndlp->nlp_flag,
6210 kref_read(&ndlp->kref));
6212 /* The check of ndlp usage to prevent incrementing the
6213 * ndlp reference count that is in the process of being
6216 spin_lock_irqsave(&ndlp->lock, flags);
6217 if (!kref_get_unless_zero(&ndlp->kref)) {
6218 spin_unlock_irqrestore(&ndlp->lock, flags);
6219 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6220 "0276 %s: ndlp:x%px refcnt:%d\n",
6221 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6224 spin_unlock_irqrestore(&ndlp->lock, flags);
6226 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6232 /* This routine decrements the reference count for a ndlp structure. If the
6233 * count goes to 0, this indicates the associated nodelist should be freed.
6236 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6239 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6240 "node put: did:x%x flg:x%x refcnt:x%x",
6241 ndlp->nlp_DID, ndlp->nlp_flag,
6242 kref_read(&ndlp->kref));
6244 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6247 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6250 /* This routine free's the specified nodelist if it is not in use
6251 * by any other discovery thread. This routine returns 1 if the
6252 * ndlp has been freed. A return value of 0 indicates the ndlp is
6253 * not yet been released.
6256 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6258 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6259 "node not used: did:x%x flg:x%x refcnt:x%x",
6260 ndlp->nlp_DID, ndlp->nlp_flag,
6261 kref_read(&ndlp->kref));
6262 if (kref_read(&ndlp->kref) == 1)
6263 if (lpfc_nlp_put(ndlp))
6269 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6270 * @phba: Pointer to hba context object.
6272 * This function iterate through all FC nodes associated
6273 * will all vports to check if there is any node with
6274 * fc_rports associated with it. If there is an fc_rport
6275 * associated with the node, then the node is either in
6276 * discovered state or its devloss_timer is pending.
6279 lpfc_fcf_inuse(struct lpfc_hba *phba)
6281 struct lpfc_vport **vports;
6283 struct lpfc_nodelist *ndlp;
6284 struct Scsi_Host *shost;
6286 vports = lpfc_create_vport_work_array(phba);
6288 /* If driver cannot allocate memory, indicate fcf is in use */
6292 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6293 shost = lpfc_shost_from_vport(vports[i]);
6294 spin_lock_irq(shost->host_lock);
6296 * IF the CVL_RCVD bit is not set then we have sent the
6298 * If dev_loss fires while we are waiting we do not want to
6301 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6302 spin_unlock_irq(shost->host_lock);
6306 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6308 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6310 spin_unlock_irq(shost->host_lock);
6312 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6314 lpfc_printf_log(phba, KERN_INFO,
6315 LOG_NODE | LOG_DISCOVERY,
6316 "2624 RPI %x DID %x flag %x "
6317 "still logged in\n",
6318 ndlp->nlp_rpi, ndlp->nlp_DID,
6322 spin_unlock_irq(shost->host_lock);
6325 lpfc_destroy_vport_work_array(phba, vports);
6330 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6331 * @phba: Pointer to hba context object.
6332 * @mboxq: Pointer to mailbox object.
6334 * This function frees memory associated with the mailbox command.
6337 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6339 struct lpfc_vport *vport = mboxq->vport;
6340 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6342 if (mboxq->u.mb.mbxStatus) {
6343 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6344 "2555 UNREG_VFI mbxStatus error x%x "
6346 mboxq->u.mb.mbxStatus, vport->port_state);
6348 spin_lock_irq(shost->host_lock);
6349 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6350 spin_unlock_irq(shost->host_lock);
6351 mempool_free(mboxq, phba->mbox_mem_pool);
6356 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6357 * @phba: Pointer to hba context object.
6358 * @mboxq: Pointer to mailbox object.
6360 * This function frees memory associated with the mailbox command.
6363 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6365 struct lpfc_vport *vport = mboxq->vport;
6367 if (mboxq->u.mb.mbxStatus) {
6368 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6369 "2550 UNREG_FCFI mbxStatus error x%x "
6371 mboxq->u.mb.mbxStatus, vport->port_state);
6373 mempool_free(mboxq, phba->mbox_mem_pool);
6378 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6379 * @phba: Pointer to hba context object.
6381 * This function prepare the HBA for unregistering the currently registered
6382 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6386 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6388 struct lpfc_vport **vports;
6389 struct lpfc_nodelist *ndlp;
6390 struct Scsi_Host *shost;
6393 /* Unregister RPIs */
6394 if (lpfc_fcf_inuse(phba))
6395 lpfc_unreg_hba_rpis(phba);
6397 /* At this point, all discovery is aborted */
6398 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6400 /* Unregister VPIs */
6401 vports = lpfc_create_vport_work_array(phba);
6402 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6403 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6404 /* Stop FLOGI/FDISC retries */
6405 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6407 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6408 lpfc_cleanup_pending_mbox(vports[i]);
6409 if (phba->sli_rev == LPFC_SLI_REV4)
6410 lpfc_sli4_unreg_all_rpis(vports[i]);
6411 lpfc_mbx_unreg_vpi(vports[i]);
6412 shost = lpfc_shost_from_vport(vports[i]);
6413 spin_lock_irq(shost->host_lock);
6414 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6415 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6416 spin_unlock_irq(shost->host_lock);
6418 lpfc_destroy_vport_work_array(phba, vports);
6419 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6420 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6422 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6423 lpfc_cleanup_pending_mbox(phba->pport);
6424 if (phba->sli_rev == LPFC_SLI_REV4)
6425 lpfc_sli4_unreg_all_rpis(phba->pport);
6426 lpfc_mbx_unreg_vpi(phba->pport);
6427 shost = lpfc_shost_from_vport(phba->pport);
6428 spin_lock_irq(shost->host_lock);
6429 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6430 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6431 spin_unlock_irq(shost->host_lock);
6434 /* Cleanup any outstanding ELS commands */
6435 lpfc_els_flush_all_cmd(phba);
6437 /* Unregister the physical port VFI */
6438 rc = lpfc_issue_unreg_vfi(phba->pport);
6443 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6444 * @phba: Pointer to hba context object.
6446 * This function issues synchronous unregister FCF mailbox command to HBA to
6447 * unregister the currently registered FCF record. The driver does not reset
6448 * the driver FCF usage state flags.
6450 * Return 0 if successfully issued, none-zero otherwise.
6453 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6458 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6460 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6461 "2551 UNREG_FCFI mbox allocation failed"
6462 "HBA state x%x\n", phba->pport->port_state);
6465 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6466 mbox->vport = phba->pport;
6467 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6468 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6470 if (rc == MBX_NOT_FINISHED) {
6471 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6472 "2552 Unregister FCFI command failed rc x%x "
6474 rc, phba->pport->port_state);
6481 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6482 * @phba: Pointer to hba context object.
6484 * This function unregisters the currently reigstered FCF. This function
6485 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6488 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6492 /* Preparation for unregistering fcf */
6493 rc = lpfc_unregister_fcf_prep(phba);
6495 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6496 "2748 Failed to prepare for unregistering "
6497 "HBA's FCF record: rc=%d\n", rc);
6501 /* Now, unregister FCF record and reset HBA FCF state */
6502 rc = lpfc_sli4_unregister_fcf(phba);
6505 /* Reset HBA FCF states after successful unregister FCF */
6506 phba->fcf.fcf_flag = 0;
6507 phba->fcf.current_rec.flag = 0;
6510 * If driver is not unloading, check if there is any other
6511 * FCF record that can be used for discovery.
6513 if ((phba->pport->load_flag & FC_UNLOADING) ||
6514 (phba->link_state < LPFC_LINK_UP))
6517 /* This is considered as the initial FCF discovery scan */
6518 spin_lock_irq(&phba->hbalock);
6519 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6520 spin_unlock_irq(&phba->hbalock);
6522 /* Reset FCF roundrobin bmask for new discovery */
6523 lpfc_sli4_clear_fcf_rr_bmask(phba);
6525 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6528 spin_lock_irq(&phba->hbalock);
6529 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6530 spin_unlock_irq(&phba->hbalock);
6531 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6532 "2553 lpfc_unregister_unused_fcf failed "
6533 "to read FCF record HBA state x%x\n",
6534 phba->pport->port_state);
6539 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6540 * @phba: Pointer to hba context object.
6542 * This function just unregisters the currently reigstered FCF. It does not
6543 * try to find another FCF for discovery.
6546 lpfc_unregister_fcf(struct lpfc_hba *phba)
6550 /* Preparation for unregistering fcf */
6551 rc = lpfc_unregister_fcf_prep(phba);
6553 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6554 "2749 Failed to prepare for unregistering "
6555 "HBA's FCF record: rc=%d\n", rc);
6559 /* Now, unregister FCF record and reset HBA FCF state */
6560 rc = lpfc_sli4_unregister_fcf(phba);
6563 /* Set proper HBA FCF states after successful unregister FCF */
6564 spin_lock_irq(&phba->hbalock);
6565 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6566 spin_unlock_irq(&phba->hbalock);
6570 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6571 * @phba: Pointer to hba context object.
6573 * This function check if there are any connected remote port for the FCF and
6574 * if all the devices are disconnected, this function unregister FCFI.
6575 * This function also tries to use another FCF for discovery.
6578 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6581 * If HBA is not running in FIP mode, if HBA does not support
6582 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6583 * registered, do nothing.
6585 spin_lock_irq(&phba->hbalock);
6586 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6587 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6588 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6589 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6590 (phba->pport->port_state == LPFC_FLOGI)) {
6591 spin_unlock_irq(&phba->hbalock);
6594 spin_unlock_irq(&phba->hbalock);
6596 if (lpfc_fcf_inuse(phba))
6599 lpfc_unregister_fcf_rescan(phba);
6603 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6604 * @phba: Pointer to hba context object.
6605 * @buff: Buffer containing the FCF connection table as in the config
6607 * This function create driver data structure for the FCF connection
6608 * record table read from config region 23.
6611 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6614 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6615 struct lpfc_fcf_conn_hdr *conn_hdr;
6616 struct lpfc_fcf_conn_rec *conn_rec;
6617 uint32_t record_count;
6620 /* Free the current connect table */
6621 list_for_each_entry_safe(conn_entry, next_conn_entry,
6622 &phba->fcf_conn_rec_list, list) {
6623 list_del_init(&conn_entry->list);
6627 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6628 record_count = conn_hdr->length * sizeof(uint32_t)/
6629 sizeof(struct lpfc_fcf_conn_rec);
6631 conn_rec = (struct lpfc_fcf_conn_rec *)
6632 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6634 for (i = 0; i < record_count; i++) {
6635 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6637 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6640 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6641 "2566 Failed to allocate connection"
6646 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6647 sizeof(struct lpfc_fcf_conn_rec));
6648 list_add_tail(&conn_entry->list,
6649 &phba->fcf_conn_rec_list);
6652 if (!list_empty(&phba->fcf_conn_rec_list)) {
6654 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6656 conn_rec = &conn_entry->conn_rec;
6657 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6658 "3345 FCF connection list rec[%02d]: "
6659 "flags:x%04x, vtag:x%04x, "
6660 "fabric_name:x%02x:%02x:%02x:%02x:"
6661 "%02x:%02x:%02x:%02x, "
6662 "switch_name:x%02x:%02x:%02x:%02x:"
6663 "%02x:%02x:%02x:%02x\n", i++,
6664 conn_rec->flags, conn_rec->vlan_tag,
6665 conn_rec->fabric_name[0],
6666 conn_rec->fabric_name[1],
6667 conn_rec->fabric_name[2],
6668 conn_rec->fabric_name[3],
6669 conn_rec->fabric_name[4],
6670 conn_rec->fabric_name[5],
6671 conn_rec->fabric_name[6],
6672 conn_rec->fabric_name[7],
6673 conn_rec->switch_name[0],
6674 conn_rec->switch_name[1],
6675 conn_rec->switch_name[2],
6676 conn_rec->switch_name[3],
6677 conn_rec->switch_name[4],
6678 conn_rec->switch_name[5],
6679 conn_rec->switch_name[6],
6680 conn_rec->switch_name[7]);
6686 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6687 * @phba: Pointer to hba context object.
6688 * @buff: Buffer containing the FCoE parameter data structure.
6690 * This function update driver data structure with config
6691 * parameters read from config region 23.
6694 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6697 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6698 struct lpfc_fcoe_params *fcoe_param;
6700 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6702 fcoe_param = (struct lpfc_fcoe_params *)
6703 (buff + sizeof(struct lpfc_fip_param_hdr));
6705 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6706 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6709 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6710 phba->valid_vlan = 1;
6711 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6715 phba->fc_map[0] = fcoe_param->fc_map[0];
6716 phba->fc_map[1] = fcoe_param->fc_map[1];
6717 phba->fc_map[2] = fcoe_param->fc_map[2];
6722 * lpfc_get_rec_conf23 - Get a record type in config region data.
6723 * @buff: Buffer containing config region 23 data.
6724 * @size: Size of the data buffer.
6725 * @rec_type: Record type to be searched.
6727 * This function searches config region data to find the beginning
6728 * of the record specified by record_type. If record found, this
6729 * function return pointer to the record else return NULL.
6732 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6734 uint32_t offset = 0, rec_length;
6736 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6737 (size < sizeof(uint32_t)))
6740 rec_length = buff[offset + 1];
6743 * One TLV record has one word header and number of data words
6744 * specified in the rec_length field of the record header.
6746 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6748 if (buff[offset] == rec_type)
6749 return &buff[offset];
6751 if (buff[offset] == LPFC_REGION23_LAST_REC)
6754 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6755 rec_length = buff[offset + 1];
6761 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6762 * @phba: Pointer to lpfc_hba data structure.
6763 * @buff: Buffer containing config region 23 data.
6764 * @size: Size of the data buffer.
6766 * This function parses the FCoE config parameters in config region 23 and
6767 * populate driver data structure with the parameters.
6770 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6774 uint32_t offset = 0;
6778 * If data size is less than 2 words signature and version cannot be
6781 if (size < 2*sizeof(uint32_t))
6784 /* Check the region signature first */
6785 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6786 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6787 "2567 Config region 23 has bad signature\n");
6793 /* Check the data structure version */
6794 if (buff[offset] != LPFC_REGION23_VERSION) {
6795 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6796 "2568 Config region 23 has bad version\n");
6801 /* Read FCoE param record */
6802 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6803 size - offset, FCOE_PARAM_TYPE);
6805 lpfc_read_fcoe_param(phba, rec_ptr);
6807 /* Read FCF connection table */
6808 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6809 size - offset, FCOE_CONN_TBL_TYPE);
6811 lpfc_read_fcf_conn_tbl(phba, rec_ptr);