blob: 04b6e18c5342a23272d285ff2f8c4c63b328e2e1 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart67073c62021-03-01 09:18:21 -08004 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
James Smart4ae2ebd2018-06-26 08:24:31 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * 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. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
James Smarta93ff372010-10-22 11:06:08 -040025#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027#include <linux/pci.h>
28#include <linux/kthread.h>
29#include <linux/interrupt.h>
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +010030#include <linux/lockdep.h>
James Smarte3ba04c2019-12-18 15:58:02 -080031#include <linux/utsname.h>
dea31012005-04-17 16:05:31 -050032
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_transport_fc.h>
James Smarta0f2d3e2017-02-12 13:52:31 -080037#include <scsi/fc/fc_fs.h>
38
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040044#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080046#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050051#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050052
53/* AlpaArray for assignment of scsid for scan-down and bind_method */
54static 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
68};
69
James Smart2e0fef82007-06-17 19:56:36 -050070static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010071static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040072static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
James Smarta93ff372010-10-22 11:06:08 -040073static int lpfc_fcf_inuse(struct lpfc_hba *);
James Smart7f048392020-09-11 13:01:47 -070074static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
dea31012005-04-17 16:05:31 -050075
James Smart07aaefd2021-01-04 10:02:29 -080076static int
77lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
78{
79 if (ndlp->nlp_fc4_type ||
James Smartfe83e3b2021-05-14 12:55:54 -070080 ndlp->nlp_type & NLP_FABRIC)
James Smart07aaefd2021-01-04 10:02:29 -080081 return 1;
82 return 0;
83}
James Smartc6adba12020-11-15 11:26:34 -080084/* The source of a terminate rport I/O is either a dev_loss_tmo
85 * event or a call to fc_remove_host. While the rport should be
86 * valid during these downcalls, the transport can call twice
87 * in a single event. This routine provides somoe protection
88 * as the NDLP isn't really free, just released to the pool.
89 */
90static int
91lpfc_rport_invalid(struct fc_rport *rport)
92{
93 struct lpfc_rport_data *rdata;
94 struct lpfc_nodelist *ndlp;
James Smartc6adba12020-11-15 11:26:34 -080095
96 if (!rport) {
97 pr_err("**** %s: NULL rport, exit.\n", __func__);
98 return -EINVAL;
99 }
100
101 rdata = rport->dd_data;
102 if (!rdata) {
James Smartf1156122021-04-11 18:31:24 -0700103 pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n",
James Smartc6adba12020-11-15 11:26:34 -0800104 __func__, rport, rport->scsi_target_id);
105 return -EINVAL;
106 }
107
108 ndlp = rdata->pnode;
109 if (!rdata->pnode) {
James Smartf1156122021-04-11 18:31:24 -0700110 pr_err("**** %s: NULL ndlp on rport x%px SID x%x\n",
James Smartc6adba12020-11-15 11:26:34 -0800111 __func__, rport, rport->scsi_target_id);
112 return -EINVAL;
113 }
114
James Smartc6adba12020-11-15 11:26:34 -0800115 if (!ndlp->vport) {
James Smartf1156122021-04-11 18:31:24 -0700116 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
James Smartc6adba12020-11-15 11:26:34 -0800117 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
118 rport->scsi_target_id);
119 return -EINVAL;
120 }
121 return 0;
122}
123
James Smartc01f3202006-08-18 17:47:08 -0400124void
125lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -0500126{
James Smartc01f3202006-08-18 17:47:08 -0400127 struct lpfc_rport_data *rdata;
James Smartc6adba12020-11-15 11:26:34 -0800128 struct lpfc_nodelist *ndlp;
129 struct lpfc_vport *vport;
130
131 if (lpfc_rport_invalid(rport))
132 return;
dea31012005-04-17 16:05:31 -0500133
James Smartc01f3202006-08-18 17:47:08 -0400134 rdata = rport->dd_data;
135 ndlp = rdata->pnode;
James Smartc6adba12020-11-15 11:26:34 -0800136 vport = ndlp->vport;
137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
138 "rport terminate: sid:x%x did:x%x flg:x%x",
139 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
James Smart858c9f62007-06-17 19:56:39 -0500140
James Smart078c68b2021-04-11 18:31:12 -0700141 if (ndlp->nlp_sid != NLP_NO_SID)
142 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -0400143}
144
145/*
146 * This function will be called when dev_loss_tmo fire.
147 */
148void
149lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
150{
James Smartc6adba12020-11-15 11:26:34 -0800151 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500152 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500153 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500154 struct lpfc_work_evt *evtp;
James Smart894bb172019-08-14 16:56:52 -0700155 unsigned long iflags;
James Smartc01f3202006-08-18 17:47:08 -0400156
James Smartc6adba12020-11-15 11:26:34 -0800157 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
James Smart307e3382020-11-15 11:26:30 -0800158 if (!ndlp)
James Smartc01f3202006-08-18 17:47:08 -0400159 return;
James Smartc01f3202006-08-18 17:47:08 -0400160
James Smart858c9f62007-06-17 19:56:39 -0500161 vport = ndlp->vport;
162 phba = vport->phba;
163
164 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
165 "rport devlosscb: sid:x%x did:x%x flg:x%x",
166 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
167
James Smart34f5ad82012-08-03 12:35:03 -0400168 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smartf1156122021-04-11 18:31:24 -0700169 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
James Smartc6adba12020-11-15 11:26:34 -0800170 "load_flag x%x refcnt %d\n",
171 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
172 vport->load_flag, kref_read(&ndlp->kref));
James Smart34f5ad82012-08-03 12:35:03 -0400173
James Smartc6adba12020-11-15 11:26:34 -0800174 /* Don't schedule a worker thread event if the vport is going down.
175 * The teardown process cleans up the node via lpfc_drop_node.
James Smarta8adb832007-10-27 13:37:53 -0400176 */
177 if (vport->load_flag & FC_UNLOADING) {
James Smartc6adba12020-11-15 11:26:34 -0800178 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
James Smarta8adb832007-10-27 13:37:53 -0400179 ndlp->rport = NULL;
James Smartc6adba12020-11-15 11:26:34 -0800180
181 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
182
183 /* Remove the node reference from remote_port_add now.
184 * The driver will not call remote_port_delete.
185 */
186 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -0400187 return;
188 }
189
190 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
191 return;
192
James Smart466e8402015-05-21 13:55:28 -0400193 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
Dick Kennedy372c1872020-06-30 14:50:00 -0700194 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
195 "6789 rport name %llx != node port name %llx",
196 rport->port_name,
197 wwn_to_u64(ndlp->nlp_portname.u.wwn));
James Smart34f5ad82012-08-03 12:35:03 -0400198
James Smart858c9f62007-06-17 19:56:39 -0500199 evtp = &ndlp->dev_loss_evt;
200
James Smart466e8402015-05-21 13:55:28 -0400201 if (!list_empty(&evtp->evt_listp)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700202 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartc6adba12020-11-15 11:26:34 -0800203 "6790 rport name %llx dev_loss_evt pending\n",
Dick Kennedy372c1872020-06-30 14:50:00 -0700204 rport->port_name);
James Smart858c9f62007-06-17 19:56:39 -0500205 return;
James Smart466e8402015-05-21 13:55:28 -0400206 }
James Smart858c9f62007-06-17 19:56:39 -0500207
James Smartc6adba12020-11-15 11:26:34 -0800208 spin_lock_irqsave(&ndlp->lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400209 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
James Smart52edb2c2020-11-15 11:26:35 -0800210 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
211
James Smartc6adba12020-11-15 11:26:34 -0800212 /*
James Smart52edb2c2020-11-15 11:26:35 -0800213 * The backend does not expect any more calls associated with this
214 * rport. Remove the association between rport and ndlp.
James Smartc6adba12020-11-15 11:26:34 -0800215 */
James Smart52edb2c2020-11-15 11:26:35 -0800216 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
James Smartc6adba12020-11-15 11:26:34 -0800217 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
218 ndlp->rport = NULL;
219 spin_unlock_irqrestore(&ndlp->lock, iflags);
James Smarta62a4352013-04-17 20:18:19 -0400220
James Smartfa4066b2008-01-11 01:53:27 -0500221 /* We need to hold the node by incrementing the reference
222 * count until this queued work is done
223 */
James Smart4430f7f2020-11-15 11:26:31 -0800224 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400225
James Smart894bb172019-08-14 16:56:52 -0700226 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart5e9d9b82008-06-14 22:52:53 -0400227 if (evtp->evt_arg1) {
228 evtp->evt = LPFC_EVT_DEV_LOSS;
229 list_add_tail(&evtp->evt_listp, &phba->work_list);
230 lpfc_worker_wake_up(phba);
231 }
James Smart894bb172019-08-14 16:56:52 -0700232 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500233
James Smart858c9f62007-06-17 19:56:39 -0500234 return;
235}
236
James Smarta93ff372010-10-22 11:06:08 -0400237/**
238 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
239 * @ndlp: Pointer to remote node object.
240 *
241 * This function is called from the worker thread when devloss timeout timer
242 * expires. For SLI4 host, this routine shall return 1 when at lease one
243 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
244 * routine shall return 0 when there is no remote node is still in use of FCF
245 * when devloss timeout happened to this @ndlp.
246 **/
247static int
James Smart858c9f62007-06-17 19:56:39 -0500248lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
249{
James Smart858c9f62007-06-17 19:56:39 -0500250 struct lpfc_vport *vport;
251 struct lpfc_hba *phba;
252 uint8_t *name;
253 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400254 int fcf_inuse = 0;
James Smart894bb172019-08-14 16:56:52 -0700255 unsigned long iflags;
James Smart858c9f62007-06-17 19:56:39 -0500256
James Smart858c9f62007-06-17 19:56:39 -0500257 vport = ndlp->vport;
James Smartc6adba12020-11-15 11:26:34 -0800258 name = (uint8_t *)&ndlp->nlp_portname;
259 phba = vport->phba;
James Smart466e8402015-05-21 13:55:28 -0400260
James Smartc6adba12020-11-15 11:26:34 -0800261 spin_lock_irqsave(&ndlp->lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400262 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
James Smartc6adba12020-11-15 11:26:34 -0800263 spin_unlock_irqrestore(&ndlp->lock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500264
James Smarta93ff372010-10-22 11:06:08 -0400265 if (phba->sli_rev == LPFC_SLI_REV4)
266 fcf_inuse = lpfc_fcf_inuse(phba);
267
James Smart858c9f62007-06-17 19:56:39 -0500268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smartc6adba12020-11-15 11:26:34 -0800269 "rport devlosstmo:did:x%x type:x%x id:x%x",
270 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
James Smart858c9f62007-06-17 19:56:39 -0500271
James Smart34f5ad82012-08-03 12:35:03 -0400272 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart52edb2c2020-11-15 11:26:35 -0800273 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
James Smartc6adba12020-11-15 11:26:34 -0800274 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
James Smart52edb2c2020-11-15 11:26:35 -0800275 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
James Smarta8adb832007-10-27 13:37:53 -0400276
James Smart52edb2c2020-11-15 11:26:35 -0800277 /* If the driver is recovering the rport, ignore devloss. */
James Smartd7c255b2008-08-24 21:50:00 -0400278 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
279 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
280 "0284 Devloss timeout Ignored on "
281 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
282 "NPort x%x\n",
283 *name, *(name+1), *(name+2), *(name+3),
284 *(name+4), *(name+5), *(name+6), *(name+7),
285 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400286 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400287 }
James Smart858c9f62007-06-17 19:56:39 -0500288
James Smart52edb2c2020-11-15 11:26:35 -0800289 /* Fabric nodes are done. */
290 if (ndlp->nlp_type & NLP_FABRIC) {
291 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400292 return fcf_inuse;
James Smart52edb2c2020-11-15 11:26:35 -0800293 }
James Smart82085712007-04-25 09:52:41 -0400294
dea31012005-04-17 16:05:31 -0500295 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400296 warn_on = 1;
James Smart078c68b2021-04-11 18:31:12 -0700297 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500298 }
James Smartc01f3202006-08-18 17:47:08 -0400299
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400300 if (warn_on) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700301 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400302 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400303 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
304 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400305 *name, *(name+1), *(name+2), *(name+3),
306 *(name+4), *(name+5), *(name+6), *(name+7),
307 ndlp->nlp_DID, ndlp->nlp_flag,
308 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400309 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -0700310 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400311 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400312 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
313 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400314 *name, *(name+1), *(name+2), *(name+3),
315 *(name+4), *(name+5), *(name+6), *(name+7),
316 ndlp->nlp_DID, ndlp->nlp_flag,
317 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400318 }
319
James Smart52edb2c2020-11-15 11:26:35 -0800320 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
James Smart2e0fef82007-06-17 19:56:36 -0500321 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400322
James Smarta93ff372010-10-22 11:06:08 -0400323 return fcf_inuse;
324}
325
326/**
327 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
328 * @phba: Pointer to hba context object.
329 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
330 * @nlp_did: remote node identifer with devloss timeout.
331 *
332 * This function is called from the worker thread after invoking devloss
333 * timeout handler and releasing the reference count for the ndlp with
334 * which the devloss timeout was handled for SLI4 host. For the devloss
335 * timeout of the last remote node which had been in use of FCF, when this
336 * routine is invoked, it shall be guaranteed that none of the remote are
337 * in-use of FCF. When devloss timeout to the last remote using the FCF,
338 * if the FIP engine is neither in FCF table scan process nor roundrobin
339 * failover process, the in-use FCF shall be unregistered. If the FIP
340 * engine is in FCF discovery process, the devloss timeout state shall
341 * be set for either the FCF table scan process or roundrobin failover
342 * process to unregister the in-use FCF.
343 **/
344static void
345lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
346 uint32_t nlp_did)
347{
348 /* If devloss timeout happened to a remote node when FCF had no
349 * longer been in-use, do nothing.
350 */
351 if (!fcf_inuse)
352 return;
353
354 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
355 spin_lock_irq(&phba->hbalock);
356 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
357 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
358 spin_unlock_irq(&phba->hbalock);
359 return;
360 }
361 phba->hba_flag |= HBA_DEVLOSS_TMO;
362 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
363 "2847 Last remote node (x%x) using "
364 "FCF devloss tmo\n", nlp_did);
365 }
366 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
367 spin_unlock_irq(&phba->hbalock);
368 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
369 "2868 Devloss tmo to FCF rediscovery "
370 "in progress\n");
371 return;
372 }
373 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
374 spin_unlock_irq(&phba->hbalock);
375 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
376 "2869 Devloss tmo to idle FIP engine, "
377 "unreg in-use FCF and rescan.\n");
378 /* Unregister in-use FCF and rescan */
379 lpfc_unregister_fcf_rescan(phba);
380 return;
381 }
382 spin_unlock_irq(&phba->hbalock);
383 if (phba->hba_flag & FCF_TS_INPROG)
384 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
385 "2870 FCF table scan in progress\n");
386 if (phba->hba_flag & FCF_RR_INPROG)
387 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
388 "2871 FLOGI roundrobin FCF failover "
389 "in progress\n");
390 }
James Smart6fb120a2009-05-22 14:52:59 -0400391 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500392}
James Smartc01f3202006-08-18 17:47:08 -0400393
James Smartea2151b2008-09-07 11:52:10 -0400394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400396 * @phba: Pointer to hba context object.
397 *
398 * This function is called from the functions which need to post
399 * events from interrupt context. This function allocates data
400 * structure required for posting event. It also keeps track of
401 * number of events pending and prevent event storm when there are
402 * too many events.
403 **/
404struct lpfc_fast_path_event *
405lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
406 struct lpfc_fast_path_event *ret;
407
408 /* If there are lot of fast event do not exhaust memory due to this */
409 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
410 return NULL;
411
412 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
413 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400414 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400415 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400416 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
417 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
418 }
James Smartea2151b2008-09-07 11:52:10 -0400419 return ret;
420}
421
422/**
James Smart3621a712009-04-06 18:47:14 -0400423 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400424 * @phba: Pointer to hba context object.
425 * @evt: Event object which need to be freed.
426 *
427 * This function frees the data structure required for posting
428 * events.
429 **/
430void
431lpfc_free_fast_evt(struct lpfc_hba *phba,
432 struct lpfc_fast_path_event *evt) {
433
434 atomic_dec(&phba->fast_event_count);
435 kfree(evt);
436}
437
438/**
James Smart3621a712009-04-06 18:47:14 -0400439 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400440 * @phba: Pointer to hba context object.
441 * @evtp: Event data structure.
442 *
443 * This function is called from worker thread, when the interrupt
444 * context need to post an event. This function posts the event
445 * to fc transport netlink interface.
446 **/
447static void
448lpfc_send_fastpath_evt(struct lpfc_hba *phba,
449 struct lpfc_work_evt *evtp)
450{
451 unsigned long evt_category, evt_sub_category;
452 struct lpfc_fast_path_event *fast_evt_data;
453 char *evt_data;
454 uint32_t evt_data_size;
455 struct Scsi_Host *shost;
456
457 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
458 work_evt);
459
460 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
461 evt_sub_category = (unsigned long) fast_evt_data->un.
462 fabric_evt.subcategory;
463 shost = lpfc_shost_from_vport(fast_evt_data->vport);
464 if (evt_category == FC_REG_FABRIC_EVENT) {
465 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
466 evt_data = (char *) &fast_evt_data->un.read_check_error;
467 evt_data_size = sizeof(fast_evt_data->un.
468 read_check_error);
469 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500470 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400471 evt_data = (char *) &fast_evt_data->un.fabric_evt;
472 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
473 } else {
474 lpfc_free_fast_evt(phba, fast_evt_data);
475 return;
476 }
477 } else if (evt_category == FC_REG_SCSI_EVENT) {
478 switch (evt_sub_category) {
479 case LPFC_EVENT_QFULL:
480 case LPFC_EVENT_DEVBSY:
481 evt_data = (char *) &fast_evt_data->un.scsi_evt;
482 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
483 break;
484 case LPFC_EVENT_CHECK_COND:
485 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
486 evt_data_size = sizeof(fast_evt_data->un.
487 check_cond_evt);
488 break;
489 case LPFC_EVENT_VARQUEDEPTH:
490 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
491 evt_data_size = sizeof(fast_evt_data->un.
492 queue_depth_evt);
493 break;
494 default:
495 lpfc_free_fast_evt(phba, fast_evt_data);
496 return;
497 }
498 } else {
499 lpfc_free_fast_evt(phba, fast_evt_data);
500 return;
501 }
502
James Smart895427b2017-02-12 13:52:30 -0800503 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
504 fc_host_post_vendor_event(shost,
505 fc_get_event_number(),
506 evt_data_size,
507 evt_data,
508 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400509
510 lpfc_free_fast_evt(phba, fast_evt_data);
511 return;
512}
513
dea31012005-04-17 16:05:31 -0500514static void
James Smart2e0fef82007-06-17 19:56:36 -0500515lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500516{
517 struct lpfc_work_evt *evtp = NULL;
518 struct lpfc_nodelist *ndlp;
519 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400520 int fcf_inuse;
521 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500522
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(&phba->hbalock);
524 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500525 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
526 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500527 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500528 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500529 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500530 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500531 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500532 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500533 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500534 /* decrement the node reference count held
535 * for this queued work
536 */
537 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500538 break;
James Smart858c9f62007-06-17 19:56:39 -0500539 case LPFC_EVT_DEV_LOSS:
540 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400541 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500542 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500543 /* decrement the node reference count held for
544 * this queued work
545 */
James Smarta93ff372010-10-22 11:06:08 -0400546 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500547 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400548 if (phba->sli_rev == LPFC_SLI_REV4)
549 lpfc_sli4_post_dev_loss_tmo_handler(phba,
550 fcf_inuse,
551 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500552 break;
James Smarte7dab162020-10-20 13:27:12 -0700553 case LPFC_EVT_RECOVER_PORT:
554 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
555 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
556 free_evt = 0;
557 /* decrement the node reference count held for
558 * this queued work
559 */
560 lpfc_nlp_put(ndlp);
561 break;
dea31012005-04-17 16:05:31 -0500562 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500563 if (phba->link_state < LPFC_LINK_DOWN)
564 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500565 else
James Smart2e0fef82007-06-17 19:56:36 -0500566 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500567 complete((struct completion *)(evtp->evt_arg2));
568 break;
James Smart46fa3112007-04-25 09:51:45 -0400569 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500570 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400571 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400572 *(int *)(evtp->evt_arg1) = 0;
573 complete((struct completion *)(evtp->evt_arg2));
574 break;
575 case LPFC_EVT_OFFLINE:
576 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500577 lpfc_sli_brdrestart(phba);
578 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400579 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
580 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500581 complete((struct completion *)(evtp->evt_arg2));
582 break;
583 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400584 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500585 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500586 lpfc_sli_brdreset(phba);
587 lpfc_hba_down_post(phba);
588 *(int *)(evtp->evt_arg1) =
589 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400590 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500591 complete((struct completion *)(evtp->evt_arg2));
592 break;
593 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400594 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500595 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500596 = (phba->pport->stopped)
597 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400598 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500599 complete((struct completion *)(evtp->evt_arg2));
600 break;
James Smartea2151b2008-09-07 11:52:10 -0400601 case LPFC_EVT_FASTPATH_MGMT_EVT:
602 lpfc_send_fastpath_evt(phba, evtp);
603 free_evt = 0;
604 break;
James Smart78730cf2010-04-06 15:06:30 -0400605 case LPFC_EVT_RESET_HBA:
606 if (!(phba->pport->load_flag & FC_UNLOADING))
607 lpfc_reset_hba(phba);
608 break;
dea31012005-04-17 16:05:31 -0500609 }
610 if (free_evt)
611 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500612 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500613 }
James Smart2e0fef82007-06-17 19:56:36 -0500614 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500615
616}
617
James Smart311464e2007-08-02 11:10:37 -0400618static void
James Smart2e0fef82007-06-17 19:56:36 -0500619lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500620{
621 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500622 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400623 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400624 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400625 int i;
dea31012005-04-17 16:05:31 -0500626
James Smart2e0fef82007-06-17 19:56:36 -0500627 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500628 ha_copy = phba->work_ha;
629 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500630 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500631
James Smartda0436e2009-05-22 14:51:39 -0400632 /* First, try to post the next mailbox command to SLI4 device */
633 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
634 lpfc_sli4_post_async_mbox(phba);
635
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500636 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400637 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500638 lpfc_handle_eratt(phba);
639
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500640 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500641 lpfc_sli_handle_mb_event(phba);
642
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500643 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500644 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400645
James Smartda0436e2009-05-22 14:51:39 -0400646 /* Process SLI4 events */
647 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500648 if (phba->hba_flag & HBA_RRQ_ACTIVE)
649 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400650 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
651 lpfc_sli4_els_xri_abort_event_proc(phba);
652 if (phba->hba_flag & ASYNC_EVENT)
653 lpfc_sli4_async_event_proc(phba);
654 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
655 spin_lock_irq(&phba->hbalock);
656 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
657 spin_unlock_irq(&phba->hbalock);
658 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
659 }
James Smartecfd03c2010-02-12 14:41:27 -0500660 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
661 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400662 }
663
James Smart549e55c2007-08-02 11:09:51 -0400664 vports = lpfc_create_vport_work_array(phba);
665 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400666 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400667 /*
668 * We could have no vports in array if unloading, so if
669 * this happens then just use the pport
670 */
671 if (vports[i] == NULL && i == 0)
672 vport = phba->pport;
673 else
674 vport = vports[i];
675 if (vport == NULL)
676 break;
James Smart58da1ff2008-04-07 10:15:56 -0400677 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400678 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400679 vport->work_port_events &= ~work_port_events;
680 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400681 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400682 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400683 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400684 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400685 if (work_port_events & WORKER_HB_TMO)
686 lpfc_hb_timeout_handler(phba);
687 if (work_port_events & WORKER_MBOX_TMO)
688 lpfc_mbox_timeout_handler(phba);
689 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
690 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400691 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
692 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500693 if (work_port_events & WORKER_DELAYED_DISC_TMO)
694 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500695 }
James Smart09372822008-01-11 01:52:54 -0500696 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500697
James Smart895427b2017-02-12 13:52:30 -0800698 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500699 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
700 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700701 if (pring && (status & HA_RXMASK ||
702 pring->flag & LPFC_DEFERRED_RING_EVENT ||
703 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400704 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500705 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800706 /* Preserve legacy behavior. */
707 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
708 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500709 } else {
James Smart15498dc2019-09-21 20:58:59 -0700710 /* Driver could have abort request completed in queue
711 * when link goes down. Allow for this transition.
712 */
713 if (phba->link_state >= LPFC_LINK_DOWN ||
James Smartae9e28f2017-05-15 15:20:51 -0700714 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500715 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
716 lpfc_sli_handle_slow_ring_event(phba, pring,
717 (status &
718 HA_RXMASK));
719 }
James Smart858c9f62007-06-17 19:56:39 -0500720 }
James Smartdc19e3b2018-05-24 21:08:57 -0700721 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400722 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500723 /*
724 * Turn on Ring interrupts
725 */
James Smart3772a992009-05-22 14:50:54 -0400726 if (phba->sli_rev <= LPFC_SLI_REV3) {
727 spin_lock_irq(&phba->hbalock);
728 control = readl(phba->HCregaddr);
729 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
730 lpfc_debugfs_slow_ring_trc(phba,
731 "WRK Enable ring: cntl:x%x hacopy:x%x",
732 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400733
James Smart3772a992009-05-22 14:50:54 -0400734 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
735 writel(control, phba->HCregaddr);
736 readl(phba->HCregaddr); /* flush */
737 } else {
738 lpfc_debugfs_slow_ring_trc(phba,
739 "WRK Ring ok: cntl:x%x hacopy:x%x",
740 control, ha_copy, 0);
741 }
742 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500743 }
744 }
James Smart2e0fef82007-06-17 19:56:36 -0500745 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500746}
747
dea31012005-04-17 16:05:31 -0500748int
749lpfc_do_work(void *p)
750{
751 struct lpfc_hba *phba = p;
752 int rc;
dea31012005-04-17 16:05:31 -0500753
Dongsheng Yang8698a742014-03-11 18:09:12 +0800754 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400755 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400756 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500757
James Smart3a55b532008-12-04 22:38:54 -0500758 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400759 /* wait and check worker queue activities */
760 rc = wait_event_interruptible(phba->work_waitq,
761 (test_and_clear_bit(LPFC_DATA_READY,
762 &phba->data_flags)
763 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500764 /* Signal wakeup shall terminate the worker thread */
765 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700766 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3a55b532008-12-04 22:38:54 -0500767 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500768 break;
James Smart3a55b532008-12-04 22:38:54 -0500769 }
dea31012005-04-17 16:05:31 -0500770
James Smart5e9d9b82008-06-14 22:52:53 -0400771 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500772 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500773 }
James Smart3a55b532008-12-04 22:38:54 -0500774 phba->worker_thread = NULL;
775 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
776 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500777 return 0;
778}
779
780/*
781 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300782 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500783 * embedding it in the IOCB.
784 */
785int
James Smart2e0fef82007-06-17 19:56:36 -0500786lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500787 uint32_t evt)
788{
789 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500790 unsigned long flags;
dea31012005-04-17 16:05:31 -0500791
792 /*
793 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
794 * be queued to worker thread for processing
795 */
James Smart92d7f7b2007-06-17 19:56:38 -0500796 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500797 if (!evtp)
798 return 0;
799
800 evtp->evt_arg1 = arg1;
801 evtp->evt_arg2 = arg2;
802 evtp->evt = evt;
803
James Smarted957682007-06-17 19:56:37 -0500804 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400805 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500806 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500807
James Smart5e9d9b82008-06-14 22:52:53 -0400808 lpfc_worker_wake_up(phba);
809
dea31012005-04-17 16:05:31 -0500810 return 1;
811}
812
James Smart92d7f7b2007-06-17 19:56:38 -0500813void
814lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
815{
James Smart09372822008-01-11 01:52:54 -0500816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500817 struct lpfc_hba *phba = vport->phba;
818 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500819
820 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
821 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
822 continue;
James Smartb3f2e672020-11-15 11:26:37 -0800823
James Smart98c9ea52007-10-27 13:37:33 -0400824 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
James Smartb3f2e672020-11-15 11:26:37 -0800825 ((vport->port_type == LPFC_NPIV_PORT) &&
826 ((ndlp->nlp_DID == NameServer_DID) ||
James Smartfe83e3b2021-05-14 12:55:54 -0700827 (ndlp->nlp_DID == FDMI_DID) ||
828 (ndlp->nlp_DID == Fabric_Cntl_DID))))
James Smart92d7f7b2007-06-17 19:56:38 -0500829 lpfc_unreg_rpi(vport, ndlp);
830
831 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400832 if ((phba->sli_rev < LPFC_SLI_REV4) &&
833 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500834 continue;
James Smart4c2805a2020-03-31 09:50:10 -0700835
836 /* Notify transport of connectivity loss to trigger cleanup. */
837 if (phba->nvmet_support &&
838 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
839 lpfc_nvmet_invalidate_host(phba, ndlp);
840
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -0400841 lpfc_disc_state_machine(vport, ndlp, NULL,
842 remove
843 ? NLP_EVT_DEVICE_RM
844 : NLP_EVT_DEVICE_RECOVERY);
James Smart92d7f7b2007-06-17 19:56:38 -0500845 }
846 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400847 if (phba->sli_rev == LPFC_SLI_REV4)
848 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500849 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500850 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500851 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500852 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500853 }
854}
855
James Smart87af33f2007-10-27 13:37:43 -0400856void
James Smart98c9ea52007-10-27 13:37:33 -0400857lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500858{
James Smart695a8142010-01-26 23:08:03 -0500859 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
860
James Smart45ed1192009-10-02 15:17:02 -0400861 /* Cleanup any outstanding received buffers */
862 lpfc_cleanup_rcv_buffers(vport);
863
James Smart92d7f7b2007-06-17 19:56:38 -0500864 /* Cleanup any outstanding RSCN activity */
865 lpfc_els_flush_rscn(vport);
866
867 /* Cleanup any outstanding ELS commands */
868 lpfc_els_flush_cmd(vport);
869
870 lpfc_cleanup_rpis(vport, 0);
871
James Smart92d7f7b2007-06-17 19:56:38 -0500872 /* Turn off discovery timer if its running */
873 lpfc_can_disctmo(vport);
874}
875
James Smart3772a992009-05-22 14:50:54 -0400876void
James Smart98c9ea52007-10-27 13:37:33 -0400877lpfc_linkdown_port(struct lpfc_vport *vport)
878{
879 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
880
James Smartf6e84792019-01-28 11:14:38 -0800881 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -0800882 fc_host_post_event(shost, fc_get_event_number(),
883 FCH_EVT_LINKDOWN, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400884
885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
886 "Link Down: state:x%x rtry:x%x flg:x%x",
887 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
888
889 lpfc_port_link_failure(vport);
890
James Smart92494142011-02-16 12:39:44 -0500891 /* Stop delayed Nport discovery */
892 spin_lock_irq(shost->host_lock);
893 vport->fc_flag &= ~FC_DISC_DELAYED;
894 spin_unlock_irq(shost->host_lock);
895 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -0400896}
897
dea31012005-04-17 16:05:31 -0500898int
James Smart685f0bf2007-04-25 09:53:08 -0400899lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500900{
James Smart2e0fef82007-06-17 19:56:36 -0500901 struct lpfc_vport *vport = phba->pport;
902 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400903 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400904 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400905 int i;
dea31012005-04-17 16:05:31 -0500906
James Smart19193ff2019-03-12 16:30:25 -0700907 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500908 return 0;
James Smart19193ff2019-03-12 16:30:25 -0700909
James Smartaacc20e2009-12-21 17:02:51 -0500910 /* Block all SCSI stack I/Os */
911 lpfc_scsi_dev_block(phba);
912
James Smart0a9e9682018-11-29 16:09:36 -0800913 phba->defer_flogi_acc_flag = false;
914
James Smart2e0fef82007-06-17 19:56:36 -0500915 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500916 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500917 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500918 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500919 phba->link_state = LPFC_LINK_DOWN;
James Smart2977a092018-12-13 15:17:52 -0800920 if (phba->sli4_hba.conf_trunk) {
921 phba->trunk_link.link0.state = 0;
922 phba->trunk_link.link1.state = 0;
923 phba->trunk_link.link2.state = 0;
924 phba->trunk_link.link3.state = 0;
James Smart845d0322019-08-14 16:57:01 -0700925 phba->sli4_hba.link_state.logical_speed =
926 LPFC_LINK_SPEED_UNKNOWN;
James Smart2977a092018-12-13 15:17:52 -0800927 }
James Smart72100cc2010-02-12 14:43:01 -0500928 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500929 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500930 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500931 }
James Smart549e55c2007-08-02 11:09:51 -0400932 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -0800933 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -0400934 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400935 /* Issue a LINK DOWN event to all nodes */
936 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -0800937
938 vports[i]->fc_myDID = 0;
939
James Smartf6e84792019-01-28 11:14:38 -0800940 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
941 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -0800942 if (phba->nvmet_support)
943 lpfc_nvmet_update_targetport(phba);
944 else
James Smart8c258642017-02-12 13:52:36 -0800945 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -0800946 }
James Smart549e55c2007-08-02 11:09:51 -0400947 }
James Smart895427b2017-02-12 13:52:30 -0800948 }
James Smart09372822008-01-11 01:52:54 -0500949 lpfc_destroy_vport_work_array(phba, vports);
James Smartc95a3b42019-03-12 16:30:07 -0700950
951 /* Clean up any SLI3 firmware default rpi's */
952 if (phba->sli_rev > LPFC_SLI_REV3)
953 goto skip_unreg_did;
954
James Smart2e0fef82007-06-17 19:56:36 -0500955 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
956 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400957 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500958 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500959 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400960 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500961 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500962 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500963 }
964 }
965
James Smartc95a3b42019-03-12 16:30:07 -0700966 skip_unreg_did:
dea31012005-04-17 16:05:31 -0500967 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500968 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -0500969 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
970 if (mb) {
dea31012005-04-17 16:05:31 -0500971 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500972 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500973 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400974 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500975 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500976 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500977 }
978 }
James Smart2e0fef82007-06-17 19:56:36 -0500979 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500980 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smartd496b9a2018-10-23 13:41:08 -0700981 phba->pport->rcv_flogi_cnt = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500982 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500983 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500984 return 0;
dea31012005-04-17 16:05:31 -0500985}
986
James Smart92d7f7b2007-06-17 19:56:38 -0500987static void
988lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500989{
James Smart92d7f7b2007-06-17 19:56:38 -0500990 struct lpfc_nodelist *ndlp;
991
992 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarta3da8252018-03-05 12:04:06 -0800993 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smart307e3382020-11-15 11:26:30 -0800994
James Smart92d7f7b2007-06-17 19:56:38 -0500995 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
996 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500997 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500998 /* On Linkup its safe to clean up the ndlp
999 * from Fabric connections.
1000 */
James Smart92d7f7b2007-06-17 19:56:38 -05001001 if (ndlp->nlp_DID != Fabric_DID)
1002 lpfc_unreg_rpi(vport, ndlp);
1003 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1004 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -05001005 /* Fail outstanding IO now since device is
1006 * marked for PLOGI.
1007 */
James Smart92d7f7b2007-06-17 19:56:38 -05001008 lpfc_unreg_rpi(vport, ndlp);
1009 }
1010 }
1011}
1012
1013static void
1014lpfc_linkup_port(struct lpfc_vport *vport)
1015{
1016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001017 struct lpfc_hba *phba = vport->phba;
1018
1019 if ((vport->load_flag & FC_UNLOADING) != 0)
1020 return;
1021
James Smart858c9f62007-06-17 19:56:39 -05001022 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1023 "Link Up: top:x%x speed:x%x flg:x%x",
1024 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1025
James Smart92d7f7b2007-06-17 19:56:38 -05001026 /* If NPIV is not enabled, only bring the physical port up */
1027 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1028 (vport != phba->pport))
1029 return;
dea31012005-04-17 16:05:31 -05001030
James Smartf6e84792019-01-28 11:14:38 -08001031 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08001032 fc_host_post_event(shost, fc_get_event_number(),
1033 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001034
James Smart2e0fef82007-06-17 19:56:36 -05001035 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001036 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1037 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1038 vport->fc_flag |= FC_NDISC_ACTIVE;
1039 vport->fc_ns_retry = 0;
1040 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001041
James Smartb3f2e672020-11-15 11:26:37 -08001042 lpfc_linkup_cleanup_nodes(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001043}
1044
1045static int
1046lpfc_linkup(struct lpfc_hba *phba)
1047{
James Smart549e55c2007-08-02 11:09:51 -04001048 struct lpfc_vport **vports;
1049 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001050 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001051
1052 phba->link_state = LPFC_LINK_UP;
1053
1054 /* Unblock fabric iocbs if they are blocked */
1055 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1056 del_timer_sync(&phba->fabric_block_timer);
1057
James Smart549e55c2007-08-02 11:09:51 -04001058 vports = lpfc_create_vport_work_array(phba);
1059 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001060 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001061 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001062 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001063
James Smartd496b9a2018-10-23 13:41:08 -07001064 /* Clear the pport flogi counter in case the link down was
1065 * absorbed without an ACQE. No lock here - in worker thread
1066 * and discovery is synchronized.
1067 */
1068 spin_lock_irq(shost->host_lock);
1069 phba->pport->rcv_flogi_cnt = 0;
1070 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001071
1072 /* reinitialize initial FLOGI flag */
1073 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1074 phba->defer_flogi_acc_flag = false;
1075
dea31012005-04-17 16:05:31 -05001076 return 0;
1077}
1078
1079/*
1080 * This routine handles processing a CLEAR_LA mailbox
1081 * command upon completion. It is setup in the LPFC_MBOXQ
1082 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001083 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001084 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001085static void
James Smart2e0fef82007-06-17 19:56:36 -05001086lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001087{
James Smart2e0fef82007-06-17 19:56:36 -05001088 struct lpfc_vport *vport = pmb->vport;
1089 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1090 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001091 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001092 uint32_t control;
1093
dea31012005-04-17 16:05:31 -05001094 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001095 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1096 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001097
1098 /* Check for error */
1099 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001100 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
Dick Kennedy372c1872020-06-30 14:50:00 -07001101 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001102 "0320 CLEAR_LA mbxStatus error x%x hba "
1103 "state x%x\n",
1104 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001105 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001106 goto out;
1107 }
1108
James Smart92d7f7b2007-06-17 19:56:38 -05001109 if (vport->port_type == LPFC_PHYSICAL_PORT)
1110 phba->link_state = LPFC_HBA_READY;
1111
1112 spin_lock_irq(&phba->hbalock);
1113 psli->sli_flag |= LPFC_PROCESS_LA;
1114 control = readl(phba->HCregaddr);
1115 control |= HC_LAINT_ENA;
1116 writel(control, phba->HCregaddr);
1117 readl(phba->HCregaddr); /* flush */
1118 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001119 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001120 return;
dea31012005-04-17 16:05:31 -05001121
dea31012005-04-17 16:05:31 -05001122out:
1123 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001124 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1125 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001126 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001127
James Smart2e0fef82007-06-17 19:56:36 -05001128 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001129 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001130 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001131
James Smart2e0fef82007-06-17 19:56:36 -05001132 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001133
1134 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001135
1136 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001137 psli->sli_flag |= LPFC_PROCESS_LA;
1138 control = readl(phba->HCregaddr);
1139 control |= HC_LAINT_ENA;
1140 writel(control, phba->HCregaddr);
1141 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001142 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001143
1144 return;
1145}
1146
James Smartd6de08c2015-12-16 18:11:53 -05001147void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001148lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001149{
James Smart2e0fef82007-06-17 19:56:36 -05001150 struct lpfc_vport *vport = pmb->vport;
James Smart7f048392020-09-11 13:01:47 -07001151 LPFC_MBOXQ_t *sparam_mb;
1152 struct lpfc_dmabuf *sparam_mp;
Dan Carpenter0be31092021-01-25 11:44:34 +03001153 u16 status = pmb->u.mb.mbxStatus;
James Smart7f048392020-09-11 13:01:47 -07001154 int rc;
dea31012005-04-17 16:05:31 -05001155
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001156 mempool_free(pmb, phba->mbox_mem_pool);
1157
Dan Carpenter0be31092021-01-25 11:44:34 +03001158 if (status)
1159 goto out;
1160
James Smart1b511972011-12-13 13:23:09 -05001161 /* don't perform discovery for SLI4 loopback diagnostic test */
1162 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1163 !(phba->hba_flag & HBA_FCOE_MODE) &&
1164 (phba->link_flag & LS_LOOPBACK_MODE))
1165 return;
1166
James Smart76a95d72010-11-20 23:11:48 -05001167 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001168 vport->fc_flag & FC_PUBLIC_LOOP &&
1169 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001170 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001171 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001172 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1173 */
James Smart2e0fef82007-06-17 19:56:36 -05001174 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001175 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001176 }
dea31012005-04-17 16:05:31 -05001177
James Smart2e0fef82007-06-17 19:56:36 -05001178 /* Start discovery by sending a FLOGI. port_state is identically
James Smart7f048392020-09-11 13:01:47 -07001179 * LPFC_FLOGI while waiting for FLOGI cmpl.
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001180 */
James Smart835214f2020-01-27 16:23:03 -08001181 if (vport->port_state != LPFC_FLOGI) {
James Smart7f048392020-09-11 13:01:47 -07001182 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1183 * bb-credit recovery is in place.
1184 */
1185 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1186 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1187 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1188 GFP_KERNEL);
1189 if (!sparam_mb)
1190 goto sparam_out;
1191
1192 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1193 if (rc) {
1194 mempool_free(sparam_mb, phba->mbox_mem_pool);
1195 goto sparam_out;
1196 }
1197 sparam_mb->vport = vport;
1198 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1199 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1200 if (rc == MBX_NOT_FINISHED) {
1201 sparam_mp = (struct lpfc_dmabuf *)
1202 sparam_mb->ctx_buf;
1203 lpfc_mbuf_free(phba, sparam_mp->virt,
1204 sparam_mp->phys);
1205 kfree(sparam_mp);
1206 sparam_mb->ctx_buf = NULL;
1207 mempool_free(sparam_mb, phba->mbox_mem_pool);
1208 goto sparam_out;
1209 }
1210
1211 phba->hba_flag |= HBA_DEFER_FLOGI;
1212 } else {
James Smart835214f2020-01-27 16:23:03 -08001213 lpfc_initial_flogi(vport);
James Smart7f048392020-09-11 13:01:47 -07001214 }
James Smart835214f2020-01-27 16:23:03 -08001215 } else {
1216 if (vport->fc_flag & FC_PT2PT)
1217 lpfc_disc_start(vport);
1218 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001219 return;
dea31012005-04-17 16:05:31 -05001220
1221out:
Dick Kennedy372c1872020-06-30 14:50:00 -07001222 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
Dan Carpenter0be31092021-01-25 11:44:34 +03001223 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1224 status, vport->port_state);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001225
Dan Carpenter0be31092021-01-25 11:44:34 +03001226sparam_out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001227 lpfc_linkdown(phba);
1228
Dick Kennedy372c1872020-06-30 14:50:00 -07001229 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001230 "0200 CONFIG_LINK bad hba state x%x\n",
1231 vport->port_state);
dea31012005-04-17 16:05:31 -05001232
James Smart92d7f7b2007-06-17 19:56:38 -05001233 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001234 return;
1235}
1236
James Smart7d791df2011-07-22 18:37:52 -04001237/**
1238 * lpfc_sli4_clear_fcf_rr_bmask
Lee Jonese415f2a2020-07-23 13:24:08 +01001239 * @phba: pointer to the struct lpfc_hba for this port.
James Smart7d791df2011-07-22 18:37:52 -04001240 * This fucnction resets the round robin bit mask and clears the
1241 * fcf priority list. The list deletions are done while holding the
1242 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1243 * from the lpfc_fcf_pri record.
1244 **/
1245void
1246lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1247{
1248 struct lpfc_fcf_pri *fcf_pri;
1249 struct lpfc_fcf_pri *next_fcf_pri;
1250 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1251 spin_lock_irq(&phba->hbalock);
1252 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1253 &phba->fcf.fcf_pri_list, list) {
1254 list_del_init(&fcf_pri->list);
1255 fcf_pri->fcf_rec.flag = 0;
1256 }
1257 spin_unlock_irq(&phba->hbalock);
1258}
dea31012005-04-17 16:05:31 -05001259static void
James Smart6fb120a2009-05-22 14:52:59 -04001260lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1261{
1262 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001263
1264 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001265 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1266 "2017 REG_FCFI mbxStatus error x%x "
1267 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1268 vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001269 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001270 }
1271
1272 /* Start FCoE discovery by sending a FLOGI. */
1273 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1274 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001275 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001276 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001277 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001278
James Smart32b97932009-07-19 10:01:21 -04001279 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001280 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1281 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001282 goto fail_out;
1283
1284 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001285 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001286 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001287 phba->hba_flag &= ~FCF_TS_INPROG;
1288 if (vport->port_state != LPFC_FLOGI) {
1289 phba->hba_flag |= FCF_RR_INPROG;
1290 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001291 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001292 goto out;
1293 }
1294 spin_unlock_irq(&phba->hbalock);
1295 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001296
James Smarta93ff372010-10-22 11:06:08 -04001297fail_out:
1298 spin_lock_irq(&phba->hbalock);
1299 phba->hba_flag &= ~FCF_RR_INPROG;
1300 spin_unlock_irq(&phba->hbalock);
1301out:
James Smart6fb120a2009-05-22 14:52:59 -04001302 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001303}
1304
1305/**
1306 * lpfc_fab_name_match - Check if the fcf fabric name match.
1307 * @fab_name: pointer to fabric name.
1308 * @new_fcf_record: pointer to fcf record.
1309 *
1310 * This routine compare the fcf record's fabric name with provided
1311 * fabric name. If the fabric name are identical this function
1312 * returns 1 else return 0.
1313 **/
1314static uint32_t
1315lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1316{
James Smartecfd03c2010-02-12 14:41:27 -05001317 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001318 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001319 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1320 return 0;
1321 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1322 return 0;
1323 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1324 return 0;
1325 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1326 return 0;
1327 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1328 return 0;
1329 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1330 return 0;
1331 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1332 return 0;
1333 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001334}
1335
1336/**
James Smart8fa38512009-07-19 10:01:03 -04001337 * lpfc_sw_name_match - Check if the fcf switch name match.
Lee Jonese415f2a2020-07-23 13:24:08 +01001338 * @sw_name: pointer to switch name.
James Smart8fa38512009-07-19 10:01:03 -04001339 * @new_fcf_record: pointer to fcf record.
1340 *
1341 * This routine compare the fcf record's switch name with provided
1342 * switch name. If the switch name are identical this function
1343 * returns 1 else return 0.
1344 **/
1345static uint32_t
1346lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1347{
James Smartecfd03c2010-02-12 14:41:27 -05001348 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001349 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001350 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1351 return 0;
1352 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1353 return 0;
1354 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1355 return 0;
1356 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1357 return 0;
1358 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1359 return 0;
1360 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1361 return 0;
1362 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1363 return 0;
1364 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001365}
1366
1367/**
James Smart6fb120a2009-05-22 14:52:59 -04001368 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001369 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001370 * @new_fcf_record: pointer to fcf record.
1371 *
1372 * This routine compare the fcf record's mac address with HBA's
1373 * FCF mac address. If the mac addresses are identical this function
1374 * returns 1 else return 0.
1375 **/
1376static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001377lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001378{
James Smartecfd03c2010-02-12 14:41:27 -05001379 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001380 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001381 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1382 return 0;
1383 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1384 return 0;
1385 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1386 return 0;
1387 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1388 return 0;
1389 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1390 return 0;
1391 return 1;
1392}
1393
1394static bool
1395lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1396{
1397 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001398}
1399
1400/**
James Smart7d791df2011-07-22 18:37:52 -04001401 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1402 * @phba: pointer to lpfc hba data structure.
1403 * @fcf_index: Index for the lpfc_fcf_record.
1404 * @new_fcf_record: pointer to hba fcf record.
1405 *
1406 * This routine updates the driver FCF priority record from the new HBA FCF
Dick Kennedy88acb4d2020-05-01 14:43:07 -07001407 * record. The hbalock is asserted held in the code path calling this
1408 * routine.
James Smart7d791df2011-07-22 18:37:52 -04001409 **/
1410static void
1411__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1412 struct fcf_record *new_fcf_record
1413 )
1414{
1415 struct lpfc_fcf_pri *fcf_pri;
1416
1417 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1418 fcf_pri->fcf_rec.fcf_index = fcf_index;
1419 /* FCF record priority */
1420 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1421
1422}
1423
1424/**
James Smart6fb120a2009-05-22 14:52:59 -04001425 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
Lee Jonese415f2a2020-07-23 13:24:08 +01001426 * @fcf_rec: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001427 * @new_fcf_record: pointer to fcf record.
1428 *
1429 * This routine copies the FCF information from the FCF
1430 * record to lpfc_hba data structure.
1431 **/
1432static void
James Smartecfd03c2010-02-12 14:41:27 -05001433lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1434 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001435{
James Smartecfd03c2010-02-12 14:41:27 -05001436 /* Fabric name */
1437 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001438 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001439 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001440 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001441 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001442 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001443 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001444 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001445 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001446 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001447 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001448 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001449 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001450 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001451 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001452 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001453 /* Mac address */
1454 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1455 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1456 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1457 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1458 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1459 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1460 /* FCF record index */
1461 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1462 /* FCF record priority */
1463 fcf_rec->priority = new_fcf_record->fip_priority;
1464 /* Switch name */
1465 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001466 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001467 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001468 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001469 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001470 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001471 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001472 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001473 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001474 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001475 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001476 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001477 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001478 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001479 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001480 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001481}
1482
1483/**
Lee Jones3884ce12021-03-03 14:46:28 +00001484 * __lpfc_update_fcf_record - Update driver fcf record
James Smartecfd03c2010-02-12 14:41:27 -05001485 * @phba: pointer to lpfc hba data structure.
1486 * @fcf_rec: pointer to driver fcf record.
1487 * @new_fcf_record: pointer to hba fcf record.
1488 * @addr_mode: address mode to be set to the driver fcf record.
1489 * @vlan_id: vlan tag to be set to the driver fcf record.
1490 * @flag: flag bits to be set to the driver fcf record.
1491 *
1492 * This routine updates the driver FCF record from the new HBA FCF record
1493 * together with the address mode, vlan_id, and other informations. This
Dick Kennedy88acb4d2020-05-01 14:43:07 -07001494 * routine is called with the hbalock held.
James Smartecfd03c2010-02-12 14:41:27 -05001495 **/
1496static void
1497__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1498 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1499 uint16_t vlan_id, uint32_t flag)
1500{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001501 lockdep_assert_held(&phba->hbalock);
1502
James Smartecfd03c2010-02-12 14:41:27 -05001503 /* Copy the fields from the HBA's FCF record */
1504 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1505 /* Update other fields of driver FCF record */
1506 fcf_rec->addr_mode = addr_mode;
1507 fcf_rec->vlan_id = vlan_id;
1508 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001509 __lpfc_update_fcf_record_pri(phba,
1510 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1511 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001512}
1513
1514/**
James Smart6fb120a2009-05-22 14:52:59 -04001515 * lpfc_register_fcf - Register the FCF with hba.
1516 * @phba: pointer to lpfc hba data structure.
1517 *
1518 * This routine issues a register fcfi mailbox command to register
1519 * the fcf with HBA.
1520 **/
1521static void
1522lpfc_register_fcf(struct lpfc_hba *phba)
1523{
1524 LPFC_MBOXQ_t *fcf_mbxq;
1525 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001526
James Smartd439d282010-09-29 11:18:45 -04001527 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001528 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001529 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001530 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001531 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001532 return;
1533 }
1534
1535 /* The FCF is already registered, start discovery */
1536 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001537 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001538 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001539 if (phba->pport->port_state != LPFC_FLOGI &&
1540 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001541 phba->hba_flag |= FCF_RR_INPROG;
1542 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001543 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001544 return;
1545 }
1546 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001547 return;
1548 }
James Smartd439d282010-09-29 11:18:45 -04001549 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001550
James Smarta93ff372010-10-22 11:06:08 -04001551 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001552 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001553 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001554 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001555 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001556 return;
James Smart4d9ab992009-10-02 15:16:39 -04001557 }
James Smart6fb120a2009-05-22 14:52:59 -04001558
1559 lpfc_reg_fcfi(phba, fcf_mbxq);
1560 fcf_mbxq->vport = phba->pport;
1561 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1562 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001563 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001564 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001565 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001566 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001567 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001568 }
James Smart6fb120a2009-05-22 14:52:59 -04001569
1570 return;
1571}
1572
1573/**
1574 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1575 * @phba: pointer to lpfc hba data structure.
1576 * @new_fcf_record: pointer to fcf record.
1577 * @boot_flag: Indicates if this record used by boot bios.
1578 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001579 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001580 *
1581 * This routine compare the fcf record with connect list obtained from the
1582 * config region to decide if this FCF can be used for SAN discovery. It returns
1583 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1584 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1585 * is used by boot bios and addr_mode will indicate the addressing mode to be
1586 * used for this FCF when the function returns.
1587 * If the FCF record need to be used with a particular vlan id, the vlan is
1588 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001589 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001590 **/
1591static int
1592lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1593 struct fcf_record *new_fcf_record,
1594 uint32_t *boot_flag, uint32_t *addr_mode,
1595 uint16_t *vlan_id)
1596{
1597 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001598 int i, j, fcf_vlan_id = 0;
1599
1600 /* Find the lowest VLAN id in the FCF record */
1601 for (i = 0; i < 512; i++) {
1602 if (new_fcf_record->vlan_bitmap[i]) {
1603 fcf_vlan_id = i * 8;
1604 j = 0;
1605 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1606 j++;
1607 fcf_vlan_id++;
1608 }
1609 break;
1610 }
1611 }
James Smart6fb120a2009-05-22 14:52:59 -04001612
James Smart26979ce2012-09-29 11:31:55 -04001613 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001614 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001615 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1616 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001617 return 0;
1618
James Smart45ed1192009-10-02 15:17:02 -04001619 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001620 *boot_flag = 0;
1621 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1622 new_fcf_record);
1623 if (phba->valid_vlan)
1624 *vlan_id = phba->vlan_id;
1625 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001626 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001627 return 1;
1628 }
1629
1630 /*
1631 * If there are no FCF connection table entry, driver connect to all
1632 * FCFs.
1633 */
1634 if (list_empty(&phba->fcf_conn_rec_list)) {
1635 *boot_flag = 0;
1636 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1637 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001638
1639 /*
1640 * When there are no FCF connect entries, use driver's default
1641 * addressing mode - FPMA.
1642 */
1643 if (*addr_mode & LPFC_FCF_FPMA)
1644 *addr_mode = LPFC_FCF_FPMA;
1645
James Smart4d9ab992009-10-02 15:16:39 -04001646 /* If FCF record report a vlan id use that vlan id */
1647 if (fcf_vlan_id)
1648 *vlan_id = fcf_vlan_id;
1649 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001650 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001651 return 1;
1652 }
1653
James Smartecfd03c2010-02-12 14:41:27 -05001654 list_for_each_entry(conn_entry,
1655 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001656 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1657 continue;
1658
1659 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1660 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001661 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001662 continue;
James Smart8fa38512009-07-19 10:01:03 -04001663 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1664 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1665 new_fcf_record))
1666 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001667 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1668 /*
1669 * If the vlan bit map does not have the bit set for the
1670 * vlan id to be used, then it is not a match.
1671 */
1672 if (!(new_fcf_record->vlan_bitmap
1673 [conn_entry->conn_rec.vlan_tag / 8] &
1674 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1675 continue;
1676 }
1677
1678 /*
James Smart0c287582009-06-10 17:22:56 -04001679 * If connection record does not support any addressing mode,
1680 * skip the FCF record.
1681 */
1682 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1683 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1684 continue;
1685
1686 /*
James Smart6fb120a2009-05-22 14:52:59 -04001687 * Check if the connection record specifies a required
1688 * addressing mode.
1689 */
1690 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1691 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1692
1693 /*
1694 * If SPMA required but FCF not support this continue.
1695 */
1696 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1697 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1698 new_fcf_record) & LPFC_FCF_SPMA))
1699 continue;
1700
1701 /*
1702 * If FPMA required but FCF not support this continue.
1703 */
1704 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1705 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1706 new_fcf_record) & LPFC_FCF_FPMA))
1707 continue;
1708 }
1709
1710 /*
1711 * This fcf record matches filtering criteria.
1712 */
1713 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1714 *boot_flag = 1;
1715 else
1716 *boot_flag = 0;
1717
James Smart0c287582009-06-10 17:22:56 -04001718 /*
1719 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001720 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001721 * by FCF, allow fabric to pick the addressing mode.
1722 */
James Smart6fb120a2009-05-22 14:52:59 -04001723 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1724 new_fcf_record);
1725 /*
1726 * If the user specified a required address mode, assign that
1727 * address mode
1728 */
1729 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1730 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1731 *addr_mode = (conn_entry->conn_rec.flags &
1732 FCFCNCT_AM_SPMA) ?
1733 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1734 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001735 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001736 * addr mode only if FCF support the addr_mode.
1737 */
1738 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1739 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1740 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1741 (*addr_mode & LPFC_FCF_SPMA))
1742 *addr_mode = LPFC_FCF_SPMA;
1743 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1744 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1745 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1746 (*addr_mode & LPFC_FCF_FPMA))
1747 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001748
James Smart4d9ab992009-10-02 15:16:39 -04001749 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001750 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1751 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001752 /*
1753 * If no vlan id is specified in connect list, use the vlan id
1754 * in the FCF record
1755 */
1756 else if (fcf_vlan_id)
1757 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001758 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001759 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001760
1761 return 1;
1762 }
1763
1764 return 0;
1765}
1766
1767/**
James Smart32b97932009-07-19 10:01:21 -04001768 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1769 * @phba: pointer to lpfc hba data structure.
1770 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1771 *
1772 * This function check if there is any fcoe event pending while driver
1773 * scan FCF entries. If there is any pending event, it will restart the
1774 * FCF saning and return 1 else return 0.
1775 */
1776int
1777lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1778{
James Smart32b97932009-07-19 10:01:21 -04001779 /*
1780 * If the Link is up and no FCoE events while in the
1781 * FCF discovery, no need to restart FCF discovery.
1782 */
1783 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001784 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001785 return 0;
1786
James Smart0c9ab6f2010-02-26 14:15:57 -05001787 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1788 "2768 Pending link or FCF event during current "
1789 "handling of the previous event: link_state:x%x, "
1790 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1791 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1792 phba->fcoe_eventtag);
1793
James Smart32b97932009-07-19 10:01:21 -04001794 spin_lock_irq(&phba->hbalock);
1795 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1796 spin_unlock_irq(&phba->hbalock);
1797
James Smart0c9ab6f2010-02-26 14:15:57 -05001798 if (phba->link_state >= LPFC_LINK_UP) {
1799 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1800 "2780 Restart FCF table scan due to "
1801 "pending FCF event:evt_tag_at_scan:x%x, "
1802 "evt_tag_current:x%x\n",
1803 phba->fcoe_eventtag_at_fcf_scan,
1804 phba->fcoe_eventtag);
1805 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1806 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001807 /*
James Smarta93ff372010-10-22 11:06:08 -04001808 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001809 * flag
1810 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001811 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1812 "2833 Stop FCF discovery process due to link "
1813 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001814 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001815 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001816 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001817 spin_unlock_irq(&phba->hbalock);
1818 }
James Smart32b97932009-07-19 10:01:21 -04001819
James Smart0c9ab6f2010-02-26 14:15:57 -05001820 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001821 if (unreg_fcf) {
1822 spin_lock_irq(&phba->hbalock);
1823 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1824 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001825 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001826 }
James Smart32b97932009-07-19 10:01:21 -04001827 return 1;
1828}
1829
1830/**
James Smart999d8132010-03-15 11:24:56 -04001831 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1832 * @phba: pointer to lpfc hba data structure.
1833 * @fcf_cnt: number of eligible fcf record seen so far.
1834 *
1835 * This function makes an running random selection decision on FCF record to
1836 * use through a sequence of @fcf_cnt eligible FCF records with equal
1837 * probability. To perform integer manunipulation of random numbers with
1838 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001839 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001840 *
1841 * Returns true when outcome is for the newly read FCF record should be
1842 * chosen; otherwise, return false when outcome is for keeping the previously
1843 * chosen FCF record.
1844 **/
1845static bool
1846lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1847{
1848 uint32_t rand_num;
1849
1850 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001851 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001852
1853 /* Decision with probability 1/fcf_cnt */
1854 if ((fcf_cnt * rand_num) < 0xFFFF)
1855 return true;
1856 else
1857 return false;
1858}
1859
1860/**
James Smart3804dc82010-07-14 15:31:37 -04001861 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001862 * @phba: pointer to lpfc hba data structure.
1863 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001864 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001865 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001866 * This routine parses the non-embedded fcf mailbox command by performing the
1867 * necessarily error checking, non-embedded read FCF record mailbox command
1868 * SGE parsing, and endianness swapping.
1869 *
1870 * Returns the pointer to the new FCF record in the non-embedded mailbox
1871 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001872 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001873static struct fcf_record *
1874lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1875 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001876{
1877 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001878 struct lpfc_mbx_sge sge;
1879 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001880 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001881 union lpfc_sli4_cfg_shdr *shdr;
1882 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001883
James Smart6fb120a2009-05-22 14:52:59 -04001884 /* Get the first SGE entry from the non-embedded DMA memory. This
1885 * routine only uses a single SGE.
1886 */
1887 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001888 if (unlikely(!mboxq->sge_array)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001889 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04001890 "2524 Failed to get the non-embedded SGE "
1891 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001892 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001893 }
1894 virt_addr = mboxq->sge_array->addr[0];
1895
1896 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001897 lpfc_sli_pcimem_bcopy(shdr, shdr,
1898 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001899 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001900 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001901 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001902 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001903 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1904 if_type == LPFC_SLI_INTF_IF_TYPE_2)
Dick Kennedy372c1872020-06-30 14:50:00 -07001905 lpfc_printf_log(phba, KERN_ERR,
1906 LOG_TRACE_EVENT,
James Smartdef9c7a2009-12-21 17:02:28 -05001907 "2726 READ_FCF_RECORD Indicates empty "
1908 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001909 else
Dick Kennedy372c1872020-06-30 14:50:00 -07001910 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartdef9c7a2009-12-21 17:02:28 -05001911 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001912 "with status x%x add_status x%x, "
1913 "mbx\n", shdr_status, shdr_add_status);
1914 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001915 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001916
1917 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001918 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1919 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1920 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001921 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001922 new_fcf_record = (struct fcf_record *)(virt_addr +
1923 sizeof(struct lpfc_mbx_read_fcf_tbl));
1924 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001925 offsetof(struct fcf_record, vlan_bitmap));
1926 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1927 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001928
James Smart0c9ab6f2010-02-26 14:15:57 -05001929 return new_fcf_record;
1930}
1931
1932/**
1933 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1934 * @phba: pointer to lpfc hba data structure.
1935 * @fcf_record: pointer to the fcf record.
1936 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1937 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1938 *
1939 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1940 * enabled.
1941 **/
1942static void
1943lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1944 struct fcf_record *fcf_record,
1945 uint16_t vlan_id,
1946 uint16_t next_fcf_index)
1947{
1948 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1949 "2764 READ_FCF_RECORD:\n"
1950 "\tFCF_Index : x%x\n"
1951 "\tFCF_Avail : x%x\n"
1952 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001953 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001954 "\tFIP_Priority : x%x\n"
1955 "\tMAC_Provider : x%x\n"
1956 "\tLowest VLANID : x%x\n"
1957 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1958 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1959 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1960 "\tNext_FCF_Index: x%x\n",
1961 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1962 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1963 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001964 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001965 fcf_record->fip_priority,
1966 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1967 vlan_id,
1968 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1969 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1970 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1971 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1972 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1973 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1974 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1975 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1976 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1977 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1978 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1979 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1980 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1981 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1982 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1983 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1984 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1985 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1986 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1987 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1988 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1989 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1990 next_fcf_index);
1991}
1992
1993/**
Lee Jonese415f2a2020-07-23 13:24:08 +01001994 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
James Smartdbb6b3a2010-06-08 18:31:37 -04001995 * @phba: pointer to lpfc hba data structure.
1996 * @fcf_rec: pointer to an existing FCF record.
1997 * @new_fcf_record: pointer to a new FCF record.
1998 * @new_vlan_id: vlan id from the new FCF record.
1999 *
2000 * This function performs matching test of a new FCF record against an existing
2001 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2002 * will not be used as part of the FCF record matching criteria.
2003 *
2004 * Returns true if all the fields matching, otherwise returns false.
2005 */
2006static bool
2007lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2008 struct lpfc_fcf_rec *fcf_rec,
2009 struct fcf_record *new_fcf_record,
2010 uint16_t new_vlan_id)
2011{
2012 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2013 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2014 return false;
2015 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2016 return false;
2017 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2018 return false;
2019 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2020 return false;
James Smart7d791df2011-07-22 18:37:52 -04002021 if (fcf_rec->priority != new_fcf_record->fip_priority)
2022 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04002023 return true;
2024}
2025
2026/**
James Smarta93ff372010-10-22 11:06:08 -04002027 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2028 * @vport: Pointer to vport object.
2029 * @fcf_index: index to next fcf.
2030 *
2031 * This function processing the roundrobin fcf failover to next fcf index.
2032 * When this function is invoked, there will be a current fcf registered
2033 * for flogi.
2034 * Return: 0 for continue retrying flogi on currently registered fcf;
2035 * 1 for stop flogi on currently registered fcf;
2036 */
2037int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2038{
2039 struct lpfc_hba *phba = vport->phba;
2040 int rc;
2041
2042 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2043 spin_lock_irq(&phba->hbalock);
2044 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2045 spin_unlock_irq(&phba->hbalock);
2046 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2047 "2872 Devloss tmo with no eligible "
2048 "FCF, unregister in-use FCF (x%x) "
2049 "and rescan FCF table\n",
2050 phba->fcf.current_rec.fcf_indx);
2051 lpfc_unregister_fcf_rescan(phba);
2052 goto stop_flogi_current_fcf;
2053 }
2054 /* Mark the end to FLOGI roundrobin failover */
2055 phba->hba_flag &= ~FCF_RR_INPROG;
2056 /* Allow action to new fcf asynchronous event */
2057 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2058 spin_unlock_irq(&phba->hbalock);
2059 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2060 "2865 No FCF available, stop roundrobin FCF "
2061 "failover and change port state:x%x/x%x\n",
2062 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2063 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002064
2065 if (!phba->fcf.fcf_redisc_attempted) {
2066 lpfc_unregister_fcf(phba);
2067
2068 rc = lpfc_sli4_redisc_fcf_table(phba);
2069 if (!rc) {
2070 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2071 "3195 Rediscover FCF table\n");
2072 phba->fcf.fcf_redisc_attempted = 1;
2073 lpfc_sli4_clear_fcf_rr_bmask(phba);
2074 } else {
2075 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2076 "3196 Rediscover FCF table "
2077 "failed. Status:x%x\n", rc);
2078 }
2079 } else {
2080 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2081 "3197 Already rediscover FCF table "
2082 "attempted. No more retry\n");
2083 }
James Smarta93ff372010-10-22 11:06:08 -04002084 goto stop_flogi_current_fcf;
2085 } else {
2086 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2087 "2794 Try FLOGI roundrobin FCF failover to "
2088 "(x%x)\n", fcf_index);
2089 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2090 if (rc)
2091 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2092 "2761 FLOGI roundrobin FCF failover "
2093 "failed (rc:x%x) to read FCF (x%x)\n",
2094 rc, phba->fcf.current_rec.fcf_indx);
2095 else
2096 goto stop_flogi_current_fcf;
2097 }
2098 return 0;
2099
2100stop_flogi_current_fcf:
2101 lpfc_can_disctmo(vport);
2102 return 1;
2103}
2104
2105/**
James Smart7d791df2011-07-22 18:37:52 -04002106 * lpfc_sli4_fcf_pri_list_del
2107 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002108 * @fcf_index: the index of the fcf record to delete
James Smart7d791df2011-07-22 18:37:52 -04002109 * This routine checks the on list flag of the fcf_index to be deleted.
2110 * If it is one the list then it is removed from the list, and the flag
2111 * is cleared. This routine grab the hbalock before removing the fcf
2112 * record from the list.
2113 **/
2114static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2115 uint16_t fcf_index)
2116{
2117 struct lpfc_fcf_pri *new_fcf_pri;
2118
2119 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2120 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2121 "3058 deleting idx x%x pri x%x flg x%x\n",
2122 fcf_index, new_fcf_pri->fcf_rec.priority,
2123 new_fcf_pri->fcf_rec.flag);
2124 spin_lock_irq(&phba->hbalock);
2125 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2126 if (phba->fcf.current_rec.priority ==
2127 new_fcf_pri->fcf_rec.priority)
2128 phba->fcf.eligible_fcf_cnt--;
2129 list_del_init(&new_fcf_pri->list);
2130 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2131 }
2132 spin_unlock_irq(&phba->hbalock);
2133}
2134
2135/**
2136 * lpfc_sli4_set_fcf_flogi_fail
2137 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002138 * @fcf_index: the index of the fcf record to update
James Smart7d791df2011-07-22 18:37:52 -04002139 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2140 * flag so the the round robin slection for the particular priority level
2141 * will try a different fcf record that does not have this bit set.
2142 * If the fcf record is re-read for any reason this flag is cleared brfore
2143 * adding it to the priority list.
2144 **/
2145void
2146lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2147{
2148 struct lpfc_fcf_pri *new_fcf_pri;
2149 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2150 spin_lock_irq(&phba->hbalock);
2151 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2152 spin_unlock_irq(&phba->hbalock);
2153}
2154
2155/**
2156 * lpfc_sli4_fcf_pri_list_add
2157 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002158 * @fcf_index: the index of the fcf record to add
2159 * @new_fcf_record: pointer to a new FCF record.
James Smart7d791df2011-07-22 18:37:52 -04002160 * This routine checks the priority of the fcf_index to be added.
2161 * If it is a lower priority than the current head of the fcf_pri list
2162 * then it is added to the list in the right order.
2163 * If it is the same priority as the current head of the list then it
2164 * is added to the head of the list and its bit in the rr_bmask is set.
2165 * If the fcf_index to be added is of a higher priority than the current
2166 * head of the list then the rr_bmask is cleared, its bit is set in the
2167 * rr_bmask and it is added to the head of the list.
2168 * returns:
2169 * 0=success 1=failure
2170 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002171static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2172 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002173 struct fcf_record *new_fcf_record)
2174{
2175 uint16_t current_fcf_pri;
2176 uint16_t last_index;
2177 struct lpfc_fcf_pri *fcf_pri;
2178 struct lpfc_fcf_pri *next_fcf_pri;
2179 struct lpfc_fcf_pri *new_fcf_pri;
2180 int ret;
2181
2182 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2183 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2184 "3059 adding idx x%x pri x%x flg x%x\n",
2185 fcf_index, new_fcf_record->fip_priority,
2186 new_fcf_pri->fcf_rec.flag);
2187 spin_lock_irq(&phba->hbalock);
2188 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2189 list_del_init(&new_fcf_pri->list);
2190 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2191 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2192 if (list_empty(&phba->fcf.fcf_pri_list)) {
2193 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2194 ret = lpfc_sli4_fcf_rr_index_set(phba,
2195 new_fcf_pri->fcf_rec.fcf_index);
2196 goto out;
2197 }
2198
2199 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2200 LPFC_SLI4_FCF_TBL_INDX_MAX);
2201 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2202 ret = 0; /* Empty rr list */
2203 goto out;
2204 }
2205 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2206 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2207 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2208 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2209 memset(phba->fcf.fcf_rr_bmask, 0,
2210 sizeof(*phba->fcf.fcf_rr_bmask));
2211 /* fcfs_at_this_priority_level = 1; */
2212 phba->fcf.eligible_fcf_cnt = 1;
2213 } else
2214 /* fcfs_at_this_priority_level++; */
2215 phba->fcf.eligible_fcf_cnt++;
2216 ret = lpfc_sli4_fcf_rr_index_set(phba,
2217 new_fcf_pri->fcf_rec.fcf_index);
2218 goto out;
2219 }
2220
2221 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2222 &phba->fcf.fcf_pri_list, list) {
2223 if (new_fcf_pri->fcf_rec.priority <=
2224 fcf_pri->fcf_rec.priority) {
2225 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2226 list_add(&new_fcf_pri->list,
2227 &phba->fcf.fcf_pri_list);
2228 else
2229 list_add(&new_fcf_pri->list,
2230 &((struct lpfc_fcf_pri *)
2231 fcf_pri->list.prev)->list);
2232 ret = 0;
2233 goto out;
2234 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2235 || new_fcf_pri->fcf_rec.priority <
2236 next_fcf_pri->fcf_rec.priority) {
2237 list_add(&new_fcf_pri->list, &fcf_pri->list);
2238 ret = 0;
2239 goto out;
2240 }
2241 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2242 continue;
2243
2244 }
2245 ret = 1;
2246out:
2247 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2248 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2249 spin_unlock_irq(&phba->hbalock);
2250 return ret;
2251}
2252
2253/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002254 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2255 * @phba: pointer to lpfc hba data structure.
2256 * @mboxq: pointer to mailbox object.
2257 *
2258 * This function iterates through all the fcf records available in
2259 * HBA and chooses the optimal FCF record for discovery. After finding
2260 * the FCF for discovery it registers the FCF record and kicks start
2261 * discovery.
2262 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2263 * use an FCF record which matches fabric name and mac address of the
2264 * currently used FCF record.
2265 * If the driver supports only one FCF, it will try to use the FCF record
2266 * used by BOOT_BIOS.
2267 */
2268void
2269lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2270{
2271 struct fcf_record *new_fcf_record;
2272 uint32_t boot_flag, addr_mode;
2273 uint16_t fcf_index, next_fcf_index;
2274 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002275 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002276 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002277 int rc;
2278
2279 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002280 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002281 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2282 return;
2283 }
2284
2285 /* Parse the FCF record from the non-embedded mailbox command */
2286 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2287 &next_fcf_index);
2288 if (!new_fcf_record) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002289 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05002290 "2765 Mailbox command READ_FCF_RECORD "
2291 "failed to retrieve a FCF record.\n");
2292 /* Let next new FCF event trigger fast failover */
2293 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002294 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002295 spin_unlock_irq(&phba->hbalock);
2296 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2297 return;
2298 }
2299
2300 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002301 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2302 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002303
2304 /* Log the FCF record information if turned on */
2305 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2306 next_fcf_index);
2307
James Smart6fb120a2009-05-22 14:52:59 -04002308 /*
2309 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002310 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002311 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002312 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002313 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002314 lpfc_sli4_fcf_pri_list_del(phba,
2315 bf_get(lpfc_fcf_record_fcf_index,
2316 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002317 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002318 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002319 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002320 bf_get(lpfc_fcf_record_fcf_index,
2321 new_fcf_record),
2322 bf_get(lpfc_fcf_record_fcf_avail,
2323 new_fcf_record),
2324 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002325 new_fcf_record),
2326 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002327 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002328 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2329 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2330 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002331 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2332 phba->fcf.current_rec.fcf_indx) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002333 lpfc_printf_log(phba, KERN_ERR,
2334 LOG_TRACE_EVENT,
James Smart5ac6b302010-10-22 11:05:36 -04002335 "2862 FCF (x%x) matches property "
2336 "of in-use FCF (x%x)\n",
2337 bf_get(lpfc_fcf_record_fcf_index,
2338 new_fcf_record),
2339 phba->fcf.current_rec.fcf_indx);
2340 goto read_next_fcf;
2341 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002342 /*
2343 * In case the current in-use FCF record becomes
2344 * invalid/unavailable during FCF discovery that
2345 * was not triggered by fast FCF failover process,
2346 * treat it as fast FCF failover.
2347 */
2348 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2349 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2350 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2351 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002352 "(x%x), enter FCF failover "
2353 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002354 phba->fcf.current_rec.fcf_indx);
2355 spin_lock_irq(&phba->hbalock);
2356 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2357 spin_unlock_irq(&phba->hbalock);
2358 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2359 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2360 LPFC_FCOE_FCF_GET_FIRST);
2361 return;
2362 }
2363 }
James Smart6fb120a2009-05-22 14:52:59 -04002364 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002365 } else {
2366 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002367 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2368 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002369 if (rc)
2370 goto read_next_fcf;
2371 }
2372
James Smart6fb120a2009-05-22 14:52:59 -04002373 /*
2374 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002375 * FCF record for the discovery. The condition that a rescan
2376 * matches the in-use FCF record: fabric name, switch name, mac
2377 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002378 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002379 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002380 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002381 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2382 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002383 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002384 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2385 phba->fcf.current_rec.fcf_indx) {
2386 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2387 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2388 /* Stop FCF redisc wait timer */
2389 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2390 phba);
2391 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2392 /* Fast failover, mark completed */
2393 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2394 spin_unlock_irq(&phba->hbalock);
2395 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2396 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002397 "FCF (x%x), port_state:x%x, "
2398 "fc_flag:x%x\n",
2399 phba->fcf.current_rec.fcf_indx,
2400 phba->pport->port_state,
2401 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002402 goto out;
2403 } else
Dick Kennedy372c1872020-06-30 14:50:00 -07002404 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5ac6b302010-10-22 11:05:36 -04002405 "2863 New FCF (x%x) matches "
2406 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002407 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002408 new_fcf_record),
2409 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002410 }
James Smartecfd03c2010-02-12 14:41:27 -05002411 /*
2412 * Read next FCF record from HBA searching for the matching
2413 * with in-use record only if not during the fast failover
2414 * period. In case of fast failover period, it shall try to
2415 * determine whether the FCF record just read should be the
2416 * next candidate.
2417 */
2418 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002419 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002420 goto read_next_fcf;
2421 }
James Smart6fb120a2009-05-22 14:52:59 -04002422 }
James Smartecfd03c2010-02-12 14:41:27 -05002423 /*
2424 * Update on failover FCF record only if it's in FCF fast-failover
2425 * period; otherwise, update on current FCF record.
2426 */
James Smartfc2b9892010-02-26 14:15:29 -05002427 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2428 fcf_rec = &phba->fcf.failover_rec;
2429 else
James Smartecfd03c2010-02-12 14:41:27 -05002430 fcf_rec = &phba->fcf.current_rec;
2431
James Smart6fb120a2009-05-22 14:52:59 -04002432 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2433 /*
James Smartecfd03c2010-02-12 14:41:27 -05002434 * If the driver FCF record does not have boot flag
2435 * set and new hba fcf record has boot flag set, use
2436 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002437 */
James Smartecfd03c2010-02-12 14:41:27 -05002438 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2439 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002440 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2441 "2837 Update current FCF record "
2442 "(x%x) with new FCF record (x%x)\n",
2443 fcf_rec->fcf_indx,
2444 bf_get(lpfc_fcf_record_fcf_index,
2445 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002446 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2447 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002448 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002449 goto read_next_fcf;
2450 }
2451 /*
James Smartecfd03c2010-02-12 14:41:27 -05002452 * If the driver FCF record has boot flag set and the
2453 * new hba FCF record does not have boot flag, read
2454 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002455 */
James Smartecfd03c2010-02-12 14:41:27 -05002456 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002457 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002458 goto read_next_fcf;
2459 }
2460 /*
James Smartecfd03c2010-02-12 14:41:27 -05002461 * If the new hba FCF record has lower priority value
2462 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002463 */
James Smartfc2b9892010-02-26 14:15:29 -05002464 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002465 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002466 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2467 "2838 Update current FCF record "
2468 "(x%x) with new FCF record (x%x)\n",
2469 fcf_rec->fcf_indx,
2470 bf_get(lpfc_fcf_record_fcf_index,
2471 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002472 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2473 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002474 /* Reset running random FCF selection count */
2475 phba->fcf.eligible_fcf_cnt = 1;
2476 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2477 /* Update running random FCF selection count */
2478 phba->fcf.eligible_fcf_cnt++;
2479 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2480 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002481 if (select_new_fcf) {
2482 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2483 "2839 Update current FCF record "
2484 "(x%x) with new FCF record (x%x)\n",
2485 fcf_rec->fcf_indx,
2486 bf_get(lpfc_fcf_record_fcf_index,
2487 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002488 /* Choose the new FCF by random selection */
2489 __lpfc_update_fcf_record(phba, fcf_rec,
2490 new_fcf_record,
2491 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002492 }
James Smart6fb120a2009-05-22 14:52:59 -04002493 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002494 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002495 goto read_next_fcf;
2496 }
2497 /*
James Smartecfd03c2010-02-12 14:41:27 -05002498 * This is the first suitable FCF record, choose this record for
2499 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002500 */
James Smartecfd03c2010-02-12 14:41:27 -05002501 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002502 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002503 "2840 Update initial FCF candidate "
2504 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002505 bf_get(lpfc_fcf_record_fcf_index,
2506 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002507 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2508 addr_mode, vlan_id, (boot_flag ?
2509 BOOT_ENABLE : 0));
2510 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002511 /* Setup initial running random FCF selection count */
2512 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002513 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002514 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002515 goto read_next_fcf;
2516
2517read_next_fcf:
2518 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002519 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2520 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2521 /*
2522 * Case of FCF fast failover scan
2523 */
2524
2525 /*
2526 * It has not found any suitable FCF record, cancel
2527 * FCF scan inprogress, and do nothing
2528 */
2529 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002530 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002531 "2782 No suitable FCF found: "
2532 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002533 phba->fcoe_eventtag_at_fcf_scan,
2534 bf_get(lpfc_fcf_record_fcf_index,
2535 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002536 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002537 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2538 phba->hba_flag &= ~FCF_TS_INPROG;
2539 spin_unlock_irq(&phba->hbalock);
2540 /* Unregister in-use FCF and rescan */
2541 lpfc_printf_log(phba, KERN_INFO,
2542 LOG_FIP,
2543 "2864 On devloss tmo "
2544 "unreg in-use FCF and "
2545 "rescan FCF table\n");
2546 lpfc_unregister_fcf_rescan(phba);
2547 return;
2548 }
2549 /*
2550 * Let next new FCF event trigger fast failover
2551 */
2552 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002553 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002554 return;
2555 }
2556 /*
2557 * It has found a suitable FCF record that is not
2558 * the same as in-use FCF record, unregister the
2559 * in-use FCF record, replace the in-use FCF record
2560 * with the new FCF record, mark FCF fast failover
2561 * completed, and then start register the new FCF
2562 * record.
2563 */
2564
James Smart0c9ab6f2010-02-26 14:15:57 -05002565 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002566 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002567
2568 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002569 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002570 "2842 Replace in-use FCF (x%x) "
2571 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002572 phba->fcf.current_rec.fcf_indx,
2573 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002574 memcpy(&phba->fcf.current_rec,
2575 &phba->fcf.failover_rec,
2576 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002577 /*
2578 * Mark the fast FCF failover rediscovery completed
2579 * and the start of the first round of the roundrobin
2580 * FCF failover.
2581 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002582 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002583 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002584 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002585 /* Register to the new FCF record */
2586 lpfc_register_fcf(phba);
2587 } else {
2588 /*
2589 * In case of transaction period to fast FCF failover,
2590 * do nothing when search to the end of the FCF table.
2591 */
2592 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2593 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2594 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002595
James Smart7d791df2011-07-22 18:37:52 -04002596 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2597 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002598 /*
2599 * In case the current in-use FCF record no
2600 * longer existed during FCF discovery that
2601 * was not triggered by fast FCF failover
2602 * process, treat it as fast FCF failover.
2603 */
2604 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2605 "2841 In-use FCF record (x%x) "
2606 "not reported, entering fast "
2607 "FCF failover mode scanning.\n",
2608 phba->fcf.current_rec.fcf_indx);
2609 spin_lock_irq(&phba->hbalock);
2610 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2611 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002612 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2613 LPFC_FCOE_FCF_GET_FIRST);
2614 return;
2615 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002616 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002617 lpfc_register_fcf(phba);
2618 }
2619 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002620 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002621 return;
2622
2623out:
2624 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2625 lpfc_register_fcf(phba);
2626
2627 return;
2628}
2629
2630/**
James Smarta93ff372010-10-22 11:06:08 -04002631 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002632 * @phba: pointer to lpfc hba data structure.
2633 * @mboxq: pointer to mailbox object.
2634 *
James Smarta93ff372010-10-22 11:06:08 -04002635 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002636 * read FCF record mailbox command from the eligible FCF record bmask for
2637 * performing the failover. If the FCF read back is not valid/available, it
2638 * fails through to retrying FLOGI to the currently registered FCF again.
2639 * Otherwise, if the FCF read back is valid and available, it will set the
2640 * newly read FCF record to the failover FCF record, unregister currently
2641 * registered FCF record, copy the failover FCF record to the current
2642 * FCF record, and then register the current FCF record before proceeding
2643 * to trying FLOGI on the new failover FCF.
2644 */
2645void
2646lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2647{
2648 struct fcf_record *new_fcf_record;
2649 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002650 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002651 uint16_t current_fcf_index;
2652 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002653 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002654
James Smarta93ff372010-10-22 11:06:08 -04002655 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002656 if (phba->link_state < LPFC_LINK_UP) {
2657 spin_lock_irq(&phba->hbalock);
2658 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002659 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002660 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002661 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002662 }
2663
2664 /* Parse the FCF record from the non-embedded mailbox command */
2665 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2666 &next_fcf_index);
2667 if (!new_fcf_record) {
2668 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2669 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002670 "failed to retrieve a FCF record. "
2671 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2672 phba->fcf.fcf_flag);
2673 lpfc_unregister_fcf_rescan(phba);
2674 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002675 }
2676
2677 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002678 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2679 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002680
2681 /* Log the FCF record information if turned on */
2682 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2683 next_fcf_index);
2684
James Smarta93ff372010-10-22 11:06:08 -04002685 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2686 if (!rc) {
2687 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2688 "2848 Remove ineligible FCF (x%x) from "
2689 "from roundrobin bmask\n", fcf_index);
2690 /* Clear roundrobin bmask bit for ineligible FCF */
2691 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2692 /* Perform next round of roundrobin FCF failover */
2693 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2694 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2695 if (rc)
2696 goto out;
2697 goto error_out;
2698 }
2699
2700 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2701 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2702 "2760 Perform FLOGI roundrobin FCF failover: "
2703 "FCF (x%x) back to FCF (x%x)\n",
2704 phba->fcf.current_rec.fcf_indx, fcf_index);
2705 /* Wait 500 ms before retrying FLOGI to current FCF */
2706 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002707 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002708 goto out;
2709 }
2710
James Smart0c9ab6f2010-02-26 14:15:57 -05002711 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002712 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002713 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2714 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002715 spin_lock_irq(&phba->hbalock);
2716 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2717 new_fcf_record, addr_mode, vlan_id,
2718 (boot_flag ? BOOT_ENABLE : 0));
2719 spin_unlock_irq(&phba->hbalock);
2720
2721 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2722
2723 /* Unregister the current in-use FCF record */
2724 lpfc_unregister_fcf(phba);
2725
2726 /* Replace in-use record with the new record */
2727 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2728 sizeof(struct lpfc_fcf_rec));
2729
2730 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002731 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2732 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002733
James Smarta93ff372010-10-22 11:06:08 -04002734error_out:
2735 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002736out:
2737 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002738}
2739
2740/**
2741 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2742 * @phba: pointer to lpfc hba data structure.
2743 * @mboxq: pointer to mailbox object.
2744 *
2745 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002746 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002747 * failover when a new FCF event happened. If the FCF read back is
2748 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002749 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002750 */
2751void
2752lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2753{
2754 struct fcf_record *new_fcf_record;
2755 uint32_t boot_flag, addr_mode;
2756 uint16_t fcf_index, next_fcf_index;
2757 uint16_t vlan_id;
2758 int rc;
2759
2760 /* If link state is not up, no need to proceed */
2761 if (phba->link_state < LPFC_LINK_UP)
2762 goto out;
2763
2764 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002765 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002766 goto out;
2767
2768 /* Parse the FCF record from the non-embedded mailbox command */
2769 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2770 &next_fcf_index);
2771 if (!new_fcf_record) {
2772 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2773 "2767 Mailbox command READ_FCF_RECORD "
2774 "failed to retrieve a FCF record.\n");
2775 goto out;
2776 }
2777
2778 /* Check the connection list for eligibility */
2779 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2780 &addr_mode, &vlan_id);
2781
2782 /* Log the FCF record information if turned on */
2783 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2784 next_fcf_index);
2785
2786 if (!rc)
2787 goto out;
2788
2789 /* Update the eligible FCF record index bmask */
2790 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002791
2792 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002793
2794out:
2795 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2796}
2797
2798/**
James Smart76a95d72010-11-20 23:11:48 -05002799 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2800 * @phba: pointer to lpfc hba data structure.
2801 * @mboxq: pointer to mailbox data structure.
2802 *
2803 * This function handles completion of init vfi mailbox command.
2804 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002805static void
James Smart76a95d72010-11-20 23:11:48 -05002806lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2807{
2808 struct lpfc_vport *vport = mboxq->vport;
2809
James Smartdf9e1b52011-12-13 13:22:17 -05002810 /*
2811 * VFI not supported on interface type 0, just do the flogi
2812 * Also continue if the VFI is in use - just use the same one.
2813 */
2814 if (mboxq->u.mb.mbxStatus &&
2815 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2816 LPFC_SLI_INTF_IF_TYPE_0) &&
2817 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002818 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2819 "2891 Init VFI mailbox failed 0x%x\n",
2820 mboxq->u.mb.mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -05002821 mempool_free(mboxq, phba->mbox_mem_pool);
2822 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2823 return;
2824 }
James Smart73d91e52011-10-10 21:32:10 -04002825
James Smart76a95d72010-11-20 23:11:48 -05002826 lpfc_initial_flogi(vport);
2827 mempool_free(mboxq, phba->mbox_mem_pool);
2828 return;
2829}
2830
2831/**
2832 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2833 * @vport: pointer to lpfc_vport data structure.
2834 *
2835 * This function issue a init_vfi mailbox command to initialize the VFI and
2836 * VPI for the physical port.
2837 */
2838void
2839lpfc_issue_init_vfi(struct lpfc_vport *vport)
2840{
2841 LPFC_MBOXQ_t *mboxq;
2842 int rc;
2843 struct lpfc_hba *phba = vport->phba;
2844
2845 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2846 if (!mboxq) {
2847 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002848 LOG_TRACE_EVENT, "2892 Failed to allocate "
James Smart76a95d72010-11-20 23:11:48 -05002849 "init_vfi mailbox\n");
2850 return;
2851 }
2852 lpfc_init_vfi(mboxq, vport);
2853 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2854 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2855 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002856 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2857 "2893 Failed to issue init_vfi mailbox\n");
James Smart76a95d72010-11-20 23:11:48 -05002858 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2859 }
2860}
2861
2862/**
James Smart1c6834a2009-07-19 10:01:26 -04002863 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2864 * @phba: pointer to lpfc hba data structure.
2865 * @mboxq: pointer to mailbox data structure.
2866 *
2867 * This function handles completion of init vpi mailbox command.
2868 */
James Smart695a8142010-01-26 23:08:03 -05002869void
James Smart1c6834a2009-07-19 10:01:26 -04002870lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2871{
2872 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002873 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002874 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2875
James Smart1c6834a2009-07-19 10:01:26 -04002876 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002877 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2878 "2609 Init VPI mailbox failed 0x%x\n",
2879 mboxq->u.mb.mbxStatus);
James Smart1c6834a2009-07-19 10:01:26 -04002880 mempool_free(mboxq, phba->mbox_mem_pool);
2881 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2882 return;
2883 }
James Smart72100cc2010-02-12 14:43:01 -05002884 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002885 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002886 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002887
James Smart695a8142010-01-26 23:08:03 -05002888 /* If this port is physical port or FDISC is done, do reg_vpi */
2889 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2890 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2891 if (!ndlp)
2892 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002893 LOG_TRACE_EVENT,
James Smart695a8142010-01-26 23:08:03 -05002894 "2731 Cannot find fabric "
2895 "controller node\n");
2896 else
2897 lpfc_register_new_vport(phba, vport, ndlp);
2898 mempool_free(mboxq, phba->mbox_mem_pool);
2899 return;
2900 }
2901
James Smart1c6834a2009-07-19 10:01:26 -04002902 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2903 lpfc_initial_fdisc(vport);
2904 else {
2905 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
Dick Kennedy372c1872020-06-30 14:50:00 -07002906 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6a9c52c2009-10-02 15:16:51 -04002907 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002908 }
James Smart695a8142010-01-26 23:08:03 -05002909 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002910 return;
2911}
2912
2913/**
James Smartecfd03c2010-02-12 14:41:27 -05002914 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2915 * @vport: pointer to lpfc_vport data structure.
2916 *
2917 * This function issue a init_vpi mailbox command to initialize
2918 * VPI for the vport.
2919 */
2920void
2921lpfc_issue_init_vpi(struct lpfc_vport *vport)
2922{
2923 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002924 int rc, vpi;
2925
2926 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2927 vpi = lpfc_alloc_vpi(vport->phba);
2928 if (!vpi) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002929 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart16a3a202013-04-17 20:14:38 -04002930 "3303 Failed to obtain vport vpi\n");
2931 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2932 return;
2933 }
2934 vport->vpi = vpi;
2935 }
James Smartecfd03c2010-02-12 14:41:27 -05002936
2937 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2938 if (!mboxq) {
2939 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002940 LOG_TRACE_EVENT, "2607 Failed to allocate "
James Smartecfd03c2010-02-12 14:41:27 -05002941 "init_vpi mailbox\n");
2942 return;
2943 }
2944 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2945 mboxq->vport = vport;
2946 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2947 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2948 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002949 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2950 "2608 Failed to issue init_vpi mailbox\n");
James Smartecfd03c2010-02-12 14:41:27 -05002951 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2952 }
2953}
2954
2955/**
James Smart6fb120a2009-05-22 14:52:59 -04002956 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2957 * @phba: pointer to lpfc hba data structure.
2958 *
2959 * This function loops through the list of vports on the @phba and issues an
2960 * FDISC if possible.
2961 */
2962void
2963lpfc_start_fdiscs(struct lpfc_hba *phba)
2964{
2965 struct lpfc_vport **vports;
2966 int i;
2967
2968 vports = lpfc_create_vport_work_array(phba);
2969 if (vports != NULL) {
2970 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2971 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2972 continue;
2973 /* There are no vpi for this vport */
2974 if (vports[i]->vpi > phba->max_vpi) {
2975 lpfc_vport_set_state(vports[i],
2976 FC_VPORT_FAILED);
2977 continue;
2978 }
James Smart76a95d72010-11-20 23:11:48 -05002979 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002980 lpfc_vport_set_state(vports[i],
2981 FC_VPORT_LINKDOWN);
2982 continue;
2983 }
James Smart1c6834a2009-07-19 10:01:26 -04002984 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002985 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002986 continue;
2987 }
James Smart6fb120a2009-05-22 14:52:59 -04002988 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2989 lpfc_initial_fdisc(vports[i]);
2990 else {
2991 lpfc_vport_set_state(vports[i],
2992 FC_VPORT_NO_FABRIC_SUPP);
2993 lpfc_printf_vlog(vports[i], KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002994 LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04002995 "0259 No NPIV "
2996 "Fabric support\n");
2997 }
2998 }
2999 }
3000 lpfc_destroy_vport_work_array(phba, vports);
3001}
3002
3003void
3004lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3005{
James Smart3e1f0712018-11-29 16:09:29 -08003006 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04003007 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05003008 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04003009
James Smartf5eca9b2012-03-01 22:37:54 -05003010 /*
3011 * VFI not supported for interface type 0, so ignore any mailbox
3012 * error (except VFI in use) and continue with the discovery.
3013 */
3014 if (mboxq->u.mb.mbxStatus &&
3015 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3016 LPFC_SLI_INTF_IF_TYPE_0) &&
3017 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003018 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3019 "2018 REG_VFI mbxStatus error x%x "
3020 "HBA state x%x\n",
3021 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05003022 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04003023 /* FLOGI failed, use loop map to make discovery list */
3024 lpfc_disc_list_loopmap(vport);
3025 /* Start discovery */
3026 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05003027 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04003028 }
3029 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05003030 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04003031 }
James Smartae05ebe2013-03-01 16:35:38 -05003032
James Smarte74c03c2013-04-17 20:15:19 -04003033 /* If the VFI is already registered, there is nothing else to do
3034 * Unless this was a VFI update and we are in PT2PT mode, then
3035 * we should drop through to set the port state to ready.
3036 */
James Smartae05ebe2013-03-01 16:35:38 -05003037 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04003038 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3039 vport->fc_flag & FC_PT2PT))
3040 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05003041
James Smartc8685952009-11-18 15:39:16 -05003042 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05003043 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003044 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003045 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003046 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04003047 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003048 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04003049
James Smart1b511972011-12-13 13:23:09 -05003050 /* In case SLI4 FC loopback test, we are ready */
3051 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3052 (phba->link_flag & LS_LOOPBACK_MODE)) {
3053 phba->link_state = LPFC_HBA_READY;
3054 goto out_free_mem;
3055 }
3056
James Smarte74c03c2013-04-17 20:15:19 -04003057 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3058 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3059 "alpacnt:%d LinkState:%x topology:%x\n",
3060 vport->port_state, vport->fc_flag, vport->fc_myDID,
3061 vport->phba->alpa_map[0],
3062 phba->link_state, phba->fc_topology);
3063
James Smart6fb120a2009-05-22 14:52:59 -04003064 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003065 /*
3066 * For private loop or for NPort pt2pt,
3067 * just start discovery and we are done.
3068 */
3069 if ((vport->fc_flag & FC_PT2PT) ||
3070 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3071 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3072
James Smart76a95d72010-11-20 23:11:48 -05003073 /* Use loop map to make discovery list */
3074 lpfc_disc_list_loopmap(vport);
3075 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003076 if (vport->fc_flag & FC_PT2PT)
3077 vport->port_state = LPFC_VPORT_READY;
3078 else
3079 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003080 } else {
3081 lpfc_start_fdiscs(phba);
3082 lpfc_do_scr_ns_plogi(phba, vport);
3083 }
James Smart6fb120a2009-05-22 14:52:59 -04003084 }
3085
James Smart1b511972011-12-13 13:23:09 -05003086out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003087 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003088 if (dmabuf) {
3089 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3090 kfree(dmabuf);
3091 }
James Smart6fb120a2009-05-22 14:52:59 -04003092 return;
3093}
3094
3095static void
James Smart2e0fef82007-06-17 19:56:36 -05003096lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003097{
James Smart6fb120a2009-05-22 14:52:59 -04003098 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003099 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003100 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003102 struct serv_parm *sp = &vport->fc_sparam;
3103 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003104
3105 /* Check for error */
3106 if (mb->mbxStatus) {
3107 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
Dick Kennedy372c1872020-06-30 14:50:00 -07003108 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003109 "0319 READ_SPARAM mbxStatus error x%x "
3110 "hba state x%x>\n",
3111 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003112 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003113 goto out;
3114 }
3115
James Smart2e0fef82007-06-17 19:56:36 -05003116 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003117 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003118
3119 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3120 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3121 ed_tov = (ed_tov + 999999) / 1000000;
3122
3123 phba->fc_edtov = ed_tov;
3124 phba->fc_ratov = (2 * ed_tov) / 1000;
3125 if (phba->fc_ratov < FF_DEF_RATOV) {
3126 /* RA_TOV should be atleast 10sec for initial flogi */
3127 phba->fc_ratov = FF_DEF_RATOV;
3128 }
3129
James Smart05580562011-05-24 11:40:48 -04003130 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003131 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003132 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3133 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3134 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3135 }
3136
dea31012005-04-17 16:05:31 -05003137 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3138 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003139 mempool_free(pmb, phba->mbox_mem_pool);
James Smart835214f2020-01-27 16:23:03 -08003140
3141 /* Check if sending the FLOGI is being deferred to after we get
3142 * up to date CSPs from MBX_READ_SPARAM.
3143 */
3144 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3145 lpfc_initial_flogi(vport);
3146 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3147 }
dea31012005-04-17 16:05:31 -05003148 return;
3149
3150out:
James Smart3e1f0712018-11-29 16:09:29 -08003151 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003152 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3153 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003154 lpfc_issue_clear_la(phba, vport);
3155 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003156 return;
3157}
3158
3159static void
James Smart76a95d72010-11-20 23:11:48 -05003160lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003161{
James Smart92d7f7b2007-06-17 19:56:38 -05003162 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003163 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003164 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003165 int i;
James Smart14691152006-12-02 13:34:28 -05003166 struct lpfc_dmabuf *mp;
3167 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003168 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003169 uint32_t fc_flags = 0;
James Smart894bb172019-08-14 16:56:52 -07003170 unsigned long iflags;
James Smart14691152006-12-02 13:34:28 -05003171
James Smart894bb172019-08-14 16:56:52 -07003172 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta085e872015-12-16 18:12:02 -05003173 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3174
3175 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3176 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3177 case LPFC_LINK_SPEED_1GHZ:
3178 case LPFC_LINK_SPEED_2GHZ:
3179 case LPFC_LINK_SPEED_4GHZ:
3180 case LPFC_LINK_SPEED_8GHZ:
3181 case LPFC_LINK_SPEED_10GHZ:
3182 case LPFC_LINK_SPEED_16GHZ:
3183 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003184 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003185 case LPFC_LINK_SPEED_128GHZ:
James Smarta085e872015-12-16 18:12:02 -05003186 break;
3187 default:
3188 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3189 break;
3190 }
dea31012005-04-17 16:05:31 -05003191 }
3192
James Smarte74c03c2013-04-17 20:15:19 -04003193 if (phba->fc_topology &&
3194 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3195 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3196 "3314 Toplogy changed was 0x%x is 0x%x\n",
3197 phba->fc_topology,
3198 bf_get(lpfc_mbx_read_top_topology, la));
3199 phba->fc_topology_changed = 1;
3200 }
3201
James Smart76a95d72010-11-20 23:11:48 -05003202 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart8aaa7bc2020-10-20 13:27:17 -07003203 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
dea31012005-04-17 16:05:31 -05003204
James Smartdf9e1b52011-12-13 13:22:17 -05003205 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003206 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003207 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003208
James Smart6a9c52c2009-10-02 15:16:51 -04003209 /* if npiv is enabled and this adapter supports npiv log
3210 * a message that npiv is not supported in this topology
3211 */
3212 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003213 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3214 "1309 Link Up Event npiv not supported in loop "
3215 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003216 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003217 if (bf_get(lpfc_mbx_read_top_il, la))
3218 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003219
James Smart76a95d72010-11-20 23:11:48 -05003220 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3221 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003222
3223 if (i == 0) {
3224 phba->alpa_map[0] = 0;
3225 } else {
James Smarte8b62012007-08-02 11:10:09 -04003226 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003227 int numalpa, j, k;
3228 union {
3229 uint8_t pamap[16];
3230 struct {
3231 uint32_t wd1;
3232 uint32_t wd2;
3233 uint32_t wd3;
3234 uint32_t wd4;
3235 } pa;
3236 } un;
3237 numalpa = phba->alpa_map[0];
3238 j = 0;
3239 while (j < numalpa) {
3240 memset(un.pamap, 0, 16);
3241 for (k = 1; j < numalpa; k++) {
3242 un.pamap[k - 1] =
3243 phba->alpa_map[j + 1];
3244 j++;
3245 if (k == 16)
3246 break;
3247 }
3248 /* Link Up Event ALPA map */
3249 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003250 KERN_WARNING,
3251 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003252 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003253 "ALPA map Data: x%x "
3254 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003255 un.pa.wd1, un.pa.wd2,
3256 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003257 }
3258 }
3259 }
3260 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003261 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003262 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003263 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003264 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3265 }
James Smart2e0fef82007-06-17 19:56:36 -05003266 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003267 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003268 }
James Smart894bb172019-08-14 16:56:52 -07003269 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003270
James Smart38c20672013-03-01 16:37:44 -05003271 if (fc_flags) {
James Smart894bb172019-08-14 16:56:52 -07003272 spin_lock_irqsave(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003273 vport->fc_flag |= fc_flags;
James Smart894bb172019-08-14 16:56:52 -07003274 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003275 }
3276
dea31012005-04-17 16:05:31 -05003277 lpfc_linkup(phba);
James Smart835214f2020-01-27 16:23:03 -08003278 sparam_mbox = NULL;
3279
James Smart9f1177a2010-02-26 14:12:57 -05003280 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3281 if (!sparam_mbox)
3282 goto out;
3283
3284 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3285 if (rc) {
3286 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3287 goto out;
3288 }
3289 sparam_mbox->vport = vport;
3290 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3291 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3292 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003293 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003294 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3295 kfree(mp);
3296 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3297 goto out;
dea31012005-04-17 16:05:31 -05003298 }
3299
James Smart7f048392020-09-11 13:01:47 -07003300 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3301 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3302 if (!cfglink_mbox)
3303 goto out;
3304 vport->port_state = LPFC_LOCAL_CFG_LINK;
3305 lpfc_config_link(phba, cfglink_mbox);
3306 cfglink_mbox->vport = vport;
3307 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3308 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3309 if (rc == MBX_NOT_FINISHED) {
3310 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3311 goto out;
3312 }
3313 } else {
James Smart32b97932009-07-19 10:01:21 -04003314 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003315 /*
3316 * Add the driver's default FCF record at FCF index 0 now. This
3317 * is phase 1 implementation that support FCF index 0 and driver
3318 * defaults.
3319 */
James Smart45ed1192009-10-02 15:17:02 -04003320 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003321 fcf_record = kzalloc(sizeof(struct fcf_record),
3322 GFP_KERNEL);
3323 if (unlikely(!fcf_record)) {
3324 lpfc_printf_log(phba, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003325 LOG_TRACE_EVENT,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003326 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003327 "fcf record\n");
3328 rc = -ENODEV;
3329 goto out;
3330 }
3331
3332 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3333 LPFC_FCOE_FCF_DEF_INDEX);
3334 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3335 if (unlikely(rc)) {
3336 lpfc_printf_log(phba, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003337 LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04003338 "2013 Could not manually add FCF "
3339 "record 0, status %d\n", rc);
3340 rc = -ENODEV;
3341 kfree(fcf_record);
3342 goto out;
3343 }
3344 kfree(fcf_record);
3345 }
3346 /*
3347 * The driver is expected to do FIP/FCF. Call the port
3348 * and get the FCF Table.
3349 */
James Smart894bb172019-08-14 16:56:52 -07003350 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta93ff372010-10-22 11:06:08 -04003351 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart894bb172019-08-14 16:56:52 -07003352 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart32b97932009-07-19 10:01:21 -04003353 return;
3354 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003355 /* This is the initial FCF discovery scan */
3356 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003357 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003358 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3359 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003360 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3361 LPFC_FCOE_FCF_GET_FIRST);
3362 if (rc) {
James Smart894bb172019-08-14 16:56:52 -07003363 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003364 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003365 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6fb120a2009-05-22 14:52:59 -04003366 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003367 }
James Smart38b92ef2010-08-04 16:11:39 -04003368 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003369 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003370 }
James Smart6fb120a2009-05-22 14:52:59 -04003371
James Smarte3ba04c2019-12-18 15:58:02 -08003372 /* Prepare for LINK up registrations */
3373 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3374 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3375 init_utsname()->nodename);
James Smart6fb120a2009-05-22 14:52:59 -04003376 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003377out:
3378 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07003379 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart32350662019-08-14 16:57:06 -07003380 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04003381 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003382 lpfc_issue_clear_la(phba, vport);
3383 return;
dea31012005-04-17 16:05:31 -05003384}
3385
3386static void
James Smart84774a42008-08-24 21:50:06 -04003387lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003388{
dea31012005-04-17 16:05:31 -05003389 uint32_t control;
3390 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003391 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003392 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003393 if (phba->sli_rev <= LPFC_SLI_REV3) {
3394 control = readl(phba->HCregaddr);
3395 control |= HC_LAINT_ENA;
3396 writel(control, phba->HCregaddr);
3397 readl(phba->HCregaddr); /* flush */
3398 }
James Smart2e0fef82007-06-17 19:56:36 -05003399 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003400}
3401
James Smart84774a42008-08-24 21:50:06 -04003402static void
3403lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3404{
3405 lpfc_linkdown(phba);
3406 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003407 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003408 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3409}
3410
3411
dea31012005-04-17 16:05:31 -05003412/*
James Smart76a95d72010-11-20 23:11:48 -05003413 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003414 * command upon completion. It is setup in the LPFC_MBOXQ
3415 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003416 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003417 */
3418void
James Smart76a95d72010-11-20 23:11:48 -05003419lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003420{
James Smart2e0fef82007-06-17 19:56:36 -05003421 struct lpfc_vport *vport = pmb->vport;
3422 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003423 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003424 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003425 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003426 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003427 uint8_t attn_type;
James Smart894bb172019-08-14 16:56:52 -07003428 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003429
James Smart0d2b6b82008-06-14 22:52:47 -04003430 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003431 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003432 if (pring)
3433 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003434
dea31012005-04-17 16:05:31 -05003435 /* Check for error */
3436 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003437 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003438 "1307 READ_LA mbox error x%x state x%x\n",
3439 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003440 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003441 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003442 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003443 }
3444
James Smart76a95d72010-11-20 23:11:48 -05003445 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003446 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003447
3448 memcpy(&phba->alpa_map[0], mp->virt, 128);
3449
James Smart894bb172019-08-14 16:56:52 -07003450 spin_lock_irqsave(shost->host_lock, iflags);
James Smart76a95d72010-11-20 23:11:48 -05003451 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003452 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003453 else
James Smart2e0fef82007-06-17 19:56:36 -05003454 vport->fc_flag &= ~FC_BYPASSED_MODE;
James Smart894bb172019-08-14 16:56:52 -07003455 spin_unlock_irqrestore(shost->host_lock, iflags);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003456
James Smartbe0c0082013-03-01 16:38:14 -05003457 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003458 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003459 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003460 if (phba->fc_eventTag != 0)
3461 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003462 }
dea31012005-04-17 16:05:31 -05003463
3464 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003465 if (phba->sli_rev < LPFC_SLI_REV4) {
James Smart894bb172019-08-14 16:56:52 -07003466 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003467 if (bf_get(lpfc_mbx_read_top_mm, la))
3468 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3469 else
3470 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart894bb172019-08-14 16:56:52 -07003471 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003472 }
dea31012005-04-17 16:05:31 -05003473
James Smart4d9ab992009-10-02 15:16:39 -04003474 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003475 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003476 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003477 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003478 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003479 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003480 "1306 Link Up Event in loop back mode "
3481 "x%x received Data: x%x x%x x%x x%x\n",
3482 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003483 bf_get(lpfc_mbx_read_top_alpa_granted,
3484 la),
3485 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003486 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003487 } else {
3488 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003489 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003490 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003491 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003492 bf_get(lpfc_mbx_read_top_alpa_granted,
3493 la),
3494 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003495 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003496 bf_get(lpfc_mbx_read_top_mm, la),
3497 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003498 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003499 }
James Smart92d7f7b2007-06-17 19:56:38 -05003500 lpfc_mbx_process_link_up(phba, la);
James Smartaeb3c812017-04-21 16:05:02 -07003501 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3502 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003503 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003504 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003505 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3506 "1308 Link Down Event in loop back mode "
3507 "x%x received "
3508 "Data: x%x x%x x%x\n",
3509 la->eventTag, phba->fc_eventTag,
3510 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003511 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3512 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smartb9da8142019-11-04 16:57:04 -08003513 "1313 Link Down Unexpected FA WWPN Event x%x "
3514 "received Data: x%x x%x x%x x%x x%x\n",
James Smartaeb3c812017-04-21 16:05:02 -07003515 la->eventTag, phba->fc_eventTag,
3516 phba->pport->port_state, vport->fc_flag,
3517 bf_get(lpfc_mbx_read_top_mm, la),
3518 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003519 else
James Smart3163f722008-02-08 18:50:25 -05003520 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003521 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003522 "Data: x%x x%x x%x x%x x%x\n",
3523 la->eventTag, phba->fc_eventTag,
3524 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003525 bf_get(lpfc_mbx_read_top_mm, la),
3526 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003527 lpfc_mbx_issue_link_down(phba);
3528 }
James Smartaeb3c812017-04-21 16:05:02 -07003529 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3530 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003531 if (phba->link_state != LPFC_LINK_DOWN) {
3532 phba->fc_stat.LinkDown++;
3533 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3534 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003535 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003536 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003537 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003538 lpfc_mbx_issue_link_down(phba);
3539 } else
3540 lpfc_enable_la(phba);
3541
3542 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3543 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3544 "Data: x%x x%x x%x\n",
3545 la->eventTag, phba->fc_eventTag,
3546 phba->pport->port_state, vport->fc_flag);
3547 /*
3548 * The cmnd that triggered this will be waiting for this
3549 * signal.
3550 */
3551 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3552 if (phba->wait_4_mlo_maint_flg) {
3553 phba->wait_4_mlo_maint_flg = 0;
3554 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003555 }
James Smart84774a42008-08-24 21:50:06 -04003556 }
3557
James Smartbe0c0082013-03-01 16:38:14 -05003558 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3559 bf_get(lpfc_mbx_read_top_fa, la)) {
3560 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003561 lpfc_issue_clear_la(phba, vport);
3562 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003563 "1311 fa %d\n",
3564 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003565 }
3566
James Smart76a95d72010-11-20 23:11:48 -05003567lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003568 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3569 kfree(mp);
3570 mempool_free(pmb, phba->mbox_mem_pool);
3571 return;
3572}
3573
3574/*
3575 * This routine handles processing a REG_LOGIN mailbox
3576 * command upon completion. It is setup in the LPFC_MBOXQ
3577 * as the completion routine when the command is
3578 * handed off to the SLI layer.
3579 */
3580void
James Smart2e0fef82007-06-17 19:56:36 -05003581lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003582{
James Smart2e0fef82007-06-17 19:56:36 -05003583 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003584 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3585 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
dea31012005-04-17 16:05:31 -05003586
James Smart3e1f0712018-11-29 16:09:29 -08003587 pmb->ctx_buf = NULL;
3588 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003589
James Smart52edb2c2020-11-15 11:26:35 -08003590 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08003591 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04003592 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003593 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08003594 ndlp);
James Smartffc95492010-06-07 15:23:17 -04003595 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3596 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3597
James Smart40426292010-12-15 17:58:10 -05003598 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3599 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003600 /* We rcvd a rscn after issuing this
3601 * mbox reg login, we may have cycled
3602 * back through the state and be
3603 * back at reg login state so this
3604 * mbox needs to be ignored becase
3605 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003606 * process.
James Smartffc95492010-06-07 15:23:17 -04003607 */
James Smartc6adba12020-11-15 11:26:34 -08003608 spin_lock_irq(&ndlp->lock);
James Smartffc95492010-06-07 15:23:17 -04003609 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
James Smartc6adba12020-11-15 11:26:34 -08003610 spin_unlock_irq(&ndlp->lock);
James Smart895427b2017-02-12 13:52:30 -08003611
3612 /*
3613 * We cannot leave the RPI registered because
3614 * if we go thru discovery again for this ndlp
3615 * a subsequent REG_RPI will fail.
3616 */
3617 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3618 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b72015-12-16 18:11:55 -05003619 }
3620
3621 /* Call state machine */
3622 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003623
dea31012005-04-17 16:05:31 -05003624 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3625 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003626 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003627 /* decrement the node reference count held for this callback
3628 * function.
3629 */
James Smart329f9bc2007-04-25 09:53:01 -04003630 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003631
3632 return;
3633}
3634
James Smart92d7f7b2007-06-17 19:56:38 -05003635static void
3636lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3637{
James Smart04c68492009-05-22 14:52:52 -04003638 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003639 struct lpfc_vport *vport = pmb->vport;
3640 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3641
3642 switch (mb->mbxStatus) {
3643 case 0x0011:
3644 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003645 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3646 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3647 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003648 break;
James Smart78730cf2010-04-06 15:06:30 -04003649 /* If VPI is busy, reset the HBA */
3650 case 0x9700:
Dick Kennedy372c1872020-06-30 14:50:00 -07003651 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart78730cf2010-04-06 15:06:30 -04003652 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3653 vport->vpi, mb->mbxStatus);
3654 if (!(phba->pport->load_flag & FC_UNLOADING))
3655 lpfc_workq_post_event(phba, NULL, NULL,
3656 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003657 }
James Smart72100cc2010-02-12 14:43:01 -05003658 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003659 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003660 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003661 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003662 vport->unreg_vpi_cmpl = VPORT_OK;
3663 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003664 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003665 /*
3666 * This shost reference might have been taken at the beginning of
3667 * lpfc_vport_delete()
3668 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003669 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003670 scsi_host_put(shost);
3671}
3672
James Smartd7c255b2008-08-24 21:50:00 -04003673int
James Smart92d7f7b2007-06-17 19:56:38 -05003674lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3675{
3676 struct lpfc_hba *phba = vport->phba;
3677 LPFC_MBOXQ_t *mbox;
3678 int rc;
3679
3680 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3681 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003682 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003683
3684 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3685 mbox->vport = vport;
3686 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003687 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003688 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003689 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003690 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003691 mempool_free(mbox, phba->mbox_mem_pool);
3692 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003693 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003694 }
James Smartd7c255b2008-08-24 21:50:00 -04003695 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003696}
3697
3698static void
3699lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3700{
3701 struct lpfc_vport *vport = pmb->vport;
3702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003703 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003704
3705 switch (mb->mbxStatus) {
3706 case 0x0011:
3707 case 0x9601:
3708 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003709 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3710 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3711 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003712 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3713 spin_lock_irq(shost->host_lock);
3714 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3715 spin_unlock_irq(shost->host_lock);
3716 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003717
James Smartf6e84792019-01-28 11:14:38 -08003718 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3719 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003720 if (phba->nvmet_support)
3721 lpfc_nvmet_update_targetport(phba);
3722 else
James Smart8c258642017-02-12 13:52:36 -08003723 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003724 }
James Smart92d7f7b2007-06-17 19:56:38 -05003725 goto out;
3726 }
James Smart92d7f7b2007-06-17 19:56:38 -05003727
James Smart72100cc2010-02-12 14:43:01 -05003728 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003729 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003730 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003731 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003732 vport->num_disc_nodes = 0;
3733 /* go thru NPR list and issue ELS PLOGIs */
3734 if (vport->fc_npr_cnt)
3735 lpfc_els_disc_plogi(vport);
3736
3737 if (!vport->num_disc_nodes) {
3738 spin_lock_irq(shost->host_lock);
3739 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3740 spin_unlock_irq(shost->host_lock);
3741 lpfc_can_disctmo(vport);
3742 }
3743 vport->port_state = LPFC_VPORT_READY;
3744
3745out:
3746 mempool_free(pmb, phba->mbox_mem_pool);
3747 return;
3748}
3749
James Smart21e9a0a2009-05-22 14:53:21 -04003750/**
3751 * lpfc_create_static_vport - Read HBA config region to create static vports.
3752 * @phba: pointer to lpfc hba data structure.
3753 *
3754 * This routine issue a DUMP mailbox command for config region 22 to get
3755 * the list of static vports to be created. The function create vports
3756 * based on the information returned from the HBA.
3757 **/
3758void
3759lpfc_create_static_vport(struct lpfc_hba *phba)
3760{
3761 LPFC_MBOXQ_t *pmb = NULL;
3762 MAILBOX_t *mb;
3763 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003764 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003765 struct fc_vport_identifiers vport_id;
3766 struct fc_vport *new_fc_vport;
3767 struct Scsi_Host *shost;
3768 struct lpfc_vport *vport;
3769 uint16_t offset = 0;
3770 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003771 struct lpfc_dmabuf *mp;
3772 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003773
3774 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3775 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003776 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04003777 "0542 lpfc_create_static_vport failed to"
3778 " allocate mailbox memory\n");
3779 return;
3780 }
James Smartcdcc2342012-08-14 14:26:35 -04003781 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003782 mb = &pmb->u.mb;
3783
3784 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3785 if (!vport_info) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003786 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04003787 "0543 lpfc_create_static_vport failed to"
3788 " allocate vport_info\n");
3789 mempool_free(pmb, phba->mbox_mem_pool);
3790 return;
3791 }
3792
3793 vport_buff = (uint8_t *) vport_info;
3794 do {
James Smartcdcc2342012-08-14 14:26:35 -04003795 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08003796 if (pmb->ctx_buf) {
3797 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04003798 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3799 kfree(mp);
3800 }
James Smart1c6834a2009-07-19 10:01:26 -04003801 if (lpfc_dump_static_vport(phba, pmb, offset))
3802 goto out;
3803
James Smart21e9a0a2009-05-22 14:53:21 -04003804 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003805 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3806 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003807
James Smartcdcc2342012-08-14 14:26:35 -04003808 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003809 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3810 "0544 lpfc_create_static_vport failed to"
3811 " issue dump mailbox command ret 0x%x "
3812 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003813 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003814 goto out;
3815 }
3816
James Smart1c6834a2009-07-19 10:01:26 -04003817 if (phba->sli_rev == LPFC_SLI_REV4) {
3818 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08003819 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003820 if (byte_count > sizeof(struct static_vport_info) -
3821 offset)
3822 byte_count = sizeof(struct static_vport_info)
3823 - offset;
3824 memcpy(vport_buff + offset, mp->virt, byte_count);
3825 offset += byte_count;
3826 } else {
3827 if (mb->un.varDmp.word_cnt >
3828 sizeof(struct static_vport_info) - offset)
3829 mb->un.varDmp.word_cnt =
3830 sizeof(struct static_vport_info)
3831 - offset;
3832 byte_count = mb->un.varDmp.word_cnt;
3833 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3834 vport_buff + offset,
3835 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003836
James Smart1c6834a2009-07-19 10:01:26 -04003837 offset += byte_count;
3838 }
James Smart21e9a0a2009-05-22 14:53:21 -04003839
James Smart1c6834a2009-07-19 10:01:26 -04003840 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003841 offset < sizeof(struct static_vport_info));
3842
3843
3844 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3845 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3846 != VPORT_INFO_REV)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003847 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3848 "0545 lpfc_create_static_vport bad"
3849 " information header 0x%x 0x%x\n",
3850 le32_to_cpu(vport_info->signature),
3851 le32_to_cpu(vport_info->rev) &
3852 VPORT_INFO_REV_MASK);
James Smart21e9a0a2009-05-22 14:53:21 -04003853
3854 goto out;
3855 }
3856
3857 shost = lpfc_shost_from_vport(phba->pport);
3858
3859 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3860 memset(&vport_id, 0, sizeof(vport_id));
3861 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3862 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3863 if (!vport_id.port_name || !vport_id.node_name)
3864 continue;
3865
3866 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3867 vport_id.vport_type = FC_PORTTYPE_NPIV;
3868 vport_id.disable = false;
3869 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3870
3871 if (!new_fc_vport) {
3872 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3873 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003874 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003875 continue;
3876 }
3877
3878 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3879 vport->vport_flag |= STATIC_VPORT;
3880 }
3881
3882out:
James Smart21e9a0a2009-05-22 14:53:21 -04003883 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003884 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08003885 if (pmb->ctx_buf) {
3886 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003887 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3888 kfree(mp);
3889 }
James Smart21e9a0a2009-05-22 14:53:21 -04003890 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003891 }
James Smart21e9a0a2009-05-22 14:53:21 -04003892
3893 return;
3894}
3895
dea31012005-04-17 16:05:31 -05003896/*
3897 * This routine handles processing a Fabric REG_LOGIN mailbox
3898 * command upon completion. It is setup in the LPFC_MBOXQ
3899 * as the completion routine when the command is
3900 * handed off to the SLI layer.
3901 */
3902void
James Smart2e0fef82007-06-17 19:56:36 -05003903lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003904{
James Smart92d7f7b2007-06-17 19:56:38 -05003905 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003906 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003907 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05003908 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003909 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003910
James Smart3e1f0712018-11-29 16:09:29 -08003911 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3912 pmb->ctx_ndlp = NULL;
3913 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04003914
dea31012005-04-17 16:05:31 -05003915 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003916 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04003917 "0258 Register Fabric login error: 0x%x\n",
3918 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003919 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3920 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003921 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003922
James Smart76a95d72010-11-20 23:11:48 -05003923 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003924 /* FLOGI failed, use loop map to make discovery list */
3925 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003926
James Smart92d7f7b2007-06-17 19:56:38 -05003927 /* Start discovery */
3928 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003929 /* Decrement the reference count to ndlp after the
3930 * reference to the ndlp are done.
3931 */
3932 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003933 return;
3934 }
3935
3936 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003937 /* Decrement the reference count to ndlp after the reference
3938 * to the ndlp are done.
3939 */
3940 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003941 return;
3942 }
3943
James Smart6d368e52011-05-24 11:44:12 -04003944 if (phba->sli_rev < LPFC_SLI_REV4)
3945 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003946 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003947 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003948 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003949
James Smart2e0fef82007-06-17 19:56:36 -05003950 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003951 /* when physical port receive logo donot start
3952 * vport discovery */
3953 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3954 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003955 else {
3956 shost = lpfc_shost_from_vport(vport);
3957 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003958 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003959 spin_unlock_irq(shost->host_lock);
3960 }
James Smart92d7f7b2007-06-17 19:56:38 -05003961 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003962 }
3963
3964 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3965 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003966 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003967
3968 /* Drop the reference count from the mbox at the end after
3969 * all the current reference to the ndlp have been done.
3970 */
3971 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003972 return;
3973}
3974
James Smarta0f2d3e2017-02-12 13:52:31 -08003975 /*
3976 * This routine will issue a GID_FT for each FC4 Type supported
3977 * by the driver. ALL GID_FTs must complete before discovery is started.
3978 */
3979int
3980lpfc_issue_gidft(struct lpfc_vport *vport)
3981{
James Smarta0f2d3e2017-02-12 13:52:31 -08003982 /* Good status, issue CT Request to NameServer */
James Smartf6e84792019-01-28 11:14:38 -08003983 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3984 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003985 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3986 /* Cannot issue NameServer FCP Query, so finish up
3987 * discovery
3988 */
Dick Kennedy372c1872020-06-30 14:50:00 -07003989 lpfc_printf_vlog(vport, KERN_ERR,
3990 LOG_TRACE_EVENT,
James Smarta0f2d3e2017-02-12 13:52:31 -08003991 "0604 %s FC TYPE %x %s\n",
3992 "Failed to issue GID_FT to ",
3993 FC_TYPE_FCP,
3994 "Finishing discovery.");
3995 return 0;
3996 }
3997 vport->gidft_inp++;
3998 }
3999
James Smartf6e84792019-01-28 11:14:38 -08004000 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4001 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004002 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4003 /* Cannot issue NameServer NVME Query, so finish up
4004 * discovery
4005 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004006 lpfc_printf_vlog(vport, KERN_ERR,
4007 LOG_TRACE_EVENT,
James Smarta0f2d3e2017-02-12 13:52:31 -08004008 "0605 %s FC_TYPE %x %s %d\n",
4009 "Failed to issue GID_FT to ",
4010 FC_TYPE_NVME,
4011 "Finishing discovery: gidftinp ",
4012 vport->gidft_inp);
4013 if (vport->gidft_inp == 0)
4014 return 0;
4015 } else
4016 vport->gidft_inp++;
4017 }
4018 return vport->gidft_inp;
4019}
4020
James Smart7ea92eb2018-10-23 13:41:10 -07004021/**
4022 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4023 * @vport: The virtual port for which this call is being executed.
4024 *
4025 * This routine will issue a GID_PT to get a list of all N_Ports
4026 *
4027 * Return value :
4028 * 0 - Failure to issue a GID_PT
4029 * 1 - GID_PT issued
4030 **/
4031int
4032lpfc_issue_gidpt(struct lpfc_vport *vport)
4033{
4034 /* Good status, issue CT Request to NameServer */
4035 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4036 /* Cannot issue NameServer FCP Query, so finish up
4037 * discovery
4038 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004039 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart7ea92eb2018-10-23 13:41:10 -07004040 "0606 %s Port TYPE %x %s\n",
4041 "Failed to issue GID_PT to ",
4042 GID_PT_N_PORT,
4043 "Finishing discovery.");
4044 return 0;
4045 }
4046 vport->gidft_inp++;
4047 return 1;
4048}
4049
dea31012005-04-17 16:05:31 -05004050/*
4051 * This routine handles processing a NameServer REG_LOGIN mailbox
4052 * command upon completion. It is setup in the LPFC_MBOXQ
4053 * as the completion routine when the command is
4054 * handed off to the SLI layer.
4055 */
4056void
James Smart2e0fef82007-06-17 19:56:36 -05004057lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004058{
James Smart21e9a0a2009-05-22 14:53:21 -04004059 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08004060 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4061 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004062 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05004063
James Smart3e1f0712018-11-29 16:09:29 -08004064 pmb->ctx_buf = NULL;
4065 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08004066 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04004067
dea31012005-04-17 16:05:31 -05004068 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004069 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04004070 "0260 Register NameServer error: 0x%x\n",
4071 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004072
4073out:
James Smartfa4066b2008-01-11 01:53:27 -05004074 /* decrement the node reference count held for this
4075 * callback function.
4076 */
James Smart329f9bc2007-04-25 09:53:01 -04004077 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4079 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004080 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004081
James Smart52edb2c2020-11-15 11:26:35 -08004082 /* If the node is not registered with the scsi or nvme
4083 * transport, remove the fabric node. The failed reg_login
4084 * is terminal.
4085 */
4086 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4087 spin_lock_irq(&ndlp->lock);
4088 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4089 spin_unlock_irq(&ndlp->lock);
4090 lpfc_nlp_not_used(ndlp);
4091 }
dea31012005-04-17 16:05:31 -05004092
James Smart76a95d72010-11-20 23:11:48 -05004093 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004094 /*
4095 * RegLogin failed, use loop map to make discovery
4096 * list
4097 */
4098 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004099
James Smart92d7f7b2007-06-17 19:56:38 -05004100 /* Start discovery */
4101 lpfc_disc_start(vport);
4102 return;
4103 }
4104 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004105 return;
4106 }
4107
James Smart6d368e52011-05-24 11:44:12 -04004108 if (phba->sli_rev < LPFC_SLI_REV4)
4109 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004110 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004111 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004112 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07004113 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08004114 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04004115 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004116 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08004117 ndlp);
dea31012005-04-17 16:05:31 -05004118
James Smart2e0fef82007-06-17 19:56:36 -05004119 if (vport->port_state < LPFC_VPORT_READY) {
4120 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004121 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4122 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4123 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4124 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004125
James Smartf6e84792019-01-28 11:14:38 -08004126 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4127 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
James Smarta0f2d3e2017-02-12 13:52:31 -08004128 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4129
James Smartf6e84792019-01-28 11:14:38 -08004130 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4131 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
James Smart01649562017-02-12 13:52:32 -08004132 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4133 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004134
4135 /* Issue SCR just before NameServer GID_FT Query */
James Smartdf3fe762020-02-10 09:31:55 -08004136 lpfc_issue_els_scr(vport, 0);
4137
James Smart8aaa7bc2020-10-20 13:27:17 -07004138 if (!phba->cfg_enable_mi ||
4139 phba->sli4_hba.pc_sli4_params.mi_ver < LPFC_MIB3_SUPPORT)
4140 lpfc_issue_els_rdf(vport, 0);
dea31012005-04-17 16:05:31 -05004141 }
4142
James Smart2e0fef82007-06-17 19:56:36 -05004143 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004144 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004145 goto out;
dea31012005-04-17 16:05:31 -05004146
James Smarta0f2d3e2017-02-12 13:52:31 -08004147 /*
4148 * At this point in time we may need to wait for multiple
4149 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4150 *
4151 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004152 * callback function.
4153 */
James Smart329f9bc2007-04-25 09:53:01 -04004154 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004155 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4156 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004157 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004158
4159 return;
4160}
4161
James Smartfe83e3b2021-05-14 12:55:54 -07004162/*
4163 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4164 * command upon completion. It is setup in the LPFC_MBOXQ
4165 * as the completion routine when the command is handed off to the SLI layer.
4166 */
4167void
4168lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4169{
4170 struct lpfc_vport *vport = pmb->vport;
4171 MAILBOX_t *mb = &pmb->u.mb;
4172 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4173 struct lpfc_nodelist *ndlp;
4174
4175 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4176 pmb->ctx_ndlp = NULL;
4177 pmb->ctx_buf = NULL;
4178
4179 if (mb->mbxStatus) {
4180 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4181 "0933 %s: Register FC login error: 0x%x\n",
4182 __func__, mb->mbxStatus);
4183 goto out;
4184 }
4185
4186 if (phba->sli_rev < LPFC_SLI_REV4)
4187 ndlp->nlp_rpi = mb->un.varWords[0];
4188
4189 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4190 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4191 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4192 ndlp->nlp_state);
4193
4194 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4195 ndlp->nlp_type |= NLP_FABRIC;
4196 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4197
4198 out:
4199 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4200 kfree(mp);
4201 mempool_free(pmb, phba->mbox_mem_pool);
4202
4203 /* Drop the reference count from the mbox at the end after
4204 * all the current reference to the ndlp have been done.
4205 */
4206 lpfc_nlp_put(ndlp);
4207}
4208
dea31012005-04-17 16:05:31 -05004209static void
James Smart2e0fef82007-06-17 19:56:36 -05004210lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004211{
James Smart2e0fef82007-06-17 19:56:36 -05004212 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4213 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004214 struct lpfc_rport_data *rdata;
4215 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004216 struct lpfc_hba *phba = vport->phba;
James Smartc6adba12020-11-15 11:26:34 -08004217 unsigned long flags;
dea31012005-04-17 16:05:31 -05004218
James Smartf6e84792019-01-28 11:14:38 -08004219 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smart895427b2017-02-12 13:52:30 -08004220 return;
4221
dea31012005-04-17 16:05:31 -05004222 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004223 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4224 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004225 rport_ids.port_id = ndlp->nlp_DID;
4226 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004227
James Smart858c9f62007-06-17 19:56:39 -05004228
4229 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smartc6adba12020-11-15 11:26:34 -08004230 "rport add: did:x%x flg:x%x type x%x",
4231 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
James Smart858c9f62007-06-17 19:56:39 -05004232
James Smart9589b0622011-04-16 11:03:17 -04004233 /* Don't add the remote port if unloading. */
4234 if (vport->load_flag & FC_UNLOADING)
4235 return;
4236
James Smartc6adba12020-11-15 11:26:34 -08004237 /*
4238 * Disassociate any older association between this ndlp and rport
4239 */
4240 if (ndlp->rport) {
4241 rdata = ndlp->rport->dd_data;
4242 rdata->pnode = NULL;
4243 }
4244
James Smart2e0fef82007-06-17 19:56:36 -05004245 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart95f0ef82020-11-15 11:26:32 -08004246 if (!rport) {
dea31012005-04-17 16:05:31 -05004247 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4248 "Warning: fc_remote_port_add failed\n");
4249 return;
4250 }
4251
James Smartc6adba12020-11-15 11:26:34 -08004252 /* Successful port add. Complete initializing node data */
dea31012005-04-17 16:05:31 -05004253 rport->maxframe_size = ndlp->nlp_maxframe;
4254 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004255 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004256 rdata->pnode = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08004257 if (!rdata->pnode) {
4258 dev_warn(&phba->pcidev->dev,
4259 "Warning - node ref failed. Unreg rport\n");
4260 fc_remote_port_delete(rport);
4261 ndlp->rport = NULL;
4262 return;
4263 }
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004264
James Smartc6adba12020-11-15 11:26:34 -08004265 spin_lock_irqsave(&ndlp->lock, flags);
4266 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4267 spin_unlock_irqrestore(&ndlp->lock, flags);
4268
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004269 if (ndlp->nlp_type & NLP_FCP_TARGET)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004270 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004271 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004272 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4273 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4274 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4275 if (ndlp->nlp_type & NLP_NVME_TARGET)
4276 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4277 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4278 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004279
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004280 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4281 fc_remote_port_rolechg(rport, rport_ids.roles);
4282
James Smart34f5ad82012-08-03 12:35:03 -04004283 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smartc6adba12020-11-15 11:26:34 -08004284 "3183 %s rport x%px DID x%x, role x%x\n",
4285 __func__, rport, rport->port_id, rport->roles);
James Smart34f5ad82012-08-03 12:35:03 -04004286
James Smart071fbd3d2006-04-15 11:53:20 -04004287 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004288 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004289 ndlp->nlp_sid = rport->scsi_target_id;
4290 }
James Smart95f0ef82020-11-15 11:26:32 -08004291
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004292 return;
4293}
4294
4295static void
James Smart2e0fef82007-06-17 19:56:36 -05004296lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004297{
4298 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004299 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004300
James Smartf6e84792019-01-28 11:14:38 -08004301 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08004302 return;
James Smartc01f3202006-08-18 17:47:08 -04004303
James Smart2ea259e2017-02-12 13:52:27 -08004304 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004305 "rport delete: did:x%x flg:x%x type x%x",
4306 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4307
James Smart2ea259e2017-02-12 13:52:27 -08004308 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smartc6adba12020-11-15 11:26:34 -08004309 "3184 rport unregister x%06x, rport x%px "
4310 "xptflg x%x\n",
4311 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags);
James Smart34f5ad82012-08-03 12:35:03 -04004312
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004313 fc_remote_port_delete(rport);
James Smartc6adba12020-11-15 11:26:34 -08004314 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004315}
4316
James Smartde0c5b32007-04-25 09:52:27 -04004317static void
James Smart2e0fef82007-06-17 19:56:36 -05004318lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004319{
James Smart2e0fef82007-06-17 19:56:36 -05004320 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -07004321 unsigned long iflags;
James Smart2e0fef82007-06-17 19:56:36 -05004322
James Smart894bb172019-08-14 16:56:52 -07004323 spin_lock_irqsave(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004324 switch (state) {
4325 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004326 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004327 break;
4328 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004329 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004330 break;
4331 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004332 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004333 break;
4334 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004335 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004336 break;
4337 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004338 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004339 break;
4340 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004341 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004342 break;
4343 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004344 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004345 break;
4346 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004347 if (vport->fc_npr_cnt == 0 && count == -1)
4348 vport->fc_npr_cnt = 0;
4349 else
4350 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004351 break;
4352 }
James Smart894bb172019-08-14 16:56:52 -07004353 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004354}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004355
James Smartde0c5b32007-04-25 09:52:27 -04004356static void
James Smart2e0fef82007-06-17 19:56:36 -05004357lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004358 int old_state, int new_state)
4359{
4360 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004361 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4362 ndlp->nlp_type |= NLP_FC_NODE;
4363 }
4364 if (new_state == NLP_STE_MAPPED_NODE)
4365 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4366 if (new_state == NLP_STE_NPR_NODE)
4367 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004368
James Smarta0f2d3e2017-02-12 13:52:31 -08004369 /* FCP and NVME Transport interface */
4370 if ((old_state == NLP_STE_MAPPED_NODE ||
4371 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart07aaefd2021-01-04 10:02:29 -08004372 if (ndlp->rport &&
4373 lpfc_valid_xpt_node(ndlp)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004374 vport->phba->nport_event_cnt++;
4375 lpfc_unregister_remote_port(ndlp);
4376 }
4377
James Smart1c5b12f2017-04-21 16:05:03 -07004378 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004379 vport->phba->nport_event_cnt++;
James Smart3b5bde692017-11-20 16:00:39 -08004380 if (vport->phba->nvmet_support == 0) {
4381 /* Start devloss if target. */
4382 if (ndlp->nlp_type & NLP_NVME_TARGET)
4383 lpfc_nvme_unregister_port(vport, ndlp);
4384 } else {
James Smart6599e122017-06-01 21:07:00 -07004385 /* NVMET has no upcall. */
4386 lpfc_nlp_put(ndlp);
James Smart3b5bde692017-11-20 16:00:39 -08004387 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004388 }
James Smartde0c5b32007-04-25 09:52:27 -04004389 }
dea31012005-04-17 16:05:31 -05004390
James Smarta0f2d3e2017-02-12 13:52:31 -08004391 /* FCP and NVME Transport interfaces */
4392
James Smartde0c5b32007-04-25 09:52:27 -04004393 if (new_state == NLP_STE_MAPPED_NODE ||
4394 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart07aaefd2021-01-04 10:02:29 -08004395 if (lpfc_valid_xpt_node(ndlp)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004396 vport->phba->nport_event_cnt++;
4397 /*
4398 * Tell the fc transport about the port, if we haven't
4399 * already. If we have, and it's a scsi entity, be
4400 */
4401 lpfc_register_remote_port(vport, ndlp);
4402 }
4403 /* Notify the NVME transport of this new rport. */
James Smart09559e82017-06-15 22:56:46 -07004404 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4405 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004406 if (vport->phba->nvmet_support == 0) {
4407 /* Register this rport with the transport.
James Smart3b5bde692017-11-20 16:00:39 -08004408 * Only NVME Target Rports are registered with
4409 * the transport.
James Smarta0f2d3e2017-02-12 13:52:31 -08004410 */
James Smart3b5bde692017-11-20 16:00:39 -08004411 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4412 vport->phba->nport_event_cnt++;
4413 lpfc_nvme_register_port(vport, ndlp);
4414 }
James Smart8c258642017-02-12 13:52:36 -08004415 } else {
4416 /* Just take an NDLP ref count since the
4417 * target does not register rports.
4418 */
4419 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004420 }
4421 }
James Smartde0c5b32007-04-25 09:52:27 -04004422 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004423
James Smartea2151b2008-09-07 11:52:10 -04004424 if ((new_state == NLP_STE_MAPPED_NODE) &&
4425 (vport->stat_data_enabled)) {
4426 /*
4427 * A new target is discovered, if there is no buffer for
4428 * statistical data collection allocate buffer.
4429 */
4430 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4431 sizeof(struct lpfc_scsicmd_bkt),
4432 GFP_KERNEL);
4433
4434 if (!ndlp->lat_data)
Dick Kennedy372c1872020-06-30 14:50:00 -07004435 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartea2151b2008-09-07 11:52:10 -04004436 "0286 lpfc_nlp_state_cleanup failed to "
4437 "allocate statistical data buffer DID "
4438 "0x%x\n", ndlp->nlp_DID);
4439 }
James Smart858c9f62007-06-17 19:56:39 -05004440 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004441 * If the node just added to Mapped list was an FCP target,
4442 * but the remote port registration failed or assigned a target
4443 * id outside the presentable range - move the node to the
4444 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004445 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004446 if ((new_state == NLP_STE_MAPPED_NODE) &&
4447 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004448 (!ndlp->rport ||
4449 ndlp->rport->scsi_target_id == -1 ||
4450 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smartc6adba12020-11-15 11:26:34 -08004451 spin_lock_irq(&ndlp->lock);
James Smartde0c5b32007-04-25 09:52:27 -04004452 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smartc6adba12020-11-15 11:26:34 -08004453 spin_unlock_irq(&ndlp->lock);
James Smart2e0fef82007-06-17 19:56:36 -05004454 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004455 }
James Smartde0c5b32007-04-25 09:52:27 -04004456}
4457
James Smart685f0bf2007-04-25 09:53:08 -04004458static char *
4459lpfc_nlp_state_name(char *buffer, size_t size, int state)
4460{
4461 static char *states[] = {
4462 [NLP_STE_UNUSED_NODE] = "UNUSED",
4463 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4464 [NLP_STE_ADISC_ISSUE] = "ADISC",
4465 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4466 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004467 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004468 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4469 [NLP_STE_MAPPED_NODE] = "MAPPED",
4470 [NLP_STE_NPR_NODE] = "NPR",
4471 };
4472
James Smart311464e2007-08-02 11:10:37 -04004473 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004474 strlcpy(buffer, states[state], size);
4475 else
4476 snprintf(buffer, size, "unknown (%d)", state);
4477 return buffer;
4478}
4479
James Smartde0c5b32007-04-25 09:52:27 -04004480void
James Smart2e0fef82007-06-17 19:56:36 -05004481lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4482 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004483{
James Smart2e0fef82007-06-17 19:56:36 -05004484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004485 int old_state = ndlp->nlp_state;
James Smart307e3382020-11-15 11:26:30 -08004486 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
James Smart685f0bf2007-04-25 09:53:08 -04004487 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004488
James Smarte8b62012007-08-02 11:10:09 -04004489 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4490 "0904 NPort state transition x%06x, %s -> %s\n",
4491 ndlp->nlp_DID,
4492 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4493 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004494
4495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4496 "node statechg did:x%x old:%d ste:%d",
4497 ndlp->nlp_DID, old_state, state);
4498
James Smart307e3382020-11-15 11:26:30 -08004499 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4500 state != NLP_STE_UNUSED_NODE) {
4501 ndlp->nlp_flag &= ~NLP_DROPPED;
4502 lpfc_nlp_get(ndlp);
4503 }
4504
James Smartde0c5b32007-04-25 09:52:27 -04004505 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004506 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004507 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004508 if (old_state == NLP_STE_UNMAPPED_NODE) {
4509 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4510 ndlp->nlp_type &= ~NLP_FC_NODE;
4511 }
4512
James Smart685f0bf2007-04-25 09:53:08 -04004513 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004514 spin_lock_irq(shost->host_lock);
4515 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4516 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004517 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004518 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004519
4520 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004521 lpfc_nlp_counters(vport, state, 1);
4522 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004523}
4524
4525void
James Smarte47c9092008-02-08 18:49:26 -05004526lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4527{
4528 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4529
4530 if (list_empty(&ndlp->nlp_listp)) {
4531 spin_lock_irq(shost->host_lock);
4532 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4533 spin_unlock_irq(shost->host_lock);
4534 }
4535}
4536
4537void
James Smart2e0fef82007-06-17 19:56:36 -05004538lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004539{
James Smart2e0fef82007-06-17 19:56:36 -05004540 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4541
James Smart0d2b6b82008-06-14 22:52:47 -04004542 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004543 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004544 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4545 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004546 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004547 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004548 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004549 NLP_STE_UNUSED_NODE);
4550}
4551
James Smart109f6ed2008-12-04 22:39:08 -05004552/**
James Smart3621a712009-04-06 18:47:14 -04004553 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004554 * @vport: Pointer to Virtual Port object.
4555 * @ndlp: Pointer to FC node object.
4556 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004557 *
4558 * This function is always called when node object need to be initialized.
4559 * It initializes all the fields of the node object. Although the reference
4560 * to phba from @ndlp can be obtained indirectly through it's reference to
4561 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4562 * to the life-span of the @ndlp might go beyond the existence of @vport as
4563 * the final release of ndlp is determined by its reference count. And, the
4564 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004565 **/
4566static inline void
4567lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4568 uint32_t did)
4569{
4570 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4571 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004572 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smarte7dab162020-10-20 13:27:12 -07004573 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4574
James Smart109f6ed2008-12-04 22:39:08 -05004575 ndlp->nlp_DID = did;
4576 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004577 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004578 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004579 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004580 kref_init(&ndlp->kref);
James Smart109f6ed2008-12-04 22:39:08 -05004581 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004582 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004583 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004584}
James Smarte47c9092008-02-08 18:49:26 -05004585
James Smartde0c5b32007-04-25 09:52:27 -04004586void
James Smart2e0fef82007-06-17 19:56:36 -05004587lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004588{
James Smart87af33f2007-10-27 13:37:43 -04004589 /*
James Smartfa4066b2008-01-11 01:53:27 -05004590 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004591 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004592 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4593 * until ALL other outstanding threads have completed. We check
4594 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004595 */
James Smartfa4066b2008-01-11 01:53:27 -05004596 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4597 return;
James Smart51ef4c22007-08-02 11:10:31 -04004598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart307e3382020-11-15 11:26:30 -08004599 ndlp->nlp_flag |= NLP_DROPPED;
James Smartbe6bb942015-04-07 15:07:22 -04004600 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004601 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004602 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004603 }
James Smart02902172015-05-21 13:55:17 -04004604
4605 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004606 return;
dea31012005-04-17 16:05:31 -05004607}
4608
4609/*
4610 * Start / ReStart rescue timer for Discovery / RSCN handling
4611 */
4612void
James Smart2e0fef82007-06-17 19:56:36 -05004613lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004614{
James Smart2e0fef82007-06-17 19:56:36 -05004615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4616 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004617 uint32_t tmo;
4618
James Smart2e0fef82007-06-17 19:56:36 -05004619 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004620 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004621 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4622 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004623 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004624 * FC spec states we need 3 * ratov for CT requests
4625 */
4626 tmo = ((phba->fc_ratov * 3) + 3);
4627 }
dea31012005-04-17 16:05:31 -05004628
James Smart858c9f62007-06-17 19:56:39 -05004629
4630 if (!timer_pending(&vport->fc_disctmo)) {
4631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4632 "set disc timer: tmo:x%x state:x%x flg:x%x",
4633 tmo, vport->port_state, vport->fc_flag);
4634 }
4635
James Smart256ec0d2013-04-17 20:14:58 -04004636 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004637 spin_lock_irq(shost->host_lock);
4638 vport->fc_flag |= FC_DISC_TMO;
4639 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004640
4641 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4643 "0247 Start Discovery Timer state x%x "
4644 "Data: x%x x%lx x%x x%x\n",
4645 vport->port_state, tmo,
4646 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4647 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004648
4649 return;
4650}
4651
4652/*
4653 * Cancel rescue timer for Discovery / RSCN handling
4654 */
4655int
James Smart2e0fef82007-06-17 19:56:36 -05004656lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004657{
James Smart2e0fef82007-06-17 19:56:36 -05004658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004659 unsigned long iflags;
4660
James Smart858c9f62007-06-17 19:56:39 -05004661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4662 "can disc timer: state:x%x rtry:x%x flg:x%x",
4663 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4664
dea31012005-04-17 16:05:31 -05004665 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004666 if (vport->fc_flag & FC_DISC_TMO) {
4667 spin_lock_irqsave(shost->host_lock, iflags);
4668 vport->fc_flag &= ~FC_DISC_TMO;
4669 spin_unlock_irqrestore(shost->host_lock, iflags);
4670 del_timer_sync(&vport->fc_disctmo);
4671 spin_lock_irqsave(&vport->work_port_lock, iflags);
4672 vport->work_port_events &= ~WORKER_DISC_TMO;
4673 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004674 }
4675
4676 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004677 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4678 "0248 Cancel Discovery Timer state x%x "
4679 "Data: x%x x%x x%x\n",
4680 vport->port_state, vport->fc_flag,
4681 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004682 return 0;
dea31012005-04-17 16:05:31 -05004683}
4684
4685/*
4686 * Check specified ring for outstanding IOCB on the SLI queue
4687 * Return true if iocb matches the specified nport
4688 */
4689int
James Smart2e0fef82007-06-17 19:56:36 -05004690lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4691 struct lpfc_sli_ring *pring,
4692 struct lpfc_iocbq *iocb,
4693 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004694{
James Smart2e0fef82007-06-17 19:56:36 -05004695 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004696 struct lpfc_vport *vport = ndlp->vport;
4697
4698 if (iocb->vport != vport)
4699 return 0;
4700
dea31012005-04-17 16:05:31 -05004701 if (pring->ringno == LPFC_ELS_RING) {
4702 switch (icmd->ulpCommand) {
4703 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004704 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004705 return 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004706 fallthrough;
dea31012005-04-17 16:05:31 -05004707 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004708 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4709 return 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004710 fallthrough;
dea31012005-04-17 16:05:31 -05004711 case CMD_XMIT_ELS_RSP64_CX:
4712 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004713 return 1;
dea31012005-04-17 16:05:31 -05004714 }
James Smart895427b2017-02-12 13:52:30 -08004715 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004716 /* Skip match check if waiting to relogin to FCP target */
4717 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004718 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004719 return 0;
dea31012005-04-17 16:05:31 -05004720 }
4721 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004722 return 1;
dea31012005-04-17 16:05:31 -05004723 }
dea31012005-04-17 16:05:31 -05004724 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004725 return 0;
dea31012005-04-17 16:05:31 -05004726}
4727
James Smart895427b2017-02-12 13:52:30 -08004728static void
4729__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4730 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4731 struct list_head *dequeue_list)
4732{
4733 struct lpfc_iocbq *iocb, *next_iocb;
4734
4735 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4736 /* Check to see if iocb matches the nport */
4737 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4738 /* match, dequeue */
4739 list_move_tail(&iocb->list, dequeue_list);
4740 }
4741}
4742
4743static void
4744lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4745 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4746{
4747 struct lpfc_sli *psli = &phba->sli;
4748 uint32_t i;
4749
4750 spin_lock_irq(&phba->hbalock);
4751 for (i = 0; i < psli->num_rings; i++)
4752 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4753 dequeue_list);
4754 spin_unlock_irq(&phba->hbalock);
4755}
4756
4757static void
4758lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4759 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4760{
4761 struct lpfc_sli_ring *pring;
4762 struct lpfc_queue *qp = NULL;
4763
4764 spin_lock_irq(&phba->hbalock);
4765 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4766 pring = qp->pring;
4767 if (!pring)
4768 continue;
James Smart2ade92a2017-03-04 09:30:38 -08004769 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004770 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08004771 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004772 }
4773 spin_unlock_irq(&phba->hbalock);
4774}
4775
dea31012005-04-17 16:05:31 -05004776/*
4777 * Free resources / clean up outstanding I/Os
4778 * associated with nlp_rpi in the LPFC_NODELIST entry.
4779 */
4780static int
James Smart2e0fef82007-06-17 19:56:36 -05004781lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004782{
James Smart2534ba72007-04-25 09:52:20 -04004783 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004784
James Smart92d7f7b2007-06-17 19:56:38 -05004785 lpfc_fabric_abort_nport(ndlp);
4786
dea31012005-04-17 16:05:31 -05004787 /*
4788 * Everything that matches on txcmplq will be returned
4789 * by firmware with a no rpi error.
4790 */
James Smart40426292010-12-15 17:58:10 -05004791 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004792 if (phba->sli_rev != LPFC_SLI_REV4)
4793 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4794 else
4795 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004796 }
James Smart2534ba72007-04-25 09:52:20 -04004797
James Smarta257bf92009-04-06 18:48:10 -04004798 /* Cancel all the IOCBs from the completions list */
4799 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4800 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004801
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004802 return 0;
dea31012005-04-17 16:05:31 -05004803}
4804
James Smart086a3452012-08-14 14:25:21 -04004805/**
4806 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4807 * @phba: Pointer to HBA context object.
4808 * @pmb: Pointer to mailbox object.
4809 *
4810 * This function will issue an ELS LOGO command after completing
4811 * the UNREG_RPI.
4812 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004813static void
James Smart086a3452012-08-14 14:25:21 -04004814lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4815{
4816 struct lpfc_vport *vport = pmb->vport;
4817 struct lpfc_nodelist *ndlp;
4818
James Smart3e1f0712018-11-29 16:09:29 -08004819 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04004820 if (!ndlp)
4821 return;
4822 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004823 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08004824
4825 /* Check to see if there are any deferred events to process */
4826 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4827 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4828 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4829 "1434 UNREG cmpl deferred logo x%x "
James Smart32350662019-08-14 16:57:06 -07004830 "on NPort x%x Data: x%x x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004831 ndlp->nlp_rpi, ndlp->nlp_DID,
4832 ndlp->nlp_defer_did, ndlp);
4833
4834 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4835 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4836 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart00292e02018-12-13 15:17:55 -08004837 } else {
James Smart01131e72021-05-14 12:55:49 -07004838 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
James Smart4f1a2fe2019-08-14 16:56:32 -07004839 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4840 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
James Smart01131e72021-05-14 12:55:49 -07004841 spin_lock_irq(&ndlp->lock);
James Smart4f1a2fe2019-08-14 16:56:32 -07004842 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
James Smart0f154222019-09-21 20:58:52 -07004843 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smart01131e72021-05-14 12:55:49 -07004844 spin_unlock_irq(&ndlp->lock);
James Smart4f1a2fe2019-08-14 16:56:32 -07004845 }
James Smart01131e72021-05-14 12:55:49 -07004846 spin_lock_irq(&ndlp->lock);
James Smart00292e02018-12-13 15:17:55 -08004847 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smart01131e72021-05-14 12:55:49 -07004848 spin_unlock_irq(&ndlp->lock);
James Smartdea16bd2018-11-29 16:09:30 -08004849 }
James Smart086a3452012-08-14 14:25:21 -04004850}
4851
dea31012005-04-17 16:05:31 -05004852/*
James Smart97acd002019-09-21 20:58:51 -07004853 * Sets the mailbox completion handler to be used for the
4854 * unreg_rpi command. The handler varies based on the state of
4855 * the port and what will be happening to the rpi next.
4856 */
4857static void
4858lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
4859 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
4860{
4861 unsigned long iflags;
4862
James Smarta70e63e2020-11-15 11:26:38 -08004863 /* Driver always gets a reference on the mailbox job
4864 * in support of async jobs.
4865 */
4866 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4867 if (!mbox->ctx_ndlp)
4868 return;
4869
James Smart97acd002019-09-21 20:58:51 -07004870 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
James Smart97acd002019-09-21 20:58:51 -07004871 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4872
4873 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
4874 (!(vport->load_flag & FC_UNLOADING)) &&
4875 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
4876 LPFC_SLI_INTF_IF_TYPE_2) &&
4877 (kref_read(&ndlp->kref) > 0)) {
James Smart97acd002019-09-21 20:58:51 -07004878 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
4879 } else {
4880 if (vport->load_flag & FC_UNLOADING) {
4881 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartc6adba12020-11-15 11:26:34 -08004882 spin_lock_irqsave(&ndlp->lock, iflags);
James Smart97acd002019-09-21 20:58:51 -07004883 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smartc6adba12020-11-15 11:26:34 -08004884 spin_unlock_irqrestore(&ndlp->lock, iflags);
James Smart97acd002019-09-21 20:58:51 -07004885 }
James Smart97acd002019-09-21 20:58:51 -07004886 }
James Smart97acd002019-09-21 20:58:51 -07004887 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4888 }
4889}
4890
4891/*
dea31012005-04-17 16:05:31 -05004892 * Free rpi associated with LPFC_NODELIST entry.
4893 * This routine is called from lpfc_freenode(), when we are removing
4894 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4895 * LOGO that completes successfully, and we are waiting to PLOGI back
4896 * to the remote NPort. In addition, it is called after we receive
4897 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4898 * we are waiting to PLOGI back to the remote NPort.
4899 */
4900int
James Smart2e0fef82007-06-17 19:56:36 -05004901lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004902{
James Smart2e0fef82007-06-17 19:56:36 -05004903 struct lpfc_hba *phba = vport->phba;
4904 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004905 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004906 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004907
James Smartf454a9a2013-09-06 12:20:07 -04004908 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4909 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4910 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
James Smart0f154222019-09-21 20:58:52 -07004911 lpfc_printf_vlog(vport, KERN_INFO,
4912 LOG_NODE | LOG_DISCOVERY,
James Smartf454a9a2013-09-06 12:20:07 -04004913 "3366 RPI x%x needs to be "
4914 "unregistered nlp_flag x%x "
4915 "did x%x\n",
4916 ndlp->nlp_rpi, ndlp->nlp_flag,
4917 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08004918
4919 /* If there is already an UNREG in progress for this ndlp,
4920 * no need to queue up another one.
4921 */
4922 if (ndlp->nlp_flag & NLP_UNREG_INP) {
James Smart0f154222019-09-21 20:58:52 -07004923 lpfc_printf_vlog(vport, KERN_INFO,
4924 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08004925 "1436 unreg_rpi SKIP UNREG x%x on "
4926 "NPort x%x deferred x%x flg x%x "
James Smart32350662019-08-14 16:57:06 -07004927 "Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004928 ndlp->nlp_rpi, ndlp->nlp_DID,
4929 ndlp->nlp_defer_did,
4930 ndlp->nlp_flag, ndlp);
4931 goto out;
4932 }
4933
James Smart2e0fef82007-06-17 19:56:36 -05004934 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4935 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004936 /* SLI4 ports require the physical rpi value. */
4937 rpi = ndlp->nlp_rpi;
4938 if (phba->sli_rev == LPFC_SLI_REV4)
4939 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004940
James Smart6d368e52011-05-24 11:44:12 -04004941 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004942 mbox->vport = vport;
James Smart97acd002019-09-21 20:58:51 -07004943 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
James Smarta70e63e2020-11-15 11:26:38 -08004944 if (!mbox->ctx_ndlp) {
4945 mempool_free(mbox, phba->mbox_mem_pool);
4946 return 1;
4947 }
4948
James Smart97acd002019-09-21 20:58:51 -07004949 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
4950 /*
4951 * accept PLOGIs after unreg_rpi_cmpl
4952 */
4953 acc_plogi = 0;
James Smartdea16bd2018-11-29 16:09:30 -08004954 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4955 Fabric_DID_MASK) &&
4956 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4957 ndlp->nlp_flag |= NLP_UNREG_INP;
4958
James Smart0f154222019-09-21 20:58:52 -07004959 lpfc_printf_vlog(vport, KERN_INFO,
4960 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08004961 "1433 unreg_rpi UNREG x%x on "
James Smart32350662019-08-14 16:57:06 -07004962 "NPort x%x deferred flg x%x "
4963 "Data:x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004964 ndlp->nlp_rpi, ndlp->nlp_DID,
4965 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004966
James Smart0b727fe2007-10-27 13:37:25 -04004967 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004968 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004969 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004970 acc_plogi = 1;
4971 }
James Smarte7dab162020-10-20 13:27:12 -07004972 } else {
4973 lpfc_printf_vlog(vport, KERN_INFO,
4974 LOG_NODE | LOG_DISCOVERY,
4975 "1444 Failed to allocate mempool "
4976 "unreg_rpi UNREG x%x, "
4977 "DID x%x, flag x%x, "
4978 "ndlp x%px\n",
4979 ndlp->nlp_rpi, ndlp->nlp_DID,
4980 ndlp->nlp_flag, ndlp);
4981
4982 /* Because mempool_alloc failed, we
4983 * will issue a LOGO here and keep the rpi alive if
4984 * not unloading.
4985 */
4986 if (!(vport->load_flag & FC_UNLOADING)) {
4987 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4988 lpfc_issue_els_logo(vport, ndlp, 0);
4989 ndlp->nlp_prev_state = ndlp->nlp_state;
4990 lpfc_nlp_set_state(vport, ndlp,
4991 NLP_STE_NPR_NODE);
4992 }
4993
4994 return 1;
dea31012005-04-17 16:05:31 -05004995 }
dea31012005-04-17 16:05:31 -05004996 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08004997out:
James Smart40426292010-12-15 17:58:10 -05004998 if (phba->sli_rev != LPFC_SLI_REV4)
4999 ndlp->nlp_rpi = 0;
5000 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04005001 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04005002 if (acc_plogi)
5003 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05005004 return 1;
5005 }
James Smart7c5e5182015-05-22 10:42:43 -04005006 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05005007 return 0;
5008}
5009
James Smartecfd03c2010-02-12 14:41:27 -05005010/**
5011 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5012 * @phba: pointer to lpfc hba data structure.
5013 *
5014 * This routine is invoked to unregister all the currently registered RPIs
5015 * to the HBA.
5016 **/
5017void
5018lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5019{
5020 struct lpfc_vport **vports;
5021 struct lpfc_nodelist *ndlp;
5022 struct Scsi_Host *shost;
5023 int i;
5024
5025 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05005026 if (!vports) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005027 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5028 "2884 Vport array allocation failed \n");
James Smart63e801c2010-11-20 23:14:19 -05005029 return;
5030 }
James Smartecfd03c2010-02-12 14:41:27 -05005031 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5032 shost = lpfc_shost_from_vport(vports[i]);
5033 spin_lock_irq(shost->host_lock);
5034 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05005035 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005036 /* The mempool_alloc might sleep */
5037 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05005038 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05005039 spin_lock_irq(shost->host_lock);
5040 }
James Smartecfd03c2010-02-12 14:41:27 -05005041 }
5042 spin_unlock_irq(shost->host_lock);
5043 }
5044 lpfc_destroy_vport_work_array(phba, vports);
5045}
5046
James Smart92d7f7b2007-06-17 19:56:38 -05005047void
5048lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5049{
5050 struct lpfc_hba *phba = vport->phba;
5051 LPFC_MBOXQ_t *mbox;
5052 int rc;
5053
James Smart5af5eee2010-10-22 11:06:38 -04005054 if (phba->sli_rev == LPFC_SLI_REV4) {
5055 lpfc_sli4_unreg_all_rpis(vport);
5056 return;
5057 }
5058
James Smart92d7f7b2007-06-17 19:56:38 -05005059 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5060 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005061 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5062 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005063 mbox->vport = vport;
5064 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005065 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005066 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005067 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005068 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04005069
5070 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
Dick Kennedy372c1872020-06-30 14:50:00 -07005071 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5072 "1836 Could not issue "
5073 "unreg_login(all_rpis) status %d\n",
5074 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005075 }
5076}
5077
5078void
5079lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5080{
5081 struct lpfc_hba *phba = vport->phba;
5082 LPFC_MBOXQ_t *mbox;
5083 int rc;
5084
James Smartc95a3b42019-03-12 16:30:07 -07005085 /* Unreg DID is an SLI3 operation. */
5086 if (phba->sli_rev > LPFC_SLI_REV3)
5087 return;
5088
James Smart92d7f7b2007-06-17 19:56:38 -05005089 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5090 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005091 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5092 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005093 mbox->vport = vport;
5094 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005095 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005096 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005097 if (rc != MBX_TIMEOUT)
5098 mempool_free(mbox, phba->mbox_mem_pool);
5099
5100 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
Dick Kennedy372c1872020-06-30 14:50:00 -07005101 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005102 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04005103 "unreg_did (default rpis) status %d\n",
5104 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005105 }
5106}
5107
dea31012005-04-17 16:05:31 -05005108/*
5109 * Free resources associated with LPFC_NODELIST entry
5110 * so it can be freed.
5111 */
5112static int
James Smart2e0fef82007-06-17 19:56:36 -05005113lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005114{
James Smart2e0fef82007-06-17 19:56:36 -05005115 struct lpfc_hba *phba = vport->phba;
5116 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005117 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05005118
5119 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005120 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5121 "0900 Cleanup node for NPort x%x "
5122 "Data: x%x x%x x%x\n",
5123 ndlp->nlp_DID, ndlp->nlp_flag,
5124 ndlp->nlp_state, ndlp->nlp_rpi);
James Smart307e3382020-11-15 11:26:30 -08005125 lpfc_dequeue_node(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -04005126
5127 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5128
dea31012005-04-17 16:05:31 -05005129 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5130 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005131 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005132 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005133 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5134 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005135 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5136 }
5137 }
James Smart33ccf8d2006-08-17 11:57:58 -04005138
James Smart2e0fef82007-06-17 19:56:36 -05005139 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005140 /* Cleanup REG_LOGIN completions which are not yet processed */
5141 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5142 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005143 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005144 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005145 continue;
5146
James Smart3e1f0712018-11-29 16:09:29 -08005147 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005148 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5149 }
5150
dea31012005-04-17 16:05:31 -05005151 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005152 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005153 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005154 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5155 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005156 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005157 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005158 kfree(mp);
5159 }
5160 list_del(&mb->list);
5161 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005162 /* We shall not invoke the lpfc_nlp_put to decrement
5163 * the ndlp reference count as we are in the process
5164 * of lpfc_nlp_release.
5165 */
dea31012005-04-17 16:05:31 -05005166 }
5167 }
James Smart2e0fef82007-06-17 19:56:36 -05005168 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005169
James Smarte47c9092008-02-08 18:49:26 -05005170 lpfc_els_abort(phba, ndlp);
5171
James Smartc6adba12020-11-15 11:26:34 -08005172 spin_lock_irq(&ndlp->lock);
James Smartc01f3202006-08-18 17:47:08 -04005173 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08005174 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005175
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005176 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005177 del_timer_sync(&ndlp->nlp_delayfunc);
5178
James Smart0d2b6b82008-06-14 22:52:47 -04005179 list_del_init(&ndlp->els_retry_evt.evt_listp);
5180 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smarte7dab162020-10-20 13:27:12 -07005181 list_del_init(&ndlp->recovery_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005182 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart01131e72021-05-14 12:55:49 -07005183
James Smart4f1a2fe2019-08-14 16:56:32 -07005184 if (phba->sli_rev == LPFC_SLI_REV4)
5185 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smart01131e72021-05-14 12:55:49 -07005186
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005187 return 0;
dea31012005-04-17 16:05:31 -05005188}
5189
dea31012005-04-17 16:05:31 -05005190static int
James Smart2e0fef82007-06-17 19:56:36 -05005191lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5192 uint32_t did)
dea31012005-04-17 16:05:31 -05005193{
James Smart2e0fef82007-06-17 19:56:36 -05005194 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005195
5196 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005197 return 0;
dea31012005-04-17 16:05:31 -05005198
dea31012005-04-17 16:05:31 -05005199 /* First check for Direct match */
5200 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005201 return 1;
dea31012005-04-17 16:05:31 -05005202
5203 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005204 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005205 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005206 return 0;
dea31012005-04-17 16:05:31 -05005207 }
5208
5209 matchdid.un.word = did;
5210 ndlpdid.un.word = ndlp->nlp_DID;
5211 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5212 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5213 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005214 /* This code is supposed to match the ID
5215 * for a private loop device that is
5216 * connect to fl_port. But we need to
5217 * check that the port did not just go
5218 * from pt2pt to fabric or we could end
5219 * up matching ndlp->nlp_DID 000001 to
5220 * fabric DID 0x20101
5221 */
dea31012005-04-17 16:05:31 -05005222 if ((ndlpdid.un.b.domain == 0) &&
5223 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005224 if (ndlpdid.un.b.id &&
5225 vport->phba->fc_topology ==
5226 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005227 return 1;
dea31012005-04-17 16:05:31 -05005228 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005229 return 0;
dea31012005-04-17 16:05:31 -05005230 }
5231
5232 matchdid.un.word = ndlp->nlp_DID;
5233 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5234 (mydid.un.b.area == ndlpdid.un.b.area)) {
5235 if ((matchdid.un.b.domain == 0) &&
5236 (matchdid.un.b.area == 0)) {
5237 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005238 return 1;
dea31012005-04-17 16:05:31 -05005239 }
5240 }
5241 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005242 return 0;
dea31012005-04-17 16:05:31 -05005243}
5244
James Smart685f0bf2007-04-25 09:53:08 -04005245/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005246static struct lpfc_nodelist *
5247__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005248{
James Smart2fb9bd82006-12-02 13:33:57 -05005249 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005250 uint32_t data1;
5251
James Smart2e0fef82007-06-17 19:56:36 -05005252 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5253 if (lpfc_matchdid(vport, ndlp, did)) {
James Smartb95b2112019-08-14 16:56:47 -07005254 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5255 ((uint32_t)ndlp->nlp_xri << 16) |
James Smart307e3382020-11-15 11:26:30 -08005256 ((uint32_t)ndlp->nlp_type << 8)
5257 );
James Smarte8b62012007-08-02 11:10:09 -04005258 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5259 "0929 FIND node DID "
James Smartb95b2112019-08-14 16:56:47 -07005260 "Data: x%px x%x x%x x%x x%x x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04005261 ndlp, ndlp->nlp_DID,
James Smartb95b2112019-08-14 16:56:47 -07005262 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
James Smartcff261f2013-12-17 20:29:47 -05005263 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005264 return ndlp;
dea31012005-04-17 16:05:31 -05005265 }
5266 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005267
dea31012005-04-17 16:05:31 -05005268 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005269 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5270 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005271 return NULL;
5272}
5273
5274struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005275lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005276{
James Smart2e0fef82007-06-17 19:56:36 -05005277 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005278 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005279 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005280
James Smartfedd3b72011-02-16 12:39:24 -05005281 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005282 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005283 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005284 return ndlp;
5285}
5286
5287struct lpfc_nodelist *
James Smartf60cb932019-05-14 14:58:05 -07005288lpfc_findnode_mapped(struct lpfc_vport *vport)
5289{
5290 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5291 struct lpfc_nodelist *ndlp;
5292 uint32_t data1;
5293 unsigned long iflags;
5294
5295 spin_lock_irqsave(shost->host_lock, iflags);
5296
5297 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5298 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5299 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5300 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5301 ((uint32_t)ndlp->nlp_xri << 16) |
5302 ((uint32_t)ndlp->nlp_type << 8) |
5303 ((uint32_t)ndlp->nlp_rpi & 0xff));
5304 spin_unlock_irqrestore(shost->host_lock, iflags);
5305 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5306 "2025 FIND node DID "
James Smart32350662019-08-14 16:57:06 -07005307 "Data: x%px x%x x%x x%x x%px\n",
James Smartf60cb932019-05-14 14:58:05 -07005308 ndlp, ndlp->nlp_DID,
5309 ndlp->nlp_flag, data1,
5310 ndlp->active_rrqs_xri_bitmap);
5311 return ndlp;
5312 }
5313 }
5314 spin_unlock_irqrestore(shost->host_lock, iflags);
5315
5316 /* FIND node did <did> NOT FOUND */
5317 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5318 "2026 FIND mapped did NOT FOUND.\n");
5319 return NULL;
5320}
5321
5322struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005323lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5324{
James Smart2e0fef82007-06-17 19:56:36 -05005325 struct lpfc_nodelist *ndlp;
5326
5327 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005328 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005329 if (vport->phba->nvmet_support)
5330 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005331 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5332 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005333 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005334 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005335 if (!ndlp)
5336 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005337 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartb4b34172019-10-18 14:18:31 -07005338
5339 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5340 "6453 Setup New Node 2B_DISC x%x "
5341 "Data:x%x x%x x%x\n",
5342 ndlp->nlp_DID, ndlp->nlp_flag,
5343 ndlp->nlp_state, vport->fc_flag);
5344
James Smartc6adba12020-11-15 11:26:34 -08005345 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005346 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08005347 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005348 return ndlp;
5349 }
James Smarte47c9092008-02-08 18:49:26 -05005350
James Smart1c5b12f2017-04-21 16:05:03 -07005351 /* The NVME Target does not want to actively manage an rport.
5352 * The goal is to allow the target to reset its state and clear
5353 * pending IO in preparation for the initiator to recover.
5354 */
James Smart58da1ff2008-04-07 10:15:56 -04005355 if ((vport->fc_flag & FC_RSCN_MODE) &&
5356 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005357 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005358
5359 /* Since this node is marked for discovery,
5360 * delay timeout is not needed.
5361 */
5362 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5363
James Smartb4b34172019-10-18 14:18:31 -07005364 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5365 "6455 Setup RSCN Node 2B_DISC x%x "
5366 "Data:x%x x%x x%x\n",
5367 ndlp->nlp_DID, ndlp->nlp_flag,
5368 ndlp->nlp_state, vport->fc_flag);
5369
James Smart1c5b12f2017-04-21 16:05:03 -07005370 /* NVME Target mode waits until rport is known to be
5371 * impacted by the RSCN before it transitions. No
5372 * active management - just go to NPR provided the
5373 * node had a valid login.
5374 */
5375 if (vport->phba->nvmet_support)
5376 return ndlp;
5377
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005378 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005379 * we don't need to try to discover it again.
5380 */
James Smart3f97aed2019-09-21 20:58:55 -07005381 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5382 !(ndlp->nlp_type &
5383 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
James Smart87af33f2007-10-27 13:37:43 -04005384 return NULL;
5385
James Smart3f97aed2019-09-21 20:58:55 -07005386 ndlp->nlp_prev_state = ndlp->nlp_state;
5387 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5388
James Smartc6adba12020-11-15 11:26:34 -08005389 spin_lock_irq(&ndlp->lock);
James Smarta257bf92009-04-06 18:48:10 -04005390 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08005391 spin_unlock_irq(&ndlp->lock);
James Smartb4b34172019-10-18 14:18:31 -07005392 } else {
5393 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5394 "6456 Skip Setup RSCN Node x%x "
5395 "Data:x%x x%x x%x\n",
5396 ndlp->nlp_DID, ndlp->nlp_flag,
5397 ndlp->nlp_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05005398 ndlp = NULL;
James Smartb4b34172019-10-18 14:18:31 -07005399 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005400 } else {
James Smartb4b34172019-10-18 14:18:31 -07005401 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5402 "6457 Setup Active Node 2B_DISC x%x "
5403 "Data:x%x x%x x%x\n",
5404 ndlp->nlp_DID, ndlp->nlp_flag,
5405 ndlp->nlp_state, vport->fc_flag);
5406
James Smart1c5b12f2017-04-21 16:05:03 -07005407 /* If the initiator received a PLOGI from this NPort or if the
5408 * initiator is already in the process of discovery on it,
5409 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005410 */
James Smart685f0bf2007-04-25 09:53:08 -04005411 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005412 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005413 (!vport->phba->nvmet_support &&
5414 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005415 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005416
James Smart8c258642017-02-12 13:52:36 -08005417 if (vport->phba->nvmet_support)
5418 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005419
5420 /* Moving to NPR state clears unsolicited flags and
5421 * allows for rediscovery
5422 */
5423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5424
James Smartc6adba12020-11-15 11:26:34 -08005425 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005426 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08005427 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005428 }
5429 return ndlp;
5430}
5431
5432/* Build a list of nodes to discover based on the loopmap */
5433void
James Smart2e0fef82007-06-17 19:56:36 -05005434lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005435{
James Smart2e0fef82007-06-17 19:56:36 -05005436 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005437 int j;
5438 uint32_t alpa, index;
5439
James Smart2e0fef82007-06-17 19:56:36 -05005440 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005441 return;
James Smart2e0fef82007-06-17 19:56:36 -05005442
James Smart76a95d72010-11-20 23:11:48 -05005443 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005444 return;
dea31012005-04-17 16:05:31 -05005445
5446 /* Check for loop map present or not */
5447 if (phba->alpa_map[0]) {
5448 for (j = 1; j <= phba->alpa_map[0]; j++) {
5449 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005450 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005451 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005452 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005453 }
5454 } else {
5455 /* No alpamap, so try all alpa's */
5456 for (j = 0; j < FC_MAXLOOP; j++) {
5457 /* If cfg_scan_down is set, start from highest
5458 * ALPA (0xef) to lowest (0x1).
5459 */
James Smart3de2a652007-08-02 11:09:59 -04005460 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005461 index = j;
5462 else
5463 index = FC_MAXLOOP - j - 1;
5464 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005465 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005466 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005467 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005468 }
5469 }
5470 return;
5471}
5472
James Smart895427b2017-02-12 13:52:30 -08005473/* SLI3 only */
dea31012005-04-17 16:05:31 -05005474void
James Smart2e0fef82007-06-17 19:56:36 -05005475lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005476{
dea31012005-04-17 16:05:31 -05005477 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005478 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005479 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5480 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005481 int rc;
5482
James Smart92d7f7b2007-06-17 19:56:38 -05005483 /*
5484 * if it's not a physical port or if we already send
5485 * clear_la then don't send it.
5486 */
5487 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005488 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5489 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005490 return;
5491
James Smart2e0fef82007-06-17 19:56:36 -05005492 /* Link up discovery */
5493 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5494 phba->link_state = LPFC_CLEAR_LA;
5495 lpfc_clear_la(phba, mbox);
5496 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5497 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005498 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005499 if (rc == MBX_NOT_FINISHED) {
5500 mempool_free(mbox, phba->mbox_mem_pool);
5501 lpfc_disc_flush_list(vport);
5502 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5503 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005504 phba->link_state = LPFC_HBA_ERROR;
5505 }
5506 }
5507}
5508
5509/* Reg_vpi to tell firmware to resume normal operations */
5510void
5511lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5512{
5513 LPFC_MBOXQ_t *regvpimbox;
5514
5515 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5516 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005517 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005518 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5519 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005520 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005521 == MBX_NOT_FINISHED) {
5522 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005523 }
5524 }
5525}
5526
5527/* Start Link up / RSCN discovery on NPR nodes */
5528void
5529lpfc_disc_start(struct lpfc_vport *vport)
5530{
5531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5532 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005533 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005534 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005535
James Smarte74c03c2013-04-17 20:15:19 -04005536 if (!lpfc_is_link_up(phba)) {
5537 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5538 "3315 Link is not up %x\n",
5539 phba->link_state);
dea31012005-04-17 16:05:31 -05005540 return;
James Smarte74c03c2013-04-17 20:15:19 -04005541 }
James Smart2e0fef82007-06-17 19:56:36 -05005542
5543 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005544 clear_la_pending = 1;
5545 else
5546 clear_la_pending = 0;
5547
James Smart2e0fef82007-06-17 19:56:36 -05005548 if (vport->port_state < LPFC_VPORT_READY)
5549 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005550
James Smart2e0fef82007-06-17 19:56:36 -05005551 lpfc_set_disctmo(vport);
5552
James Smart2e0fef82007-06-17 19:56:36 -05005553 vport->fc_prevDID = vport->fc_myDID;
5554 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005555
5556 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005557 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07005558 "0202 Start Discovery port state x%x "
5559 "flg x%x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04005560 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
James Smartb4b34172019-10-18 14:18:31 -07005561 vport->fc_adisc_cnt, vport->fc_npr_cnt);
dea31012005-04-17 16:05:31 -05005562
5563 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005564 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005565
5566 if (num_sent)
5567 return;
5568
James Smart6fa139f2013-04-17 20:20:00 -04005569 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005570 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005571 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005572 !(vport->fc_flag & FC_RSCN_MODE) &&
5573 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005574 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005575 lpfc_issue_reg_vpi(phba, vport);
5576 return;
5577 }
James Smart2e0fef82007-06-17 19:56:36 -05005578
James Smart92d7f7b2007-06-17 19:56:38 -05005579 /*
5580 * For SLI2, we need to set port_state to READY and continue
5581 * discovery.
5582 */
5583 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5584 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005585 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005586
5587 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005588 vport->num_disc_nodes = 0;
5589 /* go thru NPR nodes and issue ELS PLOGIs */
5590 if (vport->fc_npr_cnt)
5591 lpfc_els_disc_plogi(vport);
5592
5593 if (!vport->num_disc_nodes) {
5594 spin_lock_irq(shost->host_lock);
5595 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5596 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005597 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005598 }
5599 }
James Smart92d7f7b2007-06-17 19:56:38 -05005600 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005601 } else {
5602 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005603 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005604
5605 if (num_sent)
5606 return;
5607
James Smart2e0fef82007-06-17 19:56:36 -05005608 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005609 /* Check to see if more RSCNs came in while we
5610 * were processing this one.
5611 */
James Smart2e0fef82007-06-17 19:56:36 -05005612 if ((vport->fc_rscn_id_cnt == 0) &&
5613 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5614 spin_lock_irq(shost->host_lock);
5615 vport->fc_flag &= ~FC_RSCN_MODE;
5616 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005617 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005618 } else
James Smart2e0fef82007-06-17 19:56:36 -05005619 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005620 }
5621 }
5622 return;
5623}
5624
5625/*
5626 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5627 * ring the match the sppecified nodelist.
5628 */
5629static void
James Smart2e0fef82007-06-17 19:56:36 -05005630lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005631{
James Smart2534ba72007-04-25 09:52:20 -04005632 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005633 IOCB_t *icmd;
5634 struct lpfc_iocbq *iocb, *next_iocb;
5635 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005636
James Smart895427b2017-02-12 13:52:30 -08005637 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07005638 if (unlikely(!pring))
5639 return;
dea31012005-04-17 16:05:31 -05005640
5641 /* Error matching iocb on txq or txcmplq
5642 * First check the txq.
5643 */
James Smart2e0fef82007-06-17 19:56:36 -05005644 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005645 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5646 if (iocb->context1 != ndlp) {
5647 continue;
5648 }
5649 icmd = &iocb->iocb;
5650 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5651 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5652
James Smart2534ba72007-04-25 09:52:20 -04005653 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005654 }
5655 }
5656
5657 /* Next check the txcmplq */
5658 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5659 if (iocb->context1 != ndlp) {
5660 continue;
5661 }
5662 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005663 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5664 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smartdb7531d2020-11-15 11:26:44 -08005665 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
dea31012005-04-17 16:05:31 -05005666 }
5667 }
James Smart2e0fef82007-06-17 19:56:36 -05005668 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005669
James Smarta22d73b2021-01-04 10:02:38 -08005670 /* Make sure HBA is alive */
5671 lpfc_issue_hb_tmo(phba);
5672
James Smarta257bf92009-04-06 18:48:10 -04005673 /* Cancel all the IOCBs from the completions list */
5674 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5675 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005676}
5677
Adrian Bunka6ababd2007-11-05 18:07:33 +01005678static void
James Smart2e0fef82007-06-17 19:56:36 -05005679lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005680{
5681 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005682 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005683
James Smart2e0fef82007-06-17 19:56:36 -05005684 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5685 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005686 nlp_listp) {
5687 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5688 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5689 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005690 }
dea31012005-04-17 16:05:31 -05005691 }
5692 }
dea31012005-04-17 16:05:31 -05005693}
5694
James Smart92d7f7b2007-06-17 19:56:38 -05005695void
5696lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5697{
5698 lpfc_els_flush_rscn(vport);
5699 lpfc_els_flush_cmd(vport);
5700 lpfc_disc_flush_list(vport);
5701}
5702
dea31012005-04-17 16:05:31 -05005703/*****************************************************************************/
5704/*
5705 * NAME: lpfc_disc_timeout
5706 *
5707 * FUNCTION: Fibre Channel driver discovery timeout routine.
5708 *
5709 * EXECUTION ENVIRONMENT: interrupt only
5710 *
5711 * CALLED FROM:
5712 * Timer function
5713 *
5714 * RETURNS:
5715 * none
5716 */
5717/*****************************************************************************/
5718void
Kees Cookf22eb4d2017-09-06 20:24:26 -07005719lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05005720{
Kees Cookf22eb4d2017-09-06 20:24:26 -07005721 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05005722 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005723 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005724 unsigned long flags = 0;
5725
5726 if (unlikely(!phba))
5727 return;
5728
James Smart5e9d9b82008-06-14 22:52:53 -04005729 spin_lock_irqsave(&vport->work_port_lock, flags);
5730 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5731 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005732 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005733 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005734
James Smart5e9d9b82008-06-14 22:52:53 -04005735 if (!tmo_posted)
5736 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005737 return;
5738}
5739
5740static void
James Smart2e0fef82007-06-17 19:56:36 -05005741lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005742{
James Smart2e0fef82007-06-17 19:56:36 -05005743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5744 struct lpfc_hba *phba = vport->phba;
5745 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005746 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005747 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005748 int rc, clrlaerr = 0;
5749
James Smart2e0fef82007-06-17 19:56:36 -05005750 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005751 return;
5752
James Smart2e0fef82007-06-17 19:56:36 -05005753 spin_lock_irq(shost->host_lock);
5754 vport->fc_flag &= ~FC_DISC_TMO;
5755 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005756
James Smart858c9f62007-06-17 19:56:39 -05005757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5758 "disc timeout: state:x%x rtry:x%x flg:x%x",
5759 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5760
James Smart2e0fef82007-06-17 19:56:36 -05005761 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005762
5763 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005764 /*
5765 * port_state is identically LPFC_LOCAL_CFG_LINK while
5766 * waiting for FAN timeout
5767 */
James Smarte8b62012007-08-02 11:10:09 -04005768 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5769 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005770
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005771 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005772 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005773 nlp_listp) {
5774 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5775 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005776 if (ndlp->nlp_type & NLP_FABRIC) {
5777 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005778 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005779
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005780 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005781 /* Fail outstanding IO now since device
5782 * is marked for PLOGI.
5783 */
James Smart2e0fef82007-06-17 19:56:36 -05005784 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005785 }
5786 }
James Smart92d7f7b2007-06-17 19:56:38 -05005787 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005788 if (phba->sli_rev <= LPFC_SLI_REV3)
5789 lpfc_initial_flogi(vport);
5790 else
5791 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005792 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005793 }
dea31012005-04-17 16:05:31 -05005794 break;
5795
James Smart92d7f7b2007-06-17 19:56:38 -05005796 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005797 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005798 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005799 /* Initial FLOGI timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005800 lpfc_printf_vlog(vport, KERN_ERR,
5801 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005802 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005803 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005804
5805 /* Assume no Fabric and go on with discovery.
5806 * Check for outstanding ELS FLOGI to abort.
5807 */
5808
5809 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005810 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005811
5812 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005813 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005814 break;
5815
5816 case LPFC_FABRIC_CFG_LINK:
5817 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5818 NameServer login */
Dick Kennedy372c1872020-06-30 14:50:00 -07005819 lpfc_printf_vlog(vport, KERN_ERR,
5820 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005821 "0223 Timeout while waiting for "
5822 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005823 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005824 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart307e3382020-11-15 11:26:30 -08005825 if (ndlp)
James Smart87af33f2007-10-27 13:37:43 -04005826 lpfc_els_abort(phba, ndlp);
5827
5828 /* ReStart discovery */
5829 goto restart_disc;
dea31012005-04-17 16:05:31 -05005830
5831 case LPFC_NS_QRY:
5832 /* Check for wait for NameServer Rsp timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005833 lpfc_printf_vlog(vport, KERN_ERR,
5834 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005835 "0224 NameServer Query timeout "
5836 "Data: x%x x%x\n",
5837 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005838
James Smart92d7f7b2007-06-17 19:56:38 -05005839 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5840 /* Try it one more time */
5841 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005842 vport->gidft_inp = 0;
5843 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005844 if (rc == 0)
5845 break;
dea31012005-04-17 16:05:31 -05005846 }
James Smart92d7f7b2007-06-17 19:56:38 -05005847 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005848
James Smart87af33f2007-10-27 13:37:43 -04005849restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005850 /*
5851 * Discovery is over.
5852 * set port_state to PORT_READY if SLI2.
5853 * cmpl_reg_vpi will set port_state to READY for SLI3.
5854 */
James Smart3772a992009-05-22 14:50:54 -04005855 if (phba->sli_rev < LPFC_SLI_REV4) {
5856 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5857 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005858 else {
James Smart3772a992009-05-22 14:50:54 -04005859 lpfc_issue_clear_la(phba, vport);
5860 vport->port_state = LPFC_VPORT_READY;
5861 }
dea31012005-04-17 16:05:31 -05005862 }
5863
5864 /* Setup and issue mailbox INITIALIZE LINK command */
5865 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5866 if (!initlinkmbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005867 lpfc_printf_vlog(vport, KERN_ERR,
5868 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005869 "0206 Device Discovery "
5870 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005871 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005872 break;
5873 }
5874
5875 lpfc_linkdown(phba);
5876 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5877 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005878 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005879 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005880 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005881 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005882 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005883 if (rc == MBX_NOT_FINISHED)
5884 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5885
5886 break;
5887
5888 case LPFC_DISC_AUTH:
5889 /* Node Authentication timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005890 lpfc_printf_vlog(vport, KERN_ERR,
5891 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005892 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005893 lpfc_disc_flush_list(vport);
5894
James Smart92d7f7b2007-06-17 19:56:38 -05005895 /*
5896 * set port_state to PORT_READY if SLI2.
5897 * cmpl_reg_vpi will set port_state to READY for SLI3.
5898 */
James Smart3772a992009-05-22 14:50:54 -04005899 if (phba->sli_rev < LPFC_SLI_REV4) {
5900 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5901 lpfc_issue_reg_vpi(phba, vport);
5902 else { /* NPIV Not enabled */
5903 lpfc_issue_clear_la(phba, vport);
5904 vport->port_state = LPFC_VPORT_READY;
5905 }
dea31012005-04-17 16:05:31 -05005906 }
5907 break;
5908
James Smart2e0fef82007-06-17 19:56:36 -05005909 case LPFC_VPORT_READY:
5910 if (vport->fc_flag & FC_RSCN_MODE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005911 lpfc_printf_vlog(vport, KERN_ERR,
5912 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005913 "0231 RSCN timeout Data: x%x "
5914 "x%x\n",
5915 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005916
5917 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005918 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005919
James Smart2e0fef82007-06-17 19:56:36 -05005920 lpfc_els_flush_rscn(vport);
5921 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005922 }
5923 break;
James Smart2e0fef82007-06-17 19:56:36 -05005924
James Smart92d7f7b2007-06-17 19:56:38 -05005925 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005926 lpfc_printf_vlog(vport, KERN_ERR,
5927 LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04005928 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005929 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005930 break;
5931 }
5932
5933 switch (phba->link_state) {
5934 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005935 /* CLEAR LA timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005936 lpfc_printf_vlog(vport, KERN_ERR,
5937 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005938 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005939 clrlaerr = 1;
5940 break;
5941
James Smart09372822008-01-11 01:52:54 -05005942 case LPFC_LINK_UP:
5943 lpfc_issue_clear_la(phba, vport);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05005944 fallthrough;
James Smart2e0fef82007-06-17 19:56:36 -05005945 case LPFC_LINK_UNKNOWN:
5946 case LPFC_WARM_START:
5947 case LPFC_INIT_START:
5948 case LPFC_INIT_MBX_CMDS:
5949 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005950 case LPFC_HBA_ERROR:
Dick Kennedy372c1872020-06-30 14:50:00 -07005951 lpfc_printf_vlog(vport, KERN_ERR,
5952 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005953 "0230 Unexpected timeout, hba link "
5954 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005955 clrlaerr = 1;
5956 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005957
5958 case LPFC_HBA_READY:
5959 break;
dea31012005-04-17 16:05:31 -05005960 }
5961
5962 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005963 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08005964 if (phba->sli_rev != LPFC_SLI_REV4) {
5965 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5966 ~LPFC_STOP_IOCB_EVENT;
5967 psli->sli3_ring[LPFC_FCP_RING].flag &=
5968 ~LPFC_STOP_IOCB_EVENT;
5969 }
James Smart2e0fef82007-06-17 19:56:36 -05005970 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005971 }
dea31012005-04-17 16:05:31 -05005972 return;
5973}
5974
dea31012005-04-17 16:05:31 -05005975/*
5976 * This routine handles processing a NameServer REG_LOGIN mailbox
5977 * command upon completion. It is setup in the LPFC_MBOXQ
5978 * as the completion routine when the command is
5979 * handed off to the SLI layer.
5980 */
5981void
James Smart2e0fef82007-06-17 19:56:36 -05005982lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005983{
James Smart04c68492009-05-22 14:52:52 -04005984 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08005985 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5986 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005987 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005988
James Smart3e1f0712018-11-29 16:09:29 -08005989 pmb->ctx_buf = NULL;
5990 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005991
James Smart6d368e52011-05-24 11:44:12 -04005992 if (phba->sli_rev < LPFC_SLI_REV4)
5993 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05005994 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05005995 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005996 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07005997 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08005998 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04005999 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006000 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08006001 ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006002 /*
6003 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05006004 * 0xfffffa (FDMI well known port).
6005 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6006 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05006007 */
James Smarta314dec2021-04-11 18:31:20 -07006008 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6009 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
James Smart4258e982015-12-16 18:11:58 -05006010 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smarta314dec2021-04-11 18:31:20 -07006011 } else {
James Smart4258e982015-12-16 18:11:58 -05006012 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
James Smarta314dec2021-04-11 18:31:20 -07006013 }
James Smart4258e982015-12-16 18:11:58 -05006014
dea31012005-04-17 16:05:31 -05006015
James Smartfa4066b2008-01-11 01:53:27 -05006016 /* decrement the node reference count held for this callback
6017 * function.
6018 */
James Smart329f9bc2007-04-25 09:53:01 -04006019 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006020 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6021 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04006022 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006023
6024 return;
6025}
6026
James Smart685f0bf2007-04-25 09:53:08 -04006027static int
6028lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6029{
6030 uint16_t *rpi = param;
6031
6032 return ndlp->nlp_rpi == *rpi;
6033}
6034
6035static int
6036lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6037{
6038 return memcmp(&ndlp->nlp_portname, param,
6039 sizeof(ndlp->nlp_portname)) == 0;
6040}
6041
Adrian Bunka6ababd2007-11-05 18:07:33 +01006042static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006043__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05006044{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006045 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006046
James Smart2e0fef82007-06-17 19:56:36 -05006047 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04006048 if (filter(ndlp, param)) {
6049 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006050 "3185 FIND node filter %ps DID "
James Smart32350662019-08-14 16:57:06 -07006051 "ndlp x%px did x%x flg x%x st x%x "
James Smart49382502017-11-20 16:00:38 -08006052 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04006053 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08006054 ndlp->nlp_flag, ndlp->nlp_state,
6055 ndlp->nlp_xri, ndlp->nlp_type,
6056 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006057 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04006058 }
James Smart685f0bf2007-04-25 09:53:08 -04006059 }
James Smart34f5ad82012-08-03 12:35:03 -04006060 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006061 "3186 FIND node filter %ps NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006062 return NULL;
dea31012005-04-17 16:05:31 -05006063}
6064
James Smart685f0bf2007-04-25 09:53:08 -04006065/*
6066 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05006067 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04006068 */
6069struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006070__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04006071{
James Smart2e0fef82007-06-17 19:56:36 -05006072 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006073}
6074
James Smart488d1462006-03-07 15:02:37 -05006075/*
James Smart685f0bf2007-04-25 09:53:08 -04006076 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05006077 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05006078 */
6079struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006080lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05006081{
James Smart2e0fef82007-06-17 19:56:36 -05006082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05006083 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05006084
James Smart2e0fef82007-06-17 19:56:36 -05006085 spin_lock_irq(shost->host_lock);
6086 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6087 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05006088 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05006089}
6090
James Smartcb69f7d2011-12-13 13:21:57 -05006091/*
6092 * This routine looks up the ndlp lists for the given RPI. If the rpi
6093 * is found, the routine returns the node element list pointer else
6094 * return NULL.
6095 */
6096struct lpfc_nodelist *
6097lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6098{
6099 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6100 struct lpfc_nodelist *ndlp;
Fuqian Huang78d4b132019-08-12 16:31:34 +08006101 unsigned long flags;
James Smartcb69f7d2011-12-13 13:21:57 -05006102
Fuqian Huang78d4b132019-08-12 16:31:34 +08006103 spin_lock_irqsave(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006104 ndlp = __lpfc_findnode_rpi(vport, rpi);
Fuqian Huang78d4b132019-08-12 16:31:34 +08006105 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006106 return ndlp;
6107}
6108
6109/**
6110 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6111 * @phba: pointer to lpfc hba data structure.
6112 * @vpi: the physical host virtual N_Port identifier.
6113 *
6114 * This routine finds a vport on a HBA (referred by @phba) through a
6115 * @vpi. The function walks the HBA's vport list and returns the address
6116 * of the vport with the matching @vpi.
6117 *
6118 * Return code
6119 * NULL - No vport with the matching @vpi found
6120 * Otherwise - Address to the vport with the matching @vpi.
6121 **/
6122struct lpfc_vport *
6123lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6124{
6125 struct lpfc_vport *vport;
6126 unsigned long flags;
6127 int i = 0;
6128
6129 /* The physical ports are always vpi 0 - translate is unnecessary. */
6130 if (vpi > 0) {
6131 /*
6132 * Translate the physical vpi to the logical vpi. The
6133 * vport stores the logical vpi.
6134 */
James Smart58c36e82021-03-01 09:18:01 -08006135 for (i = 0; i <= phba->max_vpi; i++) {
James Smartcb69f7d2011-12-13 13:21:57 -05006136 if (vpi == phba->vpi_ids[i])
6137 break;
6138 }
6139
James Smart58c36e82021-03-01 09:18:01 -08006140 if (i > phba->max_vpi) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006141 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6142 "2936 Could not find Vport mapped "
6143 "to vpi %d\n", vpi);
James Smartcb69f7d2011-12-13 13:21:57 -05006144 return NULL;
6145 }
6146 }
6147
James Smart523128e2018-09-10 10:30:46 -07006148 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006149 list_for_each_entry(vport, &phba->port_list, listentry) {
6150 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006151 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006152 return vport;
6153 }
6154 }
James Smart523128e2018-09-10 10:30:46 -07006155 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006156 return NULL;
6157}
6158
James Smart9d3d3402017-04-21 16:05:00 -07006159struct lpfc_nodelist *
6160lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006161{
James Smart9d3d3402017-04-21 16:05:00 -07006162 struct lpfc_nodelist *ndlp;
6163 int rpi = LPFC_RPI_ALLOC_ERROR;
6164
6165 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6166 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6167 if (rpi == LPFC_RPI_ALLOC_ERROR)
6168 return NULL;
6169 }
6170
6171 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6172 if (!ndlp) {
6173 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6174 lpfc_sli4_free_rpi(vport->phba, rpi);
6175 return NULL;
6176 }
6177
dea31012005-04-17 16:05:31 -05006178 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006179
James Smartc6adba12020-11-15 11:26:34 -08006180 spin_lock_init(&ndlp->lock);
6181
James Smart109f6ed2008-12-04 22:39:08 -05006182 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006183 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006184 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006185 ndlp->nlp_rpi = rpi;
James Smart0f154222019-09-21 20:58:52 -07006186 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6187 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
James Smart307e3382020-11-15 11:26:30 -08006188 "flg:x%x refcnt:%d\n",
James Smart0f154222019-09-21 20:58:52 -07006189 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
James Smart307e3382020-11-15 11:26:30 -08006190 ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smartbe6bb942015-04-07 15:07:22 -04006191
James Smartcff261f2013-12-17 20:29:47 -05006192 ndlp->active_rrqs_xri_bitmap =
6193 mempool_alloc(vport->phba->active_rrq_pool,
6194 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006195 if (ndlp->active_rrqs_xri_bitmap)
6196 memset(ndlp->active_rrqs_xri_bitmap, 0,
6197 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006198 }
6199
James Smart725dd392013-10-10 12:23:30 -04006200
James Smart858c9f62007-06-17 19:56:39 -05006201
6202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6203 "node init: did:x%x",
6204 ndlp->nlp_DID, 0, 0);
6205
James Smart9d3d3402017-04-21 16:05:00 -07006206 return ndlp;
dea31012005-04-17 16:05:31 -05006207}
James Smart329f9bc2007-04-25 09:53:01 -04006208
James Smart98c9ea52007-10-27 13:37:33 -04006209/* This routine releases all resources associated with a specifc NPort's ndlp
6210 * and mempool_free's the nodelist.
6211 */
James Smart311464e2007-08-02 11:10:37 -04006212static void
James Smart329f9bc2007-04-25 09:53:01 -04006213lpfc_nlp_release(struct kref *kref)
6214{
6215 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6216 kref);
James Smartc6adba12020-11-15 11:26:34 -08006217 struct lpfc_vport *vport = ndlp->vport;
James Smart858c9f62007-06-17 19:56:39 -05006218
6219 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6220 "node release: did:x%x flg:x%x type:x%x",
6221 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6222
James Smartc6adba12020-11-15 11:26:34 -08006223 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smartf1156122021-04-11 18:31:24 -07006224 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
James Smartc6adba12020-11-15 11:26:34 -08006225 __func__, ndlp, ndlp->nlp_DID,
6226 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006227
6228 /* remove ndlp from action. */
James Smartc6adba12020-11-15 11:26:34 -08006229 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6230 lpfc_cleanup_node(vport, ndlp);
6231
James Smart01131e72021-05-14 12:55:49 -07006232 /* Not all ELS transactions have registered the RPI with the port.
6233 * In these cases the rpi usage is temporary and the node is
6234 * released when the WQE is completed. Catch this case to free the
6235 * RPI to the pool. Because this node is in the release path, a lock
6236 * is unnecessary. All references are gone and the node has been
6237 * dequeued.
6238 */
6239 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6240 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6241 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6242 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6243 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6244 }
6245 }
6246
6247 /* The node is not freed back to memory, it is released to a pool so
6248 * the node fields need to be cleaned up.
James Smartc6adba12020-11-15 11:26:34 -08006249 */
6250 ndlp->vport = NULL;
6251 ndlp->nlp_state = NLP_STE_FREED_NODE;
6252 ndlp->nlp_flag = 0;
6253 ndlp->fc4_xpt_flags = 0;
James Smarte47c9092008-02-08 18:49:26 -05006254
James Smarte47c9092008-02-08 18:49:26 -05006255 /* free ndlp memory for final ndlp release */
James Smart307e3382020-11-15 11:26:30 -08006256 kfree(ndlp->lat_data);
6257 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6258 mempool_free(ndlp->active_rrqs_xri_bitmap,
6259 ndlp->phba->active_rrq_pool);
6260 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04006261}
6262
James Smart98c9ea52007-10-27 13:37:33 -04006263/* This routine bumps the reference count for a ndlp structure to ensure
6264 * that one discovery thread won't free a ndlp while another discovery thread
6265 * is using it.
6266 */
James Smart329f9bc2007-04-25 09:53:01 -04006267struct lpfc_nodelist *
6268lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6269{
James Smarte47c9092008-02-08 18:49:26 -05006270 unsigned long flags;
6271
James Smart98c9ea52007-10-27 13:37:33 -04006272 if (ndlp) {
6273 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6274 "node get: did:x%x flg:x%x refcnt:x%x",
6275 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006276 kref_read(&ndlp->kref));
James Smart307e3382020-11-15 11:26:30 -08006277
James Smarte47c9092008-02-08 18:49:26 -05006278 /* The check of ndlp usage to prevent incrementing the
6279 * ndlp reference count that is in the process of being
6280 * released.
6281 */
James Smartc6adba12020-11-15 11:26:34 -08006282 spin_lock_irqsave(&ndlp->lock, flags);
James Smart307e3382020-11-15 11:26:30 -08006283 if (!kref_get_unless_zero(&ndlp->kref)) {
James Smartc6adba12020-11-15 11:26:34 -08006284 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smarte47c9092008-02-08 18:49:26 -05006285 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
James Smart307e3382020-11-15 11:26:30 -08006286 "0276 %s: ndlp:x%px refcnt:%d\n",
6287 __func__, (void *)ndlp, kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006288 return NULL;
James Smart307e3382020-11-15 11:26:30 -08006289 }
James Smartc6adba12020-11-15 11:26:34 -08006290 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smart307e3382020-11-15 11:26:30 -08006291 } else {
6292 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
James Smart98c9ea52007-10-27 13:37:33 -04006293 }
James Smart307e3382020-11-15 11:26:30 -08006294
James Smart329f9bc2007-04-25 09:53:01 -04006295 return ndlp;
6296}
6297
James Smart98c9ea52007-10-27 13:37:33 -04006298/* This routine decrements the reference count for a ndlp structure. If the
James Smart307e3382020-11-15 11:26:30 -08006299 * count goes to 0, this indicates the associated nodelist should be freed.
James Smart98c9ea52007-10-27 13:37:33 -04006300 */
James Smart329f9bc2007-04-25 09:53:01 -04006301int
6302lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6303{
James Smart307e3382020-11-15 11:26:30 -08006304 if (ndlp) {
6305 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6306 "node put: did:x%x flg:x%x refcnt:x%x",
6307 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006308 kref_read(&ndlp->kref));
James Smart307e3382020-11-15 11:26:30 -08006309 } else {
6310 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
James Smart98c9ea52007-10-27 13:37:33 -04006311 }
James Smart307e3382020-11-15 11:26:30 -08006312
6313 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
James Smart329f9bc2007-04-25 09:53:01 -04006314}
James Smart98c9ea52007-10-27 13:37:33 -04006315
6316/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006317 * by any other discovery thread. This routine returns 1 if the
6318 * ndlp has been freed. A return value of 0 indicates the ndlp is
6319 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006320 */
6321int
6322lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6323{
6324 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6325 "node not used: did:x%x flg:x%x refcnt:x%x",
6326 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006327 kref_read(&ndlp->kref));
James Smart01131e72021-05-14 12:55:49 -07006328
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006329 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006330 if (lpfc_nlp_put(ndlp))
6331 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006332 return 0;
6333}
James Smart6fb120a2009-05-22 14:52:59 -04006334
6335/**
6336 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6337 * @phba: Pointer to hba context object.
6338 *
6339 * This function iterate through all FC nodes associated
6340 * will all vports to check if there is any node with
6341 * fc_rports associated with it. If there is an fc_rport
6342 * associated with the node, then the node is either in
6343 * discovered state or its devloss_timer is pending.
6344 */
6345static int
6346lpfc_fcf_inuse(struct lpfc_hba *phba)
6347{
6348 struct lpfc_vport **vports;
6349 int i, ret = 0;
6350 struct lpfc_nodelist *ndlp;
6351 struct Scsi_Host *shost;
6352
6353 vports = lpfc_create_vport_work_array(phba);
6354
James Smart63e801c2010-11-20 23:14:19 -05006355 /* If driver cannot allocate memory, indicate fcf is in use */
6356 if (!vports)
6357 return 1;
6358
James Smart6fb120a2009-05-22 14:52:59 -04006359 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6360 shost = lpfc_shost_from_vport(vports[i]);
6361 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006362 /*
6363 * IF the CVL_RCVD bit is not set then we have sent the
6364 * flogi.
6365 * If dev_loss fires while we are waiting we do not want to
6366 * unreg the fcf.
6367 */
6368 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6369 spin_unlock_irq(shost->host_lock);
6370 ret = 1;
6371 goto out;
6372 }
James Smart6fb120a2009-05-22 14:52:59 -04006373 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08006374 if (ndlp->rport &&
James Smart6fb120a2009-05-22 14:52:59 -04006375 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6376 ret = 1;
6377 spin_unlock_irq(shost->host_lock);
6378 goto out;
James Smart80c17842012-03-01 22:35:45 -05006379 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6380 ret = 1;
James Smart0f154222019-09-21 20:58:52 -07006381 lpfc_printf_log(phba, KERN_INFO,
6382 LOG_NODE | LOG_DISCOVERY,
James Smart80c17842012-03-01 22:35:45 -05006383 "2624 RPI %x DID %x flag %x "
6384 "still logged in\n",
6385 ndlp->nlp_rpi, ndlp->nlp_DID,
6386 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006387 }
6388 }
6389 spin_unlock_irq(shost->host_lock);
6390 }
6391out:
6392 lpfc_destroy_vport_work_array(phba, vports);
6393 return ret;
6394}
6395
6396/**
6397 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6398 * @phba: Pointer to hba context object.
6399 * @mboxq: Pointer to mailbox object.
6400 *
6401 * This function frees memory associated with the mailbox command.
6402 */
James Smart1b511972011-12-13 13:23:09 -05006403void
James Smart6fb120a2009-05-22 14:52:59 -04006404lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6405{
6406 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006408
6409 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006410 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6411 "2555 UNREG_VFI mbxStatus error x%x "
6412 "HBA state x%x\n",
6413 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04006414 }
James Smart38b92ef2010-08-04 16:11:39 -04006415 spin_lock_irq(shost->host_lock);
6416 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6417 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006418 mempool_free(mboxq, phba->mbox_mem_pool);
6419 return;
6420}
6421
6422/**
6423 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6424 * @phba: Pointer to hba context object.
6425 * @mboxq: Pointer to mailbox object.
6426 *
6427 * This function frees memory associated with the mailbox command.
6428 */
6429static void
6430lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6431{
6432 struct lpfc_vport *vport = mboxq->vport;
6433
6434 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006435 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6436 "2550 UNREG_FCFI mbxStatus error x%x "
6437 "HBA state x%x\n",
6438 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04006439 }
6440 mempool_free(mboxq, phba->mbox_mem_pool);
6441 return;
6442}
6443
6444/**
James Smartecfd03c2010-02-12 14:41:27 -05006445 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006446 * @phba: Pointer to hba context object.
6447 *
James Smartecfd03c2010-02-12 14:41:27 -05006448 * This function prepare the HBA for unregistering the currently registered
6449 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6450 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006451 */
James Smartecfd03c2010-02-12 14:41:27 -05006452int
6453lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006454{
James Smart6fb120a2009-05-22 14:52:59 -04006455 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006456 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006457 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006458 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006459
James Smartecfd03c2010-02-12 14:41:27 -05006460 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006461 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006462 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006463
James Smart4d9ab992009-10-02 15:16:39 -04006464 /* At this point, all discovery is aborted */
6465 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006466
6467 /* Unregister VPIs */
6468 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006469 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006470 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006471 /* Stop FLOGI/FDISC retries */
6472 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6473 if (ndlp)
6474 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006475 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006476 if (phba->sli_rev == LPFC_SLI_REV4)
6477 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006478 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006479 shost = lpfc_shost_from_vport(vports[i]);
6480 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006481 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006482 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006483 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006484 }
6485 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006486 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6487 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6488 if (ndlp)
6489 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6490 lpfc_cleanup_pending_mbox(phba->pport);
6491 if (phba->sli_rev == LPFC_SLI_REV4)
6492 lpfc_sli4_unreg_all_rpis(phba->pport);
6493 lpfc_mbx_unreg_vpi(phba->pport);
6494 shost = lpfc_shost_from_vport(phba->pport);
6495 spin_lock_irq(shost->host_lock);
6496 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6497 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6498 spin_unlock_irq(shost->host_lock);
6499 }
James Smart6fb120a2009-05-22 14:52:59 -04006500
James Smart695a8142010-01-26 23:08:03 -05006501 /* Cleanup any outstanding ELS commands */
6502 lpfc_els_flush_all_cmd(phba);
6503
James Smart1b511972011-12-13 13:23:09 -05006504 /* Unregister the physical port VFI */
6505 rc = lpfc_issue_unreg_vfi(phba->pport);
6506 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006507}
6508
6509/**
6510 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6511 * @phba: Pointer to hba context object.
6512 *
6513 * This function issues synchronous unregister FCF mailbox command to HBA to
6514 * unregister the currently registered FCF record. The driver does not reset
6515 * the driver FCF usage state flags.
6516 *
6517 * Return 0 if successfully issued, none-zero otherwise.
6518 */
6519int
6520lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6521{
6522 LPFC_MBOXQ_t *mbox;
6523 int rc;
6524
James Smart6fb120a2009-05-22 14:52:59 -04006525 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6526 if (!mbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006527 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006528 "2551 UNREG_FCFI mbox allocation failed"
6529 "HBA state x%x\n", phba->pport->port_state);
6530 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006531 }
James Smart6fb120a2009-05-22 14:52:59 -04006532 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6533 mbox->vport = phba->pport;
6534 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6535 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6536
6537 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006538 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006539 "2552 Unregister FCFI command failed rc x%x "
6540 "HBA state x%x\n",
6541 rc, phba->pport->port_state);
6542 return -EINVAL;
6543 }
6544 return 0;
6545}
6546
6547/**
6548 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6549 * @phba: Pointer to hba context object.
6550 *
6551 * This function unregisters the currently reigstered FCF. This function
6552 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6553 */
6554void
6555lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6556{
6557 int rc;
6558
6559 /* Preparation for unregistering fcf */
6560 rc = lpfc_unregister_fcf_prep(phba);
6561 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006562 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006563 "2748 Failed to prepare for unregistering "
6564 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006565 return;
6566 }
6567
James Smartecfd03c2010-02-12 14:41:27 -05006568 /* Now, unregister FCF record and reset HBA FCF state */
6569 rc = lpfc_sli4_unregister_fcf(phba);
6570 if (rc)
6571 return;
6572 /* Reset HBA FCF states after successful unregister FCF */
6573 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006574 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006575
6576 /*
6577 * If driver is not unloading, check if there is any other
6578 * FCF record that can be used for discovery.
6579 */
6580 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006581 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006582 return;
6583
James Smart0c9ab6f2010-02-26 14:15:57 -05006584 /* This is considered as the initial FCF discovery scan */
6585 spin_lock_irq(&phba->hbalock);
6586 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6587 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006588
6589 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006590 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006591
James Smart0c9ab6f2010-02-26 14:15:57 -05006592 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006593
James Smart0c9ab6f2010-02-26 14:15:57 -05006594 if (rc) {
6595 spin_lock_irq(&phba->hbalock);
6596 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6597 spin_unlock_irq(&phba->hbalock);
Dick Kennedy372c1872020-06-30 14:50:00 -07006598 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006599 "2553 lpfc_unregister_unused_fcf failed "
6600 "to read FCF record HBA state x%x\n",
6601 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006602 }
James Smartecfd03c2010-02-12 14:41:27 -05006603}
6604
6605/**
6606 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6607 * @phba: Pointer to hba context object.
6608 *
6609 * This function just unregisters the currently reigstered FCF. It does not
6610 * try to find another FCF for discovery.
6611 */
6612void
6613lpfc_unregister_fcf(struct lpfc_hba *phba)
6614{
6615 int rc;
6616
6617 /* Preparation for unregistering fcf */
6618 rc = lpfc_unregister_fcf_prep(phba);
6619 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006620 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006621 "2749 Failed to prepare for unregistering "
6622 "HBA's FCF record: rc=%d\n", rc);
6623 return;
6624 }
6625
6626 /* Now, unregister FCF record and reset HBA FCF state */
6627 rc = lpfc_sli4_unregister_fcf(phba);
6628 if (rc)
6629 return;
6630 /* Set proper HBA FCF states after successful unregister FCF */
6631 spin_lock_irq(&phba->hbalock);
6632 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6633 spin_unlock_irq(&phba->hbalock);
6634}
6635
6636/**
6637 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6638 * @phba: Pointer to hba context object.
6639 *
6640 * This function check if there are any connected remote port for the FCF and
6641 * if all the devices are disconnected, this function unregister FCFI.
6642 * This function also tries to use another FCF for discovery.
6643 */
6644void
6645lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6646{
6647 /*
James Smart3804dc82010-07-14 15:31:37 -04006648 * If HBA is not running in FIP mode, if HBA does not support
6649 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6650 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006651 */
6652 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006653 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006654 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006655 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006656 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006657 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006658 spin_unlock_irq(&phba->hbalock);
6659 return;
6660 }
6661 spin_unlock_irq(&phba->hbalock);
6662
6663 if (lpfc_fcf_inuse(phba))
6664 return;
6665
6666 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006667}
6668
6669/**
6670 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6671 * @phba: Pointer to hba context object.
6672 * @buff: Buffer containing the FCF connection table as in the config
6673 * region.
6674 * This function create driver data structure for the FCF connection
6675 * record table read from config region 23.
6676 */
6677static void
6678lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6679 uint8_t *buff)
6680{
6681 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6682 struct lpfc_fcf_conn_hdr *conn_hdr;
6683 struct lpfc_fcf_conn_rec *conn_rec;
6684 uint32_t record_count;
6685 int i;
6686
6687 /* Free the current connect table */
6688 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006689 &phba->fcf_conn_rec_list, list) {
6690 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006691 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006692 }
James Smart6fb120a2009-05-22 14:52:59 -04006693
6694 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6695 record_count = conn_hdr->length * sizeof(uint32_t)/
6696 sizeof(struct lpfc_fcf_conn_rec);
6697
6698 conn_rec = (struct lpfc_fcf_conn_rec *)
6699 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6700
6701 for (i = 0; i < record_count; i++) {
6702 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6703 continue;
6704 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6705 GFP_KERNEL);
6706 if (!conn_entry) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006707 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6708 "2566 Failed to allocate connection"
6709 " table entry\n");
James Smart6fb120a2009-05-22 14:52:59 -04006710 return;
6711 }
6712
6713 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6714 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006715 list_add_tail(&conn_entry->list,
6716 &phba->fcf_conn_rec_list);
6717 }
James Smartdf0d0852013-05-31 17:05:08 -04006718
6719 if (!list_empty(&phba->fcf_conn_rec_list)) {
6720 i = 0;
6721 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6722 list) {
6723 conn_rec = &conn_entry->conn_rec;
6724 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6725 "3345 FCF connection list rec[%02d]: "
6726 "flags:x%04x, vtag:x%04x, "
6727 "fabric_name:x%02x:%02x:%02x:%02x:"
6728 "%02x:%02x:%02x:%02x, "
6729 "switch_name:x%02x:%02x:%02x:%02x:"
6730 "%02x:%02x:%02x:%02x\n", i++,
6731 conn_rec->flags, conn_rec->vlan_tag,
6732 conn_rec->fabric_name[0],
6733 conn_rec->fabric_name[1],
6734 conn_rec->fabric_name[2],
6735 conn_rec->fabric_name[3],
6736 conn_rec->fabric_name[4],
6737 conn_rec->fabric_name[5],
6738 conn_rec->fabric_name[6],
6739 conn_rec->fabric_name[7],
6740 conn_rec->switch_name[0],
6741 conn_rec->switch_name[1],
6742 conn_rec->switch_name[2],
6743 conn_rec->switch_name[3],
6744 conn_rec->switch_name[4],
6745 conn_rec->switch_name[5],
6746 conn_rec->switch_name[6],
6747 conn_rec->switch_name[7]);
6748 }
6749 }
James Smart6fb120a2009-05-22 14:52:59 -04006750}
6751
6752/**
6753 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6754 * @phba: Pointer to hba context object.
6755 * @buff: Buffer containing the FCoE parameter data structure.
6756 *
6757 * This function update driver data structure with config
6758 * parameters read from config region 23.
6759 */
6760static void
6761lpfc_read_fcoe_param(struct lpfc_hba *phba,
6762 uint8_t *buff)
6763{
6764 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6765 struct lpfc_fcoe_params *fcoe_param;
6766
6767 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6768 buff;
6769 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006770 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006771
6772 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6773 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6774 return;
6775
James Smart6fb120a2009-05-22 14:52:59 -04006776 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6777 phba->valid_vlan = 1;
6778 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6779 0xFFF;
6780 }
6781
6782 phba->fc_map[0] = fcoe_param->fc_map[0];
6783 phba->fc_map[1] = fcoe_param->fc_map[1];
6784 phba->fc_map[2] = fcoe_param->fc_map[2];
6785 return;
6786}
6787
6788/**
6789 * lpfc_get_rec_conf23 - Get a record type in config region data.
6790 * @buff: Buffer containing config region 23 data.
6791 * @size: Size of the data buffer.
6792 * @rec_type: Record type to be searched.
6793 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006794 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006795 * of the record specified by record_type. If record found, this
6796 * function return pointer to the record else return NULL.
6797 */
6798static uint8_t *
6799lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6800{
6801 uint32_t offset = 0, rec_length;
6802
6803 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6804 (size < sizeof(uint32_t)))
6805 return NULL;
6806
6807 rec_length = buff[offset + 1];
6808
6809 /*
6810 * One TLV record has one word header and number of data words
6811 * specified in the rec_length field of the record header.
6812 */
6813 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6814 <= size) {
6815 if (buff[offset] == rec_type)
6816 return &buff[offset];
6817
6818 if (buff[offset] == LPFC_REGION23_LAST_REC)
6819 return NULL;
6820
6821 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6822 rec_length = buff[offset + 1];
6823 }
6824 return NULL;
6825}
6826
6827/**
6828 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6829 * @phba: Pointer to lpfc_hba data structure.
6830 * @buff: Buffer containing config region 23 data.
6831 * @size: Size of the data buffer.
6832 *
Stefan Weileef35c22010-08-06 21:11:15 +02006833 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006834 * populate driver data structure with the parameters.
6835 */
6836void
6837lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6838 uint8_t *buff,
6839 uint32_t size)
6840{
James Smarteb016562014-09-03 12:58:06 -04006841 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006842 uint8_t *rec_ptr;
6843
6844 /*
6845 * If data size is less than 2 words signature and version cannot be
6846 * verified.
6847 */
6848 if (size < 2*sizeof(uint32_t))
6849 return;
6850
6851 /* Check the region signature first */
6852 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006853 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04006854 "2567 Config region 23 has bad signature\n");
6855 return;
6856 }
6857
6858 offset += 4;
6859
6860 /* Check the data structure version */
6861 if (buff[offset] != LPFC_REGION23_VERSION) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006862 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6863 "2568 Config region 23 has bad version\n");
James Smart6fb120a2009-05-22 14:52:59 -04006864 return;
6865 }
6866 offset += 4;
6867
James Smart6fb120a2009-05-22 14:52:59 -04006868 /* Read FCoE param record */
6869 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6870 size - offset, FCOE_PARAM_TYPE);
6871 if (rec_ptr)
6872 lpfc_read_fcoe_param(phba, rec_ptr);
6873
6874 /* Read FCF connection table */
6875 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6876 size - offset, FCOE_CONN_TBL_TYPE);
6877 if (rec_ptr)
6878 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6879
6880}