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 *);
75 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba);
76 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba);
79 lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
81 if (ndlp->nlp_fc4_type ||
82 ndlp->nlp_type & NLP_FABRIC)
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 x%px SID x%x\n",
106 __func__, rport, rport->scsi_target_id);
112 pr_err("**** %s: NULL ndlp on rport x%px SID x%x\n",
113 __func__, rport, rport->scsi_target_id);
118 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
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, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
148 * This function will be called when dev_loss_tmo fire.
151 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
153 struct lpfc_nodelist *ndlp;
154 struct lpfc_vport *vport;
155 struct lpfc_hba *phba;
156 struct lpfc_work_evt *evtp;
157 unsigned long iflags;
159 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
167 "rport devlosscb: sid:x%x did:x%x flg:x%x",
168 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
172 "load_flag x%x refcnt %d\n",
173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174 vport->load_flag, kref_read(&ndlp->kref));
176 /* Don't schedule a worker thread event if the vport is going down.
177 * The teardown process cleans up the node via lpfc_drop_node.
179 if (vport->load_flag & FC_UNLOADING) {
180 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
183 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
185 /* Remove the node reference from remote_port_add now.
186 * The driver will not call remote_port_delete.
192 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
195 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
196 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
197 "6789 rport name %llx != node port name %llx",
199 wwn_to_u64(ndlp->nlp_portname.u.wwn));
201 evtp = &ndlp->dev_loss_evt;
203 if (!list_empty(&evtp->evt_listp)) {
204 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
205 "6790 rport name %llx dev_loss_evt pending\n",
210 spin_lock_irqsave(&ndlp->lock, iflags);
211 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
213 /* If there is a PLOGI in progress, and we are in a
214 * NLP_NPR_2B_DISC state, don't turn off the flag.
216 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
217 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
220 * The backend does not expect any more calls associated with this
221 * rport. Remove the association between rport and ndlp.
223 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
224 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
226 spin_unlock_irqrestore(&ndlp->lock, iflags);
228 /* We need to hold the node by incrementing the reference
229 * count until this queued work is done
231 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
233 spin_lock_irqsave(&phba->hbalock, iflags);
234 if (evtp->evt_arg1) {
235 evtp->evt = LPFC_EVT_DEV_LOSS;
236 list_add_tail(&evtp->evt_listp, &phba->work_list);
237 lpfc_worker_wake_up(phba);
239 spin_unlock_irqrestore(&phba->hbalock, iflags);
245 * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport
246 * @vport: Pointer to vport context object.
248 * This function checks for idle VMID entries related to a particular vport. If
249 * found unused/idle, free them accordingly.
251 static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
254 u32 difftime = 0, r, bucket;
257 struct lpfc_vmid *vmp;
259 write_lock(&vport->vmid_lock);
261 if (!vport->cur_vmid_cnt)
264 /* iterate through the table */
265 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
267 if (vmp->flag & LPFC_VMID_REGISTERED) {
268 /* check if the particular VMID is in use */
269 /* for all available per cpu variable */
270 for_each_possible_cpu(cpu) {
271 /* if last access time is less than timeout */
272 lta = per_cpu_ptr(vmp->last_io_time, cpu);
275 difftime = (jiffies) - (*lta);
276 if ((vport->vmid_inactivity_timeout *
277 JIFFIES_PER_HR) > difftime) {
283 /* if none of the cpus have been used by the vm, */
284 /* remove the entry if already registered */
286 /* mark the entry for deregistration */
287 vmp->flag = LPFC_VMID_DE_REGISTER;
288 write_unlock(&vport->vmid_lock);
289 if (vport->vmid_priority_tagging)
290 r = lpfc_vmid_uvem(vport, vmp, false);
292 r = lpfc_vmid_cmd(vport,
296 /* decrement number of active vms and mark */
297 /* entry in slot as free */
298 write_lock(&vport->vmid_lock);
300 struct lpfc_vmid *ht = vmp;
302 vport->cur_vmid_cnt--;
303 ht->flag = LPFC_VMID_SLOT_FREE;
304 free_percpu(ht->last_io_time);
305 ht->last_io_time = NULL;
306 hash_del(&ht->hnode);
312 write_unlock(&vport->vmid_lock);
316 * lpfc_check_inactive_vmid - VMID inactivity checker
317 * @phba: Pointer to hba context object.
319 * This function is called from the worker thread to determine if an entry in
320 * the VMID table can be released since there was no I/O activity seen from that
321 * particular VM for the specified time. When this happens, the entry in the
322 * table is released and also the resources on the switch cleared.
325 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
327 struct lpfc_vport *vport;
328 struct lpfc_vport **vports;
331 vports = lpfc_create_vport_work_array(phba);
335 for (i = 0; i <= phba->max_vports; i++) {
336 if ((!vports[i]) && (i == 0))
343 lpfc_check_inactive_vmid_one(vport);
345 lpfc_destroy_vport_work_array(phba, vports);
349 * lpfc_check_nlp_post_devloss - Check to restore ndlp refcnt after devloss
350 * @vport: Pointer to vport object.
351 * @ndlp: Pointer to remote node object.
353 * If NLP_IN_RECOV_POST_DEV_LOSS flag was set due to outstanding recovery of
354 * node during dev_loss_tmo processing, then this function restores the nlp_put
355 * kref decrement from lpfc_dev_loss_tmo_handler.
358 lpfc_check_nlp_post_devloss(struct lpfc_vport *vport,
359 struct lpfc_nodelist *ndlp)
361 unsigned long iflags;
363 spin_lock_irqsave(&ndlp->lock, iflags);
364 if (ndlp->save_flags & NLP_IN_RECOV_POST_DEV_LOSS) {
365 ndlp->save_flags &= ~NLP_IN_RECOV_POST_DEV_LOSS;
366 spin_unlock_irqrestore(&ndlp->lock, iflags);
368 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE,
369 "8438 Devloss timeout reversed on DID x%x "
370 "refcnt %d ndlp %p flag x%x "
371 "port_state = x%x\n",
372 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp,
373 ndlp->nlp_flag, vport->port_state);
374 spin_lock_irqsave(&ndlp->lock, iflags);
376 spin_unlock_irqrestore(&ndlp->lock, iflags);
380 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
381 * @ndlp: Pointer to remote node object.
383 * This function is called from the worker thread when devloss timeout timer
384 * expires. For SLI4 host, this routine shall return 1 when at lease one
385 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
386 * routine shall return 0 when there is no remote node is still in use of FCF
387 * when devloss timeout happened to this @ndlp.
390 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
392 struct lpfc_vport *vport;
393 struct lpfc_hba *phba;
397 bool recovering = false;
398 struct fc_vport *fc_vport = NULL;
399 unsigned long iflags;
402 name = (uint8_t *)&ndlp->nlp_portname;
405 spin_lock_irqsave(&ndlp->lock, iflags);
406 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
407 spin_unlock_irqrestore(&ndlp->lock, iflags);
409 if (phba->sli_rev == LPFC_SLI_REV4)
410 fcf_inuse = lpfc_fcf_inuse(phba);
412 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
413 "rport devlosstmo:did:x%x type:x%x id:x%x",
414 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
416 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
417 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
418 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
419 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
421 /* If the driver is recovering the rport, ignore devloss. */
422 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
423 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
424 "0284 Devloss timeout Ignored on "
425 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
427 *name, *(name+1), *(name+2), *(name+3),
428 *(name+4), *(name+5), *(name+6), *(name+7),
433 /* Fabric nodes are done. */
434 if (ndlp->nlp_type & NLP_FABRIC) {
435 spin_lock_irqsave(&ndlp->lock, iflags);
436 /* In massive vport configuration settings, it's possible
437 * dev_loss_tmo fired during node recovery. So, check if
438 * fabric nodes are in discovery states outstanding.
440 switch (ndlp->nlp_DID) {
442 fc_vport = vport->fc_vport;
444 fc_vport->vport_state == FC_VPORT_INITIALIZING)
447 case Fabric_Cntl_DID:
448 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
454 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
455 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
459 spin_unlock_irqrestore(&ndlp->lock, iflags);
461 /* Mark an NLP_IN_RECOV_POST_DEV_LOSS flag to know if reversing
462 * the following lpfc_nlp_put is necessary after fabric node is
466 lpfc_printf_vlog(vport, KERN_INFO,
467 LOG_DISCOVERY | LOG_NODE,
468 "8436 Devloss timeout marked on "
469 "DID x%x refcnt %d ndlp %p "
470 "flag x%x port_state = x%x\n",
471 ndlp->nlp_DID, kref_read(&ndlp->kref),
472 ndlp, ndlp->nlp_flag,
474 spin_lock_irqsave(&ndlp->lock, iflags);
475 ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
476 spin_unlock_irqrestore(&ndlp->lock, iflags);
477 } else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
478 /* Fabric node fully recovered before this dev_loss_tmo
479 * queue work is processed. Thus, ignore the
480 * dev_loss_tmo event.
482 lpfc_printf_vlog(vport, KERN_INFO,
483 LOG_DISCOVERY | LOG_NODE,
484 "8437 Devloss timeout ignored on "
485 "DID x%x refcnt %d ndlp %p "
486 "flag x%x port_state = x%x\n",
487 ndlp->nlp_DID, kref_read(&ndlp->kref),
488 ndlp, ndlp->nlp_flag,
497 if (ndlp->nlp_sid != NLP_NO_SID) {
499 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
503 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
504 "0203 Devloss timeout on "
505 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
506 "NPort x%06x Data: x%x x%x x%x\n",
507 *name, *(name+1), *(name+2), *(name+3),
508 *(name+4), *(name+5), *(name+6), *(name+7),
509 ndlp->nlp_DID, ndlp->nlp_flag,
510 ndlp->nlp_state, ndlp->nlp_rpi);
512 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
513 "0204 Devloss timeout on "
514 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
515 "NPort x%06x Data: x%x x%x x%x\n",
516 *name, *(name+1), *(name+2), *(name+3),
517 *(name+4), *(name+5), *(name+6), *(name+7),
518 ndlp->nlp_DID, ndlp->nlp_flag,
519 ndlp->nlp_state, ndlp->nlp_rpi);
522 /* If we are devloss, but we are in the process of rediscovering the
523 * ndlp, don't issue a NLP_EVT_DEVICE_RM event.
525 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
526 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
530 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
531 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
536 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
538 struct lpfc_vport *vport;
539 struct lpfc_vport **vports;
542 vports = lpfc_create_vport_work_array(phba);
546 for (i = 0; i <= phba->max_vports; i++) {
547 if ((!vports[i]) && (i == 0))
554 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
555 if (!lpfc_issue_els_qfpa(vport))
556 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
559 lpfc_destroy_vport_work_array(phba, vports);
563 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
564 * @phba: Pointer to hba context object.
565 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
566 * @nlp_did: remote node identifer with devloss timeout.
568 * This function is called from the worker thread after invoking devloss
569 * timeout handler and releasing the reference count for the ndlp with
570 * which the devloss timeout was handled for SLI4 host. For the devloss
571 * timeout of the last remote node which had been in use of FCF, when this
572 * routine is invoked, it shall be guaranteed that none of the remote are
573 * in-use of FCF. When devloss timeout to the last remote using the FCF,
574 * if the FIP engine is neither in FCF table scan process nor roundrobin
575 * failover process, the in-use FCF shall be unregistered. If the FIP
576 * engine is in FCF discovery process, the devloss timeout state shall
577 * be set for either the FCF table scan process or roundrobin failover
578 * process to unregister the in-use FCF.
581 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
584 /* If devloss timeout happened to a remote node when FCF had no
585 * longer been in-use, do nothing.
590 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
591 spin_lock_irq(&phba->hbalock);
592 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
593 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
594 spin_unlock_irq(&phba->hbalock);
597 phba->hba_flag |= HBA_DEVLOSS_TMO;
598 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
599 "2847 Last remote node (x%x) using "
600 "FCF devloss tmo\n", nlp_did);
602 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
603 spin_unlock_irq(&phba->hbalock);
604 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
605 "2868 Devloss tmo to FCF rediscovery "
609 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
610 spin_unlock_irq(&phba->hbalock);
611 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
612 "2869 Devloss tmo to idle FIP engine, "
613 "unreg in-use FCF and rescan.\n");
614 /* Unregister in-use FCF and rescan */
615 lpfc_unregister_fcf_rescan(phba);
618 spin_unlock_irq(&phba->hbalock);
619 if (phba->hba_flag & FCF_TS_INPROG)
620 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
621 "2870 FCF table scan in progress\n");
622 if (phba->hba_flag & FCF_RR_INPROG)
623 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
624 "2871 FLOGI roundrobin FCF failover "
627 lpfc_unregister_unused_fcf(phba);
631 * lpfc_alloc_fast_evt - Allocates data structure for posting event
632 * @phba: Pointer to hba context object.
634 * This function is called from the functions which need to post
635 * events from interrupt context. This function allocates data
636 * structure required for posting event. It also keeps track of
637 * number of events pending and prevent event storm when there are
640 struct lpfc_fast_path_event *
641 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
642 struct lpfc_fast_path_event *ret;
644 /* If there are lot of fast event do not exhaust memory due to this */
645 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
648 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
651 atomic_inc(&phba->fast_event_count);
652 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
653 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
659 * lpfc_free_fast_evt - Frees event data structure
660 * @phba: Pointer to hba context object.
661 * @evt: Event object which need to be freed.
663 * This function frees the data structure required for posting
667 lpfc_free_fast_evt(struct lpfc_hba *phba,
668 struct lpfc_fast_path_event *evt) {
670 atomic_dec(&phba->fast_event_count);
675 * lpfc_send_fastpath_evt - Posts events generated from fast path
676 * @phba: Pointer to hba context object.
677 * @evtp: Event data structure.
679 * This function is called from worker thread, when the interrupt
680 * context need to post an event. This function posts the event
681 * to fc transport netlink interface.
684 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
685 struct lpfc_work_evt *evtp)
687 unsigned long evt_category, evt_sub_category;
688 struct lpfc_fast_path_event *fast_evt_data;
690 uint32_t evt_data_size;
691 struct Scsi_Host *shost;
693 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
696 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
697 evt_sub_category = (unsigned long) fast_evt_data->un.
698 fabric_evt.subcategory;
699 shost = lpfc_shost_from_vport(fast_evt_data->vport);
700 if (evt_category == FC_REG_FABRIC_EVENT) {
701 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
702 evt_data = (char *) &fast_evt_data->un.read_check_error;
703 evt_data_size = sizeof(fast_evt_data->un.
705 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
706 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
707 evt_data = (char *) &fast_evt_data->un.fabric_evt;
708 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
710 lpfc_free_fast_evt(phba, fast_evt_data);
713 } else if (evt_category == FC_REG_SCSI_EVENT) {
714 switch (evt_sub_category) {
715 case LPFC_EVENT_QFULL:
716 case LPFC_EVENT_DEVBSY:
717 evt_data = (char *) &fast_evt_data->un.scsi_evt;
718 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
720 case LPFC_EVENT_CHECK_COND:
721 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
722 evt_data_size = sizeof(fast_evt_data->un.
725 case LPFC_EVENT_VARQUEDEPTH:
726 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
727 evt_data_size = sizeof(fast_evt_data->un.
731 lpfc_free_fast_evt(phba, fast_evt_data);
735 lpfc_free_fast_evt(phba, fast_evt_data);
739 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
740 fc_host_post_vendor_event(shost,
741 fc_get_event_number(),
746 lpfc_free_fast_evt(phba, fast_evt_data);
751 lpfc_work_list_done(struct lpfc_hba *phba)
753 struct lpfc_work_evt *evtp = NULL;
754 struct lpfc_nodelist *ndlp;
759 spin_lock_irq(&phba->hbalock);
760 while (!list_empty(&phba->work_list)) {
761 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
763 spin_unlock_irq(&phba->hbalock);
766 case LPFC_EVT_ELS_RETRY:
767 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
768 lpfc_els_retry_delay_handler(ndlp);
769 free_evt = 0; /* evt is part of ndlp */
770 /* decrement the node reference count held
771 * for this queued work
775 case LPFC_EVT_DEV_LOSS:
776 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
777 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
779 /* decrement the node reference count held for
782 nlp_did = ndlp->nlp_DID;
784 if (phba->sli_rev == LPFC_SLI_REV4)
785 lpfc_sli4_post_dev_loss_tmo_handler(phba,
789 case LPFC_EVT_RECOVER_PORT:
790 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
791 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
793 /* decrement the node reference count held for
798 case LPFC_EVT_ONLINE:
799 if (phba->link_state < LPFC_LINK_DOWN)
800 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
802 *(int *) (evtp->evt_arg1) = 0;
803 complete((struct completion *)(evtp->evt_arg2));
805 case LPFC_EVT_OFFLINE_PREP:
806 if (phba->link_state >= LPFC_LINK_DOWN)
807 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
808 *(int *)(evtp->evt_arg1) = 0;
809 complete((struct completion *)(evtp->evt_arg2));
811 case LPFC_EVT_OFFLINE:
813 lpfc_sli_brdrestart(phba);
814 *(int *)(evtp->evt_arg1) =
815 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
816 lpfc_unblock_mgmt_io(phba);
817 complete((struct completion *)(evtp->evt_arg2));
819 case LPFC_EVT_WARM_START:
821 lpfc_reset_barrier(phba);
822 lpfc_sli_brdreset(phba);
823 lpfc_hba_down_post(phba);
824 *(int *)(evtp->evt_arg1) =
825 lpfc_sli_brdready(phba, HS_MBRDY);
826 lpfc_unblock_mgmt_io(phba);
827 complete((struct completion *)(evtp->evt_arg2));
831 *(int *)(evtp->evt_arg1)
832 = (phba->pport->stopped)
833 ? 0 : lpfc_sli_brdkill(phba);
834 lpfc_unblock_mgmt_io(phba);
835 complete((struct completion *)(evtp->evt_arg2));
837 case LPFC_EVT_FASTPATH_MGMT_EVT:
838 lpfc_send_fastpath_evt(phba, evtp);
841 case LPFC_EVT_RESET_HBA:
842 if (!(phba->pport->load_flag & FC_UNLOADING))
843 lpfc_reset_hba(phba);
848 spin_lock_irq(&phba->hbalock);
850 spin_unlock_irq(&phba->hbalock);
855 lpfc_work_done(struct lpfc_hba *phba)
857 struct lpfc_sli_ring *pring;
858 uint32_t ha_copy, status, control, work_port_events;
859 struct lpfc_vport **vports;
860 struct lpfc_vport *vport;
863 spin_lock_irq(&phba->hbalock);
864 ha_copy = phba->work_ha;
866 spin_unlock_irq(&phba->hbalock);
868 /* First, try to post the next mailbox command to SLI4 device */
869 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
870 lpfc_sli4_post_async_mbox(phba);
872 if (ha_copy & HA_ERATT) {
873 /* Handle the error attention event */
874 lpfc_handle_eratt(phba);
876 if (phba->fw_dump_cmpl) {
877 complete(phba->fw_dump_cmpl);
878 phba->fw_dump_cmpl = NULL;
882 if (ha_copy & HA_MBATT)
883 lpfc_sli_handle_mb_event(phba);
885 if (ha_copy & HA_LATT)
886 lpfc_handle_latt(phba);
888 /* Handle VMID Events */
889 if (lpfc_is_vmid_enabled(phba)) {
890 if (phba->pport->work_port_events &
891 WORKER_CHECK_VMID_ISSUE_QFPA) {
892 lpfc_check_vmid_qfpa_issue(phba);
893 phba->pport->work_port_events &=
894 ~WORKER_CHECK_VMID_ISSUE_QFPA;
896 if (phba->pport->work_port_events &
897 WORKER_CHECK_INACTIVE_VMID) {
898 lpfc_check_inactive_vmid(phba);
899 phba->pport->work_port_events &=
900 ~WORKER_CHECK_INACTIVE_VMID;
904 /* Process SLI4 events */
905 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
906 if (phba->hba_flag & HBA_RRQ_ACTIVE)
907 lpfc_handle_rrq_active(phba);
908 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
909 lpfc_sli4_els_xri_abort_event_proc(phba);
910 if (phba->hba_flag & ASYNC_EVENT)
911 lpfc_sli4_async_event_proc(phba);
912 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
913 spin_lock_irq(&phba->hbalock);
914 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
915 spin_unlock_irq(&phba->hbalock);
916 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
918 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
919 lpfc_sli4_fcf_redisc_event_proc(phba);
922 vports = lpfc_create_vport_work_array(phba);
924 for (i = 0; i <= phba->max_vports; i++) {
926 * We could have no vports in array if unloading, so if
927 * this happens then just use the pport
929 if (vports[i] == NULL && i == 0)
935 spin_lock_irq(&vport->work_port_lock);
936 work_port_events = vport->work_port_events;
937 vport->work_port_events &= ~work_port_events;
938 spin_unlock_irq(&vport->work_port_lock);
939 if (work_port_events & WORKER_DISC_TMO)
940 lpfc_disc_timeout_handler(vport);
941 if (work_port_events & WORKER_ELS_TMO)
942 lpfc_els_timeout_handler(vport);
943 if (work_port_events & WORKER_HB_TMO)
944 lpfc_hb_timeout_handler(phba);
945 if (work_port_events & WORKER_MBOX_TMO)
946 lpfc_mbox_timeout_handler(phba);
947 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
948 lpfc_unblock_fabric_iocbs(phba);
949 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
950 lpfc_ramp_down_queue_handler(phba);
951 if (work_port_events & WORKER_DELAYED_DISC_TMO)
952 lpfc_delayed_disc_timeout_handler(vport);
954 lpfc_destroy_vport_work_array(phba, vports);
956 pring = lpfc_phba_elsring(phba);
957 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
958 status >>= (4*LPFC_ELS_RING);
959 if (pring && (status & HA_RXMASK ||
960 pring->flag & LPFC_DEFERRED_RING_EVENT ||
961 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
962 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
963 pring->flag |= LPFC_DEFERRED_RING_EVENT;
964 /* Preserve legacy behavior. */
965 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
966 set_bit(LPFC_DATA_READY, &phba->data_flags);
968 /* Driver could have abort request completed in queue
969 * when link goes down. Allow for this transition.
971 if (phba->link_state >= LPFC_LINK_DOWN ||
972 phba->link_flag & LS_MDS_LOOPBACK) {
973 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
974 lpfc_sli_handle_slow_ring_event(phba, pring,
979 if (phba->sli_rev == LPFC_SLI_REV4)
980 lpfc_drain_txq(phba);
982 * Turn on Ring interrupts
984 if (phba->sli_rev <= LPFC_SLI_REV3) {
985 spin_lock_irq(&phba->hbalock);
986 control = readl(phba->HCregaddr);
987 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
988 lpfc_debugfs_slow_ring_trc(phba,
989 "WRK Enable ring: cntl:x%x hacopy:x%x",
990 control, ha_copy, 0);
992 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
993 writel(control, phba->HCregaddr);
994 readl(phba->HCregaddr); /* flush */
996 lpfc_debugfs_slow_ring_trc(phba,
997 "WRK Ring ok: cntl:x%x hacopy:x%x",
998 control, ha_copy, 0);
1000 spin_unlock_irq(&phba->hbalock);
1003 lpfc_work_list_done(phba);
1007 lpfc_do_work(void *p)
1009 struct lpfc_hba *phba = p;
1012 set_user_nice(current, MIN_NICE);
1013 current->flags |= PF_NOFREEZE;
1014 phba->data_flags = 0;
1016 while (!kthread_should_stop()) {
1017 /* wait and check worker queue activities */
1018 rc = wait_event_interruptible(phba->work_waitq,
1019 (test_and_clear_bit(LPFC_DATA_READY,
1021 || kthread_should_stop()));
1022 /* Signal wakeup shall terminate the worker thread */
1024 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1025 "0433 Wakeup on signal: rc=x%x\n", rc);
1029 /* Attend pending lpfc data processing */
1030 lpfc_work_done(phba);
1032 phba->worker_thread = NULL;
1033 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1034 "0432 Worker thread stopped.\n");
1039 * This is only called to handle FC worker events. Since this a rare
1040 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
1041 * embedding it in the IOCB.
1044 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
1047 struct lpfc_work_evt *evtp;
1048 unsigned long flags;
1051 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
1052 * be queued to worker thread for processing
1054 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
1058 evtp->evt_arg1 = arg1;
1059 evtp->evt_arg2 = arg2;
1062 spin_lock_irqsave(&phba->hbalock, flags);
1063 list_add_tail(&evtp->evt_listp, &phba->work_list);
1064 spin_unlock_irqrestore(&phba->hbalock, flags);
1066 lpfc_worker_wake_up(phba);
1072 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
1074 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1075 struct lpfc_hba *phba = vport->phba;
1076 struct lpfc_nodelist *ndlp, *next_ndlp;
1078 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1079 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1082 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
1083 ((vport->port_type == LPFC_NPIV_PORT) &&
1084 ((ndlp->nlp_DID == NameServer_DID) ||
1085 (ndlp->nlp_DID == FDMI_DID) ||
1086 (ndlp->nlp_DID == Fabric_Cntl_DID))))
1087 lpfc_unreg_rpi(vport, ndlp);
1089 /* Leave Fabric nodes alone on link down */
1090 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1091 (!remove && ndlp->nlp_type & NLP_FABRIC))
1094 /* Notify transport of connectivity loss to trigger cleanup. */
1095 if (phba->nvmet_support &&
1096 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
1097 lpfc_nvmet_invalidate_host(phba, ndlp);
1099 lpfc_disc_state_machine(vport, ndlp, NULL,
1102 : NLP_EVT_DEVICE_RECOVERY);
1104 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
1105 if (phba->sli_rev == LPFC_SLI_REV4)
1106 lpfc_sli4_unreg_all_rpis(vport);
1107 lpfc_mbx_unreg_vpi(vport);
1108 spin_lock_irq(shost->host_lock);
1109 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1110 spin_unlock_irq(shost->host_lock);
1115 lpfc_port_link_failure(struct lpfc_vport *vport)
1117 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1119 /* Cleanup any outstanding received buffers */
1120 lpfc_cleanup_rcv_buffers(vport);
1122 /* Cleanup any outstanding RSCN activity */
1123 lpfc_els_flush_rscn(vport);
1125 /* Cleanup any outstanding ELS commands */
1126 lpfc_els_flush_cmd(vport);
1128 lpfc_cleanup_rpis(vport, 0);
1130 /* Turn off discovery timer if its running */
1131 lpfc_can_disctmo(vport);
1135 lpfc_linkdown_port(struct lpfc_vport *vport)
1137 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1139 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1140 fc_host_post_event(shost, fc_get_event_number(),
1141 FCH_EVT_LINKDOWN, 0);
1143 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1144 "Link Down: state:x%x rtry:x%x flg:x%x",
1145 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1147 lpfc_port_link_failure(vport);
1149 /* Stop delayed Nport discovery */
1150 spin_lock_irq(shost->host_lock);
1151 vport->fc_flag &= ~FC_DISC_DELAYED;
1152 spin_unlock_irq(shost->host_lock);
1153 del_timer_sync(&vport->delayed_disc_tmo);
1157 lpfc_linkdown(struct lpfc_hba *phba)
1159 struct lpfc_vport *vport = phba->pport;
1160 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1161 struct lpfc_vport **vports;
1165 if (phba->link_state == LPFC_LINK_DOWN)
1168 /* Block all SCSI stack I/Os */
1169 lpfc_scsi_dev_block(phba);
1171 phba->defer_flogi_acc_flag = false;
1173 spin_lock_irq(&phba->hbalock);
1174 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1175 spin_unlock_irq(&phba->hbalock);
1176 if (phba->link_state > LPFC_LINK_DOWN) {
1177 phba->link_state = LPFC_LINK_DOWN;
1178 if (phba->sli4_hba.conf_trunk) {
1179 phba->trunk_link.link0.state = 0;
1180 phba->trunk_link.link1.state = 0;
1181 phba->trunk_link.link2.state = 0;
1182 phba->trunk_link.link3.state = 0;
1183 phba->sli4_hba.link_state.logical_speed =
1184 LPFC_LINK_SPEED_UNKNOWN;
1186 spin_lock_irq(shost->host_lock);
1187 phba->pport->fc_flag &= ~FC_LBIT;
1188 spin_unlock_irq(shost->host_lock);
1190 vports = lpfc_create_vport_work_array(phba);
1191 if (vports != NULL) {
1192 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1193 /* Issue a LINK DOWN event to all nodes */
1194 lpfc_linkdown_port(vports[i]);
1196 vports[i]->fc_myDID = 0;
1198 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1199 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1200 if (phba->nvmet_support)
1201 lpfc_nvmet_update_targetport(phba);
1203 lpfc_nvme_update_localport(vports[i]);
1207 lpfc_destroy_vport_work_array(phba, vports);
1209 /* Clean up any SLI3 firmware default rpi's */
1210 if (phba->sli_rev > LPFC_SLI_REV3)
1211 goto skip_unreg_did;
1213 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1215 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1217 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1218 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1219 == MBX_NOT_FINISHED) {
1220 mempool_free(mb, phba->mbox_mem_pool);
1225 /* Setup myDID for link up if we are in pt2pt mode */
1226 if (phba->pport->fc_flag & FC_PT2PT) {
1227 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1229 lpfc_config_link(phba, mb);
1230 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1232 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1233 == MBX_NOT_FINISHED) {
1234 mempool_free(mb, phba->mbox_mem_pool);
1237 spin_lock_irq(shost->host_lock);
1238 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1239 phba->pport->rcv_flogi_cnt = 0;
1240 spin_unlock_irq(shost->host_lock);
1246 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1248 struct lpfc_nodelist *ndlp;
1250 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1251 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1253 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1255 if (ndlp->nlp_type & NLP_FABRIC) {
1256 /* On Linkup its safe to clean up the ndlp
1257 * from Fabric connections.
1259 if (ndlp->nlp_DID != Fabric_DID)
1260 lpfc_unreg_rpi(vport, ndlp);
1261 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1262 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1263 /* Fail outstanding IO now since device is
1266 lpfc_unreg_rpi(vport, ndlp);
1272 lpfc_linkup_port(struct lpfc_vport *vport)
1274 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1275 struct lpfc_hba *phba = vport->phba;
1277 if ((vport->load_flag & FC_UNLOADING) != 0)
1280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1281 "Link Up: top:x%x speed:x%x flg:x%x",
1282 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1284 /* If NPIV is not enabled, only bring the physical port up */
1285 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1286 (vport != phba->pport))
1289 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1290 fc_host_post_event(shost, fc_get_event_number(),
1293 spin_lock_irq(shost->host_lock);
1294 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1295 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1296 vport->fc_flag |= FC_NDISC_ACTIVE;
1297 vport->fc_ns_retry = 0;
1298 spin_unlock_irq(shost->host_lock);
1300 lpfc_linkup_cleanup_nodes(vport);
1304 lpfc_linkup(struct lpfc_hba *phba)
1306 struct lpfc_vport **vports;
1308 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1310 phba->link_state = LPFC_LINK_UP;
1312 /* Unblock fabric iocbs if they are blocked */
1313 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1314 del_timer_sync(&phba->fabric_block_timer);
1316 vports = lpfc_create_vport_work_array(phba);
1318 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1319 lpfc_linkup_port(vports[i]);
1320 lpfc_destroy_vport_work_array(phba, vports);
1322 /* Clear the pport flogi counter in case the link down was
1323 * absorbed without an ACQE. No lock here - in worker thread
1324 * and discovery is synchronized.
1326 spin_lock_irq(shost->host_lock);
1327 phba->pport->rcv_flogi_cnt = 0;
1328 spin_unlock_irq(shost->host_lock);
1330 /* reinitialize initial FLOGI flag */
1331 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1332 phba->defer_flogi_acc_flag = false;
1338 * This routine handles processing a CLEAR_LA mailbox
1339 * command upon completion. It is setup in the LPFC_MBOXQ
1340 * as the completion routine when the command is
1341 * handed off to the SLI layer. SLI3 only.
1344 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1346 struct lpfc_vport *vport = pmb->vport;
1347 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1348 struct lpfc_sli *psli = &phba->sli;
1349 MAILBOX_t *mb = &pmb->u.mb;
1352 /* Since we don't do discovery right now, turn these off here */
1353 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1354 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1356 /* Check for error */
1357 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1358 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1359 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1360 "0320 CLEAR_LA mbxStatus error x%x hba "
1362 mb->mbxStatus, vport->port_state);
1363 phba->link_state = LPFC_HBA_ERROR;
1367 if (vport->port_type == LPFC_PHYSICAL_PORT)
1368 phba->link_state = LPFC_HBA_READY;
1370 spin_lock_irq(&phba->hbalock);
1371 psli->sli_flag |= LPFC_PROCESS_LA;
1372 control = readl(phba->HCregaddr);
1373 control |= HC_LAINT_ENA;
1374 writel(control, phba->HCregaddr);
1375 readl(phba->HCregaddr); /* flush */
1376 spin_unlock_irq(&phba->hbalock);
1377 mempool_free(pmb, phba->mbox_mem_pool);
1381 /* Device Discovery completes */
1382 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1383 "0225 Device Discovery completes\n");
1384 mempool_free(pmb, phba->mbox_mem_pool);
1386 spin_lock_irq(shost->host_lock);
1387 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1388 spin_unlock_irq(shost->host_lock);
1390 lpfc_can_disctmo(vport);
1392 /* turn on Link Attention interrupts */
1394 spin_lock_irq(&phba->hbalock);
1395 psli->sli_flag |= LPFC_PROCESS_LA;
1396 control = readl(phba->HCregaddr);
1397 control |= HC_LAINT_ENA;
1398 writel(control, phba->HCregaddr);
1399 readl(phba->HCregaddr); /* flush */
1400 spin_unlock_irq(&phba->hbalock);
1406 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1408 struct lpfc_vport *vport = pmb->vport;
1409 LPFC_MBOXQ_t *sparam_mb;
1410 struct lpfc_dmabuf *sparam_mp;
1411 u16 status = pmb->u.mb.mbxStatus;
1414 mempool_free(pmb, phba->mbox_mem_pool);
1419 /* don't perform discovery for SLI4 loopback diagnostic test */
1420 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1421 !(phba->hba_flag & HBA_FCOE_MODE) &&
1422 (phba->link_flag & LS_LOOPBACK_MODE))
1425 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1426 vport->fc_flag & FC_PUBLIC_LOOP &&
1427 !(vport->fc_flag & FC_LBIT)) {
1428 /* Need to wait for FAN - use discovery timer
1429 * for timeout. port_state is identically
1430 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1432 lpfc_set_disctmo(vport);
1436 /* Start discovery by sending a FLOGI. port_state is identically
1437 * LPFC_FLOGI while waiting for FLOGI cmpl.
1439 if (vport->port_state != LPFC_FLOGI) {
1440 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1441 * bb-credit recovery is in place.
1443 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1444 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1445 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1450 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1452 mempool_free(sparam_mb, phba->mbox_mem_pool);
1455 sparam_mb->vport = vport;
1456 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1457 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1458 if (rc == MBX_NOT_FINISHED) {
1459 sparam_mp = (struct lpfc_dmabuf *)
1461 lpfc_mbuf_free(phba, sparam_mp->virt,
1464 sparam_mb->ctx_buf = NULL;
1465 mempool_free(sparam_mb, phba->mbox_mem_pool);
1469 phba->hba_flag |= HBA_DEFER_FLOGI;
1471 lpfc_initial_flogi(vport);
1474 if (vport->fc_flag & FC_PT2PT)
1475 lpfc_disc_start(vport);
1480 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1481 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1482 status, vport->port_state);
1485 lpfc_linkdown(phba);
1487 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1488 "0200 CONFIG_LINK bad hba state x%x\n",
1491 lpfc_issue_clear_la(phba, vport);
1496 * lpfc_sli4_clear_fcf_rr_bmask
1497 * @phba: pointer to the struct lpfc_hba for this port.
1498 * This fucnction resets the round robin bit mask and clears the
1499 * fcf priority list. The list deletions are done while holding the
1500 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1501 * from the lpfc_fcf_pri record.
1504 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1506 struct lpfc_fcf_pri *fcf_pri;
1507 struct lpfc_fcf_pri *next_fcf_pri;
1508 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1509 spin_lock_irq(&phba->hbalock);
1510 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1511 &phba->fcf.fcf_pri_list, list) {
1512 list_del_init(&fcf_pri->list);
1513 fcf_pri->fcf_rec.flag = 0;
1515 spin_unlock_irq(&phba->hbalock);
1518 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1520 struct lpfc_vport *vport = mboxq->vport;
1522 if (mboxq->u.mb.mbxStatus) {
1523 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1524 "2017 REG_FCFI mbxStatus error x%x "
1525 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1530 /* Start FCoE discovery by sending a FLOGI. */
1531 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1532 /* Set the FCFI registered flag */
1533 spin_lock_irq(&phba->hbalock);
1534 phba->fcf.fcf_flag |= FCF_REGISTERED;
1535 spin_unlock_irq(&phba->hbalock);
1537 /* If there is a pending FCoE event, restart FCF table scan. */
1538 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1539 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1542 /* Mark successful completion of FCF table scan */
1543 spin_lock_irq(&phba->hbalock);
1544 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1545 phba->hba_flag &= ~FCF_TS_INPROG;
1546 if (vport->port_state != LPFC_FLOGI) {
1547 phba->hba_flag |= FCF_RR_INPROG;
1548 spin_unlock_irq(&phba->hbalock);
1549 lpfc_issue_init_vfi(vport);
1552 spin_unlock_irq(&phba->hbalock);
1556 spin_lock_irq(&phba->hbalock);
1557 phba->hba_flag &= ~FCF_RR_INPROG;
1558 spin_unlock_irq(&phba->hbalock);
1560 mempool_free(mboxq, phba->mbox_mem_pool);
1564 * lpfc_fab_name_match - Check if the fcf fabric name match.
1565 * @fab_name: pointer to fabric name.
1566 * @new_fcf_record: pointer to fcf record.
1568 * This routine compare the fcf record's fabric name with provided
1569 * fabric name. If the fabric name are identical this function
1570 * returns 1 else return 0.
1573 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1575 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1577 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1579 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1581 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1583 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1585 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1587 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1589 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1595 * lpfc_sw_name_match - Check if the fcf switch name match.
1596 * @sw_name: pointer to switch name.
1597 * @new_fcf_record: pointer to fcf record.
1599 * This routine compare the fcf record's switch name with provided
1600 * switch name. If the switch name are identical this function
1601 * returns 1 else return 0.
1604 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1606 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1608 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1610 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1612 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1614 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1616 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1618 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1620 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1626 * lpfc_mac_addr_match - Check if the fcf mac address match.
1627 * @mac_addr: pointer to mac address.
1628 * @new_fcf_record: pointer to fcf record.
1630 * This routine compare the fcf record's mac address with HBA's
1631 * FCF mac address. If the mac addresses are identical this function
1632 * returns 1 else return 0.
1635 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1637 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1639 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1641 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1643 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1645 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1647 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1653 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1655 return (curr_vlan_id == new_vlan_id);
1659 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1660 * @phba: pointer to lpfc hba data structure.
1661 * @fcf_index: Index for the lpfc_fcf_record.
1662 * @new_fcf_record: pointer to hba fcf record.
1664 * This routine updates the driver FCF priority record from the new HBA FCF
1665 * record. The hbalock is asserted held in the code path calling this
1669 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1670 struct fcf_record *new_fcf_record
1673 struct lpfc_fcf_pri *fcf_pri;
1675 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1676 fcf_pri->fcf_rec.fcf_index = fcf_index;
1677 /* FCF record priority */
1678 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1683 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1684 * @fcf_rec: pointer to driver fcf record.
1685 * @new_fcf_record: pointer to fcf record.
1687 * This routine copies the FCF information from the FCF
1688 * record to lpfc_hba data structure.
1691 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1692 struct fcf_record *new_fcf_record)
1695 fcf_rec->fabric_name[0] =
1696 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1697 fcf_rec->fabric_name[1] =
1698 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1699 fcf_rec->fabric_name[2] =
1700 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1701 fcf_rec->fabric_name[3] =
1702 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1703 fcf_rec->fabric_name[4] =
1704 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1705 fcf_rec->fabric_name[5] =
1706 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1707 fcf_rec->fabric_name[6] =
1708 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1709 fcf_rec->fabric_name[7] =
1710 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1712 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1713 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1714 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1715 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1716 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1717 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1718 /* FCF record index */
1719 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1720 /* FCF record priority */
1721 fcf_rec->priority = new_fcf_record->fip_priority;
1723 fcf_rec->switch_name[0] =
1724 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1725 fcf_rec->switch_name[1] =
1726 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1727 fcf_rec->switch_name[2] =
1728 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1729 fcf_rec->switch_name[3] =
1730 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1731 fcf_rec->switch_name[4] =
1732 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1733 fcf_rec->switch_name[5] =
1734 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1735 fcf_rec->switch_name[6] =
1736 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1737 fcf_rec->switch_name[7] =
1738 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1742 * __lpfc_update_fcf_record - Update driver fcf record
1743 * @phba: pointer to lpfc hba data structure.
1744 * @fcf_rec: pointer to driver fcf record.
1745 * @new_fcf_record: pointer to hba fcf record.
1746 * @addr_mode: address mode to be set to the driver fcf record.
1747 * @vlan_id: vlan tag to be set to the driver fcf record.
1748 * @flag: flag bits to be set to the driver fcf record.
1750 * This routine updates the driver FCF record from the new HBA FCF record
1751 * together with the address mode, vlan_id, and other informations. This
1752 * routine is called with the hbalock held.
1755 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1756 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1757 uint16_t vlan_id, uint32_t flag)
1759 lockdep_assert_held(&phba->hbalock);
1761 /* Copy the fields from the HBA's FCF record */
1762 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1763 /* Update other fields of driver FCF record */
1764 fcf_rec->addr_mode = addr_mode;
1765 fcf_rec->vlan_id = vlan_id;
1766 fcf_rec->flag |= (flag | RECORD_VALID);
1767 __lpfc_update_fcf_record_pri(phba,
1768 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1773 * lpfc_register_fcf - Register the FCF with hba.
1774 * @phba: pointer to lpfc hba data structure.
1776 * This routine issues a register fcfi mailbox command to register
1780 lpfc_register_fcf(struct lpfc_hba *phba)
1782 LPFC_MBOXQ_t *fcf_mbxq;
1785 spin_lock_irq(&phba->hbalock);
1786 /* If the FCF is not available do nothing. */
1787 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1788 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1789 spin_unlock_irq(&phba->hbalock);
1793 /* The FCF is already registered, start discovery */
1794 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1795 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1796 phba->hba_flag &= ~FCF_TS_INPROG;
1797 if (phba->pport->port_state != LPFC_FLOGI &&
1798 phba->pport->fc_flag & FC_FABRIC) {
1799 phba->hba_flag |= FCF_RR_INPROG;
1800 spin_unlock_irq(&phba->hbalock);
1801 lpfc_initial_flogi(phba->pport);
1804 spin_unlock_irq(&phba->hbalock);
1807 spin_unlock_irq(&phba->hbalock);
1809 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1811 spin_lock_irq(&phba->hbalock);
1812 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1813 spin_unlock_irq(&phba->hbalock);
1817 lpfc_reg_fcfi(phba, fcf_mbxq);
1818 fcf_mbxq->vport = phba->pport;
1819 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1820 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1821 if (rc == MBX_NOT_FINISHED) {
1822 spin_lock_irq(&phba->hbalock);
1823 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1824 spin_unlock_irq(&phba->hbalock);
1825 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1832 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1833 * @phba: pointer to lpfc hba data structure.
1834 * @new_fcf_record: pointer to fcf record.
1835 * @boot_flag: Indicates if this record used by boot bios.
1836 * @addr_mode: The address mode to be used by this FCF
1837 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1839 * This routine compare the fcf record with connect list obtained from the
1840 * config region to decide if this FCF can be used for SAN discovery. It returns
1841 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1842 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1843 * is used by boot bios and addr_mode will indicate the addressing mode to be
1844 * used for this FCF when the function returns.
1845 * If the FCF record need to be used with a particular vlan id, the vlan is
1846 * set in the vlan_id on return of the function. If not VLAN tagging need to
1847 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1850 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1851 struct fcf_record *new_fcf_record,
1852 uint32_t *boot_flag, uint32_t *addr_mode,
1855 struct lpfc_fcf_conn_entry *conn_entry;
1856 int i, j, fcf_vlan_id = 0;
1858 /* Find the lowest VLAN id in the FCF record */
1859 for (i = 0; i < 512; i++) {
1860 if (new_fcf_record->vlan_bitmap[i]) {
1861 fcf_vlan_id = i * 8;
1863 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1871 /* FCF not valid/available or solicitation in progress */
1872 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1873 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1874 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1877 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1879 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1881 if (phba->valid_vlan)
1882 *vlan_id = phba->vlan_id;
1884 *vlan_id = LPFC_FCOE_NULL_VID;
1889 * If there are no FCF connection table entry, driver connect to all
1892 if (list_empty(&phba->fcf_conn_rec_list)) {
1894 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1898 * When there are no FCF connect entries, use driver's default
1899 * addressing mode - FPMA.
1901 if (*addr_mode & LPFC_FCF_FPMA)
1902 *addr_mode = LPFC_FCF_FPMA;
1904 /* If FCF record report a vlan id use that vlan id */
1906 *vlan_id = fcf_vlan_id;
1908 *vlan_id = LPFC_FCOE_NULL_VID;
1912 list_for_each_entry(conn_entry,
1913 &phba->fcf_conn_rec_list, list) {
1914 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1917 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1918 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1921 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1922 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1925 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1927 * If the vlan bit map does not have the bit set for the
1928 * vlan id to be used, then it is not a match.
1930 if (!(new_fcf_record->vlan_bitmap
1931 [conn_entry->conn_rec.vlan_tag / 8] &
1932 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1937 * If connection record does not support any addressing mode,
1938 * skip the FCF record.
1940 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1941 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1945 * Check if the connection record specifies a required
1948 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1949 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1952 * If SPMA required but FCF not support this continue.
1954 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1955 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1956 new_fcf_record) & LPFC_FCF_SPMA))
1960 * If FPMA required but FCF not support this continue.
1962 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1963 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1964 new_fcf_record) & LPFC_FCF_FPMA))
1969 * This fcf record matches filtering criteria.
1971 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1977 * If user did not specify any addressing mode, or if the
1978 * preferred addressing mode specified by user is not supported
1979 * by FCF, allow fabric to pick the addressing mode.
1981 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1984 * If the user specified a required address mode, assign that
1987 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1988 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1989 *addr_mode = (conn_entry->conn_rec.flags &
1991 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1993 * If the user specified a preferred address mode, use the
1994 * addr mode only if FCF support the addr_mode.
1996 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1997 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1998 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1999 (*addr_mode & LPFC_FCF_SPMA))
2000 *addr_mode = LPFC_FCF_SPMA;
2001 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2002 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2003 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2004 (*addr_mode & LPFC_FCF_FPMA))
2005 *addr_mode = LPFC_FCF_FPMA;
2007 /* If matching connect list has a vlan id, use it */
2008 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
2009 *vlan_id = conn_entry->conn_rec.vlan_tag;
2011 * If no vlan id is specified in connect list, use the vlan id
2014 else if (fcf_vlan_id)
2015 *vlan_id = fcf_vlan_id;
2017 *vlan_id = LPFC_FCOE_NULL_VID;
2026 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
2027 * @phba: pointer to lpfc hba data structure.
2028 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
2030 * This function check if there is any fcoe event pending while driver
2031 * scan FCF entries. If there is any pending event, it will restart the
2032 * FCF saning and return 1 else return 0.
2035 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
2038 * If the Link is up and no FCoE events while in the
2039 * FCF discovery, no need to restart FCF discovery.
2041 if ((phba->link_state >= LPFC_LINK_UP) &&
2042 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
2045 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2046 "2768 Pending link or FCF event during current "
2047 "handling of the previous event: link_state:x%x, "
2048 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
2049 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
2050 phba->fcoe_eventtag);
2052 spin_lock_irq(&phba->hbalock);
2053 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
2054 spin_unlock_irq(&phba->hbalock);
2056 if (phba->link_state >= LPFC_LINK_UP) {
2057 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2058 "2780 Restart FCF table scan due to "
2059 "pending FCF event:evt_tag_at_scan:x%x, "
2060 "evt_tag_current:x%x\n",
2061 phba->fcoe_eventtag_at_fcf_scan,
2062 phba->fcoe_eventtag);
2063 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
2066 * Do not continue FCF discovery and clear FCF_TS_INPROG
2069 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2070 "2833 Stop FCF discovery process due to link "
2071 "state change (x%x)\n", phba->link_state);
2072 spin_lock_irq(&phba->hbalock);
2073 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
2074 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
2075 spin_unlock_irq(&phba->hbalock);
2078 /* Unregister the currently registered FCF if required */
2080 spin_lock_irq(&phba->hbalock);
2081 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
2082 spin_unlock_irq(&phba->hbalock);
2083 lpfc_sli4_unregister_fcf(phba);
2089 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
2090 * @phba: pointer to lpfc hba data structure.
2091 * @fcf_cnt: number of eligible fcf record seen so far.
2093 * This function makes an running random selection decision on FCF record to
2094 * use through a sequence of @fcf_cnt eligible FCF records with equal
2095 * probability. To perform integer manunipulation of random numbers with
2096 * size unit32_t, the lower 16 bits of the 32-bit random number returned
2097 * from prandom_u32() are taken as the random random number generated.
2099 * Returns true when outcome is for the newly read FCF record should be
2100 * chosen; otherwise, return false when outcome is for keeping the previously
2101 * chosen FCF record.
2104 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
2108 /* Get 16-bit uniform random number */
2109 rand_num = 0xFFFF & prandom_u32();
2111 /* Decision with probability 1/fcf_cnt */
2112 if ((fcf_cnt * rand_num) < 0xFFFF)
2119 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
2120 * @phba: pointer to lpfc hba data structure.
2121 * @mboxq: pointer to mailbox object.
2122 * @next_fcf_index: pointer to holder of next fcf index.
2124 * This routine parses the non-embedded fcf mailbox command by performing the
2125 * necessarily error checking, non-embedded read FCF record mailbox command
2126 * SGE parsing, and endianness swapping.
2128 * Returns the pointer to the new FCF record in the non-embedded mailbox
2129 * command DMA memory if successfully, other NULL.
2131 static struct fcf_record *
2132 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2133 uint16_t *next_fcf_index)
2136 struct lpfc_mbx_sge sge;
2137 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2138 uint32_t shdr_status, shdr_add_status, if_type;
2139 union lpfc_sli4_cfg_shdr *shdr;
2140 struct fcf_record *new_fcf_record;
2142 /* Get the first SGE entry from the non-embedded DMA memory. This
2143 * routine only uses a single SGE.
2145 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2146 if (unlikely(!mboxq->sge_array)) {
2147 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2148 "2524 Failed to get the non-embedded SGE "
2149 "virtual address\n");
2152 virt_addr = mboxq->sge_array->addr[0];
2154 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2155 lpfc_sli_pcimem_bcopy(shdr, shdr,
2156 sizeof(union lpfc_sli4_cfg_shdr));
2157 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2158 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2159 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2160 if (shdr_status || shdr_add_status) {
2161 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2162 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2163 lpfc_printf_log(phba, KERN_ERR,
2165 "2726 READ_FCF_RECORD Indicates empty "
2168 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2169 "2521 READ_FCF_RECORD mailbox failed "
2170 "with status x%x add_status x%x, "
2171 "mbx\n", shdr_status, shdr_add_status);
2175 /* Interpreting the returned information of the FCF record */
2176 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2177 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2178 sizeof(struct lpfc_mbx_read_fcf_tbl));
2179 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2180 new_fcf_record = (struct fcf_record *)(virt_addr +
2181 sizeof(struct lpfc_mbx_read_fcf_tbl));
2182 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2183 offsetof(struct fcf_record, vlan_bitmap));
2184 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2185 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2187 return new_fcf_record;
2191 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2192 * @phba: pointer to lpfc hba data structure.
2193 * @fcf_record: pointer to the fcf record.
2194 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2195 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2197 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2201 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2202 struct fcf_record *fcf_record,
2204 uint16_t next_fcf_index)
2206 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2207 "2764 READ_FCF_RECORD:\n"
2208 "\tFCF_Index : x%x\n"
2209 "\tFCF_Avail : x%x\n"
2210 "\tFCF_Valid : x%x\n"
2212 "\tFIP_Priority : x%x\n"
2213 "\tMAC_Provider : x%x\n"
2214 "\tLowest VLANID : x%x\n"
2215 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2216 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2217 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2218 "\tNext_FCF_Index: x%x\n",
2219 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2220 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2221 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2222 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2223 fcf_record->fip_priority,
2224 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2226 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2227 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2228 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2229 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2230 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2231 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2232 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2233 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2234 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2235 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2236 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2237 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2238 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2239 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2240 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2241 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2242 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2243 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2244 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2245 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2246 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2247 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2252 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2253 * @phba: pointer to lpfc hba data structure.
2254 * @fcf_rec: pointer to an existing FCF record.
2255 * @new_fcf_record: pointer to a new FCF record.
2256 * @new_vlan_id: vlan id from the new FCF record.
2258 * This function performs matching test of a new FCF record against an existing
2259 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2260 * will not be used as part of the FCF record matching criteria.
2262 * Returns true if all the fields matching, otherwise returns false.
2265 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2266 struct lpfc_fcf_rec *fcf_rec,
2267 struct fcf_record *new_fcf_record,
2268 uint16_t new_vlan_id)
2270 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2271 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2273 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2275 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2277 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2279 if (fcf_rec->priority != new_fcf_record->fip_priority)
2285 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2286 * @vport: Pointer to vport object.
2287 * @fcf_index: index to next fcf.
2289 * This function processing the roundrobin fcf failover to next fcf index.
2290 * When this function is invoked, there will be a current fcf registered
2292 * Return: 0 for continue retrying flogi on currently registered fcf;
2293 * 1 for stop flogi on currently registered fcf;
2295 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2297 struct lpfc_hba *phba = vport->phba;
2300 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2301 spin_lock_irq(&phba->hbalock);
2302 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2303 spin_unlock_irq(&phba->hbalock);
2304 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2305 "2872 Devloss tmo with no eligible "
2306 "FCF, unregister in-use FCF (x%x) "
2307 "and rescan FCF table\n",
2308 phba->fcf.current_rec.fcf_indx);
2309 lpfc_unregister_fcf_rescan(phba);
2310 goto stop_flogi_current_fcf;
2312 /* Mark the end to FLOGI roundrobin failover */
2313 phba->hba_flag &= ~FCF_RR_INPROG;
2314 /* Allow action to new fcf asynchronous event */
2315 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2316 spin_unlock_irq(&phba->hbalock);
2317 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2318 "2865 No FCF available, stop roundrobin FCF "
2319 "failover and change port state:x%x/x%x\n",
2320 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2321 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2323 if (!phba->fcf.fcf_redisc_attempted) {
2324 lpfc_unregister_fcf(phba);
2326 rc = lpfc_sli4_redisc_fcf_table(phba);
2328 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2329 "3195 Rediscover FCF table\n");
2330 phba->fcf.fcf_redisc_attempted = 1;
2331 lpfc_sli4_clear_fcf_rr_bmask(phba);
2333 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2334 "3196 Rediscover FCF table "
2335 "failed. Status:x%x\n", rc);
2338 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2339 "3197 Already rediscover FCF table "
2340 "attempted. No more retry\n");
2342 goto stop_flogi_current_fcf;
2344 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2345 "2794 Try FLOGI roundrobin FCF failover to "
2346 "(x%x)\n", fcf_index);
2347 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2349 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2350 "2761 FLOGI roundrobin FCF failover "
2351 "failed (rc:x%x) to read FCF (x%x)\n",
2352 rc, phba->fcf.current_rec.fcf_indx);
2354 goto stop_flogi_current_fcf;
2358 stop_flogi_current_fcf:
2359 lpfc_can_disctmo(vport);
2364 * lpfc_sli4_fcf_pri_list_del
2365 * @phba: pointer to lpfc hba data structure.
2366 * @fcf_index: the index of the fcf record to delete
2367 * This routine checks the on list flag of the fcf_index to be deleted.
2368 * If it is one the list then it is removed from the list, and the flag
2369 * is cleared. This routine grab the hbalock before removing the fcf
2370 * record from the list.
2372 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2375 struct lpfc_fcf_pri *new_fcf_pri;
2377 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2378 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2379 "3058 deleting idx x%x pri x%x flg x%x\n",
2380 fcf_index, new_fcf_pri->fcf_rec.priority,
2381 new_fcf_pri->fcf_rec.flag);
2382 spin_lock_irq(&phba->hbalock);
2383 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2384 if (phba->fcf.current_rec.priority ==
2385 new_fcf_pri->fcf_rec.priority)
2386 phba->fcf.eligible_fcf_cnt--;
2387 list_del_init(&new_fcf_pri->list);
2388 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2390 spin_unlock_irq(&phba->hbalock);
2394 * lpfc_sli4_set_fcf_flogi_fail
2395 * @phba: pointer to lpfc hba data structure.
2396 * @fcf_index: the index of the fcf record to update
2397 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2398 * flag so the the round robin slection for the particular priority level
2399 * will try a different fcf record that does not have this bit set.
2400 * If the fcf record is re-read for any reason this flag is cleared brfore
2401 * adding it to the priority list.
2404 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2406 struct lpfc_fcf_pri *new_fcf_pri;
2407 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2408 spin_lock_irq(&phba->hbalock);
2409 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2410 spin_unlock_irq(&phba->hbalock);
2414 * lpfc_sli4_fcf_pri_list_add
2415 * @phba: pointer to lpfc hba data structure.
2416 * @fcf_index: the index of the fcf record to add
2417 * @new_fcf_record: pointer to a new FCF record.
2418 * This routine checks the priority of the fcf_index to be added.
2419 * If it is a lower priority than the current head of the fcf_pri list
2420 * then it is added to the list in the right order.
2421 * If it is the same priority as the current head of the list then it
2422 * is added to the head of the list and its bit in the rr_bmask is set.
2423 * If the fcf_index to be added is of a higher priority than the current
2424 * head of the list then the rr_bmask is cleared, its bit is set in the
2425 * rr_bmask and it is added to the head of the list.
2427 * 0=success 1=failure
2429 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2431 struct fcf_record *new_fcf_record)
2433 uint16_t current_fcf_pri;
2434 uint16_t last_index;
2435 struct lpfc_fcf_pri *fcf_pri;
2436 struct lpfc_fcf_pri *next_fcf_pri;
2437 struct lpfc_fcf_pri *new_fcf_pri;
2440 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2441 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2442 "3059 adding idx x%x pri x%x flg x%x\n",
2443 fcf_index, new_fcf_record->fip_priority,
2444 new_fcf_pri->fcf_rec.flag);
2445 spin_lock_irq(&phba->hbalock);
2446 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2447 list_del_init(&new_fcf_pri->list);
2448 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2449 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2450 if (list_empty(&phba->fcf.fcf_pri_list)) {
2451 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2452 ret = lpfc_sli4_fcf_rr_index_set(phba,
2453 new_fcf_pri->fcf_rec.fcf_index);
2457 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2458 LPFC_SLI4_FCF_TBL_INDX_MAX);
2459 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2460 ret = 0; /* Empty rr list */
2463 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2464 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2465 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2466 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2467 memset(phba->fcf.fcf_rr_bmask, 0,
2468 sizeof(*phba->fcf.fcf_rr_bmask));
2469 /* fcfs_at_this_priority_level = 1; */
2470 phba->fcf.eligible_fcf_cnt = 1;
2472 /* fcfs_at_this_priority_level++; */
2473 phba->fcf.eligible_fcf_cnt++;
2474 ret = lpfc_sli4_fcf_rr_index_set(phba,
2475 new_fcf_pri->fcf_rec.fcf_index);
2479 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2480 &phba->fcf.fcf_pri_list, list) {
2481 if (new_fcf_pri->fcf_rec.priority <=
2482 fcf_pri->fcf_rec.priority) {
2483 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2484 list_add(&new_fcf_pri->list,
2485 &phba->fcf.fcf_pri_list);
2487 list_add(&new_fcf_pri->list,
2488 &((struct lpfc_fcf_pri *)
2489 fcf_pri->list.prev)->list);
2492 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2493 || new_fcf_pri->fcf_rec.priority <
2494 next_fcf_pri->fcf_rec.priority) {
2495 list_add(&new_fcf_pri->list, &fcf_pri->list);
2499 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2505 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2506 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2507 spin_unlock_irq(&phba->hbalock);
2512 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2513 * @phba: pointer to lpfc hba data structure.
2514 * @mboxq: pointer to mailbox object.
2516 * This function iterates through all the fcf records available in
2517 * HBA and chooses the optimal FCF record for discovery. After finding
2518 * the FCF for discovery it registers the FCF record and kicks start
2520 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2521 * use an FCF record which matches fabric name and mac address of the
2522 * currently used FCF record.
2523 * If the driver supports only one FCF, it will try to use the FCF record
2524 * used by BOOT_BIOS.
2527 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2529 struct fcf_record *new_fcf_record;
2530 uint32_t boot_flag, addr_mode;
2531 uint16_t fcf_index, next_fcf_index;
2532 struct lpfc_fcf_rec *fcf_rec = NULL;
2533 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2534 bool select_new_fcf;
2537 /* If there is pending FCoE event restart FCF table scan */
2538 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2539 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2543 /* Parse the FCF record from the non-embedded mailbox command */
2544 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2546 if (!new_fcf_record) {
2547 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2548 "2765 Mailbox command READ_FCF_RECORD "
2549 "failed to retrieve a FCF record.\n");
2550 /* Let next new FCF event trigger fast failover */
2551 spin_lock_irq(&phba->hbalock);
2552 phba->hba_flag &= ~FCF_TS_INPROG;
2553 spin_unlock_irq(&phba->hbalock);
2554 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2558 /* Check the FCF record against the connection list */
2559 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2560 &addr_mode, &vlan_id);
2562 /* Log the FCF record information if turned on */
2563 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2567 * If the fcf record does not match with connect list entries
2568 * read the next entry; otherwise, this is an eligible FCF
2569 * record for roundrobin FCF failover.
2572 lpfc_sli4_fcf_pri_list_del(phba,
2573 bf_get(lpfc_fcf_record_fcf_index,
2575 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2576 "2781 FCF (x%x) failed connection "
2577 "list check: (x%x/x%x/%x)\n",
2578 bf_get(lpfc_fcf_record_fcf_index,
2580 bf_get(lpfc_fcf_record_fcf_avail,
2582 bf_get(lpfc_fcf_record_fcf_valid,
2584 bf_get(lpfc_fcf_record_fcf_sol,
2586 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2587 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2588 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2589 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2590 phba->fcf.current_rec.fcf_indx) {
2591 lpfc_printf_log(phba, KERN_ERR,
2593 "2862 FCF (x%x) matches property "
2594 "of in-use FCF (x%x)\n",
2595 bf_get(lpfc_fcf_record_fcf_index,
2597 phba->fcf.current_rec.fcf_indx);
2601 * In case the current in-use FCF record becomes
2602 * invalid/unavailable during FCF discovery that
2603 * was not triggered by fast FCF failover process,
2604 * treat it as fast FCF failover.
2606 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2607 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2608 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2609 "2835 Invalid in-use FCF "
2610 "(x%x), enter FCF failover "
2612 phba->fcf.current_rec.fcf_indx);
2613 spin_lock_irq(&phba->hbalock);
2614 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2615 spin_unlock_irq(&phba->hbalock);
2616 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2617 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2618 LPFC_FCOE_FCF_GET_FIRST);
2624 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2625 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2632 * If this is not the first FCF discovery of the HBA, use last
2633 * FCF record for the discovery. The condition that a rescan
2634 * matches the in-use FCF record: fabric name, switch name, mac
2635 * address, and vlan_id.
2637 spin_lock_irq(&phba->hbalock);
2638 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2639 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2640 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2641 new_fcf_record, vlan_id)) {
2642 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2643 phba->fcf.current_rec.fcf_indx) {
2644 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2645 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2646 /* Stop FCF redisc wait timer */
2647 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2649 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2650 /* Fast failover, mark completed */
2651 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2652 spin_unlock_irq(&phba->hbalock);
2653 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2654 "2836 New FCF matches in-use "
2655 "FCF (x%x), port_state:x%x, "
2657 phba->fcf.current_rec.fcf_indx,
2658 phba->pport->port_state,
2659 phba->pport->fc_flag);
2662 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2663 "2863 New FCF (x%x) matches "
2664 "property of in-use FCF (x%x)\n",
2665 bf_get(lpfc_fcf_record_fcf_index,
2667 phba->fcf.current_rec.fcf_indx);
2670 * Read next FCF record from HBA searching for the matching
2671 * with in-use record only if not during the fast failover
2672 * period. In case of fast failover period, it shall try to
2673 * determine whether the FCF record just read should be the
2676 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2677 spin_unlock_irq(&phba->hbalock);
2682 * Update on failover FCF record only if it's in FCF fast-failover
2683 * period; otherwise, update on current FCF record.
2685 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2686 fcf_rec = &phba->fcf.failover_rec;
2688 fcf_rec = &phba->fcf.current_rec;
2690 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2692 * If the driver FCF record does not have boot flag
2693 * set and new hba fcf record has boot flag set, use
2694 * the new hba fcf record.
2696 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2697 /* Choose this FCF record */
2698 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2699 "2837 Update current FCF record "
2700 "(x%x) with new FCF record (x%x)\n",
2702 bf_get(lpfc_fcf_record_fcf_index,
2704 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2705 addr_mode, vlan_id, BOOT_ENABLE);
2706 spin_unlock_irq(&phba->hbalock);
2710 * If the driver FCF record has boot flag set and the
2711 * new hba FCF record does not have boot flag, read
2712 * the next FCF record.
2714 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2715 spin_unlock_irq(&phba->hbalock);
2719 * If the new hba FCF record has lower priority value
2720 * than the driver FCF record, use the new record.
2722 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2723 /* Choose the new FCF record with lower priority */
2724 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2725 "2838 Update current FCF record "
2726 "(x%x) with new FCF record (x%x)\n",
2728 bf_get(lpfc_fcf_record_fcf_index,
2730 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2731 addr_mode, vlan_id, 0);
2732 /* Reset running random FCF selection count */
2733 phba->fcf.eligible_fcf_cnt = 1;
2734 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2735 /* Update running random FCF selection count */
2736 phba->fcf.eligible_fcf_cnt++;
2737 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2738 phba->fcf.eligible_fcf_cnt);
2739 if (select_new_fcf) {
2740 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2741 "2839 Update current FCF record "
2742 "(x%x) with new FCF record (x%x)\n",
2744 bf_get(lpfc_fcf_record_fcf_index,
2746 /* Choose the new FCF by random selection */
2747 __lpfc_update_fcf_record(phba, fcf_rec,
2749 addr_mode, vlan_id, 0);
2752 spin_unlock_irq(&phba->hbalock);
2756 * This is the first suitable FCF record, choose this record for
2757 * initial best-fit FCF.
2760 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2761 "2840 Update initial FCF candidate "
2763 bf_get(lpfc_fcf_record_fcf_index,
2765 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2766 addr_mode, vlan_id, (boot_flag ?
2768 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2769 /* Setup initial running random FCF selection count */
2770 phba->fcf.eligible_fcf_cnt = 1;
2772 spin_unlock_irq(&phba->hbalock);
2776 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2777 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2778 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2780 * Case of FCF fast failover scan
2784 * It has not found any suitable FCF record, cancel
2785 * FCF scan inprogress, and do nothing
2787 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2788 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2789 "2782 No suitable FCF found: "
2791 phba->fcoe_eventtag_at_fcf_scan,
2792 bf_get(lpfc_fcf_record_fcf_index,
2794 spin_lock_irq(&phba->hbalock);
2795 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2796 phba->hba_flag &= ~FCF_TS_INPROG;
2797 spin_unlock_irq(&phba->hbalock);
2798 /* Unregister in-use FCF and rescan */
2799 lpfc_printf_log(phba, KERN_INFO,
2801 "2864 On devloss tmo "
2802 "unreg in-use FCF and "
2803 "rescan FCF table\n");
2804 lpfc_unregister_fcf_rescan(phba);
2808 * Let next new FCF event trigger fast failover
2810 phba->hba_flag &= ~FCF_TS_INPROG;
2811 spin_unlock_irq(&phba->hbalock);
2815 * It has found a suitable FCF record that is not
2816 * the same as in-use FCF record, unregister the
2817 * in-use FCF record, replace the in-use FCF record
2818 * with the new FCF record, mark FCF fast failover
2819 * completed, and then start register the new FCF
2823 /* Unregister the current in-use FCF record */
2824 lpfc_unregister_fcf(phba);
2826 /* Replace in-use record with the new record */
2827 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2828 "2842 Replace in-use FCF (x%x) "
2829 "with failover FCF (x%x)\n",
2830 phba->fcf.current_rec.fcf_indx,
2831 phba->fcf.failover_rec.fcf_indx);
2832 memcpy(&phba->fcf.current_rec,
2833 &phba->fcf.failover_rec,
2834 sizeof(struct lpfc_fcf_rec));
2836 * Mark the fast FCF failover rediscovery completed
2837 * and the start of the first round of the roundrobin
2840 spin_lock_irq(&phba->hbalock);
2841 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2842 spin_unlock_irq(&phba->hbalock);
2843 /* Register to the new FCF record */
2844 lpfc_register_fcf(phba);
2847 * In case of transaction period to fast FCF failover,
2848 * do nothing when search to the end of the FCF table.
2850 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2851 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2854 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2855 phba->fcf.fcf_flag & FCF_IN_USE) {
2857 * In case the current in-use FCF record no
2858 * longer existed during FCF discovery that
2859 * was not triggered by fast FCF failover
2860 * process, treat it as fast FCF failover.
2862 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2863 "2841 In-use FCF record (x%x) "
2864 "not reported, entering fast "
2865 "FCF failover mode scanning.\n",
2866 phba->fcf.current_rec.fcf_indx);
2867 spin_lock_irq(&phba->hbalock);
2868 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2869 spin_unlock_irq(&phba->hbalock);
2870 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2871 LPFC_FCOE_FCF_GET_FIRST);
2874 /* Register to the new FCF record */
2875 lpfc_register_fcf(phba);
2878 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2882 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2883 lpfc_register_fcf(phba);
2889 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2890 * @phba: pointer to lpfc hba data structure.
2891 * @mboxq: pointer to mailbox object.
2893 * This is the callback function for FLOGI failure roundrobin FCF failover
2894 * read FCF record mailbox command from the eligible FCF record bmask for
2895 * performing the failover. If the FCF read back is not valid/available, it
2896 * fails through to retrying FLOGI to the currently registered FCF again.
2897 * Otherwise, if the FCF read back is valid and available, it will set the
2898 * newly read FCF record to the failover FCF record, unregister currently
2899 * registered FCF record, copy the failover FCF record to the current
2900 * FCF record, and then register the current FCF record before proceeding
2901 * to trying FLOGI on the new failover FCF.
2904 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2906 struct fcf_record *new_fcf_record;
2907 uint32_t boot_flag, addr_mode;
2908 uint16_t next_fcf_index, fcf_index;
2909 uint16_t current_fcf_index;
2913 /* If link state is not up, stop the roundrobin failover process */
2914 if (phba->link_state < LPFC_LINK_UP) {
2915 spin_lock_irq(&phba->hbalock);
2916 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2917 phba->hba_flag &= ~FCF_RR_INPROG;
2918 spin_unlock_irq(&phba->hbalock);
2922 /* Parse the FCF record from the non-embedded mailbox command */
2923 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2925 if (!new_fcf_record) {
2926 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2927 "2766 Mailbox command READ_FCF_RECORD "
2928 "failed to retrieve a FCF record. "
2929 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2930 phba->fcf.fcf_flag);
2931 lpfc_unregister_fcf_rescan(phba);
2935 /* Get the needed parameters from FCF record */
2936 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2937 &addr_mode, &vlan_id);
2939 /* Log the FCF record information if turned on */
2940 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2943 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2945 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2946 "2848 Remove ineligible FCF (x%x) from "
2947 "from roundrobin bmask\n", fcf_index);
2948 /* Clear roundrobin bmask bit for ineligible FCF */
2949 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2950 /* Perform next round of roundrobin FCF failover */
2951 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2952 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2958 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2959 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2960 "2760 Perform FLOGI roundrobin FCF failover: "
2961 "FCF (x%x) back to FCF (x%x)\n",
2962 phba->fcf.current_rec.fcf_indx, fcf_index);
2963 /* Wait 500 ms before retrying FLOGI to current FCF */
2965 lpfc_issue_init_vfi(phba->pport);
2969 /* Upload new FCF record to the failover FCF record */
2970 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2971 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2972 phba->fcf.failover_rec.fcf_indx, fcf_index);
2973 spin_lock_irq(&phba->hbalock);
2974 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2975 new_fcf_record, addr_mode, vlan_id,
2976 (boot_flag ? BOOT_ENABLE : 0));
2977 spin_unlock_irq(&phba->hbalock);
2979 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2981 /* Unregister the current in-use FCF record */
2982 lpfc_unregister_fcf(phba);
2984 /* Replace in-use record with the new record */
2985 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2986 sizeof(struct lpfc_fcf_rec));
2988 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2989 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2990 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2993 lpfc_register_fcf(phba);
2995 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2999 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
3000 * @phba: pointer to lpfc hba data structure.
3001 * @mboxq: pointer to mailbox object.
3003 * This is the callback function of read FCF record mailbox command for
3004 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
3005 * failover when a new FCF event happened. If the FCF read back is
3006 * valid/available and it passes the connection list check, it updates
3007 * the bmask for the eligible FCF record for roundrobin failover.
3010 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3012 struct fcf_record *new_fcf_record;
3013 uint32_t boot_flag, addr_mode;
3014 uint16_t fcf_index, next_fcf_index;
3018 /* If link state is not up, no need to proceed */
3019 if (phba->link_state < LPFC_LINK_UP)
3022 /* If FCF discovery period is over, no need to proceed */
3023 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
3026 /* Parse the FCF record from the non-embedded mailbox command */
3027 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3029 if (!new_fcf_record) {
3030 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3031 "2767 Mailbox command READ_FCF_RECORD "
3032 "failed to retrieve a FCF record.\n");
3036 /* Check the connection list for eligibility */
3037 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3038 &addr_mode, &vlan_id);
3040 /* Log the FCF record information if turned on */
3041 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3047 /* Update the eligible FCF record index bmask */
3048 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3050 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
3053 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3057 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
3058 * @phba: pointer to lpfc hba data structure.
3059 * @mboxq: pointer to mailbox data structure.
3061 * This function handles completion of init vfi mailbox command.
3064 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3066 struct lpfc_vport *vport = mboxq->vport;
3069 * VFI not supported on interface type 0, just do the flogi
3070 * Also continue if the VFI is in use - just use the same one.
3072 if (mboxq->u.mb.mbxStatus &&
3073 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3074 LPFC_SLI_INTF_IF_TYPE_0) &&
3075 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3076 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3077 "2891 Init VFI mailbox failed 0x%x\n",
3078 mboxq->u.mb.mbxStatus);
3079 mempool_free(mboxq, phba->mbox_mem_pool);
3080 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3084 lpfc_initial_flogi(vport);
3085 mempool_free(mboxq, phba->mbox_mem_pool);
3090 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
3091 * @vport: pointer to lpfc_vport data structure.
3093 * This function issue a init_vfi mailbox command to initialize the VFI and
3094 * VPI for the physical port.
3097 lpfc_issue_init_vfi(struct lpfc_vport *vport)
3099 LPFC_MBOXQ_t *mboxq;
3101 struct lpfc_hba *phba = vport->phba;
3103 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3105 lpfc_printf_vlog(vport, KERN_ERR,
3106 LOG_TRACE_EVENT, "2892 Failed to allocate "
3107 "init_vfi mailbox\n");
3110 lpfc_init_vfi(mboxq, vport);
3111 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3112 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3113 if (rc == MBX_NOT_FINISHED) {
3114 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3115 "2893 Failed to issue init_vfi mailbox\n");
3116 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3121 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3122 * @phba: pointer to lpfc hba data structure.
3123 * @mboxq: pointer to mailbox data structure.
3125 * This function handles completion of init vpi mailbox command.
3128 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3130 struct lpfc_vport *vport = mboxq->vport;
3131 struct lpfc_nodelist *ndlp;
3132 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3134 if (mboxq->u.mb.mbxStatus) {
3135 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3136 "2609 Init VPI mailbox failed 0x%x\n",
3137 mboxq->u.mb.mbxStatus);
3138 mempool_free(mboxq, phba->mbox_mem_pool);
3139 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3142 spin_lock_irq(shost->host_lock);
3143 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3144 spin_unlock_irq(shost->host_lock);
3146 /* If this port is physical port or FDISC is done, do reg_vpi */
3147 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3148 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3150 lpfc_printf_vlog(vport, KERN_ERR,
3152 "2731 Cannot find fabric "
3153 "controller node\n");
3155 lpfc_register_new_vport(phba, vport, ndlp);
3156 mempool_free(mboxq, phba->mbox_mem_pool);
3160 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3161 lpfc_initial_fdisc(vport);
3163 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3164 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3165 "2606 No NPIV Fabric support\n");
3167 mempool_free(mboxq, phba->mbox_mem_pool);
3172 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3173 * @vport: pointer to lpfc_vport data structure.
3175 * This function issue a init_vpi mailbox command to initialize
3176 * VPI for the vport.
3179 lpfc_issue_init_vpi(struct lpfc_vport *vport)
3181 LPFC_MBOXQ_t *mboxq;
3184 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3185 vpi = lpfc_alloc_vpi(vport->phba);
3187 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3188 "3303 Failed to obtain vport vpi\n");
3189 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3195 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3197 lpfc_printf_vlog(vport, KERN_ERR,
3198 LOG_TRACE_EVENT, "2607 Failed to allocate "
3199 "init_vpi mailbox\n");
3202 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3203 mboxq->vport = vport;
3204 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3205 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3206 if (rc == MBX_NOT_FINISHED) {
3207 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3208 "2608 Failed to issue init_vpi mailbox\n");
3209 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3214 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3215 * @phba: pointer to lpfc hba data structure.
3217 * This function loops through the list of vports on the @phba and issues an
3218 * FDISC if possible.
3221 lpfc_start_fdiscs(struct lpfc_hba *phba)
3223 struct lpfc_vport **vports;
3226 vports = lpfc_create_vport_work_array(phba);
3227 if (vports != NULL) {
3228 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3229 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3231 /* There are no vpi for this vport */
3232 if (vports[i]->vpi > phba->max_vpi) {
3233 lpfc_vport_set_state(vports[i],
3237 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3238 lpfc_vport_set_state(vports[i],
3242 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3243 lpfc_issue_init_vpi(vports[i]);
3246 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3247 lpfc_initial_fdisc(vports[i]);
3249 lpfc_vport_set_state(vports[i],
3250 FC_VPORT_NO_FABRIC_SUPP);
3251 lpfc_printf_vlog(vports[i], KERN_ERR,
3254 "Fabric support\n");
3258 lpfc_destroy_vport_work_array(phba, vports);
3262 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3264 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
3265 struct lpfc_vport *vport = mboxq->vport;
3266 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3269 * VFI not supported for interface type 0, so ignore any mailbox
3270 * error (except VFI in use) and continue with the discovery.
3272 if (mboxq->u.mb.mbxStatus &&
3273 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3274 LPFC_SLI_INTF_IF_TYPE_0) &&
3275 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3276 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3277 "2018 REG_VFI mbxStatus error x%x "
3279 mboxq->u.mb.mbxStatus, vport->port_state);
3280 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3281 /* FLOGI failed, use loop map to make discovery list */
3282 lpfc_disc_list_loopmap(vport);
3283 /* Start discovery */
3284 lpfc_disc_start(vport);
3287 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3291 /* If the VFI is already registered, there is nothing else to do
3292 * Unless this was a VFI update and we are in PT2PT mode, then
3293 * we should drop through to set the port state to ready.
3295 if (vport->fc_flag & FC_VFI_REGISTERED)
3296 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3297 vport->fc_flag & FC_PT2PT))
3300 /* The VPI is implicitly registered when the VFI is registered */
3301 spin_lock_irq(shost->host_lock);
3302 vport->vpi_state |= LPFC_VPI_REGISTERED;
3303 vport->fc_flag |= FC_VFI_REGISTERED;
3304 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3305 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3306 spin_unlock_irq(shost->host_lock);
3308 /* In case SLI4 FC loopback test, we are ready */
3309 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3310 (phba->link_flag & LS_LOOPBACK_MODE)) {
3311 phba->link_state = LPFC_HBA_READY;
3315 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3316 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3317 "alpacnt:%d LinkState:%x topology:%x\n",
3318 vport->port_state, vport->fc_flag, vport->fc_myDID,
3319 vport->phba->alpa_map[0],
3320 phba->link_state, phba->fc_topology);
3322 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3324 * For private loop or for NPort pt2pt,
3325 * just start discovery and we are done.
3327 if ((vport->fc_flag & FC_PT2PT) ||
3328 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3329 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3331 /* Use loop map to make discovery list */
3332 lpfc_disc_list_loopmap(vport);
3333 /* Start discovery */
3334 if (vport->fc_flag & FC_PT2PT)
3335 vport->port_state = LPFC_VPORT_READY;
3337 lpfc_disc_start(vport);
3339 lpfc_start_fdiscs(phba);
3340 lpfc_do_scr_ns_plogi(phba, vport);
3345 mempool_free(mboxq, phba->mbox_mem_pool);
3347 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3354 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3356 MAILBOX_t *mb = &pmb->u.mb;
3357 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3358 struct lpfc_vport *vport = pmb->vport;
3359 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3360 struct serv_parm *sp = &vport->fc_sparam;
3363 /* Check for error */
3364 if (mb->mbxStatus) {
3365 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3366 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3367 "0319 READ_SPARAM mbxStatus error x%x "
3369 mb->mbxStatus, vport->port_state);
3370 lpfc_linkdown(phba);
3374 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3375 sizeof (struct serv_parm));
3377 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3378 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3379 ed_tov = (ed_tov + 999999) / 1000000;
3381 phba->fc_edtov = ed_tov;
3382 phba->fc_ratov = (2 * ed_tov) / 1000;
3383 if (phba->fc_ratov < FF_DEF_RATOV) {
3384 /* RA_TOV should be atleast 10sec for initial flogi */
3385 phba->fc_ratov = FF_DEF_RATOV;
3388 lpfc_update_vport_wwn(vport);
3389 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3390 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3391 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3392 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3395 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3397 mempool_free(pmb, phba->mbox_mem_pool);
3399 /* Check if sending the FLOGI is being deferred to after we get
3400 * up to date CSPs from MBX_READ_SPARAM.
3402 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3403 lpfc_initial_flogi(vport);
3404 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3409 pmb->ctx_buf = NULL;
3410 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3412 lpfc_issue_clear_la(phba, vport);
3413 mempool_free(pmb, phba->mbox_mem_pool);
3418 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3420 struct lpfc_vport *vport = phba->pport;
3421 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3422 struct Scsi_Host *shost;
3424 struct lpfc_dmabuf *mp;
3426 struct fcf_record *fcf_record;
3427 uint32_t fc_flags = 0;
3428 unsigned long iflags;
3430 spin_lock_irqsave(&phba->hbalock, iflags);
3431 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3433 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3434 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3435 case LPFC_LINK_SPEED_1GHZ:
3436 case LPFC_LINK_SPEED_2GHZ:
3437 case LPFC_LINK_SPEED_4GHZ:
3438 case LPFC_LINK_SPEED_8GHZ:
3439 case LPFC_LINK_SPEED_10GHZ:
3440 case LPFC_LINK_SPEED_16GHZ:
3441 case LPFC_LINK_SPEED_32GHZ:
3442 case LPFC_LINK_SPEED_64GHZ:
3443 case LPFC_LINK_SPEED_128GHZ:
3444 case LPFC_LINK_SPEED_256GHZ:
3447 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3452 if (phba->fc_topology &&
3453 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3454 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3455 "3314 Toplogy changed was 0x%x is 0x%x\n",
3457 bf_get(lpfc_mbx_read_top_topology, la));
3458 phba->fc_topology_changed = 1;
3461 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3462 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3464 shost = lpfc_shost_from_vport(vport);
3465 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3466 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3468 /* if npiv is enabled and this adapter supports npiv log
3469 * a message that npiv is not supported in this topology
3471 if (phba->cfg_enable_npiv && phba->max_vpi)
3472 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3473 "1309 Link Up Event npiv not supported in loop "
3475 /* Get Loop Map information */
3476 if (bf_get(lpfc_mbx_read_top_il, la))
3477 fc_flags |= FC_LBIT;
3479 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3480 i = la->lilpBde64.tus.f.bdeSize;
3483 phba->alpa_map[0] = 0;
3485 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3496 numalpa = phba->alpa_map[0];
3498 while (j < numalpa) {
3499 memset(un.pamap, 0, 16);
3500 for (k = 1; j < numalpa; k++) {
3502 phba->alpa_map[j + 1];
3507 /* Link Up Event ALPA map */
3508 lpfc_printf_log(phba,
3511 "1304 Link Up Event "
3512 "ALPA map Data: x%x "
3514 un.pa.wd1, un.pa.wd2,
3515 un.pa.wd3, un.pa.wd4);
3520 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3521 if (phba->max_vpi && phba->cfg_enable_npiv &&
3522 (phba->sli_rev >= LPFC_SLI_REV3))
3523 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3525 vport->fc_myDID = phba->fc_pref_DID;
3526 fc_flags |= FC_LBIT;
3528 spin_unlock_irqrestore(&phba->hbalock, iflags);
3531 spin_lock_irqsave(shost->host_lock, iflags);
3532 vport->fc_flag |= fc_flags;
3533 spin_unlock_irqrestore(shost->host_lock, iflags);
3539 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3543 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3545 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3548 sparam_mbox->vport = vport;
3549 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3550 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3551 if (rc == MBX_NOT_FINISHED) {
3552 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3553 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3555 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3559 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3560 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3563 vport->port_state = LPFC_LOCAL_CFG_LINK;
3564 lpfc_config_link(phba, cfglink_mbox);
3565 cfglink_mbox->vport = vport;
3566 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3567 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3568 if (rc == MBX_NOT_FINISHED) {
3569 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3573 vport->port_state = LPFC_VPORT_UNKNOWN;
3575 * Add the driver's default FCF record at FCF index 0 now. This
3576 * is phase 1 implementation that support FCF index 0 and driver
3579 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3580 fcf_record = kzalloc(sizeof(struct fcf_record),
3582 if (unlikely(!fcf_record)) {
3583 lpfc_printf_log(phba, KERN_ERR,
3585 "2554 Could not allocate memory for "
3591 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3592 LPFC_FCOE_FCF_DEF_INDEX);
3593 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3595 lpfc_printf_log(phba, KERN_ERR,
3597 "2013 Could not manually add FCF "
3598 "record 0, status %d\n", rc);
3606 * The driver is expected to do FIP/FCF. Call the port
3607 * and get the FCF Table.
3609 spin_lock_irqsave(&phba->hbalock, iflags);
3610 if (phba->hba_flag & FCF_TS_INPROG) {
3611 spin_unlock_irqrestore(&phba->hbalock, iflags);
3614 /* This is the initial FCF discovery scan */
3615 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3616 spin_unlock_irqrestore(&phba->hbalock, iflags);
3617 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3618 "2778 Start FCF table scan at linkup\n");
3619 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3620 LPFC_FCOE_FCF_GET_FIRST);
3622 spin_lock_irqsave(&phba->hbalock, iflags);
3623 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3624 spin_unlock_irqrestore(&phba->hbalock, iflags);
3627 /* Reset FCF roundrobin bmask for new discovery */
3628 lpfc_sli4_clear_fcf_rr_bmask(phba);
3631 /* Prepare for LINK up registrations */
3632 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3633 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3634 init_utsname()->nodename);
3637 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3638 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3639 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3640 vport->port_state, sparam_mbox, cfglink_mbox);
3641 lpfc_issue_clear_la(phba, vport);
3646 lpfc_enable_la(struct lpfc_hba *phba)
3649 struct lpfc_sli *psli = &phba->sli;
3650 spin_lock_irq(&phba->hbalock);
3651 psli->sli_flag |= LPFC_PROCESS_LA;
3652 if (phba->sli_rev <= LPFC_SLI_REV3) {
3653 control = readl(phba->HCregaddr);
3654 control |= HC_LAINT_ENA;
3655 writel(control, phba->HCregaddr);
3656 readl(phba->HCregaddr); /* flush */
3658 spin_unlock_irq(&phba->hbalock);
3662 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3664 lpfc_linkdown(phba);
3665 lpfc_enable_la(phba);
3666 lpfc_unregister_unused_fcf(phba);
3667 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3672 * This routine handles processing a READ_TOPOLOGY mailbox
3673 * command upon completion. It is setup in the LPFC_MBOXQ
3674 * as the completion routine when the command is
3675 * handed off to the SLI layer. SLI4 only.
3678 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3680 struct lpfc_vport *vport = pmb->vport;
3681 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3682 struct lpfc_mbx_read_top *la;
3683 struct lpfc_sli_ring *pring;
3684 MAILBOX_t *mb = &pmb->u.mb;
3685 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3687 unsigned long iflags;
3689 /* Unblock ELS traffic */
3690 pring = lpfc_phba_elsring(phba);
3692 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3694 /* Check for error */
3695 if (mb->mbxStatus) {
3696 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3697 "1307 READ_LA mbox error x%x state x%x\n",
3698 mb->mbxStatus, vport->port_state);
3699 lpfc_mbx_issue_link_down(phba);
3700 phba->link_state = LPFC_HBA_ERROR;
3701 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3704 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3705 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3707 memcpy(&phba->alpa_map[0], mp->virt, 128);
3709 spin_lock_irqsave(shost->host_lock, iflags);
3710 if (bf_get(lpfc_mbx_read_top_pb, la))
3711 vport->fc_flag |= FC_BYPASSED_MODE;
3713 vport->fc_flag &= ~FC_BYPASSED_MODE;
3714 spin_unlock_irqrestore(shost->host_lock, iflags);
3716 if (phba->fc_eventTag <= la->eventTag) {
3717 phba->fc_stat.LinkMultiEvent++;
3718 if (attn_type == LPFC_ATT_LINK_UP)
3719 if (phba->fc_eventTag != 0)
3720 lpfc_linkdown(phba);
3723 phba->fc_eventTag = la->eventTag;
3724 if (phba->sli_rev < LPFC_SLI_REV4) {
3725 spin_lock_irqsave(&phba->hbalock, iflags);
3726 if (bf_get(lpfc_mbx_read_top_mm, la))
3727 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3729 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3730 spin_unlock_irqrestore(&phba->hbalock, iflags);
3733 phba->link_events++;
3734 if ((attn_type == LPFC_ATT_LINK_UP) &&
3735 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3736 phba->fc_stat.LinkUp++;
3737 if (phba->link_flag & LS_LOOPBACK_MODE) {
3738 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3739 "1306 Link Up Event in loop back mode "
3740 "x%x received Data: x%x x%x x%x x%x\n",
3741 la->eventTag, phba->fc_eventTag,
3742 bf_get(lpfc_mbx_read_top_alpa_granted,
3744 bf_get(lpfc_mbx_read_top_link_spd, la),
3747 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3748 "1303 Link Up Event x%x received "
3749 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3750 la->eventTag, phba->fc_eventTag,
3751 bf_get(lpfc_mbx_read_top_alpa_granted,
3753 bf_get(lpfc_mbx_read_top_link_spd, la),
3755 bf_get(lpfc_mbx_read_top_mm, la),
3756 bf_get(lpfc_mbx_read_top_fa, la),
3757 phba->wait_4_mlo_maint_flg);
3759 lpfc_mbx_process_link_up(phba, la);
3761 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3762 lpfc_cmf_signal_init(phba);
3764 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3765 attn_type == LPFC_ATT_UNEXP_WWPN) {
3766 phba->fc_stat.LinkDown++;
3767 if (phba->link_flag & LS_LOOPBACK_MODE)
3768 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3769 "1308 Link Down Event in loop back mode "
3771 "Data: x%x x%x x%x\n",
3772 la->eventTag, phba->fc_eventTag,
3773 phba->pport->port_state, vport->fc_flag);
3774 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3775 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3776 "1313 Link Down Unexpected FA WWPN Event x%x "
3777 "received Data: x%x x%x x%x x%x x%x\n",
3778 la->eventTag, phba->fc_eventTag,
3779 phba->pport->port_state, vport->fc_flag,
3780 bf_get(lpfc_mbx_read_top_mm, la),
3781 bf_get(lpfc_mbx_read_top_fa, la));
3783 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3784 "1305 Link Down Event x%x received "
3785 "Data: x%x x%x x%x x%x x%x\n",
3786 la->eventTag, phba->fc_eventTag,
3787 phba->pport->port_state, vport->fc_flag,
3788 bf_get(lpfc_mbx_read_top_mm, la),
3789 bf_get(lpfc_mbx_read_top_fa, la));
3790 lpfc_mbx_issue_link_down(phba);
3792 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3793 attn_type == LPFC_ATT_LINK_UP) {
3794 if (phba->link_state != LPFC_LINK_DOWN) {
3795 phba->fc_stat.LinkDown++;
3796 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3797 "1312 Link Down Event x%x received "
3798 "Data: x%x x%x x%x\n",
3799 la->eventTag, phba->fc_eventTag,
3800 phba->pport->port_state, vport->fc_flag);
3801 lpfc_mbx_issue_link_down(phba);
3803 lpfc_enable_la(phba);
3805 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3806 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3807 "Data: x%x x%x x%x\n",
3808 la->eventTag, phba->fc_eventTag,
3809 phba->pport->port_state, vport->fc_flag);
3811 * The cmnd that triggered this will be waiting for this
3814 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3815 if (phba->wait_4_mlo_maint_flg) {
3816 phba->wait_4_mlo_maint_flg = 0;
3817 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3821 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3822 bf_get(lpfc_mbx_read_top_fa, la)) {
3823 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3824 lpfc_issue_clear_la(phba, vport);
3825 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3827 bf_get(lpfc_mbx_read_top_fa, la));
3830 lpfc_mbx_cmpl_read_topology_free_mbuf:
3831 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3833 mempool_free(pmb, phba->mbox_mem_pool);
3838 * This routine handles processing a REG_LOGIN mailbox
3839 * command upon completion. It is setup in the LPFC_MBOXQ
3840 * as the completion routine when the command is
3841 * handed off to the SLI layer.
3844 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3846 struct lpfc_vport *vport = pmb->vport;
3847 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3848 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3850 pmb->ctx_buf = NULL;
3851 pmb->ctx_ndlp = NULL;
3853 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3854 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3855 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3856 kref_read(&ndlp->kref),
3858 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3859 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3861 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3862 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3863 /* We rcvd a rscn after issuing this
3864 * mbox reg login, we may have cycled
3865 * back through the state and be
3866 * back at reg login state so this
3867 * mbox needs to be ignored becase
3868 * there is another reg login in
3871 spin_lock_irq(&ndlp->lock);
3872 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3873 spin_unlock_irq(&ndlp->lock);
3876 * We cannot leave the RPI registered because
3877 * if we go thru discovery again for this ndlp
3878 * a subsequent REG_RPI will fail.
3880 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3881 lpfc_unreg_rpi(vport, ndlp);
3884 /* Call state machine */
3885 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3887 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3889 mempool_free(pmb, phba->mbox_mem_pool);
3890 /* decrement the node reference count held for this callback
3899 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3901 MAILBOX_t *mb = &pmb->u.mb;
3902 struct lpfc_vport *vport = pmb->vport;
3903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3905 switch (mb->mbxStatus) {
3908 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3909 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3912 /* If VPI is busy, reset the HBA */
3914 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3915 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3916 vport->vpi, mb->mbxStatus);
3917 if (!(phba->pport->load_flag & FC_UNLOADING))
3918 lpfc_workq_post_event(phba, NULL, NULL,
3919 LPFC_EVT_RESET_HBA);
3921 spin_lock_irq(shost->host_lock);
3922 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3923 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3924 spin_unlock_irq(shost->host_lock);
3925 vport->unreg_vpi_cmpl = VPORT_OK;
3926 mempool_free(pmb, phba->mbox_mem_pool);
3927 lpfc_cleanup_vports_rrqs(vport, NULL);
3929 * This shost reference might have been taken at the beginning of
3930 * lpfc_vport_delete()
3932 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3933 scsi_host_put(shost);
3937 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3939 struct lpfc_hba *phba = vport->phba;
3943 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3947 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3948 mbox->vport = vport;
3949 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3950 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3951 if (rc == MBX_NOT_FINISHED) {
3952 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3953 "1800 Could not issue unreg_vpi\n");
3954 mempool_free(mbox, phba->mbox_mem_pool);
3955 vport->unreg_vpi_cmpl = VPORT_ERROR;
3962 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3964 struct lpfc_vport *vport = pmb->vport;
3965 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3966 MAILBOX_t *mb = &pmb->u.mb;
3968 switch (mb->mbxStatus) {
3972 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3973 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3975 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3976 spin_lock_irq(shost->host_lock);
3977 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3978 spin_unlock_irq(shost->host_lock);
3979 vport->fc_myDID = 0;
3981 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3982 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3983 if (phba->nvmet_support)
3984 lpfc_nvmet_update_targetport(phba);
3986 lpfc_nvme_update_localport(vport);
3991 spin_lock_irq(shost->host_lock);
3992 vport->vpi_state |= LPFC_VPI_REGISTERED;
3993 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3994 spin_unlock_irq(shost->host_lock);
3995 vport->num_disc_nodes = 0;
3996 /* go thru NPR list and issue ELS PLOGIs */
3997 if (vport->fc_npr_cnt)
3998 lpfc_els_disc_plogi(vport);
4000 if (!vport->num_disc_nodes) {
4001 spin_lock_irq(shost->host_lock);
4002 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4003 spin_unlock_irq(shost->host_lock);
4004 lpfc_can_disctmo(vport);
4006 vport->port_state = LPFC_VPORT_READY;
4009 mempool_free(pmb, phba->mbox_mem_pool);
4014 * lpfc_create_static_vport - Read HBA config region to create static vports.
4015 * @phba: pointer to lpfc hba data structure.
4017 * This routine issue a DUMP mailbox command for config region 22 to get
4018 * the list of static vports to be created. The function create vports
4019 * based on the information returned from the HBA.
4022 lpfc_create_static_vport(struct lpfc_hba *phba)
4024 LPFC_MBOXQ_t *pmb = NULL;
4026 struct static_vport_info *vport_info;
4027 int mbx_wait_rc = 0, i;
4028 struct fc_vport_identifiers vport_id;
4029 struct fc_vport *new_fc_vport;
4030 struct Scsi_Host *shost;
4031 struct lpfc_vport *vport;
4032 uint16_t offset = 0;
4033 uint8_t *vport_buff;
4034 struct lpfc_dmabuf *mp;
4035 uint32_t byte_count = 0;
4037 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4039 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4040 "0542 lpfc_create_static_vport failed to"
4041 " allocate mailbox memory\n");
4044 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4047 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
4049 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4050 "0543 lpfc_create_static_vport failed to"
4051 " allocate vport_info\n");
4052 mempool_free(pmb, phba->mbox_mem_pool);
4056 vport_buff = (uint8_t *) vport_info;
4058 /* free dma buffer from previous round */
4060 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4061 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4064 if (lpfc_dump_static_vport(phba, pmb, offset))
4067 pmb->vport = phba->pport;
4068 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
4071 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
4072 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4073 "0544 lpfc_create_static_vport failed to"
4074 " issue dump mailbox command ret 0x%x "
4076 mbx_wait_rc, mb->mbxStatus);
4080 if (phba->sli_rev == LPFC_SLI_REV4) {
4081 byte_count = pmb->u.mqe.un.mb_words[5];
4082 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4083 if (byte_count > sizeof(struct static_vport_info) -
4085 byte_count = sizeof(struct static_vport_info)
4087 memcpy(vport_buff + offset, mp->virt, byte_count);
4088 offset += byte_count;
4090 if (mb->un.varDmp.word_cnt >
4091 sizeof(struct static_vport_info) - offset)
4092 mb->un.varDmp.word_cnt =
4093 sizeof(struct static_vport_info)
4095 byte_count = mb->un.varDmp.word_cnt;
4096 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
4097 vport_buff + offset,
4100 offset += byte_count;
4103 } while (byte_count &&
4104 offset < sizeof(struct static_vport_info));
4107 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
4108 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
4109 != VPORT_INFO_REV)) {
4110 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4111 "0545 lpfc_create_static_vport bad"
4112 " information header 0x%x 0x%x\n",
4113 le32_to_cpu(vport_info->signature),
4114 le32_to_cpu(vport_info->rev) &
4115 VPORT_INFO_REV_MASK);
4120 shost = lpfc_shost_from_vport(phba->pport);
4122 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4123 memset(&vport_id, 0, sizeof(vport_id));
4124 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4125 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4126 if (!vport_id.port_name || !vport_id.node_name)
4129 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4130 vport_id.vport_type = FC_PORTTYPE_NPIV;
4131 vport_id.disable = false;
4132 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4134 if (!new_fc_vport) {
4135 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4136 "0546 lpfc_create_static_vport failed to"
4141 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4142 vport->vport_flag |= STATIC_VPORT;
4147 if (mbx_wait_rc != MBX_TIMEOUT) {
4149 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4150 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4153 mempool_free(pmb, phba->mbox_mem_pool);
4160 * This routine handles processing a Fabric REG_LOGIN mailbox
4161 * command upon completion. It is setup in the LPFC_MBOXQ
4162 * as the completion routine when the command is
4163 * handed off to the SLI layer.
4166 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4168 struct lpfc_vport *vport = pmb->vport;
4169 MAILBOX_t *mb = &pmb->u.mb;
4170 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4171 struct lpfc_nodelist *ndlp;
4172 struct Scsi_Host *shost;
4174 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4175 pmb->ctx_ndlp = NULL;
4176 pmb->ctx_buf = NULL;
4178 if (mb->mbxStatus) {
4179 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4180 "0258 Register Fabric login error: 0x%x\n",
4182 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4184 mempool_free(pmb, phba->mbox_mem_pool);
4186 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4187 /* FLOGI failed, use loop map to make discovery list */
4188 lpfc_disc_list_loopmap(vport);
4190 /* Start discovery */
4191 lpfc_disc_start(vport);
4192 /* Decrement the reference count to ndlp after the
4193 * reference to the ndlp are done.
4199 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4200 /* Decrement the reference count to ndlp after the reference
4201 * to the ndlp are done.
4207 if (phba->sli_rev < LPFC_SLI_REV4)
4208 ndlp->nlp_rpi = mb->un.varWords[0];
4209 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4210 ndlp->nlp_type |= NLP_FABRIC;
4211 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4213 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4214 /* when physical port receive logo donot start
4215 * vport discovery */
4216 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4217 lpfc_start_fdiscs(phba);
4219 shost = lpfc_shost_from_vport(vport);
4220 spin_lock_irq(shost->host_lock);
4221 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4222 spin_unlock_irq(shost->host_lock);
4224 lpfc_do_scr_ns_plogi(phba, vport);
4227 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4229 mempool_free(pmb, phba->mbox_mem_pool);
4231 /* Drop the reference count from the mbox at the end after
4232 * all the current reference to the ndlp have been done.
4239 * This routine will issue a GID_FT for each FC4 Type supported
4240 * by the driver. ALL GID_FTs must complete before discovery is started.
4243 lpfc_issue_gidft(struct lpfc_vport *vport)
4245 /* Good status, issue CT Request to NameServer */
4246 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4247 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4248 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4249 /* Cannot issue NameServer FCP Query, so finish up
4252 lpfc_printf_vlog(vport, KERN_ERR,
4254 "0604 %s FC TYPE %x %s\n",
4255 "Failed to issue GID_FT to ",
4257 "Finishing discovery.");
4263 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4264 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4265 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4266 /* Cannot issue NameServer NVME Query, so finish up
4269 lpfc_printf_vlog(vport, KERN_ERR,
4271 "0605 %s FC_TYPE %x %s %d\n",
4272 "Failed to issue GID_FT to ",
4274 "Finishing discovery: gidftinp ",
4276 if (vport->gidft_inp == 0)
4281 return vport->gidft_inp;
4285 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4286 * @vport: The virtual port for which this call is being executed.
4288 * This routine will issue a GID_PT to get a list of all N_Ports
4291 * 0 - Failure to issue a GID_PT
4295 lpfc_issue_gidpt(struct lpfc_vport *vport)
4297 /* Good status, issue CT Request to NameServer */
4298 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4299 /* Cannot issue NameServer FCP Query, so finish up
4302 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4303 "0606 %s Port TYPE %x %s\n",
4304 "Failed to issue GID_PT to ",
4306 "Finishing discovery.");
4314 * This routine handles processing a NameServer REG_LOGIN mailbox
4315 * command upon completion. It is setup in the LPFC_MBOXQ
4316 * as the completion routine when the command is
4317 * handed off to the SLI layer.
4320 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4322 MAILBOX_t *mb = &pmb->u.mb;
4323 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4324 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4325 struct lpfc_vport *vport = pmb->vport;
4328 pmb->ctx_buf = NULL;
4329 pmb->ctx_ndlp = NULL;
4330 vport->gidft_inp = 0;
4332 if (mb->mbxStatus) {
4333 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4334 "0260 Register NameServer error: 0x%x\n",
4338 /* decrement the node reference count held for this
4339 * callback function.
4342 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4344 mempool_free(pmb, phba->mbox_mem_pool);
4346 /* If the node is not registered with the scsi or nvme
4347 * transport, remove the fabric node. The failed reg_login
4350 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4351 spin_lock_irq(&ndlp->lock);
4352 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4353 spin_unlock_irq(&ndlp->lock);
4354 lpfc_nlp_not_used(ndlp);
4357 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4359 * RegLogin failed, use loop map to make discovery
4362 lpfc_disc_list_loopmap(vport);
4364 /* Start discovery */
4365 lpfc_disc_start(vport);
4368 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4372 if (phba->sli_rev < LPFC_SLI_REV4)
4373 ndlp->nlp_rpi = mb->un.varWords[0];
4374 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4375 ndlp->nlp_type |= NLP_FABRIC;
4376 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4377 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4378 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4379 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4380 kref_read(&ndlp->kref),
4383 if (vport->port_state < LPFC_VPORT_READY) {
4384 /* Link up discovery requires Fabric registration. */
4385 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4386 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4387 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4388 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4390 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4391 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4392 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4394 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4395 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4396 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4399 /* Issue SCR just before NameServer GID_FT Query */
4400 lpfc_issue_els_scr(vport, 0);
4402 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4403 * with initial FW values provided the congestion mode is
4404 * not off. Note that signals may or may not be supported
4405 * by the adapter but FPIN is provided by default for 1
4406 * or both missing signals support.
4408 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4409 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4410 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4411 rc = lpfc_issue_els_edc(vport, 0);
4412 lpfc_printf_log(phba, KERN_INFO,
4413 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4414 "4220 EDC issue error x%x, Data: x%x\n",
4415 rc, phba->cgn_init_reg_signal);
4417 lpfc_issue_els_rdf(vport, 0);
4421 vport->fc_ns_retry = 0;
4422 if (lpfc_issue_gidft(vport) == 0)
4426 * At this point in time we may need to wait for multiple
4427 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4429 * decrement the node reference count held for this
4430 * callback function.
4433 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4435 mempool_free(pmb, phba->mbox_mem_pool);
4441 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4442 * command upon completion. It is setup in the LPFC_MBOXQ
4443 * as the completion routine when the command is handed off to the SLI layer.
4446 lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4448 struct lpfc_vport *vport = pmb->vport;
4449 MAILBOX_t *mb = &pmb->u.mb;
4450 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4451 struct lpfc_nodelist *ndlp;
4453 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4454 pmb->ctx_ndlp = NULL;
4455 pmb->ctx_buf = NULL;
4457 if (mb->mbxStatus) {
4458 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4459 "0933 %s: Register FC login error: 0x%x\n",
4460 __func__, mb->mbxStatus);
4464 lpfc_check_nlp_post_devloss(vport, ndlp);
4466 if (phba->sli_rev < LPFC_SLI_REV4)
4467 ndlp->nlp_rpi = mb->un.varWords[0];
4469 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4470 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4471 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4474 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4475 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4476 ndlp->nlp_type |= NLP_FABRIC;
4477 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4480 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4482 mempool_free(pmb, phba->mbox_mem_pool);
4484 /* Drop the reference count from the mbox at the end after
4485 * all the current reference to the ndlp have been done.
4491 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4494 struct fc_rport *rport;
4495 struct lpfc_rport_data *rdata;
4496 struct fc_rport_identifiers rport_ids;
4497 struct lpfc_hba *phba = vport->phba;
4498 unsigned long flags;
4500 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4503 /* Remote port has reappeared. Re-register w/ FC transport */
4504 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4505 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4506 rport_ids.port_id = ndlp->nlp_DID;
4507 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4510 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4511 "rport add: did:x%x flg:x%x type x%x",
4512 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4514 /* Don't add the remote port if unloading. */
4515 if (vport->load_flag & FC_UNLOADING)
4519 * Disassociate any older association between this ndlp and rport
4522 rdata = ndlp->rport->dd_data;
4523 rdata->pnode = NULL;
4526 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4528 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4529 "Warning: fc_remote_port_add failed\n");
4533 /* Successful port add. Complete initializing node data */
4534 rport->maxframe_size = ndlp->nlp_maxframe;
4535 rport->supported_classes = ndlp->nlp_class_sup;
4536 rdata = rport->dd_data;
4537 rdata->pnode = lpfc_nlp_get(ndlp);
4538 if (!rdata->pnode) {
4539 dev_warn(&phba->pcidev->dev,
4540 "Warning - node ref failed. Unreg rport\n");
4541 fc_remote_port_delete(rport);
4546 spin_lock_irqsave(&ndlp->lock, flags);
4547 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4548 spin_unlock_irqrestore(&ndlp->lock, flags);
4550 if (ndlp->nlp_type & NLP_FCP_TARGET)
4551 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4552 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4553 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4554 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4555 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4556 if (ndlp->nlp_type & NLP_NVME_TARGET)
4557 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4558 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4559 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4561 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4562 fc_remote_port_rolechg(rport, rport_ids.roles);
4564 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4565 "3183 %s rport x%px DID x%x, role x%x refcnt %d\n",
4566 __func__, rport, rport->port_id, rport->roles,
4567 kref_read(&ndlp->kref));
4569 if ((rport->scsi_target_id != -1) &&
4570 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4571 ndlp->nlp_sid = rport->scsi_target_id;
4578 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4580 struct fc_rport *rport = ndlp->rport;
4581 struct lpfc_vport *vport = ndlp->vport;
4583 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4587 "rport delete: did:x%x flg:x%x type x%x",
4588 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4590 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4591 "3184 rport unregister x%06x, rport x%px "
4592 "xptflg x%x refcnt %d\n",
4593 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags,
4594 kref_read(&ndlp->kref));
4596 fc_remote_port_delete(rport);
4601 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4604 unsigned long iflags;
4606 spin_lock_irqsave(shost->host_lock, iflags);
4608 case NLP_STE_UNUSED_NODE:
4609 vport->fc_unused_cnt += count;
4611 case NLP_STE_PLOGI_ISSUE:
4612 vport->fc_plogi_cnt += count;
4614 case NLP_STE_ADISC_ISSUE:
4615 vport->fc_adisc_cnt += count;
4617 case NLP_STE_REG_LOGIN_ISSUE:
4618 vport->fc_reglogin_cnt += count;
4620 case NLP_STE_PRLI_ISSUE:
4621 vport->fc_prli_cnt += count;
4623 case NLP_STE_UNMAPPED_NODE:
4624 vport->fc_unmap_cnt += count;
4626 case NLP_STE_MAPPED_NODE:
4627 vport->fc_map_cnt += count;
4629 case NLP_STE_NPR_NODE:
4630 if (vport->fc_npr_cnt == 0 && count == -1)
4631 vport->fc_npr_cnt = 0;
4633 vport->fc_npr_cnt += count;
4636 spin_unlock_irqrestore(shost->host_lock, iflags);
4639 /* Register a node with backend if not already done */
4641 lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4643 unsigned long iflags;
4645 lpfc_check_nlp_post_devloss(vport, ndlp);
4647 spin_lock_irqsave(&ndlp->lock, iflags);
4648 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4649 /* Already registered with backend, trigger rescan */
4650 spin_unlock_irqrestore(&ndlp->lock, iflags);
4652 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4653 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4654 lpfc_nvme_rescan_port(vport, ndlp);
4659 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4660 spin_unlock_irqrestore(&ndlp->lock, iflags);
4662 if (lpfc_valid_xpt_node(ndlp)) {
4663 vport->phba->nport_event_cnt++;
4665 * Tell the fc transport about the port, if we haven't
4666 * already. If we have, and it's a scsi entity, be
4668 lpfc_register_remote_port(vport, ndlp);
4671 /* We are done if we do not have any NVME remote node */
4672 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4675 /* Notify the NVME transport of this new rport. */
4676 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4677 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4678 if (vport->phba->nvmet_support == 0) {
4679 /* Register this rport with the transport.
4680 * Only NVME Target Rports are registered with
4683 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4684 vport->phba->nport_event_cnt++;
4685 lpfc_nvme_register_port(vport, ndlp);
4688 /* Just take an NDLP ref count since the
4689 * target does not register rports.
4696 /* Unregister a node with backend if not already done */
4698 lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4700 unsigned long iflags;
4702 spin_lock_irqsave(&ndlp->lock, iflags);
4703 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4704 spin_unlock_irqrestore(&ndlp->lock, iflags);
4708 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4709 spin_unlock_irqrestore(&ndlp->lock, iflags);
4712 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4713 vport->phba->nport_event_cnt++;
4714 lpfc_unregister_remote_port(ndlp);
4717 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4718 vport->phba->nport_event_cnt++;
4719 if (vport->phba->nvmet_support == 0) {
4720 /* Start devloss if target. */
4721 if (ndlp->nlp_type & NLP_NVME_TARGET)
4722 lpfc_nvme_unregister_port(vport, ndlp);
4724 /* NVMET has no upcall. */
4732 * Adisc state change handling
4735 lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4738 switch (new_state) {
4740 * Any state to ADISC_ISSUE
4741 * Do nothing, adisc cmpl handling will trigger state changes
4743 case NLP_STE_ADISC_ISSUE:
4747 * ADISC_ISSUE to mapped states
4748 * Trigger a registration with backend, it will be nop if
4749 * already registered
4751 case NLP_STE_UNMAPPED_NODE:
4752 ndlp->nlp_type |= NLP_FC_NODE;
4754 case NLP_STE_MAPPED_NODE:
4755 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4756 lpfc_nlp_reg_node(vport, ndlp);
4760 * ADISC_ISSUE to non-mapped states
4761 * We are moving from ADISC_ISSUE to a non-mapped state because
4762 * ADISC failed, we would have skipped unregistering with
4763 * backend, attempt it now
4765 case NLP_STE_NPR_NODE:
4766 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4769 lpfc_nlp_unreg_node(vport, ndlp);
4776 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4777 int old_state, int new_state)
4779 /* Trap ADISC changes here */
4780 if (new_state == NLP_STE_ADISC_ISSUE ||
4781 old_state == NLP_STE_ADISC_ISSUE) {
4782 lpfc_handle_adisc_state(vport, ndlp, new_state);
4786 if (new_state == NLP_STE_UNMAPPED_NODE) {
4787 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4788 ndlp->nlp_type |= NLP_FC_NODE;
4790 if (new_state == NLP_STE_MAPPED_NODE)
4791 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4792 if (new_state == NLP_STE_NPR_NODE)
4793 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4795 /* Reg/Unreg for FCP and NVME Transport interface */
4796 if ((old_state == NLP_STE_MAPPED_NODE ||
4797 old_state == NLP_STE_UNMAPPED_NODE)) {
4798 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl */
4799 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
4800 lpfc_nlp_unreg_node(vport, ndlp);
4803 if (new_state == NLP_STE_MAPPED_NODE ||
4804 new_state == NLP_STE_UNMAPPED_NODE)
4805 lpfc_nlp_reg_node(vport, ndlp);
4807 if ((new_state == NLP_STE_MAPPED_NODE) &&
4808 (vport->stat_data_enabled)) {
4810 * A new target is discovered, if there is no buffer for
4811 * statistical data collection allocate buffer.
4813 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4814 sizeof(struct lpfc_scsicmd_bkt),
4817 if (!ndlp->lat_data)
4818 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4819 "0286 lpfc_nlp_state_cleanup failed to "
4820 "allocate statistical data buffer DID "
4821 "0x%x\n", ndlp->nlp_DID);
4824 * If the node just added to Mapped list was an FCP target,
4825 * but the remote port registration failed or assigned a target
4826 * id outside the presentable range - move the node to the
4829 if ((new_state == NLP_STE_MAPPED_NODE) &&
4830 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4832 ndlp->rport->scsi_target_id == -1 ||
4833 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4834 spin_lock_irq(&ndlp->lock);
4835 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4836 spin_unlock_irq(&ndlp->lock);
4837 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4842 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4844 static char *states[] = {
4845 [NLP_STE_UNUSED_NODE] = "UNUSED",
4846 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4847 [NLP_STE_ADISC_ISSUE] = "ADISC",
4848 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4849 [NLP_STE_PRLI_ISSUE] = "PRLI",
4850 [NLP_STE_LOGO_ISSUE] = "LOGO",
4851 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4852 [NLP_STE_MAPPED_NODE] = "MAPPED",
4853 [NLP_STE_NPR_NODE] = "NPR",
4856 if (state < NLP_STE_MAX_STATE && states[state])
4857 strlcpy(buffer, states[state], size);
4859 snprintf(buffer, size, "unknown (%d)", state);
4864 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4867 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4868 int old_state = ndlp->nlp_state;
4869 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4870 char name1[16], name2[16];
4872 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4873 "0904 NPort state transition x%06x, %s -> %s\n",
4875 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4876 lpfc_nlp_state_name(name2, sizeof(name2), state));
4878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4879 "node statechg did:x%x old:%d ste:%d",
4880 ndlp->nlp_DID, old_state, state);
4882 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4883 state != NLP_STE_UNUSED_NODE) {
4884 ndlp->nlp_flag &= ~NLP_DROPPED;
4888 if (old_state == NLP_STE_NPR_NODE &&
4889 state != NLP_STE_NPR_NODE)
4890 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4891 if (old_state == NLP_STE_UNMAPPED_NODE) {
4892 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4893 ndlp->nlp_type &= ~NLP_FC_NODE;
4896 if (list_empty(&ndlp->nlp_listp)) {
4897 spin_lock_irq(shost->host_lock);
4898 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4899 spin_unlock_irq(shost->host_lock);
4900 } else if (old_state)
4901 lpfc_nlp_counters(vport, old_state, -1);
4903 ndlp->nlp_state = state;
4904 lpfc_nlp_counters(vport, state, 1);
4905 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4909 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4913 if (list_empty(&ndlp->nlp_listp)) {
4914 spin_lock_irq(shost->host_lock);
4915 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4916 spin_unlock_irq(shost->host_lock);
4921 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4923 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4925 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4926 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4927 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4928 spin_lock_irq(shost->host_lock);
4929 list_del_init(&ndlp->nlp_listp);
4930 spin_unlock_irq(shost->host_lock);
4931 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4932 NLP_STE_UNUSED_NODE);
4936 * lpfc_initialize_node - Initialize all fields of node object
4937 * @vport: Pointer to Virtual Port object.
4938 * @ndlp: Pointer to FC node object.
4939 * @did: FC_ID of the node.
4941 * This function is always called when node object need to be initialized.
4942 * It initializes all the fields of the node object. Although the reference
4943 * to phba from @ndlp can be obtained indirectly through it's reference to
4944 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4945 * to the life-span of the @ndlp might go beyond the existence of @vport as
4946 * the final release of ndlp is determined by its reference count. And, the
4947 * operation on @ndlp needs the reference to phba.
4950 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4953 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4954 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4955 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4956 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4958 ndlp->nlp_DID = did;
4959 ndlp->vport = vport;
4960 ndlp->phba = vport->phba;
4961 ndlp->nlp_sid = NLP_NO_SID;
4962 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4963 kref_init(&ndlp->kref);
4964 atomic_set(&ndlp->cmd_pending, 0);
4965 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4966 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4970 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4973 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4974 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4975 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4976 * until ALL other outstanding threads have completed. We check
4977 * that the ndlp not already in the UNUSED state before we proceed.
4979 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4981 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4982 ndlp->nlp_flag |= NLP_DROPPED;
4983 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4984 lpfc_cleanup_vports_rrqs(vport, ndlp);
4985 lpfc_unreg_rpi(vport, ndlp);
4993 * Start / ReStart rescue timer for Discovery / RSCN handling
4996 lpfc_set_disctmo(struct lpfc_vport *vport)
4998 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4999 struct lpfc_hba *phba = vport->phba;
5002 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
5003 /* For FAN, timeout should be greater than edtov */
5004 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
5006 /* Normal discovery timeout should be > than ELS/CT timeout
5007 * FC spec states we need 3 * ratov for CT requests
5009 tmo = ((phba->fc_ratov * 3) + 3);
5013 if (!timer_pending(&vport->fc_disctmo)) {
5014 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5015 "set disc timer: tmo:x%x state:x%x flg:x%x",
5016 tmo, vport->port_state, vport->fc_flag);
5019 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
5020 spin_lock_irq(shost->host_lock);
5021 vport->fc_flag |= FC_DISC_TMO;
5022 spin_unlock_irq(shost->host_lock);
5024 /* Start Discovery Timer state <hba_state> */
5025 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5026 "0247 Start Discovery Timer state x%x "
5027 "Data: x%x x%lx x%x x%x\n",
5028 vport->port_state, tmo,
5029 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5030 vport->fc_adisc_cnt);
5036 * Cancel rescue timer for Discovery / RSCN handling
5039 lpfc_can_disctmo(struct lpfc_vport *vport)
5041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5042 unsigned long iflags;
5044 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5045 "can disc timer: state:x%x rtry:x%x flg:x%x",
5046 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5048 /* Turn off discovery timer if its running */
5049 if (vport->fc_flag & FC_DISC_TMO) {
5050 spin_lock_irqsave(shost->host_lock, iflags);
5051 vport->fc_flag &= ~FC_DISC_TMO;
5052 spin_unlock_irqrestore(shost->host_lock, iflags);
5053 del_timer_sync(&vport->fc_disctmo);
5054 spin_lock_irqsave(&vport->work_port_lock, iflags);
5055 vport->work_port_events &= ~WORKER_DISC_TMO;
5056 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
5059 /* Cancel Discovery Timer state <hba_state> */
5060 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5061 "0248 Cancel Discovery Timer state x%x "
5062 "Data: x%x x%x x%x\n",
5063 vport->port_state, vport->fc_flag,
5064 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
5069 * Check specified ring for outstanding IOCB on the SLI queue
5070 * Return true if iocb matches the specified nport
5073 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
5074 struct lpfc_sli_ring *pring,
5075 struct lpfc_iocbq *iocb,
5076 struct lpfc_nodelist *ndlp)
5078 IOCB_t *icmd = &iocb->iocb;
5079 struct lpfc_vport *vport = ndlp->vport;
5081 if (iocb->vport != vport)
5084 if (pring->ringno == LPFC_ELS_RING) {
5085 switch (icmd->ulpCommand) {
5086 case CMD_GEN_REQUEST64_CR:
5087 if (iocb->context_un.ndlp == ndlp)
5090 case CMD_ELS_REQUEST64_CR:
5091 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
5094 case CMD_XMIT_ELS_RSP64_CX:
5095 if (iocb->context1 == (uint8_t *) ndlp)
5098 } else if (pring->ringno == LPFC_FCP_RING) {
5099 /* Skip match check if waiting to relogin to FCP target */
5100 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5101 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
5104 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
5112 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
5113 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
5114 struct list_head *dequeue_list)
5116 struct lpfc_iocbq *iocb, *next_iocb;
5118 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5119 /* Check to see if iocb matches the nport */
5120 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5121 /* match, dequeue */
5122 list_move_tail(&iocb->list, dequeue_list);
5127 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5128 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5130 struct lpfc_sli *psli = &phba->sli;
5133 spin_lock_irq(&phba->hbalock);
5134 for (i = 0; i < psli->num_rings; i++)
5135 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5137 spin_unlock_irq(&phba->hbalock);
5141 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5142 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5144 struct lpfc_sli_ring *pring;
5145 struct lpfc_queue *qp = NULL;
5147 spin_lock_irq(&phba->hbalock);
5148 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5152 spin_lock(&pring->ring_lock);
5153 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5154 spin_unlock(&pring->ring_lock);
5156 spin_unlock_irq(&phba->hbalock);
5160 * Free resources / clean up outstanding I/Os
5161 * associated with nlp_rpi in the LPFC_NODELIST entry.
5164 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5166 LIST_HEAD(completions);
5168 lpfc_fabric_abort_nport(ndlp);
5171 * Everything that matches on txcmplq will be returned
5172 * by firmware with a no rpi error.
5174 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5175 if (phba->sli_rev != LPFC_SLI_REV4)
5176 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5178 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5181 /* Cancel all the IOCBs from the completions list */
5182 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5189 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5190 * @phba: Pointer to HBA context object.
5191 * @pmb: Pointer to mailbox object.
5193 * This function will issue an ELS LOGO command after completing
5197 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5199 struct lpfc_vport *vport = pmb->vport;
5200 struct lpfc_nodelist *ndlp;
5202 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5205 lpfc_issue_els_logo(vport, ndlp, 0);
5206 mempool_free(pmb, phba->mbox_mem_pool);
5208 /* Check to see if there are any deferred events to process */
5209 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5210 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5211 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5212 "1434 UNREG cmpl deferred logo x%x "
5213 "on NPort x%x Data: x%x x%px\n",
5214 ndlp->nlp_rpi, ndlp->nlp_DID,
5215 ndlp->nlp_defer_did, ndlp);
5217 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5218 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5219 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5221 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
5222 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5223 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5224 spin_lock_irq(&ndlp->lock);
5225 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5226 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5227 spin_unlock_irq(&ndlp->lock);
5229 spin_lock_irq(&ndlp->lock);
5230 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5231 spin_unlock_irq(&ndlp->lock);
5236 * Sets the mailbox completion handler to be used for the
5237 * unreg_rpi command. The handler varies based on the state of
5238 * the port and what will be happening to the rpi next.
5241 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5242 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5244 unsigned long iflags;
5246 /* Driver always gets a reference on the mailbox job
5247 * in support of async jobs.
5249 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5250 if (!mbox->ctx_ndlp)
5253 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5254 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5256 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5257 (!(vport->load_flag & FC_UNLOADING)) &&
5258 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5259 LPFC_SLI_INTF_IF_TYPE_2) &&
5260 (kref_read(&ndlp->kref) > 0)) {
5261 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5263 if (vport->load_flag & FC_UNLOADING) {
5264 if (phba->sli_rev == LPFC_SLI_REV4) {
5265 spin_lock_irqsave(&ndlp->lock, iflags);
5266 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5267 spin_unlock_irqrestore(&ndlp->lock, iflags);
5270 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5275 * Free rpi associated with LPFC_NODELIST entry.
5276 * This routine is called from lpfc_freenode(), when we are removing
5277 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5278 * LOGO that completes successfully, and we are waiting to PLOGI back
5279 * to the remote NPort. In addition, it is called after we receive
5280 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5281 * we are waiting to PLOGI back to the remote NPort.
5284 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5286 struct lpfc_hba *phba = vport->phba;
5288 int rc, acc_plogi = 1;
5291 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5292 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5293 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5294 lpfc_printf_vlog(vport, KERN_INFO,
5295 LOG_NODE | LOG_DISCOVERY,
5296 "3366 RPI x%x needs to be "
5297 "unregistered nlp_flag x%x "
5299 ndlp->nlp_rpi, ndlp->nlp_flag,
5302 /* If there is already an UNREG in progress for this ndlp,
5303 * no need to queue up another one.
5305 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5306 lpfc_printf_vlog(vport, KERN_INFO,
5307 LOG_NODE | LOG_DISCOVERY,
5308 "1436 unreg_rpi SKIP UNREG x%x on "
5309 "NPort x%x deferred x%x flg x%x "
5311 ndlp->nlp_rpi, ndlp->nlp_DID,
5312 ndlp->nlp_defer_did,
5313 ndlp->nlp_flag, ndlp);
5317 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5319 /* SLI4 ports require the physical rpi value. */
5320 rpi = ndlp->nlp_rpi;
5321 if (phba->sli_rev == LPFC_SLI_REV4)
5322 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5324 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5325 mbox->vport = vport;
5326 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5327 if (!mbox->ctx_ndlp) {
5328 mempool_free(mbox, phba->mbox_mem_pool);
5332 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5334 * accept PLOGIs after unreg_rpi_cmpl
5337 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5339 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5340 ndlp->nlp_flag |= NLP_UNREG_INP;
5342 lpfc_printf_vlog(vport, KERN_INFO,
5343 LOG_NODE | LOG_DISCOVERY,
5344 "1433 unreg_rpi UNREG x%x on "
5345 "NPort x%x deferred flg x%x "
5347 ndlp->nlp_rpi, ndlp->nlp_DID,
5348 ndlp->nlp_flag, ndlp);
5350 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5351 if (rc == MBX_NOT_FINISHED) {
5352 mempool_free(mbox, phba->mbox_mem_pool);
5356 lpfc_printf_vlog(vport, KERN_INFO,
5357 LOG_NODE | LOG_DISCOVERY,
5358 "1444 Failed to allocate mempool "
5359 "unreg_rpi UNREG x%x, "
5360 "DID x%x, flag x%x, "
5362 ndlp->nlp_rpi, ndlp->nlp_DID,
5363 ndlp->nlp_flag, ndlp);
5365 /* Because mempool_alloc failed, we
5366 * will issue a LOGO here and keep the rpi alive if
5369 if (!(vport->load_flag & FC_UNLOADING)) {
5370 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5371 lpfc_issue_els_logo(vport, ndlp, 0);
5372 ndlp->nlp_prev_state = ndlp->nlp_state;
5373 lpfc_nlp_set_state(vport, ndlp,
5379 lpfc_no_rpi(phba, ndlp);
5381 if (phba->sli_rev != LPFC_SLI_REV4)
5383 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5384 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5386 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5389 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5394 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5395 * @phba: pointer to lpfc hba data structure.
5397 * This routine is invoked to unregister all the currently registered RPIs
5401 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5403 struct lpfc_vport **vports;
5404 struct lpfc_nodelist *ndlp;
5405 struct Scsi_Host *shost;
5408 vports = lpfc_create_vport_work_array(phba);
5410 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5411 "2884 Vport array allocation failed \n");
5414 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5415 shost = lpfc_shost_from_vport(vports[i]);
5416 spin_lock_irq(shost->host_lock);
5417 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5418 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5419 /* The mempool_alloc might sleep */
5420 spin_unlock_irq(shost->host_lock);
5421 lpfc_unreg_rpi(vports[i], ndlp);
5422 spin_lock_irq(shost->host_lock);
5425 spin_unlock_irq(shost->host_lock);
5427 lpfc_destroy_vport_work_array(phba, vports);
5431 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5433 struct lpfc_hba *phba = vport->phba;
5437 if (phba->sli_rev == LPFC_SLI_REV4) {
5438 lpfc_sli4_unreg_all_rpis(vport);
5442 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5444 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5446 mbox->vport = vport;
5447 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5448 mbox->ctx_ndlp = NULL;
5449 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5450 if (rc != MBX_TIMEOUT)
5451 mempool_free(mbox, phba->mbox_mem_pool);
5453 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5454 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5455 "1836 Could not issue "
5456 "unreg_login(all_rpis) status %d\n",
5462 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5464 struct lpfc_hba *phba = vport->phba;
5468 /* Unreg DID is an SLI3 operation. */
5469 if (phba->sli_rev > LPFC_SLI_REV3)
5472 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5474 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5476 mbox->vport = vport;
5477 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5478 mbox->ctx_ndlp = NULL;
5479 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5480 if (rc != MBX_TIMEOUT)
5481 mempool_free(mbox, phba->mbox_mem_pool);
5483 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5484 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5485 "1815 Could not issue "
5486 "unreg_did (default rpis) status %d\n",
5492 * Free resources associated with LPFC_NODELIST entry
5493 * so it can be freed.
5496 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5498 struct lpfc_hba *phba = vport->phba;
5499 LPFC_MBOXQ_t *mb, *nextmb;
5500 struct lpfc_dmabuf *mp;
5502 /* Cleanup node for NPort <nlp_DID> */
5503 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5504 "0900 Cleanup node for NPort x%x "
5505 "Data: x%x x%x x%x\n",
5506 ndlp->nlp_DID, ndlp->nlp_flag,
5507 ndlp->nlp_state, ndlp->nlp_rpi);
5508 lpfc_dequeue_node(vport, ndlp);
5510 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5512 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5513 if ((mb = phba->sli.mbox_active)) {
5514 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5515 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5516 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5517 mb->ctx_ndlp = NULL;
5518 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5522 spin_lock_irq(&phba->hbalock);
5523 /* Cleanup REG_LOGIN completions which are not yet processed */
5524 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5525 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5526 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5527 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5530 mb->ctx_ndlp = NULL;
5531 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5534 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5535 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5536 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5537 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5538 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5540 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5543 list_del(&mb->list);
5544 mempool_free(mb, phba->mbox_mem_pool);
5545 /* We shall not invoke the lpfc_nlp_put to decrement
5546 * the ndlp reference count as we are in the process
5547 * of lpfc_nlp_release.
5551 spin_unlock_irq(&phba->hbalock);
5553 lpfc_els_abort(phba, ndlp);
5555 spin_lock_irq(&ndlp->lock);
5556 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5557 spin_unlock_irq(&ndlp->lock);
5559 ndlp->nlp_last_elscmd = 0;
5560 del_timer_sync(&ndlp->nlp_delayfunc);
5562 list_del_init(&ndlp->els_retry_evt.evt_listp);
5563 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5564 list_del_init(&ndlp->recovery_evt.evt_listp);
5565 lpfc_cleanup_vports_rrqs(vport, ndlp);
5567 if (phba->sli_rev == LPFC_SLI_REV4)
5568 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5574 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5577 D_ID mydid, ndlpdid, matchdid;
5579 if (did == Bcast_DID)
5582 /* First check for Direct match */
5583 if (ndlp->nlp_DID == did)
5586 /* Next check for area/domain identically equals 0 match */
5587 mydid.un.word = vport->fc_myDID;
5588 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5592 matchdid.un.word = did;
5593 ndlpdid.un.word = ndlp->nlp_DID;
5594 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5595 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5596 (mydid.un.b.area == matchdid.un.b.area)) {
5597 /* This code is supposed to match the ID
5598 * for a private loop device that is
5599 * connect to fl_port. But we need to
5600 * check that the port did not just go
5601 * from pt2pt to fabric or we could end
5602 * up matching ndlp->nlp_DID 000001 to
5603 * fabric DID 0x20101
5605 if ((ndlpdid.un.b.domain == 0) &&
5606 (ndlpdid.un.b.area == 0)) {
5607 if (ndlpdid.un.b.id &&
5608 vport->phba->fc_topology ==
5615 matchdid.un.word = ndlp->nlp_DID;
5616 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5617 (mydid.un.b.area == ndlpdid.un.b.area)) {
5618 if ((matchdid.un.b.domain == 0) &&
5619 (matchdid.un.b.area == 0)) {
5620 if (matchdid.un.b.id)
5628 /* Search for a nodelist entry */
5629 static struct lpfc_nodelist *
5630 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5632 struct lpfc_nodelist *ndlp;
5635 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5636 if (lpfc_matchdid(vport, ndlp, did)) {
5637 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5638 ((uint32_t)ndlp->nlp_xri << 16) |
5639 ((uint32_t)ndlp->nlp_type << 8)
5641 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5642 "0929 FIND node DID "
5643 "Data: x%px x%x x%x x%x x%x x%px\n",
5644 ndlp, ndlp->nlp_DID,
5645 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5646 ndlp->active_rrqs_xri_bitmap);
5651 /* FIND node did <did> NOT FOUND */
5652 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5653 "0932 FIND node did x%x NOT FOUND.\n", did);
5657 struct lpfc_nodelist *
5658 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5661 struct lpfc_nodelist *ndlp;
5662 unsigned long iflags;
5664 spin_lock_irqsave(shost->host_lock, iflags);
5665 ndlp = __lpfc_findnode_did(vport, did);
5666 spin_unlock_irqrestore(shost->host_lock, iflags);
5670 struct lpfc_nodelist *
5671 lpfc_findnode_mapped(struct lpfc_vport *vport)
5673 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5674 struct lpfc_nodelist *ndlp;
5676 unsigned long iflags;
5678 spin_lock_irqsave(shost->host_lock, iflags);
5680 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5681 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5682 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5683 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5684 ((uint32_t)ndlp->nlp_xri << 16) |
5685 ((uint32_t)ndlp->nlp_type << 8) |
5686 ((uint32_t)ndlp->nlp_rpi & 0xff));
5687 spin_unlock_irqrestore(shost->host_lock, iflags);
5688 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5689 "2025 FIND node DID "
5690 "Data: x%px x%x x%x x%x x%px\n",
5691 ndlp, ndlp->nlp_DID,
5692 ndlp->nlp_flag, data1,
5693 ndlp->active_rrqs_xri_bitmap);
5697 spin_unlock_irqrestore(shost->host_lock, iflags);
5699 /* FIND node did <did> NOT FOUND */
5700 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5701 "2026 FIND mapped did NOT FOUND.\n");
5705 struct lpfc_nodelist *
5706 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5708 struct lpfc_nodelist *ndlp;
5710 ndlp = lpfc_findnode_did(vport, did);
5712 if (vport->phba->nvmet_support)
5714 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5715 lpfc_rscn_payload_check(vport, did) == 0)
5717 ndlp = lpfc_nlp_init(vport, did);
5720 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5722 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5723 "6453 Setup New Node 2B_DISC x%x "
5724 "Data:x%x x%x x%x\n",
5725 ndlp->nlp_DID, ndlp->nlp_flag,
5726 ndlp->nlp_state, vport->fc_flag);
5728 spin_lock_irq(&ndlp->lock);
5729 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5730 spin_unlock_irq(&ndlp->lock);
5734 /* The NVME Target does not want to actively manage an rport.
5735 * The goal is to allow the target to reset its state and clear
5736 * pending IO in preparation for the initiator to recover.
5738 if ((vport->fc_flag & FC_RSCN_MODE) &&
5739 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5740 if (lpfc_rscn_payload_check(vport, did)) {
5742 /* Since this node is marked for discovery,
5743 * delay timeout is not needed.
5745 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5747 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5748 "6455 Setup RSCN Node 2B_DISC x%x "
5749 "Data:x%x x%x x%x\n",
5750 ndlp->nlp_DID, ndlp->nlp_flag,
5751 ndlp->nlp_state, vport->fc_flag);
5753 /* NVME Target mode waits until rport is known to be
5754 * impacted by the RSCN before it transitions. No
5755 * active management - just go to NPR provided the
5756 * node had a valid login.
5758 if (vport->phba->nvmet_support)
5761 /* If we've already received a PLOGI from this NPort
5762 * we don't need to try to discover it again.
5764 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5766 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5769 ndlp->nlp_prev_state = ndlp->nlp_state;
5770 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5772 spin_lock_irq(&ndlp->lock);
5773 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5774 spin_unlock_irq(&ndlp->lock);
5776 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5777 "6456 Skip Setup RSCN Node x%x "
5778 "Data:x%x x%x x%x\n",
5779 ndlp->nlp_DID, ndlp->nlp_flag,
5780 ndlp->nlp_state, vport->fc_flag);
5784 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5785 "6457 Setup Active Node 2B_DISC x%x "
5786 "Data:x%x x%x x%x\n",
5787 ndlp->nlp_DID, ndlp->nlp_flag,
5788 ndlp->nlp_state, vport->fc_flag);
5790 /* If the initiator received a PLOGI from this NPort or if the
5791 * initiator is already in the process of discovery on it,
5792 * there's no need to try to discover it again.
5794 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5795 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5796 (!vport->phba->nvmet_support &&
5797 ndlp->nlp_flag & NLP_RCV_PLOGI))
5800 if (vport->phba->nvmet_support)
5803 /* Moving to NPR state clears unsolicited flags and
5804 * allows for rediscovery
5806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5808 spin_lock_irq(&ndlp->lock);
5809 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5810 spin_unlock_irq(&ndlp->lock);
5815 /* Build a list of nodes to discover based on the loopmap */
5817 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5819 struct lpfc_hba *phba = vport->phba;
5821 uint32_t alpa, index;
5823 if (!lpfc_is_link_up(phba))
5826 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5829 /* Check for loop map present or not */
5830 if (phba->alpa_map[0]) {
5831 for (j = 1; j <= phba->alpa_map[0]; j++) {
5832 alpa = phba->alpa_map[j];
5833 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5835 lpfc_setup_disc_node(vport, alpa);
5838 /* No alpamap, so try all alpa's */
5839 for (j = 0; j < FC_MAXLOOP; j++) {
5840 /* If cfg_scan_down is set, start from highest
5841 * ALPA (0xef) to lowest (0x1).
5843 if (vport->cfg_scan_down)
5846 index = FC_MAXLOOP - j - 1;
5847 alpa = lpfcAlpaArray[index];
5848 if ((vport->fc_myDID & 0xff) == alpa)
5850 lpfc_setup_disc_node(vport, alpa);
5858 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5861 struct lpfc_sli *psli = &phba->sli;
5862 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5863 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5867 * if it's not a physical port or if we already send
5868 * clear_la then don't send it.
5870 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5871 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5872 (phba->sli_rev == LPFC_SLI_REV4))
5875 /* Link up discovery */
5876 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5877 phba->link_state = LPFC_CLEAR_LA;
5878 lpfc_clear_la(phba, mbox);
5879 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5880 mbox->vport = vport;
5881 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5882 if (rc == MBX_NOT_FINISHED) {
5883 mempool_free(mbox, phba->mbox_mem_pool);
5884 lpfc_disc_flush_list(vport);
5885 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5886 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5887 phba->link_state = LPFC_HBA_ERROR;
5892 /* Reg_vpi to tell firmware to resume normal operations */
5894 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5896 LPFC_MBOXQ_t *regvpimbox;
5898 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5900 lpfc_reg_vpi(vport, regvpimbox);
5901 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5902 regvpimbox->vport = vport;
5903 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5904 == MBX_NOT_FINISHED) {
5905 mempool_free(regvpimbox, phba->mbox_mem_pool);
5910 /* Start Link up / RSCN discovery on NPR nodes */
5912 lpfc_disc_start(struct lpfc_vport *vport)
5914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5915 struct lpfc_hba *phba = vport->phba;
5917 uint32_t clear_la_pending;
5919 if (!lpfc_is_link_up(phba)) {
5920 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5921 "3315 Link is not up %x\n",
5926 if (phba->link_state == LPFC_CLEAR_LA)
5927 clear_la_pending = 1;
5929 clear_la_pending = 0;
5931 if (vport->port_state < LPFC_VPORT_READY)
5932 vport->port_state = LPFC_DISC_AUTH;
5934 lpfc_set_disctmo(vport);
5936 vport->fc_prevDID = vport->fc_myDID;
5937 vport->num_disc_nodes = 0;
5939 /* Start Discovery state <hba_state> */
5940 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5941 "0202 Start Discovery port state x%x "
5942 "flg x%x Data: x%x x%x x%x\n",
5943 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5944 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5946 /* First do ADISCs - if any */
5947 num_sent = lpfc_els_disc_adisc(vport);
5952 /* Register the VPI for SLI3, NPIV only. */
5953 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5954 !(vport->fc_flag & FC_PT2PT) &&
5955 !(vport->fc_flag & FC_RSCN_MODE) &&
5956 (phba->sli_rev < LPFC_SLI_REV4)) {
5957 lpfc_issue_clear_la(phba, vport);
5958 lpfc_issue_reg_vpi(phba, vport);
5963 * For SLI2, we need to set port_state to READY and continue
5966 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5967 /* If we get here, there is nothing to ADISC */
5968 lpfc_issue_clear_la(phba, vport);
5970 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5971 vport->num_disc_nodes = 0;
5972 /* go thru NPR nodes and issue ELS PLOGIs */
5973 if (vport->fc_npr_cnt)
5974 lpfc_els_disc_plogi(vport);
5976 if (!vport->num_disc_nodes) {
5977 spin_lock_irq(shost->host_lock);
5978 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5979 spin_unlock_irq(shost->host_lock);
5980 lpfc_can_disctmo(vport);
5983 vport->port_state = LPFC_VPORT_READY;
5985 /* Next do PLOGIs - if any */
5986 num_sent = lpfc_els_disc_plogi(vport);
5991 if (vport->fc_flag & FC_RSCN_MODE) {
5992 /* Check to see if more RSCNs came in while we
5993 * were processing this one.
5995 if ((vport->fc_rscn_id_cnt == 0) &&
5996 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5997 spin_lock_irq(shost->host_lock);
5998 vport->fc_flag &= ~FC_RSCN_MODE;
5999 spin_unlock_irq(shost->host_lock);
6000 lpfc_can_disctmo(vport);
6002 lpfc_els_handle_rscn(vport);
6009 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
6010 * ring the match the sppecified nodelist.
6013 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
6015 LIST_HEAD(completions);
6017 struct lpfc_iocbq *iocb, *next_iocb;
6018 struct lpfc_sli_ring *pring;
6020 pring = lpfc_phba_elsring(phba);
6021 if (unlikely(!pring))
6024 /* Error matching iocb on txq or txcmplq
6025 * First check the txq.
6027 spin_lock_irq(&phba->hbalock);
6028 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6029 if (iocb->context1 != ndlp) {
6033 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
6034 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
6036 list_move_tail(&iocb->list, &completions);
6040 /* Next check the txcmplq */
6041 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
6042 if (iocb->context1 != ndlp) {
6046 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
6047 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
6048 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
6051 spin_unlock_irq(&phba->hbalock);
6053 /* Make sure HBA is alive */
6054 lpfc_issue_hb_tmo(phba);
6056 /* Cancel all the IOCBs from the completions list */
6057 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6062 lpfc_disc_flush_list(struct lpfc_vport *vport)
6064 struct lpfc_nodelist *ndlp, *next_ndlp;
6065 struct lpfc_hba *phba = vport->phba;
6067 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6068 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6070 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
6071 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
6072 lpfc_free_tx(phba, ndlp);
6079 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
6081 lpfc_els_flush_rscn(vport);
6082 lpfc_els_flush_cmd(vport);
6083 lpfc_disc_flush_list(vport);
6086 /*****************************************************************************/
6088 * NAME: lpfc_disc_timeout
6090 * FUNCTION: Fibre Channel driver discovery timeout routine.
6092 * EXECUTION ENVIRONMENT: interrupt only
6100 /*****************************************************************************/
6102 lpfc_disc_timeout(struct timer_list *t)
6104 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
6105 struct lpfc_hba *phba = vport->phba;
6106 uint32_t tmo_posted;
6107 unsigned long flags = 0;
6109 if (unlikely(!phba))
6112 spin_lock_irqsave(&vport->work_port_lock, flags);
6113 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
6115 vport->work_port_events |= WORKER_DISC_TMO;
6116 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6119 lpfc_worker_wake_up(phba);
6124 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6126 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6127 struct lpfc_hba *phba = vport->phba;
6128 struct lpfc_sli *psli = &phba->sli;
6129 struct lpfc_nodelist *ndlp, *next_ndlp;
6130 LPFC_MBOXQ_t *initlinkmbox;
6131 int rc, clrlaerr = 0;
6133 if (!(vport->fc_flag & FC_DISC_TMO))
6136 spin_lock_irq(shost->host_lock);
6137 vport->fc_flag &= ~FC_DISC_TMO;
6138 spin_unlock_irq(shost->host_lock);
6140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6141 "disc timeout: state:x%x rtry:x%x flg:x%x",
6142 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6144 switch (vport->port_state) {
6146 case LPFC_LOCAL_CFG_LINK:
6148 * port_state is identically LPFC_LOCAL_CFG_LINK while
6149 * waiting for FAN timeout
6151 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6152 "0221 FAN timeout\n");
6154 /* Start discovery by sending FLOGI, clean up old rpis */
6155 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6157 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6159 if (ndlp->nlp_type & NLP_FABRIC) {
6160 /* Clean up the ndlp on Fabric connections */
6161 lpfc_drop_node(vport, ndlp);
6163 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6164 /* Fail outstanding IO now since device
6165 * is marked for PLOGI.
6167 lpfc_unreg_rpi(vport, ndlp);
6170 if (vport->port_state != LPFC_FLOGI) {
6171 if (phba->sli_rev <= LPFC_SLI_REV3)
6172 lpfc_initial_flogi(vport);
6174 lpfc_issue_init_vfi(vport);
6181 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
6182 /* Initial FLOGI timeout */
6183 lpfc_printf_vlog(vport, KERN_ERR,
6185 "0222 Initial %s timeout\n",
6186 vport->vpi ? "FDISC" : "FLOGI");
6188 /* Assume no Fabric and go on with discovery.
6189 * Check for outstanding ELS FLOGI to abort.
6192 /* FLOGI failed, so just use loop map to make discovery list */
6193 lpfc_disc_list_loopmap(vport);
6195 /* Start discovery */
6196 lpfc_disc_start(vport);
6199 case LPFC_FABRIC_CFG_LINK:
6200 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6202 lpfc_printf_vlog(vport, KERN_ERR,
6204 "0223 Timeout while waiting for "
6205 "NameServer login\n");
6206 /* Next look for NameServer ndlp */
6207 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6209 lpfc_els_abort(phba, ndlp);
6211 /* ReStart discovery */
6215 /* Check for wait for NameServer Rsp timeout */
6216 lpfc_printf_vlog(vport, KERN_ERR,
6218 "0224 NameServer Query timeout "
6220 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6222 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6223 /* Try it one more time */
6224 vport->fc_ns_retry++;
6225 vport->gidft_inp = 0;
6226 rc = lpfc_issue_gidft(vport);
6230 vport->fc_ns_retry = 0;
6234 * Discovery is over.
6235 * set port_state to PORT_READY if SLI2.
6236 * cmpl_reg_vpi will set port_state to READY for SLI3.
6238 if (phba->sli_rev < LPFC_SLI_REV4) {
6239 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6240 lpfc_issue_reg_vpi(phba, vport);
6242 lpfc_issue_clear_la(phba, vport);
6243 vport->port_state = LPFC_VPORT_READY;
6247 /* Setup and issue mailbox INITIALIZE LINK command */
6248 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6249 if (!initlinkmbox) {
6250 lpfc_printf_vlog(vport, KERN_ERR,
6252 "0206 Device Discovery "
6253 "completion error\n");
6254 phba->link_state = LPFC_HBA_ERROR;
6258 lpfc_linkdown(phba);
6259 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6260 phba->cfg_link_speed);
6261 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6262 initlinkmbox->vport = vport;
6263 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6264 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6265 lpfc_set_loopback_flag(phba);
6266 if (rc == MBX_NOT_FINISHED)
6267 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6271 case LPFC_DISC_AUTH:
6272 /* Node Authentication timeout */
6273 lpfc_printf_vlog(vport, KERN_ERR,
6275 "0227 Node Authentication timeout\n");
6276 lpfc_disc_flush_list(vport);
6279 * set port_state to PORT_READY if SLI2.
6280 * cmpl_reg_vpi will set port_state to READY for SLI3.
6282 if (phba->sli_rev < LPFC_SLI_REV4) {
6283 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6284 lpfc_issue_reg_vpi(phba, vport);
6285 else { /* NPIV Not enabled */
6286 lpfc_issue_clear_la(phba, vport);
6287 vport->port_state = LPFC_VPORT_READY;
6292 case LPFC_VPORT_READY:
6293 if (vport->fc_flag & FC_RSCN_MODE) {
6294 lpfc_printf_vlog(vport, KERN_ERR,
6296 "0231 RSCN timeout Data: x%x "
6298 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6300 /* Cleanup any outstanding ELS commands */
6301 lpfc_els_flush_cmd(vport);
6303 lpfc_els_flush_rscn(vport);
6304 lpfc_disc_flush_list(vport);
6309 lpfc_printf_vlog(vport, KERN_ERR,
6311 "0273 Unexpected discovery timeout, "
6312 "vport State x%x\n", vport->port_state);
6316 switch (phba->link_state) {
6318 /* CLEAR LA timeout */
6319 lpfc_printf_vlog(vport, KERN_ERR,
6321 "0228 CLEAR LA timeout\n");
6326 lpfc_issue_clear_la(phba, vport);
6328 case LPFC_LINK_UNKNOWN:
6329 case LPFC_WARM_START:
6330 case LPFC_INIT_START:
6331 case LPFC_INIT_MBX_CMDS:
6332 case LPFC_LINK_DOWN:
6333 case LPFC_HBA_ERROR:
6334 lpfc_printf_vlog(vport, KERN_ERR,
6336 "0230 Unexpected timeout, hba link "
6337 "state x%x\n", phba->link_state);
6341 case LPFC_HBA_READY:
6346 lpfc_disc_flush_list(vport);
6347 if (phba->sli_rev != LPFC_SLI_REV4) {
6348 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6349 ~LPFC_STOP_IOCB_EVENT;
6350 psli->sli3_ring[LPFC_FCP_RING].flag &=
6351 ~LPFC_STOP_IOCB_EVENT;
6353 vport->port_state = LPFC_VPORT_READY;
6359 * This routine handles processing a NameServer REG_LOGIN mailbox
6360 * command upon completion. It is setup in the LPFC_MBOXQ
6361 * as the completion routine when the command is
6362 * handed off to the SLI layer.
6365 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6367 MAILBOX_t *mb = &pmb->u.mb;
6368 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6369 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6370 struct lpfc_vport *vport = pmb->vport;
6372 pmb->ctx_buf = NULL;
6373 pmb->ctx_ndlp = NULL;
6375 if (phba->sli_rev < LPFC_SLI_REV4)
6376 ndlp->nlp_rpi = mb->un.varWords[0];
6377 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6378 ndlp->nlp_type |= NLP_FABRIC;
6379 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6380 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6381 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6382 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6383 kref_read(&ndlp->kref),
6386 * Start issuing Fabric-Device Management Interface (FDMI) command to
6387 * 0xfffffa (FDMI well known port).
6388 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6389 * DPRT -> RPRT (vports)
6391 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6392 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
6393 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6395 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6399 /* decrement the node reference count held for this callback
6403 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6405 mempool_free(pmb, phba->mbox_mem_pool);
6411 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6413 uint16_t *rpi = param;
6415 return ndlp->nlp_rpi == *rpi;
6419 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6421 return memcmp(&ndlp->nlp_portname, param,
6422 sizeof(ndlp->nlp_portname)) == 0;
6425 static struct lpfc_nodelist *
6426 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6428 struct lpfc_nodelist *ndlp;
6430 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6431 if (filter(ndlp, param)) {
6432 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6433 "3185 FIND node filter %ps DID "
6434 "ndlp x%px did x%x flg x%x st x%x "
6435 "xri x%x type x%x rpi x%x\n",
6436 filter, ndlp, ndlp->nlp_DID,
6437 ndlp->nlp_flag, ndlp->nlp_state,
6438 ndlp->nlp_xri, ndlp->nlp_type,
6443 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6444 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6449 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6450 * returns the node list element pointer else return NULL.
6452 struct lpfc_nodelist *
6453 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6455 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6459 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6460 * returns the node element list pointer else return NULL.
6462 struct lpfc_nodelist *
6463 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6465 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6466 struct lpfc_nodelist *ndlp;
6468 spin_lock_irq(shost->host_lock);
6469 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6470 spin_unlock_irq(shost->host_lock);
6475 * This routine looks up the ndlp lists for the given RPI. If the rpi
6476 * is found, the routine returns the node element list pointer else
6479 struct lpfc_nodelist *
6480 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6483 struct lpfc_nodelist *ndlp;
6484 unsigned long flags;
6486 spin_lock_irqsave(shost->host_lock, flags);
6487 ndlp = __lpfc_findnode_rpi(vport, rpi);
6488 spin_unlock_irqrestore(shost->host_lock, flags);
6493 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6494 * @phba: pointer to lpfc hba data structure.
6495 * @vpi: the physical host virtual N_Port identifier.
6497 * This routine finds a vport on a HBA (referred by @phba) through a
6498 * @vpi. The function walks the HBA's vport list and returns the address
6499 * of the vport with the matching @vpi.
6502 * NULL - No vport with the matching @vpi found
6503 * Otherwise - Address to the vport with the matching @vpi.
6506 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6508 struct lpfc_vport *vport;
6509 unsigned long flags;
6512 /* The physical ports are always vpi 0 - translate is unnecessary. */
6515 * Translate the physical vpi to the logical vpi. The
6516 * vport stores the logical vpi.
6518 for (i = 0; i <= phba->max_vpi; i++) {
6519 if (vpi == phba->vpi_ids[i])
6523 if (i > phba->max_vpi) {
6524 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6525 "2936 Could not find Vport mapped "
6526 "to vpi %d\n", vpi);
6531 spin_lock_irqsave(&phba->port_list_lock, flags);
6532 list_for_each_entry(vport, &phba->port_list, listentry) {
6533 if (vport->vpi == i) {
6534 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6538 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6542 struct lpfc_nodelist *
6543 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6545 struct lpfc_nodelist *ndlp;
6546 int rpi = LPFC_RPI_ALLOC_ERROR;
6548 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6549 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6550 if (rpi == LPFC_RPI_ALLOC_ERROR)
6554 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6556 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6557 lpfc_sli4_free_rpi(vport->phba, rpi);
6561 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6563 spin_lock_init(&ndlp->lock);
6565 lpfc_initialize_node(vport, ndlp, did);
6566 INIT_LIST_HEAD(&ndlp->nlp_listp);
6567 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6568 ndlp->nlp_rpi = rpi;
6569 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6570 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6571 "flg:x%x refcnt:%d\n",
6572 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6573 ndlp->nlp_flag, kref_read(&ndlp->kref));
6575 ndlp->active_rrqs_xri_bitmap =
6576 mempool_alloc(vport->phba->active_rrq_pool,
6578 if (ndlp->active_rrqs_xri_bitmap)
6579 memset(ndlp->active_rrqs_xri_bitmap, 0,
6580 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6586 "node init: did:x%x",
6587 ndlp->nlp_DID, 0, 0);
6592 /* This routine releases all resources associated with a specifc NPort's ndlp
6593 * and mempool_free's the nodelist.
6596 lpfc_nlp_release(struct kref *kref)
6598 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6600 struct lpfc_vport *vport = ndlp->vport;
6602 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6603 "node release: did:x%x flg:x%x type:x%x",
6604 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6606 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6607 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6608 __func__, ndlp, ndlp->nlp_DID,
6609 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6611 /* remove ndlp from action. */
6612 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6613 lpfc_cleanup_node(vport, ndlp);
6615 /* Not all ELS transactions have registered the RPI with the port.
6616 * In these cases the rpi usage is temporary and the node is
6617 * released when the WQE is completed. Catch this case to free the
6618 * RPI to the pool. Because this node is in the release path, a lock
6619 * is unnecessary. All references are gone and the node has been
6622 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6623 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6624 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6625 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6626 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6630 /* The node is not freed back to memory, it is released to a pool so
6631 * the node fields need to be cleaned up.
6634 ndlp->nlp_state = NLP_STE_FREED_NODE;
6636 ndlp->fc4_xpt_flags = 0;
6638 /* free ndlp memory for final ndlp release */
6639 kfree(ndlp->lat_data);
6640 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6641 mempool_free(ndlp->active_rrqs_xri_bitmap,
6642 ndlp->phba->active_rrq_pool);
6643 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6646 /* This routine bumps the reference count for a ndlp structure to ensure
6647 * that one discovery thread won't free a ndlp while another discovery thread
6650 struct lpfc_nodelist *
6651 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6653 unsigned long flags;
6656 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6657 "node get: did:x%x flg:x%x refcnt:x%x",
6658 ndlp->nlp_DID, ndlp->nlp_flag,
6659 kref_read(&ndlp->kref));
6661 /* The check of ndlp usage to prevent incrementing the
6662 * ndlp reference count that is in the process of being
6665 spin_lock_irqsave(&ndlp->lock, flags);
6666 if (!kref_get_unless_zero(&ndlp->kref)) {
6667 spin_unlock_irqrestore(&ndlp->lock, flags);
6668 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6669 "0276 %s: ndlp:x%px refcnt:%d\n",
6670 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6673 spin_unlock_irqrestore(&ndlp->lock, flags);
6675 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6681 /* This routine decrements the reference count for a ndlp structure. If the
6682 * count goes to 0, this indicates the associated nodelist should be freed.
6685 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6688 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6689 "node put: did:x%x flg:x%x refcnt:x%x",
6690 ndlp->nlp_DID, ndlp->nlp_flag,
6691 kref_read(&ndlp->kref));
6693 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6696 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6699 /* This routine free's the specified nodelist if it is not in use
6700 * by any other discovery thread. This routine returns 1 if the
6701 * ndlp has been freed. A return value of 0 indicates the ndlp is
6702 * not yet been released.
6705 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6707 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6708 "node not used: did:x%x flg:x%x refcnt:x%x",
6709 ndlp->nlp_DID, ndlp->nlp_flag,
6710 kref_read(&ndlp->kref));
6712 if (kref_read(&ndlp->kref) == 1)
6713 if (lpfc_nlp_put(ndlp))
6719 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6720 * @phba: Pointer to hba context object.
6722 * This function iterate through all FC nodes associated
6723 * will all vports to check if there is any node with
6724 * fc_rports associated with it. If there is an fc_rport
6725 * associated with the node, then the node is either in
6726 * discovered state or its devloss_timer is pending.
6729 lpfc_fcf_inuse(struct lpfc_hba *phba)
6731 struct lpfc_vport **vports;
6733 struct lpfc_nodelist *ndlp;
6734 struct Scsi_Host *shost;
6736 vports = lpfc_create_vport_work_array(phba);
6738 /* If driver cannot allocate memory, indicate fcf is in use */
6742 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6743 shost = lpfc_shost_from_vport(vports[i]);
6744 spin_lock_irq(shost->host_lock);
6746 * IF the CVL_RCVD bit is not set then we have sent the
6748 * If dev_loss fires while we are waiting we do not want to
6751 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6752 spin_unlock_irq(shost->host_lock);
6756 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6758 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6760 spin_unlock_irq(shost->host_lock);
6762 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6764 lpfc_printf_log(phba, KERN_INFO,
6765 LOG_NODE | LOG_DISCOVERY,
6766 "2624 RPI %x DID %x flag %x "
6767 "still logged in\n",
6768 ndlp->nlp_rpi, ndlp->nlp_DID,
6772 spin_unlock_irq(shost->host_lock);
6775 lpfc_destroy_vport_work_array(phba, vports);
6780 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6781 * @phba: Pointer to hba context object.
6782 * @mboxq: Pointer to mailbox object.
6784 * This function frees memory associated with the mailbox command.
6787 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6789 struct lpfc_vport *vport = mboxq->vport;
6790 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6792 if (mboxq->u.mb.mbxStatus) {
6793 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6794 "2555 UNREG_VFI mbxStatus error x%x "
6796 mboxq->u.mb.mbxStatus, vport->port_state);
6798 spin_lock_irq(shost->host_lock);
6799 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6800 spin_unlock_irq(shost->host_lock);
6801 mempool_free(mboxq, phba->mbox_mem_pool);
6806 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6807 * @phba: Pointer to hba context object.
6808 * @mboxq: Pointer to mailbox object.
6810 * This function frees memory associated with the mailbox command.
6813 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6815 struct lpfc_vport *vport = mboxq->vport;
6817 if (mboxq->u.mb.mbxStatus) {
6818 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6819 "2550 UNREG_FCFI mbxStatus error x%x "
6821 mboxq->u.mb.mbxStatus, vport->port_state);
6823 mempool_free(mboxq, phba->mbox_mem_pool);
6828 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6829 * @phba: Pointer to hba context object.
6831 * This function prepare the HBA for unregistering the currently registered
6832 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6836 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6838 struct lpfc_vport **vports;
6839 struct lpfc_nodelist *ndlp;
6840 struct Scsi_Host *shost;
6843 /* Unregister RPIs */
6844 if (lpfc_fcf_inuse(phba))
6845 lpfc_unreg_hba_rpis(phba);
6847 /* At this point, all discovery is aborted */
6848 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6850 /* Unregister VPIs */
6851 vports = lpfc_create_vport_work_array(phba);
6852 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6853 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6854 /* Stop FLOGI/FDISC retries */
6855 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6857 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6858 lpfc_cleanup_pending_mbox(vports[i]);
6859 if (phba->sli_rev == LPFC_SLI_REV4)
6860 lpfc_sli4_unreg_all_rpis(vports[i]);
6861 lpfc_mbx_unreg_vpi(vports[i]);
6862 shost = lpfc_shost_from_vport(vports[i]);
6863 spin_lock_irq(shost->host_lock);
6864 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6865 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6866 spin_unlock_irq(shost->host_lock);
6868 lpfc_destroy_vport_work_array(phba, vports);
6869 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6870 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6872 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6873 lpfc_cleanup_pending_mbox(phba->pport);
6874 if (phba->sli_rev == LPFC_SLI_REV4)
6875 lpfc_sli4_unreg_all_rpis(phba->pport);
6876 lpfc_mbx_unreg_vpi(phba->pport);
6877 shost = lpfc_shost_from_vport(phba->pport);
6878 spin_lock_irq(shost->host_lock);
6879 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6880 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6881 spin_unlock_irq(shost->host_lock);
6884 /* Cleanup any outstanding ELS commands */
6885 lpfc_els_flush_all_cmd(phba);
6887 /* Unregister the physical port VFI */
6888 rc = lpfc_issue_unreg_vfi(phba->pport);
6893 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6894 * @phba: Pointer to hba context object.
6896 * This function issues synchronous unregister FCF mailbox command to HBA to
6897 * unregister the currently registered FCF record. The driver does not reset
6898 * the driver FCF usage state flags.
6900 * Return 0 if successfully issued, none-zero otherwise.
6903 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6908 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6910 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6911 "2551 UNREG_FCFI mbox allocation failed"
6912 "HBA state x%x\n", phba->pport->port_state);
6915 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6916 mbox->vport = phba->pport;
6917 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6918 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6920 if (rc == MBX_NOT_FINISHED) {
6921 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6922 "2552 Unregister FCFI command failed rc x%x "
6924 rc, phba->pport->port_state);
6931 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6932 * @phba: Pointer to hba context object.
6934 * This function unregisters the currently reigstered FCF. This function
6935 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6938 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6942 /* Preparation for unregistering fcf */
6943 rc = lpfc_unregister_fcf_prep(phba);
6945 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6946 "2748 Failed to prepare for unregistering "
6947 "HBA's FCF record: rc=%d\n", rc);
6951 /* Now, unregister FCF record and reset HBA FCF state */
6952 rc = lpfc_sli4_unregister_fcf(phba);
6955 /* Reset HBA FCF states after successful unregister FCF */
6956 phba->fcf.fcf_flag = 0;
6957 phba->fcf.current_rec.flag = 0;
6960 * If driver is not unloading, check if there is any other
6961 * FCF record that can be used for discovery.
6963 if ((phba->pport->load_flag & FC_UNLOADING) ||
6964 (phba->link_state < LPFC_LINK_UP))
6967 /* This is considered as the initial FCF discovery scan */
6968 spin_lock_irq(&phba->hbalock);
6969 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6970 spin_unlock_irq(&phba->hbalock);
6972 /* Reset FCF roundrobin bmask for new discovery */
6973 lpfc_sli4_clear_fcf_rr_bmask(phba);
6975 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6978 spin_lock_irq(&phba->hbalock);
6979 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6980 spin_unlock_irq(&phba->hbalock);
6981 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6982 "2553 lpfc_unregister_unused_fcf failed "
6983 "to read FCF record HBA state x%x\n",
6984 phba->pport->port_state);
6989 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6990 * @phba: Pointer to hba context object.
6992 * This function just unregisters the currently reigstered FCF. It does not
6993 * try to find another FCF for discovery.
6996 lpfc_unregister_fcf(struct lpfc_hba *phba)
7000 /* Preparation for unregistering fcf */
7001 rc = lpfc_unregister_fcf_prep(phba);
7003 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7004 "2749 Failed to prepare for unregistering "
7005 "HBA's FCF record: rc=%d\n", rc);
7009 /* Now, unregister FCF record and reset HBA FCF state */
7010 rc = lpfc_sli4_unregister_fcf(phba);
7013 /* Set proper HBA FCF states after successful unregister FCF */
7014 spin_lock_irq(&phba->hbalock);
7015 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
7016 spin_unlock_irq(&phba->hbalock);
7020 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
7021 * @phba: Pointer to hba context object.
7023 * This function check if there are any connected remote port for the FCF and
7024 * if all the devices are disconnected, this function unregister FCFI.
7025 * This function also tries to use another FCF for discovery.
7028 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
7031 * If HBA is not running in FIP mode, if HBA does not support
7032 * FCoE, if FCF discovery is ongoing, or if FCF has not been
7033 * registered, do nothing.
7035 spin_lock_irq(&phba->hbalock);
7036 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
7037 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
7038 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
7039 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
7040 (phba->pport->port_state == LPFC_FLOGI)) {
7041 spin_unlock_irq(&phba->hbalock);
7044 spin_unlock_irq(&phba->hbalock);
7046 if (lpfc_fcf_inuse(phba))
7049 lpfc_unregister_fcf_rescan(phba);
7053 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
7054 * @phba: Pointer to hba context object.
7055 * @buff: Buffer containing the FCF connection table as in the config
7057 * This function create driver data structure for the FCF connection
7058 * record table read from config region 23.
7061 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
7064 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7065 struct lpfc_fcf_conn_hdr *conn_hdr;
7066 struct lpfc_fcf_conn_rec *conn_rec;
7067 uint32_t record_count;
7070 /* Free the current connect table */
7071 list_for_each_entry_safe(conn_entry, next_conn_entry,
7072 &phba->fcf_conn_rec_list, list) {
7073 list_del_init(&conn_entry->list);
7077 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
7078 record_count = conn_hdr->length * sizeof(uint32_t)/
7079 sizeof(struct lpfc_fcf_conn_rec);
7081 conn_rec = (struct lpfc_fcf_conn_rec *)
7082 (buff + sizeof(struct lpfc_fcf_conn_hdr));
7084 for (i = 0; i < record_count; i++) {
7085 if (!(conn_rec[i].flags & FCFCNCT_VALID))
7087 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
7090 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7091 "2566 Failed to allocate connection"
7096 memcpy(&conn_entry->conn_rec, &conn_rec[i],
7097 sizeof(struct lpfc_fcf_conn_rec));
7098 list_add_tail(&conn_entry->list,
7099 &phba->fcf_conn_rec_list);
7102 if (!list_empty(&phba->fcf_conn_rec_list)) {
7104 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
7106 conn_rec = &conn_entry->conn_rec;
7107 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7108 "3345 FCF connection list rec[%02d]: "
7109 "flags:x%04x, vtag:x%04x, "
7110 "fabric_name:x%02x:%02x:%02x:%02x:"
7111 "%02x:%02x:%02x:%02x, "
7112 "switch_name:x%02x:%02x:%02x:%02x:"
7113 "%02x:%02x:%02x:%02x\n", i++,
7114 conn_rec->flags, conn_rec->vlan_tag,
7115 conn_rec->fabric_name[0],
7116 conn_rec->fabric_name[1],
7117 conn_rec->fabric_name[2],
7118 conn_rec->fabric_name[3],
7119 conn_rec->fabric_name[4],
7120 conn_rec->fabric_name[5],
7121 conn_rec->fabric_name[6],
7122 conn_rec->fabric_name[7],
7123 conn_rec->switch_name[0],
7124 conn_rec->switch_name[1],
7125 conn_rec->switch_name[2],
7126 conn_rec->switch_name[3],
7127 conn_rec->switch_name[4],
7128 conn_rec->switch_name[5],
7129 conn_rec->switch_name[6],
7130 conn_rec->switch_name[7]);
7136 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7137 * @phba: Pointer to hba context object.
7138 * @buff: Buffer containing the FCoE parameter data structure.
7140 * This function update driver data structure with config
7141 * parameters read from config region 23.
7144 lpfc_read_fcoe_param(struct lpfc_hba *phba,
7147 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7148 struct lpfc_fcoe_params *fcoe_param;
7150 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7152 fcoe_param = (struct lpfc_fcoe_params *)
7153 (buff + sizeof(struct lpfc_fip_param_hdr));
7155 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7156 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7159 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7160 phba->valid_vlan = 1;
7161 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7165 phba->fc_map[0] = fcoe_param->fc_map[0];
7166 phba->fc_map[1] = fcoe_param->fc_map[1];
7167 phba->fc_map[2] = fcoe_param->fc_map[2];
7172 * lpfc_get_rec_conf23 - Get a record type in config region data.
7173 * @buff: Buffer containing config region 23 data.
7174 * @size: Size of the data buffer.
7175 * @rec_type: Record type to be searched.
7177 * This function searches config region data to find the beginning
7178 * of the record specified by record_type. If record found, this
7179 * function return pointer to the record else return NULL.
7182 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7184 uint32_t offset = 0, rec_length;
7186 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7187 (size < sizeof(uint32_t)))
7190 rec_length = buff[offset + 1];
7193 * One TLV record has one word header and number of data words
7194 * specified in the rec_length field of the record header.
7196 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7198 if (buff[offset] == rec_type)
7199 return &buff[offset];
7201 if (buff[offset] == LPFC_REGION23_LAST_REC)
7204 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7205 rec_length = buff[offset + 1];
7211 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7212 * @phba: Pointer to lpfc_hba data structure.
7213 * @buff: Buffer containing config region 23 data.
7214 * @size: Size of the data buffer.
7216 * This function parses the FCoE config parameters in config region 23 and
7217 * populate driver data structure with the parameters.
7220 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7224 uint32_t offset = 0;
7228 * If data size is less than 2 words signature and version cannot be
7231 if (size < 2*sizeof(uint32_t))
7234 /* Check the region signature first */
7235 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7236 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7237 "2567 Config region 23 has bad signature\n");
7243 /* Check the data structure version */
7244 if (buff[offset] != LPFC_REGION23_VERSION) {
7245 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7246 "2568 Config region 23 has bad version\n");
7251 /* Read FCoE param record */
7252 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7253 size - offset, FCOE_PARAM_TYPE);
7255 lpfc_read_fcoe_param(phba, rec_ptr);
7257 /* Read FCF connection table */
7258 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7259 size - offset, FCOE_CONN_TBL_TYPE);
7261 lpfc_read_fcf_conn_tbl(phba, rec_ptr);